blob: 164beacea0d4678ee96c838f9894d9e72bf07a61 [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
Ahmed Bougacha59e160a2016-08-16 14:37:40 +000044/// Check whether \p I is a currently unsupported binary operation:
45/// - it has an unsized type
46/// - an operand is not a vreg
47/// - all operands are not in the same bank
48/// These are checks that should someday live in the verifier, but right now,
49/// these are mostly limitations of the aarch64 selector.
50static bool unsupportedBinOp(const MachineInstr &I,
51 const AArch64RegisterBankInfo &RBI,
52 const MachineRegisterInfo &MRI,
53 const AArch64RegisterInfo &TRI) {
Tim Northover0f140c72016-09-09 11:46:34 +000054 LLT Ty = MRI.getType(I.getOperand(0).getReg());
Tim Northover32a078a2016-09-15 10:09:59 +000055 if (!Ty.isValid()) {
56 DEBUG(dbgs() << "Generic binop register should be typed\n");
Ahmed Bougacha59e160a2016-08-16 14:37:40 +000057 return true;
58 }
59
60 const RegisterBank *PrevOpBank = nullptr;
61 for (auto &MO : I.operands()) {
62 // FIXME: Support non-register operands.
63 if (!MO.isReg()) {
64 DEBUG(dbgs() << "Generic inst non-reg operands are unsupported\n");
65 return true;
66 }
67
68 // FIXME: Can generic operations have physical registers operands? If
69 // so, this will need to be taught about that, and we'll need to get the
70 // bank out of the minimal class for the register.
71 // Either way, this needs to be documented (and possibly verified).
72 if (!TargetRegisterInfo::isVirtualRegister(MO.getReg())) {
73 DEBUG(dbgs() << "Generic inst has physical register operand\n");
74 return true;
75 }
76
77 const RegisterBank *OpBank = RBI.getRegBank(MO.getReg(), MRI, TRI);
78 if (!OpBank) {
79 DEBUG(dbgs() << "Generic register has no bank or class\n");
80 return true;
81 }
82
83 if (PrevOpBank && OpBank != PrevOpBank) {
84 DEBUG(dbgs() << "Generic inst operands have different banks\n");
85 return true;
86 }
87 PrevOpBank = OpBank;
88 }
89 return false;
90}
91
Ahmed Bougacha6756a2c2016-07-27 14:31:55 +000092/// Select the AArch64 opcode for the basic binary operation \p GenericOpc
93/// (such as G_OR or G_ADD), appropriate for the register bank \p RegBankID
94/// and of size \p OpSize.
95/// \returns \p GenericOpc if the combination is unsupported.
96static unsigned selectBinaryOp(unsigned GenericOpc, unsigned RegBankID,
97 unsigned OpSize) {
98 switch (RegBankID) {
99 case AArch64::GPRRegBankID:
100 switch (OpSize) {
101 case 32:
102 switch (GenericOpc) {
103 case TargetOpcode::G_OR:
104 return AArch64::ORRWrr;
Ahmed Bougacha6db3cfe2016-07-29 16:56:25 +0000105 case TargetOpcode::G_XOR:
106 return AArch64::EORWrr;
Ahmed Bougacha61a79282016-07-28 16:58:31 +0000107 case TargetOpcode::G_AND:
108 return AArch64::ANDWrr;
Ahmed Bougacha6756a2c2016-07-27 14:31:55 +0000109 case TargetOpcode::G_ADD:
110 return AArch64::ADDWrr;
Ahmed Bougachad7748d62016-07-28 16:58:35 +0000111 case TargetOpcode::G_SUB:
112 return AArch64::SUBWrr;
Ahmed Bougacha2ac5bf92016-08-16 14:02:47 +0000113 case TargetOpcode::G_SHL:
114 return AArch64::LSLVWr;
115 case TargetOpcode::G_LSHR:
116 return AArch64::LSRVWr;
117 case TargetOpcode::G_ASHR:
118 return AArch64::ASRVWr;
Ahmed Bougacha1d0560b2016-08-18 15:17:13 +0000119 case TargetOpcode::G_SDIV:
120 return AArch64::SDIVWr;
121 case TargetOpcode::G_UDIV:
122 return AArch64::UDIVWr;
Ahmed Bougacha6756a2c2016-07-27 14:31:55 +0000123 default:
124 return GenericOpc;
125 }
126 case 64:
127 switch (GenericOpc) {
128 case TargetOpcode::G_OR:
129 return AArch64::ORRXrr;
Ahmed Bougacha6db3cfe2016-07-29 16:56:25 +0000130 case TargetOpcode::G_XOR:
131 return AArch64::EORXrr;
Ahmed Bougacha61a79282016-07-28 16:58:31 +0000132 case TargetOpcode::G_AND:
133 return AArch64::ANDXrr;
Ahmed Bougacha6756a2c2016-07-27 14:31:55 +0000134 case TargetOpcode::G_ADD:
Tim Northover2fda4b02016-10-10 21:49:49 +0000135 case TargetOpcode::G_GEP:
Ahmed Bougacha6756a2c2016-07-27 14:31:55 +0000136 return AArch64::ADDXrr;
Ahmed Bougachad7748d62016-07-28 16:58:35 +0000137 case TargetOpcode::G_SUB:
138 return AArch64::SUBXrr;
Ahmed Bougacha2ac5bf92016-08-16 14:02:47 +0000139 case TargetOpcode::G_SHL:
140 return AArch64::LSLVXr;
141 case TargetOpcode::G_LSHR:
142 return AArch64::LSRVXr;
143 case TargetOpcode::G_ASHR:
144 return AArch64::ASRVXr;
Ahmed Bougacha1d0560b2016-08-18 15:17:13 +0000145 case TargetOpcode::G_SDIV:
146 return AArch64::SDIVXr;
147 case TargetOpcode::G_UDIV:
148 return AArch64::UDIVXr;
Ahmed Bougacha6756a2c2016-07-27 14:31:55 +0000149 default:
150 return GenericOpc;
151 }
152 }
Ahmed Bougacha33e19fe2016-08-18 16:05:11 +0000153 case AArch64::FPRRegBankID:
154 switch (OpSize) {
155 case 32:
156 switch (GenericOpc) {
157 case TargetOpcode::G_FADD:
158 return AArch64::FADDSrr;
159 case TargetOpcode::G_FSUB:
160 return AArch64::FSUBSrr;
161 case TargetOpcode::G_FMUL:
162 return AArch64::FMULSrr;
163 case TargetOpcode::G_FDIV:
164 return AArch64::FDIVSrr;
165 default:
166 return GenericOpc;
167 }
168 case 64:
169 switch (GenericOpc) {
170 case TargetOpcode::G_FADD:
171 return AArch64::FADDDrr;
172 case TargetOpcode::G_FSUB:
173 return AArch64::FSUBDrr;
174 case TargetOpcode::G_FMUL:
175 return AArch64::FMULDrr;
176 case TargetOpcode::G_FDIV:
177 return AArch64::FDIVDrr;
Quentin Colombet0e531272016-10-11 00:21:11 +0000178 case TargetOpcode::G_OR:
179 return AArch64::ORRv8i8;
Ahmed Bougacha33e19fe2016-08-18 16:05:11 +0000180 default:
181 return GenericOpc;
182 }
183 }
Ahmed Bougacha6756a2c2016-07-27 14:31:55 +0000184 };
185 return GenericOpc;
186}
187
Ahmed Bougacha7adfac52016-07-29 16:56:16 +0000188/// Select the AArch64 opcode for the G_LOAD or G_STORE operation \p GenericOpc,
189/// appropriate for the (value) register bank \p RegBankID and of memory access
190/// size \p OpSize. This returns the variant with the base+unsigned-immediate
191/// addressing mode (e.g., LDRXui).
192/// \returns \p GenericOpc if the combination is unsupported.
193static unsigned selectLoadStoreUIOp(unsigned GenericOpc, unsigned RegBankID,
194 unsigned OpSize) {
195 const bool isStore = GenericOpc == TargetOpcode::G_STORE;
196 switch (RegBankID) {
197 case AArch64::GPRRegBankID:
198 switch (OpSize) {
199 case 32:
200 return isStore ? AArch64::STRWui : AArch64::LDRWui;
201 case 64:
202 return isStore ? AArch64::STRXui : AArch64::LDRXui;
203 }
Quentin Colombetd2623f8e2016-10-11 00:21:14 +0000204 case AArch64::FPRRegBankID:
205 switch (OpSize) {
206 case 32:
207 return isStore ? AArch64::STRSui : AArch64::LDRSui;
208 case 64:
209 return isStore ? AArch64::STRDui : AArch64::LDRDui;
210 }
Ahmed Bougacha7adfac52016-07-29 16:56:16 +0000211 };
212 return GenericOpc;
213}
214
Ahmed Bougacha6756a2c2016-07-27 14:31:55 +0000215bool AArch64InstructionSelector::select(MachineInstr &I) const {
216 assert(I.getParent() && "Instruction should be in a basic block!");
217 assert(I.getParent()->getParent() && "Instruction should be in a function!");
218
219 MachineBasicBlock &MBB = *I.getParent();
220 MachineFunction &MF = *MBB.getParent();
221 MachineRegisterInfo &MRI = MF.getRegInfo();
222
223 // FIXME: Is there *really* nothing to be done here? This assumes that
224 // no upstream pass introduces things like generic vreg on copies or
225 // target-specific instructions.
226 // We should document (and verify) that assumption.
227 if (!isPreISelGenericOpcode(I.getOpcode()))
228 return true;
229
230 if (I.getNumOperands() != I.getNumExplicitOperands()) {
231 DEBUG(dbgs() << "Generic instruction has unexpected implicit operands\n");
232 return false;
233 }
234
Tim Northover32a078a2016-09-15 10:09:59 +0000235 LLT Ty =
236 I.getOperand(0).isReg() ? MRI.getType(I.getOperand(0).getReg()) : LLT{};
Ahmed Bougacha6756a2c2016-07-27 14:31:55 +0000237
Ahmed Bougacha85505092016-07-28 17:15:15 +0000238 switch (I.getOpcode()) {
239 case TargetOpcode::G_BR: {
240 I.setDesc(TII.get(AArch64::B));
Ahmed Bougacha85505092016-07-28 17:15:15 +0000241 return true;
Ahmed Bougacha6756a2c2016-07-27 14:31:55 +0000242 }
243
Tim Northover4edc60d2016-10-10 21:49:42 +0000244 case TargetOpcode::G_CONSTANT: {
245 if (Ty.getSizeInBits() <= 32)
246 I.setDesc(TII.get(AArch64::MOVi32imm));
247 else if (Ty.getSizeInBits() <= 64)
248 I.setDesc(TII.get(AArch64::MOVi64imm));
249 else
250 return false;
251 return constrainSelectedInstRegOperands(I, TII, TRI, RBI);
252 }
253
Ahmed Bougacha0306b5e2016-08-16 14:02:42 +0000254 case TargetOpcode::G_FRAME_INDEX: {
255 // allocas and G_FRAME_INDEX are only supported in addrspace(0).
Tim Northover5ae83502016-09-15 09:20:34 +0000256 if (Ty != LLT::pointer(0, 64)) {
Tim Northover0f140c72016-09-09 11:46:34 +0000257 DEBUG(dbgs() << "G_FRAME_INDEX pointer has type: " << Ty
Tim Northover5ae83502016-09-15 09:20:34 +0000258 << ", expected: " << LLT::pointer(0, 64) << '\n');
Ahmed Bougacha0306b5e2016-08-16 14:02:42 +0000259 return false;
260 }
261
262 I.setDesc(TII.get(AArch64::ADDXri));
Ahmed Bougacha0306b5e2016-08-16 14:02:42 +0000263
264 // MOs for a #0 shifted immediate.
265 I.addOperand(MachineOperand::CreateImm(0));
266 I.addOperand(MachineOperand::CreateImm(0));
267
268 return constrainSelectedInstRegOperands(I, TII, TRI, RBI);
269 }
Tim Northoverbdf16242016-10-10 21:50:00 +0000270
271 case TargetOpcode::G_GLOBAL_VALUE: {
272 auto GV = I.getOperand(1).getGlobal();
273 if (GV->isThreadLocal()) {
274 // FIXME: we don't support TLS yet.
275 return false;
276 }
277 unsigned char OpFlags = STI.ClassifyGlobalReference(GV, TM);
278 if (OpFlags & AArch64II::MO_GOT)
279 I.setDesc(TII.get(AArch64::LOADgot));
280 else {
281 I.setDesc(TII.get(AArch64::MOVaddr));
282 I.getOperand(1).setTargetFlags(OpFlags | AArch64II::MO_PAGE);
283 MachineInstrBuilder MIB(MF, I);
284 MIB.addGlobalAddress(GV, I.getOperand(1).getOffset(),
285 OpFlags | AArch64II::MO_PAGEOFF | AArch64II::MO_NC);
286 }
287 return constrainSelectedInstRegOperands(I, TII, TRI, RBI);
288 }
289
Ahmed Bougacha7adfac52016-07-29 16:56:16 +0000290 case TargetOpcode::G_LOAD:
291 case TargetOpcode::G_STORE: {
Tim Northover0f140c72016-09-09 11:46:34 +0000292 LLT MemTy = Ty;
293 LLT PtrTy = MRI.getType(I.getOperand(1).getReg());
Ahmed Bougacha7adfac52016-07-29 16:56:16 +0000294
Tim Northover5ae83502016-09-15 09:20:34 +0000295 if (PtrTy != LLT::pointer(0, 64)) {
Ahmed Bougacha7adfac52016-07-29 16:56:16 +0000296 DEBUG(dbgs() << "Load/Store pointer has type: " << PtrTy
Tim Northover5ae83502016-09-15 09:20:34 +0000297 << ", expected: " << LLT::pointer(0, 64) << '\n');
Ahmed Bougacha7adfac52016-07-29 16:56:16 +0000298 return false;
299 }
300
301#ifndef NDEBUG
302 // Sanity-check the pointer register.
303 const unsigned PtrReg = I.getOperand(1).getReg();
304 const RegisterBank &PtrRB = *RBI.getRegBank(PtrReg, MRI, TRI);
305 assert(PtrRB.getID() == AArch64::GPRRegBankID &&
306 "Load/Store pointer operand isn't a GPR");
Tim Northover0f140c72016-09-09 11:46:34 +0000307 assert(MRI.getType(PtrReg).isPointer() &&
308 "Load/Store pointer operand isn't a pointer");
Ahmed Bougacha7adfac52016-07-29 16:56:16 +0000309#endif
310
311 const unsigned ValReg = I.getOperand(0).getReg();
312 const RegisterBank &RB = *RBI.getRegBank(ValReg, MRI, TRI);
313
314 const unsigned NewOpc =
315 selectLoadStoreUIOp(I.getOpcode(), RB.getID(), MemTy.getSizeInBits());
316 if (NewOpc == I.getOpcode())
317 return false;
318
319 I.setDesc(TII.get(NewOpc));
Ahmed Bougacha7adfac52016-07-29 16:56:16 +0000320
321 I.addOperand(MachineOperand::CreateImm(0));
322 return constrainSelectedInstRegOperands(I, TII, TRI, RBI);
323 }
324
Ahmed Bougachae4c03ab2016-08-16 14:37:46 +0000325 case TargetOpcode::G_MUL: {
326 // Reject the various things we don't support yet.
327 if (unsupportedBinOp(I, RBI, MRI, TRI))
328 return false;
329
330 const unsigned DefReg = I.getOperand(0).getReg();
331 const RegisterBank &RB = *RBI.getRegBank(DefReg, MRI, TRI);
332
333 if (RB.getID() != AArch64::GPRRegBankID) {
334 DEBUG(dbgs() << "G_MUL on bank: " << RB << ", expected: GPR\n");
335 return false;
336 }
337
338 unsigned ZeroReg;
339 unsigned NewOpc;
340 if (Ty == LLT::scalar(32)) {
341 NewOpc = AArch64::MADDWrrr;
342 ZeroReg = AArch64::WZR;
343 } else if (Ty == LLT::scalar(64)) {
344 NewOpc = AArch64::MADDXrrr;
345 ZeroReg = AArch64::XZR;
346 } else {
347 DEBUG(dbgs() << "G_MUL has type: " << Ty << ", expected: "
348 << LLT::scalar(32) << " or " << LLT::scalar(64) << '\n');
349 return false;
350 }
351
352 I.setDesc(TII.get(NewOpc));
Ahmed Bougachae4c03ab2016-08-16 14:37:46 +0000353
354 I.addOperand(MachineOperand::CreateReg(ZeroReg, /*isDef=*/false));
355
356 // Now that we selected an opcode, we need to constrain the register
357 // operands to use appropriate classes.
358 return constrainSelectedInstRegOperands(I, TII, TRI, RBI);
359 }
360
Ahmed Bougacha33e19fe2016-08-18 16:05:11 +0000361 case TargetOpcode::G_FADD:
362 case TargetOpcode::G_FSUB:
363 case TargetOpcode::G_FMUL:
364 case TargetOpcode::G_FDIV:
365
Ahmed Bougacha6756a2c2016-07-27 14:31:55 +0000366 case TargetOpcode::G_OR:
Ahmed Bougacha6db3cfe2016-07-29 16:56:25 +0000367 case TargetOpcode::G_XOR:
Ahmed Bougacha61a79282016-07-28 16:58:31 +0000368 case TargetOpcode::G_AND:
Ahmed Bougacha2ac5bf92016-08-16 14:02:47 +0000369 case TargetOpcode::G_SHL:
370 case TargetOpcode::G_LSHR:
371 case TargetOpcode::G_ASHR:
Ahmed Bougacha1d0560b2016-08-18 15:17:13 +0000372 case TargetOpcode::G_SDIV:
373 case TargetOpcode::G_UDIV:
Ahmed Bougachad7748d62016-07-28 16:58:35 +0000374 case TargetOpcode::G_ADD:
Tim Northover2fda4b02016-10-10 21:49:49 +0000375 case TargetOpcode::G_SUB:
376 case TargetOpcode::G_GEP: {
Ahmed Bougacha6756a2c2016-07-27 14:31:55 +0000377 // Reject the various things we don't support yet.
Ahmed Bougacha59e160a2016-08-16 14:37:40 +0000378 if (unsupportedBinOp(I, RBI, MRI, TRI))
379 return false;
Ahmed Bougacha6756a2c2016-07-27 14:31:55 +0000380
Ahmed Bougacha59e160a2016-08-16 14:37:40 +0000381 const unsigned OpSize = Ty.getSizeInBits();
Ahmed Bougacha6756a2c2016-07-27 14:31:55 +0000382
383 const unsigned DefReg = I.getOperand(0).getReg();
384 const RegisterBank &RB = *RBI.getRegBank(DefReg, MRI, TRI);
385
386 const unsigned NewOpc = selectBinaryOp(I.getOpcode(), RB.getID(), OpSize);
387 if (NewOpc == I.getOpcode())
388 return false;
389
390 I.setDesc(TII.get(NewOpc));
391 // FIXME: Should the type be always reset in setDesc?
Ahmed Bougacha6756a2c2016-07-27 14:31:55 +0000392
393 // Now that we selected an opcode, we need to constrain the register
394 // operands to use appropriate classes.
395 return constrainSelectedInstRegOperands(I, TII, TRI, RBI);
396 }
Tim Northover3d38b3a2016-10-11 20:50:21 +0000397
398 case TargetOpcode::G_ANYEXT: {
399 const unsigned DstReg = I.getOperand(0).getReg();
400 const unsigned SrcReg = I.getOperand(1).getReg();
401
402 const RegisterBank &RB = *RBI.getRegBank(DstReg, MRI, TRI);
403
404 if (RB.getID() != AArch64::GPRRegBankID) {
405 DEBUG(dbgs() << "G_ANYEXT on bank: " << RB << ", expected: GPR\n");
406 return false;
407 }
408
409 const unsigned DstSize = MRI.getType(DstReg).getSizeInBits();
410
411 if (DstSize == 0) {
412 DEBUG(dbgs() << "G_ANYEXT operand has no size, not a gvreg?\n");
413 return false;
414 }
415
416 const TargetRegisterClass *RC = nullptr;
417 if (DstSize <= 32) {
418 RC = &AArch64::GPR32RegClass;
419 } else if (DstSize == 64) {
420 RC = &AArch64::GPR64RegClass;
421 } else {
422 DEBUG(dbgs() << "G_ANYEXT to size: " << DstSize
423 << ", expected: 32 or 64\n");
424 return false;
425 }
426
427 if (!RBI.constrainGenericRegister(SrcReg, *RC, MRI) ||
428 !RBI.constrainGenericRegister(DstReg, *RC, MRI)) {
429 DEBUG(dbgs() << "Failed to constrain G_ANYEXT\n");
430 return false;
431 }
432
433 BuildMI(MBB, I, I.getDebugLoc(), TII.get(AArch64::COPY))
434 .addDef(DstReg)
435 .addUse(SrcReg);
436
437 I.eraseFromParent();
438 return true;
439 }
440
441 case TargetOpcode::G_ZEXT:
442 case TargetOpcode::G_SEXT: {
443 unsigned Opcode = I.getOpcode();
444 const LLT DstTy = MRI.getType(I.getOperand(0).getReg()),
445 SrcTy = MRI.getType(I.getOperand(1).getReg());
446 const bool isSigned = Opcode == TargetOpcode::G_SEXT;
447 const unsigned DefReg = I.getOperand(0).getReg();
448 const unsigned SrcReg = I.getOperand(1).getReg();
449 const RegisterBank &RB = *RBI.getRegBank(DefReg, MRI, TRI);
450
451 if (RB.getID() != AArch64::GPRRegBankID) {
452 DEBUG(dbgs() << TII.getName(I.getOpcode()) << " on bank: " << RB
453 << ", expected: GPR\n");
454 return false;
455 }
456
457 MachineInstr *ExtI;
458 if (DstTy == LLT::scalar(64)) {
459 // FIXME: Can we avoid manually doing this?
460 if (!RBI.constrainGenericRegister(SrcReg, AArch64::GPR32RegClass, MRI)) {
461 DEBUG(dbgs() << "Failed to constrain " << TII.getName(Opcode)
462 << " operand\n");
463 return false;
464 }
465
466 const unsigned SrcXReg =
467 MRI.createVirtualRegister(&AArch64::GPR64RegClass);
468 BuildMI(MBB, I, I.getDebugLoc(), TII.get(AArch64::SUBREG_TO_REG))
469 .addDef(SrcXReg)
470 .addImm(0)
471 .addUse(SrcReg)
472 .addImm(AArch64::sub_32);
473
474 const unsigned NewOpc = isSigned ? AArch64::SBFMXri : AArch64::UBFMXri;
475 ExtI = BuildMI(MBB, I, I.getDebugLoc(), TII.get(NewOpc))
476 .addDef(DefReg)
477 .addUse(SrcXReg)
478 .addImm(0)
479 .addImm(SrcTy.getSizeInBits() - 1);
480 } else if (DstTy == LLT::scalar(32)) {
481 const unsigned NewOpc = isSigned ? AArch64::SBFMWri : AArch64::UBFMWri;
482 ExtI = BuildMI(MBB, I, I.getDebugLoc(), TII.get(NewOpc))
483 .addDef(DefReg)
484 .addUse(SrcReg)
485 .addImm(0)
486 .addImm(SrcTy.getSizeInBits() - 1);
487 } else {
488 return false;
489 }
490
491 constrainSelectedInstRegOperands(*ExtI, TII, TRI, RBI);
492
493 I.eraseFromParent();
494 return true;
495 }
Ahmed Bougacha6756a2c2016-07-27 14:31:55 +0000496 }
497
498 return false;
499}