blob: c5777598b65185d0b63e395f3bfad34f5fa15881 [file] [log] [blame]
Ahmed Bougacha6756a2c2016-07-27 14:31:55 +00001//===- AArch64InstructionSelector.cpp ----------------------------*- C++ -*-==//
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/// \file
10/// This file implements the targeting of the InstructionSelector class for
11/// AArch64.
12/// \todo This should be generated by TableGen.
13//===----------------------------------------------------------------------===//
14
15#include "AArch64InstructionSelector.h"
16#include "AArch64InstrInfo.h"
17#include "AArch64RegisterBankInfo.h"
18#include "AArch64RegisterInfo.h"
19#include "AArch64Subtarget.h"
Tim Northoverbdf16242016-10-10 21:50:00 +000020#include "AArch64TargetMachine.h"
Ahmed Bougacha6756a2c2016-07-27 14:31:55 +000021#include "llvm/CodeGen/MachineBasicBlock.h"
22#include "llvm/CodeGen/MachineFunction.h"
23#include "llvm/CodeGen/MachineInstr.h"
24#include "llvm/CodeGen/MachineInstrBuilder.h"
25#include "llvm/CodeGen/MachineRegisterInfo.h"
26#include "llvm/IR/Type.h"
27#include "llvm/Support/Debug.h"
28#include "llvm/Support/raw_ostream.h"
29
30#define DEBUG_TYPE "aarch64-isel"
31
32using namespace llvm;
33
34#ifndef LLVM_BUILD_GLOBAL_ISEL
35#error "You shouldn't build this"
36#endif
37
38AArch64InstructionSelector::AArch64InstructionSelector(
Tim Northoverbdf16242016-10-10 21:50:00 +000039 const AArch64TargetMachine &TM, const AArch64Subtarget &STI,
40 const AArch64RegisterBankInfo &RBI)
41 : InstructionSelector(), TM(TM), STI(STI), TII(*STI.getInstrInfo()),
Ahmed Bougacha6756a2c2016-07-27 14:31:55 +000042 TRI(*STI.getRegisterInfo()), RBI(RBI) {}
43
Tim Northoverfb8d9892016-10-12 22:49:15 +000044// FIXME: This should be target-independent, inferred from the types declared
45// for each class in the bank.
46static const TargetRegisterClass *
47getRegClassForTypeOnBank(LLT Ty, const RegisterBank &RB,
48 const RegisterBankInfo &RBI) {
49 if (RB.getID() == AArch64::GPRRegBankID) {
50 if (Ty.getSizeInBits() <= 32)
51 return &AArch64::GPR32RegClass;
52 if (Ty.getSizeInBits() == 64)
53 return &AArch64::GPR64RegClass;
54 return nullptr;
55 }
56
57 if (RB.getID() == AArch64::FPRRegBankID) {
58 if (Ty.getSizeInBits() == 32)
59 return &AArch64::FPR32RegClass;
60 if (Ty.getSizeInBits() == 64)
61 return &AArch64::FPR64RegClass;
62 if (Ty.getSizeInBits() == 128)
63 return &AArch64::FPR128RegClass;
64 return nullptr;
65 }
66
67 return nullptr;
68}
69
Ahmed Bougacha59e160a2016-08-16 14:37:40 +000070/// Check whether \p I is a currently unsupported binary operation:
71/// - it has an unsized type
72/// - an operand is not a vreg
73/// - all operands are not in the same bank
74/// These are checks that should someday live in the verifier, but right now,
75/// these are mostly limitations of the aarch64 selector.
76static bool unsupportedBinOp(const MachineInstr &I,
77 const AArch64RegisterBankInfo &RBI,
78 const MachineRegisterInfo &MRI,
79 const AArch64RegisterInfo &TRI) {
Tim Northover0f140c72016-09-09 11:46:34 +000080 LLT Ty = MRI.getType(I.getOperand(0).getReg());
Tim Northover32a078a2016-09-15 10:09:59 +000081 if (!Ty.isValid()) {
82 DEBUG(dbgs() << "Generic binop register should be typed\n");
Ahmed Bougacha59e160a2016-08-16 14:37:40 +000083 return true;
84 }
85
86 const RegisterBank *PrevOpBank = nullptr;
87 for (auto &MO : I.operands()) {
88 // FIXME: Support non-register operands.
89 if (!MO.isReg()) {
90 DEBUG(dbgs() << "Generic inst non-reg operands are unsupported\n");
91 return true;
92 }
93
94 // FIXME: Can generic operations have physical registers operands? If
95 // so, this will need to be taught about that, and we'll need to get the
96 // bank out of the minimal class for the register.
97 // Either way, this needs to be documented (and possibly verified).
98 if (!TargetRegisterInfo::isVirtualRegister(MO.getReg())) {
99 DEBUG(dbgs() << "Generic inst has physical register operand\n");
100 return true;
101 }
102
103 const RegisterBank *OpBank = RBI.getRegBank(MO.getReg(), MRI, TRI);
104 if (!OpBank) {
105 DEBUG(dbgs() << "Generic register has no bank or class\n");
106 return true;
107 }
108
109 if (PrevOpBank && OpBank != PrevOpBank) {
110 DEBUG(dbgs() << "Generic inst operands have different banks\n");
111 return true;
112 }
113 PrevOpBank = OpBank;
114 }
115 return false;
116}
117
Ahmed Bougacha6756a2c2016-07-27 14:31:55 +0000118/// Select the AArch64 opcode for the basic binary operation \p GenericOpc
119/// (such as G_OR or G_ADD), appropriate for the register bank \p RegBankID
120/// and of size \p OpSize.
121/// \returns \p GenericOpc if the combination is unsupported.
122static unsigned selectBinaryOp(unsigned GenericOpc, unsigned RegBankID,
123 unsigned OpSize) {
124 switch (RegBankID) {
125 case AArch64::GPRRegBankID:
Tim Northover55782222016-10-18 20:03:48 +0000126 if (OpSize <= 32) {
127 assert((OpSize == 32 || (GenericOpc != TargetOpcode::G_SDIV &&
128 GenericOpc != TargetOpcode::G_UDIV &&
129 GenericOpc != TargetOpcode::G_LSHR &&
130 GenericOpc != TargetOpcode::G_ASHR)) &&
131 "operation should have been legalized before now");
132
Ahmed Bougacha6756a2c2016-07-27 14:31:55 +0000133 switch (GenericOpc) {
134 case TargetOpcode::G_OR:
135 return AArch64::ORRWrr;
Ahmed Bougacha6db3cfe2016-07-29 16:56:25 +0000136 case TargetOpcode::G_XOR:
137 return AArch64::EORWrr;
Ahmed Bougacha61a79282016-07-28 16:58:31 +0000138 case TargetOpcode::G_AND:
139 return AArch64::ANDWrr;
Ahmed Bougacha6756a2c2016-07-27 14:31:55 +0000140 case TargetOpcode::G_ADD:
141 return AArch64::ADDWrr;
Ahmed Bougachad7748d62016-07-28 16:58:35 +0000142 case TargetOpcode::G_SUB:
143 return AArch64::SUBWrr;
Ahmed Bougacha2ac5bf92016-08-16 14:02:47 +0000144 case TargetOpcode::G_SHL:
145 return AArch64::LSLVWr;
146 case TargetOpcode::G_LSHR:
147 return AArch64::LSRVWr;
148 case TargetOpcode::G_ASHR:
149 return AArch64::ASRVWr;
Ahmed Bougacha1d0560b2016-08-18 15:17:13 +0000150 case TargetOpcode::G_SDIV:
151 return AArch64::SDIVWr;
152 case TargetOpcode::G_UDIV:
153 return AArch64::UDIVWr;
Ahmed Bougacha6756a2c2016-07-27 14:31:55 +0000154 default:
155 return GenericOpc;
156 }
Tim Northover55782222016-10-18 20:03:48 +0000157 } else if (OpSize == 64) {
Ahmed Bougacha6756a2c2016-07-27 14:31:55 +0000158 switch (GenericOpc) {
159 case TargetOpcode::G_OR:
160 return AArch64::ORRXrr;
Ahmed Bougacha6db3cfe2016-07-29 16:56:25 +0000161 case TargetOpcode::G_XOR:
162 return AArch64::EORXrr;
Ahmed Bougacha61a79282016-07-28 16:58:31 +0000163 case TargetOpcode::G_AND:
164 return AArch64::ANDXrr;
Ahmed Bougacha6756a2c2016-07-27 14:31:55 +0000165 case TargetOpcode::G_ADD:
Tim Northover2fda4b02016-10-10 21:49:49 +0000166 case TargetOpcode::G_GEP:
Ahmed Bougacha6756a2c2016-07-27 14:31:55 +0000167 return AArch64::ADDXrr;
Ahmed Bougachad7748d62016-07-28 16:58:35 +0000168 case TargetOpcode::G_SUB:
169 return AArch64::SUBXrr;
Ahmed Bougacha2ac5bf92016-08-16 14:02:47 +0000170 case TargetOpcode::G_SHL:
171 return AArch64::LSLVXr;
172 case TargetOpcode::G_LSHR:
173 return AArch64::LSRVXr;
174 case TargetOpcode::G_ASHR:
175 return AArch64::ASRVXr;
Ahmed Bougacha1d0560b2016-08-18 15:17:13 +0000176 case TargetOpcode::G_SDIV:
177 return AArch64::SDIVXr;
178 case TargetOpcode::G_UDIV:
179 return AArch64::UDIVXr;
Ahmed Bougacha6756a2c2016-07-27 14:31:55 +0000180 default:
181 return GenericOpc;
182 }
183 }
Ahmed Bougacha33e19fe2016-08-18 16:05:11 +0000184 case AArch64::FPRRegBankID:
185 switch (OpSize) {
186 case 32:
187 switch (GenericOpc) {
188 case TargetOpcode::G_FADD:
189 return AArch64::FADDSrr;
190 case TargetOpcode::G_FSUB:
191 return AArch64::FSUBSrr;
192 case TargetOpcode::G_FMUL:
193 return AArch64::FMULSrr;
194 case TargetOpcode::G_FDIV:
195 return AArch64::FDIVSrr;
196 default:
197 return GenericOpc;
198 }
199 case 64:
200 switch (GenericOpc) {
201 case TargetOpcode::G_FADD:
202 return AArch64::FADDDrr;
203 case TargetOpcode::G_FSUB:
204 return AArch64::FSUBDrr;
205 case TargetOpcode::G_FMUL:
206 return AArch64::FMULDrr;
207 case TargetOpcode::G_FDIV:
208 return AArch64::FDIVDrr;
Quentin Colombet0e531272016-10-11 00:21:11 +0000209 case TargetOpcode::G_OR:
210 return AArch64::ORRv8i8;
Ahmed Bougacha33e19fe2016-08-18 16:05:11 +0000211 default:
212 return GenericOpc;
213 }
214 }
Ahmed Bougacha6756a2c2016-07-27 14:31:55 +0000215 };
216 return GenericOpc;
217}
218
Ahmed Bougacha7adfac52016-07-29 16:56:16 +0000219/// Select the AArch64 opcode for the G_LOAD or G_STORE operation \p GenericOpc,
220/// appropriate for the (value) register bank \p RegBankID and of memory access
221/// size \p OpSize. This returns the variant with the base+unsigned-immediate
222/// addressing mode (e.g., LDRXui).
223/// \returns \p GenericOpc if the combination is unsupported.
224static unsigned selectLoadStoreUIOp(unsigned GenericOpc, unsigned RegBankID,
225 unsigned OpSize) {
226 const bool isStore = GenericOpc == TargetOpcode::G_STORE;
227 switch (RegBankID) {
228 case AArch64::GPRRegBankID:
229 switch (OpSize) {
Tim Northover020d1042016-10-17 18:36:53 +0000230 case 8:
231 return isStore ? AArch64::STRBBui : AArch64::LDRBBui;
232 case 16:
233 return isStore ? AArch64::STRHHui : AArch64::LDRHHui;
Ahmed Bougacha7adfac52016-07-29 16:56:16 +0000234 case 32:
235 return isStore ? AArch64::STRWui : AArch64::LDRWui;
236 case 64:
237 return isStore ? AArch64::STRXui : AArch64::LDRXui;
238 }
Quentin Colombetd2623f8e2016-10-11 00:21:14 +0000239 case AArch64::FPRRegBankID:
240 switch (OpSize) {
Tim Northover020d1042016-10-17 18:36:53 +0000241 case 8:
242 return isStore ? AArch64::STRBui : AArch64::LDRBui;
243 case 16:
244 return isStore ? AArch64::STRHui : AArch64::LDRHui;
Quentin Colombetd2623f8e2016-10-11 00:21:14 +0000245 case 32:
246 return isStore ? AArch64::STRSui : AArch64::LDRSui;
247 case 64:
248 return isStore ? AArch64::STRDui : AArch64::LDRDui;
249 }
Ahmed Bougacha7adfac52016-07-29 16:56:16 +0000250 };
251 return GenericOpc;
252}
253
Quentin Colombetcb629a82016-10-12 03:57:49 +0000254static bool selectCopy(MachineInstr &I, const TargetInstrInfo &TII,
255 MachineRegisterInfo &MRI, const TargetRegisterInfo &TRI,
256 const RegisterBankInfo &RBI) {
257
258 unsigned DstReg = I.getOperand(0).getReg();
259 if (TargetRegisterInfo::isPhysicalRegister(DstReg)) {
260 assert(I.isCopy() && "Generic operators do not allow physical registers");
261 return true;
262 }
263
264 const RegisterBank &RegBank = *RBI.getRegBank(DstReg, MRI, TRI);
265 const unsigned DstSize = MRI.getType(DstReg).getSizeInBits();
266 unsigned SrcReg = I.getOperand(1).getReg();
267 const unsigned SrcSize = RBI.getSizeInBits(SrcReg, MRI, TRI);
268 (void)SrcSize;
269 assert((!TargetRegisterInfo::isPhysicalRegister(SrcReg) || I.isCopy()) &&
270 "No phys reg on generic operators");
271 assert(
272 (DstSize == SrcSize ||
273 // Copies are a mean to setup initial types, the number of
274 // bits may not exactly match.
275 (TargetRegisterInfo::isPhysicalRegister(SrcReg) &&
276 DstSize <= RBI.getSizeInBits(SrcReg, MRI, TRI)) ||
277 // Copies are a mean to copy bits around, as long as we are
278 // on the same register class, that's fine. Otherwise, that
279 // means we need some SUBREG_TO_REG or AND & co.
280 (((DstSize + 31) / 32 == (SrcSize + 31) / 32) && DstSize > SrcSize)) &&
281 "Copy with different width?!");
282 assert((DstSize <= 64 || RegBank.getID() == AArch64::FPRRegBankID) &&
283 "GPRs cannot get more than 64-bit width values");
284 const TargetRegisterClass *RC = nullptr;
285
286 if (RegBank.getID() == AArch64::FPRRegBankID) {
287 if (DstSize <= 32)
288 RC = &AArch64::FPR32RegClass;
289 else if (DstSize <= 64)
290 RC = &AArch64::FPR64RegClass;
291 else if (DstSize <= 128)
292 RC = &AArch64::FPR128RegClass;
293 else {
294 DEBUG(dbgs() << "Unexpected bitcast size " << DstSize << '\n');
295 return false;
296 }
297 } else {
298 assert(RegBank.getID() == AArch64::GPRRegBankID &&
299 "Bitcast for the flags?");
300 RC =
301 DstSize <= 32 ? &AArch64::GPR32allRegClass : &AArch64::GPR64allRegClass;
302 }
303
304 // No need to constrain SrcReg. It will get constrained when
305 // we hit another of its use or its defs.
306 // Copies do not have constraints.
307 if (!RBI.constrainGenericRegister(DstReg, *RC, MRI)) {
308 DEBUG(dbgs() << "Failed to constrain " << TII.getName(I.getOpcode())
309 << " operand\n");
310 return false;
311 }
312 I.setDesc(TII.get(AArch64::COPY));
313 return true;
314}
315
Tim Northover69271c62016-10-12 22:49:11 +0000316static unsigned selectFPConvOpc(unsigned GenericOpc, LLT DstTy, LLT SrcTy) {
317 if (!DstTy.isScalar() || !SrcTy.isScalar())
318 return GenericOpc;
319
320 const unsigned DstSize = DstTy.getSizeInBits();
321 const unsigned SrcSize = SrcTy.getSizeInBits();
322
323 switch (DstSize) {
324 case 32:
325 switch (SrcSize) {
326 case 32:
327 switch (GenericOpc) {
328 case TargetOpcode::G_SITOFP:
329 return AArch64::SCVTFUWSri;
330 case TargetOpcode::G_UITOFP:
331 return AArch64::UCVTFUWSri;
332 case TargetOpcode::G_FPTOSI:
333 return AArch64::FCVTZSUWSr;
334 case TargetOpcode::G_FPTOUI:
335 return AArch64::FCVTZUUWSr;
336 default:
337 return GenericOpc;
338 }
339 case 64:
340 switch (GenericOpc) {
341 case TargetOpcode::G_SITOFP:
342 return AArch64::SCVTFUXSri;
343 case TargetOpcode::G_UITOFP:
344 return AArch64::UCVTFUXSri;
345 case TargetOpcode::G_FPTOSI:
346 return AArch64::FCVTZSUWDr;
347 case TargetOpcode::G_FPTOUI:
348 return AArch64::FCVTZUUWDr;
349 default:
350 return GenericOpc;
351 }
352 default:
353 return GenericOpc;
354 }
355 case 64:
356 switch (SrcSize) {
357 case 32:
358 switch (GenericOpc) {
359 case TargetOpcode::G_SITOFP:
360 return AArch64::SCVTFUWDri;
361 case TargetOpcode::G_UITOFP:
362 return AArch64::UCVTFUWDri;
363 case TargetOpcode::G_FPTOSI:
364 return AArch64::FCVTZSUXSr;
365 case TargetOpcode::G_FPTOUI:
366 return AArch64::FCVTZUUXSr;
367 default:
368 return GenericOpc;
369 }
370 case 64:
371 switch (GenericOpc) {
372 case TargetOpcode::G_SITOFP:
373 return AArch64::SCVTFUXDri;
374 case TargetOpcode::G_UITOFP:
375 return AArch64::UCVTFUXDri;
376 case TargetOpcode::G_FPTOSI:
377 return AArch64::FCVTZSUXDr;
378 case TargetOpcode::G_FPTOUI:
379 return AArch64::FCVTZUUXDr;
380 default:
381 return GenericOpc;
382 }
383 default:
384 return GenericOpc;
385 }
386 default:
387 return GenericOpc;
388 };
389 return GenericOpc;
390}
391
Tim Northover6c02ad52016-10-12 22:49:04 +0000392static AArch64CC::CondCode changeICMPPredToAArch64CC(CmpInst::Predicate P) {
393 switch (P) {
394 default:
395 llvm_unreachable("Unknown condition code!");
396 case CmpInst::ICMP_NE:
397 return AArch64CC::NE;
398 case CmpInst::ICMP_EQ:
399 return AArch64CC::EQ;
400 case CmpInst::ICMP_SGT:
401 return AArch64CC::GT;
402 case CmpInst::ICMP_SGE:
403 return AArch64CC::GE;
404 case CmpInst::ICMP_SLT:
405 return AArch64CC::LT;
406 case CmpInst::ICMP_SLE:
407 return AArch64CC::LE;
408 case CmpInst::ICMP_UGT:
409 return AArch64CC::HI;
410 case CmpInst::ICMP_UGE:
411 return AArch64CC::HS;
412 case CmpInst::ICMP_ULT:
413 return AArch64CC::LO;
414 case CmpInst::ICMP_ULE:
415 return AArch64CC::LS;
416 }
417}
418
Tim Northover7dd378d2016-10-12 22:49:07 +0000419static void changeFCMPPredToAArch64CC(CmpInst::Predicate P,
420 AArch64CC::CondCode &CondCode,
421 AArch64CC::CondCode &CondCode2) {
422 CondCode2 = AArch64CC::AL;
423 switch (P) {
424 default:
425 llvm_unreachable("Unknown FP condition!");
426 case CmpInst::FCMP_OEQ:
427 CondCode = AArch64CC::EQ;
428 break;
429 case CmpInst::FCMP_OGT:
430 CondCode = AArch64CC::GT;
431 break;
432 case CmpInst::FCMP_OGE:
433 CondCode = AArch64CC::GE;
434 break;
435 case CmpInst::FCMP_OLT:
436 CondCode = AArch64CC::MI;
437 break;
438 case CmpInst::FCMP_OLE:
439 CondCode = AArch64CC::LS;
440 break;
441 case CmpInst::FCMP_ONE:
442 CondCode = AArch64CC::MI;
443 CondCode2 = AArch64CC::GT;
444 break;
445 case CmpInst::FCMP_ORD:
446 CondCode = AArch64CC::VC;
447 break;
448 case CmpInst::FCMP_UNO:
449 CondCode = AArch64CC::VS;
450 break;
451 case CmpInst::FCMP_UEQ:
452 CondCode = AArch64CC::EQ;
453 CondCode2 = AArch64CC::VS;
454 break;
455 case CmpInst::FCMP_UGT:
456 CondCode = AArch64CC::HI;
457 break;
458 case CmpInst::FCMP_UGE:
459 CondCode = AArch64CC::PL;
460 break;
461 case CmpInst::FCMP_ULT:
462 CondCode = AArch64CC::LT;
463 break;
464 case CmpInst::FCMP_ULE:
465 CondCode = AArch64CC::LE;
466 break;
467 case CmpInst::FCMP_UNE:
468 CondCode = AArch64CC::NE;
469 break;
470 }
471}
472
Ahmed Bougacha6756a2c2016-07-27 14:31:55 +0000473bool AArch64InstructionSelector::select(MachineInstr &I) const {
474 assert(I.getParent() && "Instruction should be in a basic block!");
475 assert(I.getParent()->getParent() && "Instruction should be in a function!");
476
477 MachineBasicBlock &MBB = *I.getParent();
478 MachineFunction &MF = *MBB.getParent();
479 MachineRegisterInfo &MRI = MF.getRegInfo();
480
Tim Northovercdf23f12016-10-31 18:30:59 +0000481 unsigned Opcode = I.getOpcode();
482 if (!isPreISelGenericOpcode(I.getOpcode())) {
483 // Certain non-generic instructions also need some special handling.
484
485 if (Opcode == TargetOpcode::LOAD_STACK_GUARD)
486 return constrainSelectedInstRegOperands(I, TII, TRI, RBI);
487 else if (I.isCopy())
488 return selectCopy(I, TII, MRI, TRI, RBI);
489 else
490 return true;
491 }
492
Ahmed Bougacha6756a2c2016-07-27 14:31:55 +0000493
494 if (I.getNumOperands() != I.getNumExplicitOperands()) {
495 DEBUG(dbgs() << "Generic instruction has unexpected implicit operands\n");
496 return false;
497 }
498
Tim Northover32a078a2016-09-15 10:09:59 +0000499 LLT Ty =
500 I.getOperand(0).isReg() ? MRI.getType(I.getOperand(0).getReg()) : LLT{};
Ahmed Bougacha6756a2c2016-07-27 14:31:55 +0000501
Tim Northover69271c62016-10-12 22:49:11 +0000502 switch (Opcode) {
Ahmed Bougacha85505092016-07-28 17:15:15 +0000503 case TargetOpcode::G_BR: {
504 I.setDesc(TII.get(AArch64::B));
Ahmed Bougacha85505092016-07-28 17:15:15 +0000505 return true;
Ahmed Bougacha6756a2c2016-07-27 14:31:55 +0000506 }
507
Tim Northover5e3dbf32016-10-12 22:49:01 +0000508 case TargetOpcode::G_BRCOND: {
509 if (Ty.getSizeInBits() > 32) {
510 // We shouldn't need this on AArch64, but it would be implemented as an
511 // EXTRACT_SUBREG followed by a TBNZW because TBNZX has no encoding if the
512 // bit being tested is < 32.
513 DEBUG(dbgs() << "G_BRCOND has type: " << Ty
514 << ", expected at most 32-bits");
515 return false;
516 }
517
518 const unsigned CondReg = I.getOperand(0).getReg();
519 MachineBasicBlock *DestMBB = I.getOperand(1).getMBB();
520
521 auto MIB = BuildMI(MBB, I, I.getDebugLoc(), TII.get(AArch64::TBNZW))
522 .addUse(CondReg)
523 .addImm(/*bit offset=*/0)
524 .addMBB(DestMBB);
525
526 I.eraseFromParent();
527 return constrainSelectedInstRegOperands(*MIB.getInstr(), TII, TRI, RBI);
528 }
529
Tim Northover4494d692016-10-18 19:47:57 +0000530 case TargetOpcode::G_FCONSTANT:
Tim Northover4edc60d2016-10-10 21:49:42 +0000531 case TargetOpcode::G_CONSTANT: {
Tim Northover4494d692016-10-18 19:47:57 +0000532 const bool isFP = Opcode == TargetOpcode::G_FCONSTANT;
533
534 const LLT s32 = LLT::scalar(32);
535 const LLT s64 = LLT::scalar(64);
536 const LLT p0 = LLT::pointer(0, 64);
537
538 const unsigned DefReg = I.getOperand(0).getReg();
539 const LLT DefTy = MRI.getType(DefReg);
540 const unsigned DefSize = DefTy.getSizeInBits();
541 const RegisterBank &RB = *RBI.getRegBank(DefReg, MRI, TRI);
542
543 // FIXME: Redundant check, but even less readable when factored out.
544 if (isFP) {
545 if (Ty != s32 && Ty != s64) {
546 DEBUG(dbgs() << "Unable to materialize FP " << Ty
547 << " constant, expected: " << s32 << " or " << s64
548 << '\n');
549 return false;
550 }
551
552 if (RB.getID() != AArch64::FPRRegBankID) {
553 DEBUG(dbgs() << "Unable to materialize FP " << Ty
554 << " constant on bank: " << RB << ", expected: FPR\n");
555 return false;
556 }
557 } else {
558 if (Ty != s32 && Ty != s64 && Ty != p0) {
559 DEBUG(dbgs() << "Unable to materialize integer " << Ty
560 << " constant, expected: " << s32 << ", " << s64 << ", or "
561 << p0 << '\n');
562 return false;
563 }
564
565 if (RB.getID() != AArch64::GPRRegBankID) {
566 DEBUG(dbgs() << "Unable to materialize integer " << Ty
567 << " constant on bank: " << RB << ", expected: GPR\n");
568 return false;
569 }
570 }
571
572 const unsigned MovOpc =
573 DefSize == 32 ? AArch64::MOVi32imm : AArch64::MOVi64imm;
574
575 I.setDesc(TII.get(MovOpc));
576
577 if (isFP) {
578 const TargetRegisterClass &GPRRC =
579 DefSize == 32 ? AArch64::GPR32RegClass : AArch64::GPR64RegClass;
580 const TargetRegisterClass &FPRRC =
581 DefSize == 32 ? AArch64::FPR32RegClass : AArch64::FPR64RegClass;
582
583 const unsigned DefGPRReg = MRI.createVirtualRegister(&GPRRC);
584 MachineOperand &RegOp = I.getOperand(0);
585 RegOp.setReg(DefGPRReg);
586
587 BuildMI(MBB, std::next(I.getIterator()), I.getDebugLoc(),
588 TII.get(AArch64::COPY))
589 .addDef(DefReg)
590 .addUse(DefGPRReg);
591
592 if (!RBI.constrainGenericRegister(DefReg, FPRRC, MRI)) {
593 DEBUG(dbgs() << "Failed to constrain G_FCONSTANT def operand\n");
594 return false;
595 }
596
597 MachineOperand &ImmOp = I.getOperand(1);
598 // FIXME: Is going through int64_t always correct?
599 ImmOp.ChangeToImmediate(
600 ImmOp.getFPImm()->getValueAPF().bitcastToAPInt().getZExtValue());
601 }
602
603 constrainSelectedInstRegOperands(I, TII, TRI, RBI);
604 return true;
Tim Northover4edc60d2016-10-10 21:49:42 +0000605 }
606
Ahmed Bougacha0306b5e2016-08-16 14:02:42 +0000607 case TargetOpcode::G_FRAME_INDEX: {
608 // allocas and G_FRAME_INDEX are only supported in addrspace(0).
Tim Northover5ae83502016-09-15 09:20:34 +0000609 if (Ty != LLT::pointer(0, 64)) {
Tim Northover0f140c72016-09-09 11:46:34 +0000610 DEBUG(dbgs() << "G_FRAME_INDEX pointer has type: " << Ty
Tim Northover5ae83502016-09-15 09:20:34 +0000611 << ", expected: " << LLT::pointer(0, 64) << '\n');
Ahmed Bougacha0306b5e2016-08-16 14:02:42 +0000612 return false;
613 }
614
615 I.setDesc(TII.get(AArch64::ADDXri));
Ahmed Bougacha0306b5e2016-08-16 14:02:42 +0000616
617 // MOs for a #0 shifted immediate.
618 I.addOperand(MachineOperand::CreateImm(0));
619 I.addOperand(MachineOperand::CreateImm(0));
620
621 return constrainSelectedInstRegOperands(I, TII, TRI, RBI);
622 }
Tim Northoverbdf16242016-10-10 21:50:00 +0000623
624 case TargetOpcode::G_GLOBAL_VALUE: {
625 auto GV = I.getOperand(1).getGlobal();
626 if (GV->isThreadLocal()) {
627 // FIXME: we don't support TLS yet.
628 return false;
629 }
630 unsigned char OpFlags = STI.ClassifyGlobalReference(GV, TM);
631 if (OpFlags & AArch64II::MO_GOT)
632 I.setDesc(TII.get(AArch64::LOADgot));
633 else {
634 I.setDesc(TII.get(AArch64::MOVaddr));
635 I.getOperand(1).setTargetFlags(OpFlags | AArch64II::MO_PAGE);
636 MachineInstrBuilder MIB(MF, I);
637 MIB.addGlobalAddress(GV, I.getOperand(1).getOffset(),
638 OpFlags | AArch64II::MO_PAGEOFF | AArch64II::MO_NC);
639 }
640 return constrainSelectedInstRegOperands(I, TII, TRI, RBI);
641 }
642
Ahmed Bougacha7adfac52016-07-29 16:56:16 +0000643 case TargetOpcode::G_LOAD:
644 case TargetOpcode::G_STORE: {
Tim Northover0f140c72016-09-09 11:46:34 +0000645 LLT MemTy = Ty;
646 LLT PtrTy = MRI.getType(I.getOperand(1).getReg());
Ahmed Bougacha7adfac52016-07-29 16:56:16 +0000647
Tim Northover5ae83502016-09-15 09:20:34 +0000648 if (PtrTy != LLT::pointer(0, 64)) {
Ahmed Bougacha7adfac52016-07-29 16:56:16 +0000649 DEBUG(dbgs() << "Load/Store pointer has type: " << PtrTy
Tim Northover5ae83502016-09-15 09:20:34 +0000650 << ", expected: " << LLT::pointer(0, 64) << '\n');
Ahmed Bougacha7adfac52016-07-29 16:56:16 +0000651 return false;
652 }
653
654#ifndef NDEBUG
655 // Sanity-check the pointer register.
656 const unsigned PtrReg = I.getOperand(1).getReg();
657 const RegisterBank &PtrRB = *RBI.getRegBank(PtrReg, MRI, TRI);
658 assert(PtrRB.getID() == AArch64::GPRRegBankID &&
659 "Load/Store pointer operand isn't a GPR");
Tim Northover0f140c72016-09-09 11:46:34 +0000660 assert(MRI.getType(PtrReg).isPointer() &&
661 "Load/Store pointer operand isn't a pointer");
Ahmed Bougacha7adfac52016-07-29 16:56:16 +0000662#endif
663
664 const unsigned ValReg = I.getOperand(0).getReg();
665 const RegisterBank &RB = *RBI.getRegBank(ValReg, MRI, TRI);
666
667 const unsigned NewOpc =
668 selectLoadStoreUIOp(I.getOpcode(), RB.getID(), MemTy.getSizeInBits());
669 if (NewOpc == I.getOpcode())
670 return false;
671
672 I.setDesc(TII.get(NewOpc));
Ahmed Bougacha7adfac52016-07-29 16:56:16 +0000673
674 I.addOperand(MachineOperand::CreateImm(0));
675 return constrainSelectedInstRegOperands(I, TII, TRI, RBI);
676 }
677
Ahmed Bougachae4c03ab2016-08-16 14:37:46 +0000678 case TargetOpcode::G_MUL: {
679 // Reject the various things we don't support yet.
680 if (unsupportedBinOp(I, RBI, MRI, TRI))
681 return false;
682
683 const unsigned DefReg = I.getOperand(0).getReg();
684 const RegisterBank &RB = *RBI.getRegBank(DefReg, MRI, TRI);
685
686 if (RB.getID() != AArch64::GPRRegBankID) {
687 DEBUG(dbgs() << "G_MUL on bank: " << RB << ", expected: GPR\n");
688 return false;
689 }
690
691 unsigned ZeroReg;
692 unsigned NewOpc;
Tim Northover55782222016-10-18 20:03:48 +0000693 if (Ty.isScalar() && Ty.getSizeInBits() <= 32) {
Ahmed Bougachae4c03ab2016-08-16 14:37:46 +0000694 NewOpc = AArch64::MADDWrrr;
695 ZeroReg = AArch64::WZR;
696 } else if (Ty == LLT::scalar(64)) {
697 NewOpc = AArch64::MADDXrrr;
698 ZeroReg = AArch64::XZR;
699 } else {
700 DEBUG(dbgs() << "G_MUL has type: " << Ty << ", expected: "
701 << LLT::scalar(32) << " or " << LLT::scalar(64) << '\n');
702 return false;
703 }
704
705 I.setDesc(TII.get(NewOpc));
Ahmed Bougachae4c03ab2016-08-16 14:37:46 +0000706
707 I.addOperand(MachineOperand::CreateReg(ZeroReg, /*isDef=*/false));
708
709 // Now that we selected an opcode, we need to constrain the register
710 // operands to use appropriate classes.
711 return constrainSelectedInstRegOperands(I, TII, TRI, RBI);
712 }
713
Ahmed Bougacha33e19fe2016-08-18 16:05:11 +0000714 case TargetOpcode::G_FADD:
715 case TargetOpcode::G_FSUB:
716 case TargetOpcode::G_FMUL:
717 case TargetOpcode::G_FDIV:
718
Ahmed Bougacha6756a2c2016-07-27 14:31:55 +0000719 case TargetOpcode::G_OR:
Ahmed Bougacha6db3cfe2016-07-29 16:56:25 +0000720 case TargetOpcode::G_XOR:
Ahmed Bougacha61a79282016-07-28 16:58:31 +0000721 case TargetOpcode::G_AND:
Ahmed Bougacha2ac5bf92016-08-16 14:02:47 +0000722 case TargetOpcode::G_SHL:
723 case TargetOpcode::G_LSHR:
724 case TargetOpcode::G_ASHR:
Ahmed Bougacha1d0560b2016-08-18 15:17:13 +0000725 case TargetOpcode::G_SDIV:
726 case TargetOpcode::G_UDIV:
Ahmed Bougachad7748d62016-07-28 16:58:35 +0000727 case TargetOpcode::G_ADD:
Tim Northover2fda4b02016-10-10 21:49:49 +0000728 case TargetOpcode::G_SUB:
729 case TargetOpcode::G_GEP: {
Ahmed Bougacha6756a2c2016-07-27 14:31:55 +0000730 // Reject the various things we don't support yet.
Ahmed Bougacha59e160a2016-08-16 14:37:40 +0000731 if (unsupportedBinOp(I, RBI, MRI, TRI))
732 return false;
Ahmed Bougacha6756a2c2016-07-27 14:31:55 +0000733
Ahmed Bougacha59e160a2016-08-16 14:37:40 +0000734 const unsigned OpSize = Ty.getSizeInBits();
Ahmed Bougacha6756a2c2016-07-27 14:31:55 +0000735
736 const unsigned DefReg = I.getOperand(0).getReg();
737 const RegisterBank &RB = *RBI.getRegBank(DefReg, MRI, TRI);
738
739 const unsigned NewOpc = selectBinaryOp(I.getOpcode(), RB.getID(), OpSize);
740 if (NewOpc == I.getOpcode())
741 return false;
742
743 I.setDesc(TII.get(NewOpc));
744 // FIXME: Should the type be always reset in setDesc?
Ahmed Bougacha6756a2c2016-07-27 14:31:55 +0000745
746 // Now that we selected an opcode, we need to constrain the register
747 // operands to use appropriate classes.
748 return constrainSelectedInstRegOperands(I, TII, TRI, RBI);
749 }
Tim Northover3d38b3a2016-10-11 20:50:21 +0000750
Tim Northoverfb8d9892016-10-12 22:49:15 +0000751 case TargetOpcode::G_TRUNC: {
752 const LLT DstTy = MRI.getType(I.getOperand(0).getReg());
753 const LLT SrcTy = MRI.getType(I.getOperand(1).getReg());
754
755 const unsigned DstReg = I.getOperand(0).getReg();
756 const unsigned SrcReg = I.getOperand(1).getReg();
757
758 const RegisterBank &DstRB = *RBI.getRegBank(DstReg, MRI, TRI);
759 const RegisterBank &SrcRB = *RBI.getRegBank(SrcReg, MRI, TRI);
760
761 if (DstRB.getID() != SrcRB.getID()) {
762 DEBUG(dbgs() << "G_TRUNC input/output on different banks\n");
763 return false;
764 }
765
766 if (DstRB.getID() == AArch64::GPRRegBankID) {
767 const TargetRegisterClass *DstRC =
768 getRegClassForTypeOnBank(DstTy, DstRB, RBI);
769 if (!DstRC)
770 return false;
771
772 const TargetRegisterClass *SrcRC =
773 getRegClassForTypeOnBank(SrcTy, SrcRB, RBI);
774 if (!SrcRC)
775 return false;
776
777 if (!RBI.constrainGenericRegister(SrcReg, *SrcRC, MRI) ||
778 !RBI.constrainGenericRegister(DstReg, *DstRC, MRI)) {
779 DEBUG(dbgs() << "Failed to constrain G_TRUNC\n");
780 return false;
781 }
782
783 if (DstRC == SrcRC) {
784 // Nothing to be done
785 } else if (DstRC == &AArch64::GPR32RegClass &&
786 SrcRC == &AArch64::GPR64RegClass) {
787 I.getOperand(1).setSubReg(AArch64::sub_32);
788 } else {
789 return false;
790 }
791
792 I.setDesc(TII.get(TargetOpcode::COPY));
793 return true;
794 } else if (DstRB.getID() == AArch64::FPRRegBankID) {
795 if (DstTy == LLT::vector(4, 16) && SrcTy == LLT::vector(4, 32)) {
796 I.setDesc(TII.get(AArch64::XTNv4i16));
797 constrainSelectedInstRegOperands(I, TII, TRI, RBI);
798 return true;
799 }
800 }
801
802 return false;
803 }
804
Tim Northover3d38b3a2016-10-11 20:50:21 +0000805 case TargetOpcode::G_ANYEXT: {
806 const unsigned DstReg = I.getOperand(0).getReg();
807 const unsigned SrcReg = I.getOperand(1).getReg();
808
Quentin Colombetcb629a82016-10-12 03:57:49 +0000809 const RegisterBank &RBDst = *RBI.getRegBank(DstReg, MRI, TRI);
810 if (RBDst.getID() != AArch64::GPRRegBankID) {
811 DEBUG(dbgs() << "G_ANYEXT on bank: " << RBDst << ", expected: GPR\n");
812 return false;
813 }
Tim Northover3d38b3a2016-10-11 20:50:21 +0000814
Quentin Colombetcb629a82016-10-12 03:57:49 +0000815 const RegisterBank &RBSrc = *RBI.getRegBank(SrcReg, MRI, TRI);
816 if (RBSrc.getID() != AArch64::GPRRegBankID) {
817 DEBUG(dbgs() << "G_ANYEXT on bank: " << RBSrc << ", expected: GPR\n");
Tim Northover3d38b3a2016-10-11 20:50:21 +0000818 return false;
819 }
820
821 const unsigned DstSize = MRI.getType(DstReg).getSizeInBits();
822
823 if (DstSize == 0) {
824 DEBUG(dbgs() << "G_ANYEXT operand has no size, not a gvreg?\n");
825 return false;
826 }
827
Quentin Colombetcb629a82016-10-12 03:57:49 +0000828 if (DstSize != 64 && DstSize > 32) {
Tim Northover3d38b3a2016-10-11 20:50:21 +0000829 DEBUG(dbgs() << "G_ANYEXT to size: " << DstSize
830 << ", expected: 32 or 64\n");
831 return false;
832 }
Quentin Colombetcb629a82016-10-12 03:57:49 +0000833 // At this point G_ANYEXT is just like a plain COPY, but we need
834 // to explicitly form the 64-bit value if any.
835 if (DstSize > 32) {
836 unsigned ExtSrc = MRI.createVirtualRegister(&AArch64::GPR64allRegClass);
837 BuildMI(MBB, I, I.getDebugLoc(), TII.get(AArch64::SUBREG_TO_REG))
838 .addDef(ExtSrc)
839 .addImm(0)
840 .addUse(SrcReg)
841 .addImm(AArch64::sub_32);
842 I.getOperand(1).setReg(ExtSrc);
Tim Northover3d38b3a2016-10-11 20:50:21 +0000843 }
Quentin Colombetcb629a82016-10-12 03:57:49 +0000844 return selectCopy(I, TII, MRI, TRI, RBI);
Tim Northover3d38b3a2016-10-11 20:50:21 +0000845 }
846
847 case TargetOpcode::G_ZEXT:
848 case TargetOpcode::G_SEXT: {
849 unsigned Opcode = I.getOpcode();
850 const LLT DstTy = MRI.getType(I.getOperand(0).getReg()),
851 SrcTy = MRI.getType(I.getOperand(1).getReg());
852 const bool isSigned = Opcode == TargetOpcode::G_SEXT;
853 const unsigned DefReg = I.getOperand(0).getReg();
854 const unsigned SrcReg = I.getOperand(1).getReg();
855 const RegisterBank &RB = *RBI.getRegBank(DefReg, MRI, TRI);
856
857 if (RB.getID() != AArch64::GPRRegBankID) {
858 DEBUG(dbgs() << TII.getName(I.getOpcode()) << " on bank: " << RB
859 << ", expected: GPR\n");
860 return false;
861 }
862
863 MachineInstr *ExtI;
864 if (DstTy == LLT::scalar(64)) {
865 // FIXME: Can we avoid manually doing this?
866 if (!RBI.constrainGenericRegister(SrcReg, AArch64::GPR32RegClass, MRI)) {
867 DEBUG(dbgs() << "Failed to constrain " << TII.getName(Opcode)
868 << " operand\n");
869 return false;
870 }
871
872 const unsigned SrcXReg =
873 MRI.createVirtualRegister(&AArch64::GPR64RegClass);
874 BuildMI(MBB, I, I.getDebugLoc(), TII.get(AArch64::SUBREG_TO_REG))
875 .addDef(SrcXReg)
876 .addImm(0)
877 .addUse(SrcReg)
878 .addImm(AArch64::sub_32);
879
880 const unsigned NewOpc = isSigned ? AArch64::SBFMXri : AArch64::UBFMXri;
881 ExtI = BuildMI(MBB, I, I.getDebugLoc(), TII.get(NewOpc))
882 .addDef(DefReg)
883 .addUse(SrcXReg)
884 .addImm(0)
885 .addImm(SrcTy.getSizeInBits() - 1);
886 } else if (DstTy == LLT::scalar(32)) {
887 const unsigned NewOpc = isSigned ? AArch64::SBFMWri : AArch64::UBFMWri;
888 ExtI = BuildMI(MBB, I, I.getDebugLoc(), TII.get(NewOpc))
889 .addDef(DefReg)
890 .addUse(SrcReg)
891 .addImm(0)
892 .addImm(SrcTy.getSizeInBits() - 1);
893 } else {
894 return false;
895 }
896
897 constrainSelectedInstRegOperands(*ExtI, TII, TRI, RBI);
898
899 I.eraseFromParent();
900 return true;
901 }
Tim Northoverc1d8c2b2016-10-11 22:29:23 +0000902
Tim Northover69271c62016-10-12 22:49:11 +0000903 case TargetOpcode::G_SITOFP:
904 case TargetOpcode::G_UITOFP:
905 case TargetOpcode::G_FPTOSI:
906 case TargetOpcode::G_FPTOUI: {
907 const LLT DstTy = MRI.getType(I.getOperand(0).getReg()),
908 SrcTy = MRI.getType(I.getOperand(1).getReg());
909 const unsigned NewOpc = selectFPConvOpc(Opcode, DstTy, SrcTy);
910 if (NewOpc == Opcode)
911 return false;
912
913 I.setDesc(TII.get(NewOpc));
914 constrainSelectedInstRegOperands(I, TII, TRI, RBI);
915
916 return true;
917 }
918
919
Tim Northoverc1d8c2b2016-10-11 22:29:23 +0000920 case TargetOpcode::G_INTTOPTR:
921 case TargetOpcode::G_PTRTOINT:
Quentin Colombet9de30fa2016-10-12 03:57:52 +0000922 case TargetOpcode::G_BITCAST:
923 return selectCopy(I, TII, MRI, TRI, RBI);
Tim Northover6c02ad52016-10-12 22:49:04 +0000924
925 case TargetOpcode::G_ICMP: {
926 if (Ty != LLT::scalar(1)) {
927 DEBUG(dbgs() << "G_ICMP result has type: " << Ty
928 << ", expected: " << LLT::scalar(1) << '\n');
929 return false;
930 }
931
932 unsigned CmpOpc = 0;
933 unsigned ZReg = 0;
934
935 LLT CmpTy = MRI.getType(I.getOperand(2).getReg());
936 if (CmpTy == LLT::scalar(32)) {
937 CmpOpc = AArch64::SUBSWrr;
938 ZReg = AArch64::WZR;
939 } else if (CmpTy == LLT::scalar(64) || CmpTy.isPointer()) {
940 CmpOpc = AArch64::SUBSXrr;
941 ZReg = AArch64::XZR;
942 } else {
943 return false;
944 }
945
946 const AArch64CC::CondCode CC = changeICMPPredToAArch64CC(
947 (CmpInst::Predicate)I.getOperand(1).getPredicate());
948
949 MachineInstr &CmpMI = *BuildMI(MBB, I, I.getDebugLoc(), TII.get(CmpOpc))
950 .addDef(ZReg)
951 .addUse(I.getOperand(2).getReg())
952 .addUse(I.getOperand(3).getReg());
953
954 MachineInstr &CSetMI =
955 *BuildMI(MBB, I, I.getDebugLoc(), TII.get(AArch64::CSINCWr))
956 .addDef(I.getOperand(0).getReg())
957 .addUse(AArch64::WZR)
958 .addUse(AArch64::WZR)
959 .addImm(CC);
960
961 constrainSelectedInstRegOperands(CmpMI, TII, TRI, RBI);
962 constrainSelectedInstRegOperands(CSetMI, TII, TRI, RBI);
963
964 I.eraseFromParent();
965 return true;
966 }
967
Tim Northover7dd378d2016-10-12 22:49:07 +0000968 case TargetOpcode::G_FCMP: {
969 if (Ty != LLT::scalar(1)) {
970 DEBUG(dbgs() << "G_FCMP result has type: " << Ty
971 << ", expected: " << LLT::scalar(1) << '\n');
972 return false;
973 }
974
975 unsigned CmpOpc = 0;
976 LLT CmpTy = MRI.getType(I.getOperand(2).getReg());
977 if (CmpTy == LLT::scalar(32)) {
978 CmpOpc = AArch64::FCMPSrr;
979 } else if (CmpTy == LLT::scalar(64)) {
980 CmpOpc = AArch64::FCMPDrr;
981 } else {
982 return false;
983 }
984
985 // FIXME: regbank
986
987 AArch64CC::CondCode CC1, CC2;
988 changeFCMPPredToAArch64CC(
989 (CmpInst::Predicate)I.getOperand(1).getPredicate(), CC1, CC2);
990
991 MachineInstr &CmpMI = *BuildMI(MBB, I, I.getDebugLoc(), TII.get(CmpOpc))
992 .addUse(I.getOperand(2).getReg())
993 .addUse(I.getOperand(3).getReg());
994
995 const unsigned DefReg = I.getOperand(0).getReg();
996 unsigned Def1Reg = DefReg;
997 if (CC2 != AArch64CC::AL)
998 Def1Reg = MRI.createVirtualRegister(&AArch64::GPR32RegClass);
999
1000 MachineInstr &CSetMI =
1001 *BuildMI(MBB, I, I.getDebugLoc(), TII.get(AArch64::CSINCWr))
1002 .addDef(Def1Reg)
1003 .addUse(AArch64::WZR)
1004 .addUse(AArch64::WZR)
1005 .addImm(CC1);
1006
1007 if (CC2 != AArch64CC::AL) {
1008 unsigned Def2Reg = MRI.createVirtualRegister(&AArch64::GPR32RegClass);
1009 MachineInstr &CSet2MI =
1010 *BuildMI(MBB, I, I.getDebugLoc(), TII.get(AArch64::CSINCWr))
1011 .addDef(Def2Reg)
1012 .addUse(AArch64::WZR)
1013 .addUse(AArch64::WZR)
1014 .addImm(CC2);
1015 MachineInstr &OrMI =
1016 *BuildMI(MBB, I, I.getDebugLoc(), TII.get(AArch64::ORRWrr))
1017 .addDef(DefReg)
1018 .addUse(Def1Reg)
1019 .addUse(Def2Reg);
1020 constrainSelectedInstRegOperands(OrMI, TII, TRI, RBI);
1021 constrainSelectedInstRegOperands(CSet2MI, TII, TRI, RBI);
1022 }
1023
1024 constrainSelectedInstRegOperands(CmpMI, TII, TRI, RBI);
1025 constrainSelectedInstRegOperands(CSetMI, TII, TRI, RBI);
1026
1027 I.eraseFromParent();
1028 return true;
1029 }
Ahmed Bougacha6756a2c2016-07-27 14:31:55 +00001030 }
1031
1032 return false;
1033}