1 //===-- ARMInstrThumb2.td - Thumb2 support for ARM ---------*- tablegen -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // This file describes the Thumb2 instruction set.
11 //===----------------------------------------------------------------------===//
13 // IT block predicate field
14 def it_pred_asmoperand : AsmOperandClass {
15 let Name = "ITCondCode";
16 let ParserMethod = "parseITCondCode";
18 def it_pred : Operand<i32> {
19 let PrintMethod = "printMandatoryPredicateOperand";
20 let ParserMatchClass = it_pred_asmoperand;
23 // IT block condition mask
24 def it_mask_asmoperand : AsmOperandClass { let Name = "ITMask"; }
25 def it_mask : Operand<i32> {
26 let PrintMethod = "printThumbITMask";
27 let ParserMatchClass = it_mask_asmoperand;
28 let EncoderMethod = "getITMaskOpValue";
31 // t2_shift_imm: An integer that encodes a shift amount and the type of shift
32 // (asr or lsl). The 6-bit immediate encodes as:
35 // {4-0} imm5 shift amount.
36 // asr #32 not allowed
37 def t2_shift_imm : Operand<i32> {
38 let PrintMethod = "printShiftImmOperand";
39 let ParserMatchClass = ShifterImmAsmOperand;
40 let DecoderMethod = "DecodeT2ShifterImmOperand";
43 def mve_shift_imm : AsmOperandClass {
44 let Name = "MVELongShift";
45 let RenderMethod = "addImmOperands";
46 let DiagnosticString = "operand must be an immediate in the range [1,32]";
48 def long_shift : Operand<i32>,
49 ImmLeaf<i32, [{ return Imm > 0 && Imm <= 32; }]> {
50 let ParserMatchClass = mve_shift_imm;
51 let DecoderMethod = "DecodeLongShiftOperand";
54 // Shifted operands. No register controlled shifts for Thumb2.
55 // Note: We do not support rrx shifted operands yet.
56 def t2_so_reg : Operand<i32>, // reg imm
57 ComplexPattern<i32, 2, "SelectShiftImmShifterOperand",
59 let EncoderMethod = "getT2SORegOpValue";
60 let PrintMethod = "printT2SOOperand";
61 let DecoderMethod = "DecodeSORegImmOperand";
62 let ParserMatchClass = ShiftedImmAsmOperand;
63 let MIOperandInfo = (ops rGPR, i32imm);
66 // t2_so_imm_not_XFORM - Return the complement of a t2_so_imm value
67 def t2_so_imm_not_XFORM : SDNodeXForm<imm, [{
68 return CurDAG->getTargetConstant(~((uint32_t)N->getZExtValue()), SDLoc(N),
72 // t2_so_imm_neg_XFORM - Return the negation of a t2_so_imm value
73 def t2_so_imm_neg_XFORM : SDNodeXForm<imm, [{
74 return CurDAG->getTargetConstant(-((int)N->getZExtValue()), SDLoc(N),
78 // so_imm_notSext_XFORM - Return a so_imm value packed into the format
79 // described for so_imm_notSext def below, with sign extension from 16
81 def t2_so_imm_notSext16_XFORM : SDNodeXForm<imm, [{
82 APInt apIntN = N->getAPIntValue();
83 unsigned N16bitSignExt = apIntN.trunc(16).sext(32).getZExtValue();
84 return CurDAG->getTargetConstant(~N16bitSignExt, SDLoc(N), MVT::i32);
87 // t2_so_imm - Match a 32-bit immediate operand, which is an
88 // 8-bit immediate rotated by an arbitrary number of bits, or an 8-bit
89 // immediate splatted into multiple bytes of the word.
90 def t2_so_imm_asmoperand : AsmOperandClass {
92 let RenderMethod = "addImmOperands";
95 def t2_so_imm : Operand<i32>, ImmLeaf<i32, [{
96 return ARM_AM::getT2SOImmVal(Imm) != -1;
98 let ParserMatchClass = t2_so_imm_asmoperand;
99 let EncoderMethod = "getT2SOImmOpValue";
100 let DecoderMethod = "DecodeT2SOImm";
103 // t2_so_imm_not - Match an immediate that is a complement
105 // Note: this pattern doesn't require an encoder method and such, as it's
106 // only used on aliases (Pat<> and InstAlias<>). The actual encoding
107 // is handled by the destination instructions, which use t2_so_imm.
108 def t2_so_imm_not_asmoperand : AsmOperandClass { let Name = "T2SOImmNot"; }
109 def t2_so_imm_not : Operand<i32>, PatLeaf<(imm), [{
110 return ARM_AM::getT2SOImmVal(~((uint32_t)N->getZExtValue())) != -1;
111 }], t2_so_imm_not_XFORM> {
112 let ParserMatchClass = t2_so_imm_not_asmoperand;
115 // t2_so_imm_notSext - match an immediate that is a complement of a t2_so_imm
116 // if the upper 16 bits are zero.
117 def t2_so_imm_notSext : Operand<i32>, PatLeaf<(imm), [{
118 APInt apIntN = N->getAPIntValue();
119 if (!apIntN.isIntN(16)) return false;
120 unsigned N16bitSignExt = apIntN.trunc(16).sext(32).getZExtValue();
121 return ARM_AM::getT2SOImmVal(~N16bitSignExt) != -1;
122 }], t2_so_imm_notSext16_XFORM> {
123 let ParserMatchClass = t2_so_imm_not_asmoperand;
126 // t2_so_imm_neg - Match an immediate that is a negation of a t2_so_imm.
127 def t2_so_imm_neg_asmoperand : AsmOperandClass { let Name = "T2SOImmNeg"; }
128 def t2_so_imm_neg : Operand<i32>, ImmLeaf<i32, [{
129 return Imm && ARM_AM::getT2SOImmVal(-(uint32_t)Imm) != -1;
130 }], t2_so_imm_neg_XFORM> {
131 let ParserMatchClass = t2_so_imm_neg_asmoperand;
134 /// imm0_4095 predicate - True if the 32-bit immediate is in the range [0,4095].
135 def imm0_4095_asmoperand: ImmAsmOperand<0,4095> { let Name = "Imm0_4095"; }
136 def imm0_4095 : Operand<i32>, ImmLeaf<i32, [{
137 return Imm >= 0 && Imm < 4096;
139 let ParserMatchClass = imm0_4095_asmoperand;
142 def imm0_4095_neg_asmoperand: AsmOperandClass { let Name = "Imm0_4095Neg"; }
143 def imm0_4095_neg : Operand<i32>, PatLeaf<(i32 imm), [{
144 return (uint32_t)(-N->getZExtValue()) < 4096;
146 let ParserMatchClass = imm0_4095_neg_asmoperand;
149 def imm1_255_neg : PatLeaf<(i32 imm), [{
150 uint32_t Val = -N->getZExtValue();
151 return (Val > 0 && Val < 255);
154 def imm0_255_not : PatLeaf<(i32 imm), [{
155 return (uint32_t)(~N->getZExtValue()) < 255;
158 def lo5AllOne : PatLeaf<(i32 imm), [{
159 // Returns true if all low 5-bits are 1.
160 return (((uint32_t)N->getZExtValue()) & 0x1FUL) == 0x1FUL;
163 // Define Thumb2 specific addressing modes.
165 // t2_addr_offset_none := reg
166 def MemNoOffsetT2AsmOperand
167 : AsmOperandClass { let Name = "MemNoOffsetT2"; }
168 def t2_addr_offset_none : MemOperand {
169 let PrintMethod = "printAddrMode7Operand";
170 let DecoderMethod = "DecodeGPRnopcRegisterClass";
171 let ParserMatchClass = MemNoOffsetT2AsmOperand;
172 let MIOperandInfo = (ops GPRnopc:$base);
175 // t2_nosp_addr_offset_none := reg
176 def MemNoOffsetT2NoSpAsmOperand
177 : AsmOperandClass { let Name = "MemNoOffsetT2NoSp"; }
178 def t2_nosp_addr_offset_none : MemOperand {
179 let PrintMethod = "printAddrMode7Operand";
180 let DecoderMethod = "DecoderGPRRegisterClass";
181 let ParserMatchClass = MemNoOffsetT2NoSpAsmOperand;
182 let MIOperandInfo = (ops rGPR:$base);
185 // t2addrmode_imm12 := reg + imm12
186 def t2addrmode_imm12_asmoperand : AsmOperandClass {let Name="MemUImm12Offset";}
187 def t2addrmode_imm12 : MemOperand,
188 ComplexPattern<i32, 2, "SelectT2AddrModeImm12", []> {
189 let PrintMethod = "printAddrModeImm12Operand<false>";
190 let EncoderMethod = "getAddrModeImm12OpValue";
191 let DecoderMethod = "DecodeT2AddrModeImm12";
192 let ParserMatchClass = t2addrmode_imm12_asmoperand;
193 let MIOperandInfo = (ops GPR:$base, i32imm:$offsimm);
196 // t2ldrlabel := imm12
197 def t2ldrlabel : Operand<i32> {
198 let EncoderMethod = "getAddrModeImm12OpValue";
199 let PrintMethod = "printThumbLdrLabelOperand";
202 def t2ldr_pcrel_imm12_asmoperand : AsmOperandClass {let Name = "MemPCRelImm12";}
203 def t2ldr_pcrel_imm12 : Operand<i32> {
204 let ParserMatchClass = t2ldr_pcrel_imm12_asmoperand;
205 // used for assembler pseudo instruction and maps to t2ldrlabel, so
206 // doesn't need encoder or print methods of its own.
209 // ADR instruction labels.
210 def t2adrlabel : Operand<i32> {
211 let EncoderMethod = "getT2AdrLabelOpValue";
212 let PrintMethod = "printAdrLabelOperand<0>";
215 // t2addrmode_posimm8 := reg + imm8
216 def MemPosImm8OffsetAsmOperand : AsmOperandClass {
217 let Name="MemPosImm8Offset";
218 let RenderMethod = "addMemImmOffsetOperands";
220 def t2addrmode_posimm8 : MemOperand {
221 let PrintMethod = "printT2AddrModeImm8Operand<false>";
222 let EncoderMethod = "getT2AddrModeImmOpValue<8,0>";
223 let DecoderMethod = "DecodeT2AddrModeImm8";
224 let ParserMatchClass = MemPosImm8OffsetAsmOperand;
225 let MIOperandInfo = (ops GPR:$base, i32imm:$offsimm);
228 // t2addrmode_negimm8 := reg - imm8
229 def MemNegImm8OffsetAsmOperand : AsmOperandClass {
230 let Name="MemNegImm8Offset";
231 let RenderMethod = "addMemImmOffsetOperands";
233 def t2addrmode_negimm8 : MemOperand,
234 ComplexPattern<i32, 2, "SelectT2AddrModeImm8", []> {
235 let PrintMethod = "printT2AddrModeImm8Operand<false>";
236 let EncoderMethod = "getT2AddrModeImmOpValue<8,0>";
237 let DecoderMethod = "DecodeT2AddrModeImm8";
238 let ParserMatchClass = MemNegImm8OffsetAsmOperand;
239 let MIOperandInfo = (ops GPR:$base, i32imm:$offsimm);
242 // t2addrmode_imm8 := reg +/- imm8
243 def MemImm8OffsetAsmOperand : AsmOperandClass {
244 let Name = "MemImm8Offset";
245 let RenderMethod = "addMemImmOffsetOperands";
247 class T2AddrMode_Imm8 : MemOperand,
248 ComplexPattern<i32, 2, "SelectT2AddrModeImm8", []> {
249 let EncoderMethod = "getT2AddrModeImmOpValue<8,0>";
250 let DecoderMethod = "DecodeT2AddrModeImm8";
251 let ParserMatchClass = MemImm8OffsetAsmOperand;
252 let MIOperandInfo = (ops GPR:$base, i32imm:$offsimm);
255 def t2addrmode_imm8 : T2AddrMode_Imm8 {
256 let PrintMethod = "printT2AddrModeImm8Operand<false>";
259 def t2addrmode_imm8_pre : T2AddrMode_Imm8 {
260 let PrintMethod = "printT2AddrModeImm8Operand<true>";
263 def t2am_imm8_offset : MemOperand,
264 ComplexPattern<i32, 1, "SelectT2AddrModeImm8Offset",
265 [], [SDNPWantRoot]> {
266 let PrintMethod = "printT2AddrModeImm8OffsetOperand";
267 let EncoderMethod = "getT2AddrModeImm8OffsetOpValue";
268 let DecoderMethod = "DecodeT2Imm8";
271 // t2addrmode_imm8s4 := reg +/- (imm8 << 2)
272 def MemImm8s4OffsetAsmOperand : AsmOperandClass {let Name = "MemImm8s4Offset";}
273 class T2AddrMode_Imm8s4 : MemOperand {
274 let EncoderMethod = "getT2AddrModeImm8s4OpValue";
275 let DecoderMethod = "DecodeT2AddrModeImm8s4";
276 let ParserMatchClass = MemImm8s4OffsetAsmOperand;
277 let MIOperandInfo = (ops GPR:$base, i32imm:$offsimm);
280 def t2addrmode_imm8s4 : T2AddrMode_Imm8s4 {
281 let PrintMethod = "printT2AddrModeImm8s4Operand<false>";
284 def t2addrmode_imm8s4_pre : T2AddrMode_Imm8s4 {
285 let PrintMethod = "printT2AddrModeImm8s4Operand<true>";
288 def t2am_imm8s4_offset_asmoperand : AsmOperandClass { let Name = "Imm8s4"; }
289 def t2am_imm8s4_offset : MemOperand {
290 let PrintMethod = "printT2AddrModeImm8s4OffsetOperand";
291 let EncoderMethod = "getT2ScaledImmOpValue<8,2>";
292 let DecoderMethod = "DecodeT2Imm8S4";
295 // t2addrmode_imm7s4 := reg +/- (imm7 << 2)
296 def MemImm7s4OffsetAsmOperand : AsmOperandClass {let Name = "MemImm7s4Offset";}
297 class T2AddrMode_Imm7s4 : MemOperand {
298 let EncoderMethod = "getT2AddrModeImm7s4OpValue";
299 let DecoderMethod = "DecodeT2AddrModeImm7<2,0>";
300 let ParserMatchClass = MemImm7s4OffsetAsmOperand;
301 let MIOperandInfo = (ops GPRnopc:$base, i32imm:$offsimm);
304 def t2addrmode_imm7s4 : T2AddrMode_Imm7s4 {
305 // They are printed the same way as the imm8 version
306 let PrintMethod = "printT2AddrModeImm8s4Operand<false>";
309 def t2addrmode_imm7s4_pre : T2AddrMode_Imm7s4 {
310 // They are printed the same way as the imm8 version
311 let PrintMethod = "printT2AddrModeImm8s4Operand<true>";
314 def t2am_imm7s4_offset_asmoperand : AsmOperandClass { let Name = "Imm7s4"; }
315 def t2am_imm7s4_offset : MemOperand {
316 // They are printed the same way as the imm8 version
317 let PrintMethod = "printT2AddrModeImm8s4OffsetOperand";
318 let ParserMatchClass = t2am_imm7s4_offset_asmoperand;
319 let EncoderMethod = "getT2ScaledImmOpValue<7,2>";
320 let DecoderMethod = "DecodeT2Imm7S4";
323 // t2addrmode_imm0_1020s4 := reg + (imm8 << 2)
324 def MemImm0_1020s4OffsetAsmOperand : AsmOperandClass {
325 let Name = "MemImm0_1020s4Offset";
327 def t2addrmode_imm0_1020s4 : MemOperand,
328 ComplexPattern<i32, 2, "SelectT2AddrModeExclusive"> {
329 let PrintMethod = "printT2AddrModeImm0_1020s4Operand";
330 let EncoderMethod = "getT2AddrModeImm0_1020s4OpValue";
331 let DecoderMethod = "DecodeT2AddrModeImm0_1020s4";
332 let ParserMatchClass = MemImm0_1020s4OffsetAsmOperand;
333 let MIOperandInfo = (ops GPRnopc:$base, i32imm:$offsimm);
336 // t2addrmode_so_reg := reg + (reg << imm2)
337 def t2addrmode_so_reg_asmoperand : AsmOperandClass {let Name="T2MemRegOffset";}
338 def t2addrmode_so_reg : MemOperand,
339 ComplexPattern<i32, 3, "SelectT2AddrModeSoReg", []> {
340 let PrintMethod = "printT2AddrModeSoRegOperand";
341 let EncoderMethod = "getT2AddrModeSORegOpValue";
342 let DecoderMethod = "DecodeT2AddrModeSOReg";
343 let ParserMatchClass = t2addrmode_so_reg_asmoperand;
344 let MIOperandInfo = (ops GPRnopc:$base, rGPR:$offsreg, i32imm:$offsimm);
347 // Addresses for the TBB/TBH instructions.
348 def addrmode_tbb_asmoperand : AsmOperandClass { let Name = "MemTBB"; }
349 def addrmode_tbb : MemOperand {
350 let PrintMethod = "printAddrModeTBB";
351 let ParserMatchClass = addrmode_tbb_asmoperand;
352 let MIOperandInfo = (ops GPR:$Rn, rGPR:$Rm);
354 def addrmode_tbh_asmoperand : AsmOperandClass { let Name = "MemTBH"; }
355 def addrmode_tbh : MemOperand {
356 let PrintMethod = "printAddrModeTBH";
357 let ParserMatchClass = addrmode_tbh_asmoperand;
358 let MIOperandInfo = (ops GPR:$Rn, rGPR:$Rm);
361 // Define ARMv8.1-M specific addressing modes.
363 // Label operands for BF/BFL/WLS/DLS/LE
364 class BFLabelOp<string signed, string isNeg, string zeroPermitted, string size,
367 let EncoderMethod = !strconcat("getBFTargetOpValue<", isNeg, ", ",
369 let OperandType = "OPERAND_PCREL";
370 let DecoderMethod = !strconcat("DecodeBFLabelOperand<", signed, ", ",
371 isNeg, ", ", zeroPermitted, ", ", size, ">");
373 def bflabel_u4 : BFLabelOp<"false", "false", "false", "4", "ARM::fixup_bf_branch">;
374 def bflabel_s12 : BFLabelOp<"true", "false", "true", "12", "ARM::fixup_bfc_target">;
375 def bflabel_s16 : BFLabelOp<"true", "false", "true", "16", "ARM::fixup_bf_target">;
376 def bflabel_s18 : BFLabelOp<"true", "false", "true", "18", "ARM::fixup_bfl_target">;
378 def wlslabel_u11_asmoperand : AsmOperandClass {
379 let Name = "WLSLabel";
380 let RenderMethod = "addImmOperands";
381 let PredicateMethod = "isUnsignedOffset<11, 1>";
382 let DiagnosticString =
383 "loop end is out of range or not a positive multiple of 2";
385 def wlslabel_u11 : BFLabelOp<"false", "false", "true", "11", "ARM::fixup_wls"> {
386 let ParserMatchClass = wlslabel_u11_asmoperand;
388 def lelabel_u11_asmoperand : AsmOperandClass {
389 let Name = "LELabel";
390 let RenderMethod = "addImmOperands";
391 let PredicateMethod = "isLEOffset";
392 let DiagnosticString =
393 "loop start is out of range or not a negative multiple of 2";
395 def lelabel_u11 : BFLabelOp<"false", "true", "true", "11", "ARM::fixup_le"> {
396 let ParserMatchClass = lelabel_u11_asmoperand;
399 def bfafter_target : Operand<OtherVT> {
400 let EncoderMethod = "getBFAfterTargetOpValue";
401 let OperandType = "OPERAND_PCREL";
402 let DecoderMethod = "DecodeBFAfterTargetOperand";
405 // pred operand excluding AL
406 def pred_noal_asmoperand : AsmOperandClass {
407 let Name = "CondCodeNoAL";
408 let RenderMethod = "addITCondCodeOperands";
409 let PredicateMethod = "isITCondCodeNoAL";
410 let ParserMethod = "parseITCondCode";
412 def pred_noal : Operand<i32> {
413 let PrintMethod = "printMandatoryPredicateOperand";
414 let ParserMatchClass = pred_noal_asmoperand;
415 let DecoderMethod = "DecodePredNoALOperand";
419 // CSEL aliases inverted predicate
420 def pred_noal_inv_asmoperand : AsmOperandClass {
421 let Name = "CondCodeNoALInv";
422 let RenderMethod = "addITCondCodeInvOperands";
423 let PredicateMethod = "isITCondCodeNoAL";
424 let ParserMethod = "parseITCondCode";
426 def pred_noal_inv : Operand<i32> {
427 let PrintMethod = "printMandatoryInvertedPredicateOperand";
428 let ParserMatchClass = pred_noal_inv_asmoperand;
430 //===----------------------------------------------------------------------===//
431 // Multiclass helpers...
435 class T2OneRegImm<dag oops, dag iops, InstrItinClass itin,
436 string opc, string asm, list<dag> pattern>
437 : T2I<oops, iops, itin, opc, asm, pattern> {
442 let Inst{26} = imm{11};
443 let Inst{14-12} = imm{10-8};
444 let Inst{7-0} = imm{7-0};
448 class T2sOneRegImm<dag oops, dag iops, InstrItinClass itin,
449 string opc, string asm, list<dag> pattern>
450 : T2sI<oops, iops, itin, opc, asm, pattern> {
456 let Inst{26} = imm{11};
457 let Inst{14-12} = imm{10-8};
458 let Inst{7-0} = imm{7-0};
461 class T2OneRegCmpImm<dag oops, dag iops, InstrItinClass itin,
462 string opc, string asm, list<dag> pattern>
463 : T2I<oops, iops, itin, opc, asm, pattern> {
467 let Inst{19-16} = Rn;
468 let Inst{26} = imm{11};
469 let Inst{14-12} = imm{10-8};
470 let Inst{7-0} = imm{7-0};
474 class T2OneRegShiftedReg<dag oops, dag iops, InstrItinClass itin,
475 string opc, string asm, list<dag> pattern>
476 : T2I<oops, iops, itin, opc, asm, pattern> {
481 let Inst{3-0} = ShiftedRm{3-0};
482 let Inst{5-4} = ShiftedRm{6-5};
483 let Inst{14-12} = ShiftedRm{11-9};
484 let Inst{7-6} = ShiftedRm{8-7};
487 class T2sOneRegShiftedReg<dag oops, dag iops, InstrItinClass itin,
488 string opc, string asm, list<dag> pattern>
489 : T2sI<oops, iops, itin, opc, asm, pattern> {
494 let Inst{3-0} = ShiftedRm{3-0};
495 let Inst{5-4} = ShiftedRm{6-5};
496 let Inst{14-12} = ShiftedRm{11-9};
497 let Inst{7-6} = ShiftedRm{8-7};
500 class T2OneRegCmpShiftedReg<dag oops, dag iops, InstrItinClass itin,
501 string opc, string asm, list<dag> pattern>
502 : T2I<oops, iops, itin, opc, asm, pattern> {
506 let Inst{19-16} = Rn;
507 let Inst{3-0} = ShiftedRm{3-0};
508 let Inst{5-4} = ShiftedRm{6-5};
509 let Inst{14-12} = ShiftedRm{11-9};
510 let Inst{7-6} = ShiftedRm{8-7};
513 class T2TwoReg<dag oops, dag iops, InstrItinClass itin,
514 string opc, string asm, list<dag> pattern>
515 : T2I<oops, iops, itin, opc, asm, pattern> {
523 class T2sTwoReg<dag oops, dag iops, InstrItinClass itin,
524 string opc, string asm, list<dag> pattern>
525 : T2sI<oops, iops, itin, opc, asm, pattern> {
533 class T2TwoRegCmp<dag oops, dag iops, InstrItinClass itin,
534 string opc, string asm, list<dag> pattern>
535 : T2I<oops, iops, itin, opc, asm, pattern> {
539 let Inst{19-16} = Rn;
544 class T2TwoRegImm<dag oops, dag iops, InstrItinClass itin,
545 string opc, string asm, list<dag> pattern>
546 : T2I<oops, iops, itin, opc, asm, pattern> {
552 let Inst{19-16} = Rn;
553 let Inst{26} = imm{11};
554 let Inst{14-12} = imm{10-8};
555 let Inst{7-0} = imm{7-0};
558 class T2sTwoRegImm<dag oops, dag iops, InstrItinClass itin,
559 string opc, string asm, list<dag> pattern>
560 : T2sI<oops, iops, itin, opc, asm, pattern> {
566 let Inst{19-16} = Rn;
567 let Inst{26} = imm{11};
568 let Inst{14-12} = imm{10-8};
569 let Inst{7-0} = imm{7-0};
572 class T2TwoRegShiftImm<dag oops, dag iops, InstrItinClass itin,
573 string opc, string asm, list<dag> pattern>
574 : T2I<oops, iops, itin, opc, asm, pattern> {
581 let Inst{14-12} = imm{4-2};
582 let Inst{7-6} = imm{1-0};
585 class T2sTwoRegShiftImm<dag oops, dag iops, InstrItinClass itin,
586 string opc, string asm, list<dag> pattern>
587 : T2sI<oops, iops, itin, opc, asm, pattern> {
594 let Inst{14-12} = imm{4-2};
595 let Inst{7-6} = imm{1-0};
598 class T2ThreeReg<dag oops, dag iops, InstrItinClass itin,
599 string opc, string asm, list<dag> pattern>
600 : T2I<oops, iops, itin, opc, asm, pattern> {
606 let Inst{19-16} = Rn;
610 class T2ThreeRegNoP<dag oops, dag iops, InstrItinClass itin,
611 string asm, list<dag> pattern>
612 : T2XI<oops, iops, itin, asm, pattern> {
618 let Inst{19-16} = Rn;
622 class T2sThreeReg<dag oops, dag iops, InstrItinClass itin,
623 string opc, string asm, list<dag> pattern>
624 : T2sI<oops, iops, itin, opc, asm, pattern> {
630 let Inst{19-16} = Rn;
634 class T2TwoRegShiftedReg<dag oops, dag iops, InstrItinClass itin,
635 string opc, string asm, list<dag> pattern>
636 : T2I<oops, iops, itin, opc, asm, pattern> {
642 let Inst{19-16} = Rn;
643 let Inst{3-0} = ShiftedRm{3-0};
644 let Inst{5-4} = ShiftedRm{6-5};
645 let Inst{14-12} = ShiftedRm{11-9};
646 let Inst{7-6} = ShiftedRm{8-7};
649 class T2sTwoRegShiftedReg<dag oops, dag iops, InstrItinClass itin,
650 string opc, string asm, list<dag> pattern>
651 : T2sI<oops, iops, itin, opc, asm, pattern> {
657 let Inst{19-16} = Rn;
658 let Inst{3-0} = ShiftedRm{3-0};
659 let Inst{5-4} = ShiftedRm{6-5};
660 let Inst{14-12} = ShiftedRm{11-9};
661 let Inst{7-6} = ShiftedRm{8-7};
664 class T2FourReg<dag oops, dag iops, InstrItinClass itin,
665 string opc, string asm, list<dag> pattern>
666 : T2I<oops, iops, itin, opc, asm, pattern> {
672 let Inst{19-16} = Rn;
673 let Inst{15-12} = Ra;
678 class T2MulLong<bits<3> opc22_20, bits<4> opc7_4,
679 string opc, list<dag> pattern>
680 : T2I<(outs rGPR:$RdLo, rGPR:$RdHi), (ins rGPR:$Rn, rGPR:$Rm), IIC_iMUL64,
681 opc, "\t$RdLo, $RdHi, $Rn, $Rm", pattern>,
682 Sched<[WriteMUL64Lo, WriteMUL64Hi, ReadMUL, ReadMUL]> {
688 let Inst{31-23} = 0b111110111;
689 let Inst{22-20} = opc22_20;
690 let Inst{19-16} = Rn;
691 let Inst{15-12} = RdLo;
692 let Inst{11-8} = RdHi;
693 let Inst{7-4} = opc7_4;
696 class T2MlaLong<bits<3> opc22_20, bits<4> opc7_4, string opc>
697 : T2I<(outs rGPR:$RdLo, rGPR:$RdHi),
698 (ins rGPR:$Rn, rGPR:$Rm, rGPR:$RLo, rGPR:$RHi), IIC_iMAC64,
699 opc, "\t$RdLo, $RdHi, $Rn, $Rm", []>,
700 RegConstraint<"$RLo = $RdLo, $RHi = $RdHi">,
701 Sched<[WriteMAC64Lo, WriteMAC64Hi, ReadMUL, ReadMUL, ReadMAC, ReadMAC]> {
707 let Inst{31-23} = 0b111110111;
708 let Inst{22-20} = opc22_20;
709 let Inst{19-16} = Rn;
710 let Inst{15-12} = RdLo;
711 let Inst{11-8} = RdHi;
712 let Inst{7-4} = opc7_4;
717 /// T2I_bin_irs - Defines a set of (op reg, {so_imm|r|so_reg}) patterns for a
718 /// binary operation that produces a value. These are predicable and can be
719 /// changed to modify CPSR.
720 multiclass T2I_bin_irs<bits<4> opcod, string opc,
721 InstrItinClass iii, InstrItinClass iir, InstrItinClass iis,
722 SDPatternOperator opnode, bit Commutable = 0,
725 def ri : T2sTwoRegImm<
726 (outs rGPR:$Rd), (ins rGPR:$Rn, t2_so_imm:$imm), iii,
727 opc, "\t$Rd, $Rn, $imm",
728 [(set rGPR:$Rd, (opnode rGPR:$Rn, t2_so_imm:$imm))]>,
729 Sched<[WriteALU, ReadALU]> {
730 let Inst{31-27} = 0b11110;
732 let Inst{24-21} = opcod;
736 def rr : T2sThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), iir,
737 opc, !strconcat(wide, "\t$Rd, $Rn, $Rm"),
738 [(set rGPR:$Rd, (opnode rGPR:$Rn, rGPR:$Rm))]>,
739 Sched<[WriteALU, ReadALU, ReadALU]> {
740 let isCommutable = Commutable;
741 let Inst{31-27} = 0b11101;
742 let Inst{26-25} = 0b01;
743 let Inst{24-21} = opcod;
745 // In most of these instructions, and most versions of the Arm
746 // architecture, bit 15 of this encoding is listed as (0) rather
747 // than 0, i.e. setting it to 1 is UNPREDICTABLE or a soft-fail
748 // rather than a hard failure. In v8.1-M, this requirement is
749 // upgraded to a hard one for ORR, so that the encodings with 1
750 // in this bit can be reused for other instructions (such as
751 // CSEL). Setting Unpredictable{15} = 1 here would reintroduce
752 // that encoding clash in the auto- generated MC decoder, so I
754 let Unpredictable{15} = !if(!eq(opcod, 0b0010), 0b0, 0b1);
755 let Inst{14-12} = 0b000; // imm3
756 let Inst{7-6} = 0b00; // imm2
757 let Inst{5-4} = 0b00; // type
760 def rs : T2sTwoRegShiftedReg<
761 (outs rGPR:$Rd), (ins rGPR:$Rn, t2_so_reg:$ShiftedRm), iis,
762 opc, !strconcat(wide, "\t$Rd, $Rn, $ShiftedRm"),
763 [(set rGPR:$Rd, (opnode rGPR:$Rn, t2_so_reg:$ShiftedRm))]>,
764 Sched<[WriteALUsi, ReadALU]> {
765 let Inst{31-27} = 0b11101;
766 let Inst{26-25} = 0b01;
767 let Inst{24-21} = opcod;
769 let Unpredictable{15} = !if(!eq(opcod, 0b0010), 0b0, 0b1); // see above
771 // Assembly aliases for optional destination operand when it's the same
772 // as the source operand.
773 def : t2InstAlias<!strconcat(opc, "${s}${p} $Rdn, $imm"),
774 (!cast<Instruction>(NAME#"ri") rGPR:$Rdn, rGPR:$Rdn,
775 t2_so_imm:$imm, pred:$p,
777 def : t2InstAlias<!strconcat(opc, "${s}${p}", wide, " $Rdn, $Rm"),
778 (!cast<Instruction>(NAME#"rr") rGPR:$Rdn, rGPR:$Rdn,
781 def : t2InstAlias<!strconcat(opc, "${s}${p}", wide, " $Rdn, $shift"),
782 (!cast<Instruction>(NAME#"rs") rGPR:$Rdn, rGPR:$Rdn,
783 t2_so_reg:$shift, pred:$p,
787 /// T2I_bin_w_irs - Same as T2I_bin_irs except these operations need
788 // the ".w" suffix to indicate that they are wide.
789 multiclass T2I_bin_w_irs<bits<4> opcod, string opc,
790 InstrItinClass iii, InstrItinClass iir, InstrItinClass iis,
791 SDPatternOperator opnode, bit Commutable = 0> :
792 T2I_bin_irs<opcod, opc, iii, iir, iis, opnode, Commutable, ".w"> {
793 // Assembler aliases w/ the ".w" suffix.
794 def : t2InstAlias<!strconcat(opc, "${s}${p}.w", " $Rd, $Rn, $imm"),
795 (!cast<Instruction>(NAME#"ri") rGPR:$Rd, rGPR:$Rn, t2_so_imm:$imm, pred:$p,
797 // Assembler aliases w/o the ".w" suffix.
798 def : t2InstAlias<!strconcat(opc, "${s}${p}", " $Rd, $Rn, $Rm"),
799 (!cast<Instruction>(NAME#"rr") rGPR:$Rd, rGPR:$Rn, rGPR:$Rm, pred:$p,
801 def : t2InstAlias<!strconcat(opc, "${s}${p}", " $Rd, $Rn, $shift"),
802 (!cast<Instruction>(NAME#"rs") rGPR:$Rd, rGPR:$Rn, t2_so_reg:$shift,
803 pred:$p, cc_out:$s)>;
805 // and with the optional destination operand, too.
806 def : t2InstAlias<!strconcat(opc, "${s}${p}.w", " $Rdn, $imm"),
807 (!cast<Instruction>(NAME#"ri") rGPR:$Rdn, rGPR:$Rdn, t2_so_imm:$imm,
808 pred:$p, cc_out:$s)>;
809 def : t2InstAlias<!strconcat(opc, "${s}${p}", " $Rdn, $Rm"),
810 (!cast<Instruction>(NAME#"rr") rGPR:$Rdn, rGPR:$Rdn, rGPR:$Rm, pred:$p,
812 def : t2InstAlias<!strconcat(opc, "${s}${p}", " $Rdn, $shift"),
813 (!cast<Instruction>(NAME#"rs") rGPR:$Rdn, rGPR:$Rdn, t2_so_reg:$shift,
814 pred:$p, cc_out:$s)>;
817 /// T2I_rbin_is - Same as T2I_bin_irs except the order of operands are
818 /// reversed. The 'rr' form is only defined for the disassembler; for codegen
819 /// it is equivalent to the T2I_bin_irs counterpart.
820 multiclass T2I_rbin_irs<bits<4> opcod, string opc, SDNode opnode> {
822 def ri : T2sTwoRegImm<
823 (outs rGPR:$Rd), (ins rGPR:$Rn, t2_so_imm:$imm), IIC_iALUi,
824 opc, ".w\t$Rd, $Rn, $imm",
825 [(set rGPR:$Rd, (opnode t2_so_imm:$imm, rGPR:$Rn))]>,
826 Sched<[WriteALU, ReadALU]> {
827 let Inst{31-27} = 0b11110;
829 let Inst{24-21} = opcod;
833 def rr : T2sThreeReg<
834 (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iALUr,
835 opc, "\t$Rd, $Rn, $Rm",
836 [/* For disassembly only; pattern left blank */]>,
837 Sched<[WriteALU, ReadALU, ReadALU]> {
838 let Inst{31-27} = 0b11101;
839 let Inst{26-25} = 0b01;
840 let Inst{24-21} = opcod;
841 let Inst{14-12} = 0b000; // imm3
842 let Inst{7-6} = 0b00; // imm2
843 let Inst{5-4} = 0b00; // type
846 def rs : T2sTwoRegShiftedReg<
847 (outs rGPR:$Rd), (ins rGPR:$Rn, t2_so_reg:$ShiftedRm),
848 IIC_iALUsir, opc, "\t$Rd, $Rn, $ShiftedRm",
849 [(set rGPR:$Rd, (opnode t2_so_reg:$ShiftedRm, rGPR:$Rn))]>,
850 Sched<[WriteALUsi, ReadALU]> {
851 let Inst{31-27} = 0b11101;
852 let Inst{26-25} = 0b01;
853 let Inst{24-21} = opcod;
857 /// T2I_bin_s_irs - Similar to T2I_bin_irs except it sets the 's' bit so the
858 /// instruction modifies the CPSR register.
860 /// These opcodes will be converted to the real non-S opcodes by
861 /// AdjustInstrPostInstrSelection after giving then an optional CPSR operand.
862 let hasPostISelHook = 1, Defs = [CPSR] in {
863 multiclass T2I_bin_s_irs<InstrItinClass iii, InstrItinClass iir,
864 InstrItinClass iis, SDNode opnode,
865 bit Commutable = 0> {
867 def ri : t2PseudoInst<(outs rGPR:$Rd),
868 (ins GPRnopc:$Rn, t2_so_imm:$imm, pred:$p),
870 [(set rGPR:$Rd, CPSR, (opnode GPRnopc:$Rn,
872 Sched<[WriteALU, ReadALU]>;
874 def rr : t2PseudoInst<(outs rGPR:$Rd), (ins GPRnopc:$Rn, rGPR:$Rm, pred:$p),
876 [(set rGPR:$Rd, CPSR, (opnode GPRnopc:$Rn,
878 Sched<[WriteALU, ReadALU, ReadALU]> {
879 let isCommutable = Commutable;
882 def rs : t2PseudoInst<(outs rGPR:$Rd),
883 (ins GPRnopc:$Rn, t2_so_reg:$ShiftedRm, pred:$p),
885 [(set rGPR:$Rd, CPSR, (opnode GPRnopc:$Rn,
886 t2_so_reg:$ShiftedRm))]>,
887 Sched<[WriteALUsi, ReadALUsr]>;
891 /// T2I_rbin_s_is - Same as T2I_bin_s_irs, except selection DAG
892 /// operands are reversed.
893 let hasPostISelHook = 1, Defs = [CPSR] in {
894 multiclass T2I_rbin_s_is<SDNode opnode> {
896 def ri : t2PseudoInst<(outs rGPR:$Rd),
897 (ins rGPR:$Rn, t2_so_imm:$imm, pred:$p),
899 [(set rGPR:$Rd, CPSR, (opnode t2_so_imm:$imm,
901 Sched<[WriteALU, ReadALU]>;
903 def rs : t2PseudoInst<(outs rGPR:$Rd),
904 (ins rGPR:$Rn, t2_so_reg:$ShiftedRm, pred:$p),
906 [(set rGPR:$Rd, CPSR, (opnode t2_so_reg:$ShiftedRm,
908 Sched<[WriteALUsi, ReadALU]>;
912 /// T2I_bin_ii12rs - Defines a set of (op reg, {so_imm|imm0_4095|r|so_reg})
913 /// patterns for a binary operation that produces a value.
914 multiclass T2I_bin_ii12rs<bits<3> op23_21, string opc, SDNode opnode,
915 bit Commutable = 0> {
917 // The register-immediate version is re-materializable. This is useful
918 // in particular for taking the address of a local.
919 let isReMaterializable = 1 in {
920 def ri : T2sTwoRegImm<
921 (outs GPRnopc:$Rd), (ins GPRnopc:$Rn, t2_so_imm:$imm), IIC_iALUi,
922 opc, ".w\t$Rd, $Rn, $imm",
923 [(set GPRnopc:$Rd, (opnode GPRnopc:$Rn, t2_so_imm:$imm))]>,
924 Sched<[WriteALU, ReadALU]> {
925 let Inst{31-27} = 0b11110;
928 let Inst{23-21} = op23_21;
934 (outs GPRnopc:$Rd), (ins GPR:$Rn, imm0_4095:$imm), IIC_iALUi,
935 !strconcat(opc, "w"), "\t$Rd, $Rn, $imm",
936 [(set GPRnopc:$Rd, (opnode GPR:$Rn, imm0_4095:$imm))]>,
937 Sched<[WriteALU, ReadALU]> {
941 let Inst{31-27} = 0b11110;
942 let Inst{26} = imm{11};
943 let Inst{25-24} = 0b10;
944 let Inst{23-21} = op23_21;
945 let Inst{20} = 0; // The S bit.
946 let Inst{19-16} = Rn;
948 let Inst{14-12} = imm{10-8};
950 let Inst{7-0} = imm{7-0};
953 def rr : T2sThreeReg<(outs GPRnopc:$Rd), (ins GPRnopc:$Rn, rGPR:$Rm),
954 IIC_iALUr, opc, ".w\t$Rd, $Rn, $Rm",
955 [(set GPRnopc:$Rd, (opnode GPRnopc:$Rn, rGPR:$Rm))]>,
956 Sched<[WriteALU, ReadALU, ReadALU]> {
957 let isCommutable = Commutable;
958 let Inst{31-27} = 0b11101;
959 let Inst{26-25} = 0b01;
961 let Inst{23-21} = op23_21;
962 let Inst{14-12} = 0b000; // imm3
963 let Inst{7-6} = 0b00; // imm2
964 let Inst{5-4} = 0b00; // type
967 def rs : T2sTwoRegShiftedReg<
968 (outs GPRnopc:$Rd), (ins GPRnopc:$Rn, t2_so_reg:$ShiftedRm),
969 IIC_iALUsi, opc, ".w\t$Rd, $Rn, $ShiftedRm",
970 [(set GPRnopc:$Rd, (opnode GPRnopc:$Rn, t2_so_reg:$ShiftedRm))]>,
971 Sched<[WriteALUsi, ReadALU]> {
972 let Inst{31-27} = 0b11101;
973 let Inst{26-25} = 0b01;
975 let Inst{23-21} = op23_21;
979 /// T2I_adde_sube_irs - Defines a set of (op reg, {so_imm|r|so_reg}) patterns
980 /// for a binary operation that produces a value and use the carry
981 /// bit. It's not predicable.
982 let Defs = [CPSR], Uses = [CPSR] in {
983 multiclass T2I_adde_sube_irs<bits<4> opcod, string opc, SDNode opnode,
984 bit Commutable = 0> {
986 def ri : T2sTwoRegImm<(outs rGPR:$Rd), (ins rGPR:$Rn, t2_so_imm:$imm),
987 IIC_iALUi, opc, "\t$Rd, $Rn, $imm",
988 [(set rGPR:$Rd, CPSR, (opnode rGPR:$Rn, t2_so_imm:$imm, CPSR))]>,
989 Requires<[IsThumb2]>, Sched<[WriteALU, ReadALU]> {
990 let Inst{31-27} = 0b11110;
992 let Inst{24-21} = opcod;
996 def rr : T2sThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iALUr,
997 opc, ".w\t$Rd, $Rn, $Rm",
998 [(set rGPR:$Rd, CPSR, (opnode rGPR:$Rn, rGPR:$Rm, CPSR))]>,
999 Requires<[IsThumb2]>, Sched<[WriteALU, ReadALU, ReadALU]> {
1000 let isCommutable = Commutable;
1001 let Inst{31-27} = 0b11101;
1002 let Inst{26-25} = 0b01;
1003 let Inst{24-21} = opcod;
1004 let Inst{14-12} = 0b000; // imm3
1005 let Inst{7-6} = 0b00; // imm2
1006 let Inst{5-4} = 0b00; // type
1009 def rs : T2sTwoRegShiftedReg<
1010 (outs rGPR:$Rd), (ins rGPR:$Rn, t2_so_reg:$ShiftedRm),
1011 IIC_iALUsi, opc, ".w\t$Rd, $Rn, $ShiftedRm",
1012 [(set rGPR:$Rd, CPSR, (opnode rGPR:$Rn, t2_so_reg:$ShiftedRm, CPSR))]>,
1013 Requires<[IsThumb2]>, Sched<[WriteALUsi, ReadALU]> {
1014 let Inst{31-27} = 0b11101;
1015 let Inst{26-25} = 0b01;
1016 let Inst{24-21} = opcod;
1021 /// T2I_sh_ir - Defines a set of (op reg, {so_imm|r}) patterns for a shift /
1022 // rotate operation that produces a value.
1023 multiclass T2I_sh_ir<bits<2> opcod, string opc, Operand ty, SDNode opnode> {
1025 def ri : T2sTwoRegShiftImm<
1026 (outs rGPR:$Rd), (ins rGPR:$Rm, ty:$imm), IIC_iMOVsi,
1027 opc, ".w\t$Rd, $Rm, $imm",
1028 [(set rGPR:$Rd, (opnode rGPR:$Rm, (i32 ty:$imm)))]>,
1030 let Inst{31-27} = 0b11101;
1031 let Inst{26-21} = 0b010010;
1032 let Inst{19-16} = 0b1111; // Rn
1034 let Inst{5-4} = opcod;
1037 def rr : T2sThreeReg<
1038 (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iMOVsr,
1039 opc, ".w\t$Rd, $Rn, $Rm",
1040 [(set rGPR:$Rd, (opnode rGPR:$Rn, rGPR:$Rm))]>,
1042 let Inst{31-27} = 0b11111;
1043 let Inst{26-23} = 0b0100;
1044 let Inst{22-21} = opcod;
1045 let Inst{15-12} = 0b1111;
1046 let Inst{7-4} = 0b0000;
1049 // Optional destination register
1050 def : t2InstAlias<!strconcat(opc, "${s}${p}", ".w $Rdn, $imm"),
1051 (!cast<Instruction>(NAME#"ri") rGPR:$Rdn, rGPR:$Rdn, ty:$imm, pred:$p,
1053 def : t2InstAlias<!strconcat(opc, "${s}${p}", ".w $Rdn, $Rm"),
1054 (!cast<Instruction>(NAME#"rr") rGPR:$Rdn, rGPR:$Rdn, rGPR:$Rm, pred:$p,
1057 // Assembler aliases w/o the ".w" suffix.
1058 def : t2InstAlias<!strconcat(opc, "${s}${p}", " $Rd, $Rn, $imm"),
1059 (!cast<Instruction>(NAME#"ri") rGPR:$Rd, rGPR:$Rn, ty:$imm, pred:$p,
1061 def : t2InstAlias<!strconcat(opc, "${s}${p}", " $Rd, $Rn, $Rm"),
1062 (!cast<Instruction>(NAME#"rr") rGPR:$Rd, rGPR:$Rn, rGPR:$Rm, pred:$p,
1065 // and with the optional destination operand, too.
1066 def : t2InstAlias<!strconcat(opc, "${s}${p}", " $Rdn, $imm"),
1067 (!cast<Instruction>(NAME#"ri") rGPR:$Rdn, rGPR:$Rdn, ty:$imm, pred:$p,
1069 def : t2InstAlias<!strconcat(opc, "${s}${p}", " $Rdn, $Rm"),
1070 (!cast<Instruction>(NAME#"rr") rGPR:$Rdn, rGPR:$Rdn, rGPR:$Rm, pred:$p,
1074 /// T2I_cmp_irs - Defines a set of (op r, {so_imm|r|so_reg}) cmp / test
1075 /// patterns. Similar to T2I_bin_irs except the instruction does not produce
1076 /// a explicit result, only implicitly set CPSR.
1077 multiclass T2I_cmp_irs<bits<4> opcod, string opc, RegisterClass LHSGPR,
1078 InstrItinClass iii, InstrItinClass iir, InstrItinClass iis,
1079 SDPatternOperator opnode> {
1080 let isCompare = 1, Defs = [CPSR] in {
1082 def ri : T2OneRegCmpImm<
1083 (outs), (ins LHSGPR:$Rn, t2_so_imm:$imm), iii,
1084 opc, ".w\t$Rn, $imm",
1085 [(opnode LHSGPR:$Rn, t2_so_imm:$imm)]>, Sched<[WriteCMP]> {
1086 let Inst{31-27} = 0b11110;
1088 let Inst{24-21} = opcod;
1089 let Inst{20} = 1; // The S bit.
1091 let Inst{11-8} = 0b1111; // Rd
1094 def rr : T2TwoRegCmp<
1095 (outs), (ins LHSGPR:$Rn, rGPR:$Rm), iir,
1096 opc, ".w\t$Rn, $Rm",
1097 [(opnode LHSGPR:$Rn, rGPR:$Rm)]>, Sched<[WriteCMP]> {
1098 let Inst{31-27} = 0b11101;
1099 let Inst{26-25} = 0b01;
1100 let Inst{24-21} = opcod;
1101 let Inst{20} = 1; // The S bit.
1102 let Inst{14-12} = 0b000; // imm3
1103 let Inst{11-8} = 0b1111; // Rd
1104 let Inst{7-6} = 0b00; // imm2
1105 let Inst{5-4} = 0b00; // type
1108 def rs : T2OneRegCmpShiftedReg<
1109 (outs), (ins LHSGPR:$Rn, t2_so_reg:$ShiftedRm), iis,
1110 opc, ".w\t$Rn, $ShiftedRm",
1111 [(opnode LHSGPR:$Rn, t2_so_reg:$ShiftedRm)]>,
1112 Sched<[WriteCMPsi]> {
1113 let Inst{31-27} = 0b11101;
1114 let Inst{26-25} = 0b01;
1115 let Inst{24-21} = opcod;
1116 let Inst{20} = 1; // The S bit.
1117 let Inst{11-8} = 0b1111; // Rd
1121 // Assembler aliases w/o the ".w" suffix.
1122 // No alias here for 'rr' version as not all instantiations of this
1123 // multiclass want one (CMP in particular, does not).
1124 def : t2InstAlias<!strconcat(opc, "${p}", " $Rn, $imm"),
1125 (!cast<Instruction>(NAME#"ri") LHSGPR:$Rn, t2_so_imm:$imm, pred:$p)>;
1126 def : t2InstAlias<!strconcat(opc, "${p}", " $Rn, $shift"),
1127 (!cast<Instruction>(NAME#"rs") LHSGPR:$Rn, t2_so_reg:$shift, pred:$p)>;
1130 /// T2I_ld - Defines a set of (op r, {imm12|imm8|so_reg}) load patterns.
1131 multiclass T2I_ld<bit signed, bits<2> opcod, string opc,
1132 InstrItinClass iii, InstrItinClass iis, RegisterClass target,
1134 def i12 : T2Ii12<(outs target:$Rt), (ins t2addrmode_imm12:$addr), iii,
1135 opc, ".w\t$Rt, $addr",
1136 [(set target:$Rt, (opnode t2addrmode_imm12:$addr))]>,
1140 let Inst{31-25} = 0b1111100;
1141 let Inst{24} = signed;
1143 let Inst{22-21} = opcod;
1144 let Inst{20} = 1; // load
1145 let Inst{19-16} = addr{16-13}; // Rn
1146 let Inst{15-12} = Rt;
1147 let Inst{11-0} = addr{11-0}; // imm
1149 let DecoderMethod = "DecodeT2LoadImm12";
1151 def i8 : T2Ii8 <(outs target:$Rt), (ins t2addrmode_negimm8:$addr), iii,
1152 opc, "\t$Rt, $addr",
1153 [(set target:$Rt, (opnode t2addrmode_negimm8:$addr))]>,
1157 let Inst{31-27} = 0b11111;
1158 let Inst{26-25} = 0b00;
1159 let Inst{24} = signed;
1161 let Inst{22-21} = opcod;
1162 let Inst{20} = 1; // load
1163 let Inst{19-16} = addr{12-9}; // Rn
1164 let Inst{15-12} = Rt;
1166 // Offset: index==TRUE, wback==FALSE
1167 let Inst{10} = 1; // The P bit.
1168 let Inst{9} = addr{8}; // U
1169 let Inst{8} = 0; // The W bit.
1170 let Inst{7-0} = addr{7-0}; // imm
1172 let DecoderMethod = "DecodeT2LoadImm8";
1174 def s : T2Iso <(outs target:$Rt), (ins t2addrmode_so_reg:$addr), iis,
1175 opc, ".w\t$Rt, $addr",
1176 [(set target:$Rt, (opnode t2addrmode_so_reg:$addr))]>,
1178 let Inst{31-27} = 0b11111;
1179 let Inst{26-25} = 0b00;
1180 let Inst{24} = signed;
1182 let Inst{22-21} = opcod;
1183 let Inst{20} = 1; // load
1184 let Inst{11-6} = 0b000000;
1187 let Inst{15-12} = Rt;
1190 let Inst{19-16} = addr{9-6}; // Rn
1191 let Inst{3-0} = addr{5-2}; // Rm
1192 let Inst{5-4} = addr{1-0}; // imm
1194 let DecoderMethod = "DecodeT2LoadShift";
1197 // pci variant is very similar to i12, but supports negative offsets
1199 def pci : T2Ipc <(outs target:$Rt), (ins t2ldrlabel:$addr), iii,
1200 opc, ".w\t$Rt, $addr",
1201 [(set target:$Rt, (opnode (ARMWrapper tconstpool:$addr)))]>,
1203 let isReMaterializable = 1;
1204 let Inst{31-27} = 0b11111;
1205 let Inst{26-25} = 0b00;
1206 let Inst{24} = signed;
1207 let Inst{22-21} = opcod;
1208 let Inst{20} = 1; // load
1209 let Inst{19-16} = 0b1111; // Rn
1212 let Inst{15-12} = Rt{3-0};
1215 let Inst{23} = addr{12}; // add = (U == '1')
1216 let Inst{11-0} = addr{11-0};
1218 let DecoderMethod = "DecodeT2LoadLabel";
1222 /// T2I_st - Defines a set of (op r, {imm12|imm8|so_reg}) store patterns.
1223 multiclass T2I_st<bits<2> opcod, string opc,
1224 InstrItinClass iii, InstrItinClass iis, RegisterClass target,
1226 def i12 : T2Ii12<(outs), (ins target:$Rt, t2addrmode_imm12:$addr), iii,
1227 opc, ".w\t$Rt, $addr",
1228 [(opnode target:$Rt, t2addrmode_imm12:$addr)]>,
1230 let Inst{31-27} = 0b11111;
1231 let Inst{26-23} = 0b0001;
1232 let Inst{22-21} = opcod;
1233 let Inst{20} = 0; // !load
1236 let Inst{15-12} = Rt;
1239 let addr{12} = 1; // add = TRUE
1240 let Inst{19-16} = addr{16-13}; // Rn
1241 let Inst{23} = addr{12}; // U
1242 let Inst{11-0} = addr{11-0}; // imm
1244 def i8 : T2Ii8 <(outs), (ins target:$Rt, t2addrmode_negimm8:$addr), iii,
1245 opc, "\t$Rt, $addr",
1246 [(opnode target:$Rt, t2addrmode_negimm8:$addr)]>,
1248 let Inst{31-27} = 0b11111;
1249 let Inst{26-23} = 0b0000;
1250 let Inst{22-21} = opcod;
1251 let Inst{20} = 0; // !load
1253 // Offset: index==TRUE, wback==FALSE
1254 let Inst{10} = 1; // The P bit.
1255 let Inst{8} = 0; // The W bit.
1258 let Inst{15-12} = Rt;
1261 let Inst{19-16} = addr{12-9}; // Rn
1262 let Inst{9} = addr{8}; // U
1263 let Inst{7-0} = addr{7-0}; // imm
1265 def s : T2Iso <(outs), (ins target:$Rt, t2addrmode_so_reg:$addr), iis,
1266 opc, ".w\t$Rt, $addr",
1267 [(opnode target:$Rt, t2addrmode_so_reg:$addr)]>,
1269 let Inst{31-27} = 0b11111;
1270 let Inst{26-23} = 0b0000;
1271 let Inst{22-21} = opcod;
1272 let Inst{20} = 0; // !load
1273 let Inst{11-6} = 0b000000;
1276 let Inst{15-12} = Rt;
1279 let Inst{19-16} = addr{9-6}; // Rn
1280 let Inst{3-0} = addr{5-2}; // Rm
1281 let Inst{5-4} = addr{1-0}; // imm
1285 /// T2I_ext_rrot - A unary operation with two forms: one whose operand is a
1286 /// register and one whose operand is a register rotated by 8/16/24.
1287 class T2I_ext_rrot_base<bits<3> opcod, dag iops, dag oops,
1288 string opc, string oprs,
1290 : T2TwoReg<iops, oops, IIC_iEXTr, opc, oprs, pattern> {
1292 let Inst{31-27} = 0b11111;
1293 let Inst{26-23} = 0b0100;
1294 let Inst{22-20} = opcod;
1295 let Inst{19-16} = 0b1111; // Rn
1296 let Inst{15-12} = 0b1111;
1298 let Inst{5-4} = rot; // rotate
1301 class T2I_ext_rrot<bits<3> opcod, string opc>
1302 : T2I_ext_rrot_base<opcod,
1304 (ins rGPR:$Rm, rot_imm:$rot),
1305 opc, ".w\t$Rd, $Rm$rot", []>,
1306 Requires<[IsThumb2]>,
1307 Sched<[WriteALU, ReadALU]>;
1309 // UXTB16, SXTB16 - Requires HasDSP, does not need the .w qualifier.
1310 class T2I_ext_rrot_xtb16<bits<3> opcod, string opc>
1311 : T2I_ext_rrot_base<opcod,
1313 (ins rGPR:$Rm, rot_imm:$rot),
1314 opc, "\t$Rd, $Rm$rot", []>,
1315 Requires<[HasDSP, IsThumb2]>,
1316 Sched<[WriteALU, ReadALU]>;
1318 /// T2I_exta_rrot - A binary operation with two forms: one whose operand is a
1319 /// register and one whose operand is a register rotated by 8/16/24.
1320 class T2I_exta_rrot<bits<3> opcod, string opc>
1321 : T2ThreeReg<(outs rGPR:$Rd),
1322 (ins rGPR:$Rn, rGPR:$Rm, rot_imm:$rot),
1323 IIC_iEXTAsr, opc, "\t$Rd, $Rn, $Rm$rot", []>,
1324 Requires<[HasDSP, IsThumb2]>,
1325 Sched<[WriteALU, ReadALU]> {
1327 let Inst{31-27} = 0b11111;
1328 let Inst{26-23} = 0b0100;
1329 let Inst{22-20} = opcod;
1330 let Inst{15-12} = 0b1111;
1332 let Inst{5-4} = rot;
1335 //===----------------------------------------------------------------------===//
1337 //===----------------------------------------------------------------------===//
1339 //===----------------------------------------------------------------------===//
1340 // Miscellaneous Instructions.
1343 class T2PCOneRegImm<dag oops, dag iops, InstrItinClass itin,
1344 string asm, list<dag> pattern>
1345 : T2XI<oops, iops, itin, asm, pattern> {
1349 let Inst{11-8} = Rd;
1350 let Inst{26} = label{11};
1351 let Inst{14-12} = label{10-8};
1352 let Inst{7-0} = label{7-0};
1355 // LEApcrel - Load a pc-relative address into a register without offending the
1357 def t2ADR : T2PCOneRegImm<(outs rGPR:$Rd),
1358 (ins t2adrlabel:$addr, pred:$p),
1359 IIC_iALUi, "adr{$p}.w\t$Rd, $addr", []>,
1360 Sched<[WriteALU, ReadALU]> {
1361 let Inst{31-27} = 0b11110;
1362 let Inst{25-24} = 0b10;
1363 // Inst{23:21} = '11' (add = FALSE) or '00' (add = TRUE)
1366 let Inst{19-16} = 0b1111; // Rn
1371 let Inst{11-8} = Rd;
1372 let Inst{23} = addr{12};
1373 let Inst{21} = addr{12};
1374 let Inst{26} = addr{11};
1375 let Inst{14-12} = addr{10-8};
1376 let Inst{7-0} = addr{7-0};
1378 let DecoderMethod = "DecodeT2Adr";
1381 let hasSideEffects = 0, isReMaterializable = 1 in
1382 def t2LEApcrel : t2PseudoInst<(outs rGPR:$Rd), (ins i32imm:$label, pred:$p),
1383 4, IIC_iALUi, []>, Sched<[WriteALU, ReadALU]>;
1384 let hasSideEffects = 1 in
1385 def t2LEApcrelJT : t2PseudoInst<(outs rGPR:$Rd),
1386 (ins i32imm:$label, pred:$p),
1388 []>, Sched<[WriteALU, ReadALU]>;
1391 //===----------------------------------------------------------------------===//
1392 // Load / store Instructions.
1396 let canFoldAsLoad = 1, isReMaterializable = 1 in
1397 defm t2LDR : T2I_ld<0, 0b10, "ldr", IIC_iLoad_i, IIC_iLoad_si, GPR, load>;
1399 // Loads with zero extension
1400 defm t2LDRH : T2I_ld<0, 0b01, "ldrh", IIC_iLoad_bh_i, IIC_iLoad_bh_si,
1401 GPRnopc, zextloadi16>;
1402 defm t2LDRB : T2I_ld<0, 0b00, "ldrb", IIC_iLoad_bh_i, IIC_iLoad_bh_si,
1403 GPRnopc, zextloadi8>;
1405 // Loads with sign extension
1406 defm t2LDRSH : T2I_ld<1, 0b01, "ldrsh", IIC_iLoad_bh_i, IIC_iLoad_bh_si,
1407 GPRnopc, sextloadi16>;
1408 defm t2LDRSB : T2I_ld<1, 0b00, "ldrsb", IIC_iLoad_bh_i, IIC_iLoad_bh_si,
1409 GPRnopc, sextloadi8>;
1411 let mayLoad = 1, hasSideEffects = 0, hasExtraDefRegAllocReq = 1 in {
1413 def t2LDRDi8 : T2Ii8s4<1, 0, 1, (outs rGPR:$Rt, rGPR:$Rt2),
1414 (ins t2addrmode_imm8s4:$addr),
1415 IIC_iLoad_d_i, "ldrd", "\t$Rt, $Rt2, $addr", "", []>,
1417 } // mayLoad = 1, hasSideEffects = 0, hasExtraDefRegAllocReq = 1
1419 // zextload i1 -> zextload i8
1420 def : T2Pat<(zextloadi1 t2addrmode_imm12:$addr),
1421 (t2LDRBi12 t2addrmode_imm12:$addr)>;
1422 def : T2Pat<(zextloadi1 t2addrmode_negimm8:$addr),
1423 (t2LDRBi8 t2addrmode_negimm8:$addr)>;
1424 def : T2Pat<(zextloadi1 t2addrmode_so_reg:$addr),
1425 (t2LDRBs t2addrmode_so_reg:$addr)>;
1426 def : T2Pat<(zextloadi1 (ARMWrapper tconstpool:$addr)),
1427 (t2LDRBpci tconstpool:$addr)>;
1429 // extload -> zextload
1430 // FIXME: Reduce the number of patterns by legalizing extload to zextload
1432 def : T2Pat<(extloadi1 t2addrmode_imm12:$addr),
1433 (t2LDRBi12 t2addrmode_imm12:$addr)>;
1434 def : T2Pat<(extloadi1 t2addrmode_negimm8:$addr),
1435 (t2LDRBi8 t2addrmode_negimm8:$addr)>;
1436 def : T2Pat<(extloadi1 t2addrmode_so_reg:$addr),
1437 (t2LDRBs t2addrmode_so_reg:$addr)>;
1438 def : T2Pat<(extloadi1 (ARMWrapper tconstpool:$addr)),
1439 (t2LDRBpci tconstpool:$addr)>;
1441 def : T2Pat<(extloadi8 t2addrmode_imm12:$addr),
1442 (t2LDRBi12 t2addrmode_imm12:$addr)>;
1443 def : T2Pat<(extloadi8 t2addrmode_negimm8:$addr),
1444 (t2LDRBi8 t2addrmode_negimm8:$addr)>;
1445 def : T2Pat<(extloadi8 t2addrmode_so_reg:$addr),
1446 (t2LDRBs t2addrmode_so_reg:$addr)>;
1447 def : T2Pat<(extloadi8 (ARMWrapper tconstpool:$addr)),
1448 (t2LDRBpci tconstpool:$addr)>;
1450 def : T2Pat<(extloadi16 t2addrmode_imm12:$addr),
1451 (t2LDRHi12 t2addrmode_imm12:$addr)>;
1452 def : T2Pat<(extloadi16 t2addrmode_negimm8:$addr),
1453 (t2LDRHi8 t2addrmode_negimm8:$addr)>;
1454 def : T2Pat<(extloadi16 t2addrmode_so_reg:$addr),
1455 (t2LDRHs t2addrmode_so_reg:$addr)>;
1456 def : T2Pat<(extloadi16 (ARMWrapper tconstpool:$addr)),
1457 (t2LDRHpci tconstpool:$addr)>;
1459 // FIXME: The destination register of the loads and stores can't be PC, but
1460 // can be SP. We need another regclass (similar to rGPR) to represent
1461 // that. Not a pressing issue since these are selected manually,
1466 let mayLoad = 1, hasSideEffects = 0 in {
1467 def t2LDR_PRE : T2Ipreldst<0, 0b10, 1, 1, (outs GPR:$Rt, GPR:$Rn_wb),
1468 (ins t2addrmode_imm8_pre:$addr),
1469 AddrModeT2_i8, IndexModePre, IIC_iLoad_iu,
1470 "ldr", "\t$Rt, $addr!", "$addr.base = $Rn_wb", []>,
1473 def t2LDR_POST : T2Ipostldst<0, 0b10, 1, 0, (outs GPR:$Rt, GPR:$Rn_wb),
1474 (ins addr_offset_none:$Rn, t2am_imm8_offset:$offset),
1475 AddrModeT2_i8, IndexModePost, IIC_iLoad_iu,
1476 "ldr", "\t$Rt, $Rn$offset", "$Rn = $Rn_wb", []>,
1479 def t2LDRB_PRE : T2Ipreldst<0, 0b00, 1, 1, (outs GPR:$Rt, GPR:$Rn_wb),
1480 (ins t2addrmode_imm8_pre:$addr),
1481 AddrModeT2_i8, IndexModePre, IIC_iLoad_bh_iu,
1482 "ldrb", "\t$Rt, $addr!", "$addr.base = $Rn_wb", []>,
1485 def t2LDRB_POST : T2Ipostldst<0, 0b00, 1, 0, (outs GPR:$Rt, GPR:$Rn_wb),
1486 (ins addr_offset_none:$Rn, t2am_imm8_offset:$offset),
1487 AddrModeT2_i8, IndexModePost, IIC_iLoad_bh_iu,
1488 "ldrb", "\t$Rt, $Rn$offset", "$Rn = $Rn_wb", []>,
1491 def t2LDRH_PRE : T2Ipreldst<0, 0b01, 1, 1, (outs GPR:$Rt, GPR:$Rn_wb),
1492 (ins t2addrmode_imm8_pre:$addr),
1493 AddrModeT2_i8, IndexModePre, IIC_iLoad_bh_iu,
1494 "ldrh", "\t$Rt, $addr!", "$addr.base = $Rn_wb", []>,
1497 def t2LDRH_POST : T2Ipostldst<0, 0b01, 1, 0, (outs GPR:$Rt, GPR:$Rn_wb),
1498 (ins addr_offset_none:$Rn, t2am_imm8_offset:$offset),
1499 AddrModeT2_i8, IndexModePost, IIC_iLoad_bh_iu,
1500 "ldrh", "\t$Rt, $Rn$offset", "$Rn = $Rn_wb", []>,
1503 def t2LDRSB_PRE : T2Ipreldst<1, 0b00, 1, 1, (outs GPR:$Rt, GPR:$Rn_wb),
1504 (ins t2addrmode_imm8_pre:$addr),
1505 AddrModeT2_i8, IndexModePre, IIC_iLoad_bh_iu,
1506 "ldrsb", "\t$Rt, $addr!", "$addr.base = $Rn_wb",
1507 []>, Sched<[WriteLd]>;
1509 def t2LDRSB_POST : T2Ipostldst<1, 0b00, 1, 0, (outs GPR:$Rt, GPR:$Rn_wb),
1510 (ins addr_offset_none:$Rn, t2am_imm8_offset:$offset),
1511 AddrModeT2_i8, IndexModePost, IIC_iLoad_bh_iu,
1512 "ldrsb", "\t$Rt, $Rn$offset", "$Rn = $Rn_wb", []>,
1515 def t2LDRSH_PRE : T2Ipreldst<1, 0b01, 1, 1, (outs GPR:$Rt, GPR:$Rn_wb),
1516 (ins t2addrmode_imm8_pre:$addr),
1517 AddrModeT2_i8, IndexModePre, IIC_iLoad_bh_iu,
1518 "ldrsh", "\t$Rt, $addr!", "$addr.base = $Rn_wb",
1519 []>, Sched<[WriteLd]>;
1521 def t2LDRSH_POST : T2Ipostldst<1, 0b01, 1, 0, (outs GPR:$Rt, GPR:$Rn_wb),
1522 (ins addr_offset_none:$Rn, t2am_imm8_offset:$offset),
1523 AddrModeT2_i8, IndexModePost, IIC_iLoad_bh_iu,
1524 "ldrsh", "\t$Rt, $Rn$offset", "$Rn = $Rn_wb", []>,
1526 } // mayLoad = 1, hasSideEffects = 0
1528 // LDRT, LDRBT, LDRHT, LDRSBT, LDRSHT all have offset mode (PUW=0b110).
1529 // Ref: A8.6.57 LDR (immediate, Thumb) Encoding T4
1530 class T2IldT<bit signed, bits<2> type, string opc, InstrItinClass ii>
1531 : T2Ii8<(outs rGPR:$Rt), (ins t2addrmode_posimm8:$addr), ii, opc,
1532 "\t$Rt, $addr", []>, Sched<[WriteLd]> {
1535 let Inst{31-27} = 0b11111;
1536 let Inst{26-25} = 0b00;
1537 let Inst{24} = signed;
1539 let Inst{22-21} = type;
1540 let Inst{20} = 1; // load
1541 let Inst{19-16} = addr{12-9};
1542 let Inst{15-12} = Rt;
1544 let Inst{10-8} = 0b110; // PUW.
1545 let Inst{7-0} = addr{7-0};
1547 let DecoderMethod = "DecodeT2LoadT";
1550 def t2LDRT : T2IldT<0, 0b10, "ldrt", IIC_iLoad_i>;
1551 def t2LDRBT : T2IldT<0, 0b00, "ldrbt", IIC_iLoad_bh_i>;
1552 def t2LDRHT : T2IldT<0, 0b01, "ldrht", IIC_iLoad_bh_i>;
1553 def t2LDRSBT : T2IldT<1, 0b00, "ldrsbt", IIC_iLoad_bh_i>;
1554 def t2LDRSHT : T2IldT<1, 0b01, "ldrsht", IIC_iLoad_bh_i>;
1556 class T2Ildacq<bits<4> bits23_20, bits<2> bit54, dag oops, dag iops,
1557 string opc, string asm, list<dag> pattern>
1558 : Thumb2I<oops, iops, AddrModeNone, 4, NoItinerary,
1559 opc, asm, "", pattern>, Requires<[IsThumb, HasAcquireRelease]> {
1563 let Inst{31-27} = 0b11101;
1564 let Inst{26-24} = 0b000;
1565 let Inst{23-20} = bits23_20;
1566 let Inst{11-6} = 0b111110;
1567 let Inst{5-4} = bit54;
1568 let Inst{3-0} = 0b1111;
1570 // Encode instruction operands
1571 let Inst{19-16} = addr;
1572 let Inst{15-12} = Rt;
1575 def t2LDA : T2Ildacq<0b1101, 0b10, (outs rGPR:$Rt),
1576 (ins addr_offset_none:$addr), "lda", "\t$Rt, $addr", []>,
1578 def t2LDAB : T2Ildacq<0b1101, 0b00, (outs rGPR:$Rt),
1579 (ins addr_offset_none:$addr), "ldab", "\t$Rt, $addr", []>,
1581 def t2LDAH : T2Ildacq<0b1101, 0b01, (outs rGPR:$Rt),
1582 (ins addr_offset_none:$addr), "ldah", "\t$Rt, $addr", []>,
1586 defm t2STR :T2I_st<0b10,"str", IIC_iStore_i, IIC_iStore_si, GPR, store>;
1587 defm t2STRB:T2I_st<0b00,"strb", IIC_iStore_bh_i, IIC_iStore_bh_si,
1588 rGPR, truncstorei8>;
1589 defm t2STRH:T2I_st<0b01,"strh", IIC_iStore_bh_i, IIC_iStore_bh_si,
1590 rGPR, truncstorei16>;
1593 let mayStore = 1, hasSideEffects = 0, hasExtraSrcRegAllocReq = 1 in
1594 def t2STRDi8 : T2Ii8s4<1, 0, 0, (outs),
1595 (ins rGPR:$Rt, rGPR:$Rt2, t2addrmode_imm8s4:$addr),
1596 IIC_iStore_d_r, "strd", "\t$Rt, $Rt2, $addr", "", []>,
1601 let mayStore = 1, hasSideEffects = 0 in {
1602 def t2STR_PRE : T2Ipreldst<0, 0b10, 0, 1, (outs GPRnopc:$Rn_wb),
1603 (ins GPRnopc:$Rt, t2addrmode_imm8_pre:$addr),
1604 AddrModeT2_i8, IndexModePre, IIC_iStore_iu,
1605 "str", "\t$Rt, $addr!",
1606 "$addr.base = $Rn_wb,@earlyclobber $Rn_wb", []>,
1609 def t2STRH_PRE : T2Ipreldst<0, 0b01, 0, 1, (outs GPRnopc:$Rn_wb),
1610 (ins rGPR:$Rt, t2addrmode_imm8_pre:$addr),
1611 AddrModeT2_i8, IndexModePre, IIC_iStore_iu,
1612 "strh", "\t$Rt, $addr!",
1613 "$addr.base = $Rn_wb,@earlyclobber $Rn_wb", []>,
1616 def t2STRB_PRE : T2Ipreldst<0, 0b00, 0, 1, (outs GPRnopc:$Rn_wb),
1617 (ins rGPR:$Rt, t2addrmode_imm8_pre:$addr),
1618 AddrModeT2_i8, IndexModePre, IIC_iStore_bh_iu,
1619 "strb", "\t$Rt, $addr!",
1620 "$addr.base = $Rn_wb,@earlyclobber $Rn_wb", []>,
1622 } // mayStore = 1, hasSideEffects = 0
1624 def t2STR_POST : T2Ipostldst<0, 0b10, 0, 0, (outs GPRnopc:$Rn_wb),
1625 (ins GPRnopc:$Rt, addr_offset_none:$Rn,
1626 t2am_imm8_offset:$offset),
1627 AddrModeT2_i8, IndexModePost, IIC_iStore_iu,
1628 "str", "\t$Rt, $Rn$offset",
1629 "$Rn = $Rn_wb,@earlyclobber $Rn_wb",
1630 [(set GPRnopc:$Rn_wb,
1631 (post_store GPRnopc:$Rt, addr_offset_none:$Rn,
1632 t2am_imm8_offset:$offset))]>,
1635 def t2STRH_POST : T2Ipostldst<0, 0b01, 0, 0, (outs GPRnopc:$Rn_wb),
1636 (ins rGPR:$Rt, addr_offset_none:$Rn,
1637 t2am_imm8_offset:$offset),
1638 AddrModeT2_i8, IndexModePost, IIC_iStore_bh_iu,
1639 "strh", "\t$Rt, $Rn$offset",
1640 "$Rn = $Rn_wb,@earlyclobber $Rn_wb",
1641 [(set GPRnopc:$Rn_wb,
1642 (post_truncsti16 rGPR:$Rt, addr_offset_none:$Rn,
1643 t2am_imm8_offset:$offset))]>,
1646 def t2STRB_POST : T2Ipostldst<0, 0b00, 0, 0, (outs GPRnopc:$Rn_wb),
1647 (ins rGPR:$Rt, addr_offset_none:$Rn,
1648 t2am_imm8_offset:$offset),
1649 AddrModeT2_i8, IndexModePost, IIC_iStore_bh_iu,
1650 "strb", "\t$Rt, $Rn$offset",
1651 "$Rn = $Rn_wb,@earlyclobber $Rn_wb",
1652 [(set GPRnopc:$Rn_wb,
1653 (post_truncsti8 rGPR:$Rt, addr_offset_none:$Rn,
1654 t2am_imm8_offset:$offset))]>,
1657 // Pseudo-instructions for pattern matching the pre-indexed stores. We can't
1658 // put the patterns on the instruction definitions directly as ISel wants
1659 // the address base and offset to be separate operands, not a single
1660 // complex operand like we represent the instructions themselves. The
1661 // pseudos map between the two.
1662 let usesCustomInserter = 1,
1663 Constraints = "$Rn = $Rn_wb,@earlyclobber $Rn_wb" in {
1664 def t2STR_preidx: t2PseudoInst<(outs GPRnopc:$Rn_wb),
1665 (ins rGPR:$Rt, GPRnopc:$Rn, t2am_imm8_offset:$offset, pred:$p),
1667 [(set GPRnopc:$Rn_wb,
1668 (pre_store rGPR:$Rt, GPRnopc:$Rn, t2am_imm8_offset:$offset))]>,
1670 def t2STRB_preidx: t2PseudoInst<(outs GPRnopc:$Rn_wb),
1671 (ins rGPR:$Rt, GPRnopc:$Rn, t2am_imm8_offset:$offset, pred:$p),
1673 [(set GPRnopc:$Rn_wb,
1674 (pre_truncsti8 rGPR:$Rt, GPRnopc:$Rn, t2am_imm8_offset:$offset))]>,
1676 def t2STRH_preidx: t2PseudoInst<(outs GPRnopc:$Rn_wb),
1677 (ins rGPR:$Rt, GPRnopc:$Rn, t2am_imm8_offset:$offset, pred:$p),
1679 [(set GPRnopc:$Rn_wb,
1680 (pre_truncsti16 rGPR:$Rt, GPRnopc:$Rn, t2am_imm8_offset:$offset))]>,
1684 // STRT, STRBT, STRHT all have offset mode (PUW=0b110) and are for disassembly
1686 // Ref: A8.6.193 STR (immediate, Thumb) Encoding T4
1687 class T2IstT<bits<2> type, string opc, InstrItinClass ii>
1688 : T2Ii8<(outs rGPR:$Rt), (ins t2addrmode_imm8:$addr), ii, opc,
1689 "\t$Rt, $addr", []>, Sched<[WriteST]> {
1690 let Inst{31-27} = 0b11111;
1691 let Inst{26-25} = 0b00;
1692 let Inst{24} = 0; // not signed
1694 let Inst{22-21} = type;
1695 let Inst{20} = 0; // store
1697 let Inst{10-8} = 0b110; // PUW
1701 let Inst{15-12} = Rt;
1702 let Inst{19-16} = addr{12-9};
1703 let Inst{7-0} = addr{7-0};
1706 def t2STRT : T2IstT<0b10, "strt", IIC_iStore_i>;
1707 def t2STRBT : T2IstT<0b00, "strbt", IIC_iStore_bh_i>;
1708 def t2STRHT : T2IstT<0b01, "strht", IIC_iStore_bh_i>;
1710 // ldrd / strd pre / post variants
1713 def t2LDRD_PRE : T2Ii8s4<1, 1, 1, (outs rGPR:$Rt, rGPR:$Rt2, GPR:$wb),
1714 (ins t2addrmode_imm8s4_pre:$addr), IIC_iLoad_d_ru,
1715 "ldrd", "\t$Rt, $Rt2, $addr!", "$addr.base = $wb", []>,
1717 let DecoderMethod = "DecodeT2LDRDPreInstruction";
1721 def t2LDRD_POST : T2Ii8s4post<0, 1, 1, (outs rGPR:$Rt, rGPR:$Rt2, GPR:$wb),
1722 (ins addr_offset_none:$addr, t2am_imm8s4_offset:$imm),
1723 IIC_iLoad_d_ru, "ldrd", "\t$Rt, $Rt2, $addr$imm",
1724 "$addr.base = $wb", []>, Sched<[WriteLd]>;
1727 def t2STRD_PRE : T2Ii8s4<1, 1, 0, (outs GPR:$wb),
1728 (ins rGPR:$Rt, rGPR:$Rt2, t2addrmode_imm8s4_pre:$addr),
1729 IIC_iStore_d_ru, "strd", "\t$Rt, $Rt2, $addr!",
1730 "$addr.base = $wb", []>, Sched<[WriteST]> {
1731 let DecoderMethod = "DecodeT2STRDPreInstruction";
1735 def t2STRD_POST : T2Ii8s4post<0, 1, 0, (outs GPR:$wb),
1736 (ins rGPR:$Rt, rGPR:$Rt2, addr_offset_none:$addr,
1737 t2am_imm8s4_offset:$imm),
1738 IIC_iStore_d_ru, "strd", "\t$Rt, $Rt2, $addr$imm",
1739 "$addr.base = $wb", []>, Sched<[WriteST]>;
1741 class T2Istrrel<bits<2> bit54, dag oops, dag iops,
1742 string opc, string asm, list<dag> pattern>
1743 : Thumb2I<oops, iops, AddrModeNone, 4, NoItinerary, opc,
1744 asm, "", pattern>, Requires<[IsThumb, HasAcquireRelease]>,
1749 let Inst{31-27} = 0b11101;
1750 let Inst{26-20} = 0b0001100;
1751 let Inst{11-6} = 0b111110;
1752 let Inst{5-4} = bit54;
1753 let Inst{3-0} = 0b1111;
1755 // Encode instruction operands
1756 let Inst{19-16} = addr;
1757 let Inst{15-12} = Rt;
1760 def t2STL : T2Istrrel<0b10, (outs), (ins rGPR:$Rt, addr_offset_none:$addr),
1761 "stl", "\t$Rt, $addr", []>;
1762 def t2STLB : T2Istrrel<0b00, (outs), (ins rGPR:$Rt, addr_offset_none:$addr),
1763 "stlb", "\t$Rt, $addr", []>;
1764 def t2STLH : T2Istrrel<0b01, (outs), (ins rGPR:$Rt, addr_offset_none:$addr),
1765 "stlh", "\t$Rt, $addr", []>;
1767 // T2Ipl (Preload Data/Instruction) signals the memory system of possible future
1768 // data/instruction access.
1769 // instr_write is inverted for Thumb mode: (prefetch 3) -> (preload 0),
1770 // (prefetch 1) -> (preload 2), (prefetch 2) -> (preload 1).
1771 multiclass T2Ipl<bits<1> write, bits<1> instr, string opc> {
1773 def i12 : T2Ii12<(outs), (ins t2addrmode_imm12:$addr), IIC_Preload, opc,
1775 [(ARMPreload t2addrmode_imm12:$addr, (i32 write), (i32 instr))]>,
1776 Sched<[WritePreLd]> {
1777 let Inst{31-25} = 0b1111100;
1778 let Inst{24} = instr;
1781 let Inst{21} = write;
1783 let Inst{15-12} = 0b1111;
1786 let Inst{19-16} = addr{16-13}; // Rn
1787 let Inst{11-0} = addr{11-0}; // imm12
1789 let DecoderMethod = "DecodeT2LoadImm12";
1792 def i8 : T2Ii8<(outs), (ins t2addrmode_negimm8:$addr), IIC_Preload, opc,
1794 [(ARMPreload t2addrmode_negimm8:$addr, (i32 write), (i32 instr))]>,
1795 Sched<[WritePreLd]> {
1796 let Inst{31-25} = 0b1111100;
1797 let Inst{24} = instr;
1798 let Inst{23} = 0; // U = 0
1800 let Inst{21} = write;
1802 let Inst{15-12} = 0b1111;
1803 let Inst{11-8} = 0b1100;
1806 let Inst{19-16} = addr{12-9}; // Rn
1807 let Inst{7-0} = addr{7-0}; // imm8
1809 let DecoderMethod = "DecodeT2LoadImm8";
1812 def s : T2Iso<(outs), (ins t2addrmode_so_reg:$addr), IIC_Preload, opc,
1814 [(ARMPreload t2addrmode_so_reg:$addr, (i32 write), (i32 instr))]>,
1815 Sched<[WritePreLd]> {
1816 let Inst{31-25} = 0b1111100;
1817 let Inst{24} = instr;
1818 let Inst{23} = 0; // add = TRUE for T1
1820 let Inst{21} = write;
1822 let Inst{15-12} = 0b1111;
1823 let Inst{11-6} = 0b000000;
1826 let Inst{19-16} = addr{9-6}; // Rn
1827 let Inst{3-0} = addr{5-2}; // Rm
1828 let Inst{5-4} = addr{1-0}; // imm2
1830 let DecoderMethod = "DecodeT2LoadShift";
1834 defm t2PLD : T2Ipl<0, 0, "pld">, Requires<[IsThumb2]>;
1835 defm t2PLDW : T2Ipl<1, 0, "pldw">, Requires<[IsThumb2,HasV7,HasMP]>;
1836 defm t2PLI : T2Ipl<0, 1, "pli">, Requires<[IsThumb2,HasV7]>;
1838 // pci variant is very similar to i12, but supports negative offsets
1839 // from the PC. Only PLD and PLI have pci variants (not PLDW)
1840 class T2Iplpci<bits<1> inst, string opc> : T2Iso<(outs), (ins t2ldrlabel:$addr),
1841 IIC_Preload, opc, "\t$addr",
1842 [(ARMPreload (ARMWrapper tconstpool:$addr),
1843 (i32 0), (i32 inst))]>, Sched<[WritePreLd]> {
1844 let Inst{31-25} = 0b1111100;
1845 let Inst{24} = inst;
1846 let Inst{22-20} = 0b001;
1847 let Inst{19-16} = 0b1111;
1848 let Inst{15-12} = 0b1111;
1851 let Inst{23} = addr{12}; // add = (U == '1')
1852 let Inst{11-0} = addr{11-0}; // imm12
1854 let DecoderMethod = "DecodeT2LoadLabel";
1857 def t2PLDpci : T2Iplpci<0, "pld">, Requires<[IsThumb2]>;
1858 def t2PLIpci : T2Iplpci<1, "pli">, Requires<[IsThumb2,HasV7]>;
1860 //===----------------------------------------------------------------------===//
1861 // Load / store multiple Instructions.
1864 multiclass thumb2_ld_mult<string asm, InstrItinClass itin,
1865 InstrItinClass itin_upd, bit L_bit> {
1867 T2XI<(outs), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops),
1868 itin, !strconcat(asm, "${p}.w\t$Rn, $regs"), []> {
1872 let Inst{31-27} = 0b11101;
1873 let Inst{26-25} = 0b00;
1874 let Inst{24-23} = 0b01; // Increment After
1876 let Inst{21} = 0; // No writeback
1877 let Inst{20} = L_bit;
1878 let Inst{19-16} = Rn;
1879 let Inst{15-0} = regs;
1882 T2XIt<(outs GPR:$wb), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops),
1883 itin_upd, !strconcat(asm, "${p}.w\t$Rn!, $regs"), "$Rn = $wb", []> {
1887 let Inst{31-27} = 0b11101;
1888 let Inst{26-25} = 0b00;
1889 let Inst{24-23} = 0b01; // Increment After
1891 let Inst{21} = 1; // Writeback
1892 let Inst{20} = L_bit;
1893 let Inst{19-16} = Rn;
1894 let Inst{15-0} = regs;
1897 T2XI<(outs), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops),
1898 itin, !strconcat(asm, "db${p}\t$Rn, $regs"), []> {
1902 let Inst{31-27} = 0b11101;
1903 let Inst{26-25} = 0b00;
1904 let Inst{24-23} = 0b10; // Decrement Before
1906 let Inst{21} = 0; // No writeback
1907 let Inst{20} = L_bit;
1908 let Inst{19-16} = Rn;
1909 let Inst{15-0} = regs;
1912 T2XIt<(outs GPR:$wb), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops),
1913 itin_upd, !strconcat(asm, "db${p}\t$Rn!, $regs"), "$Rn = $wb", []> {
1917 let Inst{31-27} = 0b11101;
1918 let Inst{26-25} = 0b00;
1919 let Inst{24-23} = 0b10; // Decrement Before
1921 let Inst{21} = 1; // Writeback
1922 let Inst{20} = L_bit;
1923 let Inst{19-16} = Rn;
1924 let Inst{15-0} = regs;
1928 let hasSideEffects = 0 in {
1930 let mayLoad = 1, hasExtraDefRegAllocReq = 1, variadicOpsAreDefs = 1 in
1931 defm t2LDM : thumb2_ld_mult<"ldm", IIC_iLoad_m, IIC_iLoad_mu, 1>;
1933 multiclass thumb2_st_mult<string asm, InstrItinClass itin,
1934 InstrItinClass itin_upd, bit L_bit> {
1936 T2XI<(outs), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops),
1937 itin, !strconcat(asm, "${p}.w\t$Rn, $regs"), []> {
1941 let Inst{31-27} = 0b11101;
1942 let Inst{26-25} = 0b00;
1943 let Inst{24-23} = 0b01; // Increment After
1945 let Inst{21} = 0; // No writeback
1946 let Inst{20} = L_bit;
1947 let Inst{19-16} = Rn;
1949 let Inst{14} = regs{14};
1951 let Inst{12-0} = regs{12-0};
1954 T2XIt<(outs GPR:$wb), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops),
1955 itin_upd, !strconcat(asm, "${p}.w\t$Rn!, $regs"), "$Rn = $wb", []> {
1959 let Inst{31-27} = 0b11101;
1960 let Inst{26-25} = 0b00;
1961 let Inst{24-23} = 0b01; // Increment After
1963 let Inst{21} = 1; // Writeback
1964 let Inst{20} = L_bit;
1965 let Inst{19-16} = Rn;
1967 let Inst{14} = regs{14};
1969 let Inst{12-0} = regs{12-0};
1972 T2XI<(outs), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops),
1973 itin, !strconcat(asm, "db${p}\t$Rn, $regs"), []> {
1977 let Inst{31-27} = 0b11101;
1978 let Inst{26-25} = 0b00;
1979 let Inst{24-23} = 0b10; // Decrement Before
1981 let Inst{21} = 0; // No writeback
1982 let Inst{20} = L_bit;
1983 let Inst{19-16} = Rn;
1985 let Inst{14} = regs{14};
1987 let Inst{12-0} = regs{12-0};
1990 T2XIt<(outs GPR:$wb), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops),
1991 itin_upd, !strconcat(asm, "db${p}\t$Rn!, $regs"), "$Rn = $wb", []> {
1995 let Inst{31-27} = 0b11101;
1996 let Inst{26-25} = 0b00;
1997 let Inst{24-23} = 0b10; // Decrement Before
1999 let Inst{21} = 1; // Writeback
2000 let Inst{20} = L_bit;
2001 let Inst{19-16} = Rn;
2003 let Inst{14} = regs{14};
2005 let Inst{12-0} = regs{12-0};
2010 let mayStore = 1, hasExtraSrcRegAllocReq = 1 in
2011 defm t2STM : thumb2_st_mult<"stm", IIC_iStore_m, IIC_iStore_mu, 0>;
2016 //===----------------------------------------------------------------------===//
2017 // Move Instructions.
2020 let hasSideEffects = 0 in
2021 def t2MOVr : T2sTwoReg<(outs GPRnopc:$Rd), (ins GPRnopc:$Rm), IIC_iMOVr,
2022 "mov", ".w\t$Rd, $Rm", []>, Sched<[WriteALU]> {
2023 let Inst{31-27} = 0b11101;
2024 let Inst{26-25} = 0b01;
2025 let Inst{24-21} = 0b0010;
2026 let Inst{19-16} = 0b1111; // Rn
2028 let Inst{14-12} = 0b000;
2029 let Inst{7-4} = 0b0000;
2031 def : t2InstAlias<"mov${p}.w $Rd, $Rm", (t2MOVr GPRnopc:$Rd, GPRnopc:$Rm,
2032 pred:$p, zero_reg)>;
2033 def : t2InstAlias<"movs${p}.w $Rd, $Rm", (t2MOVr GPRnopc:$Rd, GPRnopc:$Rm,
2035 def : t2InstAlias<"movs${p} $Rd, $Rm", (t2MOVr GPRnopc:$Rd, GPRnopc:$Rm,
2038 // AddedComplexity to ensure isel tries t2MOVi before t2MOVi16.
2039 let isReMaterializable = 1, isAsCheapAsAMove = 1, isMoveImm = 1,
2040 AddedComplexity = 1 in
2041 def t2MOVi : T2sOneRegImm<(outs rGPR:$Rd), (ins t2_so_imm:$imm), IIC_iMOVi,
2042 "mov", ".w\t$Rd, $imm",
2043 [(set rGPR:$Rd, t2_so_imm:$imm)]>, Sched<[WriteALU]> {
2044 let Inst{31-27} = 0b11110;
2046 let Inst{24-21} = 0b0010;
2047 let Inst{19-16} = 0b1111; // Rn
2051 // cc_out is handled as part of the explicit mnemonic in the parser for 'mov'.
2052 // Use aliases to get that to play nice here.
2053 def : t2InstAlias<"movs${p}.w $Rd, $imm", (t2MOVi rGPR:$Rd, t2_so_imm:$imm,
2055 def : t2InstAlias<"movs${p} $Rd, $imm", (t2MOVi rGPR:$Rd, t2_so_imm:$imm,
2058 def : t2InstAlias<"mov${p}.w $Rd, $imm", (t2MOVi rGPR:$Rd, t2_so_imm:$imm,
2059 pred:$p, zero_reg)>;
2060 def : t2InstAlias<"mov${p} $Rd, $imm", (t2MOVi rGPR:$Rd, t2_so_imm:$imm,
2061 pred:$p, zero_reg)>;
2063 let isReMaterializable = 1, isAsCheapAsAMove = 1, isMoveImm = 1 in
2064 def t2MOVi16 : T2I<(outs rGPR:$Rd), (ins imm0_65535_expr:$imm), IIC_iMOVi,
2065 "movw", "\t$Rd, $imm",
2066 [(set rGPR:$Rd, imm0_65535:$imm)]>, Sched<[WriteALU]>,
2067 Requires<[IsThumb, HasV8MBaseline]> {
2068 let Inst{31-27} = 0b11110;
2070 let Inst{24-21} = 0b0010;
2071 let Inst{20} = 0; // The S bit.
2077 let Inst{11-8} = Rd;
2078 let Inst{19-16} = imm{15-12};
2079 let Inst{26} = imm{11};
2080 let Inst{14-12} = imm{10-8};
2081 let Inst{7-0} = imm{7-0};
2082 let DecoderMethod = "DecodeT2MOVTWInstruction";
2085 def : InstAlias<"mov${p} $Rd, $imm",
2086 (t2MOVi16 rGPR:$Rd, imm256_65535_expr:$imm, pred:$p), 0>,
2087 Requires<[IsThumb, HasV8MBaseline]>, Sched<[WriteALU]>;
2089 def t2MOVi16_ga_pcrel : PseudoInst<(outs rGPR:$Rd),
2090 (ins i32imm:$addr, pclabel:$id), IIC_iMOVi, []>,
2093 let Constraints = "$src = $Rd" in {
2094 def t2MOVTi16 : T2I<(outs rGPR:$Rd),
2095 (ins rGPR:$src, imm0_65535_expr:$imm), IIC_iMOVi,
2096 "movt", "\t$Rd, $imm",
2098 (or (and rGPR:$src, 0xffff), lo16AllZero:$imm))]>,
2100 Requires<[IsThumb, HasV8MBaseline]> {
2101 let Inst{31-27} = 0b11110;
2103 let Inst{24-21} = 0b0110;
2104 let Inst{20} = 0; // The S bit.
2110 let Inst{11-8} = Rd;
2111 let Inst{19-16} = imm{15-12};
2112 let Inst{26} = imm{11};
2113 let Inst{14-12} = imm{10-8};
2114 let Inst{7-0} = imm{7-0};
2115 let DecoderMethod = "DecodeT2MOVTWInstruction";
2118 def t2MOVTi16_ga_pcrel : PseudoInst<(outs rGPR:$Rd),
2119 (ins rGPR:$src, i32imm:$addr, pclabel:$id), IIC_iMOVi, []>,
2120 Sched<[WriteALU]>, Requires<[IsThumb, HasV8MBaseline]>;
2123 def : T2Pat<(or rGPR:$src, 0xffff0000), (t2MOVTi16 rGPR:$src, 0xffff)>;
2125 //===----------------------------------------------------------------------===//
2126 // Extend Instructions.
2131 def t2SXTB : T2I_ext_rrot<0b100, "sxtb">;
2132 def t2SXTH : T2I_ext_rrot<0b000, "sxth">;
2133 def t2SXTB16 : T2I_ext_rrot_xtb16<0b010, "sxtb16">;
2135 def t2SXTAB : T2I_exta_rrot<0b100, "sxtab">;
2136 def t2SXTAH : T2I_exta_rrot<0b000, "sxtah">;
2137 def t2SXTAB16 : T2I_exta_rrot<0b010, "sxtab16">;
2139 def : T2Pat<(sext_inreg (rotr rGPR:$Rn, rot_imm:$rot), i8),
2140 (t2SXTB rGPR:$Rn, rot_imm:$rot)>;
2141 def : T2Pat<(sext_inreg (rotr rGPR:$Rn, rot_imm:$rot), i16),
2142 (t2SXTH rGPR:$Rn, rot_imm:$rot)>;
2143 def : Thumb2DSPPat<(add rGPR:$Rn,
2144 (sext_inreg (rotr rGPR:$Rm, rot_imm:$rot), i8)),
2145 (t2SXTAB rGPR:$Rn, rGPR:$Rm, rot_imm:$rot)>;
2146 def : Thumb2DSPPat<(add rGPR:$Rn,
2147 (sext_inreg (rotr rGPR:$Rm, rot_imm:$rot), i16)),
2148 (t2SXTAH rGPR:$Rn, rGPR:$Rm, rot_imm:$rot)>;
2149 def : Thumb2DSPPat<(int_arm_sxtb16 rGPR:$Rn),
2150 (t2SXTB16 rGPR:$Rn, 0)>;
2151 def : Thumb2DSPPat<(int_arm_sxtab16 rGPR:$Rn, rGPR:$Rm),
2152 (t2SXTAB16 rGPR:$Rn, rGPR:$Rm, 0)>;
2153 def : Thumb2DSPPat<(int_arm_sxtb16 (rotr rGPR:$Rn, rot_imm:$rot)),
2154 (t2SXTB16 rGPR:$Rn, rot_imm:$rot)>;
2155 def : Thumb2DSPPat<(int_arm_sxtab16 rGPR:$Rn, (rotr rGPR:$Rm, rot_imm:$rot)),
2156 (t2SXTAB16 rGPR:$Rn, rGPR:$Rm, rot_imm:$rot)>;
2159 // A simple right-shift can also be used in most cases (the exception is the
2160 // SXTH operations with a rotate of 24: there the non-contiguous bits are
2162 def : Thumb2DSPPat<(add rGPR:$Rn, (sext_inreg
2163 (srl rGPR:$Rm, rot_imm:$rot), i8)),
2164 (t2SXTAB rGPR:$Rn, rGPR:$Rm, rot_imm:$rot)>;
2165 def : Thumb2DSPPat<(add rGPR:$Rn, (sext_inreg
2166 (srl rGPR:$Rm, imm8_or_16:$rot), i16)),
2167 (t2SXTAH rGPR:$Rn, rGPR:$Rm, rot_imm:$rot)>;
2168 def : Thumb2DSPPat<(add rGPR:$Rn, (sext_inreg
2169 (rotr rGPR:$Rm, (i32 24)), i16)),
2170 (t2SXTAH rGPR:$Rn, rGPR:$Rm, (i32 3))>;
2171 def : Thumb2DSPPat<(add rGPR:$Rn, (sext_inreg
2172 (or (srl rGPR:$Rm, (i32 24)),
2173 (shl rGPR:$Rm, (i32 8))), i16)),
2174 (t2SXTAH rGPR:$Rn, rGPR:$Rm, (i32 3))>;
2178 let AddedComplexity = 16 in {
2179 def t2UXTB : T2I_ext_rrot<0b101, "uxtb">;
2180 def t2UXTH : T2I_ext_rrot<0b001, "uxth">;
2181 def t2UXTB16 : T2I_ext_rrot_xtb16<0b011, "uxtb16">;
2183 def : Thumb2DSPPat<(and (rotr rGPR:$Rm, rot_imm:$rot), 0x000000FF),
2184 (t2UXTB rGPR:$Rm, rot_imm:$rot)>;
2185 def : Thumb2DSPPat<(and (rotr rGPR:$Rm, rot_imm:$rot), 0x0000FFFF),
2186 (t2UXTH rGPR:$Rm, rot_imm:$rot)>;
2187 def : Thumb2DSPPat<(and (rotr rGPR:$Rm, rot_imm:$rot), 0x00FF00FF),
2188 (t2UXTB16 rGPR:$Rm, rot_imm:$rot)>;
2190 def : Thumb2DSPPat<(int_arm_uxtb16 rGPR:$Rm),
2191 (t2UXTB16 rGPR:$Rm, 0)>;
2192 def : Thumb2DSPPat<(int_arm_uxtb16 (rotr rGPR:$Rn, rot_imm:$rot)),
2193 (t2UXTB16 rGPR:$Rn, rot_imm:$rot)>;
2195 // FIXME: This pattern incorrectly assumes the shl operator is a rotate.
2196 // The transformation should probably be done as a combiner action
2197 // instead so we can include a check for masking back in the upper
2198 // eight bits of the source into the lower eight bits of the result.
2199 //def : T2Pat<(and (shl rGPR:$Src, (i32 8)), 0xFF00FF),
2200 // (t2UXTB16 rGPR:$Src, 3)>,
2201 // Requires<[HasDSP, IsThumb2]>;
2202 def : T2Pat<(and (srl rGPR:$Src, (i32 8)), 0xFF00FF),
2203 (t2UXTB16 rGPR:$Src, 1)>,
2204 Requires<[HasDSP, IsThumb2]>;
2206 def t2UXTAB : T2I_exta_rrot<0b101, "uxtab">;
2207 def t2UXTAH : T2I_exta_rrot<0b001, "uxtah">;
2208 def t2UXTAB16 : T2I_exta_rrot<0b011, "uxtab16">;
2210 def : Thumb2DSPPat<(add rGPR:$Rn, (and (rotr rGPR:$Rm, rot_imm:$rot),
2212 (t2UXTAB rGPR:$Rn, rGPR:$Rm, rot_imm:$rot)>;
2213 def : Thumb2DSPPat<(add rGPR:$Rn, (and (rotr rGPR:$Rm, rot_imm:$rot),
2215 (t2UXTAH rGPR:$Rn, rGPR:$Rm, rot_imm:$rot)>;
2216 def : Thumb2DSPPat<(add rGPR:$Rn, (and (srl rGPR:$Rm, rot_imm:$rot),
2218 (t2UXTAB rGPR:$Rn, rGPR:$Rm, rot_imm:$rot)>;
2219 def : Thumb2DSPPat<(add rGPR:$Rn, (and (srl rGPR:$Rm, imm8_or_16:$rot),
2221 (t2UXTAH rGPR:$Rn, rGPR:$Rm, rot_imm:$rot)>;
2222 def : Thumb2DSPPat<(int_arm_uxtab16 rGPR:$Rn, rGPR:$Rm),
2223 (t2UXTAB16 rGPR:$Rn, rGPR:$Rm, 0)>;
2224 def : Thumb2DSPPat<(int_arm_uxtab16 rGPR:$Rn, (rotr rGPR:$Rm, rot_imm:$rot)),
2225 (t2UXTAB16 rGPR:$Rn, rGPR:$Rm, rot_imm:$rot)>;
2229 //===----------------------------------------------------------------------===//
2230 // Arithmetic Instructions.
2234 defm t2ADD : T2I_bin_ii12rs<0b000, "add", add, 1>;
2235 defm t2SUB : T2I_bin_ii12rs<0b101, "sub", sub>;
2237 // ADD and SUB with 's' bit set. No 12-bit immediate (T4) variants.
2239 // Currently, t2ADDS/t2SUBS are pseudo opcodes that exist only in the
2240 // selection DAG. They are "lowered" to real t2ADD/t2SUB opcodes by
2241 // AdjustInstrPostInstrSelection where we determine whether or not to
2242 // set the "s" bit based on CPSR liveness.
2244 // FIXME: Eliminate t2ADDS/t2SUBS pseudo opcodes after adding tablegen
2245 // support for an optional CPSR definition that corresponds to the DAG
2246 // node's second value. We can then eliminate the implicit def of CPSR.
2247 defm t2ADDS : T2I_bin_s_irs <IIC_iALUi, IIC_iALUr, IIC_iALUsi, ARMaddc, 1>;
2248 defm t2SUBS : T2I_bin_s_irs <IIC_iALUi, IIC_iALUr, IIC_iALUsi, ARMsubc>;
2250 def : T2Pat<(ARMsubs GPRnopc:$Rn, t2_so_imm:$imm),
2251 (t2SUBSri $Rn, t2_so_imm:$imm)>;
2252 def : T2Pat<(ARMsubs GPRnopc:$Rn, rGPR:$Rm), (t2SUBSrr $Rn, $Rm)>;
2253 def : T2Pat<(ARMsubs GPRnopc:$Rn, t2_so_reg:$ShiftedRm),
2254 (t2SUBSrs $Rn, t2_so_reg:$ShiftedRm)>;
2256 let hasPostISelHook = 1 in {
2257 defm t2ADC : T2I_adde_sube_irs<0b1010, "adc", ARMadde, 1>;
2258 defm t2SBC : T2I_adde_sube_irs<0b1011, "sbc", ARMsube>;
2261 def : t2InstSubst<"adc${s}${p} $rd, $rn, $imm",
2262 (t2SBCri rGPR:$rd, rGPR:$rn, t2_so_imm_not:$imm, pred:$p, s_cc_out:$s)>;
2263 def : t2InstSubst<"sbc${s}${p} $rd, $rn, $imm",
2264 (t2ADCri rGPR:$rd, rGPR:$rn, t2_so_imm_not:$imm, pred:$p, s_cc_out:$s)>;
2266 def : t2InstSubst<"add${s}${p}.w $rd, $rn, $imm",
2267 (t2SUBri GPRnopc:$rd, GPRnopc:$rn, t2_so_imm_neg:$imm, pred:$p, s_cc_out:$s)>;
2268 def : t2InstSubst<"addw${p} $rd, $rn, $imm",
2269 (t2SUBri12 GPRnopc:$rd, GPR:$rn, t2_so_imm_neg:$imm, pred:$p)>;
2270 def : t2InstSubst<"sub${s}${p}.w $rd, $rn, $imm",
2271 (t2ADDri GPRnopc:$rd, GPRnopc:$rn, t2_so_imm_neg:$imm, pred:$p, s_cc_out:$s)>;
2272 def : t2InstSubst<"subw${p} $rd, $rn, $imm",
2273 (t2ADDri12 GPRnopc:$rd, GPR:$rn, t2_so_imm_neg:$imm, pred:$p)>;
2274 def : t2InstSubst<"subw${p} $Rd, $Rn, $imm",
2275 (t2ADDri12 GPRnopc:$Rd, GPR:$Rn, imm0_4095_neg:$imm, pred:$p)>;
2276 def : t2InstSubst<"sub${s}${p} $rd, $rn, $imm",
2277 (t2ADDri GPRnopc:$rd, GPRnopc:$rn, t2_so_imm_neg:$imm, pred:$p, s_cc_out:$s)>;
2278 def : t2InstSubst<"sub${p} $rd, $rn, $imm",
2279 (t2ADDri12 GPRnopc:$rd, GPR:$rn, t2_so_imm_neg:$imm, pred:$p)>;
2281 defm t2RSB : T2I_rbin_irs <0b1110, "rsb", sub>;
2283 // FIXME: Eliminate them if we can write def : Pat patterns which defines
2284 // CPSR and the implicit def of CPSR is not needed.
2285 defm t2RSBS : T2I_rbin_s_is <ARMsubc>;
2287 // (sub X, imm) gets canonicalized to (add X, -imm). Match this form.
2288 // The assume-no-carry-in form uses the negation of the input since add/sub
2289 // assume opposite meanings of the carry flag (i.e., carry == !borrow).
2290 // See the definition of AddWithCarry() in the ARM ARM A2.2.1 for the gory
2292 // The AddedComplexity preferences the first variant over the others since
2293 // it can be shrunk to a 16-bit wide encoding, while the others cannot.
2294 let AddedComplexity = 1 in
2295 def : T2Pat<(add GPR:$src, imm1_255_neg:$imm),
2296 (t2SUBri GPR:$src, imm1_255_neg:$imm)>;
2297 def : T2Pat<(add GPR:$src, t2_so_imm_neg:$imm),
2298 (t2SUBri GPR:$src, t2_so_imm_neg:$imm)>;
2299 def : T2Pat<(add GPR:$src, imm0_4095_neg:$imm),
2300 (t2SUBri12 GPR:$src, imm0_4095_neg:$imm)>;
2301 def : T2Pat<(add GPR:$src, imm0_65535_neg:$imm),
2302 (t2SUBrr GPR:$src, (t2MOVi16 (imm_neg_XFORM imm:$imm)))>;
2304 // Do the same for v8m targets since they support movw with a 16-bit value.
2305 def : T1Pat<(add tGPR:$src, imm0_65535_neg:$imm),
2306 (tSUBrr tGPR:$src, (t2MOVi16 (imm_neg_XFORM imm:$imm)))>,
2307 Requires<[HasV8MBaseline]>;
2309 let AddedComplexity = 1 in
2310 def : T2Pat<(ARMaddc rGPR:$src, imm1_255_neg:$imm),
2311 (t2SUBSri rGPR:$src, imm1_255_neg:$imm)>;
2312 def : T2Pat<(ARMaddc rGPR:$src, t2_so_imm_neg:$imm),
2313 (t2SUBSri rGPR:$src, t2_so_imm_neg:$imm)>;
2314 def : T2Pat<(ARMaddc rGPR:$src, imm0_65535_neg:$imm),
2315 (t2SUBSrr rGPR:$src, (t2MOVi16 (imm_neg_XFORM imm:$imm)))>;
2316 // The with-carry-in form matches bitwise not instead of the negation.
2317 // Effectively, the inverse interpretation of the carry flag already accounts
2318 // for part of the negation.
2319 let AddedComplexity = 1 in
2320 def : T2Pat<(ARMadde rGPR:$src, imm0_255_not:$imm, CPSR),
2321 (t2SBCri rGPR:$src, imm0_255_not:$imm)>;
2322 def : T2Pat<(ARMadde rGPR:$src, t2_so_imm_not:$imm, CPSR),
2323 (t2SBCri rGPR:$src, t2_so_imm_not:$imm)>;
2324 def : T2Pat<(ARMadde rGPR:$src, imm0_65535_neg:$imm, CPSR),
2325 (t2SBCrr rGPR:$src, (t2MOVi16 (imm_not_XFORM imm:$imm)))>;
2327 def t2SEL : T2ThreeReg<(outs GPR:$Rd), (ins GPR:$Rn, GPR:$Rm),
2328 NoItinerary, "sel", "\t$Rd, $Rn, $Rm",
2329 [(set GPR:$Rd, (int_arm_sel GPR:$Rn, GPR:$Rm))]>,
2330 Requires<[IsThumb2, HasDSP]> {
2331 let Inst{31-27} = 0b11111;
2332 let Inst{26-24} = 0b010;
2334 let Inst{22-20} = 0b010;
2335 let Inst{15-12} = 0b1111;
2337 let Inst{6-4} = 0b000;
2340 // A6.3.13, A6.3.14, A6.3.15 Parallel addition and subtraction (signed/unsigned)
2341 // And Miscellaneous operations -- for disassembly only
2342 class T2I_pam<bits<3> op22_20, bits<4> op7_4, string opc,
2343 list<dag> pat, dag iops, string asm>
2344 : T2I<(outs rGPR:$Rd), iops, NoItinerary, opc, asm, pat>,
2345 Requires<[IsThumb2, HasDSP]> {
2346 let Inst{31-27} = 0b11111;
2347 let Inst{26-23} = 0b0101;
2348 let Inst{22-20} = op22_20;
2349 let Inst{15-12} = 0b1111;
2350 let Inst{7-4} = op7_4;
2356 let Inst{11-8} = Rd;
2357 let Inst{19-16} = Rn;
2361 class T2I_pam_intrinsics<bits<3> op22_20, bits<4> op7_4, string opc,
2362 Intrinsic intrinsic>
2363 : T2I_pam<op22_20, op7_4, opc,
2364 [(set rGPR:$Rd, (intrinsic rGPR:$Rn, rGPR:$Rm))],
2365 (ins rGPR:$Rn, rGPR:$Rm), "\t$Rd, $Rn, $Rm">;
2367 class T2I_pam_intrinsics_rev<bits<3> op22_20, bits<4> op7_4, string opc>
2368 : T2I_pam<op22_20, op7_4, opc, [],
2369 (ins rGPR:$Rm, rGPR:$Rn), "\t$Rd, $Rm, $Rn">;
2371 // Saturating add/subtract
2372 def t2QADD16 : T2I_pam_intrinsics<0b001, 0b0001, "qadd16", int_arm_qadd16>;
2373 def t2QADD8 : T2I_pam_intrinsics<0b000, 0b0001, "qadd8", int_arm_qadd8>;
2374 def t2QASX : T2I_pam_intrinsics<0b010, 0b0001, "qasx", int_arm_qasx>;
2375 def t2UQSUB8 : T2I_pam_intrinsics<0b100, 0b0101, "uqsub8", int_arm_uqsub8>;
2376 def t2QSAX : T2I_pam_intrinsics<0b110, 0b0001, "qsax", int_arm_qsax>;
2377 def t2QSUB16 : T2I_pam_intrinsics<0b101, 0b0001, "qsub16", int_arm_qsub16>;
2378 def t2QSUB8 : T2I_pam_intrinsics<0b100, 0b0001, "qsub8", int_arm_qsub8>;
2379 def t2UQADD16 : T2I_pam_intrinsics<0b001, 0b0101, "uqadd16", int_arm_uqadd16>;
2380 def t2UQADD8 : T2I_pam_intrinsics<0b000, 0b0101, "uqadd8", int_arm_uqadd8>;
2381 def t2UQASX : T2I_pam_intrinsics<0b010, 0b0101, "uqasx", int_arm_uqasx>;
2382 def t2UQSAX : T2I_pam_intrinsics<0b110, 0b0101, "uqsax", int_arm_uqsax>;
2383 def t2UQSUB16 : T2I_pam_intrinsics<0b101, 0b0101, "uqsub16", int_arm_uqsub16>;
2384 def t2QADD : T2I_pam_intrinsics_rev<0b000, 0b1000, "qadd">;
2385 def t2QSUB : T2I_pam_intrinsics_rev<0b000, 0b1010, "qsub">;
2386 def t2QDADD : T2I_pam_intrinsics_rev<0b000, 0b1001, "qdadd">;
2387 def t2QDSUB : T2I_pam_intrinsics_rev<0b000, 0b1011, "qdsub">;
2389 def : Thumb2DSPPat<(int_arm_qadd rGPR:$Rm, rGPR:$Rn),
2390 (t2QADD rGPR:$Rm, rGPR:$Rn)>;
2391 def : Thumb2DSPPat<(int_arm_qsub rGPR:$Rm, rGPR:$Rn),
2392 (t2QSUB rGPR:$Rm, rGPR:$Rn)>;
2393 def : Thumb2DSPPat<(int_arm_qadd(int_arm_qadd rGPR:$Rm, rGPR:$Rm), rGPR:$Rn),
2394 (t2QDADD rGPR:$Rm, rGPR:$Rn)>;
2395 def : Thumb2DSPPat<(int_arm_qsub rGPR:$Rm, (int_arm_qadd rGPR:$Rn, rGPR:$Rn)),
2396 (t2QDSUB rGPR:$Rm, rGPR:$Rn)>;
2398 def : Thumb2DSPPat<(ARMqadd8b rGPR:$Rm, rGPR:$Rn),
2399 (t2QADD8 rGPR:$Rm, rGPR:$Rn)>;
2400 def : Thumb2DSPPat<(ARMqsub8b rGPR:$Rm, rGPR:$Rn),
2401 (t2QSUB8 rGPR:$Rm, rGPR:$Rn)>;
2402 def : Thumb2DSPPat<(ARMqadd16b rGPR:$Rm, rGPR:$Rn),
2403 (t2QADD16 rGPR:$Rm, rGPR:$Rn)>;
2404 def : Thumb2DSPPat<(ARMqsub16b rGPR:$Rm, rGPR:$Rn),
2405 (t2QSUB16 rGPR:$Rm, rGPR:$Rn)>;
2407 // Signed/Unsigned add/subtract
2409 def t2SASX : T2I_pam_intrinsics<0b010, 0b0000, "sasx", int_arm_sasx>;
2410 def t2SADD16 : T2I_pam_intrinsics<0b001, 0b0000, "sadd16", int_arm_sadd16>;
2411 def t2SADD8 : T2I_pam_intrinsics<0b000, 0b0000, "sadd8", int_arm_sadd8>;
2412 def t2SSAX : T2I_pam_intrinsics<0b110, 0b0000, "ssax", int_arm_ssax>;
2413 def t2SSUB16 : T2I_pam_intrinsics<0b101, 0b0000, "ssub16", int_arm_ssub16>;
2414 def t2SSUB8 : T2I_pam_intrinsics<0b100, 0b0000, "ssub8", int_arm_ssub8>;
2415 def t2UASX : T2I_pam_intrinsics<0b010, 0b0100, "uasx", int_arm_uasx>;
2416 def t2UADD16 : T2I_pam_intrinsics<0b001, 0b0100, "uadd16", int_arm_uadd16>;
2417 def t2UADD8 : T2I_pam_intrinsics<0b000, 0b0100, "uadd8", int_arm_uadd8>;
2418 def t2USAX : T2I_pam_intrinsics<0b110, 0b0100, "usax", int_arm_usax>;
2419 def t2USUB16 : T2I_pam_intrinsics<0b101, 0b0100, "usub16", int_arm_usub16>;
2420 def t2USUB8 : T2I_pam_intrinsics<0b100, 0b0100, "usub8", int_arm_usub8>;
2422 // Signed/Unsigned halving add/subtract
2424 def t2SHASX : T2I_pam_intrinsics<0b010, 0b0010, "shasx", int_arm_shasx>;
2425 def t2SHADD16 : T2I_pam_intrinsics<0b001, 0b0010, "shadd16", int_arm_shadd16>;
2426 def t2SHADD8 : T2I_pam_intrinsics<0b000, 0b0010, "shadd8", int_arm_shadd8>;
2427 def t2SHSAX : T2I_pam_intrinsics<0b110, 0b0010, "shsax", int_arm_shsax>;
2428 def t2SHSUB16 : T2I_pam_intrinsics<0b101, 0b0010, "shsub16", int_arm_shsub16>;
2429 def t2SHSUB8 : T2I_pam_intrinsics<0b100, 0b0010, "shsub8", int_arm_shsub8>;
2430 def t2UHASX : T2I_pam_intrinsics<0b010, 0b0110, "uhasx", int_arm_uhasx>;
2431 def t2UHADD16 : T2I_pam_intrinsics<0b001, 0b0110, "uhadd16", int_arm_uhadd16>;
2432 def t2UHADD8 : T2I_pam_intrinsics<0b000, 0b0110, "uhadd8", int_arm_uhadd8>;
2433 def t2UHSAX : T2I_pam_intrinsics<0b110, 0b0110, "uhsax", int_arm_uhsax>;
2434 def t2UHSUB16 : T2I_pam_intrinsics<0b101, 0b0110, "uhsub16", int_arm_uhsub16>;
2435 def t2UHSUB8 : T2I_pam_intrinsics<0b100, 0b0110, "uhsub8", int_arm_uhsub8>;
2437 // Helper class for disassembly only
2438 // A6.3.16 & A6.3.17
2439 // T2Imac - Thumb2 multiply [accumulate, and absolute difference] instructions.
2440 class T2ThreeReg_mac<bit long, bits<3> op22_20, bits<4> op7_4, dag oops,
2441 dag iops, InstrItinClass itin, string opc, string asm, list<dag> pattern>
2442 : T2ThreeReg<oops, iops, itin, opc, asm, pattern> {
2443 let Inst{31-27} = 0b11111;
2444 let Inst{26-24} = 0b011;
2445 let Inst{23} = long;
2446 let Inst{22-20} = op22_20;
2447 let Inst{7-4} = op7_4;
2450 class T2FourReg_mac<bit long, bits<3> op22_20, bits<4> op7_4, dag oops,
2451 dag iops, InstrItinClass itin, string opc, string asm, list<dag> pattern>
2452 : T2FourReg<oops, iops, itin, opc, asm, pattern> {
2453 let Inst{31-27} = 0b11111;
2454 let Inst{26-24} = 0b011;
2455 let Inst{23} = long;
2456 let Inst{22-20} = op22_20;
2457 let Inst{7-4} = op7_4;
2460 // Unsigned Sum of Absolute Differences [and Accumulate].
2461 def t2USAD8 : T2ThreeReg_mac<0, 0b111, 0b0000, (outs rGPR:$Rd),
2462 (ins rGPR:$Rn, rGPR:$Rm),
2463 NoItinerary, "usad8", "\t$Rd, $Rn, $Rm",
2464 [(set rGPR:$Rd, (int_arm_usad8 rGPR:$Rn, rGPR:$Rm))]>,
2465 Requires<[IsThumb2, HasDSP]> {
2466 let Inst{15-12} = 0b1111;
2468 def t2USADA8 : T2FourReg_mac<0, 0b111, 0b0000, (outs rGPR:$Rd),
2469 (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), NoItinerary,
2470 "usada8", "\t$Rd, $Rn, $Rm, $Ra",
2471 [(set rGPR:$Rd, (int_arm_usada8 rGPR:$Rn, rGPR:$Rm, rGPR:$Ra))]>,
2472 Requires<[IsThumb2, HasDSP]>;
2474 // Signed/Unsigned saturate.
2475 let hasSideEffects = 1 in
2476 class T2SatI<dag iops, string opc, string asm>
2477 : T2I<(outs rGPR:$Rd), iops, NoItinerary, opc, asm, []> {
2483 let Inst{31-24} = 0b11110011;
2484 let Inst{21} = sh{5};
2486 let Inst{19-16} = Rn;
2488 let Inst{14-12} = sh{4-2};
2489 let Inst{11-8} = Rd;
2490 let Inst{7-6} = sh{1-0};
2492 let Inst{4-0} = sat_imm;
2495 def t2SSAT: T2SatI<(ins imm1_32:$sat_imm, rGPR:$Rn, t2_shift_imm:$sh),
2496 "ssat", "\t$Rd, $sat_imm, $Rn$sh">,
2497 Requires<[IsThumb2]>, Sched<[WriteALU]> {
2498 let Inst{23-22} = 0b00;
2502 def t2SSAT16: T2SatI<(ins imm1_16:$sat_imm, rGPR:$Rn),
2503 "ssat16", "\t$Rd, $sat_imm, $Rn">,
2504 Requires<[IsThumb2, HasDSP]>, Sched<[WriteALU]> {
2505 let Inst{23-22} = 0b00;
2510 def t2USAT: T2SatI<(ins imm0_31:$sat_imm, rGPR:$Rn, t2_shift_imm:$sh),
2511 "usat", "\t$Rd, $sat_imm, $Rn$sh">,
2512 Requires<[IsThumb2]>, Sched<[WriteALU]> {
2513 let Inst{23-22} = 0b10;
2516 def t2USAT16: T2SatI<(ins imm0_15:$sat_imm, rGPR:$Rn),
2517 "usat16", "\t$Rd, $sat_imm, $Rn">,
2518 Requires<[IsThumb2, HasDSP]>, Sched<[WriteALU]> {
2519 let Inst{23-22} = 0b10;
2524 def : T2Pat<(ARMssatnoshift GPRnopc:$Rn, imm0_31:$imm),
2525 (t2SSAT imm0_31:$imm, GPRnopc:$Rn, 0)>;
2526 def : T2Pat<(ARMusatnoshift GPRnopc:$Rn, imm0_31:$imm),
2527 (t2USAT imm0_31:$imm, GPRnopc:$Rn, 0)>;
2528 def : T2Pat<(int_arm_ssat GPR:$a, imm1_32:$pos),
2529 (t2SSAT imm1_32:$pos, GPR:$a, 0)>;
2530 def : T2Pat<(int_arm_usat GPR:$a, imm0_31:$pos),
2531 (t2USAT imm0_31:$pos, GPR:$a, 0)>;
2532 def : T2Pat<(int_arm_ssat16 GPR:$a, imm1_16:$pos),
2533 (t2SSAT16 imm1_16:$pos, GPR:$a)>;
2534 def : T2Pat<(int_arm_usat16 GPR:$a, imm0_15:$pos),
2535 (t2USAT16 imm0_15:$pos, GPR:$a)>;
2537 //===----------------------------------------------------------------------===//
2538 // Shift and rotate Instructions.
2541 defm t2LSL : T2I_sh_ir<0b00, "lsl", imm1_31, shl>;
2542 defm t2LSR : T2I_sh_ir<0b01, "lsr", imm_sr, srl>;
2543 defm t2ASR : T2I_sh_ir<0b10, "asr", imm_sr, sra>;
2544 defm t2ROR : T2I_sh_ir<0b11, "ror", imm0_31, rotr>;
2546 // LSL #0 is actually MOV, and has slightly different permitted registers to
2547 // LSL with non-zero shift
2548 def : t2InstAlias<"lsl${s}${p} $Rd, $Rm, #0",
2549 (t2MOVr GPRnopc:$Rd, GPRnopc:$Rm, pred:$p, cc_out:$s)>;
2550 def : t2InstAlias<"lsl${s}${p}.w $Rd, $Rm, #0",
2551 (t2MOVr GPRnopc:$Rd, GPRnopc:$Rm, pred:$p, cc_out:$s)>;
2553 // (rotr x, (and y, 0x...1f)) ==> (ROR x, y)
2554 def : T2Pat<(rotr rGPR:$lhs, (and rGPR:$rhs, lo5AllOne)),
2555 (t2RORrr rGPR:$lhs, rGPR:$rhs)>;
2557 let Uses = [CPSR] in {
2558 def t2RRX : T2sTwoReg<(outs rGPR:$Rd), (ins rGPR:$Rm), IIC_iMOVsi,
2559 "rrx", "\t$Rd, $Rm",
2560 [(set rGPR:$Rd, (ARMrrx rGPR:$Rm))]>, Sched<[WriteALU]> {
2561 let Inst{31-27} = 0b11101;
2562 let Inst{26-25} = 0b01;
2563 let Inst{24-21} = 0b0010;
2564 let Inst{19-16} = 0b1111; // Rn
2566 let Unpredictable{15} = 0b1;
2567 let Inst{14-12} = 0b000;
2568 let Inst{7-4} = 0b0011;
2572 let isCodeGenOnly = 1, Defs = [CPSR] in {
2573 def t2MOVsrl_flag : T2TwoRegShiftImm<
2574 (outs rGPR:$Rd), (ins rGPR:$Rm), IIC_iMOVsi,
2575 "lsrs", ".w\t$Rd, $Rm, #1",
2576 [(set rGPR:$Rd, (ARMsrl_flag rGPR:$Rm))]>,
2578 let Inst{31-27} = 0b11101;
2579 let Inst{26-25} = 0b01;
2580 let Inst{24-21} = 0b0010;
2581 let Inst{20} = 1; // The S bit.
2582 let Inst{19-16} = 0b1111; // Rn
2583 let Inst{5-4} = 0b01; // Shift type.
2584 // Shift amount = Inst{14-12:7-6} = 1.
2585 let Inst{14-12} = 0b000;
2586 let Inst{7-6} = 0b01;
2588 def t2MOVsra_flag : T2TwoRegShiftImm<
2589 (outs rGPR:$Rd), (ins rGPR:$Rm), IIC_iMOVsi,
2590 "asrs", ".w\t$Rd, $Rm, #1",
2591 [(set rGPR:$Rd, (ARMsra_flag rGPR:$Rm))]>,
2593 let Inst{31-27} = 0b11101;
2594 let Inst{26-25} = 0b01;
2595 let Inst{24-21} = 0b0010;
2596 let Inst{20} = 1; // The S bit.
2597 let Inst{19-16} = 0b1111; // Rn
2598 let Inst{5-4} = 0b10; // Shift type.
2599 // Shift amount = Inst{14-12:7-6} = 1.
2600 let Inst{14-12} = 0b000;
2601 let Inst{7-6} = 0b01;
2605 //===----------------------------------------------------------------------===//
2606 // Bitwise Instructions.
2609 defm t2AND : T2I_bin_w_irs<0b0000, "and",
2610 IIC_iBITi, IIC_iBITr, IIC_iBITsi, and, 1>;
2611 defm t2ORR : T2I_bin_w_irs<0b0010, "orr",
2612 IIC_iBITi, IIC_iBITr, IIC_iBITsi, or, 1>;
2613 defm t2EOR : T2I_bin_w_irs<0b0100, "eor",
2614 IIC_iBITi, IIC_iBITr, IIC_iBITsi, xor, 1>;
2616 defm t2BIC : T2I_bin_w_irs<0b0001, "bic",
2617 IIC_iBITi, IIC_iBITr, IIC_iBITsi,
2618 BinOpFrag<(and node:$LHS, (not node:$RHS))>>;
2620 class T2BitFI<dag oops, dag iops, InstrItinClass itin,
2621 string opc, string asm, list<dag> pattern>
2622 : T2I<oops, iops, itin, opc, asm, pattern> {
2627 let Inst{11-8} = Rd;
2628 let Inst{4-0} = msb{4-0};
2629 let Inst{14-12} = lsb{4-2};
2630 let Inst{7-6} = lsb{1-0};
2633 class T2TwoRegBitFI<dag oops, dag iops, InstrItinClass itin,
2634 string opc, string asm, list<dag> pattern>
2635 : T2BitFI<oops, iops, itin, opc, asm, pattern> {
2638 let Inst{19-16} = Rn;
2641 let Constraints = "$src = $Rd" in
2642 def t2BFC : T2BitFI<(outs rGPR:$Rd), (ins rGPR:$src, bf_inv_mask_imm:$imm),
2643 IIC_iUNAsi, "bfc", "\t$Rd, $imm",
2644 [(set rGPR:$Rd, (and rGPR:$src, bf_inv_mask_imm:$imm))]>, Sched<[WriteALU]> {
2645 let Inst{31-27} = 0b11110;
2646 let Inst{26} = 0; // should be 0.
2648 let Inst{24-20} = 0b10110;
2649 let Inst{19-16} = 0b1111; // Rn
2651 let Inst{5} = 0; // should be 0.
2654 let msb{4-0} = imm{9-5};
2655 let lsb{4-0} = imm{4-0};
2658 def t2SBFX: T2TwoRegBitFI<
2659 (outs rGPR:$Rd), (ins rGPR:$Rn, imm0_31:$lsb, imm1_32:$msb),
2660 IIC_iUNAsi, "sbfx", "\t$Rd, $Rn, $lsb, $msb", []>, Sched<[WriteALU]> {
2661 let Inst{31-27} = 0b11110;
2663 let Inst{24-20} = 0b10100;
2667 def t2UBFX: T2TwoRegBitFI<
2668 (outs rGPR:$Rd), (ins rGPR:$Rn, imm0_31:$lsb, imm1_32:$msb),
2669 IIC_iUNAsi, "ubfx", "\t$Rd, $Rn, $lsb, $msb", []>, Sched<[WriteALU]> {
2670 let Inst{31-27} = 0b11110;
2672 let Inst{24-20} = 0b11100;
2676 // A8.8.247 UDF - Undefined (Encoding T2)
2677 def t2UDF : T2XI<(outs), (ins imm0_65535:$imm16), IIC_Br, "udf.w\t$imm16",
2678 [(int_arm_undefined imm0_65535:$imm16)]> {
2680 let Inst{31-29} = 0b111;
2681 let Inst{28-27} = 0b10;
2682 let Inst{26-20} = 0b1111111;
2683 let Inst{19-16} = imm16{15-12};
2685 let Inst{14-12} = 0b010;
2686 let Inst{11-0} = imm16{11-0};
2689 // A8.6.18 BFI - Bitfield insert (Encoding T1)
2690 let Constraints = "$src = $Rd" in {
2691 def t2BFI : T2TwoRegBitFI<(outs rGPR:$Rd),
2692 (ins rGPR:$src, rGPR:$Rn, bf_inv_mask_imm:$imm),
2693 IIC_iBITi, "bfi", "\t$Rd, $Rn, $imm",
2694 [(set rGPR:$Rd, (ARMbfi rGPR:$src, rGPR:$Rn,
2695 bf_inv_mask_imm:$imm))]>, Sched<[WriteALU]> {
2696 let Inst{31-27} = 0b11110;
2697 let Inst{26} = 0; // should be 0.
2699 let Inst{24-20} = 0b10110;
2701 let Inst{5} = 0; // should be 0.
2704 let msb{4-0} = imm{9-5};
2705 let lsb{4-0} = imm{4-0};
2709 defm t2ORN : T2I_bin_irs<0b0011, "orn",
2710 IIC_iBITi, IIC_iBITr, IIC_iBITsi,
2711 BinOpFrag<(or node:$LHS, (not node:$RHS))>, 0, "">;
2713 /// T2I_un_irs - Defines a set of (op reg, {so_imm|r|so_reg}) patterns for a
2714 /// unary operation that produces a value. These are predicable and can be
2715 /// changed to modify CPSR.
2716 multiclass T2I_un_irs<bits<4> opcod, string opc,
2717 InstrItinClass iii, InstrItinClass iir, InstrItinClass iis,
2719 bit Cheap = 0, bit ReMat = 0, bit MoveImm = 0> {
2721 def i : T2sOneRegImm<(outs rGPR:$Rd), (ins t2_so_imm:$imm), iii,
2723 [(set rGPR:$Rd, (opnode t2_so_imm:$imm))]>, Sched<[WriteALU]> {
2724 let isAsCheapAsAMove = Cheap;
2725 let isReMaterializable = ReMat;
2726 let isMoveImm = MoveImm;
2727 let Inst{31-27} = 0b11110;
2729 let Inst{24-21} = opcod;
2730 let Inst{19-16} = 0b1111; // Rn
2734 def r : T2sTwoReg<(outs rGPR:$Rd), (ins rGPR:$Rm), iir,
2735 opc, ".w\t$Rd, $Rm",
2736 [(set rGPR:$Rd, (opnode rGPR:$Rm))]>, Sched<[WriteALU]> {
2737 let Inst{31-27} = 0b11101;
2738 let Inst{26-25} = 0b01;
2739 let Inst{24-21} = opcod;
2740 let Inst{19-16} = 0b1111; // Rn
2741 let Inst{14-12} = 0b000; // imm3
2742 let Inst{7-6} = 0b00; // imm2
2743 let Inst{5-4} = 0b00; // type
2746 def s : T2sOneRegShiftedReg<(outs rGPR:$Rd), (ins t2_so_reg:$ShiftedRm), iis,
2747 opc, ".w\t$Rd, $ShiftedRm",
2748 [(set rGPR:$Rd, (opnode t2_so_reg:$ShiftedRm))]>,
2750 let Inst{31-27} = 0b11101;
2751 let Inst{26-25} = 0b01;
2752 let Inst{24-21} = opcod;
2753 let Inst{19-16} = 0b1111; // Rn
2757 // Prefer over of t2EORri ra, rb, -1 because mvn has 16-bit version
2758 let AddedComplexity = 1 in
2759 defm t2MVN : T2I_un_irs <0b0011, "mvn",
2760 IIC_iMVNi, IIC_iMVNr, IIC_iMVNsi,
2763 let AddedComplexity = 1 in
2764 def : T2Pat<(and rGPR:$src, t2_so_imm_not:$imm),
2765 (t2BICri rGPR:$src, t2_so_imm_not:$imm)>;
2767 // top16Zero - answer true if the upper 16 bits of $src are 0, false otherwise
2768 def top16Zero: PatLeaf<(i32 rGPR:$src), [{
2769 return !SDValue(N,0)->getValueType(0).isVector() &&
2770 CurDAG->MaskedValueIsZero(SDValue(N,0), APInt::getHighBitsSet(32, 16));
2773 // so_imm_notSext is needed instead of so_imm_not, as the value of imm
2774 // will match the extended, not the original bitWidth for $src.
2775 def : T2Pat<(and top16Zero:$src, t2_so_imm_notSext:$imm),
2776 (t2BICri rGPR:$src, t2_so_imm_notSext:$imm)>;
2779 // FIXME: Disable this pattern on Darwin to workaround an assembler bug.
2780 def : T2Pat<(or rGPR:$src, t2_so_imm_not:$imm),
2781 (t2ORNri rGPR:$src, t2_so_imm_not:$imm)>,
2782 Requires<[IsThumb2]>;
2784 def : T2Pat<(t2_so_imm_not:$src),
2785 (t2MVNi t2_so_imm_not:$src)>;
2787 // There are shorter Thumb encodings for ADD than ORR, so to increase
2788 // Thumb2SizeReduction's chances later on we select a t2ADD for an or where
2790 def : T2Pat<(or AddLikeOrOp:$Rn, t2_so_imm:$imm),
2791 (t2ADDri $Rn, t2_so_imm:$imm)>;
2793 def : T2Pat<(or AddLikeOrOp:$Rn, imm0_4095:$Rm),
2794 (t2ADDri12 $Rn, imm0_4095:$Rm)>;
2796 def : T2Pat<(or AddLikeOrOp:$Rn, non_imm32:$Rm),
2797 (t2ADDrr $Rn, $Rm)>;
2799 //===----------------------------------------------------------------------===//
2800 // Multiply Instructions.
2802 let isCommutable = 1 in
2803 def t2MUL: T2ThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iMUL32,
2804 "mul", "\t$Rd, $Rn, $Rm",
2805 [(set rGPR:$Rd, (mul rGPR:$Rn, rGPR:$Rm))]>,
2806 Sched<[WriteMUL32, ReadMUL, ReadMUL]> {
2807 let Inst{31-27} = 0b11111;
2808 let Inst{26-23} = 0b0110;
2809 let Inst{22-20} = 0b000;
2810 let Inst{15-12} = 0b1111; // Ra = 0b1111 (no accumulate)
2811 let Inst{7-4} = 0b0000; // Multiply
2814 class T2FourRegMLA<bits<4> op7_4, string opc, list<dag> pattern>
2815 : T2FourReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC32,
2816 opc, "\t$Rd, $Rn, $Rm, $Ra", pattern>,
2817 Requires<[IsThumb2, UseMulOps]>,
2818 Sched<[WriteMAC32, ReadMUL, ReadMUL, ReadMAC]> {
2819 let Inst{31-27} = 0b11111;
2820 let Inst{26-23} = 0b0110;
2821 let Inst{22-20} = 0b000;
2822 let Inst{7-4} = op7_4;
2825 def t2MLA : T2FourRegMLA<0b0000, "mla",
2826 [(set rGPR:$Rd, (add (mul rGPR:$Rn, rGPR:$Rm),
2828 def t2MLS: T2FourRegMLA<0b0001, "mls",
2829 [(set rGPR:$Rd, (sub rGPR:$Ra, (mul rGPR:$Rn,
2832 // Extra precision multiplies with low / high results
2833 let hasSideEffects = 0 in {
2834 let isCommutable = 1 in {
2835 def t2SMULL : T2MulLong<0b000, 0b0000, "smull",
2836 [(set rGPR:$RdLo, rGPR:$RdHi,
2837 (smullohi rGPR:$Rn, rGPR:$Rm))]>;
2838 def t2UMULL : T2MulLong<0b010, 0b0000, "umull",
2839 [(set rGPR:$RdLo, rGPR:$RdHi,
2840 (umullohi rGPR:$Rn, rGPR:$Rm))]>;
2843 // Multiply + accumulate
2844 def t2SMLAL : T2MlaLong<0b100, 0b0000, "smlal">;
2845 def t2UMLAL : T2MlaLong<0b110, 0b0000, "umlal">;
2846 def t2UMAAL : T2MlaLong<0b110, 0b0110, "umaal">, Requires<[IsThumb2, HasDSP]>;
2849 // Rounding variants of the below included for disassembly only
2851 // Most significant word multiply
2852 class T2SMMUL<bits<4> op7_4, string opc, list<dag> pattern>
2853 : T2ThreeReg<(outs rGPR:$Rd),
2854 (ins rGPR:$Rn, rGPR:$Rm), IIC_iMUL32,
2855 opc, "\t$Rd, $Rn, $Rm", pattern>,
2856 Requires<[IsThumb2, HasDSP]>,
2857 Sched<[WriteMUL32, ReadMUL, ReadMUL]> {
2858 let Inst{31-27} = 0b11111;
2859 let Inst{26-23} = 0b0110;
2860 let Inst{22-20} = 0b101;
2861 let Inst{15-12} = 0b1111; // Ra = 0b1111 (no accumulate)
2862 let Inst{7-4} = op7_4;
2864 def t2SMMUL : T2SMMUL<0b0000, "smmul", [(set rGPR:$Rd, (mulhs rGPR:$Rn,
2867 T2SMMUL<0b0001, "smmulr",
2868 [(set rGPR:$Rd, (ARMsmmlar rGPR:$Rn, rGPR:$Rm, (i32 0)))]>;
2870 class T2FourRegSMMLA<bits<3> op22_20, bits<4> op7_4, string opc,
2872 : T2FourReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC32,
2873 opc, "\t$Rd, $Rn, $Rm, $Ra", pattern>,
2874 Requires<[IsThumb2, HasDSP, UseMulOps]>,
2875 Sched<[WriteMAC32, ReadMUL, ReadMUL, ReadMAC]> {
2876 let Inst{31-27} = 0b11111;
2877 let Inst{26-23} = 0b0110;
2878 let Inst{22-20} = op22_20;
2879 let Inst{7-4} = op7_4;
2882 def t2SMMLA : T2FourRegSMMLA<0b101, 0b0000, "smmla",
2883 [(set rGPR:$Rd, (add (mulhs rGPR:$Rm, rGPR:$Rn), rGPR:$Ra))]>;
2884 def t2SMMLAR: T2FourRegSMMLA<0b101, 0b0001, "smmlar",
2885 [(set rGPR:$Rd, (ARMsmmlar rGPR:$Rn, rGPR:$Rm, rGPR:$Ra))]>;
2886 def t2SMMLS: T2FourRegSMMLA<0b110, 0b0000, "smmls", []>;
2887 def t2SMMLSR: T2FourRegSMMLA<0b110, 0b0001, "smmlsr",
2888 [(set rGPR:$Rd, (ARMsmmlsr rGPR:$Rn, rGPR:$Rm, rGPR:$Ra))]>;
2890 class T2ThreeRegSMUL<bits<3> op22_20, bits<2> op5_4, string opc,
2892 : T2ThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iMUL16, opc,
2893 "\t$Rd, $Rn, $Rm", pattern>,
2894 Requires<[IsThumb2, HasDSP]>,
2895 Sched<[WriteMUL16, ReadMUL, ReadMUL]> {
2896 let Inst{31-27} = 0b11111;
2897 let Inst{26-23} = 0b0110;
2898 let Inst{22-20} = op22_20;
2899 let Inst{15-12} = 0b1111; // Ra = 0b1111 (no accumulate)
2900 let Inst{7-6} = 0b00;
2901 let Inst{5-4} = op5_4;
2904 def t2SMULBB : T2ThreeRegSMUL<0b001, 0b00, "smulbb",
2905 [(set rGPR:$Rd, (bb_mul rGPR:$Rn, rGPR:$Rm))]>;
2906 def t2SMULBT : T2ThreeRegSMUL<0b001, 0b01, "smulbt",
2907 [(set rGPR:$Rd, (bt_mul rGPR:$Rn, rGPR:$Rm))]>;
2908 def t2SMULTB : T2ThreeRegSMUL<0b001, 0b10, "smultb",
2909 [(set rGPR:$Rd, (tb_mul rGPR:$Rn, rGPR:$Rm))]>;
2910 def t2SMULTT : T2ThreeRegSMUL<0b001, 0b11, "smultt",
2911 [(set rGPR:$Rd, (tt_mul rGPR:$Rn, rGPR:$Rm))]>;
2912 def t2SMULWB : T2ThreeRegSMUL<0b011, 0b00, "smulwb",
2913 [(set rGPR:$Rd, (ARMsmulwb rGPR:$Rn, rGPR:$Rm))]>;
2914 def t2SMULWT : T2ThreeRegSMUL<0b011, 0b01, "smulwt",
2915 [(set rGPR:$Rd, (ARMsmulwt rGPR:$Rn, rGPR:$Rm))]>;
2917 def : Thumb2DSPPat<(mul sext_16_node:$Rn, (sext_bottom_16 rGPR:$Rm)),
2918 (t2SMULBB rGPR:$Rn, rGPR:$Rm)>;
2919 def : Thumb2DSPPat<(mul sext_16_node:$Rn, (sext_top_16 rGPR:$Rm)),
2920 (t2SMULBT rGPR:$Rn, rGPR:$Rm)>;
2921 def : Thumb2DSPPat<(mul (sext_top_16 rGPR:$Rn), sext_16_node:$Rm),
2922 (t2SMULTB rGPR:$Rn, rGPR:$Rm)>;
2924 def : Thumb2DSPPat<(int_arm_smulbb rGPR:$Rn, rGPR:$Rm),
2925 (t2SMULBB rGPR:$Rn, rGPR:$Rm)>;
2926 def : Thumb2DSPPat<(int_arm_smulbt rGPR:$Rn, rGPR:$Rm),
2927 (t2SMULBT rGPR:$Rn, rGPR:$Rm)>;
2928 def : Thumb2DSPPat<(int_arm_smultb rGPR:$Rn, rGPR:$Rm),
2929 (t2SMULTB rGPR:$Rn, rGPR:$Rm)>;
2930 def : Thumb2DSPPat<(int_arm_smultt rGPR:$Rn, rGPR:$Rm),
2931 (t2SMULTT rGPR:$Rn, rGPR:$Rm)>;
2932 def : Thumb2DSPPat<(int_arm_smulwb rGPR:$Rn, rGPR:$Rm),
2933 (t2SMULWB rGPR:$Rn, rGPR:$Rm)>;
2934 def : Thumb2DSPPat<(int_arm_smulwt rGPR:$Rn, rGPR:$Rm),
2935 (t2SMULWT rGPR:$Rn, rGPR:$Rm)>;
2937 class T2FourRegSMLA<bits<3> op22_20, bits<2> op5_4, string opc,
2939 : T2FourReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMUL16,
2940 opc, "\t$Rd, $Rn, $Rm, $Ra", pattern>,
2941 Requires<[IsThumb2, HasDSP, UseMulOps]>,
2942 Sched<[WriteMAC16, ReadMUL, ReadMUL, ReadMAC]> {
2943 let Inst{31-27} = 0b11111;
2944 let Inst{26-23} = 0b0110;
2945 let Inst{22-20} = op22_20;
2946 let Inst{7-6} = 0b00;
2947 let Inst{5-4} = op5_4;
2950 def t2SMLABB : T2FourRegSMLA<0b001, 0b00, "smlabb",
2951 [(set rGPR:$Rd, (add rGPR:$Ra, (bb_mul rGPR:$Rn, rGPR:$Rm)))]>;
2952 def t2SMLABT : T2FourRegSMLA<0b001, 0b01, "smlabt",
2953 [(set rGPR:$Rd, (add rGPR:$Ra, (bt_mul rGPR:$Rn, rGPR:$Rm)))]>;
2954 def t2SMLATB : T2FourRegSMLA<0b001, 0b10, "smlatb",
2955 [(set rGPR:$Rd, (add rGPR:$Ra, (tb_mul rGPR:$Rn, rGPR:$Rm)))]>;
2956 def t2SMLATT : T2FourRegSMLA<0b001, 0b11, "smlatt",
2957 [(set rGPR:$Rd, (add rGPR:$Ra, (tt_mul rGPR:$Rn, rGPR:$Rm)))]>;
2958 def t2SMLAWB : T2FourRegSMLA<0b011, 0b00, "smlawb",
2959 [(set rGPR:$Rd, (add rGPR:$Ra, (ARMsmulwb rGPR:$Rn, rGPR:$Rm)))]>;
2960 def t2SMLAWT : T2FourRegSMLA<0b011, 0b01, "smlawt",
2961 [(set rGPR:$Rd, (add rGPR:$Ra, (ARMsmulwt rGPR:$Rn, rGPR:$Rm)))]>;
2963 def : Thumb2DSPMulPat<(add rGPR:$Ra, (mul sext_16_node:$Rn, sext_16_node:$Rm)),
2964 (t2SMLABB rGPR:$Rn, rGPR:$Rm, rGPR:$Ra)>;
2965 def : Thumb2DSPMulPat<(add rGPR:$Ra, (mul sext_16_node:$Rn,
2966 (sext_bottom_16 rGPR:$Rm))),
2967 (t2SMLABB rGPR:$Rn, rGPR:$Rm, rGPR:$Ra)>;
2968 def : Thumb2DSPMulPat<(add rGPR:$Ra, (mul sext_16_node:$Rn,
2969 (sext_top_16 rGPR:$Rm))),
2970 (t2SMLABT rGPR:$Rn, rGPR:$Rm, rGPR:$Ra)>;
2971 def : Thumb2DSPMulPat<(add rGPR:$Ra, (mul (sext_top_16 rGPR:$Rn),
2973 (t2SMLATB rGPR:$Rn, rGPR:$Rm, rGPR:$Ra)>;
2975 def : Thumb2DSPPat<(int_arm_smlabb GPR:$a, GPR:$b, GPR:$acc),
2976 (t2SMLABB GPR:$a, GPR:$b, GPR:$acc)>;
2977 def : Thumb2DSPPat<(int_arm_smlabt GPR:$a, GPR:$b, GPR:$acc),
2978 (t2SMLABT GPR:$a, GPR:$b, GPR:$acc)>;
2979 def : Thumb2DSPPat<(int_arm_smlatb GPR:$a, GPR:$b, GPR:$acc),
2980 (t2SMLATB GPR:$a, GPR:$b, GPR:$acc)>;
2981 def : Thumb2DSPPat<(int_arm_smlatt GPR:$a, GPR:$b, GPR:$acc),
2982 (t2SMLATT GPR:$a, GPR:$b, GPR:$acc)>;
2983 def : Thumb2DSPPat<(int_arm_smlawb GPR:$a, GPR:$b, GPR:$acc),
2984 (t2SMLAWB GPR:$a, GPR:$b, GPR:$acc)>;
2985 def : Thumb2DSPPat<(int_arm_smlawt GPR:$a, GPR:$b, GPR:$acc),
2986 (t2SMLAWT GPR:$a, GPR:$b, GPR:$acc)>;
2988 // Halfword multiple accumulate long: SMLAL<x><y>
2989 def t2SMLALBB : T2MlaLong<0b100, 0b1000, "smlalbb">,
2990 Requires<[IsThumb2, HasDSP]>;
2991 def t2SMLALBT : T2MlaLong<0b100, 0b1001, "smlalbt">,
2992 Requires<[IsThumb2, HasDSP]>;
2993 def t2SMLALTB : T2MlaLong<0b100, 0b1010, "smlaltb">,
2994 Requires<[IsThumb2, HasDSP]>;
2995 def t2SMLALTT : T2MlaLong<0b100, 0b1011, "smlaltt">,
2996 Requires<[IsThumb2, HasDSP]>;
2998 def : Thumb2DSPPat<(ARMsmlalbb GPR:$Rn, GPR:$Rm, GPR:$RLo, GPR:$RHi),
2999 (t2SMLALBB $Rn, $Rm, $RLo, $RHi)>;
3000 def : Thumb2DSPPat<(ARMsmlalbt GPR:$Rn, GPR:$Rm, GPR:$RLo, GPR:$RHi),
3001 (t2SMLALBT $Rn, $Rm, $RLo, $RHi)>;
3002 def : Thumb2DSPPat<(ARMsmlaltb GPR:$Rn, GPR:$Rm, GPR:$RLo, GPR:$RHi),
3003 (t2SMLALTB $Rn, $Rm, $RLo, $RHi)>;
3004 def : Thumb2DSPPat<(ARMsmlaltt GPR:$Rn, GPR:$Rm, GPR:$RLo, GPR:$RHi),
3005 (t2SMLALTT $Rn, $Rm, $RLo, $RHi)>;
3007 class T2DualHalfMul<bits<3> op22_20, bits<4> op7_4, string opc,
3008 Intrinsic intrinsic>
3009 : T2ThreeReg_mac<0, op22_20, op7_4,
3011 (ins rGPR:$Rn, rGPR:$Rm),
3012 IIC_iMAC32, opc, "\t$Rd, $Rn, $Rm",
3013 [(set rGPR:$Rd, (intrinsic rGPR:$Rn, rGPR:$Rm))]>,
3014 Requires<[IsThumb2, HasDSP]>,
3015 Sched<[WriteMAC32, ReadMUL, ReadMUL, ReadMAC]> {
3016 let Inst{15-12} = 0b1111;
3019 // Dual halfword multiple: SMUAD, SMUSD, SMLAD, SMLSD, SMLALD, SMLSLD
3020 def t2SMUAD: T2DualHalfMul<0b010, 0b0000, "smuad", int_arm_smuad>;
3021 def t2SMUADX: T2DualHalfMul<0b010, 0b0001, "smuadx", int_arm_smuadx>;
3022 def t2SMUSD: T2DualHalfMul<0b100, 0b0000, "smusd", int_arm_smusd>;
3023 def t2SMUSDX: T2DualHalfMul<0b100, 0b0001, "smusdx", int_arm_smusdx>;
3025 class T2DualHalfMulAdd<bits<3> op22_20, bits<4> op7_4, string opc,
3026 Intrinsic intrinsic>
3027 : T2FourReg_mac<0, op22_20, op7_4,
3029 (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra),
3030 IIC_iMAC32, opc, "\t$Rd, $Rn, $Rm, $Ra",
3031 [(set rGPR:$Rd, (intrinsic rGPR:$Rn, rGPR:$Rm, rGPR:$Ra))]>,
3032 Requires<[IsThumb2, HasDSP]>;
3034 def t2SMLAD : T2DualHalfMulAdd<0b010, 0b0000, "smlad", int_arm_smlad>;
3035 def t2SMLADX : T2DualHalfMulAdd<0b010, 0b0001, "smladx", int_arm_smladx>;
3036 def t2SMLSD : T2DualHalfMulAdd<0b100, 0b0000, "smlsd", int_arm_smlsd>;
3037 def t2SMLSDX : T2DualHalfMulAdd<0b100, 0b0001, "smlsdx", int_arm_smlsdx>;
3039 class T2DualHalfMulAddLong<bits<3> op22_20, bits<4> op7_4, string opc>
3040 : T2FourReg_mac<1, op22_20, op7_4,
3041 (outs rGPR:$Ra, rGPR:$Rd),
3042 (ins rGPR:$Rn, rGPR:$Rm, rGPR:$RLo, rGPR:$RHi),
3043 IIC_iMAC64, opc, "\t$Ra, $Rd, $Rn, $Rm", []>,
3044 RegConstraint<"$Ra = $RLo, $Rd = $RHi">,
3045 Requires<[IsThumb2, HasDSP]>,
3046 Sched<[WriteMAC64Lo, WriteMAC64Hi, ReadMUL, ReadMUL, ReadMAC, ReadMAC]>;
3048 def t2SMLALD : T2DualHalfMulAddLong<0b100, 0b1100, "smlald">;
3049 def t2SMLALDX : T2DualHalfMulAddLong<0b100, 0b1101, "smlaldx">;
3050 def t2SMLSLD : T2DualHalfMulAddLong<0b101, 0b1100, "smlsld">;
3051 def t2SMLSLDX : T2DualHalfMulAddLong<0b101, 0b1101, "smlsldx">;
3053 def : Thumb2DSPPat<(ARMSmlald rGPR:$Rn, rGPR:$Rm, rGPR:$RLo, rGPR:$RHi),
3054 (t2SMLALD rGPR:$Rn, rGPR:$Rm, rGPR:$RLo, rGPR:$RHi)>;
3055 def : Thumb2DSPPat<(ARMSmlaldx rGPR:$Rn, rGPR:$Rm, rGPR:$RLo, rGPR:$RHi),
3056 (t2SMLALDX rGPR:$Rn, rGPR:$Rm, rGPR:$RLo, rGPR:$RHi)>;
3057 def : Thumb2DSPPat<(ARMSmlsld rGPR:$Rn, rGPR:$Rm, rGPR:$RLo, rGPR:$RHi),
3058 (t2SMLSLD rGPR:$Rn, rGPR:$Rm, rGPR:$RLo, rGPR:$RHi)>;
3059 def : Thumb2DSPPat<(ARMSmlsldx rGPR:$Rn, rGPR:$Rm, rGPR:$RLo, rGPR:$RHi),
3060 (t2SMLSLDX rGPR:$Rn, rGPR:$Rm, rGPR:$RLo, rGPR:$RHi)>;
3062 //===----------------------------------------------------------------------===//
3063 // Division Instructions.
3064 // Signed and unsigned division on v7-M
3066 def t2SDIV : T2ThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iDIV,
3067 "sdiv", "\t$Rd, $Rn, $Rm",
3068 [(set rGPR:$Rd, (sdiv rGPR:$Rn, rGPR:$Rm))]>,
3069 Requires<[HasDivideInThumb, IsThumb, HasV8MBaseline]>,
3071 let Inst{31-27} = 0b11111;
3072 let Inst{26-21} = 0b011100;
3074 let Inst{15-12} = 0b1111;
3075 let Inst{7-4} = 0b1111;
3078 def t2UDIV : T2ThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iDIV,
3079 "udiv", "\t$Rd, $Rn, $Rm",
3080 [(set rGPR:$Rd, (udiv rGPR:$Rn, rGPR:$Rm))]>,
3081 Requires<[HasDivideInThumb, IsThumb, HasV8MBaseline]>,
3083 let Inst{31-27} = 0b11111;
3084 let Inst{26-21} = 0b011101;
3086 let Inst{15-12} = 0b1111;
3087 let Inst{7-4} = 0b1111;
3090 //===----------------------------------------------------------------------===//
3091 // Misc. Arithmetic Instructions.
3094 class T2I_misc<bits<2> op1, bits<2> op2, dag oops, dag iops,
3095 InstrItinClass itin, string opc, string asm, list<dag> pattern>
3096 : T2ThreeReg<oops, iops, itin, opc, asm, pattern> {
3097 let Inst{31-27} = 0b11111;
3098 let Inst{26-22} = 0b01010;
3099 let Inst{21-20} = op1;
3100 let Inst{15-12} = 0b1111;
3101 let Inst{7-6} = 0b10;
3102 let Inst{5-4} = op2;
3106 def t2CLZ : T2I_misc<0b11, 0b00, (outs rGPR:$Rd), (ins rGPR:$Rm), IIC_iUNAr,
3107 "clz", "\t$Rd, $Rm", [(set rGPR:$Rd, (ctlz rGPR:$Rm))]>,
3110 def t2RBIT : T2I_misc<0b01, 0b10, (outs rGPR:$Rd), (ins rGPR:$Rm), IIC_iUNAr,
3111 "rbit", "\t$Rd, $Rm",
3112 [(set rGPR:$Rd, (bitreverse rGPR:$Rm))]>,
3115 def t2REV : T2I_misc<0b01, 0b00, (outs rGPR:$Rd), (ins rGPR:$Rm), IIC_iUNAr,
3116 "rev", ".w\t$Rd, $Rm", [(set rGPR:$Rd, (bswap rGPR:$Rm))]>,
3119 def t2REV16 : T2I_misc<0b01, 0b01, (outs rGPR:$Rd), (ins rGPR:$Rm), IIC_iUNAr,
3120 "rev16", ".w\t$Rd, $Rm",
3121 [(set rGPR:$Rd, (rotr (bswap rGPR:$Rm), (i32 16)))]>,
3124 def t2REVSH : T2I_misc<0b01, 0b11, (outs rGPR:$Rd), (ins rGPR:$Rm), IIC_iUNAr,
3125 "revsh", ".w\t$Rd, $Rm",
3126 [(set rGPR:$Rd, (sra (bswap rGPR:$Rm), (i32 16)))]>,
3129 def : T2Pat<(or (sra (shl rGPR:$Rm, (i32 24)), (i32 16)),
3130 (and (srl rGPR:$Rm, (i32 8)), 0xFF)),
3131 (t2REVSH rGPR:$Rm)>;
3133 def t2PKHBT : T2ThreeReg<
3134 (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, pkh_lsl_amt:$sh),
3135 IIC_iBITsi, "pkhbt", "\t$Rd, $Rn, $Rm$sh",
3136 [(set rGPR:$Rd, (or (and rGPR:$Rn, 0xFFFF),
3137 (and (shl rGPR:$Rm, pkh_lsl_amt:$sh),
3139 Requires<[HasDSP, IsThumb2]>,
3140 Sched<[WriteALUsi, ReadALU]> {
3141 let Inst{31-27} = 0b11101;
3142 let Inst{26-25} = 0b01;
3143 let Inst{24-20} = 0b01100;
3144 let Inst{5} = 0; // BT form
3148 let Inst{14-12} = sh{4-2};
3149 let Inst{7-6} = sh{1-0};
3152 // Alternate cases for PKHBT where identities eliminate some nodes.
3153 def : T2Pat<(or (and rGPR:$src1, 0xFFFF), (and rGPR:$src2, 0xFFFF0000)),
3154 (t2PKHBT rGPR:$src1, rGPR:$src2, 0)>,
3155 Requires<[HasDSP, IsThumb2]>;
3156 def : T2Pat<(or (and rGPR:$src1, 0xFFFF), (shl rGPR:$src2, imm16_31:$sh)),
3157 (t2PKHBT rGPR:$src1, rGPR:$src2, imm16_31:$sh)>,
3158 Requires<[HasDSP, IsThumb2]>;
3160 // Note: Shifts of 1-15 bits will be transformed to srl instead of sra and
3161 // will match the pattern below.
3162 def t2PKHTB : T2ThreeReg<
3163 (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, pkh_asr_amt:$sh),
3164 IIC_iBITsi, "pkhtb", "\t$Rd, $Rn, $Rm$sh",
3165 [(set rGPR:$Rd, (or (and rGPR:$Rn, 0xFFFF0000),
3166 (and (sra rGPR:$Rm, pkh_asr_amt:$sh),
3168 Requires<[HasDSP, IsThumb2]>,
3169 Sched<[WriteALUsi, ReadALU]> {
3170 let Inst{31-27} = 0b11101;
3171 let Inst{26-25} = 0b01;
3172 let Inst{24-20} = 0b01100;
3173 let Inst{5} = 1; // TB form
3177 let Inst{14-12} = sh{4-2};
3178 let Inst{7-6} = sh{1-0};
3181 // Alternate cases for PKHTB where identities eliminate some nodes. Note that
3182 // a shift amount of 0 is *not legal* here, it is PKHBT instead.
3183 // We also can not replace a srl (17..31) by an arithmetic shift we would use in
3184 // pkhtb src1, src2, asr (17..31).
3185 def : T2Pat<(or (and rGPR:$src1, 0xFFFF0000), (srl rGPR:$src2, imm16:$sh)),
3186 (t2PKHTB rGPR:$src1, rGPR:$src2, imm16:$sh)>,
3187 Requires<[HasDSP, IsThumb2]>;
3188 def : T2Pat<(or (and rGPR:$src1, 0xFFFF0000), (sra rGPR:$src2, imm16_31:$sh)),
3189 (t2PKHTB rGPR:$src1, rGPR:$src2, imm16_31:$sh)>,
3190 Requires<[HasDSP, IsThumb2]>;
3191 def : T2Pat<(or (and rGPR:$src1, 0xFFFF0000),
3192 (and (srl rGPR:$src2, imm1_15:$sh), 0xFFFF)),
3193 (t2PKHTB rGPR:$src1, rGPR:$src2, imm1_15:$sh)>,
3194 Requires<[HasDSP, IsThumb2]>;
3196 //===----------------------------------------------------------------------===//
3197 // CRC32 Instructions
3200 // + CRC32{B,H,W} 0x04C11DB7
3201 // + CRC32C{B,H,W} 0x1EDC6F41
3204 class T2I_crc32<bit C, bits<2> sz, string suffix, SDPatternOperator builtin>
3205 : T2ThreeRegNoP<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), NoItinerary,
3206 !strconcat("crc32", suffix, "\t$Rd, $Rn, $Rm"),
3207 [(set rGPR:$Rd, (builtin rGPR:$Rn, rGPR:$Rm))]>,
3208 Requires<[IsThumb2, HasV8, HasCRC]> {
3209 let Inst{31-27} = 0b11111;
3210 let Inst{26-21} = 0b010110;
3212 let Inst{15-12} = 0b1111;
3213 let Inst{7-6} = 0b10;
3217 def t2CRC32B : T2I_crc32<0, 0b00, "b", int_arm_crc32b>;
3218 def t2CRC32CB : T2I_crc32<1, 0b00, "cb", int_arm_crc32cb>;
3219 def t2CRC32H : T2I_crc32<0, 0b01, "h", int_arm_crc32h>;
3220 def t2CRC32CH : T2I_crc32<1, 0b01, "ch", int_arm_crc32ch>;
3221 def t2CRC32W : T2I_crc32<0, 0b10, "w", int_arm_crc32w>;
3222 def t2CRC32CW : T2I_crc32<1, 0b10, "cw", int_arm_crc32cw>;
3224 //===----------------------------------------------------------------------===//
3225 // Comparison Instructions...
3227 defm t2CMP : T2I_cmp_irs<0b1101, "cmp", GPRnopc,
3228 IIC_iCMPi, IIC_iCMPr, IIC_iCMPsi, ARMcmp>;
3230 def : T2Pat<(ARMcmpZ GPRnopc:$lhs, t2_so_imm:$imm),
3231 (t2CMPri GPRnopc:$lhs, t2_so_imm:$imm)>;
3232 def : T2Pat<(ARMcmpZ GPRnopc:$lhs, rGPR:$rhs),
3233 (t2CMPrr GPRnopc:$lhs, rGPR:$rhs)>;
3234 def : T2Pat<(ARMcmpZ GPRnopc:$lhs, t2_so_reg:$rhs),
3235 (t2CMPrs GPRnopc:$lhs, t2_so_reg:$rhs)>;
3237 let isCompare = 1, Defs = [CPSR] in {
3239 def t2CMNri : T2OneRegCmpImm<
3240 (outs), (ins GPRnopc:$Rn, t2_so_imm:$imm), IIC_iCMPi,
3241 "cmn", ".w\t$Rn, $imm",
3242 [(ARMcmn GPRnopc:$Rn, (ineg t2_so_imm:$imm))]>,
3243 Sched<[WriteCMP, ReadALU]> {
3244 let Inst{31-27} = 0b11110;
3246 let Inst{24-21} = 0b1000;
3247 let Inst{20} = 1; // The S bit.
3249 let Inst{11-8} = 0b1111; // Rd
3252 def t2CMNzrr : T2TwoRegCmp<
3253 (outs), (ins GPRnopc:$Rn, rGPR:$Rm), IIC_iCMPr,
3254 "cmn", ".w\t$Rn, $Rm",
3255 [(BinOpFrag<(ARMcmpZ node:$LHS,(ineg node:$RHS))>
3256 GPRnopc:$Rn, rGPR:$Rm)]>, Sched<[WriteCMP, ReadALU, ReadALU]> {
3257 let Inst{31-27} = 0b11101;
3258 let Inst{26-25} = 0b01;
3259 let Inst{24-21} = 0b1000;
3260 let Inst{20} = 1; // The S bit.
3261 let Inst{14-12} = 0b000; // imm3
3262 let Inst{11-8} = 0b1111; // Rd
3263 let Inst{7-6} = 0b00; // imm2
3264 let Inst{5-4} = 0b00; // type
3267 def t2CMNzrs : T2OneRegCmpShiftedReg<
3268 (outs), (ins GPRnopc:$Rn, t2_so_reg:$ShiftedRm), IIC_iCMPsi,
3269 "cmn", ".w\t$Rn, $ShiftedRm",
3270 [(BinOpFrag<(ARMcmpZ node:$LHS,(ineg node:$RHS))>
3271 GPRnopc:$Rn, t2_so_reg:$ShiftedRm)]>,
3272 Sched<[WriteCMPsi, ReadALU, ReadALU]> {
3273 let Inst{31-27} = 0b11101;
3274 let Inst{26-25} = 0b01;
3275 let Inst{24-21} = 0b1000;
3276 let Inst{20} = 1; // The S bit.
3277 let Inst{11-8} = 0b1111; // Rd
3281 // Assembler aliases w/o the ".w" suffix.
3282 // No alias here for 'rr' version as not all instantiations of this multiclass
3283 // want one (CMP in particular, does not).
3284 def : t2InstAlias<"cmn${p} $Rn, $imm",
3285 (t2CMNri GPRnopc:$Rn, t2_so_imm:$imm, pred:$p)>;
3286 def : t2InstAlias<"cmn${p} $Rn, $shift",
3287 (t2CMNzrs GPRnopc:$Rn, t2_so_reg:$shift, pred:$p)>;
3289 def : T2Pat<(ARMcmp GPR:$src, t2_so_imm_neg:$imm),
3290 (t2CMNri GPR:$src, t2_so_imm_neg:$imm)>;
3292 def : T2Pat<(ARMcmpZ GPRnopc:$src, t2_so_imm_neg:$imm),
3293 (t2CMNri GPRnopc:$src, t2_so_imm_neg:$imm)>;
3295 defm t2TST : T2I_cmp_irs<0b0000, "tst", rGPR,
3296 IIC_iTSTi, IIC_iTSTr, IIC_iTSTsi,
3297 BinOpFrag<(ARMcmpZ (and_su node:$LHS, node:$RHS), 0)>>;
3298 defm t2TEQ : T2I_cmp_irs<0b0100, "teq", rGPR,
3299 IIC_iTSTi, IIC_iTSTr, IIC_iTSTsi,
3300 BinOpFrag<(ARMcmpZ (xor_su node:$LHS, node:$RHS), 0)>>;
3302 // Conditional moves
3303 let hasSideEffects = 0 in {
3305 let isCommutable = 1, isSelect = 1 in
3306 def t2MOVCCr : t2PseudoInst<(outs rGPR:$Rd),
3307 (ins rGPR:$false, rGPR:$Rm, cmovpred:$p),
3309 [(set rGPR:$Rd, (ARMcmov rGPR:$false, rGPR:$Rm,
3311 RegConstraint<"$false = $Rd">, Sched<[WriteALU]>;
3313 let isMoveImm = 1 in
3315 : t2PseudoInst<(outs rGPR:$Rd),
3316 (ins rGPR:$false, t2_so_imm:$imm, cmovpred:$p),
3318 [(set rGPR:$Rd, (ARMcmov rGPR:$false,t2_so_imm:$imm,
3320 RegConstraint<"$false = $Rd">, Sched<[WriteALU]>;
3322 let isCodeGenOnly = 1 in {
3323 let isMoveImm = 1 in
3325 : t2PseudoInst<(outs rGPR:$Rd),
3326 (ins rGPR:$false, imm0_65535_expr:$imm, cmovpred:$p),
3328 [(set rGPR:$Rd, (ARMcmov rGPR:$false, imm0_65535:$imm,
3330 RegConstraint<"$false = $Rd">, Sched<[WriteALU]>;
3332 let isMoveImm = 1 in
3334 : t2PseudoInst<(outs rGPR:$Rd),
3335 (ins rGPR:$false, t2_so_imm:$imm, cmovpred:$p),
3338 (ARMcmov rGPR:$false, t2_so_imm_not:$imm,
3340 RegConstraint<"$false = $Rd">, Sched<[WriteALU]>;
3342 class MOVCCShPseudo<SDPatternOperator opnode, Operand ty>
3343 : t2PseudoInst<(outs rGPR:$Rd),
3344 (ins rGPR:$false, rGPR:$Rm, i32imm:$imm, cmovpred:$p),
3346 [(set rGPR:$Rd, (ARMcmov rGPR:$false,
3347 (opnode rGPR:$Rm, (i32 ty:$imm)),
3349 RegConstraint<"$false = $Rd">, Sched<[WriteALU]>;
3351 def t2MOVCClsl : MOVCCShPseudo<shl, imm0_31>;
3352 def t2MOVCClsr : MOVCCShPseudo<srl, imm_sr>;
3353 def t2MOVCCasr : MOVCCShPseudo<sra, imm_sr>;
3354 def t2MOVCCror : MOVCCShPseudo<rotr, imm0_31>;
3356 let isMoveImm = 1 in
3358 : t2PseudoInst<(outs rGPR:$dst),
3359 (ins rGPR:$false, i32imm:$src, cmovpred:$p),
3361 [(set rGPR:$dst, (ARMcmov rGPR:$false, imm:$src,
3363 RegConstraint<"$false = $dst">;
3364 } // isCodeGenOnly = 1
3368 //===----------------------------------------------------------------------===//
3369 // Atomic operations intrinsics
3372 // memory barriers protect the atomic sequences
3373 let hasSideEffects = 1 in {
3374 def t2DMB : T2I<(outs), (ins memb_opt:$opt), NoItinerary,
3375 "dmb", "\t$opt", [(int_arm_dmb (i32 imm0_15:$opt))]>,
3376 Requires<[IsThumb, HasDB]> {
3378 let Inst{31-4} = 0xf3bf8f5;
3379 let Inst{3-0} = opt;
3382 def t2DSB : T2I<(outs), (ins memb_opt:$opt), NoItinerary,
3383 "dsb", "\t$opt", [(int_arm_dsb (i32 imm0_15:$opt))]>,
3384 Requires<[IsThumb, HasDB]> {
3386 let Inst{31-4} = 0xf3bf8f4;
3387 let Inst{3-0} = opt;
3390 def t2ISB : T2I<(outs), (ins instsyncb_opt:$opt), NoItinerary,
3391 "isb", "\t$opt", [(int_arm_isb (i32 imm0_15:$opt))]>,
3392 Requires<[IsThumb, HasDB]> {
3394 let Inst{31-4} = 0xf3bf8f6;
3395 let Inst{3-0} = opt;
3398 let hasNoSchedulingInfo = 1 in
3399 def t2TSB : T2I<(outs), (ins tsb_opt:$opt), NoItinerary,
3400 "tsb", "\t$opt", []>, Requires<[IsThumb, HasV8_4a]> {
3401 let Inst{31-0} = 0xf3af8012;
3405 // Armv8.5-A speculation barrier
3406 def t2SB : Thumb2XI<(outs), (ins), AddrModeNone, 4, NoItinerary, "sb", "", []>,
3407 Requires<[IsThumb2, HasSB]>, Sched<[]> {
3408 let Inst{31-0} = 0xf3bf8f70;
3409 let Unpredictable = 0x000f2f0f;
3410 let hasSideEffects = 1;
3413 class T2I_ldrex<bits<4> opcod, dag oops, dag iops, AddrMode am, int sz,
3414 InstrItinClass itin, string opc, string asm, string cstr,
3415 list<dag> pattern, bits<4> rt2 = 0b1111>
3416 : Thumb2I<oops, iops, am, sz, itin, opc, asm, cstr, pattern> {
3417 let Inst{31-27} = 0b11101;
3418 let Inst{26-20} = 0b0001101;
3419 let Inst{11-8} = rt2;
3420 let Inst{7-4} = opcod;
3421 let Inst{3-0} = 0b1111;
3425 let Inst{19-16} = addr;
3426 let Inst{15-12} = Rt;
3428 class T2I_strex<bits<4> opcod, dag oops, dag iops, AddrMode am, int sz,
3429 InstrItinClass itin, string opc, string asm, string cstr,
3430 list<dag> pattern, bits<4> rt2 = 0b1111>
3431 : Thumb2I<oops, iops, am, sz, itin, opc, asm, cstr, pattern> {
3432 let Inst{31-27} = 0b11101;
3433 let Inst{26-20} = 0b0001100;
3434 let Inst{11-8} = rt2;
3435 let Inst{7-4} = opcod;
3441 let Inst{19-16} = addr;
3442 let Inst{15-12} = Rt;
3445 let mayLoad = 1 in {
3446 def t2LDREXB : T2I_ldrex<0b0100, (outs rGPR:$Rt), (ins addr_offset_none:$addr),
3447 AddrModeNone, 4, NoItinerary,
3448 "ldrexb", "\t$Rt, $addr", "",
3449 [(set rGPR:$Rt, (ldrex_1 addr_offset_none:$addr))]>,
3450 Requires<[IsThumb, HasV8MBaseline]>, Sched<[WriteLd]>;
3451 def t2LDREXH : T2I_ldrex<0b0101, (outs rGPR:$Rt), (ins addr_offset_none:$addr),
3452 AddrModeNone, 4, NoItinerary,
3453 "ldrexh", "\t$Rt, $addr", "",
3454 [(set rGPR:$Rt, (ldrex_2 addr_offset_none:$addr))]>,
3455 Requires<[IsThumb, HasV8MBaseline]>, Sched<[WriteLd]>;
3456 def t2LDREX : Thumb2I<(outs rGPR:$Rt), (ins t2addrmode_imm0_1020s4:$addr),
3457 AddrModeT2_ldrex, 4, NoItinerary,
3458 "ldrex", "\t$Rt, $addr", "",
3459 [(set rGPR:$Rt, (ldrex_4 t2addrmode_imm0_1020s4:$addr))]>,
3460 Requires<[IsThumb, HasV8MBaseline]>, Sched<[WriteLd]> {
3463 let Inst{31-27} = 0b11101;
3464 let Inst{26-20} = 0b0000101;
3465 let Inst{19-16} = addr{11-8};
3466 let Inst{15-12} = Rt;
3467 let Inst{11-8} = 0b1111;
3468 let Inst{7-0} = addr{7-0};
3470 let hasExtraDefRegAllocReq = 1 in
3471 def t2LDREXD : T2I_ldrex<0b0111, (outs rGPR:$Rt, rGPR:$Rt2),
3472 (ins addr_offset_none:$addr),
3473 AddrModeNone, 4, NoItinerary,
3474 "ldrexd", "\t$Rt, $Rt2, $addr", "",
3476 Requires<[IsThumb2, IsNotMClass]>, Sched<[WriteLd]> {
3478 let Inst{11-8} = Rt2;
3480 def t2LDAEXB : T2I_ldrex<0b1100, (outs rGPR:$Rt), (ins addr_offset_none:$addr),
3481 AddrModeNone, 4, NoItinerary,
3482 "ldaexb", "\t$Rt, $addr", "",
3483 [(set rGPR:$Rt, (ldaex_1 addr_offset_none:$addr))]>,
3484 Requires<[IsThumb, HasAcquireRelease, HasV7Clrex]>, Sched<[WriteLd]>;
3485 def t2LDAEXH : T2I_ldrex<0b1101, (outs rGPR:$Rt), (ins addr_offset_none:$addr),
3486 AddrModeNone, 4, NoItinerary,
3487 "ldaexh", "\t$Rt, $addr", "",
3488 [(set rGPR:$Rt, (ldaex_2 addr_offset_none:$addr))]>,
3489 Requires<[IsThumb, HasAcquireRelease, HasV7Clrex]>, Sched<[WriteLd]>;
3490 def t2LDAEX : Thumb2I<(outs rGPR:$Rt), (ins addr_offset_none:$addr),
3491 AddrModeNone, 4, NoItinerary,
3492 "ldaex", "\t$Rt, $addr", "",
3493 [(set rGPR:$Rt, (ldaex_4 addr_offset_none:$addr))]>,
3494 Requires<[IsThumb, HasAcquireRelease, HasV7Clrex]>, Sched<[WriteLd]> {
3497 let Inst{31-27} = 0b11101;
3498 let Inst{26-20} = 0b0001101;
3499 let Inst{19-16} = addr;
3500 let Inst{15-12} = Rt;
3501 let Inst{11-8} = 0b1111;
3502 let Inst{7-0} = 0b11101111;
3504 let hasExtraDefRegAllocReq = 1 in
3505 def t2LDAEXD : T2I_ldrex<0b1111, (outs rGPR:$Rt, rGPR:$Rt2),
3506 (ins addr_offset_none:$addr),
3507 AddrModeNone, 4, NoItinerary,
3508 "ldaexd", "\t$Rt, $Rt2, $addr", "",
3509 [], {?, ?, ?, ?}>, Requires<[IsThumb,
3510 HasAcquireRelease, HasV7Clrex, IsNotMClass]>, Sched<[WriteLd]> {
3512 let Inst{11-8} = Rt2;
3518 let mayStore = 1, Constraints = "@earlyclobber $Rd" in {
3519 def t2STREXB : T2I_strex<0b0100, (outs rGPR:$Rd),
3520 (ins rGPR:$Rt, addr_offset_none:$addr),
3521 AddrModeNone, 4, NoItinerary,
3522 "strexb", "\t$Rd, $Rt, $addr", "",
3524 (strex_1 rGPR:$Rt, addr_offset_none:$addr))]>,
3525 Requires<[IsThumb, HasV8MBaseline]>, Sched<[WriteST]>;
3526 def t2STREXH : T2I_strex<0b0101, (outs rGPR:$Rd),
3527 (ins rGPR:$Rt, addr_offset_none:$addr),
3528 AddrModeNone, 4, NoItinerary,
3529 "strexh", "\t$Rd, $Rt, $addr", "",
3531 (strex_2 rGPR:$Rt, addr_offset_none:$addr))]>,
3532 Requires<[IsThumb, HasV8MBaseline]>, Sched<[WriteST]>;
3534 def t2STREX : Thumb2I<(outs rGPR:$Rd), (ins rGPR:$Rt,
3535 t2addrmode_imm0_1020s4:$addr),
3536 AddrModeT2_ldrex, 4, NoItinerary,
3537 "strex", "\t$Rd, $Rt, $addr", "",
3539 (strex_4 rGPR:$Rt, t2addrmode_imm0_1020s4:$addr))]>,
3540 Requires<[IsThumb, HasV8MBaseline]>, Sched<[WriteST]> {
3544 let Inst{31-27} = 0b11101;
3545 let Inst{26-20} = 0b0000100;
3546 let Inst{19-16} = addr{11-8};
3547 let Inst{15-12} = Rt;
3548 let Inst{11-8} = Rd;
3549 let Inst{7-0} = addr{7-0};
3551 let hasExtraSrcRegAllocReq = 1 in
3552 def t2STREXD : T2I_strex<0b0111, (outs rGPR:$Rd),
3553 (ins rGPR:$Rt, rGPR:$Rt2, addr_offset_none:$addr),
3554 AddrModeNone, 4, NoItinerary,
3555 "strexd", "\t$Rd, $Rt, $Rt2, $addr", "", [],
3557 Requires<[IsThumb2, IsNotMClass]>, Sched<[WriteST]> {
3559 let Inst{11-8} = Rt2;
3561 def t2STLEXB : T2I_strex<0b1100, (outs rGPR:$Rd),
3562 (ins rGPR:$Rt, addr_offset_none:$addr),
3563 AddrModeNone, 4, NoItinerary,
3564 "stlexb", "\t$Rd, $Rt, $addr", "",
3566 (stlex_1 rGPR:$Rt, addr_offset_none:$addr))]>,
3567 Requires<[IsThumb, HasAcquireRelease,
3568 HasV7Clrex]>, Sched<[WriteST]>;
3570 def t2STLEXH : T2I_strex<0b1101, (outs rGPR:$Rd),
3571 (ins rGPR:$Rt, addr_offset_none:$addr),
3572 AddrModeNone, 4, NoItinerary,
3573 "stlexh", "\t$Rd, $Rt, $addr", "",
3575 (stlex_2 rGPR:$Rt, addr_offset_none:$addr))]>,
3576 Requires<[IsThumb, HasAcquireRelease,
3577 HasV7Clrex]>, Sched<[WriteST]>;
3579 def t2STLEX : Thumb2I<(outs rGPR:$Rd), (ins rGPR:$Rt,
3580 addr_offset_none:$addr),
3581 AddrModeNone, 4, NoItinerary,
3582 "stlex", "\t$Rd, $Rt, $addr", "",
3584 (stlex_4 rGPR:$Rt, addr_offset_none:$addr))]>,
3585 Requires<[IsThumb, HasAcquireRelease, HasV7Clrex]>,
3590 let Inst{31-27} = 0b11101;
3591 let Inst{26-20} = 0b0001100;
3592 let Inst{19-16} = addr;
3593 let Inst{15-12} = Rt;
3594 let Inst{11-4} = 0b11111110;
3597 let hasExtraSrcRegAllocReq = 1 in
3598 def t2STLEXD : T2I_strex<0b1111, (outs rGPR:$Rd),
3599 (ins rGPR:$Rt, rGPR:$Rt2, addr_offset_none:$addr),
3600 AddrModeNone, 4, NoItinerary,
3601 "stlexd", "\t$Rd, $Rt, $Rt2, $addr", "", [],
3602 {?, ?, ?, ?}>, Requires<[IsThumb, HasAcquireRelease,
3603 HasV7Clrex, IsNotMClass]>, Sched<[WriteST]> {
3605 let Inst{11-8} = Rt2;
3609 def t2CLREX : T2I<(outs), (ins), NoItinerary, "clrex", "", [(int_arm_clrex)]>,
3610 Requires<[IsThumb, HasV7Clrex]> {
3611 let Inst{31-16} = 0xf3bf;
3612 let Inst{15-14} = 0b10;
3615 let Inst{11-8} = 0b1111;
3616 let Inst{7-4} = 0b0010;
3617 let Inst{3-0} = 0b1111;
3620 def : T2Pat<(and (ldrex_1 addr_offset_none:$addr), 0xff),
3621 (t2LDREXB addr_offset_none:$addr)>,
3622 Requires<[IsThumb, HasV8MBaseline]>;
3623 def : T2Pat<(and (ldrex_2 addr_offset_none:$addr), 0xffff),
3624 (t2LDREXH addr_offset_none:$addr)>,
3625 Requires<[IsThumb, HasV8MBaseline]>;
3626 def : T2Pat<(strex_1 (and GPR:$Rt, 0xff), addr_offset_none:$addr),
3627 (t2STREXB GPR:$Rt, addr_offset_none:$addr)>,
3628 Requires<[IsThumb, HasV8MBaseline]>;
3629 def : T2Pat<(strex_2 (and GPR:$Rt, 0xffff), addr_offset_none:$addr),
3630 (t2STREXH GPR:$Rt, addr_offset_none:$addr)>,
3631 Requires<[IsThumb, HasV8MBaseline]>;
3633 def : T2Pat<(and (ldaex_1 addr_offset_none:$addr), 0xff),
3634 (t2LDAEXB addr_offset_none:$addr)>,
3635 Requires<[IsThumb, HasAcquireRelease, HasV7Clrex]>;
3636 def : T2Pat<(and (ldaex_2 addr_offset_none:$addr), 0xffff),
3637 (t2LDAEXH addr_offset_none:$addr)>,
3638 Requires<[IsThumb, HasAcquireRelease, HasV7Clrex]>;
3639 def : T2Pat<(stlex_1 (and GPR:$Rt, 0xff), addr_offset_none:$addr),
3640 (t2STLEXB GPR:$Rt, addr_offset_none:$addr)>,
3641 Requires<[IsThumb, HasAcquireRelease, HasV7Clrex]>;
3642 def : T2Pat<(stlex_2 (and GPR:$Rt, 0xffff), addr_offset_none:$addr),
3643 (t2STLEXH GPR:$Rt, addr_offset_none:$addr)>,
3644 Requires<[IsThumb, HasAcquireRelease, HasV7Clrex]>;
3646 //===----------------------------------------------------------------------===//
3647 // SJLJ Exception handling intrinsics
3648 // eh_sjlj_setjmp() is an instruction sequence to store the return
3649 // address and save #0 in R0 for the non-longjmp case.
3650 // Since by its nature we may be coming from some other function to get
3651 // here, and we're using the stack frame for the containing function to
3652 // save/restore registers, we can't keep anything live in regs across
3653 // the eh_sjlj_setjmp(), else it will almost certainly have been tromped upon
3654 // when we get here from a longjmp(). We force everything out of registers
3655 // except for our own input by listing the relevant registers in Defs. By
3656 // doing so, we also cause the prologue/epilogue code to actively preserve
3657 // all of the callee-saved resgisters, which is exactly what we want.
3658 // $val is a scratch register for our use.
3660 [ R0, R1, R2, R3, R4, R5, R6, R7, R8, R9, R10, R11, R12, LR, CPSR,
3661 Q0, Q1, Q2, Q3, Q8, Q9, Q10, Q11, Q12, Q13, Q14, Q15],
3662 hasSideEffects = 1, isBarrier = 1, isCodeGenOnly = 1,
3663 usesCustomInserter = 1 in {
3664 def t2Int_eh_sjlj_setjmp : Thumb2XI<(outs), (ins tGPR:$src, tGPR:$val),
3665 AddrModeNone, 0, NoItinerary, "", "",
3666 [(set R0, (ARMeh_sjlj_setjmp tGPR:$src, tGPR:$val))]>,
3667 Requires<[IsThumb2, HasVFP2]>;
3671 [ R0, R1, R2, R3, R4, R5, R6, R7, R8, R9, R10, R11, R12, LR, CPSR ],
3672 hasSideEffects = 1, isBarrier = 1, isCodeGenOnly = 1,
3673 usesCustomInserter = 1 in {
3674 def t2Int_eh_sjlj_setjmp_nofp : Thumb2XI<(outs), (ins tGPR:$src, tGPR:$val),
3675 AddrModeNone, 0, NoItinerary, "", "",
3676 [(set R0, (ARMeh_sjlj_setjmp tGPR:$src, tGPR:$val))]>,
3677 Requires<[IsThumb2, NoVFP]>;
3681 //===----------------------------------------------------------------------===//
3682 // Control-Flow Instructions
3685 // FIXME: remove when we have a way to marking a MI with these properties.
3686 // FIXME: Should pc be an implicit operand like PICADD, etc?
3687 let isReturn = 1, isTerminator = 1, isBarrier = 1, mayLoad = 1,
3688 hasExtraDefRegAllocReq = 1, isCodeGenOnly = 1 in
3689 def t2LDMIA_RET: t2PseudoExpand<(outs GPR:$wb), (ins GPR:$Rn, pred:$p,
3690 reglist:$regs, variable_ops),
3691 4, IIC_iLoad_mBr, [],
3692 (t2LDMIA_UPD GPR:$wb, GPR:$Rn, pred:$p, reglist:$regs)>,
3693 RegConstraint<"$Rn = $wb">;
3695 let isBranch = 1, isTerminator = 1, isBarrier = 1 in {
3696 let isPredicable = 1 in
3697 def t2B : T2I<(outs), (ins thumb_br_target:$target), IIC_Br,
3699 [(br bb:$target)]>, Sched<[WriteBr]>,
3700 Requires<[IsThumb, HasV8MBaseline]> {
3701 let Inst{31-27} = 0b11110;
3702 let Inst{15-14} = 0b10;
3706 let Inst{26} = target{23};
3707 let Inst{13} = target{22};
3708 let Inst{11} = target{21};
3709 let Inst{25-16} = target{20-11};
3710 let Inst{10-0} = target{10-0};
3711 let DecoderMethod = "DecodeT2BInstruction";
3712 let AsmMatchConverter = "cvtThumbBranches";
3715 let Size = 4, isNotDuplicable = 1, isBranch = 1, isTerminator = 1,
3716 isBarrier = 1, isIndirectBranch = 1 in {
3718 // available in both v8-M.Baseline and Thumb2 targets
3719 def t2BR_JT : t2basePseudoInst<(outs),
3720 (ins GPR:$target, GPR:$index, i32imm:$jt),
3722 [(ARMbr2jt GPR:$target, GPR:$index, tjumptable:$jt)]>,
3725 // FIXME: Add a case that can be predicated.
3726 def t2TBB_JT : t2PseudoInst<(outs),
3727 (ins GPR:$base, GPR:$index, i32imm:$jt, i32imm:$pclbl), 0, IIC_Br, []>,
3730 def t2TBH_JT : t2PseudoInst<(outs),
3731 (ins GPR:$base, GPR:$index, i32imm:$jt, i32imm:$pclbl), 0, IIC_Br, []>,
3734 def t2TBB : T2I<(outs), (ins addrmode_tbb:$addr), IIC_Br,
3735 "tbb", "\t$addr", []>, Sched<[WriteBrTbl]> {
3738 let Inst{31-20} = 0b111010001101;
3739 let Inst{19-16} = Rn;
3740 let Inst{15-5} = 0b11110000000;
3741 let Inst{4} = 0; // B form
3744 let DecoderMethod = "DecodeThumbTableBranch";
3747 def t2TBH : T2I<(outs), (ins addrmode_tbh:$addr), IIC_Br,
3748 "tbh", "\t$addr", []>, Sched<[WriteBrTbl]> {
3751 let Inst{31-20} = 0b111010001101;
3752 let Inst{19-16} = Rn;
3753 let Inst{15-5} = 0b11110000000;
3754 let Inst{4} = 1; // H form
3757 let DecoderMethod = "DecodeThumbTableBranch";
3759 } // isNotDuplicable, isIndirectBranch
3761 } // isBranch, isTerminator, isBarrier
3763 // FIXME: should be able to write a pattern for ARMBrcond, but can't use
3764 // a two-value operand where a dag node expects ", "two operands. :(
3765 let isBranch = 1, isTerminator = 1 in
3766 def t2Bcc : T2I<(outs), (ins brtarget:$target), IIC_Br,
3768 [/*(ARMbrcond bb:$target, imm:$cc)*/]>, Sched<[WriteBr]> {
3769 let Inst{31-27} = 0b11110;
3770 let Inst{15-14} = 0b10;
3774 let Inst{25-22} = p;
3777 let Inst{26} = target{20};
3778 let Inst{11} = target{19};
3779 let Inst{13} = target{18};
3780 let Inst{21-16} = target{17-12};
3781 let Inst{10-0} = target{11-1};
3783 let DecoderMethod = "DecodeThumb2BCCInstruction";
3784 let AsmMatchConverter = "cvtThumbBranches";
3787 // Tail calls. The MachO version of thumb tail calls uses a t2 branch, so
3789 let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1 in {
3792 def tTAILJMPd: tPseudoExpand<(outs),
3793 (ins thumb_br_target:$dst, pred:$p),
3795 (t2B thumb_br_target:$dst, pred:$p)>,
3796 Requires<[IsThumb2, IsMachO]>, Sched<[WriteBr]>;
3800 let Defs = [ITSTATE] in
3801 def t2IT : Thumb2XI<(outs), (ins it_pred:$cc, it_mask:$mask),
3802 AddrModeNone, 2, IIC_iALUx,
3803 "it$mask\t$cc", "", []>,
3804 ComplexDeprecationPredicate<"IT"> {
3805 // 16-bit instruction.
3806 let Inst{31-16} = 0x0000;
3807 let Inst{15-8} = 0b10111111;
3812 let Inst{3-0} = mask;
3814 let DecoderMethod = "DecodeIT";
3817 // Branch and Exchange Jazelle -- for disassembly only
3819 let isBranch = 1, isTerminator = 1, isBarrier = 1, isIndirectBranch = 1 in
3820 def t2BXJ : T2I<(outs), (ins GPRnopc:$func), NoItinerary, "bxj", "\t$func", []>,
3821 Sched<[WriteBr]>, Requires<[IsThumb2, IsNotMClass]> {
3823 let Inst{31-27} = 0b11110;
3825 let Inst{25-20} = 0b111100;
3826 let Inst{19-16} = func;
3827 let Inst{15-0} = 0b1000111100000000;
3830 // Compare and branch on zero / non-zero
3831 let isBranch = 1, isTerminator = 1 in {
3832 def tCBZ : T1I<(outs), (ins tGPR:$Rn, thumb_cb_target:$target), IIC_Br,
3833 "cbz\t$Rn, $target", []>,
3834 T1Misc<{0,0,?,1,?,?,?}>,
3835 Requires<[IsThumb, HasV8MBaseline]>, Sched<[WriteBr]> {
3839 let Inst{9} = target{5};
3840 let Inst{7-3} = target{4-0};
3844 def tCBNZ : T1I<(outs), (ins tGPR:$Rn, thumb_cb_target:$target), IIC_Br,
3845 "cbnz\t$Rn, $target", []>,
3846 T1Misc<{1,0,?,1,?,?,?}>,
3847 Requires<[IsThumb, HasV8MBaseline]>, Sched<[WriteBr]> {
3851 let Inst{9} = target{5};
3852 let Inst{7-3} = target{4-0};
3858 // Change Processor State is a system instruction.
3859 // FIXME: Since the asm parser has currently no clean way to handle optional
3860 // operands, create 3 versions of the same instruction. Once there's a clean
3861 // framework to represent optional operands, change this behavior.
3862 class t2CPS<dag iops, string asm_op> : T2XI<(outs), iops, NoItinerary,
3863 !strconcat("cps", asm_op), []>,
3864 Requires<[IsThumb2, IsNotMClass]> {
3870 let Inst{31-11} = 0b111100111010111110000;
3871 let Inst{10-9} = imod;
3873 let Inst{7-5} = iflags;
3874 let Inst{4-0} = mode;
3875 let DecoderMethod = "DecodeT2CPSInstruction";
3879 def t2CPS3p : t2CPS<(ins imod_op:$imod, iflags_op:$iflags, i32imm:$mode),
3880 "$imod\t$iflags, $mode">;
3881 let mode = 0, M = 0 in
3882 def t2CPS2p : t2CPS<(ins imod_op:$imod, iflags_op:$iflags),
3883 "$imod.w\t$iflags">;
3884 let imod = 0, iflags = 0, M = 1 in
3885 def t2CPS1p : t2CPS<(ins imm0_31:$mode), "\t$mode">;
3887 def : t2InstAlias<"cps$imod.w $iflags, $mode",
3888 (t2CPS3p imod_op:$imod, iflags_op:$iflags, i32imm:$mode), 0>;
3889 def : t2InstAlias<"cps.w $mode", (t2CPS1p imm0_31:$mode), 0>;
3891 // A6.3.4 Branches and miscellaneous control
3892 // Table A6-14 Change Processor State, and hint instructions
3893 def t2HINT : T2I<(outs), (ins imm0_239:$imm), NoItinerary, "hint", ".w\t$imm",
3894 [(int_arm_hint imm0_239:$imm)]> {
3896 let Inst{31-3} = 0b11110011101011111000000000000;
3897 let Inst{7-0} = imm;
3900 def : t2InstAlias<"hint$p $imm", (t2HINT imm0_239:$imm, pred:$p), 0>;
3901 def : t2InstAlias<"nop$p.w", (t2HINT 0, pred:$p), 1>;
3902 def : t2InstAlias<"yield$p.w", (t2HINT 1, pred:$p), 1>;
3903 def : t2InstAlias<"wfe$p.w", (t2HINT 2, pred:$p), 1>;
3904 def : t2InstAlias<"wfi$p.w", (t2HINT 3, pred:$p), 1>;
3905 def : t2InstAlias<"sev$p.w", (t2HINT 4, pred:$p), 1>;
3906 def : t2InstAlias<"sevl$p.w", (t2HINT 5, pred:$p), 1> {
3907 let Predicates = [IsThumb2, HasV8];
3909 def : t2InstAlias<"esb$p.w", (t2HINT 16, pred:$p), 1> {
3910 let Predicates = [IsThumb2, HasRAS];
3912 def : t2InstAlias<"esb$p", (t2HINT 16, pred:$p), 0> {
3913 let Predicates = [IsThumb2, HasRAS];
3915 def : t2InstAlias<"csdb$p.w", (t2HINT 20, pred:$p), 0>;
3916 def : t2InstAlias<"csdb$p", (t2HINT 20, pred:$p), 1>;
3918 def t2DBG : T2I<(outs), (ins imm0_15:$opt), NoItinerary, "dbg", "\t$opt",
3919 [(int_arm_dbg imm0_15:$opt)]> {
3921 let Inst{31-20} = 0b111100111010;
3922 let Inst{19-16} = 0b1111;
3923 let Inst{15-8} = 0b10000000;
3924 let Inst{7-4} = 0b1111;
3925 let Inst{3-0} = opt;
3928 // Secure Monitor Call is a system instruction.
3929 // Option = Inst{19-16}
3930 let isCall = 1, Uses = [SP] in
3931 def t2SMC : T2I<(outs), (ins imm0_15:$opt), NoItinerary, "smc", "\t$opt",
3932 []>, Requires<[IsThumb2, HasTrustZone]> {
3933 let Inst{31-27} = 0b11110;
3934 let Inst{26-20} = 0b1111111;
3935 let Inst{15-12} = 0b1000;
3938 let Inst{19-16} = opt;
3941 class T2DCPS<bits<2> opt, string opc>
3942 : T2I<(outs), (ins), NoItinerary, opc, "", []>, Requires<[IsThumb2, HasV8]> {
3943 let Inst{31-27} = 0b11110;
3944 let Inst{26-20} = 0b1111000;
3945 let Inst{19-16} = 0b1111;
3946 let Inst{15-12} = 0b1000;
3947 let Inst{11-2} = 0b0000000000;
3948 let Inst{1-0} = opt;
3951 def t2DCPS1 : T2DCPS<0b01, "dcps1">;
3952 def t2DCPS2 : T2DCPS<0b10, "dcps2">;
3953 def t2DCPS3 : T2DCPS<0b11, "dcps3">;
3955 class T2SRS<bits<2> Op, bit W, dag oops, dag iops, InstrItinClass itin,
3956 string opc, string asm, list<dag> pattern>
3957 : T2I<oops, iops, itin, opc, asm, pattern>,
3958 Requires<[IsThumb2,IsNotMClass]> {
3960 let Inst{31-25} = 0b1110100;
3961 let Inst{24-23} = Op;
3964 let Inst{20-16} = 0b01101;
3965 let Inst{15-5} = 0b11000000000;
3966 let Inst{4-0} = mode{4-0};
3969 // Store Return State is a system instruction.
3970 def t2SRSDB_UPD : T2SRS<0b00, 1, (outs), (ins imm0_31:$mode), NoItinerary,
3971 "srsdb", "\tsp!, $mode", []>;
3972 def t2SRSDB : T2SRS<0b00, 0, (outs), (ins imm0_31:$mode), NoItinerary,
3973 "srsdb","\tsp, $mode", []>;
3974 def t2SRSIA_UPD : T2SRS<0b11, 1, (outs), (ins imm0_31:$mode), NoItinerary,
3975 "srsia","\tsp!, $mode", []>;
3976 def t2SRSIA : T2SRS<0b11, 0, (outs), (ins imm0_31:$mode), NoItinerary,
3977 "srsia","\tsp, $mode", []>;
3980 def : t2InstAlias<"srsdb${p} $mode", (t2SRSDB imm0_31:$mode, pred:$p)>;
3981 def : t2InstAlias<"srsdb${p} $mode!", (t2SRSDB_UPD imm0_31:$mode, pred:$p)>;
3983 def : t2InstAlias<"srsia${p} $mode", (t2SRSIA imm0_31:$mode, pred:$p)>;
3984 def : t2InstAlias<"srsia${p} $mode!", (t2SRSIA_UPD imm0_31:$mode, pred:$p)>;
3986 // Return From Exception is a system instruction.
3987 let isReturn = 1, isBarrier = 1, isTerminator = 1, Defs = [PC] in
3988 class T2RFE<bits<12> op31_20, dag oops, dag iops, InstrItinClass itin,
3989 string opc, string asm, list<dag> pattern>
3990 : T2I<oops, iops, itin, opc, asm, pattern>,
3991 Requires<[IsThumb2,IsNotMClass]> {
3992 let Inst{31-20} = op31_20{11-0};
3995 let Inst{19-16} = Rn;
3996 let Inst{15-0} = 0xc000;
3999 def t2RFEDBW : T2RFE<0b111010000011,
4000 (outs), (ins GPR:$Rn), NoItinerary, "rfedb", "\t$Rn!",
4001 [/* For disassembly only; pattern left blank */]>;
4002 def t2RFEDB : T2RFE<0b111010000001,
4003 (outs), (ins GPR:$Rn), NoItinerary, "rfedb", "\t$Rn",
4004 [/* For disassembly only; pattern left blank */]>;
4005 def t2RFEIAW : T2RFE<0b111010011011,
4006 (outs), (ins GPR:$Rn), NoItinerary, "rfeia", "\t$Rn!",
4007 [/* For disassembly only; pattern left blank */]>;
4008 def t2RFEIA : T2RFE<0b111010011001,
4009 (outs), (ins GPR:$Rn), NoItinerary, "rfeia", "\t$Rn",
4010 [/* For disassembly only; pattern left blank */]>;
4012 // B9.3.19 SUBS PC, LR, #imm (Thumb2) system instruction.
4013 // Exception return instruction is "subs pc, lr, #imm".
4014 let isReturn = 1, isBarrier = 1, isTerminator = 1, Defs = [PC] in
4015 def t2SUBS_PC_LR : T2I <(outs), (ins imm0_255:$imm), NoItinerary,
4016 "subs", "\tpc, lr, $imm",
4017 [(ARMintretflag imm0_255:$imm)]>,
4018 Requires<[IsThumb2,IsNotMClass]> {
4019 let Inst{31-8} = 0b111100111101111010001111;
4022 let Inst{7-0} = imm;
4025 // Hypervisor Call is a system instruction.
4027 def t2HVC : T2XI <(outs), (ins imm0_65535:$imm16), IIC_Br, "hvc.w\t$imm16", []>,
4028 Requires<[IsThumb2, HasVirtualization]>, Sched<[WriteBr]> {
4030 let Inst{31-20} = 0b111101111110;
4031 let Inst{19-16} = imm16{15-12};
4032 let Inst{15-12} = 0b1000;
4033 let Inst{11-0} = imm16{11-0};
4037 // Alias for HVC without the ".w" optional width specifier
4038 def : t2InstAlias<"hvc\t$imm16", (t2HVC imm0_65535:$imm16)>;
4040 // ERET - Return from exception in Hypervisor mode.
4041 // B9.3.3, B9.3.20: ERET is an alias for "SUBS PC, LR, #0" in an implementation that
4042 // includes virtualization extensions.
4043 def t2ERET : InstAlias<"eret${p}", (t2SUBS_PC_LR 0, pred:$p), 1>,
4044 Requires<[IsThumb2, HasVirtualization]>;
4046 //===----------------------------------------------------------------------===//
4047 // Non-Instruction Patterns
4050 // 32-bit immediate using movw + movt.
4051 // This is a single pseudo instruction to make it re-materializable.
4052 // FIXME: Remove this when we can do generalized remat.
4053 let isReMaterializable = 1, isMoveImm = 1 in
4054 def t2MOVi32imm : PseudoInst<(outs rGPR:$dst), (ins i32imm:$src), IIC_iMOVix2,
4055 [(set rGPR:$dst, (i32 imm:$src))]>,
4056 Requires<[IsThumb, UseMovt]>;
4058 // Pseudo instruction that combines movw + movt + add pc (if pic).
4059 // It also makes it possible to rematerialize the instructions.
4060 // FIXME: Remove this when we can do generalized remat and when machine licm
4061 // can properly the instructions.
4062 let isReMaterializable = 1 in {
4063 def t2MOV_ga_pcrel : PseudoInst<(outs rGPR:$dst), (ins i32imm:$addr),
4065 [(set rGPR:$dst, (ARMWrapperPIC tglobaladdr:$addr))]>,
4066 Requires<[IsThumb, HasV8MBaseline, UseMovtInPic]>;
4070 def : T2Pat<(ARMWrapperPIC tglobaltlsaddr :$dst),
4071 (t2MOV_ga_pcrel tglobaltlsaddr:$dst)>,
4072 Requires<[IsThumb2, UseMovtInPic]>;
4073 def : T2Pat<(ARMWrapper tglobaltlsaddr:$dst),
4074 (t2MOVi32imm tglobaltlsaddr:$dst)>,
4075 Requires<[IsThumb2, UseMovt]>;
4077 // ConstantPool, GlobalAddress, and JumpTable
4078 def : T2Pat<(ARMWrapper tconstpool :$dst), (t2LEApcrel tconstpool :$dst)>;
4079 def : T2Pat<(ARMWrapper texternalsym :$dst), (t2MOVi32imm texternalsym :$dst)>,
4080 Requires<[IsThumb, HasV8MBaseline, UseMovt]>;
4081 def : T2Pat<(ARMWrapper tglobaladdr :$dst), (t2MOVi32imm tglobaladdr :$dst)>,
4082 Requires<[IsThumb, HasV8MBaseline, UseMovt]>;
4084 def : T2Pat<(ARMWrapperJT tjumptable:$dst), (t2LEApcrelJT tjumptable:$dst)>;
4086 // Pseudo instruction that combines ldr from constpool and add pc. This should
4087 // be expanded into two instructions late to allow if-conversion and
4089 let canFoldAsLoad = 1, isReMaterializable = 1 in
4090 def t2LDRpci_pic : PseudoInst<(outs rGPR:$dst), (ins i32imm:$addr, pclabel:$cp),
4092 [(set rGPR:$dst, (ARMpic_add (load (ARMWrapper tconstpool:$addr)),
4094 Requires<[IsThumb2]>;
4096 // Pseudo isntruction that combines movs + predicated rsbmi
4097 // to implement integer ABS
4098 let usesCustomInserter = 1, Defs = [CPSR], hasNoSchedulingInfo = 1 in {
4099 def t2ABS : PseudoInst<(outs rGPR:$dst), (ins rGPR:$src),
4100 NoItinerary, []>, Requires<[IsThumb2]>;
4103 //===----------------------------------------------------------------------===//
4104 // Coprocessor load/store -- for disassembly only
4106 class T2CI<bits<4> op31_28, dag oops, dag iops, string opc, string asm, list<dag> pattern>
4107 : T2I<oops, iops, NoItinerary, opc, asm, pattern> {
4108 let Inst{31-28} = op31_28;
4109 let Inst{27-25} = 0b110;
4112 multiclass t2LdStCop<bits<4> op31_28, bit load, bit Dbit, string asm, list<dag> pattern> {
4113 def _OFFSET : T2CI<op31_28,
4114 (outs), (ins p_imm:$cop, c_imm:$CRd, addrmode5:$addr),
4115 asm, "\t$cop, $CRd, $addr", pattern> {
4119 let Inst{24} = 1; // P = 1
4120 let Inst{23} = addr{8};
4121 let Inst{22} = Dbit;
4122 let Inst{21} = 0; // W = 0
4123 let Inst{20} = load;
4124 let Inst{19-16} = addr{12-9};
4125 let Inst{15-12} = CRd;
4126 let Inst{11-8} = cop;
4127 let Inst{7-0} = addr{7-0};
4128 let DecoderMethod = "DecodeCopMemInstruction";
4130 def _PRE : T2CI<op31_28,
4131 (outs), (ins p_imm:$cop, c_imm:$CRd, addrmode5_pre:$addr),
4132 asm, "\t$cop, $CRd, $addr!", []> {
4136 let Inst{24} = 1; // P = 1
4137 let Inst{23} = addr{8};
4138 let Inst{22} = Dbit;
4139 let Inst{21} = 1; // W = 1
4140 let Inst{20} = load;
4141 let Inst{19-16} = addr{12-9};
4142 let Inst{15-12} = CRd;
4143 let Inst{11-8} = cop;
4144 let Inst{7-0} = addr{7-0};
4145 let DecoderMethod = "DecodeCopMemInstruction";
4147 def _POST: T2CI<op31_28,
4148 (outs), (ins p_imm:$cop, c_imm:$CRd, addr_offset_none:$addr,
4149 postidx_imm8s4:$offset),
4150 asm, "\t$cop, $CRd, $addr, $offset", []> {
4155 let Inst{24} = 0; // P = 0
4156 let Inst{23} = offset{8};
4157 let Inst{22} = Dbit;
4158 let Inst{21} = 1; // W = 1
4159 let Inst{20} = load;
4160 let Inst{19-16} = addr;
4161 let Inst{15-12} = CRd;
4162 let Inst{11-8} = cop;
4163 let Inst{7-0} = offset{7-0};
4164 let DecoderMethod = "DecodeCopMemInstruction";
4166 def _OPTION : T2CI<op31_28, (outs),
4167 (ins p_imm:$cop, c_imm:$CRd, addr_offset_none:$addr,
4168 coproc_option_imm:$option),
4169 asm, "\t$cop, $CRd, $addr, $option", []> {
4174 let Inst{24} = 0; // P = 0
4175 let Inst{23} = 1; // U = 1
4176 let Inst{22} = Dbit;
4177 let Inst{21} = 0; // W = 0
4178 let Inst{20} = load;
4179 let Inst{19-16} = addr;
4180 let Inst{15-12} = CRd;
4181 let Inst{11-8} = cop;
4182 let Inst{7-0} = option;
4183 let DecoderMethod = "DecodeCopMemInstruction";
4187 let DecoderNamespace = "Thumb2CoProc" in {
4188 defm t2LDC : t2LdStCop<0b1110, 1, 0, "ldc", [(int_arm_ldc timm:$cop, timm:$CRd, addrmode5:$addr)]>;
4189 defm t2LDCL : t2LdStCop<0b1110, 1, 1, "ldcl", [(int_arm_ldcl timm:$cop, timm:$CRd, addrmode5:$addr)]>;
4190 defm t2LDC2 : t2LdStCop<0b1111, 1, 0, "ldc2", [(int_arm_ldc2 timm:$cop, timm:$CRd, addrmode5:$addr)]>, Requires<[PreV8,IsThumb2]>;
4191 defm t2LDC2L : t2LdStCop<0b1111, 1, 1, "ldc2l", [(int_arm_ldc2l timm:$cop, timm:$CRd, addrmode5:$addr)]>, Requires<[PreV8,IsThumb2]>;
4193 defm t2STC : t2LdStCop<0b1110, 0, 0, "stc", [(int_arm_stc timm:$cop, timm:$CRd, addrmode5:$addr)]>;
4194 defm t2STCL : t2LdStCop<0b1110, 0, 1, "stcl", [(int_arm_stcl timm:$cop, timm:$CRd, addrmode5:$addr)]>;
4195 defm t2STC2 : t2LdStCop<0b1111, 0, 0, "stc2", [(int_arm_stc2 timm:$cop, timm:$CRd, addrmode5:$addr)]>, Requires<[PreV8,IsThumb2]>;
4196 defm t2STC2L : t2LdStCop<0b1111, 0, 1, "stc2l", [(int_arm_stc2l timm:$cop, timm:$CRd, addrmode5:$addr)]>, Requires<[PreV8,IsThumb2]>;
4200 //===----------------------------------------------------------------------===//
4201 // Move between special register and ARM core register -- for disassembly only
4203 // Move to ARM core register from Special Register
4207 // A/R class can only move from CPSR or SPSR.
4208 def t2MRS_AR : T2I<(outs GPR:$Rd), (ins), NoItinerary, "mrs", "\t$Rd, apsr",
4209 []>, Requires<[IsThumb2,IsNotMClass]> {
4211 let Inst{31-12} = 0b11110011111011111000;
4212 let Inst{11-8} = Rd;
4213 let Inst{7-0} = 0b00000000;
4216 def : t2InstAlias<"mrs${p} $Rd, cpsr", (t2MRS_AR GPR:$Rd, pred:$p)>;
4218 def t2MRSsys_AR: T2I<(outs GPR:$Rd), (ins), NoItinerary, "mrs", "\t$Rd, spsr",
4219 []>, Requires<[IsThumb2,IsNotMClass]> {
4221 let Inst{31-12} = 0b11110011111111111000;
4222 let Inst{11-8} = Rd;
4223 let Inst{7-0} = 0b00000000;
4226 def t2MRSbanked : T2I<(outs rGPR:$Rd), (ins banked_reg:$banked),
4227 NoItinerary, "mrs", "\t$Rd, $banked", []>,
4228 Requires<[IsThumb, HasVirtualization]> {
4232 let Inst{31-21} = 0b11110011111;
4233 let Inst{20} = banked{5}; // R bit
4234 let Inst{19-16} = banked{3-0};
4235 let Inst{15-12} = 0b1000;
4236 let Inst{11-8} = Rd;
4237 let Inst{7-5} = 0b001;
4238 let Inst{4} = banked{4};
4239 let Inst{3-0} = 0b0000;
4245 // This MRS has a mask field in bits 7-0 and can take more values than
4246 // the A/R class (a full msr_mask).
4247 def t2MRS_M : T2I<(outs rGPR:$Rd), (ins msr_mask:$SYSm), NoItinerary,
4248 "mrs", "\t$Rd, $SYSm", []>,
4249 Requires<[IsThumb,IsMClass]> {
4252 let Inst{31-12} = 0b11110011111011111000;
4253 let Inst{11-8} = Rd;
4254 let Inst{7-0} = SYSm;
4256 let Unpredictable{20-16} = 0b11111;
4257 let Unpredictable{13} = 0b1;
4261 // Move from ARM core register to Special Register
4265 // No need to have both system and application versions, the encodings are the
4266 // same and the assembly parser has no way to distinguish between them. The mask
4267 // operand contains the special register (R Bit) in bit 4 and bits 3-0 contains
4268 // the mask with the fields to be accessed in the special register.
4269 let Defs = [CPSR] in
4270 def t2MSR_AR : T2I<(outs), (ins msr_mask:$mask, rGPR:$Rn),
4271 NoItinerary, "msr", "\t$mask, $Rn", []>,
4272 Requires<[IsThumb2,IsNotMClass]> {
4275 let Inst{31-21} = 0b11110011100;
4276 let Inst{20} = mask{4}; // R Bit
4277 let Inst{19-16} = Rn;
4278 let Inst{15-12} = 0b1000;
4279 let Inst{11-8} = mask{3-0};
4283 // However, the MSR (banked register) system instruction (ARMv7VE) *does* have a
4284 // separate encoding (distinguished by bit 5.
4285 def t2MSRbanked : T2I<(outs), (ins banked_reg:$banked, rGPR:$Rn),
4286 NoItinerary, "msr", "\t$banked, $Rn", []>,
4287 Requires<[IsThumb, HasVirtualization]> {
4291 let Inst{31-21} = 0b11110011100;
4292 let Inst{20} = banked{5}; // R bit
4293 let Inst{19-16} = Rn;
4294 let Inst{15-12} = 0b1000;
4295 let Inst{11-8} = banked{3-0};
4296 let Inst{7-5} = 0b001;
4297 let Inst{4} = banked{4};
4298 let Inst{3-0} = 0b0000;
4304 // Move from ARM core register to Special Register
4305 let Defs = [CPSR] in
4306 def t2MSR_M : T2I<(outs), (ins msr_mask:$SYSm, rGPR:$Rn),
4307 NoItinerary, "msr", "\t$SYSm, $Rn", []>,
4308 Requires<[IsThumb,IsMClass]> {
4311 let Inst{31-21} = 0b11110011100;
4313 let Inst{19-16} = Rn;
4314 let Inst{15-12} = 0b1000;
4315 let Inst{11-10} = SYSm{11-10};
4316 let Inst{9-8} = 0b00;
4317 let Inst{7-0} = SYSm{7-0};
4319 let Unpredictable{20} = 0b1;
4320 let Unpredictable{13} = 0b1;
4321 let Unpredictable{9-8} = 0b11;
4325 //===----------------------------------------------------------------------===//
4326 // Move between coprocessor and ARM core register
4329 class t2MovRCopro<bits<4> Op, string opc, bit direction, dag oops, dag iops,
4331 : T2Cop<Op, oops, iops, opc, "\t$cop, $opc1, $Rt, $CRn, $CRm, $opc2",
4333 let Inst{27-24} = 0b1110;
4334 let Inst{20} = direction;
4344 let Inst{15-12} = Rt;
4345 let Inst{11-8} = cop;
4346 let Inst{23-21} = opc1;
4347 let Inst{7-5} = opc2;
4348 let Inst{3-0} = CRm;
4349 let Inst{19-16} = CRn;
4351 let DecoderNamespace = "Thumb2CoProc";
4354 class t2MovRRCopro<bits<4> Op, string opc, bit direction, dag oops, dag iops,
4355 list<dag> pattern = []>
4356 : T2Cop<Op, oops, iops, opc, "\t$cop, $opc1, $Rt, $Rt2, $CRm", pattern> {
4357 let Inst{27-24} = 0b1100;
4358 let Inst{23-21} = 0b010;
4359 let Inst{20} = direction;
4367 let Inst{15-12} = Rt;
4368 let Inst{19-16} = Rt2;
4369 let Inst{11-8} = cop;
4370 let Inst{7-4} = opc1;
4371 let Inst{3-0} = CRm;
4373 let DecoderNamespace = "Thumb2CoProc";
4376 /* from ARM core register to coprocessor */
4377 def t2MCR : t2MovRCopro<0b1110, "mcr", 0,
4379 (ins p_imm:$cop, imm0_7:$opc1, GPR:$Rt, c_imm:$CRn,
4380 c_imm:$CRm, imm0_7:$opc2),
4381 [(int_arm_mcr timm:$cop, timm:$opc1, GPR:$Rt, timm:$CRn,
4382 timm:$CRm, timm:$opc2)]>,
4383 ComplexDeprecationPredicate<"MCR">;
4384 def : t2InstAlias<"mcr${p} $cop, $opc1, $Rt, $CRn, $CRm",
4385 (t2MCR p_imm:$cop, imm0_7:$opc1, GPR:$Rt, c_imm:$CRn,
4386 c_imm:$CRm, 0, pred:$p)>;
4387 def t2MCR2 : t2MovRCopro<0b1111, "mcr2", 0,
4388 (outs), (ins p_imm:$cop, imm0_7:$opc1, GPR:$Rt, c_imm:$CRn,
4389 c_imm:$CRm, imm0_7:$opc2),
4390 [(int_arm_mcr2 timm:$cop, timm:$opc1, GPR:$Rt, timm:$CRn,
4391 timm:$CRm, timm:$opc2)]> {
4392 let Predicates = [IsThumb2, PreV8];
4394 def : t2InstAlias<"mcr2${p} $cop, $opc1, $Rt, $CRn, $CRm",
4395 (t2MCR2 p_imm:$cop, imm0_7:$opc1, GPR:$Rt, c_imm:$CRn,
4396 c_imm:$CRm, 0, pred:$p)>;
4398 /* from coprocessor to ARM core register */
4399 def t2MRC : t2MovRCopro<0b1110, "mrc", 1,
4400 (outs GPRwithAPSR:$Rt), (ins p_imm:$cop, imm0_7:$opc1, c_imm:$CRn,
4401 c_imm:$CRm, imm0_7:$opc2), []>;
4402 def : t2InstAlias<"mrc${p} $cop, $opc1, $Rt, $CRn, $CRm",
4403 (t2MRC GPRwithAPSR:$Rt, p_imm:$cop, imm0_7:$opc1, c_imm:$CRn,
4404 c_imm:$CRm, 0, pred:$p)>;
4406 def t2MRC2 : t2MovRCopro<0b1111, "mrc2", 1,
4407 (outs GPRwithAPSR:$Rt), (ins p_imm:$cop, imm0_7:$opc1, c_imm:$CRn,
4408 c_imm:$CRm, imm0_7:$opc2), []> {
4409 let Predicates = [IsThumb2, PreV8];
4411 def : t2InstAlias<"mrc2${p} $cop, $opc1, $Rt, $CRn, $CRm",
4412 (t2MRC2 GPRwithAPSR:$Rt, p_imm:$cop, imm0_7:$opc1, c_imm:$CRn,
4413 c_imm:$CRm, 0, pred:$p)>;
4415 def : T2v6Pat<(int_arm_mrc timm:$cop, timm:$opc1, timm:$CRn, timm:$CRm, timm:$opc2),
4416 (t2MRC p_imm:$cop, imm0_7:$opc1, c_imm:$CRn, c_imm:$CRm, imm0_7:$opc2)>;
4418 def : T2v6Pat<(int_arm_mrc2 timm:$cop, timm:$opc1, timm:$CRn, timm:$CRm, timm:$opc2),
4419 (t2MRC2 p_imm:$cop, imm0_7:$opc1, c_imm:$CRn, c_imm:$CRm, imm0_7:$opc2)>;
4422 /* from ARM core register to coprocessor */
4423 def t2MCRR : t2MovRRCopro<0b1110, "mcrr", 0, (outs),
4424 (ins p_imm:$cop, imm0_15:$opc1, GPR:$Rt, GPR:$Rt2,
4426 [(int_arm_mcrr timm:$cop, timm:$opc1, GPR:$Rt, GPR:$Rt2,
4428 def t2MCRR2 : t2MovRRCopro<0b1111, "mcrr2", 0, (outs),
4429 (ins p_imm:$cop, imm0_15:$opc1, GPR:$Rt, GPR:$Rt2,
4431 [(int_arm_mcrr2 timm:$cop, timm:$opc1, GPR:$Rt,
4432 GPR:$Rt2, timm:$CRm)]> {
4433 let Predicates = [IsThumb2, PreV8];
4436 /* from coprocessor to ARM core register */
4437 def t2MRRC : t2MovRRCopro<0b1110, "mrrc", 1, (outs GPR:$Rt, GPR:$Rt2),
4438 (ins p_imm:$cop, imm0_15:$opc1, c_imm:$CRm)>;
4440 def t2MRRC2 : t2MovRRCopro<0b1111, "mrrc2", 1, (outs GPR:$Rt, GPR:$Rt2),
4441 (ins p_imm:$cop, imm0_15:$opc1, c_imm:$CRm)> {
4442 let Predicates = [IsThumb2, PreV8];
4445 //===----------------------------------------------------------------------===//
4446 // Other Coprocessor Instructions.
4449 def t2CDP : T2Cop<0b1110, (outs), (ins p_imm:$cop, imm0_15:$opc1,
4450 c_imm:$CRd, c_imm:$CRn, c_imm:$CRm, imm0_7:$opc2),
4451 "cdp", "\t$cop, $opc1, $CRd, $CRn, $CRm, $opc2",
4452 [(int_arm_cdp timm:$cop, timm:$opc1, timm:$CRd, timm:$CRn,
4453 timm:$CRm, timm:$opc2)]> {
4454 let Inst{27-24} = 0b1110;
4463 let Inst{3-0} = CRm;
4465 let Inst{7-5} = opc2;
4466 let Inst{11-8} = cop;
4467 let Inst{15-12} = CRd;
4468 let Inst{19-16} = CRn;
4469 let Inst{23-20} = opc1;
4471 let Predicates = [IsThumb2, PreV8];
4472 let DecoderNamespace = "Thumb2CoProc";
4475 def t2CDP2 : T2Cop<0b1111, (outs), (ins p_imm:$cop, imm0_15:$opc1,
4476 c_imm:$CRd, c_imm:$CRn, c_imm:$CRm, imm0_7:$opc2),
4477 "cdp2", "\t$cop, $opc1, $CRd, $CRn, $CRm, $opc2",
4478 [(int_arm_cdp2 timm:$cop, timm:$opc1, timm:$CRd, timm:$CRn,
4479 timm:$CRm, timm:$opc2)]> {
4480 let Inst{27-24} = 0b1110;
4489 let Inst{3-0} = CRm;
4491 let Inst{7-5} = opc2;
4492 let Inst{11-8} = cop;
4493 let Inst{15-12} = CRd;
4494 let Inst{19-16} = CRn;
4495 let Inst{23-20} = opc1;
4497 let Predicates = [IsThumb2, PreV8];
4498 let DecoderNamespace = "Thumb2CoProc";
4503 //===----------------------------------------------------------------------===//
4504 // ARMv8.1 Privilege Access Never extension
4508 def t2SETPAN : T1I<(outs), (ins imm0_1:$imm), NoItinerary, "setpan\t$imm", []>,
4509 T1Misc<0b0110000>, Requires<[IsThumb2, HasV8, HasV8_1a]> {
4514 let Inst{2-0} = 0b000;
4516 let Unpredictable{4} = 0b1;
4517 let Unpredictable{2-0} = 0b111;
4520 //===----------------------------------------------------------------------===//
4521 // ARMv8-M Security Extensions instructions
4524 let hasSideEffects = 1 in
4525 def t2SG : T2I<(outs), (ins), NoItinerary, "sg", "", []>,
4526 Requires<[Has8MSecExt]> {
4527 let Inst = 0xe97fe97f;
4530 class T2TT<bits<2> at, string asm, list<dag> pattern>
4531 : T2I<(outs rGPR:$Rt), (ins GPRnopc:$Rn), NoItinerary, asm, "\t$Rt, $Rn",
4536 let Inst{31-20} = 0b111010000100;
4537 let Inst{19-16} = Rn;
4538 let Inst{15-12} = 0b1111;
4539 let Inst{11-8} = Rt;
4541 let Inst{5-0} = 0b000000;
4543 let Unpredictable{5-0} = 0b111111;
4546 def t2TT : T2TT<0b00, "tt", []>, Requires<[IsThumb,Has8MSecExt]>;
4547 def t2TTT : T2TT<0b01, "ttt", []>, Requires<[IsThumb,Has8MSecExt]>;
4548 def t2TTA : T2TT<0b10, "tta", []>, Requires<[IsThumb,Has8MSecExt]>;
4549 def t2TTAT : T2TT<0b11, "ttat", []>, Requires<[IsThumb,Has8MSecExt]>;
4551 //===----------------------------------------------------------------------===//
4552 // Non-Instruction Patterns
4555 // SXT/UXT with no rotate
4556 let AddedComplexity = 16 in {
4557 def : T2Pat<(and rGPR:$Rm, 0x000000FF), (t2UXTB rGPR:$Rm, 0)>,
4558 Requires<[IsThumb2]>;
4559 def : T2Pat<(and rGPR:$Rm, 0x0000FFFF), (t2UXTH rGPR:$Rm, 0)>,
4560 Requires<[IsThumb2]>;
4561 def : T2Pat<(and rGPR:$Rm, 0x00FF00FF), (t2UXTB16 rGPR:$Rm, 0)>,
4562 Requires<[HasDSP, IsThumb2]>;
4563 def : T2Pat<(add rGPR:$Rn, (and rGPR:$Rm, 0x00FF)),
4564 (t2UXTAB rGPR:$Rn, rGPR:$Rm, 0)>,
4565 Requires<[HasDSP, IsThumb2]>;
4566 def : T2Pat<(add rGPR:$Rn, (and rGPR:$Rm, 0xFFFF)),
4567 (t2UXTAH rGPR:$Rn, rGPR:$Rm, 0)>,
4568 Requires<[HasDSP, IsThumb2]>;
4571 def : T2Pat<(sext_inreg rGPR:$Src, i8), (t2SXTB rGPR:$Src, 0)>,
4572 Requires<[IsThumb2]>;
4573 def : T2Pat<(sext_inreg rGPR:$Src, i16), (t2SXTH rGPR:$Src, 0)>,
4574 Requires<[IsThumb2]>;
4575 def : T2Pat<(add rGPR:$Rn, (sext_inreg rGPR:$Rm, i8)),
4576 (t2SXTAB rGPR:$Rn, rGPR:$Rm, 0)>,
4577 Requires<[HasDSP, IsThumb2]>;
4578 def : T2Pat<(add rGPR:$Rn, (sext_inreg rGPR:$Rm, i16)),
4579 (t2SXTAH rGPR:$Rn, rGPR:$Rm, 0)>,
4580 Requires<[HasDSP, IsThumb2]>;
4582 // Atomic load/store patterns
4583 def : T2Pat<(atomic_load_8 t2addrmode_imm12:$addr),
4584 (t2LDRBi12 t2addrmode_imm12:$addr)>;
4585 def : T2Pat<(atomic_load_8 t2addrmode_negimm8:$addr),
4586 (t2LDRBi8 t2addrmode_negimm8:$addr)>;
4587 def : T2Pat<(atomic_load_8 t2addrmode_so_reg:$addr),
4588 (t2LDRBs t2addrmode_so_reg:$addr)>;
4589 def : T2Pat<(atomic_load_16 t2addrmode_imm12:$addr),
4590 (t2LDRHi12 t2addrmode_imm12:$addr)>;
4591 def : T2Pat<(atomic_load_16 t2addrmode_negimm8:$addr),
4592 (t2LDRHi8 t2addrmode_negimm8:$addr)>;
4593 def : T2Pat<(atomic_load_16 t2addrmode_so_reg:$addr),
4594 (t2LDRHs t2addrmode_so_reg:$addr)>;
4595 def : T2Pat<(atomic_load_32 t2addrmode_imm12:$addr),
4596 (t2LDRi12 t2addrmode_imm12:$addr)>;
4597 def : T2Pat<(atomic_load_32 t2addrmode_negimm8:$addr),
4598 (t2LDRi8 t2addrmode_negimm8:$addr)>;
4599 def : T2Pat<(atomic_load_32 t2addrmode_so_reg:$addr),
4600 (t2LDRs t2addrmode_so_reg:$addr)>;
4601 def : T2Pat<(atomic_store_8 t2addrmode_imm12:$addr, GPR:$val),
4602 (t2STRBi12 GPR:$val, t2addrmode_imm12:$addr)>;
4603 def : T2Pat<(atomic_store_8 t2addrmode_negimm8:$addr, GPR:$val),
4604 (t2STRBi8 GPR:$val, t2addrmode_negimm8:$addr)>;
4605 def : T2Pat<(atomic_store_8 t2addrmode_so_reg:$addr, GPR:$val),
4606 (t2STRBs GPR:$val, t2addrmode_so_reg:$addr)>;
4607 def : T2Pat<(atomic_store_16 t2addrmode_imm12:$addr, GPR:$val),
4608 (t2STRHi12 GPR:$val, t2addrmode_imm12:$addr)>;
4609 def : T2Pat<(atomic_store_16 t2addrmode_negimm8:$addr, GPR:$val),
4610 (t2STRHi8 GPR:$val, t2addrmode_negimm8:$addr)>;
4611 def : T2Pat<(atomic_store_16 t2addrmode_so_reg:$addr, GPR:$val),
4612 (t2STRHs GPR:$val, t2addrmode_so_reg:$addr)>;
4613 def : T2Pat<(atomic_store_32 t2addrmode_imm12:$addr, GPR:$val),
4614 (t2STRi12 GPR:$val, t2addrmode_imm12:$addr)>;
4615 def : T2Pat<(atomic_store_32 t2addrmode_negimm8:$addr, GPR:$val),
4616 (t2STRi8 GPR:$val, t2addrmode_negimm8:$addr)>;
4617 def : T2Pat<(atomic_store_32 t2addrmode_so_reg:$addr, GPR:$val),
4618 (t2STRs GPR:$val, t2addrmode_so_reg:$addr)>;
4620 let AddedComplexity = 8, Predicates = [IsThumb, HasAcquireRelease, HasV7Clrex] in {
4621 def : Pat<(atomic_load_acquire_8 addr_offset_none:$addr), (t2LDAB addr_offset_none:$addr)>;
4622 def : Pat<(atomic_load_acquire_16 addr_offset_none:$addr), (t2LDAH addr_offset_none:$addr)>;
4623 def : Pat<(atomic_load_acquire_32 addr_offset_none:$addr), (t2LDA addr_offset_none:$addr)>;
4624 def : Pat<(atomic_store_release_8 addr_offset_none:$addr, GPR:$val), (t2STLB GPR:$val, addr_offset_none:$addr)>;
4625 def : Pat<(atomic_store_release_16 addr_offset_none:$addr, GPR:$val), (t2STLH GPR:$val, addr_offset_none:$addr)>;
4626 def : Pat<(atomic_store_release_32 addr_offset_none:$addr, GPR:$val), (t2STL GPR:$val, addr_offset_none:$addr)>;
4630 //===----------------------------------------------------------------------===//
4631 // Assembler aliases
4634 // Aliases for ADC without the ".w" optional width specifier.
4635 def : t2InstAlias<"adc${s}${p} $Rd, $Rn, $Rm",
4636 (t2ADCrr rGPR:$Rd, rGPR:$Rn, rGPR:$Rm, pred:$p, cc_out:$s)>;
4637 def : t2InstAlias<"adc${s}${p} $Rd, $Rn, $ShiftedRm",
4638 (t2ADCrs rGPR:$Rd, rGPR:$Rn, t2_so_reg:$ShiftedRm,
4639 pred:$p, cc_out:$s)>;
4641 // Aliases for SBC without the ".w" optional width specifier.
4642 def : t2InstAlias<"sbc${s}${p} $Rd, $Rn, $Rm",
4643 (t2SBCrr rGPR:$Rd, rGPR:$Rn, rGPR:$Rm, pred:$p, cc_out:$s)>;
4644 def : t2InstAlias<"sbc${s}${p} $Rd, $Rn, $ShiftedRm",
4645 (t2SBCrs rGPR:$Rd, rGPR:$Rn, t2_so_reg:$ShiftedRm,
4646 pred:$p, cc_out:$s)>;
4648 // Aliases for ADD without the ".w" optional width specifier.
4649 def : t2InstAlias<"add${s}${p} $Rd, $Rn, $imm",
4650 (t2ADDri GPRnopc:$Rd, GPRnopc:$Rn, t2_so_imm:$imm, pred:$p,
4652 def : t2InstAlias<"add${p} $Rd, $Rn, $imm",
4653 (t2ADDri12 GPRnopc:$Rd, GPR:$Rn, imm0_4095:$imm, pred:$p)>;
4654 def : t2InstAlias<"add${s}${p} $Rd, $Rn, $Rm",
4655 (t2ADDrr GPRnopc:$Rd, GPRnopc:$Rn, rGPR:$Rm, pred:$p, cc_out:$s)>;
4656 def : t2InstAlias<"add${s}${p} $Rd, $Rn, $ShiftedRm",
4657 (t2ADDrs GPRnopc:$Rd, GPRnopc:$Rn, t2_so_reg:$ShiftedRm,
4658 pred:$p, cc_out:$s)>;
4659 // ... and with the destination and source register combined.
4660 def : t2InstAlias<"add${s}${p} $Rdn, $imm",
4661 (t2ADDri GPRnopc:$Rdn, GPRnopc:$Rdn, t2_so_imm:$imm, pred:$p, cc_out:$s)>;
4662 def : t2InstAlias<"add${p} $Rdn, $imm",
4663 (t2ADDri12 GPRnopc:$Rdn, GPRnopc:$Rdn, imm0_4095:$imm, pred:$p)>;
4664 def : t2InstAlias<"add${s}${p} $Rdn, $Rm",
4665 (t2ADDrr GPRnopc:$Rdn, GPRnopc:$Rdn, rGPR:$Rm, pred:$p, cc_out:$s)>;
4666 def : t2InstAlias<"add${s}${p} $Rdn, $ShiftedRm",
4667 (t2ADDrs GPRnopc:$Rdn, GPRnopc:$Rdn, t2_so_reg:$ShiftedRm,
4668 pred:$p, cc_out:$s)>;
4670 // add w/ negative immediates is just a sub.
4671 def : t2InstSubst<"add${s}${p} $Rd, $Rn, $imm",
4672 (t2SUBri GPRnopc:$Rd, GPRnopc:$Rn, t2_so_imm_neg:$imm, pred:$p,
4674 def : t2InstSubst<"add${p} $Rd, $Rn, $imm",
4675 (t2SUBri12 GPRnopc:$Rd, GPR:$Rn, imm0_4095_neg:$imm, pred:$p)>;
4676 def : t2InstSubst<"add${s}${p} $Rdn, $imm",
4677 (t2SUBri GPRnopc:$Rdn, GPRnopc:$Rdn, t2_so_imm_neg:$imm, pred:$p,
4679 def : t2InstSubst<"add${p} $Rdn, $imm",
4680 (t2SUBri12 GPRnopc:$Rdn, GPRnopc:$Rdn, imm0_4095_neg:$imm, pred:$p)>;
4682 def : t2InstSubst<"add${s}${p}.w $Rd, $Rn, $imm",
4683 (t2SUBri GPRnopc:$Rd, GPRnopc:$Rn, t2_so_imm_neg:$imm, pred:$p,
4685 def : t2InstSubst<"addw${p} $Rd, $Rn, $imm",
4686 (t2SUBri12 GPRnopc:$Rd, GPR:$Rn, imm0_4095_neg:$imm, pred:$p)>;
4687 def : t2InstSubst<"add${s}${p}.w $Rdn, $imm",
4688 (t2SUBri GPRnopc:$Rdn, GPRnopc:$Rdn, t2_so_imm_neg:$imm, pred:$p,
4690 def : t2InstSubst<"addw${p} $Rdn, $imm",
4691 (t2SUBri12 GPRnopc:$Rdn, GPRnopc:$Rdn, imm0_4095_neg:$imm, pred:$p)>;
4694 // Aliases for SUB without the ".w" optional width specifier.
4695 def : t2InstAlias<"sub${s}${p} $Rd, $Rn, $imm",
4696 (t2SUBri GPRnopc:$Rd, GPRnopc:$Rn, t2_so_imm:$imm, pred:$p, cc_out:$s)>;
4697 def : t2InstAlias<"sub${p} $Rd, $Rn, $imm",
4698 (t2SUBri12 GPRnopc:$Rd, GPR:$Rn, imm0_4095:$imm, pred:$p)>;
4699 def : t2InstAlias<"sub${s}${p} $Rd, $Rn, $Rm",
4700 (t2SUBrr GPRnopc:$Rd, GPRnopc:$Rn, rGPR:$Rm, pred:$p, cc_out:$s)>;
4701 def : t2InstAlias<"sub${s}${p} $Rd, $Rn, $ShiftedRm",
4702 (t2SUBrs GPRnopc:$Rd, GPRnopc:$Rn, t2_so_reg:$ShiftedRm,
4703 pred:$p, cc_out:$s)>;
4704 // ... and with the destination and source register combined.
4705 def : t2InstAlias<"sub${s}${p} $Rdn, $imm",
4706 (t2SUBri GPRnopc:$Rdn, GPRnopc:$Rdn, t2_so_imm:$imm, pred:$p, cc_out:$s)>;
4707 def : t2InstAlias<"sub${p} $Rdn, $imm",
4708 (t2SUBri12 GPRnopc:$Rdn, GPRnopc:$Rdn, imm0_4095:$imm, pred:$p)>;
4709 def : t2InstAlias<"sub${s}${p}.w $Rdn, $Rm",
4710 (t2SUBrr GPRnopc:$Rdn, GPRnopc:$Rdn, rGPR:$Rm, pred:$p, cc_out:$s)>;
4711 def : t2InstAlias<"sub${s}${p} $Rdn, $Rm",
4712 (t2SUBrr GPRnopc:$Rdn, GPRnopc:$Rdn, rGPR:$Rm, pred:$p, cc_out:$s)>;
4713 def : t2InstAlias<"sub${s}${p} $Rdn, $ShiftedRm",
4714 (t2SUBrs GPRnopc:$Rdn, GPRnopc:$Rdn, t2_so_reg:$ShiftedRm,
4715 pred:$p, cc_out:$s)>;
4717 // Alias for compares without the ".w" optional width specifier.
4718 def : t2InstAlias<"cmn${p} $Rn, $Rm",
4719 (t2CMNzrr GPRnopc:$Rn, rGPR:$Rm, pred:$p)>;
4720 def : t2InstAlias<"teq${p} $Rn, $Rm",
4721 (t2TEQrr rGPR:$Rn, rGPR:$Rm, pred:$p)>;
4722 def : t2InstAlias<"tst${p} $Rn, $Rm",
4723 (t2TSTrr rGPR:$Rn, rGPR:$Rm, pred:$p)>;
4726 def : InstAlias<"dmb${p}", (t2DMB 0xf, pred:$p), 0>, Requires<[HasDB]>;
4727 def : InstAlias<"dsb${p}", (t2DSB 0xf, pred:$p), 0>, Requires<[HasDB]>;
4728 def : InstAlias<"isb${p}", (t2ISB 0xf, pred:$p), 0>, Requires<[HasDB]>;
4730 // Non-predicable aliases of a predicable DSB: the predicate is (14, 0) where
4731 // 14 = AL (always execute) and 0 = "instruction doesn't read the CPSR".
4732 def : InstAlias<"ssbb", (t2DSB 0x0, 14, 0), 1>, Requires<[HasDB, IsThumb2]>;
4733 def : InstAlias<"pssbb", (t2DSB 0x4, 14, 0), 1>, Requires<[HasDB, IsThumb2]>;
4735 // Armv8-R 'Data Full Barrier'
4736 def : InstAlias<"dfb${p}", (t2DSB 0xc, pred:$p), 1>, Requires<[HasDFB]>;
4738 // Alias for LDR, LDRB, LDRH, LDRSB, and LDRSH without the ".w" optional
4740 def : t2InstAlias<"ldr${p} $Rt, $addr",
4741 (t2LDRi12 GPR:$Rt, t2addrmode_imm12:$addr, pred:$p)>;
4742 def : t2InstAlias<"ldrb${p} $Rt, $addr",
4743 (t2LDRBi12 rGPR:$Rt, t2addrmode_imm12:$addr, pred:$p)>;
4744 def : t2InstAlias<"ldrh${p} $Rt, $addr",
4745 (t2LDRHi12 rGPR:$Rt, t2addrmode_imm12:$addr, pred:$p)>;
4746 def : t2InstAlias<"ldrsb${p} $Rt, $addr",
4747 (t2LDRSBi12 rGPR:$Rt, t2addrmode_imm12:$addr, pred:$p)>;
4748 def : t2InstAlias<"ldrsh${p} $Rt, $addr",
4749 (t2LDRSHi12 rGPR:$Rt, t2addrmode_imm12:$addr, pred:$p)>;
4751 def : t2InstAlias<"ldr${p} $Rt, $addr",
4752 (t2LDRs GPR:$Rt, t2addrmode_so_reg:$addr, pred:$p)>;
4753 def : t2InstAlias<"ldrb${p} $Rt, $addr",
4754 (t2LDRBs rGPR:$Rt, t2addrmode_so_reg:$addr, pred:$p)>;
4755 def : t2InstAlias<"ldrh${p} $Rt, $addr",
4756 (t2LDRHs rGPR:$Rt, t2addrmode_so_reg:$addr, pred:$p)>;
4757 def : t2InstAlias<"ldrsb${p} $Rt, $addr",
4758 (t2LDRSBs rGPR:$Rt, t2addrmode_so_reg:$addr, pred:$p)>;
4759 def : t2InstAlias<"ldrsh${p} $Rt, $addr",
4760 (t2LDRSHs rGPR:$Rt, t2addrmode_so_reg:$addr, pred:$p)>;
4762 def : t2InstAlias<"ldr${p} $Rt, $addr",
4763 (t2LDRpci GPR:$Rt, t2ldrlabel:$addr, pred:$p)>;
4764 def : t2InstAlias<"ldrb${p} $Rt, $addr",
4765 (t2LDRBpci rGPR:$Rt, t2ldrlabel:$addr, pred:$p)>;
4766 def : t2InstAlias<"ldrh${p} $Rt, $addr",
4767 (t2LDRHpci rGPR:$Rt, t2ldrlabel:$addr, pred:$p)>;
4768 def : t2InstAlias<"ldrsb${p} $Rt, $addr",
4769 (t2LDRSBpci rGPR:$Rt, t2ldrlabel:$addr, pred:$p)>;
4770 def : t2InstAlias<"ldrsh${p} $Rt, $addr",
4771 (t2LDRSHpci rGPR:$Rt, t2ldrlabel:$addr, pred:$p)>;
4773 // Alias for MVN with(out) the ".w" optional width specifier.
4774 def : t2InstAlias<"mvn${s}${p}.w $Rd, $imm",
4775 (t2MVNi rGPR:$Rd, t2_so_imm:$imm, pred:$p, cc_out:$s)>;
4776 def : t2InstAlias<"mvn${s}${p} $Rd, $Rm",
4777 (t2MVNr rGPR:$Rd, rGPR:$Rm, pred:$p, cc_out:$s)>;
4778 def : t2InstAlias<"mvn${s}${p} $Rd, $ShiftedRm",
4779 (t2MVNs rGPR:$Rd, t2_so_reg:$ShiftedRm, pred:$p, cc_out:$s)>;
4781 // PKHBT/PKHTB with default shift amount. PKHTB is equivalent to PKHBT with the
4782 // input operands swapped when the shift amount is zero (i.e., unspecified).
4783 def : InstAlias<"pkhbt${p} $Rd, $Rn, $Rm",
4784 (t2PKHBT rGPR:$Rd, rGPR:$Rn, rGPR:$Rm, 0, pred:$p), 0>,
4785 Requires<[HasDSP, IsThumb2]>;
4786 def : InstAlias<"pkhtb${p} $Rd, $Rn, $Rm",
4787 (t2PKHBT rGPR:$Rd, rGPR:$Rm, rGPR:$Rn, 0, pred:$p), 0>,
4788 Requires<[HasDSP, IsThumb2]>;
4790 // PUSH/POP aliases for STM/LDM
4791 def : t2InstAlias<"push${p}.w $regs", (t2STMDB_UPD SP, pred:$p, reglist:$regs)>;
4792 def : t2InstAlias<"push${p} $regs", (t2STMDB_UPD SP, pred:$p, reglist:$regs)>;
4793 def : t2InstAlias<"pop${p}.w $regs", (t2LDMIA_UPD SP, pred:$p, reglist:$regs)>;
4794 def : t2InstAlias<"pop${p} $regs", (t2LDMIA_UPD SP, pred:$p, reglist:$regs)>;
4796 // STMIA/STMIA_UPD aliases w/o the optional .w suffix
4797 def : t2InstAlias<"stm${p} $Rn, $regs",
4798 (t2STMIA GPR:$Rn, pred:$p, reglist:$regs)>;
4799 def : t2InstAlias<"stm${p} $Rn!, $regs",
4800 (t2STMIA_UPD GPR:$Rn, pred:$p, reglist:$regs)>;
4802 // LDMIA/LDMIA_UPD aliases w/o the optional .w suffix
4803 def : t2InstAlias<"ldm${p} $Rn, $regs",
4804 (t2LDMIA GPR:$Rn, pred:$p, reglist:$regs)>;
4805 def : t2InstAlias<"ldm${p} $Rn!, $regs",
4806 (t2LDMIA_UPD GPR:$Rn, pred:$p, reglist:$regs)>;
4808 // STMDB/STMDB_UPD aliases w/ the optional .w suffix
4809 def : t2InstAlias<"stmdb${p}.w $Rn, $regs",
4810 (t2STMDB GPR:$Rn, pred:$p, reglist:$regs)>;
4811 def : t2InstAlias<"stmdb${p}.w $Rn!, $regs",
4812 (t2STMDB_UPD GPR:$Rn, pred:$p, reglist:$regs)>;
4814 // LDMDB/LDMDB_UPD aliases w/ the optional .w suffix
4815 def : t2InstAlias<"ldmdb${p}.w $Rn, $regs",
4816 (t2LDMDB GPR:$Rn, pred:$p, reglist:$regs)>;
4817 def : t2InstAlias<"ldmdb${p}.w $Rn!, $regs",
4818 (t2LDMDB_UPD GPR:$Rn, pred:$p, reglist:$regs)>;
4820 // Alias for REV/REV16/REVSH without the ".w" optional width specifier.
4821 def : t2InstAlias<"rev${p} $Rd, $Rm", (t2REV rGPR:$Rd, rGPR:$Rm, pred:$p)>;
4822 def : t2InstAlias<"rev16${p} $Rd, $Rm", (t2REV16 rGPR:$Rd, rGPR:$Rm, pred:$p)>;
4823 def : t2InstAlias<"revsh${p} $Rd, $Rm", (t2REVSH rGPR:$Rd, rGPR:$Rm, pred:$p)>;
4826 // Alias for RSB without the ".w" optional width specifier, and with optional
4827 // implied destination register.
4828 def : t2InstAlias<"rsb${s}${p} $Rd, $Rn, $imm",
4829 (t2RSBri rGPR:$Rd, rGPR:$Rn, t2_so_imm:$imm, pred:$p, cc_out:$s)>;
4830 def : t2InstAlias<"rsb${s}${p} $Rdn, $imm",
4831 (t2RSBri rGPR:$Rdn, rGPR:$Rdn, t2_so_imm:$imm, pred:$p, cc_out:$s)>;
4832 def : t2InstAlias<"rsb${s}${p} $Rdn, $Rm",
4833 (t2RSBrr rGPR:$Rdn, rGPR:$Rdn, rGPR:$Rm, pred:$p, cc_out:$s)>;
4834 def : t2InstAlias<"rsb${s}${p} $Rdn, $ShiftedRm",
4835 (t2RSBrs rGPR:$Rdn, rGPR:$Rdn, t2_so_reg:$ShiftedRm, pred:$p,
4838 // SSAT/USAT optional shift operand.
4839 def : t2InstAlias<"ssat${p} $Rd, $sat_imm, $Rn",
4840 (t2SSAT rGPR:$Rd, imm1_32:$sat_imm, rGPR:$Rn, 0, pred:$p)>;
4841 def : t2InstAlias<"usat${p} $Rd, $sat_imm, $Rn",
4842 (t2USAT rGPR:$Rd, imm0_31:$sat_imm, rGPR:$Rn, 0, pred:$p)>;
4844 // STM w/o the .w suffix.
4845 def : t2InstAlias<"stm${p} $Rn, $regs",
4846 (t2STMIA GPR:$Rn, pred:$p, reglist:$regs)>;
4848 // Alias for STR, STRB, and STRH without the ".w" optional
4850 def : t2InstAlias<"str${p} $Rt, $addr",
4851 (t2STRi12 GPR:$Rt, t2addrmode_imm12:$addr, pred:$p)>;
4852 def : t2InstAlias<"strb${p} $Rt, $addr",
4853 (t2STRBi12 rGPR:$Rt, t2addrmode_imm12:$addr, pred:$p)>;
4854 def : t2InstAlias<"strh${p} $Rt, $addr",
4855 (t2STRHi12 rGPR:$Rt, t2addrmode_imm12:$addr, pred:$p)>;
4857 def : t2InstAlias<"str${p} $Rt, $addr",
4858 (t2STRs GPR:$Rt, t2addrmode_so_reg:$addr, pred:$p)>;
4859 def : t2InstAlias<"strb${p} $Rt, $addr",
4860 (t2STRBs rGPR:$Rt, t2addrmode_so_reg:$addr, pred:$p)>;
4861 def : t2InstAlias<"strh${p} $Rt, $addr",
4862 (t2STRHs rGPR:$Rt, t2addrmode_so_reg:$addr, pred:$p)>;
4864 // Extend instruction optional rotate operand.
4865 def : InstAlias<"sxtab${p} $Rd, $Rn, $Rm",
4866 (t2SXTAB rGPR:$Rd, rGPR:$Rn, rGPR:$Rm, 0, pred:$p), 0>,
4867 Requires<[HasDSP, IsThumb2]>;
4868 def : InstAlias<"sxtah${p} $Rd, $Rn, $Rm",
4869 (t2SXTAH rGPR:$Rd, rGPR:$Rn, rGPR:$Rm, 0, pred:$p), 0>,
4870 Requires<[HasDSP, IsThumb2]>;
4871 def : InstAlias<"sxtab16${p} $Rd, $Rn, $Rm",
4872 (t2SXTAB16 rGPR:$Rd, rGPR:$Rn, rGPR:$Rm, 0, pred:$p), 0>,
4873 Requires<[HasDSP, IsThumb2]>;
4874 def : InstAlias<"sxtb16${p} $Rd, $Rm",
4875 (t2SXTB16 rGPR:$Rd, rGPR:$Rm, 0, pred:$p), 0>,
4876 Requires<[HasDSP, IsThumb2]>;
4878 def : t2InstAlias<"sxtb${p} $Rd, $Rm",
4879 (t2SXTB rGPR:$Rd, rGPR:$Rm, 0, pred:$p)>;
4880 def : t2InstAlias<"sxth${p} $Rd, $Rm",
4881 (t2SXTH rGPR:$Rd, rGPR:$Rm, 0, pred:$p)>;
4882 def : t2InstAlias<"sxtb${p}.w $Rd, $Rm",
4883 (t2SXTB rGPR:$Rd, rGPR:$Rm, 0, pred:$p)>;
4884 def : t2InstAlias<"sxth${p}.w $Rd, $Rm",
4885 (t2SXTH rGPR:$Rd, rGPR:$Rm, 0, pred:$p)>;
4887 def : InstAlias<"uxtab${p} $Rd, $Rn, $Rm",
4888 (t2UXTAB rGPR:$Rd, rGPR:$Rn, rGPR:$Rm, 0, pred:$p), 0>,
4889 Requires<[HasDSP, IsThumb2]>;
4890 def : InstAlias<"uxtah${p} $Rd, $Rn, $Rm",
4891 (t2UXTAH rGPR:$Rd, rGPR:$Rn, rGPR:$Rm, 0, pred:$p), 0>,
4892 Requires<[HasDSP, IsThumb2]>;
4893 def : InstAlias<"uxtab16${p} $Rd, $Rn, $Rm",
4894 (t2UXTAB16 rGPR:$Rd, rGPR:$Rn, rGPR:$Rm, 0, pred:$p), 0>,
4895 Requires<[HasDSP, IsThumb2]>;
4896 def : InstAlias<"uxtb16${p} $Rd, $Rm",
4897 (t2UXTB16 rGPR:$Rd, rGPR:$Rm, 0, pred:$p), 0>,
4898 Requires<[HasDSP, IsThumb2]>;
4900 def : t2InstAlias<"uxtb${p} $Rd, $Rm",
4901 (t2UXTB rGPR:$Rd, rGPR:$Rm, 0, pred:$p)>;
4902 def : t2InstAlias<"uxth${p} $Rd, $Rm",
4903 (t2UXTH rGPR:$Rd, rGPR:$Rm, 0, pred:$p)>;
4904 def : t2InstAlias<"uxtb${p}.w $Rd, $Rm",
4905 (t2UXTB rGPR:$Rd, rGPR:$Rm, 0, pred:$p)>;
4906 def : t2InstAlias<"uxth${p}.w $Rd, $Rm",
4907 (t2UXTH rGPR:$Rd, rGPR:$Rm, 0, pred:$p)>;
4909 // Extend instruction w/o the ".w" optional width specifier.
4910 def : t2InstAlias<"uxtb${p} $Rd, $Rm$rot",
4911 (t2UXTB rGPR:$Rd, rGPR:$Rm, rot_imm:$rot, pred:$p)>;
4912 def : InstAlias<"uxtb16${p} $Rd, $Rm$rot",
4913 (t2UXTB16 rGPR:$Rd, rGPR:$Rm, rot_imm:$rot, pred:$p), 0>,
4914 Requires<[HasDSP, IsThumb2]>;
4915 def : t2InstAlias<"uxth${p} $Rd, $Rm$rot",
4916 (t2UXTH rGPR:$Rd, rGPR:$Rm, rot_imm:$rot, pred:$p)>;
4918 def : t2InstAlias<"sxtb${p} $Rd, $Rm$rot",
4919 (t2SXTB rGPR:$Rd, rGPR:$Rm, rot_imm:$rot, pred:$p)>;
4920 def : InstAlias<"sxtb16${p} $Rd, $Rm$rot",
4921 (t2SXTB16 rGPR:$Rd, rGPR:$Rm, rot_imm:$rot, pred:$p), 0>,
4922 Requires<[HasDSP, IsThumb2]>;
4923 def : t2InstAlias<"sxth${p} $Rd, $Rm$rot",
4924 (t2SXTH rGPR:$Rd, rGPR:$Rm, rot_imm:$rot, pred:$p)>;
4927 // "mov Rd, t2_so_imm_not" can be handled via "mvn" in assembly, just like
4929 def : t2InstSubst<"mov${p} $Rd, $imm",
4930 (t2MVNi rGPR:$Rd, t2_so_imm_not:$imm, pred:$p, zero_reg)>;
4931 def : t2InstSubst<"mvn${s}${p} $Rd, $imm",
4932 (t2MOVi rGPR:$Rd, t2_so_imm_not:$imm, pred:$p, s_cc_out:$s)>;
4933 // Same for AND <--> BIC
4934 def : t2InstSubst<"bic${s}${p} $Rd, $Rn, $imm",
4935 (t2ANDri rGPR:$Rd, rGPR:$Rn, t2_so_imm_not:$imm,
4936 pred:$p, cc_out:$s)>;
4937 def : t2InstSubst<"bic${s}${p} $Rdn, $imm",
4938 (t2ANDri rGPR:$Rdn, rGPR:$Rdn, t2_so_imm_not:$imm,
4939 pred:$p, cc_out:$s)>;
4940 def : t2InstSubst<"bic${s}${p}.w $Rd, $Rn, $imm",
4941 (t2ANDri rGPR:$Rd, rGPR:$Rn, t2_so_imm_not:$imm,
4942 pred:$p, cc_out:$s)>;
4943 def : t2InstSubst<"bic${s}${p}.w $Rdn, $imm",
4944 (t2ANDri rGPR:$Rdn, rGPR:$Rdn, t2_so_imm_not:$imm,
4945 pred:$p, cc_out:$s)>;
4946 def : t2InstSubst<"and${s}${p} $Rd, $Rn, $imm",
4947 (t2BICri rGPR:$Rd, rGPR:$Rn, t2_so_imm_not:$imm,
4948 pred:$p, cc_out:$s)>;
4949 def : t2InstSubst<"and${s}${p} $Rdn, $imm",
4950 (t2BICri rGPR:$Rdn, rGPR:$Rdn, t2_so_imm_not:$imm,
4951 pred:$p, cc_out:$s)>;
4952 def : t2InstSubst<"and${s}${p}.w $Rd, $Rn, $imm",
4953 (t2BICri rGPR:$Rd, rGPR:$Rn, t2_so_imm_not:$imm,
4954 pred:$p, cc_out:$s)>;
4955 def : t2InstSubst<"and${s}${p}.w $Rdn, $imm",
4956 (t2BICri rGPR:$Rdn, rGPR:$Rdn, t2_so_imm_not:$imm,
4957 pred:$p, cc_out:$s)>;
4959 def : t2InstSubst<"orn${s}${p} $Rd, $Rn, $imm",
4960 (t2ORRri rGPR:$Rd, rGPR:$Rn, t2_so_imm_not:$imm,
4961 pred:$p, cc_out:$s)>;
4962 def : t2InstSubst<"orn${s}${p} $Rdn, $imm",
4963 (t2ORRri rGPR:$Rdn, rGPR:$Rdn, t2_so_imm_not:$imm,
4964 pred:$p, cc_out:$s)>;
4965 def : t2InstSubst<"orr${s}${p} $Rd, $Rn, $imm",
4966 (t2ORNri rGPR:$Rd, rGPR:$Rn, t2_so_imm_not:$imm,
4967 pred:$p, cc_out:$s)>;
4968 def : t2InstSubst<"orr${s}${p} $Rdn, $imm",
4969 (t2ORNri rGPR:$Rdn, rGPR:$Rdn, t2_so_imm_not:$imm,
4970 pred:$p, cc_out:$s)>;
4971 // Likewise, "add Rd, t2_so_imm_neg" -> sub
4972 def : t2InstSubst<"add${s}${p} $Rd, $Rn, $imm",
4973 (t2SUBri GPRnopc:$Rd, GPRnopc:$Rn, t2_so_imm_neg:$imm,
4974 pred:$p, cc_out:$s)>;
4975 def : t2InstSubst<"add${s}${p} $Rd, $imm",
4976 (t2SUBri GPRnopc:$Rd, GPRnopc:$Rd, t2_so_imm_neg:$imm,
4977 pred:$p, cc_out:$s)>;
4978 // Same for CMP <--> CMN via t2_so_imm_neg
4979 def : t2InstSubst<"cmp${p} $Rd, $imm",
4980 (t2CMNri rGPR:$Rd, t2_so_imm_neg:$imm, pred:$p)>;
4981 def : t2InstSubst<"cmn${p} $Rd, $imm",
4982 (t2CMPri rGPR:$Rd, t2_so_imm_neg:$imm, pred:$p)>;
4985 // Wide 'mul' encoding can be specified with only two operands.
4986 def : t2InstAlias<"mul${p} $Rn, $Rm",
4987 (t2MUL rGPR:$Rn, rGPR:$Rm, rGPR:$Rn, pred:$p)>;
4989 // "neg" is and alias for "rsb rd, rn, #0"
4990 def : t2InstAlias<"neg${s}${p} $Rd, $Rm",
4991 (t2RSBri rGPR:$Rd, rGPR:$Rm, 0, pred:$p, cc_out:$s)>;
4993 // MOV so_reg assembler pseudos. InstAlias isn't expressive enough for
4994 // these, unfortunately.
4995 // FIXME: LSL #0 in the shift should allow SP to be used as either the
4996 // source or destination (but not both).
4997 def t2MOVsi: t2AsmPseudo<"mov${p} $Rd, $shift",
4998 (ins rGPR:$Rd, t2_so_reg:$shift, pred:$p)>;
4999 def t2MOVSsi: t2AsmPseudo<"movs${p} $Rd, $shift",
5000 (ins rGPR:$Rd, t2_so_reg:$shift, pred:$p)>;
5002 def t2MOVsr: t2AsmPseudo<"mov${p} $Rd, $shift",
5003 (ins rGPR:$Rd, so_reg_reg:$shift, pred:$p)>;
5004 def t2MOVSsr: t2AsmPseudo<"movs${p} $Rd, $shift",
5005 (ins rGPR:$Rd, so_reg_reg:$shift, pred:$p)>;
5007 // Aliases for the above with the .w qualifier
5008 def : t2InstAlias<"mov${p}.w $Rd, $shift",
5009 (t2MOVsi rGPR:$Rd, t2_so_reg:$shift, pred:$p)>;
5010 def : t2InstAlias<"movs${p}.w $Rd, $shift",
5011 (t2MOVSsi rGPR:$Rd, t2_so_reg:$shift, pred:$p)>;
5012 def : t2InstAlias<"mov${p}.w $Rd, $shift",
5013 (t2MOVsr rGPR:$Rd, so_reg_reg:$shift, pred:$p)>;
5014 def : t2InstAlias<"movs${p}.w $Rd, $shift",
5015 (t2MOVSsr rGPR:$Rd, so_reg_reg:$shift, pred:$p)>;
5017 // ADR w/o the .w suffix
5018 def : t2InstAlias<"adr${p} $Rd, $addr",
5019 (t2ADR rGPR:$Rd, t2adrlabel:$addr, pred:$p)>;
5021 // LDR(literal) w/ alternate [pc, #imm] syntax.
5022 def t2LDRpcrel : t2AsmPseudo<"ldr${p} $Rt, $addr",
5023 (ins GPR:$Rt, t2ldr_pcrel_imm12:$addr, pred:$p)>;
5024 def t2LDRBpcrel : t2AsmPseudo<"ldrb${p} $Rt, $addr",
5025 (ins GPRnopc:$Rt, t2ldr_pcrel_imm12:$addr, pred:$p)>;
5026 def t2LDRHpcrel : t2AsmPseudo<"ldrh${p} $Rt, $addr",
5027 (ins GPRnopc:$Rt, t2ldr_pcrel_imm12:$addr, pred:$p)>;
5028 def t2LDRSBpcrel : t2AsmPseudo<"ldrsb${p} $Rt, $addr",
5029 (ins GPRnopc:$Rt, t2ldr_pcrel_imm12:$addr, pred:$p)>;
5030 def t2LDRSHpcrel : t2AsmPseudo<"ldrsh${p} $Rt, $addr",
5031 (ins GPRnopc:$Rt, t2ldr_pcrel_imm12:$addr, pred:$p)>;
5032 // Version w/ the .w suffix.
5033 def : t2InstAlias<"ldr${p}.w $Rt, $addr",
5034 (t2LDRpcrel GPR:$Rt, t2ldr_pcrel_imm12:$addr, pred:$p), 0>;
5035 def : t2InstAlias<"ldrb${p}.w $Rt, $addr",
5036 (t2LDRBpcrel GPRnopc:$Rt, t2ldr_pcrel_imm12:$addr, pred:$p)>;
5037 def : t2InstAlias<"ldrh${p}.w $Rt, $addr",
5038 (t2LDRHpcrel GPRnopc:$Rt, t2ldr_pcrel_imm12:$addr, pred:$p)>;
5039 def : t2InstAlias<"ldrsb${p}.w $Rt, $addr",
5040 (t2LDRSBpcrel GPRnopc:$Rt, t2ldr_pcrel_imm12:$addr, pred:$p)>;
5041 def : t2InstAlias<"ldrsh${p}.w $Rt, $addr",
5042 (t2LDRSHpcrel GPRnopc:$Rt, t2ldr_pcrel_imm12:$addr, pred:$p)>;
5044 def : t2InstAlias<"add${p} $Rd, pc, $imm",
5045 (t2ADR rGPR:$Rd, imm0_4095:$imm, pred:$p)>;
5047 // Pseudo instruction ldr Rt, =immediate
5049 : t2AsmPseudo<"ldr${p} $Rt, $immediate",
5050 (ins GPR:$Rt, const_pool_asm_imm:$immediate, pred:$p)>;
5051 // Version w/ the .w suffix.
5052 def : t2InstAlias<"ldr${p}.w $Rt, $immediate",
5053 (t2LDRConstPool GPRnopc:$Rt,
5054 const_pool_asm_imm:$immediate, pred:$p)>;
5056 // PLD/PLDW/PLI with alternate literal form.
5057 def : t2InstAlias<"pld${p} $addr",
5058 (t2PLDpci t2ldr_pcrel_imm12:$addr, pred:$p)>;
5059 def : InstAlias<"pli${p} $addr",
5060 (t2PLIpci t2ldr_pcrel_imm12:$addr, pred:$p), 0>,
5061 Requires<[IsThumb2,HasV7]>;
5064 //===----------------------------------------------------------------------===//
5065 // ARMv8.1m instructions
5068 class V8_1MI<dag oops, dag iops, AddrMode am, InstrItinClass itin, string asm,
5069 string ops, string cstr, list<dag> pattern>
5070 : Thumb2XI<oops, iops, am, 4, itin, !strconcat(asm, "\t", ops), cstr,
5072 Requires<[HasV8_1MMainline]>;
5074 def t2CLRM : V8_1MI<(outs),
5075 (ins pred:$p, reglist_with_apsr:$regs, variable_ops),
5076 AddrModeNone, NoItinerary, "clrm", "${p}\t$regs", "", []> {
5079 let Inst{31-16} = 0b1110100010011111;
5080 let Inst{15-14} = regs{15-14};
5082 let Inst{12-0} = regs{12-0};
5085 class t2BF<dag iops, string asm, string ops>
5086 : V8_1MI<(outs ), iops, AddrModeNone, NoItinerary, asm, ops, "", []> {
5088 let Inst{31-27} = 0b11110;
5089 let Inst{15-14} = 0b11;
5093 let Predicates = [IsThumb2, HasV8_1MMainline, HasLOB];
5096 def t2BF_LabelPseudo
5097 : t2PseudoInst<(outs ), (ins pclabel:$cp), 0, NoItinerary, []> {
5098 let isTerminator = 1;
5099 let Predicates = [IsThumb2, HasV8_1MMainline, HasLOB];
5100 let hasNoSchedulingInfo = 1;
5103 def t2BFi : t2BF<(ins bflabel_u4:$b_label, bflabel_s16:$label, pred:$p),
5104 !strconcat("bf", "${p}"), "$b_label, $label"> {
5108 let Inst{26-23} = b_label{3-0};
5109 let Inst{22-21} = 0b10;
5110 let Inst{20-16} = label{15-11};
5112 let Inst{11} = label{0};
5113 let Inst{10-1} = label{10-1};
5116 def t2BFic : t2BF<(ins bflabel_u4:$b_label, bflabel_s12:$label,
5117 bfafter_target:$ba_label, pred_noal:$bcond), "bfcsel",
5118 "$b_label, $label, $ba_label, $bcond"> {
5124 let Inst{26-23} = b_label{3-0};
5126 let Inst{21-18} = bcond{3-0};
5127 let Inst{17} = ba_label{0};
5128 let Inst{16} = label{11};
5130 let Inst{11} = label{0};
5131 let Inst{10-1} = label{10-1};
5134 def t2BFr : t2BF<(ins bflabel_u4:$b_label, rGPR:$Rn, pred:$p),
5135 !strconcat("bfx", "${p}"), "$b_label, $Rn"> {
5139 let Inst{26-23} = b_label{3-0};
5140 let Inst{22-20} = 0b110;
5141 let Inst{19-16} = Rn{3-0};
5142 let Inst{13-1} = 0b1000000000000;
5145 def t2BFLi : t2BF<(ins bflabel_u4:$b_label, bflabel_s18:$label, pred:$p),
5146 !strconcat("bfl", "${p}"), "$b_label, $label"> {
5150 let Inst{26-23} = b_label{3-0};
5151 let Inst{22-16} = label{17-11};
5153 let Inst{11} = label{0};
5154 let Inst{10-1} = label{10-1};
5157 def t2BFLr : t2BF<(ins bflabel_u4:$b_label, rGPR:$Rn, pred:$p),
5158 !strconcat("bflx", "${p}"), "$b_label, $Rn"> {
5162 let Inst{26-23} = b_label{3-0};
5163 let Inst{22-20} = 0b111;
5164 let Inst{19-16} = Rn{3-0};
5165 let Inst{13-1} = 0b1000000000000;
5168 class t2LOL<dag oops, dag iops, string asm, string ops>
5169 : V8_1MI<oops, iops, AddrModeNone, NoItinerary, asm, ops, "", [] > {
5170 let Inst{31-23} = 0b111100000;
5171 let Inst{15-14} = 0b11;
5174 let isTerminator = 1;
5175 let DecoderMethod = "DecodeLOLoop";
5176 let Predicates = [IsThumb2, HasV8_1MMainline, HasLOB];
5179 let isNotDuplicable = 1 in {
5180 def t2WLS : t2LOL<(outs GPRlr:$LR),
5181 (ins rGPR:$Rn, wlslabel_u11:$label),
5182 "wls", "$LR, $Rn, $label"> {
5185 let Inst{22-20} = 0b100;
5186 let Inst{19-16} = Rn{3-0};
5187 let Inst{13-12} = 0b00;
5188 let Inst{11} = label{0};
5189 let Inst{10-1} = label{10-1};
5190 let usesCustomInserter = 1;
5193 def t2DLS : t2LOL<(outs GPRlr:$LR), (ins rGPR:$Rn),
5194 "dls", "$LR, $Rn"> {
5197 let isTerminator = 0;
5198 let Inst{22-20} = 0b100;
5199 let Inst{19-16} = Rn{3-0};
5200 let Inst{13-1} = 0b1000000000000;
5201 let usesCustomInserter = 1;
5204 def t2LEUpdate : t2LOL<(outs GPRlr:$LRout),
5205 (ins GPRlr:$LRin, lelabel_u11:$label),
5206 "le", "$LRin, $label"> {
5208 let Inst{22-16} = 0b0001111;
5209 let Inst{13-12} = 0b00;
5210 let Inst{11} = label{0};
5211 let Inst{10-1} = label{10-1};
5212 let usesCustomInserter = 1;
5215 def t2LE : t2LOL<(outs ), (ins lelabel_u11:$label), "le", "$label"> {
5217 let Inst{22-16} = 0b0101111;
5218 let Inst{13-12} = 0b00;
5219 let Inst{11} = label{0};
5220 let Inst{10-1} = label{10-1};
5224 t2PseudoInst<(outs), (ins rGPR:$elts), 4, IIC_Br,
5225 [(int_set_loop_iterations rGPR:$elts)]>, Sched<[WriteBr]>;
5228 t2PseudoInst<(outs GPRlr:$Rm), (ins GPRlr:$Rn, imm0_7:$size),
5229 4, IIC_Br, []>, Sched<[WriteBr]>;
5231 let isBranch = 1, isTerminator = 1, hasSideEffects = 1, Defs = [CPSR] in {
5232 // Set WhileLoopStart and LoopEnd to occupy 8 bytes because they may
5233 // get converted into t2CMP and t2Bcc.
5234 def t2WhileLoopStart :
5235 t2PseudoInst<(outs),
5236 (ins rGPR:$elts, brtarget:$target),
5241 t2PseudoInst<(outs), (ins GPRlr:$elts, brtarget:$target),
5242 8, IIC_Br, []>, Sched<[WriteBr]>;
5244 } // end isBranch, isTerminator, hasSideEffects
5246 } // end isNotDuplicable
5248 class CS<string iname, bits<4> opcode, list<dag> pattern=[]>
5249 : V8_1MI<(outs rGPR:$Rd), (ins GPRwithZRnosp:$Rn, GPRwithZRnosp:$Rm, pred_noal:$fcond),
5250 AddrModeNone, NoItinerary, iname, "$Rd, $Rn, $Rm, $fcond", "", pattern> {
5256 let Inst{31-20} = 0b111010100101;
5257 let Inst{19-16} = Rn{3-0};
5258 let Inst{15-12} = opcode;
5259 let Inst{11-8} = Rd{3-0};
5260 let Inst{7-4} = fcond{3-0};
5261 let Inst{3-0} = Rm{3-0};
5266 def t2CSEL : CS<"csel", 0b1000>;
5267 def t2CSINC : CS<"csinc", 0b1001>;
5268 def t2CSINV : CS<"csinv", 0b1010>;
5269 def t2CSNEG : CS<"csneg", 0b1011>;
5271 let Predicates = [HasV8_1MMainline] in {
5272 def : T2Pat<(ARMcsinc GPRwithZR:$tval, GPRwithZR:$fval, imm0_31:$imm),
5273 (t2CSINC GPRwithZR:$tval, GPRwithZR:$fval, imm0_31:$imm)>;
5274 def : T2Pat<(ARMcsinv GPRwithZR:$tval, GPRwithZR:$fval, imm0_31:$imm),
5275 (t2CSINV GPRwithZR:$tval, GPRwithZR:$fval, imm0_31:$imm)>;
5276 def : T2Pat<(ARMcsneg GPRwithZR:$tval, GPRwithZR:$fval, imm0_31:$imm),
5277 (t2CSNEG GPRwithZR:$tval, GPRwithZR:$fval, imm0_31:$imm)>;
5279 multiclass ModifiedV8_1CSEL<Instruction Insn, dag modvalue> {
5280 def : T2Pat<(ARMcmov modvalue, GPRwithZR:$tval, cmovpred:$imm),
5281 (Insn GPRwithZR:$tval, GPRwithZR:$fval, imm0_31:$imm)>;
5282 def : T2Pat<(ARMcmov GPRwithZR:$tval, modvalue, cmovpred:$imm),
5283 (Insn GPRwithZR:$tval, GPRwithZR:$fval,
5284 (i32 (inv_cond_XFORM imm:$imm)))>;
5286 defm : ModifiedV8_1CSEL<t2CSINC, (add rGPR:$fval, 1)>;
5287 defm : ModifiedV8_1CSEL<t2CSINV, (xor rGPR:$fval, -1)>;
5288 defm : ModifiedV8_1CSEL<t2CSNEG, (sub 0, rGPR:$fval)>;
5292 let Predicates = [HasV8_1MMainline] in {
5293 def : InstAlias<"csetm\t$Rd, $fcond",
5294 (t2CSINV rGPR:$Rd, ZR, ZR, pred_noal_inv:$fcond)>;
5296 def : InstAlias<"cset\t$Rd, $fcond",
5297 (t2CSINC rGPR:$Rd, ZR, ZR, pred_noal_inv:$fcond)>;
5299 def : InstAlias<"cinc\t$Rd, $Rn, $fcond",
5300 (t2CSINC rGPR:$Rd, GPRwithZRnosp:$Rn, GPRwithZRnosp:$Rn, pred_noal_inv:$fcond)>;
5302 def : InstAlias<"cinv\t$Rd, $Rn, $fcond",
5303 (t2CSINV rGPR:$Rd, GPRwithZRnosp:$Rn, GPRwithZRnosp:$Rn, pred_noal_inv:$fcond)>;
5305 def : InstAlias<"cneg\t$Rd, $Rn, $fcond",
5306 (t2CSNEG rGPR:$Rd, GPRwithZRnosp:$Rn, GPRwithZRnosp:$Rn, pred_noal_inv:$fcond)>;