blob: 9720f96f462a012858f907d768a690d169760208 [file] [log] [blame]
Tim Northover3b0846e2014-05-24 12:50:23 +00001//===-- AArch64ISelDAGToDAG.cpp - A dag to dag inst selector for AArch64 --===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file defines an instruction selector for the AArch64 target.
11//
12//===----------------------------------------------------------------------===//
13
14#include "AArch64TargetMachine.h"
15#include "MCTargetDesc/AArch64AddressingModes.h"
16#include "llvm/ADT/APSInt.h"
17#include "llvm/CodeGen/SelectionDAGISel.h"
18#include "llvm/IR/Function.h" // To access function attributes.
19#include "llvm/IR/GlobalValue.h"
20#include "llvm/IR/Intrinsics.h"
21#include "llvm/Support/Debug.h"
22#include "llvm/Support/ErrorHandling.h"
23#include "llvm/Support/MathExtras.h"
24#include "llvm/Support/raw_ostream.h"
25
26using namespace llvm;
27
28#define DEBUG_TYPE "aarch64-isel"
29
30//===--------------------------------------------------------------------===//
31/// AArch64DAGToDAGISel - AArch64 specific code to select AArch64 machine
32/// instructions for SelectionDAG operations.
33///
34namespace {
35
36class AArch64DAGToDAGISel : public SelectionDAGISel {
37 AArch64TargetMachine &TM;
38
39 /// Subtarget - Keep a pointer to the AArch64Subtarget around so that we can
40 /// make the right decision when generating code for different targets.
41 const AArch64Subtarget *Subtarget;
42
43 bool ForCodeSize;
44
45public:
46 explicit AArch64DAGToDAGISel(AArch64TargetMachine &tm,
47 CodeGenOpt::Level OptLevel)
48 : SelectionDAGISel(tm, OptLevel), TM(tm), Subtarget(nullptr),
49 ForCodeSize(false) {}
50
51 const char *getPassName() const override {
52 return "AArch64 Instruction Selection";
53 }
54
55 bool runOnMachineFunction(MachineFunction &MF) override {
Tim Northover3b0846e2014-05-24 12:50:23 +000056 ForCodeSize =
Duncan P. N. Exon Smith003bb7d2015-02-14 02:09:06 +000057 MF.getFunction()->hasFnAttribute(Attribute::OptimizeForSize) ||
58 MF.getFunction()->hasFnAttribute(Attribute::MinSize);
Eric Christopher1e513342015-01-30 23:46:40 +000059 Subtarget = &MF.getSubtarget<AArch64Subtarget>();
Tim Northover3b0846e2014-05-24 12:50:23 +000060 return SelectionDAGISel::runOnMachineFunction(MF);
61 }
62
63 SDNode *Select(SDNode *Node) override;
64
65 /// SelectInlineAsmMemoryOperand - Implement addressing mode selection for
66 /// inline asm expressions.
67 bool SelectInlineAsmMemoryOperand(const SDValue &Op,
Daniel Sanders60f1db02015-03-13 12:45:09 +000068 unsigned ConstraintID,
Tim Northover3b0846e2014-05-24 12:50:23 +000069 std::vector<SDValue> &OutOps) override;
70
71 SDNode *SelectMLAV64LaneV128(SDNode *N);
72 SDNode *SelectMULLV64LaneV128(unsigned IntNo, SDNode *N);
73 bool SelectArithExtendedRegister(SDValue N, SDValue &Reg, SDValue &Shift);
74 bool SelectArithImmed(SDValue N, SDValue &Val, SDValue &Shift);
75 bool SelectNegArithImmed(SDValue N, SDValue &Val, SDValue &Shift);
76 bool SelectArithShiftedRegister(SDValue N, SDValue &Reg, SDValue &Shift) {
77 return SelectShiftedRegister(N, false, Reg, Shift);
78 }
79 bool SelectLogicalShiftedRegister(SDValue N, SDValue &Reg, SDValue &Shift) {
80 return SelectShiftedRegister(N, true, Reg, Shift);
81 }
82 bool SelectAddrModeIndexed8(SDValue N, SDValue &Base, SDValue &OffImm) {
83 return SelectAddrModeIndexed(N, 1, Base, OffImm);
84 }
85 bool SelectAddrModeIndexed16(SDValue N, SDValue &Base, SDValue &OffImm) {
86 return SelectAddrModeIndexed(N, 2, Base, OffImm);
87 }
88 bool SelectAddrModeIndexed32(SDValue N, SDValue &Base, SDValue &OffImm) {
89 return SelectAddrModeIndexed(N, 4, Base, OffImm);
90 }
91 bool SelectAddrModeIndexed64(SDValue N, SDValue &Base, SDValue &OffImm) {
92 return SelectAddrModeIndexed(N, 8, Base, OffImm);
93 }
94 bool SelectAddrModeIndexed128(SDValue N, SDValue &Base, SDValue &OffImm) {
95 return SelectAddrModeIndexed(N, 16, Base, OffImm);
96 }
97 bool SelectAddrModeUnscaled8(SDValue N, SDValue &Base, SDValue &OffImm) {
98 return SelectAddrModeUnscaled(N, 1, Base, OffImm);
99 }
100 bool SelectAddrModeUnscaled16(SDValue N, SDValue &Base, SDValue &OffImm) {
101 return SelectAddrModeUnscaled(N, 2, Base, OffImm);
102 }
103 bool SelectAddrModeUnscaled32(SDValue N, SDValue &Base, SDValue &OffImm) {
104 return SelectAddrModeUnscaled(N, 4, Base, OffImm);
105 }
106 bool SelectAddrModeUnscaled64(SDValue N, SDValue &Base, SDValue &OffImm) {
107 return SelectAddrModeUnscaled(N, 8, Base, OffImm);
108 }
109 bool SelectAddrModeUnscaled128(SDValue N, SDValue &Base, SDValue &OffImm) {
110 return SelectAddrModeUnscaled(N, 16, Base, OffImm);
111 }
112
113 template<int Width>
114 bool SelectAddrModeWRO(SDValue N, SDValue &Base, SDValue &Offset,
115 SDValue &SignExtend, SDValue &DoShift) {
116 return SelectAddrModeWRO(N, Width / 8, Base, Offset, SignExtend, DoShift);
117 }
118
119 template<int Width>
120 bool SelectAddrModeXRO(SDValue N, SDValue &Base, SDValue &Offset,
121 SDValue &SignExtend, SDValue &DoShift) {
122 return SelectAddrModeXRO(N, Width / 8, Base, Offset, SignExtend, DoShift);
123 }
124
125
126 /// Form sequences of consecutive 64/128-bit registers for use in NEON
127 /// instructions making use of a vector-list (e.g. ldN, tbl). Vecs must have
128 /// between 1 and 4 elements. If it contains a single element that is returned
129 /// unchanged; otherwise a REG_SEQUENCE value is returned.
130 SDValue createDTuple(ArrayRef<SDValue> Vecs);
131 SDValue createQTuple(ArrayRef<SDValue> Vecs);
132
133 /// Generic helper for the createDTuple/createQTuple
134 /// functions. Those should almost always be called instead.
Benjamin Kramerea68a942015-02-19 15:26:17 +0000135 SDValue createTuple(ArrayRef<SDValue> Vecs, const unsigned RegClassIDs[],
136 const unsigned SubRegs[]);
Tim Northover3b0846e2014-05-24 12:50:23 +0000137
138 SDNode *SelectTable(SDNode *N, unsigned NumVecs, unsigned Opc, bool isExt);
139
140 SDNode *SelectIndexedLoad(SDNode *N, bool &Done);
141
142 SDNode *SelectLoad(SDNode *N, unsigned NumVecs, unsigned Opc,
143 unsigned SubRegIdx);
144 SDNode *SelectPostLoad(SDNode *N, unsigned NumVecs, unsigned Opc,
145 unsigned SubRegIdx);
146 SDNode *SelectLoadLane(SDNode *N, unsigned NumVecs, unsigned Opc);
147 SDNode *SelectPostLoadLane(SDNode *N, unsigned NumVecs, unsigned Opc);
148
149 SDNode *SelectStore(SDNode *N, unsigned NumVecs, unsigned Opc);
150 SDNode *SelectPostStore(SDNode *N, unsigned NumVecs, unsigned Opc);
151 SDNode *SelectStoreLane(SDNode *N, unsigned NumVecs, unsigned Opc);
152 SDNode *SelectPostStoreLane(SDNode *N, unsigned NumVecs, unsigned Opc);
153
Tim Northover3b0846e2014-05-24 12:50:23 +0000154 SDNode *SelectBitfieldExtractOp(SDNode *N);
155 SDNode *SelectBitfieldInsertOp(SDNode *N);
156
157 SDNode *SelectLIBM(SDNode *N);
158
Luke Cheeseman85fd06d2015-06-01 12:02:47 +0000159 SDNode *SelectReadRegister(SDNode *N);
160 SDNode *SelectWriteRegister(SDNode *N);
161
Tim Northover3b0846e2014-05-24 12:50:23 +0000162// Include the pieces autogenerated from the target description.
163#include "AArch64GenDAGISel.inc"
164
165private:
166 bool SelectShiftedRegister(SDValue N, bool AllowROR, SDValue &Reg,
167 SDValue &Shift);
168 bool SelectAddrModeIndexed(SDValue N, unsigned Size, SDValue &Base,
169 SDValue &OffImm);
170 bool SelectAddrModeUnscaled(SDValue N, unsigned Size, SDValue &Base,
171 SDValue &OffImm);
172 bool SelectAddrModeWRO(SDValue N, unsigned Size, SDValue &Base,
173 SDValue &Offset, SDValue &SignExtend,
174 SDValue &DoShift);
175 bool SelectAddrModeXRO(SDValue N, unsigned Size, SDValue &Base,
176 SDValue &Offset, SDValue &SignExtend,
177 SDValue &DoShift);
178 bool isWorthFolding(SDValue V) const;
179 bool SelectExtendedSHL(SDValue N, unsigned Size, bool WantExtend,
180 SDValue &Offset, SDValue &SignExtend);
181
182 template<unsigned RegWidth>
183 bool SelectCVTFixedPosOperand(SDValue N, SDValue &FixedPos) {
184 return SelectCVTFixedPosOperand(N, FixedPos, RegWidth);
185 }
186
187 bool SelectCVTFixedPosOperand(SDValue N, SDValue &FixedPos, unsigned Width);
188};
189} // end anonymous namespace
190
191/// isIntImmediate - This method tests to see if the node is a constant
192/// operand. If so Imm will receive the 32-bit value.
193static bool isIntImmediate(const SDNode *N, uint64_t &Imm) {
194 if (const ConstantSDNode *C = dyn_cast<const ConstantSDNode>(N)) {
195 Imm = C->getZExtValue();
196 return true;
197 }
198 return false;
199}
200
201// isIntImmediate - This method tests to see if a constant operand.
202// If so Imm will receive the value.
203static bool isIntImmediate(SDValue N, uint64_t &Imm) {
204 return isIntImmediate(N.getNode(), Imm);
205}
206
207// isOpcWithIntImmediate - This method tests to see if the node is a specific
208// opcode and that it has a immediate integer right operand.
209// If so Imm will receive the 32 bit value.
210static bool isOpcWithIntImmediate(const SDNode *N, unsigned Opc,
211 uint64_t &Imm) {
212 return N->getOpcode() == Opc &&
213 isIntImmediate(N->getOperand(1).getNode(), Imm);
214}
215
216bool AArch64DAGToDAGISel::SelectInlineAsmMemoryOperand(
Daniel Sanders60f1db02015-03-13 12:45:09 +0000217 const SDValue &Op, unsigned ConstraintID, std::vector<SDValue> &OutOps) {
Daniel Sandersf731eee2015-03-23 11:33:15 +0000218 switch(ConstraintID) {
219 default:
220 llvm_unreachable("Unexpected asm memory constraint");
221 case InlineAsm::Constraint_i:
222 case InlineAsm::Constraint_m:
223 case InlineAsm::Constraint_Q:
224 // Require the address to be in a register. That is safe for all AArch64
225 // variants and it is hard to do anything much smarter without knowing
226 // how the operand is used.
227 OutOps.push_back(Op);
228 return false;
229 }
230 return true;
Tim Northover3b0846e2014-05-24 12:50:23 +0000231}
232
233/// SelectArithImmed - Select an immediate value that can be represented as
234/// a 12-bit value shifted left by either 0 or 12. If so, return true with
235/// Val set to the 12-bit value and Shift set to the shifter operand.
236bool AArch64DAGToDAGISel::SelectArithImmed(SDValue N, SDValue &Val,
237 SDValue &Shift) {
238 // This function is called from the addsub_shifted_imm ComplexPattern,
239 // which lists [imm] as the list of opcode it's interested in, however
240 // we still need to check whether the operand is actually an immediate
241 // here because the ComplexPattern opcode list is only used in
242 // root-level opcode matching.
243 if (!isa<ConstantSDNode>(N.getNode()))
244 return false;
245
246 uint64_t Immed = cast<ConstantSDNode>(N.getNode())->getZExtValue();
247 unsigned ShiftAmt;
248
249 if (Immed >> 12 == 0) {
250 ShiftAmt = 0;
251 } else if ((Immed & 0xfff) == 0 && Immed >> 24 == 0) {
252 ShiftAmt = 12;
253 Immed = Immed >> 12;
254 } else
255 return false;
256
257 unsigned ShVal = AArch64_AM::getShifterImm(AArch64_AM::LSL, ShiftAmt);
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +0000258 SDLoc dl(N);
259 Val = CurDAG->getTargetConstant(Immed, dl, MVT::i32);
260 Shift = CurDAG->getTargetConstant(ShVal, dl, MVT::i32);
Tim Northover3b0846e2014-05-24 12:50:23 +0000261 return true;
262}
263
264/// SelectNegArithImmed - As above, but negates the value before trying to
265/// select it.
266bool AArch64DAGToDAGISel::SelectNegArithImmed(SDValue N, SDValue &Val,
267 SDValue &Shift) {
268 // This function is called from the addsub_shifted_imm ComplexPattern,
269 // which lists [imm] as the list of opcode it's interested in, however
270 // we still need to check whether the operand is actually an immediate
271 // here because the ComplexPattern opcode list is only used in
272 // root-level opcode matching.
273 if (!isa<ConstantSDNode>(N.getNode()))
274 return false;
275
276 // The immediate operand must be a 24-bit zero-extended immediate.
277 uint64_t Immed = cast<ConstantSDNode>(N.getNode())->getZExtValue();
278
279 // This negation is almost always valid, but "cmp wN, #0" and "cmn wN, #0"
280 // have the opposite effect on the C flag, so this pattern mustn't match under
281 // those circumstances.
282 if (Immed == 0)
283 return false;
284
285 if (N.getValueType() == MVT::i32)
286 Immed = ~((uint32_t)Immed) + 1;
287 else
288 Immed = ~Immed + 1ULL;
289 if (Immed & 0xFFFFFFFFFF000000ULL)
290 return false;
291
292 Immed &= 0xFFFFFFULL;
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +0000293 return SelectArithImmed(CurDAG->getConstant(Immed, SDLoc(N), MVT::i32), Val,
294 Shift);
Tim Northover3b0846e2014-05-24 12:50:23 +0000295}
296
297/// getShiftTypeForNode - Translate a shift node to the corresponding
298/// ShiftType value.
299static AArch64_AM::ShiftExtendType getShiftTypeForNode(SDValue N) {
300 switch (N.getOpcode()) {
301 default:
302 return AArch64_AM::InvalidShiftExtend;
303 case ISD::SHL:
304 return AArch64_AM::LSL;
305 case ISD::SRL:
306 return AArch64_AM::LSR;
307 case ISD::SRA:
308 return AArch64_AM::ASR;
309 case ISD::ROTR:
310 return AArch64_AM::ROR;
311 }
312}
313
Eric Christopher25dbdeb2015-03-07 01:39:09 +0000314/// \brief Determine whether it is worth to fold V into an extended register.
Tim Northover3b0846e2014-05-24 12:50:23 +0000315bool AArch64DAGToDAGISel::isWorthFolding(SDValue V) const {
Robin Morisset039781e2014-08-29 21:53:01 +0000316 // it hurts if the value is used at least twice, unless we are optimizing
Tim Northover3b0846e2014-05-24 12:50:23 +0000317 // for code size.
318 if (ForCodeSize || V.hasOneUse())
319 return true;
320 return false;
321}
322
323/// SelectShiftedRegister - Select a "shifted register" operand. If the value
324/// is not shifted, set the Shift operand to default of "LSL 0". The logical
325/// instructions allow the shifted register to be rotated, but the arithmetic
326/// instructions do not. The AllowROR parameter specifies whether ROR is
327/// supported.
328bool AArch64DAGToDAGISel::SelectShiftedRegister(SDValue N, bool AllowROR,
329 SDValue &Reg, SDValue &Shift) {
330 AArch64_AM::ShiftExtendType ShType = getShiftTypeForNode(N);
331 if (ShType == AArch64_AM::InvalidShiftExtend)
332 return false;
333 if (!AllowROR && ShType == AArch64_AM::ROR)
334 return false;
335
336 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
337 unsigned BitSize = N.getValueType().getSizeInBits();
338 unsigned Val = RHS->getZExtValue() & (BitSize - 1);
339 unsigned ShVal = AArch64_AM::getShifterImm(ShType, Val);
340
341 Reg = N.getOperand(0);
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +0000342 Shift = CurDAG->getTargetConstant(ShVal, SDLoc(N), MVT::i32);
Tim Northover3b0846e2014-05-24 12:50:23 +0000343 return isWorthFolding(N);
344 }
345
346 return false;
347}
348
349/// getExtendTypeForNode - Translate an extend node to the corresponding
350/// ExtendType value.
351static AArch64_AM::ShiftExtendType
352getExtendTypeForNode(SDValue N, bool IsLoadStore = false) {
353 if (N.getOpcode() == ISD::SIGN_EXTEND ||
354 N.getOpcode() == ISD::SIGN_EXTEND_INREG) {
355 EVT SrcVT;
356 if (N.getOpcode() == ISD::SIGN_EXTEND_INREG)
357 SrcVT = cast<VTSDNode>(N.getOperand(1))->getVT();
358 else
359 SrcVT = N.getOperand(0).getValueType();
360
361 if (!IsLoadStore && SrcVT == MVT::i8)
362 return AArch64_AM::SXTB;
363 else if (!IsLoadStore && SrcVT == MVT::i16)
364 return AArch64_AM::SXTH;
365 else if (SrcVT == MVT::i32)
366 return AArch64_AM::SXTW;
367 assert(SrcVT != MVT::i64 && "extend from 64-bits?");
368
369 return AArch64_AM::InvalidShiftExtend;
370 } else if (N.getOpcode() == ISD::ZERO_EXTEND ||
371 N.getOpcode() == ISD::ANY_EXTEND) {
372 EVT SrcVT = N.getOperand(0).getValueType();
373 if (!IsLoadStore && SrcVT == MVT::i8)
374 return AArch64_AM::UXTB;
375 else if (!IsLoadStore && SrcVT == MVT::i16)
376 return AArch64_AM::UXTH;
377 else if (SrcVT == MVT::i32)
378 return AArch64_AM::UXTW;
379 assert(SrcVT != MVT::i64 && "extend from 64-bits?");
380
381 return AArch64_AM::InvalidShiftExtend;
382 } else if (N.getOpcode() == ISD::AND) {
383 ConstantSDNode *CSD = dyn_cast<ConstantSDNode>(N.getOperand(1));
384 if (!CSD)
385 return AArch64_AM::InvalidShiftExtend;
386 uint64_t AndMask = CSD->getZExtValue();
387
388 switch (AndMask) {
389 default:
390 return AArch64_AM::InvalidShiftExtend;
391 case 0xFF:
392 return !IsLoadStore ? AArch64_AM::UXTB : AArch64_AM::InvalidShiftExtend;
393 case 0xFFFF:
394 return !IsLoadStore ? AArch64_AM::UXTH : AArch64_AM::InvalidShiftExtend;
395 case 0xFFFFFFFF:
396 return AArch64_AM::UXTW;
397 }
398 }
399
400 return AArch64_AM::InvalidShiftExtend;
401}
402
403// Helper for SelectMLAV64LaneV128 - Recognize high lane extracts.
404static bool checkHighLaneIndex(SDNode *DL, SDValue &LaneOp, int &LaneIdx) {
405 if (DL->getOpcode() != AArch64ISD::DUPLANE16 &&
406 DL->getOpcode() != AArch64ISD::DUPLANE32)
407 return false;
408
409 SDValue SV = DL->getOperand(0);
410 if (SV.getOpcode() != ISD::INSERT_SUBVECTOR)
411 return false;
412
413 SDValue EV = SV.getOperand(1);
414 if (EV.getOpcode() != ISD::EXTRACT_SUBVECTOR)
415 return false;
416
417 ConstantSDNode *DLidx = cast<ConstantSDNode>(DL->getOperand(1).getNode());
418 ConstantSDNode *EVidx = cast<ConstantSDNode>(EV.getOperand(1).getNode());
419 LaneIdx = DLidx->getSExtValue() + EVidx->getSExtValue();
420 LaneOp = EV.getOperand(0);
421
422 return true;
423}
424
425// Helper for SelectOpcV64LaneV128 - Recogzine operatinos where one operand is a
426// high lane extract.
427static bool checkV64LaneV128(SDValue Op0, SDValue Op1, SDValue &StdOp,
428 SDValue &LaneOp, int &LaneIdx) {
429
430 if (!checkHighLaneIndex(Op0.getNode(), LaneOp, LaneIdx)) {
431 std::swap(Op0, Op1);
432 if (!checkHighLaneIndex(Op0.getNode(), LaneOp, LaneIdx))
433 return false;
434 }
435 StdOp = Op1;
436 return true;
437}
438
439/// SelectMLAV64LaneV128 - AArch64 supports vector MLAs where one multiplicand
440/// is a lane in the upper half of a 128-bit vector. Recognize and select this
441/// so that we don't emit unnecessary lane extracts.
442SDNode *AArch64DAGToDAGISel::SelectMLAV64LaneV128(SDNode *N) {
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +0000443 SDLoc dl(N);
Tim Northover3b0846e2014-05-24 12:50:23 +0000444 SDValue Op0 = N->getOperand(0);
445 SDValue Op1 = N->getOperand(1);
446 SDValue MLAOp1; // Will hold ordinary multiplicand for MLA.
447 SDValue MLAOp2; // Will hold lane-accessed multiplicand for MLA.
448 int LaneIdx = -1; // Will hold the lane index.
449
450 if (Op1.getOpcode() != ISD::MUL ||
451 !checkV64LaneV128(Op1.getOperand(0), Op1.getOperand(1), MLAOp1, MLAOp2,
452 LaneIdx)) {
453 std::swap(Op0, Op1);
454 if (Op1.getOpcode() != ISD::MUL ||
455 !checkV64LaneV128(Op1.getOperand(0), Op1.getOperand(1), MLAOp1, MLAOp2,
456 LaneIdx))
457 return nullptr;
458 }
459
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +0000460 SDValue LaneIdxVal = CurDAG->getTargetConstant(LaneIdx, dl, MVT::i64);
Tim Northover3b0846e2014-05-24 12:50:23 +0000461
462 SDValue Ops[] = { Op0, MLAOp1, MLAOp2, LaneIdxVal };
463
464 unsigned MLAOpc = ~0U;
465
466 switch (N->getSimpleValueType(0).SimpleTy) {
467 default:
468 llvm_unreachable("Unrecognized MLA.");
469 case MVT::v4i16:
470 MLAOpc = AArch64::MLAv4i16_indexed;
471 break;
472 case MVT::v8i16:
473 MLAOpc = AArch64::MLAv8i16_indexed;
474 break;
475 case MVT::v2i32:
476 MLAOpc = AArch64::MLAv2i32_indexed;
477 break;
478 case MVT::v4i32:
479 MLAOpc = AArch64::MLAv4i32_indexed;
480 break;
481 }
482
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +0000483 return CurDAG->getMachineNode(MLAOpc, dl, N->getValueType(0), Ops);
Tim Northover3b0846e2014-05-24 12:50:23 +0000484}
485
486SDNode *AArch64DAGToDAGISel::SelectMULLV64LaneV128(unsigned IntNo, SDNode *N) {
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +0000487 SDLoc dl(N);
Tim Northover3b0846e2014-05-24 12:50:23 +0000488 SDValue SMULLOp0;
489 SDValue SMULLOp1;
490 int LaneIdx;
491
492 if (!checkV64LaneV128(N->getOperand(1), N->getOperand(2), SMULLOp0, SMULLOp1,
493 LaneIdx))
494 return nullptr;
495
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +0000496 SDValue LaneIdxVal = CurDAG->getTargetConstant(LaneIdx, dl, MVT::i64);
Tim Northover3b0846e2014-05-24 12:50:23 +0000497
498 SDValue Ops[] = { SMULLOp0, SMULLOp1, LaneIdxVal };
499
500 unsigned SMULLOpc = ~0U;
501
502 if (IntNo == Intrinsic::aarch64_neon_smull) {
503 switch (N->getSimpleValueType(0).SimpleTy) {
504 default:
505 llvm_unreachable("Unrecognized SMULL.");
506 case MVT::v4i32:
507 SMULLOpc = AArch64::SMULLv4i16_indexed;
508 break;
509 case MVT::v2i64:
510 SMULLOpc = AArch64::SMULLv2i32_indexed;
511 break;
512 }
513 } else if (IntNo == Intrinsic::aarch64_neon_umull) {
514 switch (N->getSimpleValueType(0).SimpleTy) {
515 default:
516 llvm_unreachable("Unrecognized SMULL.");
517 case MVT::v4i32:
518 SMULLOpc = AArch64::UMULLv4i16_indexed;
519 break;
520 case MVT::v2i64:
521 SMULLOpc = AArch64::UMULLv2i32_indexed;
522 break;
523 }
524 } else
525 llvm_unreachable("Unrecognized intrinsic.");
526
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +0000527 return CurDAG->getMachineNode(SMULLOpc, dl, N->getValueType(0), Ops);
Tim Northover3b0846e2014-05-24 12:50:23 +0000528}
529
530/// Instructions that accept extend modifiers like UXTW expect the register
531/// being extended to be a GPR32, but the incoming DAG might be acting on a
532/// GPR64 (either via SEXT_INREG or AND). Extract the appropriate low bits if
533/// this is the case.
534static SDValue narrowIfNeeded(SelectionDAG *CurDAG, SDValue N) {
535 if (N.getValueType() == MVT::i32)
536 return N;
537
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +0000538 SDLoc dl(N);
539 SDValue SubReg = CurDAG->getTargetConstant(AArch64::sub_32, dl, MVT::i32);
Tim Northover3b0846e2014-05-24 12:50:23 +0000540 MachineSDNode *Node = CurDAG->getMachineNode(TargetOpcode::EXTRACT_SUBREG,
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +0000541 dl, MVT::i32, N, SubReg);
Tim Northover3b0846e2014-05-24 12:50:23 +0000542 return SDValue(Node, 0);
543}
544
545
546/// SelectArithExtendedRegister - Select a "extended register" operand. This
547/// operand folds in an extend followed by an optional left shift.
548bool AArch64DAGToDAGISel::SelectArithExtendedRegister(SDValue N, SDValue &Reg,
549 SDValue &Shift) {
550 unsigned ShiftVal = 0;
551 AArch64_AM::ShiftExtendType Ext;
552
553 if (N.getOpcode() == ISD::SHL) {
554 ConstantSDNode *CSD = dyn_cast<ConstantSDNode>(N.getOperand(1));
555 if (!CSD)
556 return false;
557 ShiftVal = CSD->getZExtValue();
558 if (ShiftVal > 4)
559 return false;
560
561 Ext = getExtendTypeForNode(N.getOperand(0));
562 if (Ext == AArch64_AM::InvalidShiftExtend)
563 return false;
564
565 Reg = N.getOperand(0).getOperand(0);
566 } else {
567 Ext = getExtendTypeForNode(N);
568 if (Ext == AArch64_AM::InvalidShiftExtend)
569 return false;
570
571 Reg = N.getOperand(0);
572 }
573
574 // AArch64 mandates that the RHS of the operation must use the smallest
575 // register classs that could contain the size being extended from. Thus,
576 // if we're folding a (sext i8), we need the RHS to be a GPR32, even though
577 // there might not be an actual 32-bit value in the program. We can
578 // (harmlessly) synthesize one by injected an EXTRACT_SUBREG here.
579 assert(Ext != AArch64_AM::UXTX && Ext != AArch64_AM::SXTX);
580 Reg = narrowIfNeeded(CurDAG, Reg);
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +0000581 Shift = CurDAG->getTargetConstant(getArithExtendImm(Ext, ShiftVal), SDLoc(N),
582 MVT::i32);
Tim Northover3b0846e2014-05-24 12:50:23 +0000583 return isWorthFolding(N);
584}
585
Tim Northoverec7ebeb2014-12-02 23:13:39 +0000586/// If there's a use of this ADDlow that's not itself a load/store then we'll
587/// need to create a real ADD instruction from it anyway and there's no point in
588/// folding it into the mem op. Theoretically, it shouldn't matter, but there's
589/// a single pseudo-instruction for an ADRP/ADD pair so over-aggressive folding
590/// leads to duplaicated ADRP instructions.
591static bool isWorthFoldingADDlow(SDValue N) {
592 for (auto Use : N->uses()) {
593 if (Use->getOpcode() != ISD::LOAD && Use->getOpcode() != ISD::STORE &&
594 Use->getOpcode() != ISD::ATOMIC_LOAD &&
595 Use->getOpcode() != ISD::ATOMIC_STORE)
596 return false;
597
598 // ldar and stlr have much more restrictive addressing modes (just a
599 // register).
600 if (cast<MemSDNode>(Use)->getOrdering() > Monotonic)
601 return false;
602 }
603
604 return true;
605}
606
Tim Northover3b0846e2014-05-24 12:50:23 +0000607/// SelectAddrModeIndexed - Select a "register plus scaled unsigned 12-bit
608/// immediate" address. The "Size" argument is the size in bytes of the memory
609/// reference, which determines the scale.
610bool AArch64DAGToDAGISel::SelectAddrModeIndexed(SDValue N, unsigned Size,
611 SDValue &Base, SDValue &OffImm) {
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +0000612 SDLoc dl(N);
Mehdi Amini44ede332015-07-09 02:09:04 +0000613 const DataLayout &DL = CurDAG->getDataLayout();
Tim Northover3b0846e2014-05-24 12:50:23 +0000614 const TargetLowering *TLI = getTargetLowering();
615 if (N.getOpcode() == ISD::FrameIndex) {
616 int FI = cast<FrameIndexSDNode>(N)->getIndex();
Mehdi Amini44ede332015-07-09 02:09:04 +0000617 Base = CurDAG->getTargetFrameIndex(FI, TLI->getPointerTy(DL));
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +0000618 OffImm = CurDAG->getTargetConstant(0, dl, MVT::i64);
Tim Northover3b0846e2014-05-24 12:50:23 +0000619 return true;
620 }
621
Tim Northoverec7ebeb2014-12-02 23:13:39 +0000622 if (N.getOpcode() == AArch64ISD::ADDlow && isWorthFoldingADDlow(N)) {
Tim Northover3b0846e2014-05-24 12:50:23 +0000623 GlobalAddressSDNode *GAN =
624 dyn_cast<GlobalAddressSDNode>(N.getOperand(1).getNode());
625 Base = N.getOperand(0);
626 OffImm = N.getOperand(1);
627 if (!GAN)
628 return true;
629
630 const GlobalValue *GV = GAN->getGlobal();
631 unsigned Alignment = GV->getAlignment();
Chad Rosier304fe3f2014-06-30 15:03:00 +0000632 Type *Ty = GV->getType()->getElementType();
Tim Northover4a8ac262014-12-02 23:53:43 +0000633 if (Alignment == 0 && Ty->isSized())
Mehdi Amini44ede332015-07-09 02:09:04 +0000634 Alignment = DL.getABITypeAlignment(Ty);
Tim Northover3b0846e2014-05-24 12:50:23 +0000635
636 if (Alignment >= Size)
637 return true;
638 }
639
640 if (CurDAG->isBaseWithConstantOffset(N)) {
641 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
642 int64_t RHSC = (int64_t)RHS->getZExtValue();
643 unsigned Scale = Log2_32(Size);
644 if ((RHSC & (Size - 1)) == 0 && RHSC >= 0 && RHSC < (0x1000 << Scale)) {
645 Base = N.getOperand(0);
646 if (Base.getOpcode() == ISD::FrameIndex) {
647 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
Mehdi Amini44ede332015-07-09 02:09:04 +0000648 Base = CurDAG->getTargetFrameIndex(FI, TLI->getPointerTy(DL));
Tim Northover3b0846e2014-05-24 12:50:23 +0000649 }
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +0000650 OffImm = CurDAG->getTargetConstant(RHSC >> Scale, dl, MVT::i64);
Tim Northover3b0846e2014-05-24 12:50:23 +0000651 return true;
652 }
653 }
654 }
655
656 // Before falling back to our general case, check if the unscaled
657 // instructions can handle this. If so, that's preferable.
658 if (SelectAddrModeUnscaled(N, Size, Base, OffImm))
659 return false;
660
661 // Base only. The address will be materialized into a register before
662 // the memory is accessed.
663 // add x0, Xbase, #offset
664 // ldr x0, [x0]
665 Base = N;
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +0000666 OffImm = CurDAG->getTargetConstant(0, dl, MVT::i64);
Tim Northover3b0846e2014-05-24 12:50:23 +0000667 return true;
668}
669
670/// SelectAddrModeUnscaled - Select a "register plus unscaled signed 9-bit
671/// immediate" address. This should only match when there is an offset that
672/// is not valid for a scaled immediate addressing mode. The "Size" argument
673/// is the size in bytes of the memory reference, which is needed here to know
674/// what is valid for a scaled immediate.
675bool AArch64DAGToDAGISel::SelectAddrModeUnscaled(SDValue N, unsigned Size,
676 SDValue &Base,
677 SDValue &OffImm) {
678 if (!CurDAG->isBaseWithConstantOffset(N))
679 return false;
680 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
681 int64_t RHSC = RHS->getSExtValue();
682 // If the offset is valid as a scaled immediate, don't match here.
683 if ((RHSC & (Size - 1)) == 0 && RHSC >= 0 &&
684 RHSC < (0x1000 << Log2_32(Size)))
685 return false;
686 if (RHSC >= -256 && RHSC < 256) {
687 Base = N.getOperand(0);
688 if (Base.getOpcode() == ISD::FrameIndex) {
689 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
690 const TargetLowering *TLI = getTargetLowering();
Mehdi Amini44ede332015-07-09 02:09:04 +0000691 Base = CurDAG->getTargetFrameIndex(
692 FI, TLI->getPointerTy(CurDAG->getDataLayout()));
Tim Northover3b0846e2014-05-24 12:50:23 +0000693 }
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +0000694 OffImm = CurDAG->getTargetConstant(RHSC, SDLoc(N), MVT::i64);
Tim Northover3b0846e2014-05-24 12:50:23 +0000695 return true;
696 }
697 }
698 return false;
699}
700
701static SDValue Widen(SelectionDAG *CurDAG, SDValue N) {
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +0000702 SDLoc dl(N);
703 SDValue SubReg = CurDAG->getTargetConstant(AArch64::sub_32, dl, MVT::i32);
Tim Northover3b0846e2014-05-24 12:50:23 +0000704 SDValue ImpDef = SDValue(
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +0000705 CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, MVT::i64), 0);
Tim Northover3b0846e2014-05-24 12:50:23 +0000706 MachineSDNode *Node = CurDAG->getMachineNode(
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +0000707 TargetOpcode::INSERT_SUBREG, dl, MVT::i64, ImpDef, N, SubReg);
Tim Northover3b0846e2014-05-24 12:50:23 +0000708 return SDValue(Node, 0);
709}
710
711/// \brief Check if the given SHL node (\p N), can be used to form an
712/// extended register for an addressing mode.
713bool AArch64DAGToDAGISel::SelectExtendedSHL(SDValue N, unsigned Size,
714 bool WantExtend, SDValue &Offset,
715 SDValue &SignExtend) {
716 assert(N.getOpcode() == ISD::SHL && "Invalid opcode.");
717 ConstantSDNode *CSD = dyn_cast<ConstantSDNode>(N.getOperand(1));
718 if (!CSD || (CSD->getZExtValue() & 0x7) != CSD->getZExtValue())
719 return false;
720
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +0000721 SDLoc dl(N);
Tim Northover3b0846e2014-05-24 12:50:23 +0000722 if (WantExtend) {
723 AArch64_AM::ShiftExtendType Ext =
724 getExtendTypeForNode(N.getOperand(0), true);
725 if (Ext == AArch64_AM::InvalidShiftExtend)
726 return false;
727
728 Offset = narrowIfNeeded(CurDAG, N.getOperand(0).getOperand(0));
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +0000729 SignExtend = CurDAG->getTargetConstant(Ext == AArch64_AM::SXTW, dl,
730 MVT::i32);
Tim Northover3b0846e2014-05-24 12:50:23 +0000731 } else {
732 Offset = N.getOperand(0);
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +0000733 SignExtend = CurDAG->getTargetConstant(0, dl, MVT::i32);
Tim Northover3b0846e2014-05-24 12:50:23 +0000734 }
735
736 unsigned LegalShiftVal = Log2_32(Size);
737 unsigned ShiftVal = CSD->getZExtValue();
738
739 if (ShiftVal != 0 && ShiftVal != LegalShiftVal)
740 return false;
741
742 if (isWorthFolding(N))
743 return true;
744
745 return false;
746}
747
748bool AArch64DAGToDAGISel::SelectAddrModeWRO(SDValue N, unsigned Size,
749 SDValue &Base, SDValue &Offset,
750 SDValue &SignExtend,
751 SDValue &DoShift) {
752 if (N.getOpcode() != ISD::ADD)
753 return false;
754 SDValue LHS = N.getOperand(0);
755 SDValue RHS = N.getOperand(1);
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +0000756 SDLoc dl(N);
Tim Northover3b0846e2014-05-24 12:50:23 +0000757
758 // We don't want to match immediate adds here, because they are better lowered
759 // to the register-immediate addressing modes.
760 if (isa<ConstantSDNode>(LHS) || isa<ConstantSDNode>(RHS))
761 return false;
762
763 // Check if this particular node is reused in any non-memory related
764 // operation. If yes, do not try to fold this node into the address
765 // computation, since the computation will be kept.
766 const SDNode *Node = N.getNode();
767 for (SDNode *UI : Node->uses()) {
768 if (!isa<MemSDNode>(*UI))
769 return false;
770 }
771
772 // Remember if it is worth folding N when it produces extended register.
773 bool IsExtendedRegisterWorthFolding = isWorthFolding(N);
774
775 // Try to match a shifted extend on the RHS.
776 if (IsExtendedRegisterWorthFolding && RHS.getOpcode() == ISD::SHL &&
777 SelectExtendedSHL(RHS, Size, true, Offset, SignExtend)) {
778 Base = LHS;
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +0000779 DoShift = CurDAG->getTargetConstant(true, dl, MVT::i32);
Tim Northover3b0846e2014-05-24 12:50:23 +0000780 return true;
781 }
782
783 // Try to match a shifted extend on the LHS.
784 if (IsExtendedRegisterWorthFolding && LHS.getOpcode() == ISD::SHL &&
785 SelectExtendedSHL(LHS, Size, true, Offset, SignExtend)) {
786 Base = RHS;
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +0000787 DoShift = CurDAG->getTargetConstant(true, dl, MVT::i32);
Tim Northover3b0846e2014-05-24 12:50:23 +0000788 return true;
789 }
790
791 // There was no shift, whatever else we find.
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +0000792 DoShift = CurDAG->getTargetConstant(false, dl, MVT::i32);
Tim Northover3b0846e2014-05-24 12:50:23 +0000793
794 AArch64_AM::ShiftExtendType Ext = AArch64_AM::InvalidShiftExtend;
795 // Try to match an unshifted extend on the LHS.
796 if (IsExtendedRegisterWorthFolding &&
797 (Ext = getExtendTypeForNode(LHS, true)) !=
798 AArch64_AM::InvalidShiftExtend) {
799 Base = RHS;
800 Offset = narrowIfNeeded(CurDAG, LHS.getOperand(0));
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +0000801 SignExtend = CurDAG->getTargetConstant(Ext == AArch64_AM::SXTW, dl,
802 MVT::i32);
Tim Northover3b0846e2014-05-24 12:50:23 +0000803 if (isWorthFolding(LHS))
804 return true;
805 }
806
807 // Try to match an unshifted extend on the RHS.
808 if (IsExtendedRegisterWorthFolding &&
809 (Ext = getExtendTypeForNode(RHS, true)) !=
810 AArch64_AM::InvalidShiftExtend) {
811 Base = LHS;
812 Offset = narrowIfNeeded(CurDAG, RHS.getOperand(0));
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +0000813 SignExtend = CurDAG->getTargetConstant(Ext == AArch64_AM::SXTW, dl,
814 MVT::i32);
Tim Northover3b0846e2014-05-24 12:50:23 +0000815 if (isWorthFolding(RHS))
816 return true;
817 }
818
819 return false;
820}
821
Hao Liu3cb826c2014-10-14 06:50:36 +0000822// Check if the given immediate is preferred by ADD. If an immediate can be
823// encoded in an ADD, or it can be encoded in an "ADD LSL #12" and can not be
824// encoded by one MOVZ, return true.
825static bool isPreferredADD(int64_t ImmOff) {
826 // Constant in [0x0, 0xfff] can be encoded in ADD.
827 if ((ImmOff & 0xfffffffffffff000LL) == 0x0LL)
828 return true;
829 // Check if it can be encoded in an "ADD LSL #12".
830 if ((ImmOff & 0xffffffffff000fffLL) == 0x0LL)
831 // As a single MOVZ is faster than a "ADD of LSL #12", ignore such constant.
832 return (ImmOff & 0xffffffffff00ffffLL) != 0x0LL &&
833 (ImmOff & 0xffffffffffff0fffLL) != 0x0LL;
834 return false;
835}
836
Tim Northover3b0846e2014-05-24 12:50:23 +0000837bool AArch64DAGToDAGISel::SelectAddrModeXRO(SDValue N, unsigned Size,
838 SDValue &Base, SDValue &Offset,
839 SDValue &SignExtend,
840 SDValue &DoShift) {
841 if (N.getOpcode() != ISD::ADD)
842 return false;
843 SDValue LHS = N.getOperand(0);
844 SDValue RHS = N.getOperand(1);
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +0000845 SDLoc DL(N);
Tim Northover3b0846e2014-05-24 12:50:23 +0000846
Tim Northover3b0846e2014-05-24 12:50:23 +0000847 // Check if this particular node is reused in any non-memory related
848 // operation. If yes, do not try to fold this node into the address
849 // computation, since the computation will be kept.
850 const SDNode *Node = N.getNode();
851 for (SDNode *UI : Node->uses()) {
852 if (!isa<MemSDNode>(*UI))
853 return false;
854 }
855
Hao Liu3cb826c2014-10-14 06:50:36 +0000856 // Watch out if RHS is a wide immediate, it can not be selected into
857 // [BaseReg+Imm] addressing mode. Also it may not be able to be encoded into
858 // ADD/SUB. Instead it will use [BaseReg + 0] address mode and generate
859 // instructions like:
860 // MOV X0, WideImmediate
861 // ADD X1, BaseReg, X0
862 // LDR X2, [X1, 0]
863 // For such situation, using [BaseReg, XReg] addressing mode can save one
864 // ADD/SUB:
865 // MOV X0, WideImmediate
866 // LDR X2, [BaseReg, X0]
867 if (isa<ConstantSDNode>(RHS)) {
Benjamin Kramer619c4e52015-04-10 11:24:51 +0000868 int64_t ImmOff = (int64_t)cast<ConstantSDNode>(RHS)->getZExtValue();
Hao Liu3cb826c2014-10-14 06:50:36 +0000869 unsigned Scale = Log2_32(Size);
870 // Skip the immediate can be seleced by load/store addressing mode.
871 // Also skip the immediate can be encoded by a single ADD (SUB is also
872 // checked by using -ImmOff).
873 if ((ImmOff % Size == 0 && ImmOff >= 0 && ImmOff < (0x1000 << Scale)) ||
874 isPreferredADD(ImmOff) || isPreferredADD(-ImmOff))
875 return false;
876
Hao Liu3cb826c2014-10-14 06:50:36 +0000877 SDValue Ops[] = { RHS };
878 SDNode *MOVI =
879 CurDAG->getMachineNode(AArch64::MOVi64imm, DL, MVT::i64, Ops);
880 SDValue MOVIV = SDValue(MOVI, 0);
881 // This ADD of two X register will be selected into [Reg+Reg] mode.
882 N = CurDAG->getNode(ISD::ADD, DL, MVT::i64, LHS, MOVIV);
883 }
884
Tim Northover3b0846e2014-05-24 12:50:23 +0000885 // Remember if it is worth folding N when it produces extended register.
886 bool IsExtendedRegisterWorthFolding = isWorthFolding(N);
887
888 // Try to match a shifted extend on the RHS.
889 if (IsExtendedRegisterWorthFolding && RHS.getOpcode() == ISD::SHL &&
890 SelectExtendedSHL(RHS, Size, false, Offset, SignExtend)) {
891 Base = LHS;
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +0000892 DoShift = CurDAG->getTargetConstant(true, DL, MVT::i32);
Tim Northover3b0846e2014-05-24 12:50:23 +0000893 return true;
894 }
895
896 // Try to match a shifted extend on the LHS.
897 if (IsExtendedRegisterWorthFolding && LHS.getOpcode() == ISD::SHL &&
898 SelectExtendedSHL(LHS, Size, false, Offset, SignExtend)) {
899 Base = RHS;
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +0000900 DoShift = CurDAG->getTargetConstant(true, DL, MVT::i32);
Tim Northover3b0846e2014-05-24 12:50:23 +0000901 return true;
902 }
903
904 // Match any non-shifted, non-extend, non-immediate add expression.
905 Base = LHS;
906 Offset = RHS;
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +0000907 SignExtend = CurDAG->getTargetConstant(false, DL, MVT::i32);
908 DoShift = CurDAG->getTargetConstant(false, DL, MVT::i32);
Tim Northover3b0846e2014-05-24 12:50:23 +0000909 // Reg1 + Reg2 is free: no check needed.
910 return true;
911}
912
913SDValue AArch64DAGToDAGISel::createDTuple(ArrayRef<SDValue> Regs) {
Benjamin Kramerea68a942015-02-19 15:26:17 +0000914 static const unsigned RegClassIDs[] = {
Tim Northover3b0846e2014-05-24 12:50:23 +0000915 AArch64::DDRegClassID, AArch64::DDDRegClassID, AArch64::DDDDRegClassID};
Benjamin Kramerea68a942015-02-19 15:26:17 +0000916 static const unsigned SubRegs[] = {AArch64::dsub0, AArch64::dsub1,
917 AArch64::dsub2, AArch64::dsub3};
Tim Northover3b0846e2014-05-24 12:50:23 +0000918
919 return createTuple(Regs, RegClassIDs, SubRegs);
920}
921
922SDValue AArch64DAGToDAGISel::createQTuple(ArrayRef<SDValue> Regs) {
Benjamin Kramerea68a942015-02-19 15:26:17 +0000923 static const unsigned RegClassIDs[] = {
Tim Northover3b0846e2014-05-24 12:50:23 +0000924 AArch64::QQRegClassID, AArch64::QQQRegClassID, AArch64::QQQQRegClassID};
Benjamin Kramerea68a942015-02-19 15:26:17 +0000925 static const unsigned SubRegs[] = {AArch64::qsub0, AArch64::qsub1,
926 AArch64::qsub2, AArch64::qsub3};
Tim Northover3b0846e2014-05-24 12:50:23 +0000927
928 return createTuple(Regs, RegClassIDs, SubRegs);
929}
930
931SDValue AArch64DAGToDAGISel::createTuple(ArrayRef<SDValue> Regs,
Benjamin Kramerea68a942015-02-19 15:26:17 +0000932 const unsigned RegClassIDs[],
933 const unsigned SubRegs[]) {
Tim Northover3b0846e2014-05-24 12:50:23 +0000934 // There's no special register-class for a vector-list of 1 element: it's just
935 // a vector.
936 if (Regs.size() == 1)
937 return Regs[0];
938
939 assert(Regs.size() >= 2 && Regs.size() <= 4);
940
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +0000941 SDLoc DL(Regs[0]);
Tim Northover3b0846e2014-05-24 12:50:23 +0000942
943 SmallVector<SDValue, 4> Ops;
944
945 // First operand of REG_SEQUENCE is the desired RegClass.
946 Ops.push_back(
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +0000947 CurDAG->getTargetConstant(RegClassIDs[Regs.size() - 2], DL, MVT::i32));
Tim Northover3b0846e2014-05-24 12:50:23 +0000948
949 // Then we get pairs of source & subregister-position for the components.
950 for (unsigned i = 0; i < Regs.size(); ++i) {
951 Ops.push_back(Regs[i]);
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +0000952 Ops.push_back(CurDAG->getTargetConstant(SubRegs[i], DL, MVT::i32));
Tim Northover3b0846e2014-05-24 12:50:23 +0000953 }
954
955 SDNode *N =
956 CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, DL, MVT::Untyped, Ops);
957 return SDValue(N, 0);
958}
959
960SDNode *AArch64DAGToDAGISel::SelectTable(SDNode *N, unsigned NumVecs,
961 unsigned Opc, bool isExt) {
962 SDLoc dl(N);
963 EVT VT = N->getValueType(0);
964
965 unsigned ExtOff = isExt;
966
967 // Form a REG_SEQUENCE to force register allocation.
968 unsigned Vec0Off = ExtOff + 1;
969 SmallVector<SDValue, 4> Regs(N->op_begin() + Vec0Off,
970 N->op_begin() + Vec0Off + NumVecs);
971 SDValue RegSeq = createQTuple(Regs);
972
973 SmallVector<SDValue, 6> Ops;
974 if (isExt)
975 Ops.push_back(N->getOperand(1));
976 Ops.push_back(RegSeq);
977 Ops.push_back(N->getOperand(NumVecs + ExtOff + 1));
978 return CurDAG->getMachineNode(Opc, dl, VT, Ops);
979}
980
981SDNode *AArch64DAGToDAGISel::SelectIndexedLoad(SDNode *N, bool &Done) {
982 LoadSDNode *LD = cast<LoadSDNode>(N);
983 if (LD->isUnindexed())
984 return nullptr;
985 EVT VT = LD->getMemoryVT();
986 EVT DstVT = N->getValueType(0);
987 ISD::MemIndexedMode AM = LD->getAddressingMode();
988 bool IsPre = AM == ISD::PRE_INC || AM == ISD::PRE_DEC;
989
990 // We're not doing validity checking here. That was done when checking
991 // if we should mark the load as indexed or not. We're just selecting
992 // the right instruction.
993 unsigned Opcode = 0;
994
995 ISD::LoadExtType ExtType = LD->getExtensionType();
996 bool InsertTo64 = false;
997 if (VT == MVT::i64)
998 Opcode = IsPre ? AArch64::LDRXpre : AArch64::LDRXpost;
999 else if (VT == MVT::i32) {
1000 if (ExtType == ISD::NON_EXTLOAD)
1001 Opcode = IsPre ? AArch64::LDRWpre : AArch64::LDRWpost;
1002 else if (ExtType == ISD::SEXTLOAD)
1003 Opcode = IsPre ? AArch64::LDRSWpre : AArch64::LDRSWpost;
1004 else {
1005 Opcode = IsPre ? AArch64::LDRWpre : AArch64::LDRWpost;
1006 InsertTo64 = true;
1007 // The result of the load is only i32. It's the subreg_to_reg that makes
1008 // it into an i64.
1009 DstVT = MVT::i32;
1010 }
1011 } else if (VT == MVT::i16) {
1012 if (ExtType == ISD::SEXTLOAD) {
1013 if (DstVT == MVT::i64)
1014 Opcode = IsPre ? AArch64::LDRSHXpre : AArch64::LDRSHXpost;
1015 else
1016 Opcode = IsPre ? AArch64::LDRSHWpre : AArch64::LDRSHWpost;
1017 } else {
1018 Opcode = IsPre ? AArch64::LDRHHpre : AArch64::LDRHHpost;
1019 InsertTo64 = DstVT == MVT::i64;
1020 // The result of the load is only i32. It's the subreg_to_reg that makes
1021 // it into an i64.
1022 DstVT = MVT::i32;
1023 }
1024 } else if (VT == MVT::i8) {
1025 if (ExtType == ISD::SEXTLOAD) {
1026 if (DstVT == MVT::i64)
1027 Opcode = IsPre ? AArch64::LDRSBXpre : AArch64::LDRSBXpost;
1028 else
1029 Opcode = IsPre ? AArch64::LDRSBWpre : AArch64::LDRSBWpost;
1030 } else {
1031 Opcode = IsPre ? AArch64::LDRBBpre : AArch64::LDRBBpost;
1032 InsertTo64 = DstVT == MVT::i64;
1033 // The result of the load is only i32. It's the subreg_to_reg that makes
1034 // it into an i64.
1035 DstVT = MVT::i32;
1036 }
1037 } else if (VT == MVT::f32) {
1038 Opcode = IsPre ? AArch64::LDRSpre : AArch64::LDRSpost;
1039 } else if (VT == MVT::f64 || VT.is64BitVector()) {
1040 Opcode = IsPre ? AArch64::LDRDpre : AArch64::LDRDpost;
1041 } else if (VT.is128BitVector()) {
1042 Opcode = IsPre ? AArch64::LDRQpre : AArch64::LDRQpost;
1043 } else
1044 return nullptr;
1045 SDValue Chain = LD->getChain();
1046 SDValue Base = LD->getBasePtr();
1047 ConstantSDNode *OffsetOp = cast<ConstantSDNode>(LD->getOffset());
1048 int OffsetVal = (int)OffsetOp->getZExtValue();
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +00001049 SDLoc dl(N);
1050 SDValue Offset = CurDAG->getTargetConstant(OffsetVal, dl, MVT::i64);
Tim Northover3b0846e2014-05-24 12:50:23 +00001051 SDValue Ops[] = { Base, Offset, Chain };
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +00001052 SDNode *Res = CurDAG->getMachineNode(Opcode, dl, MVT::i64, DstVT,
Tim Northover3b0846e2014-05-24 12:50:23 +00001053 MVT::Other, Ops);
1054 // Either way, we're replacing the node, so tell the caller that.
1055 Done = true;
1056 SDValue LoadedVal = SDValue(Res, 1);
1057 if (InsertTo64) {
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +00001058 SDValue SubReg = CurDAG->getTargetConstant(AArch64::sub_32, dl, MVT::i32);
Tim Northover3b0846e2014-05-24 12:50:23 +00001059 LoadedVal =
1060 SDValue(CurDAG->getMachineNode(
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +00001061 AArch64::SUBREG_TO_REG, dl, MVT::i64,
1062 CurDAG->getTargetConstant(0, dl, MVT::i64), LoadedVal,
1063 SubReg),
Tim Northover3b0846e2014-05-24 12:50:23 +00001064 0);
1065 }
1066
1067 ReplaceUses(SDValue(N, 0), LoadedVal);
1068 ReplaceUses(SDValue(N, 1), SDValue(Res, 0));
1069 ReplaceUses(SDValue(N, 2), SDValue(Res, 2));
1070
1071 return nullptr;
1072}
1073
1074SDNode *AArch64DAGToDAGISel::SelectLoad(SDNode *N, unsigned NumVecs,
1075 unsigned Opc, unsigned SubRegIdx) {
1076 SDLoc dl(N);
1077 EVT VT = N->getValueType(0);
1078 SDValue Chain = N->getOperand(0);
1079
Benjamin Kramerea68a942015-02-19 15:26:17 +00001080 SDValue Ops[] = {N->getOperand(2), // Mem operand;
1081 Chain};
Tim Northover3b0846e2014-05-24 12:50:23 +00001082
Benjamin Kramer867bfc52015-03-07 17:41:00 +00001083 const EVT ResTys[] = {MVT::Untyped, MVT::Other};
Tim Northover3b0846e2014-05-24 12:50:23 +00001084
1085 SDNode *Ld = CurDAG->getMachineNode(Opc, dl, ResTys, Ops);
1086 SDValue SuperReg = SDValue(Ld, 0);
1087 for (unsigned i = 0; i < NumVecs; ++i)
1088 ReplaceUses(SDValue(N, i),
1089 CurDAG->getTargetExtractSubreg(SubRegIdx + i, dl, VT, SuperReg));
1090
1091 ReplaceUses(SDValue(N, NumVecs), SDValue(Ld, 1));
1092 return nullptr;
1093}
1094
1095SDNode *AArch64DAGToDAGISel::SelectPostLoad(SDNode *N, unsigned NumVecs,
1096 unsigned Opc, unsigned SubRegIdx) {
1097 SDLoc dl(N);
1098 EVT VT = N->getValueType(0);
1099 SDValue Chain = N->getOperand(0);
1100
Benjamin Kramerea68a942015-02-19 15:26:17 +00001101 SDValue Ops[] = {N->getOperand(1), // Mem operand
1102 N->getOperand(2), // Incremental
1103 Chain};
Tim Northover3b0846e2014-05-24 12:50:23 +00001104
Benjamin Kramer867bfc52015-03-07 17:41:00 +00001105 const EVT ResTys[] = {MVT::i64, // Type of the write back register
1106 MVT::Untyped, MVT::Other};
Tim Northover3b0846e2014-05-24 12:50:23 +00001107
1108 SDNode *Ld = CurDAG->getMachineNode(Opc, dl, ResTys, Ops);
1109
1110 // Update uses of write back register
1111 ReplaceUses(SDValue(N, NumVecs), SDValue(Ld, 0));
1112
1113 // Update uses of vector list
1114 SDValue SuperReg = SDValue(Ld, 1);
1115 if (NumVecs == 1)
1116 ReplaceUses(SDValue(N, 0), SuperReg);
1117 else
1118 for (unsigned i = 0; i < NumVecs; ++i)
1119 ReplaceUses(SDValue(N, i),
1120 CurDAG->getTargetExtractSubreg(SubRegIdx + i, dl, VT, SuperReg));
1121
1122 // Update the chain
1123 ReplaceUses(SDValue(N, NumVecs + 1), SDValue(Ld, 2));
1124 return nullptr;
1125}
1126
1127SDNode *AArch64DAGToDAGISel::SelectStore(SDNode *N, unsigned NumVecs,
1128 unsigned Opc) {
1129 SDLoc dl(N);
1130 EVT VT = N->getOperand(2)->getValueType(0);
1131
1132 // Form a REG_SEQUENCE to force register allocation.
1133 bool Is128Bit = VT.getSizeInBits() == 128;
1134 SmallVector<SDValue, 4> Regs(N->op_begin() + 2, N->op_begin() + 2 + NumVecs);
1135 SDValue RegSeq = Is128Bit ? createQTuple(Regs) : createDTuple(Regs);
1136
Benjamin Kramerea68a942015-02-19 15:26:17 +00001137 SDValue Ops[] = {RegSeq, N->getOperand(NumVecs + 2), N->getOperand(0)};
Tim Northover3b0846e2014-05-24 12:50:23 +00001138 SDNode *St = CurDAG->getMachineNode(Opc, dl, N->getValueType(0), Ops);
1139
1140 return St;
1141}
1142
1143SDNode *AArch64DAGToDAGISel::SelectPostStore(SDNode *N, unsigned NumVecs,
1144 unsigned Opc) {
1145 SDLoc dl(N);
1146 EVT VT = N->getOperand(2)->getValueType(0);
Benjamin Kramer867bfc52015-03-07 17:41:00 +00001147 const EVT ResTys[] = {MVT::i64, // Type of the write back register
1148 MVT::Other}; // Type for the Chain
Tim Northover3b0846e2014-05-24 12:50:23 +00001149
1150 // Form a REG_SEQUENCE to force register allocation.
1151 bool Is128Bit = VT.getSizeInBits() == 128;
1152 SmallVector<SDValue, 4> Regs(N->op_begin() + 1, N->op_begin() + 1 + NumVecs);
1153 SDValue RegSeq = Is128Bit ? createQTuple(Regs) : createDTuple(Regs);
1154
Benjamin Kramerea68a942015-02-19 15:26:17 +00001155 SDValue Ops[] = {RegSeq,
1156 N->getOperand(NumVecs + 1), // base register
1157 N->getOperand(NumVecs + 2), // Incremental
1158 N->getOperand(0)}; // Chain
Tim Northover3b0846e2014-05-24 12:50:23 +00001159 SDNode *St = CurDAG->getMachineNode(Opc, dl, ResTys, Ops);
1160
1161 return St;
1162}
1163
Benjamin Kramer51f6096c2015-03-23 12:30:58 +00001164namespace {
Tim Northover3b0846e2014-05-24 12:50:23 +00001165/// WidenVector - Given a value in the V64 register class, produce the
1166/// equivalent value in the V128 register class.
1167class WidenVector {
1168 SelectionDAG &DAG;
1169
1170public:
1171 WidenVector(SelectionDAG &DAG) : DAG(DAG) {}
1172
1173 SDValue operator()(SDValue V64Reg) {
1174 EVT VT = V64Reg.getValueType();
1175 unsigned NarrowSize = VT.getVectorNumElements();
1176 MVT EltTy = VT.getVectorElementType().getSimpleVT();
1177 MVT WideTy = MVT::getVectorVT(EltTy, 2 * NarrowSize);
1178 SDLoc DL(V64Reg);
1179
1180 SDValue Undef =
1181 SDValue(DAG.getMachineNode(TargetOpcode::IMPLICIT_DEF, DL, WideTy), 0);
1182 return DAG.getTargetInsertSubreg(AArch64::dsub, DL, WideTy, Undef, V64Reg);
1183 }
1184};
Benjamin Kramer51f6096c2015-03-23 12:30:58 +00001185} // namespace
Tim Northover3b0846e2014-05-24 12:50:23 +00001186
1187/// NarrowVector - Given a value in the V128 register class, produce the
1188/// equivalent value in the V64 register class.
1189static SDValue NarrowVector(SDValue V128Reg, SelectionDAG &DAG) {
1190 EVT VT = V128Reg.getValueType();
1191 unsigned WideSize = VT.getVectorNumElements();
1192 MVT EltTy = VT.getVectorElementType().getSimpleVT();
1193 MVT NarrowTy = MVT::getVectorVT(EltTy, WideSize / 2);
1194
1195 return DAG.getTargetExtractSubreg(AArch64::dsub, SDLoc(V128Reg), NarrowTy,
1196 V128Reg);
1197}
1198
1199SDNode *AArch64DAGToDAGISel::SelectLoadLane(SDNode *N, unsigned NumVecs,
1200 unsigned Opc) {
1201 SDLoc dl(N);
1202 EVT VT = N->getValueType(0);
1203 bool Narrow = VT.getSizeInBits() == 64;
1204
1205 // Form a REG_SEQUENCE to force register allocation.
1206 SmallVector<SDValue, 4> Regs(N->op_begin() + 2, N->op_begin() + 2 + NumVecs);
1207
1208 if (Narrow)
1209 std::transform(Regs.begin(), Regs.end(), Regs.begin(),
1210 WidenVector(*CurDAG));
1211
1212 SDValue RegSeq = createQTuple(Regs);
1213
Benjamin Kramer867bfc52015-03-07 17:41:00 +00001214 const EVT ResTys[] = {MVT::Untyped, MVT::Other};
Tim Northover3b0846e2014-05-24 12:50:23 +00001215
1216 unsigned LaneNo =
1217 cast<ConstantSDNode>(N->getOperand(NumVecs + 2))->getZExtValue();
1218
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +00001219 SDValue Ops[] = {RegSeq, CurDAG->getTargetConstant(LaneNo, dl, MVT::i64),
Benjamin Kramerea68a942015-02-19 15:26:17 +00001220 N->getOperand(NumVecs + 3), N->getOperand(0)};
Tim Northover3b0846e2014-05-24 12:50:23 +00001221 SDNode *Ld = CurDAG->getMachineNode(Opc, dl, ResTys, Ops);
1222 SDValue SuperReg = SDValue(Ld, 0);
1223
1224 EVT WideVT = RegSeq.getOperand(1)->getValueType(0);
1225 static unsigned QSubs[] = { AArch64::qsub0, AArch64::qsub1, AArch64::qsub2,
1226 AArch64::qsub3 };
1227 for (unsigned i = 0; i < NumVecs; ++i) {
1228 SDValue NV = CurDAG->getTargetExtractSubreg(QSubs[i], dl, WideVT, SuperReg);
1229 if (Narrow)
1230 NV = NarrowVector(NV, *CurDAG);
1231 ReplaceUses(SDValue(N, i), NV);
1232 }
1233
1234 ReplaceUses(SDValue(N, NumVecs), SDValue(Ld, 1));
1235
1236 return Ld;
1237}
1238
1239SDNode *AArch64DAGToDAGISel::SelectPostLoadLane(SDNode *N, unsigned NumVecs,
1240 unsigned Opc) {
1241 SDLoc dl(N);
1242 EVT VT = N->getValueType(0);
1243 bool Narrow = VT.getSizeInBits() == 64;
1244
1245 // Form a REG_SEQUENCE to force register allocation.
1246 SmallVector<SDValue, 4> Regs(N->op_begin() + 1, N->op_begin() + 1 + NumVecs);
1247
1248 if (Narrow)
1249 std::transform(Regs.begin(), Regs.end(), Regs.begin(),
1250 WidenVector(*CurDAG));
1251
1252 SDValue RegSeq = createQTuple(Regs);
1253
Benjamin Kramer867bfc52015-03-07 17:41:00 +00001254 const EVT ResTys[] = {MVT::i64, // Type of the write back register
Ahmed Bougachae14a4d42015-04-17 23:43:33 +00001255 RegSeq->getValueType(0), MVT::Other};
Tim Northover3b0846e2014-05-24 12:50:23 +00001256
1257 unsigned LaneNo =
1258 cast<ConstantSDNode>(N->getOperand(NumVecs + 1))->getZExtValue();
1259
Benjamin Kramerea68a942015-02-19 15:26:17 +00001260 SDValue Ops[] = {RegSeq,
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +00001261 CurDAG->getTargetConstant(LaneNo, dl,
1262 MVT::i64), // Lane Number
Benjamin Kramerea68a942015-02-19 15:26:17 +00001263 N->getOperand(NumVecs + 2), // Base register
1264 N->getOperand(NumVecs + 3), // Incremental
1265 N->getOperand(0)};
Tim Northover3b0846e2014-05-24 12:50:23 +00001266 SDNode *Ld = CurDAG->getMachineNode(Opc, dl, ResTys, Ops);
1267
1268 // Update uses of the write back register
1269 ReplaceUses(SDValue(N, NumVecs), SDValue(Ld, 0));
1270
1271 // Update uses of the vector list
1272 SDValue SuperReg = SDValue(Ld, 1);
1273 if (NumVecs == 1) {
1274 ReplaceUses(SDValue(N, 0),
1275 Narrow ? NarrowVector(SuperReg, *CurDAG) : SuperReg);
1276 } else {
1277 EVT WideVT = RegSeq.getOperand(1)->getValueType(0);
1278 static unsigned QSubs[] = { AArch64::qsub0, AArch64::qsub1, AArch64::qsub2,
1279 AArch64::qsub3 };
1280 for (unsigned i = 0; i < NumVecs; ++i) {
1281 SDValue NV = CurDAG->getTargetExtractSubreg(QSubs[i], dl, WideVT,
1282 SuperReg);
1283 if (Narrow)
1284 NV = NarrowVector(NV, *CurDAG);
1285 ReplaceUses(SDValue(N, i), NV);
1286 }
1287 }
1288
1289 // Update the Chain
1290 ReplaceUses(SDValue(N, NumVecs + 1), SDValue(Ld, 2));
1291
1292 return Ld;
1293}
1294
1295SDNode *AArch64DAGToDAGISel::SelectStoreLane(SDNode *N, unsigned NumVecs,
1296 unsigned Opc) {
1297 SDLoc dl(N);
1298 EVT VT = N->getOperand(2)->getValueType(0);
1299 bool Narrow = VT.getSizeInBits() == 64;
1300
1301 // Form a REG_SEQUENCE to force register allocation.
1302 SmallVector<SDValue, 4> Regs(N->op_begin() + 2, N->op_begin() + 2 + NumVecs);
1303
1304 if (Narrow)
1305 std::transform(Regs.begin(), Regs.end(), Regs.begin(),
1306 WidenVector(*CurDAG));
1307
1308 SDValue RegSeq = createQTuple(Regs);
1309
1310 unsigned LaneNo =
1311 cast<ConstantSDNode>(N->getOperand(NumVecs + 2))->getZExtValue();
1312
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +00001313 SDValue Ops[] = {RegSeq, CurDAG->getTargetConstant(LaneNo, dl, MVT::i64),
Benjamin Kramerea68a942015-02-19 15:26:17 +00001314 N->getOperand(NumVecs + 3), N->getOperand(0)};
Tim Northover3b0846e2014-05-24 12:50:23 +00001315 SDNode *St = CurDAG->getMachineNode(Opc, dl, MVT::Other, Ops);
1316
1317 // Transfer memoperands.
1318 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
1319 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
1320 cast<MachineSDNode>(St)->setMemRefs(MemOp, MemOp + 1);
1321
1322 return St;
1323}
1324
1325SDNode *AArch64DAGToDAGISel::SelectPostStoreLane(SDNode *N, unsigned NumVecs,
1326 unsigned Opc) {
1327 SDLoc dl(N);
1328 EVT VT = N->getOperand(2)->getValueType(0);
1329 bool Narrow = VT.getSizeInBits() == 64;
1330
1331 // Form a REG_SEQUENCE to force register allocation.
1332 SmallVector<SDValue, 4> Regs(N->op_begin() + 1, N->op_begin() + 1 + NumVecs);
1333
1334 if (Narrow)
1335 std::transform(Regs.begin(), Regs.end(), Regs.begin(),
1336 WidenVector(*CurDAG));
1337
1338 SDValue RegSeq = createQTuple(Regs);
1339
Benjamin Kramer867bfc52015-03-07 17:41:00 +00001340 const EVT ResTys[] = {MVT::i64, // Type of the write back register
1341 MVT::Other};
Tim Northover3b0846e2014-05-24 12:50:23 +00001342
1343 unsigned LaneNo =
1344 cast<ConstantSDNode>(N->getOperand(NumVecs + 1))->getZExtValue();
1345
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +00001346 SDValue Ops[] = {RegSeq, CurDAG->getTargetConstant(LaneNo, dl, MVT::i64),
Benjamin Kramerea68a942015-02-19 15:26:17 +00001347 N->getOperand(NumVecs + 2), // Base Register
1348 N->getOperand(NumVecs + 3), // Incremental
1349 N->getOperand(0)};
Tim Northover3b0846e2014-05-24 12:50:23 +00001350 SDNode *St = CurDAG->getMachineNode(Opc, dl, ResTys, Ops);
1351
1352 // Transfer memoperands.
1353 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
1354 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
1355 cast<MachineSDNode>(St)->setMemRefs(MemOp, MemOp + 1);
1356
1357 return St;
1358}
1359
1360static bool isBitfieldExtractOpFromAnd(SelectionDAG *CurDAG, SDNode *N,
1361 unsigned &Opc, SDValue &Opd0,
1362 unsigned &LSB, unsigned &MSB,
1363 unsigned NumberOfIgnoredLowBits,
1364 bool BiggerPattern) {
1365 assert(N->getOpcode() == ISD::AND &&
1366 "N must be a AND operation to call this function");
1367
1368 EVT VT = N->getValueType(0);
1369
1370 // Here we can test the type of VT and return false when the type does not
1371 // match, but since it is done prior to that call in the current context
1372 // we turned that into an assert to avoid redundant code.
1373 assert((VT == MVT::i32 || VT == MVT::i64) &&
1374 "Type checking must have been done before calling this function");
1375
1376 // FIXME: simplify-demanded-bits in DAGCombine will probably have
1377 // changed the AND node to a 32-bit mask operation. We'll have to
1378 // undo that as part of the transform here if we want to catch all
1379 // the opportunities.
1380 // Currently the NumberOfIgnoredLowBits argument helps to recover
1381 // form these situations when matching bigger pattern (bitfield insert).
1382
1383 // For unsigned extracts, check for a shift right and mask
1384 uint64_t And_imm = 0;
1385 if (!isOpcWithIntImmediate(N, ISD::AND, And_imm))
1386 return false;
1387
1388 const SDNode *Op0 = N->getOperand(0).getNode();
1389
1390 // Because of simplify-demanded-bits in DAGCombine, the mask may have been
1391 // simplified. Try to undo that
1392 And_imm |= (1 << NumberOfIgnoredLowBits) - 1;
1393
1394 // The immediate is a mask of the low bits iff imm & (imm+1) == 0
1395 if (And_imm & (And_imm + 1))
1396 return false;
1397
1398 bool ClampMSB = false;
1399 uint64_t Srl_imm = 0;
1400 // Handle the SRL + ANY_EXTEND case.
1401 if (VT == MVT::i64 && Op0->getOpcode() == ISD::ANY_EXTEND &&
1402 isOpcWithIntImmediate(Op0->getOperand(0).getNode(), ISD::SRL, Srl_imm)) {
1403 // Extend the incoming operand of the SRL to 64-bit.
1404 Opd0 = Widen(CurDAG, Op0->getOperand(0).getOperand(0));
1405 // Make sure to clamp the MSB so that we preserve the semantics of the
1406 // original operations.
1407 ClampMSB = true;
1408 } else if (VT == MVT::i32 && Op0->getOpcode() == ISD::TRUNCATE &&
1409 isOpcWithIntImmediate(Op0->getOperand(0).getNode(), ISD::SRL,
1410 Srl_imm)) {
1411 // If the shift result was truncated, we can still combine them.
1412 Opd0 = Op0->getOperand(0).getOperand(0);
1413
1414 // Use the type of SRL node.
1415 VT = Opd0->getValueType(0);
1416 } else if (isOpcWithIntImmediate(Op0, ISD::SRL, Srl_imm)) {
1417 Opd0 = Op0->getOperand(0);
1418 } else if (BiggerPattern) {
1419 // Let's pretend a 0 shift right has been performed.
1420 // The resulting code will be at least as good as the original one
1421 // plus it may expose more opportunities for bitfield insert pattern.
1422 // FIXME: Currently we limit this to the bigger pattern, because
1423 // some optimizations expect AND and not UBFM
1424 Opd0 = N->getOperand(0);
1425 } else
1426 return false;
1427
Matthias Braun75260352015-02-24 18:52:04 +00001428 // Bail out on large immediates. This happens when no proper
1429 // combining/constant folding was performed.
Matthias Braun02892ec2015-02-25 18:03:50 +00001430 if (!BiggerPattern && (Srl_imm <= 0 || Srl_imm >= VT.getSizeInBits())) {
1431 DEBUG((dbgs() << N
1432 << ": Found large shift immediate, this should not happen\n"));
Matthias Braun75260352015-02-24 18:52:04 +00001433 return false;
Matthias Braun02892ec2015-02-25 18:03:50 +00001434 }
Tim Northover3b0846e2014-05-24 12:50:23 +00001435
1436 LSB = Srl_imm;
Benjamin Kramer5f6a9072015-02-12 15:35:40 +00001437 MSB = Srl_imm + (VT == MVT::i32 ? countTrailingOnes<uint32_t>(And_imm)
1438 : countTrailingOnes<uint64_t>(And_imm)) -
Tim Northover3b0846e2014-05-24 12:50:23 +00001439 1;
1440 if (ClampMSB)
1441 // Since we're moving the extend before the right shift operation, we need
1442 // to clamp the MSB to make sure we don't shift in undefined bits instead of
1443 // the zeros which would get shifted in with the original right shift
1444 // operation.
1445 MSB = MSB > 31 ? 31 : MSB;
1446
1447 Opc = VT == MVT::i32 ? AArch64::UBFMWri : AArch64::UBFMXri;
1448 return true;
1449}
1450
David Xu052b9d92014-09-02 09:33:56 +00001451static bool isSeveralBitsExtractOpFromShr(SDNode *N, unsigned &Opc,
1452 SDValue &Opd0, unsigned &LSB,
1453 unsigned &MSB) {
1454 // We are looking for the following pattern which basically extracts several
1455 // continuous bits from the source value and places it from the LSB of the
1456 // destination value, all other bits of the destination value or set to zero:
Tim Northover3b0846e2014-05-24 12:50:23 +00001457 //
1458 // Value2 = AND Value, MaskImm
1459 // SRL Value2, ShiftImm
1460 //
David Xu052b9d92014-09-02 09:33:56 +00001461 // with MaskImm >> ShiftImm to search for the bit width.
Tim Northover3b0846e2014-05-24 12:50:23 +00001462 //
1463 // This gets selected into a single UBFM:
1464 //
David Xu052b9d92014-09-02 09:33:56 +00001465 // UBFM Value, ShiftImm, BitWide + Srl_imm -1
Tim Northover3b0846e2014-05-24 12:50:23 +00001466 //
1467
1468 if (N->getOpcode() != ISD::SRL)
1469 return false;
1470
1471 uint64_t And_mask = 0;
1472 if (!isOpcWithIntImmediate(N->getOperand(0).getNode(), ISD::AND, And_mask))
1473 return false;
1474
1475 Opd0 = N->getOperand(0).getOperand(0);
1476
1477 uint64_t Srl_imm = 0;
1478 if (!isIntImmediate(N->getOperand(1), Srl_imm))
1479 return false;
1480
David Xu052b9d92014-09-02 09:33:56 +00001481 // Check whether we really have several bits extract here.
Benjamin Kramer5f6a9072015-02-12 15:35:40 +00001482 unsigned BitWide = 64 - countLeadingOnes(~(And_mask >> Srl_imm));
David Xu052b9d92014-09-02 09:33:56 +00001483 if (BitWide && isMask_64(And_mask >> Srl_imm)) {
Tim Northover3b0846e2014-05-24 12:50:23 +00001484 if (N->getValueType(0) == MVT::i32)
1485 Opc = AArch64::UBFMWri;
1486 else
1487 Opc = AArch64::UBFMXri;
1488
David Xu052b9d92014-09-02 09:33:56 +00001489 LSB = Srl_imm;
1490 MSB = BitWide + Srl_imm - 1;
Tim Northover3b0846e2014-05-24 12:50:23 +00001491 return true;
1492 }
1493
1494 return false;
1495}
1496
1497static bool isBitfieldExtractOpFromShr(SDNode *N, unsigned &Opc, SDValue &Opd0,
1498 unsigned &LSB, unsigned &MSB,
1499 bool BiggerPattern) {
1500 assert((N->getOpcode() == ISD::SRA || N->getOpcode() == ISD::SRL) &&
1501 "N must be a SHR/SRA operation to call this function");
1502
1503 EVT VT = N->getValueType(0);
1504
1505 // Here we can test the type of VT and return false when the type does not
1506 // match, but since it is done prior to that call in the current context
1507 // we turned that into an assert to avoid redundant code.
1508 assert((VT == MVT::i32 || VT == MVT::i64) &&
1509 "Type checking must have been done before calling this function");
1510
David Xu052b9d92014-09-02 09:33:56 +00001511 // Check for AND + SRL doing several bits extract.
1512 if (isSeveralBitsExtractOpFromShr(N, Opc, Opd0, LSB, MSB))
Tim Northover3b0846e2014-05-24 12:50:23 +00001513 return true;
1514
1515 // we're looking for a shift of a shift
1516 uint64_t Shl_imm = 0;
1517 uint64_t Trunc_bits = 0;
1518 if (isOpcWithIntImmediate(N->getOperand(0).getNode(), ISD::SHL, Shl_imm)) {
1519 Opd0 = N->getOperand(0).getOperand(0);
1520 } else if (VT == MVT::i32 && N->getOpcode() == ISD::SRL &&
1521 N->getOperand(0).getNode()->getOpcode() == ISD::TRUNCATE) {
1522 // We are looking for a shift of truncate. Truncate from i64 to i32 could
1523 // be considered as setting high 32 bits as zero. Our strategy here is to
1524 // always generate 64bit UBFM. This consistency will help the CSE pass
1525 // later find more redundancy.
1526 Opd0 = N->getOperand(0).getOperand(0);
1527 Trunc_bits = Opd0->getValueType(0).getSizeInBits() - VT.getSizeInBits();
1528 VT = Opd0->getValueType(0);
1529 assert(VT == MVT::i64 && "the promoted type should be i64");
1530 } else if (BiggerPattern) {
1531 // Let's pretend a 0 shift left has been performed.
1532 // FIXME: Currently we limit this to the bigger pattern case,
1533 // because some optimizations expect AND and not UBFM
1534 Opd0 = N->getOperand(0);
1535 } else
1536 return false;
1537
Matthias Braun75260352015-02-24 18:52:04 +00001538 // Missing combines/constant folding may have left us with strange
1539 // constants.
Matthias Braun02892ec2015-02-25 18:03:50 +00001540 if (Shl_imm >= VT.getSizeInBits()) {
1541 DEBUG((dbgs() << N
1542 << ": Found large shift immediate, this should not happen\n"));
Matthias Braun75260352015-02-24 18:52:04 +00001543 return false;
Matthias Braun02892ec2015-02-25 18:03:50 +00001544 }
Matthias Braun75260352015-02-24 18:52:04 +00001545
Tim Northover3b0846e2014-05-24 12:50:23 +00001546 uint64_t Srl_imm = 0;
1547 if (!isIntImmediate(N->getOperand(1), Srl_imm))
1548 return false;
1549
1550 assert(Srl_imm > 0 && Srl_imm < VT.getSizeInBits() &&
1551 "bad amount in shift node!");
1552 // Note: The width operand is encoded as width-1.
1553 unsigned Width = VT.getSizeInBits() - Trunc_bits - Srl_imm - 1;
1554 int sLSB = Srl_imm - Shl_imm;
1555 if (sLSB < 0)
1556 return false;
1557 LSB = sLSB;
1558 MSB = LSB + Width;
1559 // SRA requires a signed extraction
1560 if (VT == MVT::i32)
1561 Opc = N->getOpcode() == ISD::SRA ? AArch64::SBFMWri : AArch64::UBFMWri;
1562 else
1563 Opc = N->getOpcode() == ISD::SRA ? AArch64::SBFMXri : AArch64::UBFMXri;
1564 return true;
1565}
1566
1567static bool isBitfieldExtractOp(SelectionDAG *CurDAG, SDNode *N, unsigned &Opc,
1568 SDValue &Opd0, unsigned &LSB, unsigned &MSB,
1569 unsigned NumberOfIgnoredLowBits = 0,
1570 bool BiggerPattern = false) {
1571 if (N->getValueType(0) != MVT::i32 && N->getValueType(0) != MVT::i64)
1572 return false;
1573
1574 switch (N->getOpcode()) {
1575 default:
1576 if (!N->isMachineOpcode())
1577 return false;
1578 break;
1579 case ISD::AND:
1580 return isBitfieldExtractOpFromAnd(CurDAG, N, Opc, Opd0, LSB, MSB,
1581 NumberOfIgnoredLowBits, BiggerPattern);
1582 case ISD::SRL:
1583 case ISD::SRA:
1584 return isBitfieldExtractOpFromShr(N, Opc, Opd0, LSB, MSB, BiggerPattern);
1585 }
1586
1587 unsigned NOpc = N->getMachineOpcode();
1588 switch (NOpc) {
1589 default:
1590 return false;
1591 case AArch64::SBFMWri:
1592 case AArch64::UBFMWri:
1593 case AArch64::SBFMXri:
1594 case AArch64::UBFMXri:
1595 Opc = NOpc;
1596 Opd0 = N->getOperand(0);
1597 LSB = cast<ConstantSDNode>(N->getOperand(1).getNode())->getZExtValue();
1598 MSB = cast<ConstantSDNode>(N->getOperand(2).getNode())->getZExtValue();
1599 return true;
1600 }
1601 // Unreachable
1602 return false;
1603}
1604
1605SDNode *AArch64DAGToDAGISel::SelectBitfieldExtractOp(SDNode *N) {
1606 unsigned Opc, LSB, MSB;
1607 SDValue Opd0;
1608 if (!isBitfieldExtractOp(CurDAG, N, Opc, Opd0, LSB, MSB))
1609 return nullptr;
1610
1611 EVT VT = N->getValueType(0);
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +00001612 SDLoc dl(N);
Tim Northover3b0846e2014-05-24 12:50:23 +00001613
1614 // If the bit extract operation is 64bit but the original type is 32bit, we
1615 // need to add one EXTRACT_SUBREG.
1616 if ((Opc == AArch64::SBFMXri || Opc == AArch64::UBFMXri) && VT == MVT::i32) {
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +00001617 SDValue Ops64[] = {Opd0, CurDAG->getTargetConstant(LSB, dl, MVT::i64),
1618 CurDAG->getTargetConstant(MSB, dl, MVT::i64)};
Tim Northover3b0846e2014-05-24 12:50:23 +00001619
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +00001620 SDNode *BFM = CurDAG->getMachineNode(Opc, dl, MVT::i64, Ops64);
1621 SDValue SubReg = CurDAG->getTargetConstant(AArch64::sub_32, dl, MVT::i32);
Tim Northover3b0846e2014-05-24 12:50:23 +00001622 MachineSDNode *Node =
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +00001623 CurDAG->getMachineNode(TargetOpcode::EXTRACT_SUBREG, dl, MVT::i32,
Tim Northover3b0846e2014-05-24 12:50:23 +00001624 SDValue(BFM, 0), SubReg);
1625 return Node;
1626 }
1627
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +00001628 SDValue Ops[] = {Opd0, CurDAG->getTargetConstant(LSB, dl, VT),
1629 CurDAG->getTargetConstant(MSB, dl, VT)};
Tim Northover3b0846e2014-05-24 12:50:23 +00001630 return CurDAG->SelectNodeTo(N, Opc, VT, Ops);
1631}
1632
1633/// Does DstMask form a complementary pair with the mask provided by
1634/// BitsToBeInserted, suitable for use in a BFI instruction. Roughly speaking,
1635/// this asks whether DstMask zeroes precisely those bits that will be set by
1636/// the other half.
1637static bool isBitfieldDstMask(uint64_t DstMask, APInt BitsToBeInserted,
1638 unsigned NumberOfIgnoredHighBits, EVT VT) {
1639 assert((VT == MVT::i32 || VT == MVT::i64) &&
1640 "i32 or i64 mask type expected!");
1641 unsigned BitWidth = VT.getSizeInBits() - NumberOfIgnoredHighBits;
1642
1643 APInt SignificantDstMask = APInt(BitWidth, DstMask);
1644 APInt SignificantBitsToBeInserted = BitsToBeInserted.zextOrTrunc(BitWidth);
1645
1646 return (SignificantDstMask & SignificantBitsToBeInserted) == 0 &&
1647 (SignificantDstMask | SignificantBitsToBeInserted).isAllOnesValue();
1648}
1649
1650// Look for bits that will be useful for later uses.
1651// A bit is consider useless as soon as it is dropped and never used
1652// before it as been dropped.
1653// E.g., looking for useful bit of x
1654// 1. y = x & 0x7
1655// 2. z = y >> 2
1656// After #1, x useful bits are 0x7, then the useful bits of x, live through
1657// y.
1658// After #2, the useful bits of x are 0x4.
1659// However, if x is used on an unpredicatable instruction, then all its bits
1660// are useful.
1661// E.g.
1662// 1. y = x & 0x7
1663// 2. z = y >> 2
1664// 3. str x, [@x]
1665static void getUsefulBits(SDValue Op, APInt &UsefulBits, unsigned Depth = 0);
1666
1667static void getUsefulBitsFromAndWithImmediate(SDValue Op, APInt &UsefulBits,
1668 unsigned Depth) {
1669 uint64_t Imm =
1670 cast<const ConstantSDNode>(Op.getOperand(1).getNode())->getZExtValue();
1671 Imm = AArch64_AM::decodeLogicalImmediate(Imm, UsefulBits.getBitWidth());
1672 UsefulBits &= APInt(UsefulBits.getBitWidth(), Imm);
1673 getUsefulBits(Op, UsefulBits, Depth + 1);
1674}
1675
1676static void getUsefulBitsFromBitfieldMoveOpd(SDValue Op, APInt &UsefulBits,
1677 uint64_t Imm, uint64_t MSB,
1678 unsigned Depth) {
1679 // inherit the bitwidth value
1680 APInt OpUsefulBits(UsefulBits);
1681 OpUsefulBits = 1;
1682
1683 if (MSB >= Imm) {
1684 OpUsefulBits = OpUsefulBits.shl(MSB - Imm + 1);
1685 --OpUsefulBits;
1686 // The interesting part will be in the lower part of the result
1687 getUsefulBits(Op, OpUsefulBits, Depth + 1);
1688 // The interesting part was starting at Imm in the argument
1689 OpUsefulBits = OpUsefulBits.shl(Imm);
1690 } else {
1691 OpUsefulBits = OpUsefulBits.shl(MSB + 1);
1692 --OpUsefulBits;
1693 // The interesting part will be shifted in the result
1694 OpUsefulBits = OpUsefulBits.shl(OpUsefulBits.getBitWidth() - Imm);
1695 getUsefulBits(Op, OpUsefulBits, Depth + 1);
1696 // The interesting part was at zero in the argument
1697 OpUsefulBits = OpUsefulBits.lshr(OpUsefulBits.getBitWidth() - Imm);
1698 }
1699
1700 UsefulBits &= OpUsefulBits;
1701}
1702
1703static void getUsefulBitsFromUBFM(SDValue Op, APInt &UsefulBits,
1704 unsigned Depth) {
1705 uint64_t Imm =
1706 cast<const ConstantSDNode>(Op.getOperand(1).getNode())->getZExtValue();
1707 uint64_t MSB =
1708 cast<const ConstantSDNode>(Op.getOperand(2).getNode())->getZExtValue();
1709
1710 getUsefulBitsFromBitfieldMoveOpd(Op, UsefulBits, Imm, MSB, Depth);
1711}
1712
1713static void getUsefulBitsFromOrWithShiftedReg(SDValue Op, APInt &UsefulBits,
1714 unsigned Depth) {
1715 uint64_t ShiftTypeAndValue =
1716 cast<const ConstantSDNode>(Op.getOperand(2).getNode())->getZExtValue();
1717 APInt Mask(UsefulBits);
1718 Mask.clearAllBits();
1719 Mask.flipAllBits();
1720
1721 if (AArch64_AM::getShiftType(ShiftTypeAndValue) == AArch64_AM::LSL) {
1722 // Shift Left
1723 uint64_t ShiftAmt = AArch64_AM::getShiftValue(ShiftTypeAndValue);
1724 Mask = Mask.shl(ShiftAmt);
1725 getUsefulBits(Op, Mask, Depth + 1);
1726 Mask = Mask.lshr(ShiftAmt);
1727 } else if (AArch64_AM::getShiftType(ShiftTypeAndValue) == AArch64_AM::LSR) {
1728 // Shift Right
1729 // We do not handle AArch64_AM::ASR, because the sign will change the
1730 // number of useful bits
1731 uint64_t ShiftAmt = AArch64_AM::getShiftValue(ShiftTypeAndValue);
1732 Mask = Mask.lshr(ShiftAmt);
1733 getUsefulBits(Op, Mask, Depth + 1);
1734 Mask = Mask.shl(ShiftAmt);
1735 } else
1736 return;
1737
1738 UsefulBits &= Mask;
1739}
1740
1741static void getUsefulBitsFromBFM(SDValue Op, SDValue Orig, APInt &UsefulBits,
1742 unsigned Depth) {
1743 uint64_t Imm =
1744 cast<const ConstantSDNode>(Op.getOperand(2).getNode())->getZExtValue();
1745 uint64_t MSB =
1746 cast<const ConstantSDNode>(Op.getOperand(3).getNode())->getZExtValue();
1747
1748 if (Op.getOperand(1) == Orig)
1749 return getUsefulBitsFromBitfieldMoveOpd(Op, UsefulBits, Imm, MSB, Depth);
1750
1751 APInt OpUsefulBits(UsefulBits);
1752 OpUsefulBits = 1;
1753
1754 if (MSB >= Imm) {
1755 OpUsefulBits = OpUsefulBits.shl(MSB - Imm + 1);
1756 --OpUsefulBits;
1757 UsefulBits &= ~OpUsefulBits;
1758 getUsefulBits(Op, UsefulBits, Depth + 1);
1759 } else {
1760 OpUsefulBits = OpUsefulBits.shl(MSB + 1);
1761 --OpUsefulBits;
1762 UsefulBits = ~(OpUsefulBits.shl(OpUsefulBits.getBitWidth() - Imm));
1763 getUsefulBits(Op, UsefulBits, Depth + 1);
1764 }
1765}
1766
1767static void getUsefulBitsForUse(SDNode *UserNode, APInt &UsefulBits,
1768 SDValue Orig, unsigned Depth) {
1769
1770 // Users of this node should have already been instruction selected
1771 // FIXME: Can we turn that into an assert?
1772 if (!UserNode->isMachineOpcode())
1773 return;
1774
1775 switch (UserNode->getMachineOpcode()) {
1776 default:
1777 return;
1778 case AArch64::ANDSWri:
1779 case AArch64::ANDSXri:
1780 case AArch64::ANDWri:
1781 case AArch64::ANDXri:
1782 // We increment Depth only when we call the getUsefulBits
1783 return getUsefulBitsFromAndWithImmediate(SDValue(UserNode, 0), UsefulBits,
1784 Depth);
1785 case AArch64::UBFMWri:
1786 case AArch64::UBFMXri:
1787 return getUsefulBitsFromUBFM(SDValue(UserNode, 0), UsefulBits, Depth);
1788
1789 case AArch64::ORRWrs:
1790 case AArch64::ORRXrs:
1791 if (UserNode->getOperand(1) != Orig)
1792 return;
1793 return getUsefulBitsFromOrWithShiftedReg(SDValue(UserNode, 0), UsefulBits,
1794 Depth);
1795 case AArch64::BFMWri:
1796 case AArch64::BFMXri:
1797 return getUsefulBitsFromBFM(SDValue(UserNode, 0), Orig, UsefulBits, Depth);
1798 }
1799}
1800
1801static void getUsefulBits(SDValue Op, APInt &UsefulBits, unsigned Depth) {
1802 if (Depth >= 6)
1803 return;
1804 // Initialize UsefulBits
1805 if (!Depth) {
1806 unsigned Bitwidth = Op.getValueType().getScalarType().getSizeInBits();
1807 // At the beginning, assume every produced bits is useful
1808 UsefulBits = APInt(Bitwidth, 0);
1809 UsefulBits.flipAllBits();
1810 }
1811 APInt UsersUsefulBits(UsefulBits.getBitWidth(), 0);
1812
1813 for (SDNode *Node : Op.getNode()->uses()) {
1814 // A use cannot produce useful bits
1815 APInt UsefulBitsForUse = APInt(UsefulBits);
1816 getUsefulBitsForUse(Node, UsefulBitsForUse, Op, Depth);
1817 UsersUsefulBits |= UsefulBitsForUse;
1818 }
1819 // UsefulBits contains the produced bits that are meaningful for the
1820 // current definition, thus a user cannot make a bit meaningful at
1821 // this point
1822 UsefulBits &= UsersUsefulBits;
1823}
1824
1825/// Create a machine node performing a notional SHL of Op by ShlAmount. If
1826/// ShlAmount is negative, do a (logical) right-shift instead. If ShlAmount is
1827/// 0, return Op unchanged.
1828static SDValue getLeftShift(SelectionDAG *CurDAG, SDValue Op, int ShlAmount) {
1829 if (ShlAmount == 0)
1830 return Op;
1831
1832 EVT VT = Op.getValueType();
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +00001833 SDLoc dl(Op);
Tim Northover3b0846e2014-05-24 12:50:23 +00001834 unsigned BitWidth = VT.getSizeInBits();
1835 unsigned UBFMOpc = BitWidth == 32 ? AArch64::UBFMWri : AArch64::UBFMXri;
1836
1837 SDNode *ShiftNode;
1838 if (ShlAmount > 0) {
1839 // LSL wD, wN, #Amt == UBFM wD, wN, #32-Amt, #31-Amt
1840 ShiftNode = CurDAG->getMachineNode(
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +00001841 UBFMOpc, dl, VT, Op,
1842 CurDAG->getTargetConstant(BitWidth - ShlAmount, dl, VT),
1843 CurDAG->getTargetConstant(BitWidth - 1 - ShlAmount, dl, VT));
Tim Northover3b0846e2014-05-24 12:50:23 +00001844 } else {
1845 // LSR wD, wN, #Amt == UBFM wD, wN, #Amt, #32-1
1846 assert(ShlAmount < 0 && "expected right shift");
1847 int ShrAmount = -ShlAmount;
1848 ShiftNode = CurDAG->getMachineNode(
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +00001849 UBFMOpc, dl, VT, Op, CurDAG->getTargetConstant(ShrAmount, dl, VT),
1850 CurDAG->getTargetConstant(BitWidth - 1, dl, VT));
Tim Northover3b0846e2014-05-24 12:50:23 +00001851 }
1852
1853 return SDValue(ShiftNode, 0);
1854}
1855
1856/// Does this tree qualify as an attempt to move a bitfield into position,
1857/// essentially "(and (shl VAL, N), Mask)".
1858static bool isBitfieldPositioningOp(SelectionDAG *CurDAG, SDValue Op,
1859 SDValue &Src, int &ShiftAmount,
1860 int &MaskWidth) {
1861 EVT VT = Op.getValueType();
1862 unsigned BitWidth = VT.getSizeInBits();
1863 (void)BitWidth;
1864 assert(BitWidth == 32 || BitWidth == 64);
1865
1866 APInt KnownZero, KnownOne;
1867 CurDAG->computeKnownBits(Op, KnownZero, KnownOne);
1868
1869 // Non-zero in the sense that they're not provably zero, which is the key
1870 // point if we want to use this value
1871 uint64_t NonZeroBits = (~KnownZero).getZExtValue();
1872
1873 // Discard a constant AND mask if present. It's safe because the node will
1874 // already have been factored into the computeKnownBits calculation above.
1875 uint64_t AndImm;
1876 if (isOpcWithIntImmediate(Op.getNode(), ISD::AND, AndImm)) {
1877 assert((~APInt(BitWidth, AndImm) & ~KnownZero) == 0);
1878 Op = Op.getOperand(0);
1879 }
1880
1881 uint64_t ShlImm;
1882 if (!isOpcWithIntImmediate(Op.getNode(), ISD::SHL, ShlImm))
1883 return false;
1884 Op = Op.getOperand(0);
1885
1886 if (!isShiftedMask_64(NonZeroBits))
1887 return false;
1888
1889 ShiftAmount = countTrailingZeros(NonZeroBits);
Benjamin Kramer5f6a9072015-02-12 15:35:40 +00001890 MaskWidth = countTrailingOnes(NonZeroBits >> ShiftAmount);
Tim Northover3b0846e2014-05-24 12:50:23 +00001891
1892 // BFI encompasses sufficiently many nodes that it's worth inserting an extra
1893 // LSL/LSR if the mask in NonZeroBits doesn't quite match up with the ISD::SHL
1894 // amount.
1895 Src = getLeftShift(CurDAG, Op, ShlImm - ShiftAmount);
1896
1897 return true;
1898}
1899
1900// Given a OR operation, check if we have the following pattern
1901// ubfm c, b, imm, imm2 (or something that does the same jobs, see
1902// isBitfieldExtractOp)
1903// d = e & mask2 ; where mask is a binary sequence of 1..10..0 and
1904// countTrailingZeros(mask2) == imm2 - imm + 1
1905// f = d | c
1906// if yes, given reference arguments will be update so that one can replace
1907// the OR instruction with:
1908// f = Opc Opd0, Opd1, LSB, MSB ; where Opc is a BFM, LSB = imm, and MSB = imm2
1909static bool isBitfieldInsertOpFromOr(SDNode *N, unsigned &Opc, SDValue &Dst,
1910 SDValue &Src, unsigned &ImmR,
1911 unsigned &ImmS, SelectionDAG *CurDAG) {
1912 assert(N->getOpcode() == ISD::OR && "Expect a OR operation");
1913
1914 // Set Opc
1915 EVT VT = N->getValueType(0);
1916 if (VT == MVT::i32)
1917 Opc = AArch64::BFMWri;
1918 else if (VT == MVT::i64)
1919 Opc = AArch64::BFMXri;
1920 else
1921 return false;
1922
1923 // Because of simplify-demanded-bits in DAGCombine, involved masks may not
1924 // have the expected shape. Try to undo that.
1925 APInt UsefulBits;
1926 getUsefulBits(SDValue(N, 0), UsefulBits);
1927
1928 unsigned NumberOfIgnoredLowBits = UsefulBits.countTrailingZeros();
1929 unsigned NumberOfIgnoredHighBits = UsefulBits.countLeadingZeros();
1930
1931 // OR is commutative, check both possibilities (does llvm provide a
1932 // way to do that directely, e.g., via code matcher?)
1933 SDValue OrOpd1Val = N->getOperand(1);
1934 SDNode *OrOpd0 = N->getOperand(0).getNode();
1935 SDNode *OrOpd1 = N->getOperand(1).getNode();
1936 for (int i = 0; i < 2;
1937 ++i, std::swap(OrOpd0, OrOpd1), OrOpd1Val = N->getOperand(0)) {
1938 unsigned BFXOpc;
1939 int DstLSB, Width;
1940 if (isBitfieldExtractOp(CurDAG, OrOpd0, BFXOpc, Src, ImmR, ImmS,
1941 NumberOfIgnoredLowBits, true)) {
1942 // Check that the returned opcode is compatible with the pattern,
1943 // i.e., same type and zero extended (U and not S)
1944 if ((BFXOpc != AArch64::UBFMXri && VT == MVT::i64) ||
1945 (BFXOpc != AArch64::UBFMWri && VT == MVT::i32))
1946 continue;
1947
1948 // Compute the width of the bitfield insertion
1949 DstLSB = 0;
1950 Width = ImmS - ImmR + 1;
1951 // FIXME: This constraint is to catch bitfield insertion we may
1952 // want to widen the pattern if we want to grab general bitfied
1953 // move case
1954 if (Width <= 0)
1955 continue;
1956
1957 // If the mask on the insertee is correct, we have a BFXIL operation. We
1958 // can share the ImmR and ImmS values from the already-computed UBFM.
1959 } else if (isBitfieldPositioningOp(CurDAG, SDValue(OrOpd0, 0), Src,
1960 DstLSB, Width)) {
1961 ImmR = (VT.getSizeInBits() - DstLSB) % VT.getSizeInBits();
1962 ImmS = Width - 1;
1963 } else
1964 continue;
1965
1966 // Check the second part of the pattern
1967 EVT VT = OrOpd1->getValueType(0);
1968 assert((VT == MVT::i32 || VT == MVT::i64) && "unexpected OR operand");
1969
1970 // Compute the Known Zero for the candidate of the first operand.
1971 // This allows to catch more general case than just looking for
1972 // AND with imm. Indeed, simplify-demanded-bits may have removed
1973 // the AND instruction because it proves it was useless.
1974 APInt KnownZero, KnownOne;
1975 CurDAG->computeKnownBits(OrOpd1Val, KnownZero, KnownOne);
1976
1977 // Check if there is enough room for the second operand to appear
1978 // in the first one
1979 APInt BitsToBeInserted =
1980 APInt::getBitsSet(KnownZero.getBitWidth(), DstLSB, DstLSB + Width);
1981
1982 if ((BitsToBeInserted & ~KnownZero) != 0)
1983 continue;
1984
1985 // Set the first operand
1986 uint64_t Imm;
1987 if (isOpcWithIntImmediate(OrOpd1, ISD::AND, Imm) &&
1988 isBitfieldDstMask(Imm, BitsToBeInserted, NumberOfIgnoredHighBits, VT))
1989 // In that case, we can eliminate the AND
1990 Dst = OrOpd1->getOperand(0);
1991 else
1992 // Maybe the AND has been removed by simplify-demanded-bits
1993 // or is useful because it discards more bits
1994 Dst = OrOpd1Val;
1995
1996 // both parts match
1997 return true;
1998 }
1999
2000 return false;
2001}
2002
2003SDNode *AArch64DAGToDAGISel::SelectBitfieldInsertOp(SDNode *N) {
2004 if (N->getOpcode() != ISD::OR)
2005 return nullptr;
2006
2007 unsigned Opc;
2008 unsigned LSB, MSB;
2009 SDValue Opd0, Opd1;
2010
2011 if (!isBitfieldInsertOpFromOr(N, Opc, Opd0, Opd1, LSB, MSB, CurDAG))
2012 return nullptr;
2013
2014 EVT VT = N->getValueType(0);
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +00002015 SDLoc dl(N);
Tim Northover3b0846e2014-05-24 12:50:23 +00002016 SDValue Ops[] = { Opd0,
2017 Opd1,
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +00002018 CurDAG->getTargetConstant(LSB, dl, VT),
2019 CurDAG->getTargetConstant(MSB, dl, VT) };
Tim Northover3b0846e2014-05-24 12:50:23 +00002020 return CurDAG->SelectNodeTo(N, Opc, VT, Ops);
2021}
2022
2023SDNode *AArch64DAGToDAGISel::SelectLIBM(SDNode *N) {
2024 EVT VT = N->getValueType(0);
2025 unsigned Variant;
2026 unsigned Opc;
2027 unsigned FRINTXOpcs[] = { AArch64::FRINTXSr, AArch64::FRINTXDr };
2028
2029 if (VT == MVT::f32) {
2030 Variant = 0;
2031 } else if (VT == MVT::f64) {
2032 Variant = 1;
2033 } else
2034 return nullptr; // Unrecognized argument type. Fall back on default codegen.
2035
2036 // Pick the FRINTX variant needed to set the flags.
2037 unsigned FRINTXOpc = FRINTXOpcs[Variant];
2038
2039 switch (N->getOpcode()) {
2040 default:
2041 return nullptr; // Unrecognized libm ISD node. Fall back on default codegen.
2042 case ISD::FCEIL: {
2043 unsigned FRINTPOpcs[] = { AArch64::FRINTPSr, AArch64::FRINTPDr };
2044 Opc = FRINTPOpcs[Variant];
2045 break;
2046 }
2047 case ISD::FFLOOR: {
2048 unsigned FRINTMOpcs[] = { AArch64::FRINTMSr, AArch64::FRINTMDr };
2049 Opc = FRINTMOpcs[Variant];
2050 break;
2051 }
2052 case ISD::FTRUNC: {
2053 unsigned FRINTZOpcs[] = { AArch64::FRINTZSr, AArch64::FRINTZDr };
2054 Opc = FRINTZOpcs[Variant];
2055 break;
2056 }
2057 case ISD::FROUND: {
2058 unsigned FRINTAOpcs[] = { AArch64::FRINTASr, AArch64::FRINTADr };
2059 Opc = FRINTAOpcs[Variant];
2060 break;
2061 }
2062 }
2063
2064 SDLoc dl(N);
2065 SDValue In = N->getOperand(0);
2066 SmallVector<SDValue, 2> Ops;
2067 Ops.push_back(In);
2068
2069 if (!TM.Options.UnsafeFPMath) {
2070 SDNode *FRINTX = CurDAG->getMachineNode(FRINTXOpc, dl, VT, MVT::Glue, In);
2071 Ops.push_back(SDValue(FRINTX, 1));
2072 }
2073
2074 return CurDAG->getMachineNode(Opc, dl, VT, Ops);
2075}
2076
2077bool
2078AArch64DAGToDAGISel::SelectCVTFixedPosOperand(SDValue N, SDValue &FixedPos,
2079 unsigned RegWidth) {
2080 APFloat FVal(0.0);
2081 if (ConstantFPSDNode *CN = dyn_cast<ConstantFPSDNode>(N))
2082 FVal = CN->getValueAPF();
2083 else if (LoadSDNode *LN = dyn_cast<LoadSDNode>(N)) {
2084 // Some otherwise illegal constants are allowed in this case.
2085 if (LN->getOperand(1).getOpcode() != AArch64ISD::ADDlow ||
2086 !isa<ConstantPoolSDNode>(LN->getOperand(1)->getOperand(1)))
2087 return false;
2088
2089 ConstantPoolSDNode *CN =
2090 dyn_cast<ConstantPoolSDNode>(LN->getOperand(1)->getOperand(1));
2091 FVal = cast<ConstantFP>(CN->getConstVal())->getValueAPF();
2092 } else
2093 return false;
2094
2095 // An FCVT[SU] instruction performs: convertToInt(Val * 2^fbits) where fbits
2096 // is between 1 and 32 for a destination w-register, or 1 and 64 for an
2097 // x-register.
2098 //
2099 // By this stage, we've detected (fp_to_[su]int (fmul Val, THIS_NODE)) so we
2100 // want THIS_NODE to be 2^fbits. This is much easier to deal with using
2101 // integers.
2102 bool IsExact;
2103
2104 // fbits is between 1 and 64 in the worst-case, which means the fmul
2105 // could have 2^64 as an actual operand. Need 65 bits of precision.
2106 APSInt IntVal(65, true);
2107 FVal.convertToInteger(IntVal, APFloat::rmTowardZero, &IsExact);
2108
2109 // N.b. isPowerOf2 also checks for > 0.
2110 if (!IsExact || !IntVal.isPowerOf2()) return false;
2111 unsigned FBits = IntVal.logBase2();
2112
2113 // Checks above should have guaranteed that we haven't lost information in
2114 // finding FBits, but it must still be in range.
2115 if (FBits == 0 || FBits > RegWidth) return false;
2116
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +00002117 FixedPos = CurDAG->getTargetConstant(FBits, SDLoc(N), MVT::i32);
Tim Northover3b0846e2014-05-24 12:50:23 +00002118 return true;
2119}
2120
Luke Cheeseman85fd06d2015-06-01 12:02:47 +00002121// Inspects a register string of the form o0:op1:CRn:CRm:op2 gets the fields
2122// of the string and obtains the integer values from them and combines these
2123// into a single value to be used in the MRS/MSR instruction.
2124static int getIntOperandFromRegisterString(StringRef RegString) {
2125 SmallVector<StringRef, 5> Fields;
2126 RegString.split(Fields, ":");
2127
2128 if (Fields.size() == 1)
2129 return -1;
2130
2131 assert(Fields.size() == 5
2132 && "Invalid number of fields in read register string");
2133
2134 SmallVector<int, 5> Ops;
2135 bool AllIntFields = true;
2136
2137 for (StringRef Field : Fields) {
2138 unsigned IntField;
2139 AllIntFields &= !Field.getAsInteger(10, IntField);
2140 Ops.push_back(IntField);
2141 }
2142
2143 assert(AllIntFields &&
2144 "Unexpected non-integer value in special register string.");
2145
2146 // Need to combine the integer fields of the string into a single value
2147 // based on the bit encoding of MRS/MSR instruction.
2148 return (Ops[0] << 14) | (Ops[1] << 11) | (Ops[2] << 7) |
2149 (Ops[3] << 3) | (Ops[4]);
2150}
2151
2152// Lower the read_register intrinsic to an MRS instruction node if the special
2153// register string argument is either of the form detailed in the ALCE (the
2154// form described in getIntOperandsFromRegsterString) or is a named register
2155// known by the MRS SysReg mapper.
2156SDNode *AArch64DAGToDAGISel::SelectReadRegister(SDNode *N) {
2157 const MDNodeSDNode *MD = dyn_cast<MDNodeSDNode>(N->getOperand(1));
2158 const MDString *RegString = dyn_cast<MDString>(MD->getMD()->getOperand(0));
2159 SDLoc DL(N);
2160
2161 int Reg = getIntOperandFromRegisterString(RegString->getString());
2162 if (Reg != -1)
2163 return CurDAG->getMachineNode(AArch64::MRS, DL, N->getSimpleValueType(0),
2164 MVT::Other,
2165 CurDAG->getTargetConstant(Reg, DL, MVT::i32),
2166 N->getOperand(0));
2167
2168 // Use the sysreg mapper to map the remaining possible strings to the
2169 // value for the register to be used for the instruction operand.
2170 AArch64SysReg::MRSMapper mapper;
2171 bool IsValidSpecialReg;
2172 Reg = mapper.fromString(RegString->getString(),
2173 Subtarget->getFeatureBits(),
2174 IsValidSpecialReg);
2175 if (IsValidSpecialReg)
2176 return CurDAG->getMachineNode(AArch64::MRS, DL, N->getSimpleValueType(0),
2177 MVT::Other,
2178 CurDAG->getTargetConstant(Reg, DL, MVT::i32),
2179 N->getOperand(0));
2180
2181 return nullptr;
2182}
2183
2184// Lower the write_register intrinsic to an MSR instruction node if the special
2185// register string argument is either of the form detailed in the ALCE (the
2186// form described in getIntOperandsFromRegsterString) or is a named register
2187// known by the MSR SysReg mapper.
2188SDNode *AArch64DAGToDAGISel::SelectWriteRegister(SDNode *N) {
2189 const MDNodeSDNode *MD = dyn_cast<MDNodeSDNode>(N->getOperand(1));
2190 const MDString *RegString = dyn_cast<MDString>(MD->getMD()->getOperand(0));
2191 SDLoc DL(N);
2192
2193 int Reg = getIntOperandFromRegisterString(RegString->getString());
2194 if (Reg != -1)
2195 return CurDAG->getMachineNode(AArch64::MSR, DL, MVT::Other,
2196 CurDAG->getTargetConstant(Reg, DL, MVT::i32),
2197 N->getOperand(2), N->getOperand(0));
2198
2199 // Check if the register was one of those allowed as the pstatefield value in
2200 // the MSR (immediate) instruction. To accept the values allowed in the
2201 // pstatefield for the MSR (immediate) instruction, we also require that an
2202 // immediate value has been provided as an argument, we know that this is
2203 // the case as it has been ensured by semantic checking.
2204 AArch64PState::PStateMapper PMapper;
2205 bool IsValidSpecialReg;
2206 Reg = PMapper.fromString(RegString->getString(),
2207 Subtarget->getFeatureBits(),
2208 IsValidSpecialReg);
2209 if (IsValidSpecialReg) {
2210 assert (isa<ConstantSDNode>(N->getOperand(2))
2211 && "Expected a constant integer expression.");
2212 uint64_t Immed = cast<ConstantSDNode>(N->getOperand(2))->getZExtValue();
2213 return CurDAG->getMachineNode(AArch64::MSRpstate, DL, MVT::Other,
2214 CurDAG->getTargetConstant(Reg, DL, MVT::i32),
2215 CurDAG->getTargetConstant(Immed, DL, MVT::i16),
2216 N->getOperand(0));
2217 }
2218
2219 // Use the sysreg mapper to attempt to map the remaining possible strings
2220 // to the value for the register to be used for the MSR (register)
2221 // instruction operand.
2222 AArch64SysReg::MSRMapper Mapper;
2223 Reg = Mapper.fromString(RegString->getString(),
2224 Subtarget->getFeatureBits(),
2225 IsValidSpecialReg);
2226
2227 if (IsValidSpecialReg)
2228 return CurDAG->getMachineNode(AArch64::MSR, DL, MVT::Other,
2229 CurDAG->getTargetConstant(Reg, DL, MVT::i32),
2230 N->getOperand(2), N->getOperand(0));
2231
2232 return nullptr;
2233}
2234
Tim Northover3b0846e2014-05-24 12:50:23 +00002235SDNode *AArch64DAGToDAGISel::Select(SDNode *Node) {
2236 // Dump information about the Node being selected
2237 DEBUG(errs() << "Selecting: ");
2238 DEBUG(Node->dump(CurDAG));
2239 DEBUG(errs() << "\n");
2240
2241 // If we have a custom node, we already have selected!
2242 if (Node->isMachineOpcode()) {
2243 DEBUG(errs() << "== "; Node->dump(CurDAG); errs() << "\n");
2244 Node->setNodeId(-1);
2245 return nullptr;
2246 }
2247
2248 // Few custom selection stuff.
2249 SDNode *ResNode = nullptr;
2250 EVT VT = Node->getValueType(0);
2251
2252 switch (Node->getOpcode()) {
2253 default:
2254 break;
2255
Luke Cheeseman85fd06d2015-06-01 12:02:47 +00002256 case ISD::READ_REGISTER:
2257 if (SDNode *Res = SelectReadRegister(Node))
2258 return Res;
2259 break;
2260
2261 case ISD::WRITE_REGISTER:
2262 if (SDNode *Res = SelectWriteRegister(Node))
2263 return Res;
2264 break;
2265
Tim Northover3b0846e2014-05-24 12:50:23 +00002266 case ISD::ADD:
2267 if (SDNode *I = SelectMLAV64LaneV128(Node))
2268 return I;
2269 break;
2270
2271 case ISD::LOAD: {
2272 // Try to select as an indexed load. Fall through to normal processing
2273 // if we can't.
2274 bool Done = false;
2275 SDNode *I = SelectIndexedLoad(Node, Done);
2276 if (Done)
2277 return I;
2278 break;
2279 }
2280
2281 case ISD::SRL:
2282 case ISD::AND:
2283 case ISD::SRA:
2284 if (SDNode *I = SelectBitfieldExtractOp(Node))
2285 return I;
2286 break;
2287
2288 case ISD::OR:
2289 if (SDNode *I = SelectBitfieldInsertOp(Node))
2290 return I;
2291 break;
2292
2293 case ISD::EXTRACT_VECTOR_ELT: {
2294 // Extracting lane zero is a special case where we can just use a plain
2295 // EXTRACT_SUBREG instruction, which will become FMOV. This is easier for
2296 // the rest of the compiler, especially the register allocator and copyi
2297 // propagation, to reason about, so is preferred when it's possible to
2298 // use it.
2299 ConstantSDNode *LaneNode = cast<ConstantSDNode>(Node->getOperand(1));
2300 // Bail and use the default Select() for non-zero lanes.
2301 if (LaneNode->getZExtValue() != 0)
2302 break;
2303 // If the element type is not the same as the result type, likewise
2304 // bail and use the default Select(), as there's more to do than just
2305 // a cross-class COPY. This catches extracts of i8 and i16 elements
2306 // since they will need an explicit zext.
2307 if (VT != Node->getOperand(0).getValueType().getVectorElementType())
2308 break;
2309 unsigned SubReg;
2310 switch (Node->getOperand(0)
2311 .getValueType()
2312 .getVectorElementType()
2313 .getSizeInBits()) {
2314 default:
Craig Topper2a30d782014-06-18 05:05:13 +00002315 llvm_unreachable("Unexpected vector element type!");
Tim Northover3b0846e2014-05-24 12:50:23 +00002316 case 64:
2317 SubReg = AArch64::dsub;
2318 break;
2319 case 32:
2320 SubReg = AArch64::ssub;
2321 break;
Oliver Stannard89d15422014-08-27 16:16:04 +00002322 case 16:
2323 SubReg = AArch64::hsub;
2324 break;
Tim Northover3b0846e2014-05-24 12:50:23 +00002325 case 8:
2326 llvm_unreachable("unexpected zext-requiring extract element!");
2327 }
2328 SDValue Extract = CurDAG->getTargetExtractSubreg(SubReg, SDLoc(Node), VT,
2329 Node->getOperand(0));
2330 DEBUG(dbgs() << "ISEL: Custom selection!\n=> ");
2331 DEBUG(Extract->dumpr(CurDAG));
2332 DEBUG(dbgs() << "\n");
2333 return Extract.getNode();
2334 }
2335 case ISD::Constant: {
2336 // Materialize zero constants as copies from WZR/XZR. This allows
2337 // the coalescer to propagate these into other instructions.
2338 ConstantSDNode *ConstNode = cast<ConstantSDNode>(Node);
2339 if (ConstNode->isNullValue()) {
2340 if (VT == MVT::i32)
2341 return CurDAG->getCopyFromReg(CurDAG->getEntryNode(), SDLoc(Node),
2342 AArch64::WZR, MVT::i32).getNode();
2343 else if (VT == MVT::i64)
2344 return CurDAG->getCopyFromReg(CurDAG->getEntryNode(), SDLoc(Node),
2345 AArch64::XZR, MVT::i64).getNode();
2346 }
2347 break;
2348 }
2349
2350 case ISD::FrameIndex: {
2351 // Selects to ADDXri FI, 0 which in turn will become ADDXri SP, imm.
2352 int FI = cast<FrameIndexSDNode>(Node)->getIndex();
2353 unsigned Shifter = AArch64_AM::getShifterImm(AArch64_AM::LSL, 0);
2354 const TargetLowering *TLI = getTargetLowering();
Mehdi Amini44ede332015-07-09 02:09:04 +00002355 SDValue TFI = CurDAG->getTargetFrameIndex(
2356 FI, TLI->getPointerTy(CurDAG->getDataLayout()));
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +00002357 SDLoc DL(Node);
2358 SDValue Ops[] = { TFI, CurDAG->getTargetConstant(0, DL, MVT::i32),
2359 CurDAG->getTargetConstant(Shifter, DL, MVT::i32) };
Tim Northover3b0846e2014-05-24 12:50:23 +00002360 return CurDAG->SelectNodeTo(Node, AArch64::ADDXri, MVT::i64, Ops);
2361 }
2362 case ISD::INTRINSIC_W_CHAIN: {
2363 unsigned IntNo = cast<ConstantSDNode>(Node->getOperand(1))->getZExtValue();
2364 switch (IntNo) {
2365 default:
2366 break;
2367 case Intrinsic::aarch64_ldaxp:
2368 case Intrinsic::aarch64_ldxp: {
2369 unsigned Op =
2370 IntNo == Intrinsic::aarch64_ldaxp ? AArch64::LDAXPX : AArch64::LDXPX;
2371 SDValue MemAddr = Node->getOperand(2);
2372 SDLoc DL(Node);
2373 SDValue Chain = Node->getOperand(0);
2374
2375 SDNode *Ld = CurDAG->getMachineNode(Op, DL, MVT::i64, MVT::i64,
2376 MVT::Other, MemAddr, Chain);
2377
2378 // Transfer memoperands.
2379 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
2380 MemOp[0] = cast<MemIntrinsicSDNode>(Node)->getMemOperand();
2381 cast<MachineSDNode>(Ld)->setMemRefs(MemOp, MemOp + 1);
2382 return Ld;
2383 }
2384 case Intrinsic::aarch64_stlxp:
2385 case Intrinsic::aarch64_stxp: {
2386 unsigned Op =
2387 IntNo == Intrinsic::aarch64_stlxp ? AArch64::STLXPX : AArch64::STXPX;
2388 SDLoc DL(Node);
2389 SDValue Chain = Node->getOperand(0);
2390 SDValue ValLo = Node->getOperand(2);
2391 SDValue ValHi = Node->getOperand(3);
2392 SDValue MemAddr = Node->getOperand(4);
2393
2394 // Place arguments in the right order.
Benjamin Kramerea68a942015-02-19 15:26:17 +00002395 SDValue Ops[] = {ValLo, ValHi, MemAddr, Chain};
Tim Northover3b0846e2014-05-24 12:50:23 +00002396
2397 SDNode *St = CurDAG->getMachineNode(Op, DL, MVT::i32, MVT::Other, Ops);
2398 // Transfer memoperands.
2399 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
2400 MemOp[0] = cast<MemIntrinsicSDNode>(Node)->getMemOperand();
2401 cast<MachineSDNode>(St)->setMemRefs(MemOp, MemOp + 1);
2402
2403 return St;
2404 }
2405 case Intrinsic::aarch64_neon_ld1x2:
2406 if (VT == MVT::v8i8)
2407 return SelectLoad(Node, 2, AArch64::LD1Twov8b, AArch64::dsub0);
2408 else if (VT == MVT::v16i8)
2409 return SelectLoad(Node, 2, AArch64::LD1Twov16b, AArch64::qsub0);
Oliver Stannard89d15422014-08-27 16:16:04 +00002410 else if (VT == MVT::v4i16 || VT == MVT::v4f16)
Tim Northover3b0846e2014-05-24 12:50:23 +00002411 return SelectLoad(Node, 2, AArch64::LD1Twov4h, AArch64::dsub0);
Oliver Stannard89d15422014-08-27 16:16:04 +00002412 else if (VT == MVT::v8i16 || VT == MVT::v8f16)
Tim Northover3b0846e2014-05-24 12:50:23 +00002413 return SelectLoad(Node, 2, AArch64::LD1Twov8h, AArch64::qsub0);
2414 else if (VT == MVT::v2i32 || VT == MVT::v2f32)
2415 return SelectLoad(Node, 2, AArch64::LD1Twov2s, AArch64::dsub0);
2416 else if (VT == MVT::v4i32 || VT == MVT::v4f32)
2417 return SelectLoad(Node, 2, AArch64::LD1Twov4s, AArch64::qsub0);
2418 else if (VT == MVT::v1i64 || VT == MVT::v1f64)
2419 return SelectLoad(Node, 2, AArch64::LD1Twov1d, AArch64::dsub0);
2420 else if (VT == MVT::v2i64 || VT == MVT::v2f64)
2421 return SelectLoad(Node, 2, AArch64::LD1Twov2d, AArch64::qsub0);
2422 break;
2423 case Intrinsic::aarch64_neon_ld1x3:
2424 if (VT == MVT::v8i8)
2425 return SelectLoad(Node, 3, AArch64::LD1Threev8b, AArch64::dsub0);
2426 else if (VT == MVT::v16i8)
2427 return SelectLoad(Node, 3, AArch64::LD1Threev16b, AArch64::qsub0);
Oliver Stannard89d15422014-08-27 16:16:04 +00002428 else if (VT == MVT::v4i16 || VT == MVT::v4f16)
Tim Northover3b0846e2014-05-24 12:50:23 +00002429 return SelectLoad(Node, 3, AArch64::LD1Threev4h, AArch64::dsub0);
Oliver Stannard89d15422014-08-27 16:16:04 +00002430 else if (VT == MVT::v8i16 || VT == MVT::v8f16)
Tim Northover3b0846e2014-05-24 12:50:23 +00002431 return SelectLoad(Node, 3, AArch64::LD1Threev8h, AArch64::qsub0);
2432 else if (VT == MVT::v2i32 || VT == MVT::v2f32)
2433 return SelectLoad(Node, 3, AArch64::LD1Threev2s, AArch64::dsub0);
2434 else if (VT == MVT::v4i32 || VT == MVT::v4f32)
2435 return SelectLoad(Node, 3, AArch64::LD1Threev4s, AArch64::qsub0);
2436 else if (VT == MVT::v1i64 || VT == MVT::v1f64)
2437 return SelectLoad(Node, 3, AArch64::LD1Threev1d, AArch64::dsub0);
2438 else if (VT == MVT::v2i64 || VT == MVT::v2f64)
2439 return SelectLoad(Node, 3, AArch64::LD1Threev2d, AArch64::qsub0);
2440 break;
2441 case Intrinsic::aarch64_neon_ld1x4:
2442 if (VT == MVT::v8i8)
2443 return SelectLoad(Node, 4, AArch64::LD1Fourv8b, AArch64::dsub0);
2444 else if (VT == MVT::v16i8)
2445 return SelectLoad(Node, 4, AArch64::LD1Fourv16b, AArch64::qsub0);
Oliver Stannard89d15422014-08-27 16:16:04 +00002446 else if (VT == MVT::v4i16 || VT == MVT::v4f16)
Tim Northover3b0846e2014-05-24 12:50:23 +00002447 return SelectLoad(Node, 4, AArch64::LD1Fourv4h, AArch64::dsub0);
Oliver Stannard89d15422014-08-27 16:16:04 +00002448 else if (VT == MVT::v8i16 || VT == MVT::v8f16)
Tim Northover3b0846e2014-05-24 12:50:23 +00002449 return SelectLoad(Node, 4, AArch64::LD1Fourv8h, AArch64::qsub0);
2450 else if (VT == MVT::v2i32 || VT == MVT::v2f32)
2451 return SelectLoad(Node, 4, AArch64::LD1Fourv2s, AArch64::dsub0);
2452 else if (VT == MVT::v4i32 || VT == MVT::v4f32)
2453 return SelectLoad(Node, 4, AArch64::LD1Fourv4s, AArch64::qsub0);
2454 else if (VT == MVT::v1i64 || VT == MVT::v1f64)
2455 return SelectLoad(Node, 4, AArch64::LD1Fourv1d, AArch64::dsub0);
2456 else if (VT == MVT::v2i64 || VT == MVT::v2f64)
2457 return SelectLoad(Node, 4, AArch64::LD1Fourv2d, AArch64::qsub0);
2458 break;
2459 case Intrinsic::aarch64_neon_ld2:
2460 if (VT == MVT::v8i8)
2461 return SelectLoad(Node, 2, AArch64::LD2Twov8b, AArch64::dsub0);
2462 else if (VT == MVT::v16i8)
2463 return SelectLoad(Node, 2, AArch64::LD2Twov16b, AArch64::qsub0);
Oliver Stannard89d15422014-08-27 16:16:04 +00002464 else if (VT == MVT::v4i16 || VT == MVT::v4f16)
Tim Northover3b0846e2014-05-24 12:50:23 +00002465 return SelectLoad(Node, 2, AArch64::LD2Twov4h, AArch64::dsub0);
Oliver Stannard89d15422014-08-27 16:16:04 +00002466 else if (VT == MVT::v8i16 || VT == MVT::v8f16)
Tim Northover3b0846e2014-05-24 12:50:23 +00002467 return SelectLoad(Node, 2, AArch64::LD2Twov8h, AArch64::qsub0);
2468 else if (VT == MVT::v2i32 || VT == MVT::v2f32)
2469 return SelectLoad(Node, 2, AArch64::LD2Twov2s, AArch64::dsub0);
2470 else if (VT == MVT::v4i32 || VT == MVT::v4f32)
2471 return SelectLoad(Node, 2, AArch64::LD2Twov4s, AArch64::qsub0);
2472 else if (VT == MVT::v1i64 || VT == MVT::v1f64)
2473 return SelectLoad(Node, 2, AArch64::LD1Twov1d, AArch64::dsub0);
2474 else if (VT == MVT::v2i64 || VT == MVT::v2f64)
2475 return SelectLoad(Node, 2, AArch64::LD2Twov2d, AArch64::qsub0);
2476 break;
2477 case Intrinsic::aarch64_neon_ld3:
2478 if (VT == MVT::v8i8)
2479 return SelectLoad(Node, 3, AArch64::LD3Threev8b, AArch64::dsub0);
2480 else if (VT == MVT::v16i8)
2481 return SelectLoad(Node, 3, AArch64::LD3Threev16b, AArch64::qsub0);
Oliver Stannard89d15422014-08-27 16:16:04 +00002482 else if (VT == MVT::v4i16 || VT == MVT::v4f16)
Tim Northover3b0846e2014-05-24 12:50:23 +00002483 return SelectLoad(Node, 3, AArch64::LD3Threev4h, AArch64::dsub0);
Oliver Stannard89d15422014-08-27 16:16:04 +00002484 else if (VT == MVT::v8i16 || VT == MVT::v8f16)
Tim Northover3b0846e2014-05-24 12:50:23 +00002485 return SelectLoad(Node, 3, AArch64::LD3Threev8h, AArch64::qsub0);
2486 else if (VT == MVT::v2i32 || VT == MVT::v2f32)
2487 return SelectLoad(Node, 3, AArch64::LD3Threev2s, AArch64::dsub0);
2488 else if (VT == MVT::v4i32 || VT == MVT::v4f32)
2489 return SelectLoad(Node, 3, AArch64::LD3Threev4s, AArch64::qsub0);
2490 else if (VT == MVT::v1i64 || VT == MVT::v1f64)
2491 return SelectLoad(Node, 3, AArch64::LD1Threev1d, AArch64::dsub0);
2492 else if (VT == MVT::v2i64 || VT == MVT::v2f64)
2493 return SelectLoad(Node, 3, AArch64::LD3Threev2d, AArch64::qsub0);
2494 break;
2495 case Intrinsic::aarch64_neon_ld4:
2496 if (VT == MVT::v8i8)
2497 return SelectLoad(Node, 4, AArch64::LD4Fourv8b, AArch64::dsub0);
2498 else if (VT == MVT::v16i8)
2499 return SelectLoad(Node, 4, AArch64::LD4Fourv16b, AArch64::qsub0);
Oliver Stannard89d15422014-08-27 16:16:04 +00002500 else if (VT == MVT::v4i16 || VT == MVT::v4f16)
Tim Northover3b0846e2014-05-24 12:50:23 +00002501 return SelectLoad(Node, 4, AArch64::LD4Fourv4h, AArch64::dsub0);
Oliver Stannard89d15422014-08-27 16:16:04 +00002502 else if (VT == MVT::v8i16 || VT == MVT::v8f16)
Tim Northover3b0846e2014-05-24 12:50:23 +00002503 return SelectLoad(Node, 4, AArch64::LD4Fourv8h, AArch64::qsub0);
2504 else if (VT == MVT::v2i32 || VT == MVT::v2f32)
2505 return SelectLoad(Node, 4, AArch64::LD4Fourv2s, AArch64::dsub0);
2506 else if (VT == MVT::v4i32 || VT == MVT::v4f32)
2507 return SelectLoad(Node, 4, AArch64::LD4Fourv4s, AArch64::qsub0);
2508 else if (VT == MVT::v1i64 || VT == MVT::v1f64)
2509 return SelectLoad(Node, 4, AArch64::LD1Fourv1d, AArch64::dsub0);
2510 else if (VT == MVT::v2i64 || VT == MVT::v2f64)
2511 return SelectLoad(Node, 4, AArch64::LD4Fourv2d, AArch64::qsub0);
2512 break;
2513 case Intrinsic::aarch64_neon_ld2r:
2514 if (VT == MVT::v8i8)
2515 return SelectLoad(Node, 2, AArch64::LD2Rv8b, AArch64::dsub0);
2516 else if (VT == MVT::v16i8)
2517 return SelectLoad(Node, 2, AArch64::LD2Rv16b, AArch64::qsub0);
Oliver Stannard89d15422014-08-27 16:16:04 +00002518 else if (VT == MVT::v4i16 || VT == MVT::v4f16)
Tim Northover3b0846e2014-05-24 12:50:23 +00002519 return SelectLoad(Node, 2, AArch64::LD2Rv4h, AArch64::dsub0);
Oliver Stannard89d15422014-08-27 16:16:04 +00002520 else if (VT == MVT::v8i16 || VT == MVT::v8f16)
Tim Northover3b0846e2014-05-24 12:50:23 +00002521 return SelectLoad(Node, 2, AArch64::LD2Rv8h, AArch64::qsub0);
2522 else if (VT == MVT::v2i32 || VT == MVT::v2f32)
2523 return SelectLoad(Node, 2, AArch64::LD2Rv2s, AArch64::dsub0);
2524 else if (VT == MVT::v4i32 || VT == MVT::v4f32)
2525 return SelectLoad(Node, 2, AArch64::LD2Rv4s, AArch64::qsub0);
2526 else if (VT == MVT::v1i64 || VT == MVT::v1f64)
2527 return SelectLoad(Node, 2, AArch64::LD2Rv1d, AArch64::dsub0);
2528 else if (VT == MVT::v2i64 || VT == MVT::v2f64)
2529 return SelectLoad(Node, 2, AArch64::LD2Rv2d, AArch64::qsub0);
2530 break;
2531 case Intrinsic::aarch64_neon_ld3r:
2532 if (VT == MVT::v8i8)
2533 return SelectLoad(Node, 3, AArch64::LD3Rv8b, AArch64::dsub0);
2534 else if (VT == MVT::v16i8)
2535 return SelectLoad(Node, 3, AArch64::LD3Rv16b, AArch64::qsub0);
Oliver Stannard89d15422014-08-27 16:16:04 +00002536 else if (VT == MVT::v4i16 || VT == MVT::v4f16)
Tim Northover3b0846e2014-05-24 12:50:23 +00002537 return SelectLoad(Node, 3, AArch64::LD3Rv4h, AArch64::dsub0);
Oliver Stannard89d15422014-08-27 16:16:04 +00002538 else if (VT == MVT::v8i16 || VT == MVT::v8f16)
Tim Northover3b0846e2014-05-24 12:50:23 +00002539 return SelectLoad(Node, 3, AArch64::LD3Rv8h, AArch64::qsub0);
2540 else if (VT == MVT::v2i32 || VT == MVT::v2f32)
2541 return SelectLoad(Node, 3, AArch64::LD3Rv2s, AArch64::dsub0);
2542 else if (VT == MVT::v4i32 || VT == MVT::v4f32)
2543 return SelectLoad(Node, 3, AArch64::LD3Rv4s, AArch64::qsub0);
2544 else if (VT == MVT::v1i64 || VT == MVT::v1f64)
2545 return SelectLoad(Node, 3, AArch64::LD3Rv1d, AArch64::dsub0);
2546 else if (VT == MVT::v2i64 || VT == MVT::v2f64)
2547 return SelectLoad(Node, 3, AArch64::LD3Rv2d, AArch64::qsub0);
2548 break;
2549 case Intrinsic::aarch64_neon_ld4r:
2550 if (VT == MVT::v8i8)
2551 return SelectLoad(Node, 4, AArch64::LD4Rv8b, AArch64::dsub0);
2552 else if (VT == MVT::v16i8)
2553 return SelectLoad(Node, 4, AArch64::LD4Rv16b, AArch64::qsub0);
Oliver Stannard89d15422014-08-27 16:16:04 +00002554 else if (VT == MVT::v4i16 || VT == MVT::v4f16)
Tim Northover3b0846e2014-05-24 12:50:23 +00002555 return SelectLoad(Node, 4, AArch64::LD4Rv4h, AArch64::dsub0);
Oliver Stannard89d15422014-08-27 16:16:04 +00002556 else if (VT == MVT::v8i16 || VT == MVT::v8f16)
Tim Northover3b0846e2014-05-24 12:50:23 +00002557 return SelectLoad(Node, 4, AArch64::LD4Rv8h, AArch64::qsub0);
2558 else if (VT == MVT::v2i32 || VT == MVT::v2f32)
2559 return SelectLoad(Node, 4, AArch64::LD4Rv2s, AArch64::dsub0);
2560 else if (VT == MVT::v4i32 || VT == MVT::v4f32)
2561 return SelectLoad(Node, 4, AArch64::LD4Rv4s, AArch64::qsub0);
2562 else if (VT == MVT::v1i64 || VT == MVT::v1f64)
2563 return SelectLoad(Node, 4, AArch64::LD4Rv1d, AArch64::dsub0);
2564 else if (VT == MVT::v2i64 || VT == MVT::v2f64)
2565 return SelectLoad(Node, 4, AArch64::LD4Rv2d, AArch64::qsub0);
2566 break;
2567 case Intrinsic::aarch64_neon_ld2lane:
2568 if (VT == MVT::v16i8 || VT == MVT::v8i8)
2569 return SelectLoadLane(Node, 2, AArch64::LD2i8);
Oliver Stannard89d15422014-08-27 16:16:04 +00002570 else if (VT == MVT::v8i16 || VT == MVT::v4i16 || VT == MVT::v4f16 ||
2571 VT == MVT::v8f16)
Tim Northover3b0846e2014-05-24 12:50:23 +00002572 return SelectLoadLane(Node, 2, AArch64::LD2i16);
2573 else if (VT == MVT::v4i32 || VT == MVT::v2i32 || VT == MVT::v4f32 ||
2574 VT == MVT::v2f32)
2575 return SelectLoadLane(Node, 2, AArch64::LD2i32);
2576 else if (VT == MVT::v2i64 || VT == MVT::v1i64 || VT == MVT::v2f64 ||
2577 VT == MVT::v1f64)
2578 return SelectLoadLane(Node, 2, AArch64::LD2i64);
2579 break;
2580 case Intrinsic::aarch64_neon_ld3lane:
2581 if (VT == MVT::v16i8 || VT == MVT::v8i8)
2582 return SelectLoadLane(Node, 3, AArch64::LD3i8);
Oliver Stannard89d15422014-08-27 16:16:04 +00002583 else if (VT == MVT::v8i16 || VT == MVT::v4i16 || VT == MVT::v4f16 ||
2584 VT == MVT::v8f16)
Tim Northover3b0846e2014-05-24 12:50:23 +00002585 return SelectLoadLane(Node, 3, AArch64::LD3i16);
2586 else if (VT == MVT::v4i32 || VT == MVT::v2i32 || VT == MVT::v4f32 ||
2587 VT == MVT::v2f32)
2588 return SelectLoadLane(Node, 3, AArch64::LD3i32);
2589 else if (VT == MVT::v2i64 || VT == MVT::v1i64 || VT == MVT::v2f64 ||
2590 VT == MVT::v1f64)
2591 return SelectLoadLane(Node, 3, AArch64::LD3i64);
2592 break;
2593 case Intrinsic::aarch64_neon_ld4lane:
2594 if (VT == MVT::v16i8 || VT == MVT::v8i8)
2595 return SelectLoadLane(Node, 4, AArch64::LD4i8);
Oliver Stannard89d15422014-08-27 16:16:04 +00002596 else if (VT == MVT::v8i16 || VT == MVT::v4i16 || VT == MVT::v4f16 ||
2597 VT == MVT::v8f16)
Tim Northover3b0846e2014-05-24 12:50:23 +00002598 return SelectLoadLane(Node, 4, AArch64::LD4i16);
2599 else if (VT == MVT::v4i32 || VT == MVT::v2i32 || VT == MVT::v4f32 ||
2600 VT == MVT::v2f32)
2601 return SelectLoadLane(Node, 4, AArch64::LD4i32);
2602 else if (VT == MVT::v2i64 || VT == MVT::v1i64 || VT == MVT::v2f64 ||
2603 VT == MVT::v1f64)
2604 return SelectLoadLane(Node, 4, AArch64::LD4i64);
2605 break;
2606 }
2607 } break;
2608 case ISD::INTRINSIC_WO_CHAIN: {
2609 unsigned IntNo = cast<ConstantSDNode>(Node->getOperand(0))->getZExtValue();
2610 switch (IntNo) {
2611 default:
2612 break;
2613 case Intrinsic::aarch64_neon_tbl2:
2614 return SelectTable(Node, 2, VT == MVT::v8i8 ? AArch64::TBLv8i8Two
2615 : AArch64::TBLv16i8Two,
2616 false);
2617 case Intrinsic::aarch64_neon_tbl3:
2618 return SelectTable(Node, 3, VT == MVT::v8i8 ? AArch64::TBLv8i8Three
2619 : AArch64::TBLv16i8Three,
2620 false);
2621 case Intrinsic::aarch64_neon_tbl4:
2622 return SelectTable(Node, 4, VT == MVT::v8i8 ? AArch64::TBLv8i8Four
2623 : AArch64::TBLv16i8Four,
2624 false);
2625 case Intrinsic::aarch64_neon_tbx2:
2626 return SelectTable(Node, 2, VT == MVT::v8i8 ? AArch64::TBXv8i8Two
2627 : AArch64::TBXv16i8Two,
2628 true);
2629 case Intrinsic::aarch64_neon_tbx3:
2630 return SelectTable(Node, 3, VT == MVT::v8i8 ? AArch64::TBXv8i8Three
2631 : AArch64::TBXv16i8Three,
2632 true);
2633 case Intrinsic::aarch64_neon_tbx4:
2634 return SelectTable(Node, 4, VT == MVT::v8i8 ? AArch64::TBXv8i8Four
2635 : AArch64::TBXv16i8Four,
2636 true);
2637 case Intrinsic::aarch64_neon_smull:
2638 case Intrinsic::aarch64_neon_umull:
2639 if (SDNode *N = SelectMULLV64LaneV128(IntNo, Node))
2640 return N;
2641 break;
2642 }
2643 break;
2644 }
2645 case ISD::INTRINSIC_VOID: {
2646 unsigned IntNo = cast<ConstantSDNode>(Node->getOperand(1))->getZExtValue();
2647 if (Node->getNumOperands() >= 3)
2648 VT = Node->getOperand(2)->getValueType(0);
2649 switch (IntNo) {
2650 default:
2651 break;
2652 case Intrinsic::aarch64_neon_st1x2: {
2653 if (VT == MVT::v8i8)
2654 return SelectStore(Node, 2, AArch64::ST1Twov8b);
2655 else if (VT == MVT::v16i8)
2656 return SelectStore(Node, 2, AArch64::ST1Twov16b);
Oliver Stannard89d15422014-08-27 16:16:04 +00002657 else if (VT == MVT::v4i16 || VT == MVT::v4f16)
Tim Northover3b0846e2014-05-24 12:50:23 +00002658 return SelectStore(Node, 2, AArch64::ST1Twov4h);
Oliver Stannard89d15422014-08-27 16:16:04 +00002659 else if (VT == MVT::v8i16 || VT == MVT::v8f16)
Tim Northover3b0846e2014-05-24 12:50:23 +00002660 return SelectStore(Node, 2, AArch64::ST1Twov8h);
2661 else if (VT == MVT::v2i32 || VT == MVT::v2f32)
2662 return SelectStore(Node, 2, AArch64::ST1Twov2s);
2663 else if (VT == MVT::v4i32 || VT == MVT::v4f32)
2664 return SelectStore(Node, 2, AArch64::ST1Twov4s);
2665 else if (VT == MVT::v2i64 || VT == MVT::v2f64)
2666 return SelectStore(Node, 2, AArch64::ST1Twov2d);
2667 else if (VT == MVT::v1i64 || VT == MVT::v1f64)
2668 return SelectStore(Node, 2, AArch64::ST1Twov1d);
2669 break;
2670 }
2671 case Intrinsic::aarch64_neon_st1x3: {
2672 if (VT == MVT::v8i8)
2673 return SelectStore(Node, 3, AArch64::ST1Threev8b);
2674 else if (VT == MVT::v16i8)
2675 return SelectStore(Node, 3, AArch64::ST1Threev16b);
Oliver Stannard89d15422014-08-27 16:16:04 +00002676 else if (VT == MVT::v4i16 || VT == MVT::v4f16)
Tim Northover3b0846e2014-05-24 12:50:23 +00002677 return SelectStore(Node, 3, AArch64::ST1Threev4h);
Oliver Stannard89d15422014-08-27 16:16:04 +00002678 else if (VT == MVT::v8i16 || VT == MVT::v8f16)
Tim Northover3b0846e2014-05-24 12:50:23 +00002679 return SelectStore(Node, 3, AArch64::ST1Threev8h);
2680 else if (VT == MVT::v2i32 || VT == MVT::v2f32)
2681 return SelectStore(Node, 3, AArch64::ST1Threev2s);
2682 else if (VT == MVT::v4i32 || VT == MVT::v4f32)
2683 return SelectStore(Node, 3, AArch64::ST1Threev4s);
2684 else if (VT == MVT::v2i64 || VT == MVT::v2f64)
2685 return SelectStore(Node, 3, AArch64::ST1Threev2d);
2686 else if (VT == MVT::v1i64 || VT == MVT::v1f64)
2687 return SelectStore(Node, 3, AArch64::ST1Threev1d);
2688 break;
2689 }
2690 case Intrinsic::aarch64_neon_st1x4: {
2691 if (VT == MVT::v8i8)
2692 return SelectStore(Node, 4, AArch64::ST1Fourv8b);
2693 else if (VT == MVT::v16i8)
2694 return SelectStore(Node, 4, AArch64::ST1Fourv16b);
Oliver Stannard89d15422014-08-27 16:16:04 +00002695 else if (VT == MVT::v4i16 || VT == MVT::v4f16)
Tim Northover3b0846e2014-05-24 12:50:23 +00002696 return SelectStore(Node, 4, AArch64::ST1Fourv4h);
Oliver Stannard89d15422014-08-27 16:16:04 +00002697 else if (VT == MVT::v8i16 || VT == MVT::v8f16)
Tim Northover3b0846e2014-05-24 12:50:23 +00002698 return SelectStore(Node, 4, AArch64::ST1Fourv8h);
2699 else if (VT == MVT::v2i32 || VT == MVT::v2f32)
2700 return SelectStore(Node, 4, AArch64::ST1Fourv2s);
2701 else if (VT == MVT::v4i32 || VT == MVT::v4f32)
2702 return SelectStore(Node, 4, AArch64::ST1Fourv4s);
2703 else if (VT == MVT::v2i64 || VT == MVT::v2f64)
2704 return SelectStore(Node, 4, AArch64::ST1Fourv2d);
2705 else if (VT == MVT::v1i64 || VT == MVT::v1f64)
2706 return SelectStore(Node, 4, AArch64::ST1Fourv1d);
2707 break;
2708 }
2709 case Intrinsic::aarch64_neon_st2: {
2710 if (VT == MVT::v8i8)
2711 return SelectStore(Node, 2, AArch64::ST2Twov8b);
2712 else if (VT == MVT::v16i8)
2713 return SelectStore(Node, 2, AArch64::ST2Twov16b);
Oliver Stannard89d15422014-08-27 16:16:04 +00002714 else if (VT == MVT::v4i16 || VT == MVT::v4f16)
Tim Northover3b0846e2014-05-24 12:50:23 +00002715 return SelectStore(Node, 2, AArch64::ST2Twov4h);
Oliver Stannard89d15422014-08-27 16:16:04 +00002716 else if (VT == MVT::v8i16 || VT == MVT::v8f16)
Tim Northover3b0846e2014-05-24 12:50:23 +00002717 return SelectStore(Node, 2, AArch64::ST2Twov8h);
2718 else if (VT == MVT::v2i32 || VT == MVT::v2f32)
2719 return SelectStore(Node, 2, AArch64::ST2Twov2s);
2720 else if (VT == MVT::v4i32 || VT == MVT::v4f32)
2721 return SelectStore(Node, 2, AArch64::ST2Twov4s);
2722 else if (VT == MVT::v2i64 || VT == MVT::v2f64)
2723 return SelectStore(Node, 2, AArch64::ST2Twov2d);
2724 else if (VT == MVT::v1i64 || VT == MVT::v1f64)
2725 return SelectStore(Node, 2, AArch64::ST1Twov1d);
2726 break;
2727 }
2728 case Intrinsic::aarch64_neon_st3: {
2729 if (VT == MVT::v8i8)
2730 return SelectStore(Node, 3, AArch64::ST3Threev8b);
2731 else if (VT == MVT::v16i8)
2732 return SelectStore(Node, 3, AArch64::ST3Threev16b);
Oliver Stannard89d15422014-08-27 16:16:04 +00002733 else if (VT == MVT::v4i16 || VT == MVT::v4f16)
Tim Northover3b0846e2014-05-24 12:50:23 +00002734 return SelectStore(Node, 3, AArch64::ST3Threev4h);
Oliver Stannard89d15422014-08-27 16:16:04 +00002735 else if (VT == MVT::v8i16 || VT == MVT::v8f16)
Tim Northover3b0846e2014-05-24 12:50:23 +00002736 return SelectStore(Node, 3, AArch64::ST3Threev8h);
2737 else if (VT == MVT::v2i32 || VT == MVT::v2f32)
2738 return SelectStore(Node, 3, AArch64::ST3Threev2s);
2739 else if (VT == MVT::v4i32 || VT == MVT::v4f32)
2740 return SelectStore(Node, 3, AArch64::ST3Threev4s);
2741 else if (VT == MVT::v2i64 || VT == MVT::v2f64)
2742 return SelectStore(Node, 3, AArch64::ST3Threev2d);
2743 else if (VT == MVT::v1i64 || VT == MVT::v1f64)
2744 return SelectStore(Node, 3, AArch64::ST1Threev1d);
2745 break;
2746 }
2747 case Intrinsic::aarch64_neon_st4: {
2748 if (VT == MVT::v8i8)
2749 return SelectStore(Node, 4, AArch64::ST4Fourv8b);
2750 else if (VT == MVT::v16i8)
2751 return SelectStore(Node, 4, AArch64::ST4Fourv16b);
Oliver Stannard89d15422014-08-27 16:16:04 +00002752 else if (VT == MVT::v4i16 || VT == MVT::v4f16)
Tim Northover3b0846e2014-05-24 12:50:23 +00002753 return SelectStore(Node, 4, AArch64::ST4Fourv4h);
Oliver Stannard89d15422014-08-27 16:16:04 +00002754 else if (VT == MVT::v8i16 || VT == MVT::v8f16)
Tim Northover3b0846e2014-05-24 12:50:23 +00002755 return SelectStore(Node, 4, AArch64::ST4Fourv8h);
2756 else if (VT == MVT::v2i32 || VT == MVT::v2f32)
2757 return SelectStore(Node, 4, AArch64::ST4Fourv2s);
2758 else if (VT == MVT::v4i32 || VT == MVT::v4f32)
2759 return SelectStore(Node, 4, AArch64::ST4Fourv4s);
2760 else if (VT == MVT::v2i64 || VT == MVT::v2f64)
2761 return SelectStore(Node, 4, AArch64::ST4Fourv2d);
2762 else if (VT == MVT::v1i64 || VT == MVT::v1f64)
2763 return SelectStore(Node, 4, AArch64::ST1Fourv1d);
2764 break;
2765 }
2766 case Intrinsic::aarch64_neon_st2lane: {
2767 if (VT == MVT::v16i8 || VT == MVT::v8i8)
2768 return SelectStoreLane(Node, 2, AArch64::ST2i8);
Oliver Stannard89d15422014-08-27 16:16:04 +00002769 else if (VT == MVT::v8i16 || VT == MVT::v4i16 || VT == MVT::v4f16 ||
2770 VT == MVT::v8f16)
Tim Northover3b0846e2014-05-24 12:50:23 +00002771 return SelectStoreLane(Node, 2, AArch64::ST2i16);
2772 else if (VT == MVT::v4i32 || VT == MVT::v2i32 || VT == MVT::v4f32 ||
2773 VT == MVT::v2f32)
2774 return SelectStoreLane(Node, 2, AArch64::ST2i32);
2775 else if (VT == MVT::v2i64 || VT == MVT::v1i64 || VT == MVT::v2f64 ||
2776 VT == MVT::v1f64)
2777 return SelectStoreLane(Node, 2, AArch64::ST2i64);
2778 break;
2779 }
2780 case Intrinsic::aarch64_neon_st3lane: {
2781 if (VT == MVT::v16i8 || VT == MVT::v8i8)
2782 return SelectStoreLane(Node, 3, AArch64::ST3i8);
Oliver Stannard89d15422014-08-27 16:16:04 +00002783 else if (VT == MVT::v8i16 || VT == MVT::v4i16 || VT == MVT::v4f16 ||
2784 VT == MVT::v8f16)
Tim Northover3b0846e2014-05-24 12:50:23 +00002785 return SelectStoreLane(Node, 3, AArch64::ST3i16);
2786 else if (VT == MVT::v4i32 || VT == MVT::v2i32 || VT == MVT::v4f32 ||
2787 VT == MVT::v2f32)
2788 return SelectStoreLane(Node, 3, AArch64::ST3i32);
2789 else if (VT == MVT::v2i64 || VT == MVT::v1i64 || VT == MVT::v2f64 ||
2790 VT == MVT::v1f64)
2791 return SelectStoreLane(Node, 3, AArch64::ST3i64);
2792 break;
2793 }
2794 case Intrinsic::aarch64_neon_st4lane: {
2795 if (VT == MVT::v16i8 || VT == MVT::v8i8)
2796 return SelectStoreLane(Node, 4, AArch64::ST4i8);
Oliver Stannard89d15422014-08-27 16:16:04 +00002797 else if (VT == MVT::v8i16 || VT == MVT::v4i16 || VT == MVT::v4f16 ||
2798 VT == MVT::v8f16)
Tim Northover3b0846e2014-05-24 12:50:23 +00002799 return SelectStoreLane(Node, 4, AArch64::ST4i16);
2800 else if (VT == MVT::v4i32 || VT == MVT::v2i32 || VT == MVT::v4f32 ||
2801 VT == MVT::v2f32)
2802 return SelectStoreLane(Node, 4, AArch64::ST4i32);
2803 else if (VT == MVT::v2i64 || VT == MVT::v1i64 || VT == MVT::v2f64 ||
2804 VT == MVT::v1f64)
2805 return SelectStoreLane(Node, 4, AArch64::ST4i64);
2806 break;
2807 }
2808 }
2809 }
2810 case AArch64ISD::LD2post: {
2811 if (VT == MVT::v8i8)
2812 return SelectPostLoad(Node, 2, AArch64::LD2Twov8b_POST, AArch64::dsub0);
2813 else if (VT == MVT::v16i8)
2814 return SelectPostLoad(Node, 2, AArch64::LD2Twov16b_POST, AArch64::qsub0);
Oliver Stannard89d15422014-08-27 16:16:04 +00002815 else if (VT == MVT::v4i16 || VT == MVT::v4f16)
Tim Northover3b0846e2014-05-24 12:50:23 +00002816 return SelectPostLoad(Node, 2, AArch64::LD2Twov4h_POST, AArch64::dsub0);
Oliver Stannard89d15422014-08-27 16:16:04 +00002817 else if (VT == MVT::v8i16 || VT == MVT::v8f16)
Tim Northover3b0846e2014-05-24 12:50:23 +00002818 return SelectPostLoad(Node, 2, AArch64::LD2Twov8h_POST, AArch64::qsub0);
2819 else if (VT == MVT::v2i32 || VT == MVT::v2f32)
2820 return SelectPostLoad(Node, 2, AArch64::LD2Twov2s_POST, AArch64::dsub0);
2821 else if (VT == MVT::v4i32 || VT == MVT::v4f32)
2822 return SelectPostLoad(Node, 2, AArch64::LD2Twov4s_POST, AArch64::qsub0);
2823 else if (VT == MVT::v1i64 || VT == MVT::v1f64)
2824 return SelectPostLoad(Node, 2, AArch64::LD1Twov1d_POST, AArch64::dsub0);
2825 else if (VT == MVT::v2i64 || VT == MVT::v2f64)
2826 return SelectPostLoad(Node, 2, AArch64::LD2Twov2d_POST, AArch64::qsub0);
2827 break;
2828 }
2829 case AArch64ISD::LD3post: {
2830 if (VT == MVT::v8i8)
2831 return SelectPostLoad(Node, 3, AArch64::LD3Threev8b_POST, AArch64::dsub0);
2832 else if (VT == MVT::v16i8)
2833 return SelectPostLoad(Node, 3, AArch64::LD3Threev16b_POST, AArch64::qsub0);
Oliver Stannard89d15422014-08-27 16:16:04 +00002834 else if (VT == MVT::v4i16 || VT == MVT::v4f16)
Tim Northover3b0846e2014-05-24 12:50:23 +00002835 return SelectPostLoad(Node, 3, AArch64::LD3Threev4h_POST, AArch64::dsub0);
Oliver Stannard89d15422014-08-27 16:16:04 +00002836 else if (VT == MVT::v8i16 || VT == MVT::v8f16)
Tim Northover3b0846e2014-05-24 12:50:23 +00002837 return SelectPostLoad(Node, 3, AArch64::LD3Threev8h_POST, AArch64::qsub0);
2838 else if (VT == MVT::v2i32 || VT == MVT::v2f32)
2839 return SelectPostLoad(Node, 3, AArch64::LD3Threev2s_POST, AArch64::dsub0);
2840 else if (VT == MVT::v4i32 || VT == MVT::v4f32)
2841 return SelectPostLoad(Node, 3, AArch64::LD3Threev4s_POST, AArch64::qsub0);
2842 else if (VT == MVT::v1i64 || VT == MVT::v1f64)
2843 return SelectPostLoad(Node, 3, AArch64::LD1Threev1d_POST, AArch64::dsub0);
2844 else if (VT == MVT::v2i64 || VT == MVT::v2f64)
2845 return SelectPostLoad(Node, 3, AArch64::LD3Threev2d_POST, AArch64::qsub0);
2846 break;
2847 }
2848 case AArch64ISD::LD4post: {
2849 if (VT == MVT::v8i8)
2850 return SelectPostLoad(Node, 4, AArch64::LD4Fourv8b_POST, AArch64::dsub0);
2851 else if (VT == MVT::v16i8)
2852 return SelectPostLoad(Node, 4, AArch64::LD4Fourv16b_POST, AArch64::qsub0);
Oliver Stannard89d15422014-08-27 16:16:04 +00002853 else if (VT == MVT::v4i16 || VT == MVT::v4f16)
Tim Northover3b0846e2014-05-24 12:50:23 +00002854 return SelectPostLoad(Node, 4, AArch64::LD4Fourv4h_POST, AArch64::dsub0);
Oliver Stannard89d15422014-08-27 16:16:04 +00002855 else if (VT == MVT::v8i16 || VT == MVT::v8f16)
Tim Northover3b0846e2014-05-24 12:50:23 +00002856 return SelectPostLoad(Node, 4, AArch64::LD4Fourv8h_POST, AArch64::qsub0);
2857 else if (VT == MVT::v2i32 || VT == MVT::v2f32)
2858 return SelectPostLoad(Node, 4, AArch64::LD4Fourv2s_POST, AArch64::dsub0);
2859 else if (VT == MVT::v4i32 || VT == MVT::v4f32)
2860 return SelectPostLoad(Node, 4, AArch64::LD4Fourv4s_POST, AArch64::qsub0);
2861 else if (VT == MVT::v1i64 || VT == MVT::v1f64)
2862 return SelectPostLoad(Node, 4, AArch64::LD1Fourv1d_POST, AArch64::dsub0);
2863 else if (VT == MVT::v2i64 || VT == MVT::v2f64)
2864 return SelectPostLoad(Node, 4, AArch64::LD4Fourv2d_POST, AArch64::qsub0);
2865 break;
2866 }
2867 case AArch64ISD::LD1x2post: {
2868 if (VT == MVT::v8i8)
2869 return SelectPostLoad(Node, 2, AArch64::LD1Twov8b_POST, AArch64::dsub0);
2870 else if (VT == MVT::v16i8)
2871 return SelectPostLoad(Node, 2, AArch64::LD1Twov16b_POST, AArch64::qsub0);
Oliver Stannard89d15422014-08-27 16:16:04 +00002872 else if (VT == MVT::v4i16 || VT == MVT::v4f16)
Tim Northover3b0846e2014-05-24 12:50:23 +00002873 return SelectPostLoad(Node, 2, AArch64::LD1Twov4h_POST, AArch64::dsub0);
Oliver Stannard89d15422014-08-27 16:16:04 +00002874 else if (VT == MVT::v8i16 || VT == MVT::v8f16)
Tim Northover3b0846e2014-05-24 12:50:23 +00002875 return SelectPostLoad(Node, 2, AArch64::LD1Twov8h_POST, AArch64::qsub0);
2876 else if (VT == MVT::v2i32 || VT == MVT::v2f32)
2877 return SelectPostLoad(Node, 2, AArch64::LD1Twov2s_POST, AArch64::dsub0);
2878 else if (VT == MVT::v4i32 || VT == MVT::v4f32)
2879 return SelectPostLoad(Node, 2, AArch64::LD1Twov4s_POST, AArch64::qsub0);
2880 else if (VT == MVT::v1i64 || VT == MVT::v1f64)
2881 return SelectPostLoad(Node, 2, AArch64::LD1Twov1d_POST, AArch64::dsub0);
2882 else if (VT == MVT::v2i64 || VT == MVT::v2f64)
2883 return SelectPostLoad(Node, 2, AArch64::LD1Twov2d_POST, AArch64::qsub0);
2884 break;
2885 }
2886 case AArch64ISD::LD1x3post: {
2887 if (VT == MVT::v8i8)
2888 return SelectPostLoad(Node, 3, AArch64::LD1Threev8b_POST, AArch64::dsub0);
2889 else if (VT == MVT::v16i8)
2890 return SelectPostLoad(Node, 3, AArch64::LD1Threev16b_POST, AArch64::qsub0);
Oliver Stannard89d15422014-08-27 16:16:04 +00002891 else if (VT == MVT::v4i16 || VT == MVT::v4f16)
Tim Northover3b0846e2014-05-24 12:50:23 +00002892 return SelectPostLoad(Node, 3, AArch64::LD1Threev4h_POST, AArch64::dsub0);
Oliver Stannard89d15422014-08-27 16:16:04 +00002893 else if (VT == MVT::v8i16 || VT == MVT::v8f16)
Tim Northover3b0846e2014-05-24 12:50:23 +00002894 return SelectPostLoad(Node, 3, AArch64::LD1Threev8h_POST, AArch64::qsub0);
2895 else if (VT == MVT::v2i32 || VT == MVT::v2f32)
2896 return SelectPostLoad(Node, 3, AArch64::LD1Threev2s_POST, AArch64::dsub0);
2897 else if (VT == MVT::v4i32 || VT == MVT::v4f32)
2898 return SelectPostLoad(Node, 3, AArch64::LD1Threev4s_POST, AArch64::qsub0);
2899 else if (VT == MVT::v1i64 || VT == MVT::v1f64)
2900 return SelectPostLoad(Node, 3, AArch64::LD1Threev1d_POST, AArch64::dsub0);
2901 else if (VT == MVT::v2i64 || VT == MVT::v2f64)
2902 return SelectPostLoad(Node, 3, AArch64::LD1Threev2d_POST, AArch64::qsub0);
2903 break;
2904 }
2905 case AArch64ISD::LD1x4post: {
2906 if (VT == MVT::v8i8)
2907 return SelectPostLoad(Node, 4, AArch64::LD1Fourv8b_POST, AArch64::dsub0);
2908 else if (VT == MVT::v16i8)
2909 return SelectPostLoad(Node, 4, AArch64::LD1Fourv16b_POST, AArch64::qsub0);
Oliver Stannard89d15422014-08-27 16:16:04 +00002910 else if (VT == MVT::v4i16 || VT == MVT::v4f16)
Tim Northover3b0846e2014-05-24 12:50:23 +00002911 return SelectPostLoad(Node, 4, AArch64::LD1Fourv4h_POST, AArch64::dsub0);
Oliver Stannard89d15422014-08-27 16:16:04 +00002912 else if (VT == MVT::v8i16 || VT == MVT::v8f16)
Tim Northover3b0846e2014-05-24 12:50:23 +00002913 return SelectPostLoad(Node, 4, AArch64::LD1Fourv8h_POST, AArch64::qsub0);
2914 else if (VT == MVT::v2i32 || VT == MVT::v2f32)
2915 return SelectPostLoad(Node, 4, AArch64::LD1Fourv2s_POST, AArch64::dsub0);
2916 else if (VT == MVT::v4i32 || VT == MVT::v4f32)
2917 return SelectPostLoad(Node, 4, AArch64::LD1Fourv4s_POST, AArch64::qsub0);
2918 else if (VT == MVT::v1i64 || VT == MVT::v1f64)
2919 return SelectPostLoad(Node, 4, AArch64::LD1Fourv1d_POST, AArch64::dsub0);
2920 else if (VT == MVT::v2i64 || VT == MVT::v2f64)
2921 return SelectPostLoad(Node, 4, AArch64::LD1Fourv2d_POST, AArch64::qsub0);
2922 break;
2923 }
2924 case AArch64ISD::LD1DUPpost: {
2925 if (VT == MVT::v8i8)
2926 return SelectPostLoad(Node, 1, AArch64::LD1Rv8b_POST, AArch64::dsub0);
2927 else if (VT == MVT::v16i8)
2928 return SelectPostLoad(Node, 1, AArch64::LD1Rv16b_POST, AArch64::qsub0);
Oliver Stannard89d15422014-08-27 16:16:04 +00002929 else if (VT == MVT::v4i16 || VT == MVT::v4f16)
Tim Northover3b0846e2014-05-24 12:50:23 +00002930 return SelectPostLoad(Node, 1, AArch64::LD1Rv4h_POST, AArch64::dsub0);
Oliver Stannard89d15422014-08-27 16:16:04 +00002931 else if (VT == MVT::v8i16 || VT == MVT::v8f16)
Tim Northover3b0846e2014-05-24 12:50:23 +00002932 return SelectPostLoad(Node, 1, AArch64::LD1Rv8h_POST, AArch64::qsub0);
2933 else if (VT == MVT::v2i32 || VT == MVT::v2f32)
2934 return SelectPostLoad(Node, 1, AArch64::LD1Rv2s_POST, AArch64::dsub0);
2935 else if (VT == MVT::v4i32 || VT == MVT::v4f32)
2936 return SelectPostLoad(Node, 1, AArch64::LD1Rv4s_POST, AArch64::qsub0);
2937 else if (VT == MVT::v1i64 || VT == MVT::v1f64)
2938 return SelectPostLoad(Node, 1, AArch64::LD1Rv1d_POST, AArch64::dsub0);
2939 else if (VT == MVT::v2i64 || VT == MVT::v2f64)
2940 return SelectPostLoad(Node, 1, AArch64::LD1Rv2d_POST, AArch64::qsub0);
2941 break;
2942 }
2943 case AArch64ISD::LD2DUPpost: {
2944 if (VT == MVT::v8i8)
2945 return SelectPostLoad(Node, 2, AArch64::LD2Rv8b_POST, AArch64::dsub0);
2946 else if (VT == MVT::v16i8)
2947 return SelectPostLoad(Node, 2, AArch64::LD2Rv16b_POST, AArch64::qsub0);
Oliver Stannard89d15422014-08-27 16:16:04 +00002948 else if (VT == MVT::v4i16 || VT == MVT::v4f16)
Tim Northover3b0846e2014-05-24 12:50:23 +00002949 return SelectPostLoad(Node, 2, AArch64::LD2Rv4h_POST, AArch64::dsub0);
Oliver Stannard89d15422014-08-27 16:16:04 +00002950 else if (VT == MVT::v8i16 || VT == MVT::v8f16)
Tim Northover3b0846e2014-05-24 12:50:23 +00002951 return SelectPostLoad(Node, 2, AArch64::LD2Rv8h_POST, AArch64::qsub0);
2952 else if (VT == MVT::v2i32 || VT == MVT::v2f32)
2953 return SelectPostLoad(Node, 2, AArch64::LD2Rv2s_POST, AArch64::dsub0);
2954 else if (VT == MVT::v4i32 || VT == MVT::v4f32)
2955 return SelectPostLoad(Node, 2, AArch64::LD2Rv4s_POST, AArch64::qsub0);
2956 else if (VT == MVT::v1i64 || VT == MVT::v1f64)
2957 return SelectPostLoad(Node, 2, AArch64::LD2Rv1d_POST, AArch64::dsub0);
2958 else if (VT == MVT::v2i64 || VT == MVT::v2f64)
2959 return SelectPostLoad(Node, 2, AArch64::LD2Rv2d_POST, AArch64::qsub0);
2960 break;
2961 }
2962 case AArch64ISD::LD3DUPpost: {
2963 if (VT == MVT::v8i8)
2964 return SelectPostLoad(Node, 3, AArch64::LD3Rv8b_POST, AArch64::dsub0);
2965 else if (VT == MVT::v16i8)
2966 return SelectPostLoad(Node, 3, AArch64::LD3Rv16b_POST, AArch64::qsub0);
Oliver Stannard89d15422014-08-27 16:16:04 +00002967 else if (VT == MVT::v4i16 || VT == MVT::v4f16)
Tim Northover3b0846e2014-05-24 12:50:23 +00002968 return SelectPostLoad(Node, 3, AArch64::LD3Rv4h_POST, AArch64::dsub0);
Oliver Stannard89d15422014-08-27 16:16:04 +00002969 else if (VT == MVT::v8i16 || VT == MVT::v8f16)
Tim Northover3b0846e2014-05-24 12:50:23 +00002970 return SelectPostLoad(Node, 3, AArch64::LD3Rv8h_POST, AArch64::qsub0);
2971 else if (VT == MVT::v2i32 || VT == MVT::v2f32)
2972 return SelectPostLoad(Node, 3, AArch64::LD3Rv2s_POST, AArch64::dsub0);
2973 else if (VT == MVT::v4i32 || VT == MVT::v4f32)
2974 return SelectPostLoad(Node, 3, AArch64::LD3Rv4s_POST, AArch64::qsub0);
2975 else if (VT == MVT::v1i64 || VT == MVT::v1f64)
2976 return SelectPostLoad(Node, 3, AArch64::LD3Rv1d_POST, AArch64::dsub0);
2977 else if (VT == MVT::v2i64 || VT == MVT::v2f64)
2978 return SelectPostLoad(Node, 3, AArch64::LD3Rv2d_POST, AArch64::qsub0);
2979 break;
2980 }
2981 case AArch64ISD::LD4DUPpost: {
2982 if (VT == MVT::v8i8)
2983 return SelectPostLoad(Node, 4, AArch64::LD4Rv8b_POST, AArch64::dsub0);
2984 else if (VT == MVT::v16i8)
2985 return SelectPostLoad(Node, 4, AArch64::LD4Rv16b_POST, AArch64::qsub0);
Oliver Stannard89d15422014-08-27 16:16:04 +00002986 else if (VT == MVT::v4i16 || VT == MVT::v4f16)
Tim Northover3b0846e2014-05-24 12:50:23 +00002987 return SelectPostLoad(Node, 4, AArch64::LD4Rv4h_POST, AArch64::dsub0);
Oliver Stannard89d15422014-08-27 16:16:04 +00002988 else if (VT == MVT::v8i16 || VT == MVT::v8f16)
Tim Northover3b0846e2014-05-24 12:50:23 +00002989 return SelectPostLoad(Node, 4, AArch64::LD4Rv8h_POST, AArch64::qsub0);
2990 else if (VT == MVT::v2i32 || VT == MVT::v2f32)
2991 return SelectPostLoad(Node, 4, AArch64::LD4Rv2s_POST, AArch64::dsub0);
2992 else if (VT == MVT::v4i32 || VT == MVT::v4f32)
2993 return SelectPostLoad(Node, 4, AArch64::LD4Rv4s_POST, AArch64::qsub0);
2994 else if (VT == MVT::v1i64 || VT == MVT::v1f64)
2995 return SelectPostLoad(Node, 4, AArch64::LD4Rv1d_POST, AArch64::dsub0);
2996 else if (VT == MVT::v2i64 || VT == MVT::v2f64)
2997 return SelectPostLoad(Node, 4, AArch64::LD4Rv2d_POST, AArch64::qsub0);
2998 break;
2999 }
3000 case AArch64ISD::LD1LANEpost: {
3001 if (VT == MVT::v16i8 || VT == MVT::v8i8)
3002 return SelectPostLoadLane(Node, 1, AArch64::LD1i8_POST);
Oliver Stannard89d15422014-08-27 16:16:04 +00003003 else if (VT == MVT::v8i16 || VT == MVT::v4i16 || VT == MVT::v4f16 ||
3004 VT == MVT::v8f16)
Tim Northover3b0846e2014-05-24 12:50:23 +00003005 return SelectPostLoadLane(Node, 1, AArch64::LD1i16_POST);
3006 else if (VT == MVT::v4i32 || VT == MVT::v2i32 || VT == MVT::v4f32 ||
3007 VT == MVT::v2f32)
3008 return SelectPostLoadLane(Node, 1, AArch64::LD1i32_POST);
3009 else if (VT == MVT::v2i64 || VT == MVT::v1i64 || VT == MVT::v2f64 ||
3010 VT == MVT::v1f64)
3011 return SelectPostLoadLane(Node, 1, AArch64::LD1i64_POST);
3012 break;
3013 }
3014 case AArch64ISD::LD2LANEpost: {
3015 if (VT == MVT::v16i8 || VT == MVT::v8i8)
3016 return SelectPostLoadLane(Node, 2, AArch64::LD2i8_POST);
Oliver Stannard89d15422014-08-27 16:16:04 +00003017 else if (VT == MVT::v8i16 || VT == MVT::v4i16 || VT == MVT::v4f16 ||
3018 VT == MVT::v8f16)
Tim Northover3b0846e2014-05-24 12:50:23 +00003019 return SelectPostLoadLane(Node, 2, AArch64::LD2i16_POST);
3020 else if (VT == MVT::v4i32 || VT == MVT::v2i32 || VT == MVT::v4f32 ||
3021 VT == MVT::v2f32)
3022 return SelectPostLoadLane(Node, 2, AArch64::LD2i32_POST);
3023 else if (VT == MVT::v2i64 || VT == MVT::v1i64 || VT == MVT::v2f64 ||
3024 VT == MVT::v1f64)
3025 return SelectPostLoadLane(Node, 2, AArch64::LD2i64_POST);
3026 break;
3027 }
3028 case AArch64ISD::LD3LANEpost: {
3029 if (VT == MVT::v16i8 || VT == MVT::v8i8)
3030 return SelectPostLoadLane(Node, 3, AArch64::LD3i8_POST);
Oliver Stannard89d15422014-08-27 16:16:04 +00003031 else if (VT == MVT::v8i16 || VT == MVT::v4i16 || VT == MVT::v4f16 ||
3032 VT == MVT::v8f16)
Tim Northover3b0846e2014-05-24 12:50:23 +00003033 return SelectPostLoadLane(Node, 3, AArch64::LD3i16_POST);
3034 else if (VT == MVT::v4i32 || VT == MVT::v2i32 || VT == MVT::v4f32 ||
3035 VT == MVT::v2f32)
3036 return SelectPostLoadLane(Node, 3, AArch64::LD3i32_POST);
3037 else if (VT == MVT::v2i64 || VT == MVT::v1i64 || VT == MVT::v2f64 ||
3038 VT == MVT::v1f64)
3039 return SelectPostLoadLane(Node, 3, AArch64::LD3i64_POST);
3040 break;
3041 }
3042 case AArch64ISD::LD4LANEpost: {
3043 if (VT == MVT::v16i8 || VT == MVT::v8i8)
3044 return SelectPostLoadLane(Node, 4, AArch64::LD4i8_POST);
Oliver Stannard89d15422014-08-27 16:16:04 +00003045 else if (VT == MVT::v8i16 || VT == MVT::v4i16 || VT == MVT::v4f16 ||
3046 VT == MVT::v8f16)
Tim Northover3b0846e2014-05-24 12:50:23 +00003047 return SelectPostLoadLane(Node, 4, AArch64::LD4i16_POST);
3048 else if (VT == MVT::v4i32 || VT == MVT::v2i32 || VT == MVT::v4f32 ||
3049 VT == MVT::v2f32)
3050 return SelectPostLoadLane(Node, 4, AArch64::LD4i32_POST);
3051 else if (VT == MVT::v2i64 || VT == MVT::v1i64 || VT == MVT::v2f64 ||
3052 VT == MVT::v1f64)
3053 return SelectPostLoadLane(Node, 4, AArch64::LD4i64_POST);
3054 break;
3055 }
3056 case AArch64ISD::ST2post: {
3057 VT = Node->getOperand(1).getValueType();
3058 if (VT == MVT::v8i8)
3059 return SelectPostStore(Node, 2, AArch64::ST2Twov8b_POST);
3060 else if (VT == MVT::v16i8)
3061 return SelectPostStore(Node, 2, AArch64::ST2Twov16b_POST);
Oliver Stannard89d15422014-08-27 16:16:04 +00003062 else if (VT == MVT::v4i16 || VT == MVT::v4f16)
Tim Northover3b0846e2014-05-24 12:50:23 +00003063 return SelectPostStore(Node, 2, AArch64::ST2Twov4h_POST);
Oliver Stannard89d15422014-08-27 16:16:04 +00003064 else if (VT == MVT::v8i16 || VT == MVT::v8f16)
Tim Northover3b0846e2014-05-24 12:50:23 +00003065 return SelectPostStore(Node, 2, AArch64::ST2Twov8h_POST);
3066 else if (VT == MVT::v2i32 || VT == MVT::v2f32)
3067 return SelectPostStore(Node, 2, AArch64::ST2Twov2s_POST);
3068 else if (VT == MVT::v4i32 || VT == MVT::v4f32)
3069 return SelectPostStore(Node, 2, AArch64::ST2Twov4s_POST);
3070 else if (VT == MVT::v2i64 || VT == MVT::v2f64)
3071 return SelectPostStore(Node, 2, AArch64::ST2Twov2d_POST);
3072 else if (VT == MVT::v1i64 || VT == MVT::v1f64)
3073 return SelectPostStore(Node, 2, AArch64::ST1Twov1d_POST);
3074 break;
3075 }
3076 case AArch64ISD::ST3post: {
3077 VT = Node->getOperand(1).getValueType();
3078 if (VT == MVT::v8i8)
3079 return SelectPostStore(Node, 3, AArch64::ST3Threev8b_POST);
3080 else if (VT == MVT::v16i8)
3081 return SelectPostStore(Node, 3, AArch64::ST3Threev16b_POST);
Oliver Stannard89d15422014-08-27 16:16:04 +00003082 else if (VT == MVT::v4i16 || VT == MVT::v4f16)
Tim Northover3b0846e2014-05-24 12:50:23 +00003083 return SelectPostStore(Node, 3, AArch64::ST3Threev4h_POST);
Oliver Stannard89d15422014-08-27 16:16:04 +00003084 else if (VT == MVT::v8i16 || VT == MVT::v8f16)
Tim Northover3b0846e2014-05-24 12:50:23 +00003085 return SelectPostStore(Node, 3, AArch64::ST3Threev8h_POST);
3086 else if (VT == MVT::v2i32 || VT == MVT::v2f32)
3087 return SelectPostStore(Node, 3, AArch64::ST3Threev2s_POST);
3088 else if (VT == MVT::v4i32 || VT == MVT::v4f32)
3089 return SelectPostStore(Node, 3, AArch64::ST3Threev4s_POST);
3090 else if (VT == MVT::v2i64 || VT == MVT::v2f64)
3091 return SelectPostStore(Node, 3, AArch64::ST3Threev2d_POST);
3092 else if (VT == MVT::v1i64 || VT == MVT::v1f64)
3093 return SelectPostStore(Node, 3, AArch64::ST1Threev1d_POST);
3094 break;
3095 }
3096 case AArch64ISD::ST4post: {
3097 VT = Node->getOperand(1).getValueType();
3098 if (VT == MVT::v8i8)
3099 return SelectPostStore(Node, 4, AArch64::ST4Fourv8b_POST);
3100 else if (VT == MVT::v16i8)
3101 return SelectPostStore(Node, 4, AArch64::ST4Fourv16b_POST);
Oliver Stannard89d15422014-08-27 16:16:04 +00003102 else if (VT == MVT::v4i16 || VT == MVT::v4f16)
Tim Northover3b0846e2014-05-24 12:50:23 +00003103 return SelectPostStore(Node, 4, AArch64::ST4Fourv4h_POST);
Oliver Stannard89d15422014-08-27 16:16:04 +00003104 else if (VT == MVT::v8i16 || VT == MVT::v8f16)
Tim Northover3b0846e2014-05-24 12:50:23 +00003105 return SelectPostStore(Node, 4, AArch64::ST4Fourv8h_POST);
3106 else if (VT == MVT::v2i32 || VT == MVT::v2f32)
3107 return SelectPostStore(Node, 4, AArch64::ST4Fourv2s_POST);
3108 else if (VT == MVT::v4i32 || VT == MVT::v4f32)
3109 return SelectPostStore(Node, 4, AArch64::ST4Fourv4s_POST);
3110 else if (VT == MVT::v2i64 || VT == MVT::v2f64)
3111 return SelectPostStore(Node, 4, AArch64::ST4Fourv2d_POST);
3112 else if (VT == MVT::v1i64 || VT == MVT::v1f64)
3113 return SelectPostStore(Node, 4, AArch64::ST1Fourv1d_POST);
3114 break;
3115 }
3116 case AArch64ISD::ST1x2post: {
3117 VT = Node->getOperand(1).getValueType();
3118 if (VT == MVT::v8i8)
3119 return SelectPostStore(Node, 2, AArch64::ST1Twov8b_POST);
3120 else if (VT == MVT::v16i8)
3121 return SelectPostStore(Node, 2, AArch64::ST1Twov16b_POST);
Oliver Stannard89d15422014-08-27 16:16:04 +00003122 else if (VT == MVT::v4i16 || VT == MVT::v4f16)
Tim Northover3b0846e2014-05-24 12:50:23 +00003123 return SelectPostStore(Node, 2, AArch64::ST1Twov4h_POST);
Oliver Stannard89d15422014-08-27 16:16:04 +00003124 else if (VT == MVT::v8i16 || VT == MVT::v8f16)
Tim Northover3b0846e2014-05-24 12:50:23 +00003125 return SelectPostStore(Node, 2, AArch64::ST1Twov8h_POST);
3126 else if (VT == MVT::v2i32 || VT == MVT::v2f32)
3127 return SelectPostStore(Node, 2, AArch64::ST1Twov2s_POST);
3128 else if (VT == MVT::v4i32 || VT == MVT::v4f32)
3129 return SelectPostStore(Node, 2, AArch64::ST1Twov4s_POST);
3130 else if (VT == MVT::v1i64 || VT == MVT::v1f64)
3131 return SelectPostStore(Node, 2, AArch64::ST1Twov1d_POST);
3132 else if (VT == MVT::v2i64 || VT == MVT::v2f64)
3133 return SelectPostStore(Node, 2, AArch64::ST1Twov2d_POST);
3134 break;
3135 }
3136 case AArch64ISD::ST1x3post: {
3137 VT = Node->getOperand(1).getValueType();
3138 if (VT == MVT::v8i8)
3139 return SelectPostStore(Node, 3, AArch64::ST1Threev8b_POST);
3140 else if (VT == MVT::v16i8)
3141 return SelectPostStore(Node, 3, AArch64::ST1Threev16b_POST);
Oliver Stannard89d15422014-08-27 16:16:04 +00003142 else if (VT == MVT::v4i16 || VT == MVT::v4f16)
Tim Northover3b0846e2014-05-24 12:50:23 +00003143 return SelectPostStore(Node, 3, AArch64::ST1Threev4h_POST);
Oliver Stannard89d15422014-08-27 16:16:04 +00003144 else if (VT == MVT::v8i16 || VT == MVT::v8f16)
Tim Northover3b0846e2014-05-24 12:50:23 +00003145 return SelectPostStore(Node, 3, AArch64::ST1Threev8h_POST);
3146 else if (VT == MVT::v2i32 || VT == MVT::v2f32)
3147 return SelectPostStore(Node, 3, AArch64::ST1Threev2s_POST);
3148 else if (VT == MVT::v4i32 || VT == MVT::v4f32)
3149 return SelectPostStore(Node, 3, AArch64::ST1Threev4s_POST);
3150 else if (VT == MVT::v1i64 || VT == MVT::v1f64)
3151 return SelectPostStore(Node, 3, AArch64::ST1Threev1d_POST);
3152 else if (VT == MVT::v2i64 || VT == MVT::v2f64)
3153 return SelectPostStore(Node, 3, AArch64::ST1Threev2d_POST);
3154 break;
3155 }
3156 case AArch64ISD::ST1x4post: {
3157 VT = Node->getOperand(1).getValueType();
3158 if (VT == MVT::v8i8)
3159 return SelectPostStore(Node, 4, AArch64::ST1Fourv8b_POST);
3160 else if (VT == MVT::v16i8)
3161 return SelectPostStore(Node, 4, AArch64::ST1Fourv16b_POST);
Oliver Stannard89d15422014-08-27 16:16:04 +00003162 else if (VT == MVT::v4i16 || VT == MVT::v4f16)
Tim Northover3b0846e2014-05-24 12:50:23 +00003163 return SelectPostStore(Node, 4, AArch64::ST1Fourv4h_POST);
Oliver Stannard89d15422014-08-27 16:16:04 +00003164 else if (VT == MVT::v8i16 || VT == MVT::v8f16)
Tim Northover3b0846e2014-05-24 12:50:23 +00003165 return SelectPostStore(Node, 4, AArch64::ST1Fourv8h_POST);
3166 else if (VT == MVT::v2i32 || VT == MVT::v2f32)
3167 return SelectPostStore(Node, 4, AArch64::ST1Fourv2s_POST);
3168 else if (VT == MVT::v4i32 || VT == MVT::v4f32)
3169 return SelectPostStore(Node, 4, AArch64::ST1Fourv4s_POST);
3170 else if (VT == MVT::v1i64 || VT == MVT::v1f64)
3171 return SelectPostStore(Node, 4, AArch64::ST1Fourv1d_POST);
3172 else if (VT == MVT::v2i64 || VT == MVT::v2f64)
3173 return SelectPostStore(Node, 4, AArch64::ST1Fourv2d_POST);
3174 break;
3175 }
3176 case AArch64ISD::ST2LANEpost: {
3177 VT = Node->getOperand(1).getValueType();
3178 if (VT == MVT::v16i8 || VT == MVT::v8i8)
3179 return SelectPostStoreLane(Node, 2, AArch64::ST2i8_POST);
Oliver Stannard89d15422014-08-27 16:16:04 +00003180 else if (VT == MVT::v8i16 || VT == MVT::v4i16 || VT == MVT::v4f16 ||
3181 VT == MVT::v8f16)
Tim Northover3b0846e2014-05-24 12:50:23 +00003182 return SelectPostStoreLane(Node, 2, AArch64::ST2i16_POST);
3183 else if (VT == MVT::v4i32 || VT == MVT::v2i32 || VT == MVT::v4f32 ||
3184 VT == MVT::v2f32)
3185 return SelectPostStoreLane(Node, 2, AArch64::ST2i32_POST);
3186 else if (VT == MVT::v2i64 || VT == MVT::v1i64 || VT == MVT::v2f64 ||
3187 VT == MVT::v1f64)
3188 return SelectPostStoreLane(Node, 2, AArch64::ST2i64_POST);
3189 break;
3190 }
3191 case AArch64ISD::ST3LANEpost: {
3192 VT = Node->getOperand(1).getValueType();
3193 if (VT == MVT::v16i8 || VT == MVT::v8i8)
3194 return SelectPostStoreLane(Node, 3, AArch64::ST3i8_POST);
Oliver Stannard89d15422014-08-27 16:16:04 +00003195 else if (VT == MVT::v8i16 || VT == MVT::v4i16 || VT == MVT::v4f16 ||
3196 VT == MVT::v8f16)
Tim Northover3b0846e2014-05-24 12:50:23 +00003197 return SelectPostStoreLane(Node, 3, AArch64::ST3i16_POST);
3198 else if (VT == MVT::v4i32 || VT == MVT::v2i32 || VT == MVT::v4f32 ||
3199 VT == MVT::v2f32)
3200 return SelectPostStoreLane(Node, 3, AArch64::ST3i32_POST);
3201 else if (VT == MVT::v2i64 || VT == MVT::v1i64 || VT == MVT::v2f64 ||
3202 VT == MVT::v1f64)
3203 return SelectPostStoreLane(Node, 3, AArch64::ST3i64_POST);
3204 break;
3205 }
3206 case AArch64ISD::ST4LANEpost: {
3207 VT = Node->getOperand(1).getValueType();
3208 if (VT == MVT::v16i8 || VT == MVT::v8i8)
3209 return SelectPostStoreLane(Node, 4, AArch64::ST4i8_POST);
Oliver Stannard89d15422014-08-27 16:16:04 +00003210 else if (VT == MVT::v8i16 || VT == MVT::v4i16 || VT == MVT::v4f16 ||
3211 VT == MVT::v8f16)
Tim Northover3b0846e2014-05-24 12:50:23 +00003212 return SelectPostStoreLane(Node, 4, AArch64::ST4i16_POST);
3213 else if (VT == MVT::v4i32 || VT == MVT::v2i32 || VT == MVT::v4f32 ||
3214 VT == MVT::v2f32)
3215 return SelectPostStoreLane(Node, 4, AArch64::ST4i32_POST);
3216 else if (VT == MVT::v2i64 || VT == MVT::v1i64 || VT == MVT::v2f64 ||
3217 VT == MVT::v1f64)
3218 return SelectPostStoreLane(Node, 4, AArch64::ST4i64_POST);
3219 break;
3220 }
3221
3222 case ISD::FCEIL:
3223 case ISD::FFLOOR:
3224 case ISD::FTRUNC:
3225 case ISD::FROUND:
3226 if (SDNode *I = SelectLIBM(Node))
3227 return I;
3228 break;
3229 }
3230
3231 // Select the default instruction
3232 ResNode = SelectCode(Node);
3233
3234 DEBUG(errs() << "=> ");
3235 if (ResNode == nullptr || ResNode == Node)
3236 DEBUG(Node->dump(CurDAG));
3237 else
3238 DEBUG(ResNode->dump(CurDAG));
3239 DEBUG(errs() << "\n");
3240
3241 return ResNode;
3242}
3243
3244/// createAArch64ISelDag - This pass converts a legalized DAG into a
3245/// AArch64-specific DAG, ready for instruction scheduling.
3246FunctionPass *llvm::createAArch64ISelDag(AArch64TargetMachine &TM,
3247 CodeGenOpt::Level OptLevel) {
3248 return new AArch64DAGToDAGISel(TM, OptLevel);
3249}