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 ComplexPattern<i32, 2, "SelectT2AddrModeImm8<2>", []> {
275 let EncoderMethod = "getT2AddrModeImm8s4OpValue";
276 let DecoderMethod = "DecodeT2AddrModeImm8s4";
277 let ParserMatchClass = MemImm8s4OffsetAsmOperand;
278 let MIOperandInfo = (ops GPR:$base, i32imm:$offsimm);
281 def t2addrmode_imm8s4 : T2AddrMode_Imm8s4 {
282 let PrintMethod = "printT2AddrModeImm8s4Operand<false>";
285 def t2addrmode_imm8s4_pre : T2AddrMode_Imm8s4 {
286 let PrintMethod = "printT2AddrModeImm8s4Operand<true>";
289 def t2am_imm8s4_offset_asmoperand : AsmOperandClass { let Name = "Imm8s4"; }
290 def t2am_imm8s4_offset : MemOperand {
291 let PrintMethod = "printT2AddrModeImm8s4OffsetOperand";
292 let EncoderMethod = "getT2ScaledImmOpValue<8,2>";
293 let DecoderMethod = "DecodeT2Imm8S4";
296 // t2addrmode_imm7s4 := reg +/- (imm7 << 2)
297 def MemImm7s4OffsetAsmOperand : AsmOperandClass {let Name = "MemImm7s4Offset";}
298 class T2AddrMode_Imm7s4 : MemOperand {
299 let EncoderMethod = "getT2AddrModeImm7s4OpValue";
300 let DecoderMethod = "DecodeT2AddrModeImm7<2,0>";
301 let ParserMatchClass = MemImm7s4OffsetAsmOperand;
302 let MIOperandInfo = (ops GPRnopc:$base, i32imm:$offsimm);
305 def t2addrmode_imm7s4 : T2AddrMode_Imm7s4 {
306 // They are printed the same way as the imm8 version
307 let PrintMethod = "printT2AddrModeImm8s4Operand<false>";
310 def t2addrmode_imm7s4_pre : T2AddrMode_Imm7s4 {
311 // They are printed the same way as the imm8 version
312 let PrintMethod = "printT2AddrModeImm8s4Operand<true>";
315 def t2am_imm7s4_offset_asmoperand : AsmOperandClass { let Name = "Imm7s4"; }
316 def t2am_imm7s4_offset : MemOperand {
317 // They are printed the same way as the imm8 version
318 let PrintMethod = "printT2AddrModeImm8s4OffsetOperand";
319 let ParserMatchClass = t2am_imm7s4_offset_asmoperand;
320 let EncoderMethod = "getT2ScaledImmOpValue<7,2>";
321 let DecoderMethod = "DecodeT2Imm7S4";
324 // t2addrmode_imm0_1020s4 := reg + (imm8 << 2)
325 def MemImm0_1020s4OffsetAsmOperand : AsmOperandClass {
326 let Name = "MemImm0_1020s4Offset";
328 def t2addrmode_imm0_1020s4 : MemOperand,
329 ComplexPattern<i32, 2, "SelectT2AddrModeExclusive"> {
330 let PrintMethod = "printT2AddrModeImm0_1020s4Operand";
331 let EncoderMethod = "getT2AddrModeImm0_1020s4OpValue";
332 let DecoderMethod = "DecodeT2AddrModeImm0_1020s4";
333 let ParserMatchClass = MemImm0_1020s4OffsetAsmOperand;
334 let MIOperandInfo = (ops GPRnopc:$base, i32imm:$offsimm);
337 // t2addrmode_so_reg := reg + (reg << imm2)
338 def t2addrmode_so_reg_asmoperand : AsmOperandClass {let Name="T2MemRegOffset";}
339 def t2addrmode_so_reg : MemOperand,
340 ComplexPattern<i32, 3, "SelectT2AddrModeSoReg", []> {
341 let PrintMethod = "printT2AddrModeSoRegOperand";
342 let EncoderMethod = "getT2AddrModeSORegOpValue";
343 let DecoderMethod = "DecodeT2AddrModeSOReg";
344 let ParserMatchClass = t2addrmode_so_reg_asmoperand;
345 let MIOperandInfo = (ops GPRnopc:$base, rGPR:$offsreg, i32imm:$offsimm);
348 // Addresses for the TBB/TBH instructions.
349 def addrmode_tbb_asmoperand : AsmOperandClass { let Name = "MemTBB"; }
350 def addrmode_tbb : MemOperand {
351 let PrintMethod = "printAddrModeTBB";
352 let ParserMatchClass = addrmode_tbb_asmoperand;
353 let MIOperandInfo = (ops GPR:$Rn, rGPR:$Rm);
355 def addrmode_tbh_asmoperand : AsmOperandClass { let Name = "MemTBH"; }
356 def addrmode_tbh : MemOperand {
357 let PrintMethod = "printAddrModeTBH";
358 let ParserMatchClass = addrmode_tbh_asmoperand;
359 let MIOperandInfo = (ops GPR:$Rn, rGPR:$Rm);
362 // Define ARMv8.1-M specific addressing modes.
364 // Label operands for BF/BFL/WLS/DLS/LE
365 class BFLabelOp<string signed, string isNeg, string zeroPermitted, string size,
368 let EncoderMethod = !strconcat("getBFTargetOpValue<", isNeg, ", ",
370 let OperandType = "OPERAND_PCREL";
371 let DecoderMethod = !strconcat("DecodeBFLabelOperand<", signed, ", ",
372 isNeg, ", ", zeroPermitted, ", ", size, ">");
374 def bflabel_u4 : BFLabelOp<"false", "false", "false", "4", "ARM::fixup_bf_branch">;
375 def bflabel_s12 : BFLabelOp<"true", "false", "true", "12", "ARM::fixup_bfc_target">;
376 def bflabel_s16 : BFLabelOp<"true", "false", "true", "16", "ARM::fixup_bf_target">;
377 def bflabel_s18 : BFLabelOp<"true", "false", "true", "18", "ARM::fixup_bfl_target">;
379 def wlslabel_u11_asmoperand : AsmOperandClass {
380 let Name = "WLSLabel";
381 let RenderMethod = "addImmOperands";
382 let PredicateMethod = "isUnsignedOffset<11, 1>";
383 let DiagnosticString =
384 "loop end is out of range or not a positive multiple of 2";
386 def wlslabel_u11 : BFLabelOp<"false", "false", "true", "11", "ARM::fixup_wls"> {
387 let ParserMatchClass = wlslabel_u11_asmoperand;
389 def lelabel_u11_asmoperand : AsmOperandClass {
390 let Name = "LELabel";
391 let RenderMethod = "addImmOperands";
392 let PredicateMethod = "isLEOffset";
393 let DiagnosticString =
394 "loop start is out of range or not a negative multiple of 2";
396 def lelabel_u11 : BFLabelOp<"false", "true", "true", "11", "ARM::fixup_le"> {
397 let ParserMatchClass = lelabel_u11_asmoperand;
400 def bfafter_target : Operand<OtherVT> {
401 let EncoderMethod = "getBFAfterTargetOpValue";
402 let OperandType = "OPERAND_PCREL";
403 let DecoderMethod = "DecodeBFAfterTargetOperand";
406 // pred operand excluding AL
407 def pred_noal_asmoperand : AsmOperandClass {
408 let Name = "CondCodeNoAL";
409 let RenderMethod = "addITCondCodeOperands";
410 let PredicateMethod = "isITCondCodeNoAL";
411 let ParserMethod = "parseITCondCode";
413 def pred_noal : Operand<i32> {
414 let PrintMethod = "printMandatoryPredicateOperand";
415 let ParserMatchClass = pred_noal_asmoperand;
416 let DecoderMethod = "DecodePredNoALOperand";
420 // CSEL aliases inverted predicate
421 def pred_noal_inv_asmoperand : AsmOperandClass {
422 let Name = "CondCodeNoALInv";
423 let RenderMethod = "addITCondCodeInvOperands";
424 let PredicateMethod = "isITCondCodeNoAL";
425 let ParserMethod = "parseITCondCode";
427 def pred_noal_inv : Operand<i32> {
428 let PrintMethod = "printMandatoryInvertedPredicateOperand";
429 let ParserMatchClass = pred_noal_inv_asmoperand;
431 //===----------------------------------------------------------------------===//
432 // Multiclass helpers...
436 class T2OneRegImm<dag oops, dag iops, InstrItinClass itin,
437 string opc, string asm, list<dag> pattern>
438 : T2I<oops, iops, itin, opc, asm, pattern> {
443 let Inst{26} = imm{11};
444 let Inst{14-12} = imm{10-8};
445 let Inst{7-0} = imm{7-0};
449 class T2sOneRegImm<dag oops, dag iops, InstrItinClass itin,
450 string opc, string asm, list<dag> pattern>
451 : T2sI<oops, iops, itin, opc, asm, pattern> {
457 let Inst{26} = imm{11};
458 let Inst{14-12} = imm{10-8};
459 let Inst{7-0} = imm{7-0};
462 class T2OneRegCmpImm<dag oops, dag iops, InstrItinClass itin,
463 string opc, string asm, list<dag> pattern>
464 : T2I<oops, iops, itin, opc, asm, pattern> {
468 let Inst{19-16} = Rn;
469 let Inst{26} = imm{11};
470 let Inst{14-12} = imm{10-8};
471 let Inst{7-0} = imm{7-0};
475 class T2OneRegShiftedReg<dag oops, dag iops, InstrItinClass itin,
476 string opc, string asm, list<dag> pattern>
477 : T2I<oops, iops, itin, opc, asm, pattern> {
482 let Inst{3-0} = ShiftedRm{3-0};
483 let Inst{5-4} = ShiftedRm{6-5};
484 let Inst{14-12} = ShiftedRm{11-9};
485 let Inst{7-6} = ShiftedRm{8-7};
488 class T2sOneRegShiftedReg<dag oops, dag iops, InstrItinClass itin,
489 string opc, string asm, list<dag> pattern>
490 : T2sI<oops, iops, itin, opc, asm, pattern> {
495 let Inst{3-0} = ShiftedRm{3-0};
496 let Inst{5-4} = ShiftedRm{6-5};
497 let Inst{14-12} = ShiftedRm{11-9};
498 let Inst{7-6} = ShiftedRm{8-7};
501 class T2OneRegCmpShiftedReg<dag oops, dag iops, InstrItinClass itin,
502 string opc, string asm, list<dag> pattern>
503 : T2I<oops, iops, itin, opc, asm, pattern> {
507 let Inst{19-16} = Rn;
508 let Inst{3-0} = ShiftedRm{3-0};
509 let Inst{5-4} = ShiftedRm{6-5};
510 let Inst{14-12} = ShiftedRm{11-9};
511 let Inst{7-6} = ShiftedRm{8-7};
514 class T2TwoReg<dag oops, dag iops, InstrItinClass itin,
515 string opc, string asm, list<dag> pattern>
516 : T2I<oops, iops, itin, opc, asm, pattern> {
524 class T2sTwoReg<dag oops, dag iops, InstrItinClass itin,
525 string opc, string asm, list<dag> pattern>
526 : T2sI<oops, iops, itin, opc, asm, pattern> {
534 class T2TwoRegCmp<dag oops, dag iops, InstrItinClass itin,
535 string opc, string asm, list<dag> pattern>
536 : T2I<oops, iops, itin, opc, asm, pattern> {
540 let Inst{19-16} = Rn;
545 class T2TwoRegImm<dag oops, dag iops, InstrItinClass itin,
546 string opc, string asm, list<dag> pattern>
547 : T2I<oops, iops, itin, opc, asm, pattern> {
553 let Inst{19-16} = Rn;
554 let Inst{26} = imm{11};
555 let Inst{14-12} = imm{10-8};
556 let Inst{7-0} = imm{7-0};
559 class T2sTwoRegImm<dag oops, dag iops, InstrItinClass itin,
560 string opc, string asm, list<dag> pattern>
561 : T2sI<oops, iops, itin, opc, asm, pattern> {
567 let Inst{19-16} = Rn;
568 let Inst{26} = imm{11};
569 let Inst{14-12} = imm{10-8};
570 let Inst{7-0} = imm{7-0};
573 class T2TwoRegShiftImm<dag oops, dag iops, InstrItinClass itin,
574 string opc, string asm, list<dag> pattern>
575 : T2I<oops, iops, itin, opc, asm, pattern> {
582 let Inst{14-12} = imm{4-2};
583 let Inst{7-6} = imm{1-0};
586 class T2sTwoRegShiftImm<dag oops, dag iops, InstrItinClass itin,
587 string opc, string asm, list<dag> pattern>
588 : T2sI<oops, iops, itin, opc, asm, pattern> {
595 let Inst{14-12} = imm{4-2};
596 let Inst{7-6} = imm{1-0};
599 class T2ThreeReg<dag oops, dag iops, InstrItinClass itin,
600 string opc, string asm, list<dag> pattern>
601 : T2I<oops, iops, itin, opc, asm, pattern> {
607 let Inst{19-16} = Rn;
611 class T2ThreeRegNoP<dag oops, dag iops, InstrItinClass itin,
612 string asm, list<dag> pattern>
613 : T2XI<oops, iops, itin, asm, pattern> {
619 let Inst{19-16} = Rn;
623 class T2sThreeReg<dag oops, dag iops, InstrItinClass itin,
624 string opc, string asm, list<dag> pattern>
625 : T2sI<oops, iops, itin, opc, asm, pattern> {
631 let Inst{19-16} = Rn;
635 class T2TwoRegShiftedReg<dag oops, dag iops, InstrItinClass itin,
636 string opc, string asm, list<dag> pattern>
637 : T2I<oops, iops, itin, opc, asm, pattern> {
643 let Inst{19-16} = Rn;
644 let Inst{3-0} = ShiftedRm{3-0};
645 let Inst{5-4} = ShiftedRm{6-5};
646 let Inst{14-12} = ShiftedRm{11-9};
647 let Inst{7-6} = ShiftedRm{8-7};
650 class T2sTwoRegShiftedReg<dag oops, dag iops, InstrItinClass itin,
651 string opc, string asm, list<dag> pattern>
652 : T2sI<oops, iops, itin, opc, asm, pattern> {
658 let Inst{19-16} = Rn;
659 let Inst{3-0} = ShiftedRm{3-0};
660 let Inst{5-4} = ShiftedRm{6-5};
661 let Inst{14-12} = ShiftedRm{11-9};
662 let Inst{7-6} = ShiftedRm{8-7};
665 class T2FourReg<dag oops, dag iops, InstrItinClass itin,
666 string opc, string asm, list<dag> pattern>
667 : T2I<oops, iops, itin, opc, asm, pattern> {
673 let Inst{19-16} = Rn;
674 let Inst{15-12} = Ra;
679 class T2MulLong<bits<3> opc22_20, bits<4> opc7_4,
680 string opc, list<dag> pattern>
681 : T2I<(outs rGPR:$RdLo, rGPR:$RdHi), (ins rGPR:$Rn, rGPR:$Rm), IIC_iMUL64,
682 opc, "\t$RdLo, $RdHi, $Rn, $Rm", pattern>,
683 Sched<[WriteMUL64Lo, WriteMUL64Hi, ReadMUL, ReadMUL]> {
689 let Inst{31-23} = 0b111110111;
690 let Inst{22-20} = opc22_20;
691 let Inst{19-16} = Rn;
692 let Inst{15-12} = RdLo;
693 let Inst{11-8} = RdHi;
694 let Inst{7-4} = opc7_4;
697 class T2MlaLong<bits<3> opc22_20, bits<4> opc7_4, string opc>
698 : T2I<(outs rGPR:$RdLo, rGPR:$RdHi),
699 (ins rGPR:$Rn, rGPR:$Rm, rGPR:$RLo, rGPR:$RHi), IIC_iMAC64,
700 opc, "\t$RdLo, $RdHi, $Rn, $Rm", []>,
701 RegConstraint<"$RLo = $RdLo, $RHi = $RdHi">,
702 Sched<[WriteMAC64Lo, WriteMAC64Hi, ReadMUL, ReadMUL, ReadMAC, ReadMAC]> {
708 let Inst{31-23} = 0b111110111;
709 let Inst{22-20} = opc22_20;
710 let Inst{19-16} = Rn;
711 let Inst{15-12} = RdLo;
712 let Inst{11-8} = RdHi;
713 let Inst{7-4} = opc7_4;
718 /// T2I_bin_irs - Defines a set of (op reg, {so_imm|r|so_reg}) patterns for a
719 /// binary operation that produces a value. These are predicable and can be
720 /// changed to modify CPSR.
721 multiclass T2I_bin_irs<bits<4> opcod, string opc,
722 InstrItinClass iii, InstrItinClass iir, InstrItinClass iis,
723 SDPatternOperator opnode, bit Commutable = 0,
726 def ri : T2sTwoRegImm<
727 (outs rGPR:$Rd), (ins rGPR:$Rn, t2_so_imm:$imm), iii,
728 opc, "\t$Rd, $Rn, $imm",
729 [(set rGPR:$Rd, (opnode rGPR:$Rn, t2_so_imm:$imm))]>,
730 Sched<[WriteALU, ReadALU]> {
731 let Inst{31-27} = 0b11110;
733 let Inst{24-21} = opcod;
737 def rr : T2sThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), iir,
738 opc, !strconcat(wide, "\t$Rd, $Rn, $Rm"),
739 [(set rGPR:$Rd, (opnode rGPR:$Rn, rGPR:$Rm))]>,
740 Sched<[WriteALU, ReadALU, ReadALU]> {
741 let isCommutable = Commutable;
742 let Inst{31-27} = 0b11101;
743 let Inst{26-25} = 0b01;
744 let Inst{24-21} = opcod;
746 // In most of these instructions, and most versions of the Arm
747 // architecture, bit 15 of this encoding is listed as (0) rather
748 // than 0, i.e. setting it to 1 is UNPREDICTABLE or a soft-fail
749 // rather than a hard failure. In v8.1-M, this requirement is
750 // upgraded to a hard one for ORR, so that the encodings with 1
751 // in this bit can be reused for other instructions (such as
752 // CSEL). Setting Unpredictable{15} = 1 here would reintroduce
753 // that encoding clash in the auto- generated MC decoder, so I
755 let Unpredictable{15} = !if(!eq(opcod, 0b0010), 0b0, 0b1);
756 let Inst{14-12} = 0b000; // imm3
757 let Inst{7-6} = 0b00; // imm2
758 let Inst{5-4} = 0b00; // type
761 def rs : T2sTwoRegShiftedReg<
762 (outs rGPR:$Rd), (ins rGPR:$Rn, t2_so_reg:$ShiftedRm), iis,
763 opc, !strconcat(wide, "\t$Rd, $Rn, $ShiftedRm"),
764 [(set rGPR:$Rd, (opnode rGPR:$Rn, t2_so_reg:$ShiftedRm))]>,
765 Sched<[WriteALUsi, ReadALU]> {
766 let Inst{31-27} = 0b11101;
767 let Inst{26-25} = 0b01;
768 let Inst{24-21} = opcod;
770 let Unpredictable{15} = !if(!eq(opcod, 0b0010), 0b0, 0b1); // see above
772 // Assembly aliases for optional destination operand when it's the same
773 // as the source operand.
774 def : t2InstAlias<!strconcat(opc, "${s}${p} $Rdn, $imm"),
775 (!cast<Instruction>(NAME#"ri") rGPR:$Rdn, rGPR:$Rdn,
776 t2_so_imm:$imm, pred:$p,
778 def : t2InstAlias<!strconcat(opc, "${s}${p}", wide, " $Rdn, $Rm"),
779 (!cast<Instruction>(NAME#"rr") rGPR:$Rdn, rGPR:$Rdn,
782 def : t2InstAlias<!strconcat(opc, "${s}${p}", wide, " $Rdn, $shift"),
783 (!cast<Instruction>(NAME#"rs") rGPR:$Rdn, rGPR:$Rdn,
784 t2_so_reg:$shift, pred:$p,
788 /// T2I_bin_w_irs - Same as T2I_bin_irs except these operations need
789 // the ".w" suffix to indicate that they are wide.
790 multiclass T2I_bin_w_irs<bits<4> opcod, string opc,
791 InstrItinClass iii, InstrItinClass iir, InstrItinClass iis,
792 SDPatternOperator opnode, bit Commutable = 0> :
793 T2I_bin_irs<opcod, opc, iii, iir, iis, opnode, Commutable, ".w"> {
794 // Assembler aliases w/ the ".w" suffix.
795 def : t2InstAlias<!strconcat(opc, "${s}${p}.w", " $Rd, $Rn, $imm"),
796 (!cast<Instruction>(NAME#"ri") rGPR:$Rd, rGPR:$Rn, t2_so_imm:$imm, pred:$p,
798 // Assembler aliases w/o the ".w" suffix.
799 def : t2InstAlias<!strconcat(opc, "${s}${p}", " $Rd, $Rn, $Rm"),
800 (!cast<Instruction>(NAME#"rr") rGPR:$Rd, rGPR:$Rn, rGPR:$Rm, pred:$p,
802 def : t2InstAlias<!strconcat(opc, "${s}${p}", " $Rd, $Rn, $shift"),
803 (!cast<Instruction>(NAME#"rs") rGPR:$Rd, rGPR:$Rn, t2_so_reg:$shift,
804 pred:$p, cc_out:$s)>;
806 // and with the optional destination operand, too.
807 def : t2InstAlias<!strconcat(opc, "${s}${p}.w", " $Rdn, $imm"),
808 (!cast<Instruction>(NAME#"ri") rGPR:$Rdn, rGPR:$Rdn, t2_so_imm:$imm,
809 pred:$p, cc_out:$s)>;
810 def : t2InstAlias<!strconcat(opc, "${s}${p}", " $Rdn, $Rm"),
811 (!cast<Instruction>(NAME#"rr") rGPR:$Rdn, rGPR:$Rdn, rGPR:$Rm, pred:$p,
813 def : t2InstAlias<!strconcat(opc, "${s}${p}", " $Rdn, $shift"),
814 (!cast<Instruction>(NAME#"rs") rGPR:$Rdn, rGPR:$Rdn, t2_so_reg:$shift,
815 pred:$p, cc_out:$s)>;
818 /// T2I_rbin_is - Same as T2I_bin_irs except the order of operands are
819 /// reversed. The 'rr' form is only defined for the disassembler; for codegen
820 /// it is equivalent to the T2I_bin_irs counterpart.
821 multiclass T2I_rbin_irs<bits<4> opcod, string opc, SDNode opnode> {
823 def ri : T2sTwoRegImm<
824 (outs rGPR:$Rd), (ins rGPR:$Rn, t2_so_imm:$imm), IIC_iALUi,
825 opc, ".w\t$Rd, $Rn, $imm",
826 [(set rGPR:$Rd, (opnode t2_so_imm:$imm, rGPR:$Rn))]>,
827 Sched<[WriteALU, ReadALU]> {
828 let Inst{31-27} = 0b11110;
830 let Inst{24-21} = opcod;
834 def rr : T2sThreeReg<
835 (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iALUr,
836 opc, "\t$Rd, $Rn, $Rm",
837 [/* For disassembly only; pattern left blank */]>,
838 Sched<[WriteALU, ReadALU, ReadALU]> {
839 let Inst{31-27} = 0b11101;
840 let Inst{26-25} = 0b01;
841 let Inst{24-21} = opcod;
842 let Inst{14-12} = 0b000; // imm3
843 let Inst{7-6} = 0b00; // imm2
844 let Inst{5-4} = 0b00; // type
847 def rs : T2sTwoRegShiftedReg<
848 (outs rGPR:$Rd), (ins rGPR:$Rn, t2_so_reg:$ShiftedRm),
849 IIC_iALUsir, opc, "\t$Rd, $Rn, $ShiftedRm",
850 [(set rGPR:$Rd, (opnode t2_so_reg:$ShiftedRm, rGPR:$Rn))]>,
851 Sched<[WriteALUsi, ReadALU]> {
852 let Inst{31-27} = 0b11101;
853 let Inst{26-25} = 0b01;
854 let Inst{24-21} = opcod;
858 /// T2I_bin_s_irs - Similar to T2I_bin_irs except it sets the 's' bit so the
859 /// instruction modifies the CPSR register.
861 /// These opcodes will be converted to the real non-S opcodes by
862 /// AdjustInstrPostInstrSelection after giving then an optional CPSR operand.
863 let hasPostISelHook = 1, Defs = [CPSR] in {
864 multiclass T2I_bin_s_irs<InstrItinClass iii, InstrItinClass iir,
865 InstrItinClass iis, SDNode opnode,
866 bit Commutable = 0> {
868 def ri : t2PseudoInst<(outs rGPR:$Rd),
869 (ins GPRnopc:$Rn, t2_so_imm:$imm, pred:$p),
871 [(set rGPR:$Rd, CPSR, (opnode GPRnopc:$Rn,
873 Sched<[WriteALU, ReadALU]>;
875 def rr : t2PseudoInst<(outs rGPR:$Rd), (ins GPRnopc:$Rn, rGPR:$Rm, pred:$p),
877 [(set rGPR:$Rd, CPSR, (opnode GPRnopc:$Rn,
879 Sched<[WriteALU, ReadALU, ReadALU]> {
880 let isCommutable = Commutable;
883 def rs : t2PseudoInst<(outs rGPR:$Rd),
884 (ins GPRnopc:$Rn, t2_so_reg:$ShiftedRm, pred:$p),
886 [(set rGPR:$Rd, CPSR, (opnode GPRnopc:$Rn,
887 t2_so_reg:$ShiftedRm))]>,
888 Sched<[WriteALUsi, ReadALUsr]>;
892 /// T2I_rbin_s_is - Same as T2I_bin_s_irs, except selection DAG
893 /// operands are reversed.
894 let hasPostISelHook = 1, Defs = [CPSR] in {
895 multiclass T2I_rbin_s_is<SDNode opnode> {
897 def ri : t2PseudoInst<(outs rGPR:$Rd),
898 (ins rGPR:$Rn, t2_so_imm:$imm, pred:$p),
900 [(set rGPR:$Rd, CPSR, (opnode t2_so_imm:$imm,
902 Sched<[WriteALU, ReadALU]>;
904 def rs : t2PseudoInst<(outs rGPR:$Rd),
905 (ins rGPR:$Rn, t2_so_reg:$ShiftedRm, pred:$p),
907 [(set rGPR:$Rd, CPSR, (opnode t2_so_reg:$ShiftedRm,
909 Sched<[WriteALUsi, ReadALU]>;
913 /// T2I_bin_ii12rs - Defines a set of (op reg, {so_imm|imm0_4095|r|so_reg})
914 /// patterns for a binary operation that produces a value.
915 multiclass T2I_bin_ii12rs<bits<3> op23_21, string opc, SDNode opnode,
916 bit Commutable = 0> {
918 // The register-immediate version is re-materializable. This is useful
919 // in particular for taking the address of a local.
920 let isReMaterializable = 1 in {
921 def spImm : T2sTwoRegImm<
922 (outs GPRsp:$Rd), (ins GPRsp:$Rn, t2_so_imm:$imm), IIC_iALUi,
923 opc, ".w\t$Rd, $Rn, $imm",
925 Sched<[WriteALU, ReadALU]> {
929 let Inst{31-27} = 0b11110;
930 let Inst{25-24} = 0b01;
931 let Inst{23-21} = op23_21;
934 let DecoderMethod = "DecodeT2AddSubSPImm";
937 def ri : T2sTwoRegImm<
938 (outs rGPR:$Rd), (ins GPRnopc:$Rn, t2_so_imm:$imm), IIC_iALUi,
939 opc, ".w\t$Rd, $Rn, $imm",
940 [(set rGPR:$Rd, (opnode GPRnopc:$Rn, t2_so_imm:$imm))]>,
941 Sched<[WriteALU, ReadALU]> {
942 let Inst{31-27} = 0b11110;
945 let Inst{23-21} = op23_21;
951 (outs rGPR:$Rd), (ins GPR:$Rn, imm0_4095:$imm), IIC_iALUi,
952 !strconcat(opc, "w"), "\t$Rd, $Rn, $imm",
953 [(set rGPR:$Rd, (opnode GPR:$Rn, imm0_4095:$imm))]>,
954 Sched<[WriteALU, ReadALU]> {
958 let Inst{31-27} = 0b11110;
959 let Inst{26} = imm{11};
960 let Inst{25-24} = 0b10;
961 let Inst{23-21} = op23_21;
962 let Inst{20} = 0; // The S bit.
963 let Inst{19-16} = Rn;
965 let Inst{14-12} = imm{10-8};
967 let Inst{7-0} = imm{7-0};
970 (outs GPRsp:$Rd), (ins GPRsp:$Rn, imm0_4095:$imm), IIC_iALUi,
971 !strconcat(opc, "w"), "\t$Rd, $Rn, $imm",
973 Sched<[WriteALU, ReadALU]> {
977 let Inst{31-27} = 0b11110;
978 let Inst{26} = imm{11};
979 let Inst{25-24} = 0b10;
980 let Inst{23-21} = op23_21;
981 let Inst{20} = 0; // The S bit.
982 let Inst{19-16} = Rn;
984 let Inst{14-12} = imm{10-8};
986 let Inst{7-0} = imm{7-0};
987 let DecoderMethod = "DecodeT2AddSubSPImm";
990 def rr : T2sThreeReg<(outs GPRnopc:$Rd), (ins GPRnopc:$Rn, rGPR:$Rm),
991 IIC_iALUr, opc, ".w\t$Rd, $Rn, $Rm",
992 [(set GPRnopc:$Rd, (opnode GPRnopc:$Rn, rGPR:$Rm))]>,
993 Sched<[WriteALU, ReadALU, ReadALU]> {
994 let isCommutable = Commutable;
995 let Inst{31-27} = 0b11101;
996 let Inst{26-25} = 0b01;
998 let Inst{23-21} = op23_21;
999 let Inst{14-12} = 0b000; // imm3
1000 let Inst{7-6} = 0b00; // imm2
1001 let Inst{5-4} = 0b00; // type
1004 def rs : T2sTwoRegShiftedReg<
1005 (outs GPRnopc:$Rd), (ins GPRnopc:$Rn, t2_so_reg:$ShiftedRm),
1006 IIC_iALUsi, opc, ".w\t$Rd, $Rn, $ShiftedRm",
1007 [(set GPRnopc:$Rd, (opnode GPRnopc:$Rn, t2_so_reg:$ShiftedRm))]>,
1008 Sched<[WriteALUsi, ReadALU]> {
1009 let Inst{31-27} = 0b11101;
1010 let Inst{26-25} = 0b01;
1012 let Inst{23-21} = op23_21;
1016 /// T2I_adde_sube_irs - Defines a set of (op reg, {so_imm|r|so_reg}) patterns
1017 /// for a binary operation that produces a value and use the carry
1018 /// bit. It's not predicable.
1019 let Defs = [CPSR], Uses = [CPSR] in {
1020 multiclass T2I_adde_sube_irs<bits<4> opcod, string opc, SDNode opnode,
1021 bit Commutable = 0> {
1023 def ri : T2sTwoRegImm<(outs rGPR:$Rd), (ins rGPR:$Rn, t2_so_imm:$imm),
1024 IIC_iALUi, opc, "\t$Rd, $Rn, $imm",
1025 [(set rGPR:$Rd, CPSR, (opnode rGPR:$Rn, t2_so_imm:$imm, CPSR))]>,
1026 Requires<[IsThumb2]>, Sched<[WriteALU, ReadALU]> {
1027 let Inst{31-27} = 0b11110;
1029 let Inst{24-21} = opcod;
1033 def rr : T2sThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iALUr,
1034 opc, ".w\t$Rd, $Rn, $Rm",
1035 [(set rGPR:$Rd, CPSR, (opnode rGPR:$Rn, rGPR:$Rm, CPSR))]>,
1036 Requires<[IsThumb2]>, Sched<[WriteALU, ReadALU, ReadALU]> {
1037 let isCommutable = Commutable;
1038 let Inst{31-27} = 0b11101;
1039 let Inst{26-25} = 0b01;
1040 let Inst{24-21} = opcod;
1041 let Inst{14-12} = 0b000; // imm3
1042 let Inst{7-6} = 0b00; // imm2
1043 let Inst{5-4} = 0b00; // type
1046 def rs : T2sTwoRegShiftedReg<
1047 (outs rGPR:$Rd), (ins rGPR:$Rn, t2_so_reg:$ShiftedRm),
1048 IIC_iALUsi, opc, ".w\t$Rd, $Rn, $ShiftedRm",
1049 [(set rGPR:$Rd, CPSR, (opnode rGPR:$Rn, t2_so_reg:$ShiftedRm, CPSR))]>,
1050 Requires<[IsThumb2]>, Sched<[WriteALUsi, ReadALU]> {
1051 let Inst{31-27} = 0b11101;
1052 let Inst{26-25} = 0b01;
1053 let Inst{24-21} = opcod;
1058 /// T2I_sh_ir - Defines a set of (op reg, {so_imm|r}) patterns for a shift /
1059 // rotate operation that produces a value.
1060 multiclass T2I_sh_ir<bits<2> opcod, string opc, Operand ty, SDNode opnode> {
1062 def ri : T2sTwoRegShiftImm<
1063 (outs rGPR:$Rd), (ins rGPR:$Rm, ty:$imm), IIC_iMOVsi,
1064 opc, ".w\t$Rd, $Rm, $imm",
1065 [(set rGPR:$Rd, (opnode rGPR:$Rm, (i32 ty:$imm)))]>,
1067 let Inst{31-27} = 0b11101;
1068 let Inst{26-21} = 0b010010;
1069 let Inst{19-16} = 0b1111; // Rn
1071 let Inst{5-4} = opcod;
1074 def rr : T2sThreeReg<
1075 (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iMOVsr,
1076 opc, ".w\t$Rd, $Rn, $Rm",
1077 [(set rGPR:$Rd, (opnode rGPR:$Rn, rGPR:$Rm))]>,
1079 let Inst{31-27} = 0b11111;
1080 let Inst{26-23} = 0b0100;
1081 let Inst{22-21} = opcod;
1082 let Inst{15-12} = 0b1111;
1083 let Inst{7-4} = 0b0000;
1086 // Optional destination register
1087 def : t2InstAlias<!strconcat(opc, "${s}${p}", ".w $Rdn, $imm"),
1088 (!cast<Instruction>(NAME#"ri") rGPR:$Rdn, rGPR:$Rdn, ty:$imm, pred:$p,
1090 def : t2InstAlias<!strconcat(opc, "${s}${p}", ".w $Rdn, $Rm"),
1091 (!cast<Instruction>(NAME#"rr") rGPR:$Rdn, rGPR:$Rdn, rGPR:$Rm, pred:$p,
1094 // Assembler aliases w/o the ".w" suffix.
1095 def : t2InstAlias<!strconcat(opc, "${s}${p}", " $Rd, $Rn, $imm"),
1096 (!cast<Instruction>(NAME#"ri") rGPR:$Rd, rGPR:$Rn, ty:$imm, pred:$p,
1098 def : t2InstAlias<!strconcat(opc, "${s}${p}", " $Rd, $Rn, $Rm"),
1099 (!cast<Instruction>(NAME#"rr") rGPR:$Rd, rGPR:$Rn, rGPR:$Rm, pred:$p,
1102 // and with the optional destination operand, too.
1103 def : t2InstAlias<!strconcat(opc, "${s}${p}", " $Rdn, $imm"),
1104 (!cast<Instruction>(NAME#"ri") rGPR:$Rdn, rGPR:$Rdn, ty:$imm, pred:$p,
1106 def : t2InstAlias<!strconcat(opc, "${s}${p}", " $Rdn, $Rm"),
1107 (!cast<Instruction>(NAME#"rr") rGPR:$Rdn, rGPR:$Rdn, rGPR:$Rm, pred:$p,
1111 /// T2I_cmp_irs - Defines a set of (op r, {so_imm|r|so_reg}) cmp / test
1112 /// patterns. Similar to T2I_bin_irs except the instruction does not produce
1113 /// a explicit result, only implicitly set CPSR.
1114 multiclass T2I_cmp_irs<bits<4> opcod, string opc, RegisterClass LHSGPR,
1115 InstrItinClass iii, InstrItinClass iir, InstrItinClass iis,
1116 SDPatternOperator opnode> {
1117 let isCompare = 1, Defs = [CPSR] in {
1119 def ri : T2OneRegCmpImm<
1120 (outs), (ins LHSGPR:$Rn, t2_so_imm:$imm), iii,
1121 opc, ".w\t$Rn, $imm",
1122 [(opnode LHSGPR:$Rn, t2_so_imm:$imm)]>, Sched<[WriteCMP]> {
1123 let Inst{31-27} = 0b11110;
1125 let Inst{24-21} = opcod;
1126 let Inst{20} = 1; // The S bit.
1128 let Inst{11-8} = 0b1111; // Rd
1131 def rr : T2TwoRegCmp<
1132 (outs), (ins LHSGPR:$Rn, rGPR:$Rm), iir,
1133 opc, ".w\t$Rn, $Rm",
1134 [(opnode LHSGPR:$Rn, rGPR:$Rm)]>, Sched<[WriteCMP]> {
1135 let Inst{31-27} = 0b11101;
1136 let Inst{26-25} = 0b01;
1137 let Inst{24-21} = opcod;
1138 let Inst{20} = 1; // The S bit.
1139 let Inst{14-12} = 0b000; // imm3
1140 let Inst{11-8} = 0b1111; // Rd
1141 let Inst{7-6} = 0b00; // imm2
1142 let Inst{5-4} = 0b00; // type
1145 def rs : T2OneRegCmpShiftedReg<
1146 (outs), (ins LHSGPR:$Rn, t2_so_reg:$ShiftedRm), iis,
1147 opc, ".w\t$Rn, $ShiftedRm",
1148 [(opnode LHSGPR:$Rn, t2_so_reg:$ShiftedRm)]>,
1149 Sched<[WriteCMPsi]> {
1150 let Inst{31-27} = 0b11101;
1151 let Inst{26-25} = 0b01;
1152 let Inst{24-21} = opcod;
1153 let Inst{20} = 1; // The S bit.
1154 let Inst{11-8} = 0b1111; // Rd
1158 // Assembler aliases w/o the ".w" suffix.
1159 // No alias here for 'rr' version as not all instantiations of this
1160 // multiclass want one (CMP in particular, does not).
1161 def : t2InstAlias<!strconcat(opc, "${p}", " $Rn, $imm"),
1162 (!cast<Instruction>(NAME#"ri") LHSGPR:$Rn, t2_so_imm:$imm, pred:$p)>;
1163 def : t2InstAlias<!strconcat(opc, "${p}", " $Rn, $shift"),
1164 (!cast<Instruction>(NAME#"rs") LHSGPR:$Rn, t2_so_reg:$shift, pred:$p)>;
1167 /// T2I_ld - Defines a set of (op r, {imm12|imm8|so_reg}) load patterns.
1168 multiclass T2I_ld<bit signed, bits<2> opcod, string opc,
1169 InstrItinClass iii, InstrItinClass iis, RegisterClass target,
1171 def i12 : T2Ii12<(outs target:$Rt), (ins t2addrmode_imm12:$addr), iii,
1172 opc, ".w\t$Rt, $addr",
1173 [(set target:$Rt, (opnode t2addrmode_imm12:$addr))]>,
1177 let Inst{31-25} = 0b1111100;
1178 let Inst{24} = signed;
1180 let Inst{22-21} = opcod;
1181 let Inst{20} = 1; // load
1182 let Inst{19-16} = addr{16-13}; // Rn
1183 let Inst{15-12} = Rt;
1184 let Inst{11-0} = addr{11-0}; // imm
1186 let DecoderMethod = "DecodeT2LoadImm12";
1188 def i8 : T2Ii8 <(outs target:$Rt), (ins t2addrmode_negimm8:$addr), iii,
1189 opc, "\t$Rt, $addr",
1190 [(set target:$Rt, (opnode t2addrmode_negimm8:$addr))]>,
1194 let Inst{31-27} = 0b11111;
1195 let Inst{26-25} = 0b00;
1196 let Inst{24} = signed;
1198 let Inst{22-21} = opcod;
1199 let Inst{20} = 1; // load
1200 let Inst{19-16} = addr{12-9}; // Rn
1201 let Inst{15-12} = Rt;
1203 // Offset: index==TRUE, wback==FALSE
1204 let Inst{10} = 1; // The P bit.
1205 let Inst{9} = addr{8}; // U
1206 let Inst{8} = 0; // The W bit.
1207 let Inst{7-0} = addr{7-0}; // imm
1209 let DecoderMethod = "DecodeT2LoadImm8";
1211 def s : T2Iso <(outs target:$Rt), (ins t2addrmode_so_reg:$addr), iis,
1212 opc, ".w\t$Rt, $addr",
1213 [(set target:$Rt, (opnode t2addrmode_so_reg:$addr))]>,
1215 let Inst{31-27} = 0b11111;
1216 let Inst{26-25} = 0b00;
1217 let Inst{24} = signed;
1219 let Inst{22-21} = opcod;
1220 let Inst{20} = 1; // load
1221 let Inst{11-6} = 0b000000;
1224 let Inst{15-12} = Rt;
1227 let Inst{19-16} = addr{9-6}; // Rn
1228 let Inst{3-0} = addr{5-2}; // Rm
1229 let Inst{5-4} = addr{1-0}; // imm
1231 let DecoderMethod = "DecodeT2LoadShift";
1234 // pci variant is very similar to i12, but supports negative offsets
1236 def pci : T2Ipc <(outs target:$Rt), (ins t2ldrlabel:$addr), iii,
1237 opc, ".w\t$Rt, $addr",
1238 [(set target:$Rt, (opnode (ARMWrapper tconstpool:$addr)))]>,
1240 let isReMaterializable = 1;
1241 let Inst{31-27} = 0b11111;
1242 let Inst{26-25} = 0b00;
1243 let Inst{24} = signed;
1244 let Inst{22-21} = opcod;
1245 let Inst{20} = 1; // load
1246 let Inst{19-16} = 0b1111; // Rn
1249 let Inst{15-12} = Rt{3-0};
1252 let Inst{23} = addr{12}; // add = (U == '1')
1253 let Inst{11-0} = addr{11-0};
1255 let DecoderMethod = "DecodeT2LoadLabel";
1259 /// T2I_st - Defines a set of (op r, {imm12|imm8|so_reg}) store patterns.
1260 multiclass T2I_st<bits<2> opcod, string opc,
1261 InstrItinClass iii, InstrItinClass iis, RegisterClass target,
1263 def i12 : T2Ii12<(outs), (ins target:$Rt, t2addrmode_imm12:$addr), iii,
1264 opc, ".w\t$Rt, $addr",
1265 [(opnode target:$Rt, t2addrmode_imm12:$addr)]>,
1267 let Inst{31-27} = 0b11111;
1268 let Inst{26-23} = 0b0001;
1269 let Inst{22-21} = opcod;
1270 let Inst{20} = 0; // !load
1273 let Inst{15-12} = Rt;
1276 let addr{12} = 1; // add = TRUE
1277 let Inst{19-16} = addr{16-13}; // Rn
1278 let Inst{23} = addr{12}; // U
1279 let Inst{11-0} = addr{11-0}; // imm
1281 def i8 : T2Ii8 <(outs), (ins target:$Rt, t2addrmode_negimm8:$addr), iii,
1282 opc, "\t$Rt, $addr",
1283 [(opnode target:$Rt, t2addrmode_negimm8:$addr)]>,
1285 let Inst{31-27} = 0b11111;
1286 let Inst{26-23} = 0b0000;
1287 let Inst{22-21} = opcod;
1288 let Inst{20} = 0; // !load
1290 // Offset: index==TRUE, wback==FALSE
1291 let Inst{10} = 1; // The P bit.
1292 let Inst{8} = 0; // The W bit.
1295 let Inst{15-12} = Rt;
1298 let Inst{19-16} = addr{12-9}; // Rn
1299 let Inst{9} = addr{8}; // U
1300 let Inst{7-0} = addr{7-0}; // imm
1302 def s : T2Iso <(outs), (ins target:$Rt, t2addrmode_so_reg:$addr), iis,
1303 opc, ".w\t$Rt, $addr",
1304 [(opnode target:$Rt, t2addrmode_so_reg:$addr)]>,
1306 let Inst{31-27} = 0b11111;
1307 let Inst{26-23} = 0b0000;
1308 let Inst{22-21} = opcod;
1309 let Inst{20} = 0; // !load
1310 let Inst{11-6} = 0b000000;
1313 let Inst{15-12} = Rt;
1316 let Inst{19-16} = addr{9-6}; // Rn
1317 let Inst{3-0} = addr{5-2}; // Rm
1318 let Inst{5-4} = addr{1-0}; // imm
1322 /// T2I_ext_rrot - A unary operation with two forms: one whose operand is a
1323 /// register and one whose operand is a register rotated by 8/16/24.
1324 class T2I_ext_rrot_base<bits<3> opcod, dag iops, dag oops,
1325 string opc, string oprs,
1327 : T2TwoReg<iops, oops, IIC_iEXTr, opc, oprs, pattern> {
1329 let Inst{31-27} = 0b11111;
1330 let Inst{26-23} = 0b0100;
1331 let Inst{22-20} = opcod;
1332 let Inst{19-16} = 0b1111; // Rn
1333 let Inst{15-12} = 0b1111;
1335 let Inst{5-4} = rot; // rotate
1338 class T2I_ext_rrot<bits<3> opcod, string opc>
1339 : T2I_ext_rrot_base<opcod,
1341 (ins rGPR:$Rm, rot_imm:$rot),
1342 opc, ".w\t$Rd, $Rm$rot", []>,
1343 Requires<[IsThumb2]>,
1344 Sched<[WriteALU, ReadALU]>;
1346 // UXTB16, SXTB16 - Requires HasDSP, does not need the .w qualifier.
1347 class T2I_ext_rrot_xtb16<bits<3> opcod, string opc>
1348 : T2I_ext_rrot_base<opcod,
1350 (ins rGPR:$Rm, rot_imm:$rot),
1351 opc, "\t$Rd, $Rm$rot", []>,
1352 Requires<[HasDSP, IsThumb2]>,
1353 Sched<[WriteALU, ReadALU]>;
1355 /// T2I_exta_rrot - A binary operation with two forms: one whose operand is a
1356 /// register and one whose operand is a register rotated by 8/16/24.
1357 class T2I_exta_rrot<bits<3> opcod, string opc>
1358 : T2ThreeReg<(outs rGPR:$Rd),
1359 (ins rGPR:$Rn, rGPR:$Rm, rot_imm:$rot),
1360 IIC_iEXTAsr, opc, "\t$Rd, $Rn, $Rm$rot", []>,
1361 Requires<[HasDSP, IsThumb2]>,
1362 Sched<[WriteALU, ReadALU]> {
1364 let Inst{31-27} = 0b11111;
1365 let Inst{26-23} = 0b0100;
1366 let Inst{22-20} = opcod;
1367 let Inst{15-12} = 0b1111;
1369 let Inst{5-4} = rot;
1372 //===----------------------------------------------------------------------===//
1374 //===----------------------------------------------------------------------===//
1376 //===----------------------------------------------------------------------===//
1377 // Miscellaneous Instructions.
1380 class T2PCOneRegImm<dag oops, dag iops, InstrItinClass itin,
1381 string asm, list<dag> pattern>
1382 : T2XI<oops, iops, itin, asm, pattern> {
1386 let Inst{11-8} = Rd;
1387 let Inst{26} = label{11};
1388 let Inst{14-12} = label{10-8};
1389 let Inst{7-0} = label{7-0};
1392 // LEApcrel - Load a pc-relative address into a register without offending the
1394 def t2ADR : T2PCOneRegImm<(outs rGPR:$Rd),
1395 (ins t2adrlabel:$addr, pred:$p),
1396 IIC_iALUi, "adr{$p}.w\t$Rd, $addr", []>,
1397 Sched<[WriteALU, ReadALU]> {
1398 let Inst{31-27} = 0b11110;
1399 let Inst{25-24} = 0b10;
1400 // Inst{23:21} = '11' (add = FALSE) or '00' (add = TRUE)
1403 let Inst{19-16} = 0b1111; // Rn
1408 let Inst{11-8} = Rd;
1409 let Inst{23} = addr{12};
1410 let Inst{21} = addr{12};
1411 let Inst{26} = addr{11};
1412 let Inst{14-12} = addr{10-8};
1413 let Inst{7-0} = addr{7-0};
1415 let DecoderMethod = "DecodeT2Adr";
1418 let hasSideEffects = 0, isReMaterializable = 1 in
1419 def t2LEApcrel : t2PseudoInst<(outs rGPR:$Rd), (ins i32imm:$label, pred:$p),
1420 4, IIC_iALUi, []>, Sched<[WriteALU, ReadALU]>;
1421 let hasSideEffects = 1 in
1422 def t2LEApcrelJT : t2PseudoInst<(outs rGPR:$Rd),
1423 (ins i32imm:$label, pred:$p),
1425 []>, Sched<[WriteALU, ReadALU]>;
1428 //===----------------------------------------------------------------------===//
1429 // Load / store Instructions.
1433 let canFoldAsLoad = 1, isReMaterializable = 1 in
1434 defm t2LDR : T2I_ld<0, 0b10, "ldr", IIC_iLoad_i, IIC_iLoad_si, GPR, load>;
1436 // Loads with zero extension
1437 defm t2LDRH : T2I_ld<0, 0b01, "ldrh", IIC_iLoad_bh_i, IIC_iLoad_bh_si,
1438 GPRnopc, zextloadi16>;
1439 defm t2LDRB : T2I_ld<0, 0b00, "ldrb", IIC_iLoad_bh_i, IIC_iLoad_bh_si,
1440 GPRnopc, zextloadi8>;
1442 // Loads with sign extension
1443 defm t2LDRSH : T2I_ld<1, 0b01, "ldrsh", IIC_iLoad_bh_i, IIC_iLoad_bh_si,
1444 GPRnopc, sextloadi16>;
1445 defm t2LDRSB : T2I_ld<1, 0b00, "ldrsb", IIC_iLoad_bh_i, IIC_iLoad_bh_si,
1446 GPRnopc, sextloadi8>;
1448 let mayLoad = 1, hasSideEffects = 0, hasExtraDefRegAllocReq = 1 in {
1450 def t2LDRDi8 : T2Ii8s4<1, 0, 1, (outs rGPR:$Rt, rGPR:$Rt2),
1451 (ins t2addrmode_imm8s4:$addr),
1452 IIC_iLoad_d_i, "ldrd", "\t$Rt, $Rt2, $addr", "",
1453 [(set rGPR:$Rt, rGPR:$Rt2, (ARMldrd t2addrmode_imm8s4:$addr))]>,
1455 } // mayLoad = 1, hasSideEffects = 0, hasExtraDefRegAllocReq = 1
1457 // zextload i1 -> zextload i8
1458 def : T2Pat<(zextloadi1 t2addrmode_imm12:$addr),
1459 (t2LDRBi12 t2addrmode_imm12:$addr)>;
1460 def : T2Pat<(zextloadi1 t2addrmode_negimm8:$addr),
1461 (t2LDRBi8 t2addrmode_negimm8:$addr)>;
1462 def : T2Pat<(zextloadi1 t2addrmode_so_reg:$addr),
1463 (t2LDRBs t2addrmode_so_reg:$addr)>;
1464 def : T2Pat<(zextloadi1 (ARMWrapper tconstpool:$addr)),
1465 (t2LDRBpci tconstpool:$addr)>;
1467 // extload -> zextload
1468 // FIXME: Reduce the number of patterns by legalizing extload to zextload
1470 def : T2Pat<(extloadi1 t2addrmode_imm12:$addr),
1471 (t2LDRBi12 t2addrmode_imm12:$addr)>;
1472 def : T2Pat<(extloadi1 t2addrmode_negimm8:$addr),
1473 (t2LDRBi8 t2addrmode_negimm8:$addr)>;
1474 def : T2Pat<(extloadi1 t2addrmode_so_reg:$addr),
1475 (t2LDRBs t2addrmode_so_reg:$addr)>;
1476 def : T2Pat<(extloadi1 (ARMWrapper tconstpool:$addr)),
1477 (t2LDRBpci tconstpool:$addr)>;
1479 def : T2Pat<(extloadi8 t2addrmode_imm12:$addr),
1480 (t2LDRBi12 t2addrmode_imm12:$addr)>;
1481 def : T2Pat<(extloadi8 t2addrmode_negimm8:$addr),
1482 (t2LDRBi8 t2addrmode_negimm8:$addr)>;
1483 def : T2Pat<(extloadi8 t2addrmode_so_reg:$addr),
1484 (t2LDRBs t2addrmode_so_reg:$addr)>;
1485 def : T2Pat<(extloadi8 (ARMWrapper tconstpool:$addr)),
1486 (t2LDRBpci tconstpool:$addr)>;
1488 def : T2Pat<(extloadi16 t2addrmode_imm12:$addr),
1489 (t2LDRHi12 t2addrmode_imm12:$addr)>;
1490 def : T2Pat<(extloadi16 t2addrmode_negimm8:$addr),
1491 (t2LDRHi8 t2addrmode_negimm8:$addr)>;
1492 def : T2Pat<(extloadi16 t2addrmode_so_reg:$addr),
1493 (t2LDRHs t2addrmode_so_reg:$addr)>;
1494 def : T2Pat<(extloadi16 (ARMWrapper tconstpool:$addr)),
1495 (t2LDRHpci tconstpool:$addr)>;
1497 // FIXME: The destination register of the loads and stores can't be PC, but
1498 // can be SP. We need another regclass (similar to rGPR) to represent
1499 // that. Not a pressing issue since these are selected manually,
1504 let mayLoad = 1, hasSideEffects = 0 in {
1505 def t2LDR_PRE : T2Ipreldst<0, 0b10, 1, 1, (outs GPR:$Rt, GPR:$Rn_wb),
1506 (ins t2addrmode_imm8_pre:$addr),
1507 AddrModeT2_i8, IndexModePre, IIC_iLoad_iu,
1508 "ldr", "\t$Rt, $addr!", "$addr.base = $Rn_wb", []>,
1511 def t2LDR_POST : T2Ipostldst<0, 0b10, 1, 0, (outs GPR:$Rt, GPR:$Rn_wb),
1512 (ins addr_offset_none:$Rn, t2am_imm8_offset:$offset),
1513 AddrModeT2_i8, IndexModePost, IIC_iLoad_iu,
1514 "ldr", "\t$Rt, $Rn$offset", "$Rn = $Rn_wb", []>,
1517 def t2LDRB_PRE : T2Ipreldst<0, 0b00, 1, 1, (outs GPR:$Rt, GPR:$Rn_wb),
1518 (ins t2addrmode_imm8_pre:$addr),
1519 AddrModeT2_i8, IndexModePre, IIC_iLoad_bh_iu,
1520 "ldrb", "\t$Rt, $addr!", "$addr.base = $Rn_wb", []>,
1523 def t2LDRB_POST : T2Ipostldst<0, 0b00, 1, 0, (outs GPR:$Rt, GPR:$Rn_wb),
1524 (ins addr_offset_none:$Rn, t2am_imm8_offset:$offset),
1525 AddrModeT2_i8, IndexModePost, IIC_iLoad_bh_iu,
1526 "ldrb", "\t$Rt, $Rn$offset", "$Rn = $Rn_wb", []>,
1529 def t2LDRH_PRE : T2Ipreldst<0, 0b01, 1, 1, (outs GPR:$Rt, GPR:$Rn_wb),
1530 (ins t2addrmode_imm8_pre:$addr),
1531 AddrModeT2_i8, IndexModePre, IIC_iLoad_bh_iu,
1532 "ldrh", "\t$Rt, $addr!", "$addr.base = $Rn_wb", []>,
1535 def t2LDRH_POST : T2Ipostldst<0, 0b01, 1, 0, (outs GPR:$Rt, GPR:$Rn_wb),
1536 (ins addr_offset_none:$Rn, t2am_imm8_offset:$offset),
1537 AddrModeT2_i8, IndexModePost, IIC_iLoad_bh_iu,
1538 "ldrh", "\t$Rt, $Rn$offset", "$Rn = $Rn_wb", []>,
1541 def t2LDRSB_PRE : T2Ipreldst<1, 0b00, 1, 1, (outs GPR:$Rt, GPR:$Rn_wb),
1542 (ins t2addrmode_imm8_pre:$addr),
1543 AddrModeT2_i8, IndexModePre, IIC_iLoad_bh_iu,
1544 "ldrsb", "\t$Rt, $addr!", "$addr.base = $Rn_wb",
1545 []>, Sched<[WriteLd]>;
1547 def t2LDRSB_POST : T2Ipostldst<1, 0b00, 1, 0, (outs GPR:$Rt, GPR:$Rn_wb),
1548 (ins addr_offset_none:$Rn, t2am_imm8_offset:$offset),
1549 AddrModeT2_i8, IndexModePost, IIC_iLoad_bh_iu,
1550 "ldrsb", "\t$Rt, $Rn$offset", "$Rn = $Rn_wb", []>,
1553 def t2LDRSH_PRE : T2Ipreldst<1, 0b01, 1, 1, (outs GPR:$Rt, GPR:$Rn_wb),
1554 (ins t2addrmode_imm8_pre:$addr),
1555 AddrModeT2_i8, IndexModePre, IIC_iLoad_bh_iu,
1556 "ldrsh", "\t$Rt, $addr!", "$addr.base = $Rn_wb",
1557 []>, Sched<[WriteLd]>;
1559 def t2LDRSH_POST : T2Ipostldst<1, 0b01, 1, 0, (outs GPR:$Rt, GPR:$Rn_wb),
1560 (ins addr_offset_none:$Rn, t2am_imm8_offset:$offset),
1561 AddrModeT2_i8, IndexModePost, IIC_iLoad_bh_iu,
1562 "ldrsh", "\t$Rt, $Rn$offset", "$Rn = $Rn_wb", []>,
1564 } // mayLoad = 1, hasSideEffects = 0
1566 // LDRT, LDRBT, LDRHT, LDRSBT, LDRSHT all have offset mode (PUW=0b110).
1567 // Ref: A8.6.57 LDR (immediate, Thumb) Encoding T4
1568 class T2IldT<bit signed, bits<2> type, string opc, InstrItinClass ii>
1569 : T2Ii8<(outs rGPR:$Rt), (ins t2addrmode_posimm8:$addr), ii, opc,
1570 "\t$Rt, $addr", []>, Sched<[WriteLd]> {
1573 let Inst{31-27} = 0b11111;
1574 let Inst{26-25} = 0b00;
1575 let Inst{24} = signed;
1577 let Inst{22-21} = type;
1578 let Inst{20} = 1; // load
1579 let Inst{19-16} = addr{12-9};
1580 let Inst{15-12} = Rt;
1582 let Inst{10-8} = 0b110; // PUW.
1583 let Inst{7-0} = addr{7-0};
1585 let DecoderMethod = "DecodeT2LoadT";
1588 def t2LDRT : T2IldT<0, 0b10, "ldrt", IIC_iLoad_i>;
1589 def t2LDRBT : T2IldT<0, 0b00, "ldrbt", IIC_iLoad_bh_i>;
1590 def t2LDRHT : T2IldT<0, 0b01, "ldrht", IIC_iLoad_bh_i>;
1591 def t2LDRSBT : T2IldT<1, 0b00, "ldrsbt", IIC_iLoad_bh_i>;
1592 def t2LDRSHT : T2IldT<1, 0b01, "ldrsht", IIC_iLoad_bh_i>;
1594 class T2Ildacq<bits<4> bits23_20, bits<2> bit54, dag oops, dag iops,
1595 string opc, string asm, list<dag> pattern>
1596 : Thumb2I<oops, iops, AddrModeNone, 4, NoItinerary,
1597 opc, asm, "", pattern>, Requires<[IsThumb, HasAcquireRelease]> {
1601 let Inst{31-27} = 0b11101;
1602 let Inst{26-24} = 0b000;
1603 let Inst{23-20} = bits23_20;
1604 let Inst{11-6} = 0b111110;
1605 let Inst{5-4} = bit54;
1606 let Inst{3-0} = 0b1111;
1608 // Encode instruction operands
1609 let Inst{19-16} = addr;
1610 let Inst{15-12} = Rt;
1613 def t2LDA : T2Ildacq<0b1101, 0b10, (outs rGPR:$Rt),
1614 (ins addr_offset_none:$addr), "lda", "\t$Rt, $addr", []>,
1616 def t2LDAB : T2Ildacq<0b1101, 0b00, (outs rGPR:$Rt),
1617 (ins addr_offset_none:$addr), "ldab", "\t$Rt, $addr", []>,
1619 def t2LDAH : T2Ildacq<0b1101, 0b01, (outs rGPR:$Rt),
1620 (ins addr_offset_none:$addr), "ldah", "\t$Rt, $addr", []>,
1624 defm t2STR :T2I_st<0b10,"str", IIC_iStore_i, IIC_iStore_si, GPR, store>;
1625 defm t2STRB:T2I_st<0b00,"strb", IIC_iStore_bh_i, IIC_iStore_bh_si,
1626 rGPR, truncstorei8>;
1627 defm t2STRH:T2I_st<0b01,"strh", IIC_iStore_bh_i, IIC_iStore_bh_si,
1628 rGPR, truncstorei16>;
1631 let mayStore = 1, hasSideEffects = 0, hasExtraSrcRegAllocReq = 1 in
1632 def t2STRDi8 : T2Ii8s4<1, 0, 0, (outs),
1633 (ins rGPR:$Rt, rGPR:$Rt2, t2addrmode_imm8s4:$addr),
1634 IIC_iStore_d_r, "strd", "\t$Rt, $Rt2, $addr", "",
1635 [(ARMstrd rGPR:$Rt, rGPR:$Rt2, t2addrmode_imm8s4:$addr)]>,
1640 let mayStore = 1, hasSideEffects = 0 in {
1641 def t2STR_PRE : T2Ipreldst<0, 0b10, 0, 1, (outs GPRnopc:$Rn_wb),
1642 (ins GPRnopc:$Rt, t2addrmode_imm8_pre:$addr),
1643 AddrModeT2_i8, IndexModePre, IIC_iStore_iu,
1644 "str", "\t$Rt, $addr!",
1645 "$addr.base = $Rn_wb,@earlyclobber $Rn_wb", []>,
1648 def t2STRH_PRE : T2Ipreldst<0, 0b01, 0, 1, (outs GPRnopc:$Rn_wb),
1649 (ins rGPR:$Rt, t2addrmode_imm8_pre:$addr),
1650 AddrModeT2_i8, IndexModePre, IIC_iStore_iu,
1651 "strh", "\t$Rt, $addr!",
1652 "$addr.base = $Rn_wb,@earlyclobber $Rn_wb", []>,
1655 def t2STRB_PRE : T2Ipreldst<0, 0b00, 0, 1, (outs GPRnopc:$Rn_wb),
1656 (ins rGPR:$Rt, t2addrmode_imm8_pre:$addr),
1657 AddrModeT2_i8, IndexModePre, IIC_iStore_bh_iu,
1658 "strb", "\t$Rt, $addr!",
1659 "$addr.base = $Rn_wb,@earlyclobber $Rn_wb", []>,
1661 } // mayStore = 1, hasSideEffects = 0
1663 def t2STR_POST : T2Ipostldst<0, 0b10, 0, 0, (outs GPRnopc:$Rn_wb),
1664 (ins GPRnopc:$Rt, addr_offset_none:$Rn,
1665 t2am_imm8_offset:$offset),
1666 AddrModeT2_i8, IndexModePost, IIC_iStore_iu,
1667 "str", "\t$Rt, $Rn$offset",
1668 "$Rn = $Rn_wb,@earlyclobber $Rn_wb",
1669 [(set GPRnopc:$Rn_wb,
1670 (post_store GPRnopc:$Rt, addr_offset_none:$Rn,
1671 t2am_imm8_offset:$offset))]>,
1674 def t2STRH_POST : T2Ipostldst<0, 0b01, 0, 0, (outs GPRnopc:$Rn_wb),
1675 (ins rGPR:$Rt, addr_offset_none:$Rn,
1676 t2am_imm8_offset:$offset),
1677 AddrModeT2_i8, IndexModePost, IIC_iStore_bh_iu,
1678 "strh", "\t$Rt, $Rn$offset",
1679 "$Rn = $Rn_wb,@earlyclobber $Rn_wb",
1680 [(set GPRnopc:$Rn_wb,
1681 (post_truncsti16 rGPR:$Rt, addr_offset_none:$Rn,
1682 t2am_imm8_offset:$offset))]>,
1685 def t2STRB_POST : T2Ipostldst<0, 0b00, 0, 0, (outs GPRnopc:$Rn_wb),
1686 (ins rGPR:$Rt, addr_offset_none:$Rn,
1687 t2am_imm8_offset:$offset),
1688 AddrModeT2_i8, IndexModePost, IIC_iStore_bh_iu,
1689 "strb", "\t$Rt, $Rn$offset",
1690 "$Rn = $Rn_wb,@earlyclobber $Rn_wb",
1691 [(set GPRnopc:$Rn_wb,
1692 (post_truncsti8 rGPR:$Rt, addr_offset_none:$Rn,
1693 t2am_imm8_offset:$offset))]>,
1696 // Pseudo-instructions for pattern matching the pre-indexed stores. We can't
1697 // put the patterns on the instruction definitions directly as ISel wants
1698 // the address base and offset to be separate operands, not a single
1699 // complex operand like we represent the instructions themselves. The
1700 // pseudos map between the two.
1701 let usesCustomInserter = 1,
1702 Constraints = "$Rn = $Rn_wb,@earlyclobber $Rn_wb" in {
1703 def t2STR_preidx: t2PseudoInst<(outs GPRnopc:$Rn_wb),
1704 (ins rGPR:$Rt, GPRnopc:$Rn, t2am_imm8_offset:$offset, pred:$p),
1706 [(set GPRnopc:$Rn_wb,
1707 (pre_store rGPR:$Rt, GPRnopc:$Rn, t2am_imm8_offset:$offset))]>,
1709 def t2STRB_preidx: t2PseudoInst<(outs GPRnopc:$Rn_wb),
1710 (ins rGPR:$Rt, GPRnopc:$Rn, t2am_imm8_offset:$offset, pred:$p),
1712 [(set GPRnopc:$Rn_wb,
1713 (pre_truncsti8 rGPR:$Rt, GPRnopc:$Rn, t2am_imm8_offset:$offset))]>,
1715 def t2STRH_preidx: t2PseudoInst<(outs GPRnopc:$Rn_wb),
1716 (ins rGPR:$Rt, GPRnopc:$Rn, t2am_imm8_offset:$offset, pred:$p),
1718 [(set GPRnopc:$Rn_wb,
1719 (pre_truncsti16 rGPR:$Rt, GPRnopc:$Rn, t2am_imm8_offset:$offset))]>,
1723 // STRT, STRBT, STRHT all have offset mode (PUW=0b110) and are for disassembly
1725 // Ref: A8.6.193 STR (immediate, Thumb) Encoding T4
1726 class T2IstT<bits<2> type, string opc, InstrItinClass ii>
1727 : T2Ii8<(outs rGPR:$Rt), (ins t2addrmode_imm8:$addr), ii, opc,
1728 "\t$Rt, $addr", []>, Sched<[WriteST]> {
1729 let Inst{31-27} = 0b11111;
1730 let Inst{26-25} = 0b00;
1731 let Inst{24} = 0; // not signed
1733 let Inst{22-21} = type;
1734 let Inst{20} = 0; // store
1736 let Inst{10-8} = 0b110; // PUW
1740 let Inst{15-12} = Rt;
1741 let Inst{19-16} = addr{12-9};
1742 let Inst{7-0} = addr{7-0};
1745 def t2STRT : T2IstT<0b10, "strt", IIC_iStore_i>;
1746 def t2STRBT : T2IstT<0b00, "strbt", IIC_iStore_bh_i>;
1747 def t2STRHT : T2IstT<0b01, "strht", IIC_iStore_bh_i>;
1749 // ldrd / strd pre / post variants
1751 let mayLoad = 1, hasSideEffects = 0 in
1752 def t2LDRD_PRE : T2Ii8s4<1, 1, 1, (outs rGPR:$Rt, rGPR:$Rt2, GPR:$wb),
1753 (ins t2addrmode_imm8s4_pre:$addr), IIC_iLoad_d_ru,
1754 "ldrd", "\t$Rt, $Rt2, $addr!", "$addr.base = $wb", []>,
1756 let DecoderMethod = "DecodeT2LDRDPreInstruction";
1759 let mayLoad = 1, hasSideEffects = 0 in
1760 def t2LDRD_POST : T2Ii8s4post<0, 1, 1, (outs rGPR:$Rt, rGPR:$Rt2, GPR:$wb),
1761 (ins addr_offset_none:$addr, t2am_imm8s4_offset:$imm),
1762 IIC_iLoad_d_ru, "ldrd", "\t$Rt, $Rt2, $addr$imm",
1763 "$addr.base = $wb", []>, Sched<[WriteLd]>;
1765 let mayStore = 1, hasSideEffects = 0 in
1766 def t2STRD_PRE : T2Ii8s4<1, 1, 0, (outs GPR:$wb),
1767 (ins rGPR:$Rt, rGPR:$Rt2, t2addrmode_imm8s4_pre:$addr),
1768 IIC_iStore_d_ru, "strd", "\t$Rt, $Rt2, $addr!",
1769 "$addr.base = $wb", []>, Sched<[WriteST]> {
1770 let DecoderMethod = "DecodeT2STRDPreInstruction";
1773 let mayStore = 1, hasSideEffects = 0 in
1774 def t2STRD_POST : T2Ii8s4post<0, 1, 0, (outs GPR:$wb),
1775 (ins rGPR:$Rt, rGPR:$Rt2, addr_offset_none:$addr,
1776 t2am_imm8s4_offset:$imm),
1777 IIC_iStore_d_ru, "strd", "\t$Rt, $Rt2, $addr$imm",
1778 "$addr.base = $wb", []>, Sched<[WriteST]>;
1780 class T2Istrrel<bits<2> bit54, dag oops, dag iops,
1781 string opc, string asm, list<dag> pattern>
1782 : Thumb2I<oops, iops, AddrModeNone, 4, NoItinerary, opc,
1783 asm, "", pattern>, Requires<[IsThumb, HasAcquireRelease]>,
1788 let Inst{31-27} = 0b11101;
1789 let Inst{26-20} = 0b0001100;
1790 let Inst{11-6} = 0b111110;
1791 let Inst{5-4} = bit54;
1792 let Inst{3-0} = 0b1111;
1794 // Encode instruction operands
1795 let Inst{19-16} = addr;
1796 let Inst{15-12} = Rt;
1799 def t2STL : T2Istrrel<0b10, (outs), (ins rGPR:$Rt, addr_offset_none:$addr),
1800 "stl", "\t$Rt, $addr", []>;
1801 def t2STLB : T2Istrrel<0b00, (outs), (ins rGPR:$Rt, addr_offset_none:$addr),
1802 "stlb", "\t$Rt, $addr", []>;
1803 def t2STLH : T2Istrrel<0b01, (outs), (ins rGPR:$Rt, addr_offset_none:$addr),
1804 "stlh", "\t$Rt, $addr", []>;
1806 // T2Ipl (Preload Data/Instruction) signals the memory system of possible future
1807 // data/instruction access.
1808 // instr_write is inverted for Thumb mode: (prefetch 3) -> (preload 0),
1809 // (prefetch 1) -> (preload 2), (prefetch 2) -> (preload 1).
1810 multiclass T2Ipl<bits<1> write, bits<1> instr, string opc> {
1812 def i12 : T2Ii12<(outs), (ins t2addrmode_imm12:$addr), IIC_Preload, opc,
1814 [(ARMPreload t2addrmode_imm12:$addr, (i32 write), (i32 instr))]>,
1815 Sched<[WritePreLd]> {
1816 let Inst{31-25} = 0b1111100;
1817 let Inst{24} = instr;
1820 let Inst{21} = write;
1822 let Inst{15-12} = 0b1111;
1825 let Inst{19-16} = addr{16-13}; // Rn
1826 let Inst{11-0} = addr{11-0}; // imm12
1828 let DecoderMethod = "DecodeT2LoadImm12";
1831 def i8 : T2Ii8<(outs), (ins t2addrmode_negimm8:$addr), IIC_Preload, opc,
1833 [(ARMPreload t2addrmode_negimm8:$addr, (i32 write), (i32 instr))]>,
1834 Sched<[WritePreLd]> {
1835 let Inst{31-25} = 0b1111100;
1836 let Inst{24} = instr;
1837 let Inst{23} = 0; // U = 0
1839 let Inst{21} = write;
1841 let Inst{15-12} = 0b1111;
1842 let Inst{11-8} = 0b1100;
1845 let Inst{19-16} = addr{12-9}; // Rn
1846 let Inst{7-0} = addr{7-0}; // imm8
1848 let DecoderMethod = "DecodeT2LoadImm8";
1851 def s : T2Iso<(outs), (ins t2addrmode_so_reg:$addr), IIC_Preload, opc,
1853 [(ARMPreload t2addrmode_so_reg:$addr, (i32 write), (i32 instr))]>,
1854 Sched<[WritePreLd]> {
1855 let Inst{31-25} = 0b1111100;
1856 let Inst{24} = instr;
1857 let Inst{23} = 0; // add = TRUE for T1
1859 let Inst{21} = write;
1861 let Inst{15-12} = 0b1111;
1862 let Inst{11-6} = 0b000000;
1865 let Inst{19-16} = addr{9-6}; // Rn
1866 let Inst{3-0} = addr{5-2}; // Rm
1867 let Inst{5-4} = addr{1-0}; // imm2
1869 let DecoderMethod = "DecodeT2LoadShift";
1873 defm t2PLD : T2Ipl<0, 0, "pld">, Requires<[IsThumb2]>;
1874 defm t2PLDW : T2Ipl<1, 0, "pldw">, Requires<[IsThumb2,HasV7,HasMP]>;
1875 defm t2PLI : T2Ipl<0, 1, "pli">, Requires<[IsThumb2,HasV7]>;
1877 // PLD/PLDW/PLI aliases w/ the optional .w suffix
1878 def : t2InstAlias<"pld${p}.w\t$addr",
1879 (t2PLDi12 t2addrmode_imm12:$addr, pred:$p)>;
1880 def : t2InstAlias<"pld${p}.w\t$addr",
1881 (t2PLDi8 t2addrmode_negimm8:$addr, pred:$p)>;
1882 def : t2InstAlias<"pld${p}.w\t$addr",
1883 (t2PLDs t2addrmode_so_reg:$addr, pred:$p)>;
1885 def : InstAlias<"pldw${p}.w\t$addr",
1886 (t2PLDWi12 t2addrmode_imm12:$addr, pred:$p), 0>,
1887 Requires<[IsThumb2,HasV7,HasMP]>;
1888 def : InstAlias<"pldw${p}.w\t$addr",
1889 (t2PLDWi8 t2addrmode_negimm8:$addr, pred:$p), 0>,
1890 Requires<[IsThumb2,HasV7,HasMP]>;
1891 def : InstAlias<"pldw${p}.w\t$addr",
1892 (t2PLDWs t2addrmode_so_reg:$addr, pred:$p), 0>,
1893 Requires<[IsThumb2,HasV7,HasMP]>;
1895 def : InstAlias<"pli${p}.w\t$addr",
1896 (t2PLIi12 t2addrmode_imm12:$addr, pred:$p), 0>,
1897 Requires<[IsThumb2,HasV7]>;
1898 def : InstAlias<"pli${p}.w\t$addr",
1899 (t2PLIi8 t2addrmode_negimm8:$addr, pred:$p), 0>,
1900 Requires<[IsThumb2,HasV7]>;
1901 def : InstAlias<"pli${p}.w\t$addr",
1902 (t2PLIs t2addrmode_so_reg:$addr, pred:$p), 0>,
1903 Requires<[IsThumb2,HasV7]>;
1905 // pci variant is very similar to i12, but supports negative offsets
1906 // from the PC. Only PLD and PLI have pci variants (not PLDW)
1907 class T2Iplpci<bits<1> inst, string opc> : T2Iso<(outs), (ins t2ldrlabel:$addr),
1908 IIC_Preload, opc, "\t$addr",
1909 [(ARMPreload (ARMWrapper tconstpool:$addr),
1910 (i32 0), (i32 inst))]>, Sched<[WritePreLd]> {
1911 let Inst{31-25} = 0b1111100;
1912 let Inst{24} = inst;
1913 let Inst{22-20} = 0b001;
1914 let Inst{19-16} = 0b1111;
1915 let Inst{15-12} = 0b1111;
1918 let Inst{23} = addr{12}; // add = (U == '1')
1919 let Inst{11-0} = addr{11-0}; // imm12
1921 let DecoderMethod = "DecodeT2LoadLabel";
1924 def t2PLDpci : T2Iplpci<0, "pld">, Requires<[IsThumb2]>;
1925 def t2PLIpci : T2Iplpci<1, "pli">, Requires<[IsThumb2,HasV7]>;
1927 def : t2InstAlias<"pld${p}.w $addr",
1928 (t2PLDpci t2ldrlabel:$addr, pred:$p)>;
1929 def : InstAlias<"pli${p}.w $addr",
1930 (t2PLIpci t2ldrlabel:$addr, pred:$p), 0>,
1931 Requires<[IsThumb2,HasV7]>;
1933 // PLD/PLI with alternate literal form.
1934 def : t2InstAlias<"pld${p} $addr",
1935 (t2PLDpci t2ldr_pcrel_imm12:$addr, pred:$p)>;
1936 def : InstAlias<"pli${p} $addr",
1937 (t2PLIpci t2ldr_pcrel_imm12:$addr, pred:$p), 0>,
1938 Requires<[IsThumb2,HasV7]>;
1939 def : t2InstAlias<"pld${p}.w $addr",
1940 (t2PLDpci t2ldr_pcrel_imm12:$addr, pred:$p)>;
1941 def : InstAlias<"pli${p}.w $addr",
1942 (t2PLIpci t2ldr_pcrel_imm12:$addr, pred:$p), 0>,
1943 Requires<[IsThumb2,HasV7]>;
1945 //===----------------------------------------------------------------------===//
1946 // Load / store multiple Instructions.
1949 multiclass thumb2_ld_mult<string asm, InstrItinClass itin,
1950 InstrItinClass itin_upd, bit L_bit> {
1952 T2XI<(outs), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops),
1953 itin, !strconcat(asm, "${p}.w\t$Rn, $regs"), []> {
1957 let Inst{31-27} = 0b11101;
1958 let Inst{26-25} = 0b00;
1959 let Inst{24-23} = 0b01; // Increment After
1961 let Inst{21} = 0; // No writeback
1962 let Inst{20} = L_bit;
1963 let Inst{19-16} = Rn;
1964 let Inst{15-0} = regs;
1967 T2XIt<(outs GPR:$wb), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops),
1968 itin_upd, !strconcat(asm, "${p}.w\t$Rn!, $regs"), "$Rn = $wb", []> {
1972 let Inst{31-27} = 0b11101;
1973 let Inst{26-25} = 0b00;
1974 let Inst{24-23} = 0b01; // Increment After
1976 let Inst{21} = 1; // Writeback
1977 let Inst{20} = L_bit;
1978 let Inst{19-16} = Rn;
1979 let Inst{15-0} = regs;
1982 T2XI<(outs), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops),
1983 itin, !strconcat(asm, "db${p}\t$Rn, $regs"), []> {
1987 let Inst{31-27} = 0b11101;
1988 let Inst{26-25} = 0b00;
1989 let Inst{24-23} = 0b10; // Decrement Before
1991 let Inst{21} = 0; // No writeback
1992 let Inst{20} = L_bit;
1993 let Inst{19-16} = Rn;
1994 let Inst{15-0} = regs;
1997 T2XIt<(outs GPR:$wb), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops),
1998 itin_upd, !strconcat(asm, "db${p}\t$Rn!, $regs"), "$Rn = $wb", []> {
2002 let Inst{31-27} = 0b11101;
2003 let Inst{26-25} = 0b00;
2004 let Inst{24-23} = 0b10; // Decrement Before
2006 let Inst{21} = 1; // Writeback
2007 let Inst{20} = L_bit;
2008 let Inst{19-16} = Rn;
2009 let Inst{15-0} = regs;
2013 let hasSideEffects = 0 in {
2015 let mayLoad = 1, hasExtraDefRegAllocReq = 1, variadicOpsAreDefs = 1 in
2016 defm t2LDM : thumb2_ld_mult<"ldm", IIC_iLoad_m, IIC_iLoad_mu, 1>;
2018 multiclass thumb2_st_mult<string asm, InstrItinClass itin,
2019 InstrItinClass itin_upd, bit L_bit> {
2021 T2XI<(outs), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops),
2022 itin, !strconcat(asm, "${p}.w\t$Rn, $regs"), []> {
2026 let Inst{31-27} = 0b11101;
2027 let Inst{26-25} = 0b00;
2028 let Inst{24-23} = 0b01; // Increment After
2030 let Inst{21} = 0; // No writeback
2031 let Inst{20} = L_bit;
2032 let Inst{19-16} = Rn;
2034 let Inst{14} = regs{14};
2036 let Inst{12-0} = regs{12-0};
2039 T2XIt<(outs GPR:$wb), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops),
2040 itin_upd, !strconcat(asm, "${p}.w\t$Rn!, $regs"), "$Rn = $wb", []> {
2044 let Inst{31-27} = 0b11101;
2045 let Inst{26-25} = 0b00;
2046 let Inst{24-23} = 0b01; // Increment After
2048 let Inst{21} = 1; // Writeback
2049 let Inst{20} = L_bit;
2050 let Inst{19-16} = Rn;
2052 let Inst{14} = regs{14};
2054 let Inst{12-0} = regs{12-0};
2057 T2XI<(outs), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops),
2058 itin, !strconcat(asm, "db${p}\t$Rn, $regs"), []> {
2062 let Inst{31-27} = 0b11101;
2063 let Inst{26-25} = 0b00;
2064 let Inst{24-23} = 0b10; // Decrement Before
2066 let Inst{21} = 0; // No writeback
2067 let Inst{20} = L_bit;
2068 let Inst{19-16} = Rn;
2070 let Inst{14} = regs{14};
2072 let Inst{12-0} = regs{12-0};
2075 T2XIt<(outs GPR:$wb), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops),
2076 itin_upd, !strconcat(asm, "db${p}\t$Rn!, $regs"), "$Rn = $wb", []> {
2080 let Inst{31-27} = 0b11101;
2081 let Inst{26-25} = 0b00;
2082 let Inst{24-23} = 0b10; // Decrement Before
2084 let Inst{21} = 1; // Writeback
2085 let Inst{20} = L_bit;
2086 let Inst{19-16} = Rn;
2088 let Inst{14} = regs{14};
2090 let Inst{12-0} = regs{12-0};
2095 let mayStore = 1, hasExtraSrcRegAllocReq = 1 in
2096 defm t2STM : thumb2_st_mult<"stm", IIC_iStore_m, IIC_iStore_mu, 0>;
2101 //===----------------------------------------------------------------------===//
2102 // Move Instructions.
2105 let hasSideEffects = 0 in
2106 def t2MOVr : T2sTwoReg<(outs GPRnopc:$Rd), (ins GPRnopc:$Rm), IIC_iMOVr,
2107 "mov", ".w\t$Rd, $Rm", []>, Sched<[WriteALU]> {
2108 let Inst{31-27} = 0b11101;
2109 let Inst{26-25} = 0b01;
2110 let Inst{24-21} = 0b0010;
2111 let Inst{19-16} = 0b1111; // Rn
2113 let Inst{14-12} = 0b000;
2114 let Inst{7-4} = 0b0000;
2116 def : t2InstAlias<"mov${p}.w $Rd, $Rm", (t2MOVr GPRnopc:$Rd, GPRnopc:$Rm,
2117 pred:$p, zero_reg)>;
2118 def : t2InstAlias<"movs${p}.w $Rd, $Rm", (t2MOVr GPRnopc:$Rd, GPRnopc:$Rm,
2120 def : t2InstAlias<"movs${p} $Rd, $Rm", (t2MOVr GPRnopc:$Rd, GPRnopc:$Rm,
2123 // AddedComplexity to ensure isel tries t2MOVi before t2MOVi16.
2124 let isReMaterializable = 1, isAsCheapAsAMove = 1, isMoveImm = 1,
2125 AddedComplexity = 1 in
2126 def t2MOVi : T2sOneRegImm<(outs rGPR:$Rd), (ins t2_so_imm:$imm), IIC_iMOVi,
2127 "mov", ".w\t$Rd, $imm",
2128 [(set rGPR:$Rd, t2_so_imm:$imm)]>, Sched<[WriteALU]> {
2129 let Inst{31-27} = 0b11110;
2131 let Inst{24-21} = 0b0010;
2132 let Inst{19-16} = 0b1111; // Rn
2136 // cc_out is handled as part of the explicit mnemonic in the parser for 'mov'.
2137 // Use aliases to get that to play nice here.
2138 def : t2InstAlias<"movs${p}.w $Rd, $imm", (t2MOVi rGPR:$Rd, t2_so_imm:$imm,
2140 def : t2InstAlias<"movs${p} $Rd, $imm", (t2MOVi rGPR:$Rd, t2_so_imm:$imm,
2143 def : t2InstAlias<"mov${p}.w $Rd, $imm", (t2MOVi rGPR:$Rd, t2_so_imm:$imm,
2144 pred:$p, zero_reg)>;
2145 def : t2InstAlias<"mov${p} $Rd, $imm", (t2MOVi rGPR:$Rd, t2_so_imm:$imm,
2146 pred:$p, zero_reg)>;
2148 let isReMaterializable = 1, isAsCheapAsAMove = 1, isMoveImm = 1 in
2149 def t2MOVi16 : T2I<(outs rGPR:$Rd), (ins imm0_65535_expr:$imm), IIC_iMOVi,
2150 "movw", "\t$Rd, $imm",
2151 [(set rGPR:$Rd, imm0_65535:$imm)]>, Sched<[WriteALU]>,
2152 Requires<[IsThumb, HasV8MBaseline]> {
2153 let Inst{31-27} = 0b11110;
2155 let Inst{24-21} = 0b0010;
2156 let Inst{20} = 0; // The S bit.
2162 let Inst{11-8} = Rd;
2163 let Inst{19-16} = imm{15-12};
2164 let Inst{26} = imm{11};
2165 let Inst{14-12} = imm{10-8};
2166 let Inst{7-0} = imm{7-0};
2167 let DecoderMethod = "DecodeT2MOVTWInstruction";
2170 def : InstAlias<"mov${p} $Rd, $imm",
2171 (t2MOVi16 rGPR:$Rd, imm256_65535_expr:$imm, pred:$p), 0>,
2172 Requires<[IsThumb, HasV8MBaseline]>, Sched<[WriteALU]>;
2174 def t2MOVi16_ga_pcrel : PseudoInst<(outs rGPR:$Rd),
2175 (ins i32imm:$addr, pclabel:$id), IIC_iMOVi, []>,
2178 let Constraints = "$src = $Rd" in {
2179 def t2MOVTi16 : T2I<(outs rGPR:$Rd),
2180 (ins rGPR:$src, imm0_65535_expr:$imm), IIC_iMOVi,
2181 "movt", "\t$Rd, $imm",
2183 (or (and rGPR:$src, 0xffff), lo16AllZero:$imm))]>,
2185 Requires<[IsThumb, HasV8MBaseline]> {
2186 let Inst{31-27} = 0b11110;
2188 let Inst{24-21} = 0b0110;
2189 let Inst{20} = 0; // The S bit.
2195 let Inst{11-8} = Rd;
2196 let Inst{19-16} = imm{15-12};
2197 let Inst{26} = imm{11};
2198 let Inst{14-12} = imm{10-8};
2199 let Inst{7-0} = imm{7-0};
2200 let DecoderMethod = "DecodeT2MOVTWInstruction";
2203 def t2MOVTi16_ga_pcrel : PseudoInst<(outs rGPR:$Rd),
2204 (ins rGPR:$src, i32imm:$addr, pclabel:$id), IIC_iMOVi, []>,
2205 Sched<[WriteALU]>, Requires<[IsThumb, HasV8MBaseline]>;
2208 def : T2Pat<(or rGPR:$src, 0xffff0000), (t2MOVTi16 rGPR:$src, 0xffff)>;
2210 //===----------------------------------------------------------------------===//
2211 // Extend Instructions.
2216 def t2SXTB : T2I_ext_rrot<0b100, "sxtb">;
2217 def t2SXTH : T2I_ext_rrot<0b000, "sxth">;
2218 def t2SXTB16 : T2I_ext_rrot_xtb16<0b010, "sxtb16">;
2220 def t2SXTAB : T2I_exta_rrot<0b100, "sxtab">;
2221 def t2SXTAH : T2I_exta_rrot<0b000, "sxtah">;
2222 def t2SXTAB16 : T2I_exta_rrot<0b010, "sxtab16">;
2224 def : T2Pat<(sext_inreg (rotr rGPR:$Rn, rot_imm:$rot), i8),
2225 (t2SXTB rGPR:$Rn, rot_imm:$rot)>;
2226 def : T2Pat<(sext_inreg (rotr rGPR:$Rn, rot_imm:$rot), i16),
2227 (t2SXTH rGPR:$Rn, rot_imm:$rot)>;
2228 def : Thumb2DSPPat<(add rGPR:$Rn,
2229 (sext_inreg (rotr rGPR:$Rm, rot_imm:$rot), i8)),
2230 (t2SXTAB rGPR:$Rn, rGPR:$Rm, rot_imm:$rot)>;
2231 def : Thumb2DSPPat<(add rGPR:$Rn,
2232 (sext_inreg (rotr rGPR:$Rm, rot_imm:$rot), i16)),
2233 (t2SXTAH rGPR:$Rn, rGPR:$Rm, rot_imm:$rot)>;
2234 def : Thumb2DSPPat<(int_arm_sxtb16 rGPR:$Rn),
2235 (t2SXTB16 rGPR:$Rn, 0)>;
2236 def : Thumb2DSPPat<(int_arm_sxtab16 rGPR:$Rn, rGPR:$Rm),
2237 (t2SXTAB16 rGPR:$Rn, rGPR:$Rm, 0)>;
2238 def : Thumb2DSPPat<(int_arm_sxtb16 (rotr rGPR:$Rn, rot_imm:$rot)),
2239 (t2SXTB16 rGPR:$Rn, rot_imm:$rot)>;
2240 def : Thumb2DSPPat<(int_arm_sxtab16 rGPR:$Rn, (rotr rGPR:$Rm, rot_imm:$rot)),
2241 (t2SXTAB16 rGPR:$Rn, rGPR:$Rm, rot_imm:$rot)>;
2244 // A simple right-shift can also be used in most cases (the exception is the
2245 // SXTH operations with a rotate of 24: there the non-contiguous bits are
2247 def : Thumb2DSPPat<(add rGPR:$Rn, (sext_inreg
2248 (srl rGPR:$Rm, rot_imm:$rot), i8)),
2249 (t2SXTAB rGPR:$Rn, rGPR:$Rm, rot_imm:$rot)>;
2250 def : Thumb2DSPPat<(add rGPR:$Rn, (sext_inreg
2251 (srl rGPR:$Rm, imm8_or_16:$rot), i16)),
2252 (t2SXTAH rGPR:$Rn, rGPR:$Rm, rot_imm:$rot)>;
2253 def : Thumb2DSPPat<(add rGPR:$Rn, (sext_inreg
2254 (rotr rGPR:$Rm, (i32 24)), i16)),
2255 (t2SXTAH rGPR:$Rn, rGPR:$Rm, (i32 3))>;
2256 def : Thumb2DSPPat<(add rGPR:$Rn, (sext_inreg
2257 (or (srl rGPR:$Rm, (i32 24)),
2258 (shl rGPR:$Rm, (i32 8))), i16)),
2259 (t2SXTAH rGPR:$Rn, rGPR:$Rm, (i32 3))>;
2263 let AddedComplexity = 16 in {
2264 def t2UXTB : T2I_ext_rrot<0b101, "uxtb">;
2265 def t2UXTH : T2I_ext_rrot<0b001, "uxth">;
2266 def t2UXTB16 : T2I_ext_rrot_xtb16<0b011, "uxtb16">;
2268 def : Thumb2DSPPat<(and (rotr rGPR:$Rm, rot_imm:$rot), 0x000000FF),
2269 (t2UXTB rGPR:$Rm, rot_imm:$rot)>;
2270 def : Thumb2DSPPat<(and (rotr rGPR:$Rm, rot_imm:$rot), 0x0000FFFF),
2271 (t2UXTH rGPR:$Rm, rot_imm:$rot)>;
2272 def : Thumb2DSPPat<(and (rotr rGPR:$Rm, rot_imm:$rot), 0x00FF00FF),
2273 (t2UXTB16 rGPR:$Rm, rot_imm:$rot)>;
2275 def : Thumb2DSPPat<(int_arm_uxtb16 rGPR:$Rm),
2276 (t2UXTB16 rGPR:$Rm, 0)>;
2277 def : Thumb2DSPPat<(int_arm_uxtb16 (rotr rGPR:$Rn, rot_imm:$rot)),
2278 (t2UXTB16 rGPR:$Rn, rot_imm:$rot)>;
2280 // FIXME: This pattern incorrectly assumes the shl operator is a rotate.
2281 // The transformation should probably be done as a combiner action
2282 // instead so we can include a check for masking back in the upper
2283 // eight bits of the source into the lower eight bits of the result.
2284 //def : T2Pat<(and (shl rGPR:$Src, (i32 8)), 0xFF00FF),
2285 // (t2UXTB16 rGPR:$Src, 3)>,
2286 // Requires<[HasDSP, IsThumb2]>;
2287 def : T2Pat<(and (srl rGPR:$Src, (i32 8)), 0xFF00FF),
2288 (t2UXTB16 rGPR:$Src, 1)>,
2289 Requires<[HasDSP, IsThumb2]>;
2291 def t2UXTAB : T2I_exta_rrot<0b101, "uxtab">;
2292 def t2UXTAH : T2I_exta_rrot<0b001, "uxtah">;
2293 def t2UXTAB16 : T2I_exta_rrot<0b011, "uxtab16">;
2295 def : Thumb2DSPPat<(add rGPR:$Rn, (and (rotr rGPR:$Rm, rot_imm:$rot),
2297 (t2UXTAB rGPR:$Rn, rGPR:$Rm, rot_imm:$rot)>;
2298 def : Thumb2DSPPat<(add rGPR:$Rn, (and (rotr rGPR:$Rm, rot_imm:$rot),
2300 (t2UXTAH rGPR:$Rn, rGPR:$Rm, rot_imm:$rot)>;
2301 def : Thumb2DSPPat<(add rGPR:$Rn, (and (srl rGPR:$Rm, rot_imm:$rot),
2303 (t2UXTAB rGPR:$Rn, rGPR:$Rm, rot_imm:$rot)>;
2304 def : Thumb2DSPPat<(add rGPR:$Rn, (and (srl rGPR:$Rm, imm8_or_16:$rot),
2306 (t2UXTAH rGPR:$Rn, rGPR:$Rm, rot_imm:$rot)>;
2307 def : Thumb2DSPPat<(int_arm_uxtab16 rGPR:$Rn, rGPR:$Rm),
2308 (t2UXTAB16 rGPR:$Rn, rGPR:$Rm, 0)>;
2309 def : Thumb2DSPPat<(int_arm_uxtab16 rGPR:$Rn, (rotr rGPR:$Rm, rot_imm:$rot)),
2310 (t2UXTAB16 rGPR:$Rn, rGPR:$Rm, rot_imm:$rot)>;
2314 //===----------------------------------------------------------------------===//
2315 // Arithmetic Instructions.
2319 defm t2ADD : T2I_bin_ii12rs<0b000, "add", add, 1>;
2320 defm t2SUB : T2I_bin_ii12rs<0b101, "sub", sub>;
2322 // ADD and SUB with 's' bit set. No 12-bit immediate (T4) variants.
2324 // Currently, t2ADDS/t2SUBS are pseudo opcodes that exist only in the
2325 // selection DAG. They are "lowered" to real t2ADD/t2SUB opcodes by
2326 // AdjustInstrPostInstrSelection where we determine whether or not to
2327 // set the "s" bit based on CPSR liveness.
2329 // FIXME: Eliminate t2ADDS/t2SUBS pseudo opcodes after adding tablegen
2330 // support for an optional CPSR definition that corresponds to the DAG
2331 // node's second value. We can then eliminate the implicit def of CPSR.
2332 defm t2ADDS : T2I_bin_s_irs <IIC_iALUi, IIC_iALUr, IIC_iALUsi, ARMaddc, 1>;
2333 defm t2SUBS : T2I_bin_s_irs <IIC_iALUi, IIC_iALUr, IIC_iALUsi, ARMsubc>;
2335 def : T2Pat<(ARMsubs GPRnopc:$Rn, t2_so_imm:$imm),
2336 (t2SUBSri $Rn, t2_so_imm:$imm)>;
2337 def : T2Pat<(ARMsubs GPRnopc:$Rn, rGPR:$Rm), (t2SUBSrr $Rn, $Rm)>;
2338 def : T2Pat<(ARMsubs GPRnopc:$Rn, t2_so_reg:$ShiftedRm),
2339 (t2SUBSrs $Rn, t2_so_reg:$ShiftedRm)>;
2341 let hasPostISelHook = 1 in {
2342 defm t2ADC : T2I_adde_sube_irs<0b1010, "adc", ARMadde, 1>;
2343 defm t2SBC : T2I_adde_sube_irs<0b1011, "sbc", ARMsube>;
2346 def : t2InstSubst<"adc${s}${p} $rd, $rn, $imm",
2347 (t2SBCri rGPR:$rd, rGPR:$rn, t2_so_imm_not:$imm, pred:$p, s_cc_out:$s)>;
2348 def : t2InstSubst<"sbc${s}${p} $rd, $rn, $imm",
2349 (t2ADCri rGPR:$rd, rGPR:$rn, t2_so_imm_not:$imm, pred:$p, s_cc_out:$s)>;
2351 def : t2InstSubst<"add${s}${p}.w $rd, $rn, $imm",
2352 (t2SUBri rGPR:$rd, GPRnopc:$rn, t2_so_imm_neg:$imm, pred:$p, s_cc_out:$s)>;
2353 def : t2InstSubst<"sub${s}${p}.w $rd, $rn, $imm",
2354 (t2ADDri rGPR:$rd, GPRnopc:$rn, t2_so_imm_neg:$imm, pred:$p, s_cc_out:$s)>;
2355 def : t2InstSubst<"subw${p} $Rd, $Rn, $imm",
2356 (t2ADDri12 rGPR:$Rd, GPR:$Rn, imm0_4095_neg:$imm, pred:$p)>;
2357 def : t2InstSubst<"sub${s}${p} $rd, $rn, $imm",
2358 (t2ADDri rGPR:$rd, GPRnopc:$rn, t2_so_imm_neg:$imm, pred:$p, s_cc_out:$s)>;
2359 def : t2InstSubst<"sub${p} $rd, $rn, $imm",
2360 (t2ADDri12 rGPR:$rd, GPR:$rn, imm0_4095_neg:$imm, pred:$p)>;
2363 def : t2InstSubst<"add${s}${p}.w $rd, $rn, $imm",
2364 (t2SUBspImm GPRsp:$rd, GPRsp:$rn, t2_so_imm_neg:$imm, pred:$p, s_cc_out:$s)>;
2365 def : t2InstSubst<"sub${s}${p}.w $rd, $rn, $imm",
2366 (t2ADDspImm GPRsp:$rd, GPRsp:$rn, t2_so_imm_neg:$imm, pred:$p, s_cc_out:$s)>;
2367 def : t2InstSubst<"subw${p} $Rd, $Rn, $imm",
2368 (t2ADDspImm12 GPRsp:$Rd, GPRsp:$Rn, imm0_4095_neg:$imm, pred:$p)>;
2369 def : t2InstSubst<"sub${s}${p} $rd, $rn, $imm",
2370 (t2ADDspImm GPRsp:$rd, GPRsp:$rn, t2_so_imm_neg:$imm, pred:$p, s_cc_out:$s)>;
2371 def : t2InstSubst<"sub${p} $rd, $rn, $imm",
2372 (t2ADDspImm12 GPRsp:$rd, GPRsp:$rn, imm0_4095_neg:$imm, pred:$p)>;
2376 defm t2RSB : T2I_rbin_irs <0b1110, "rsb", sub>;
2378 // FIXME: Eliminate them if we can write def : Pat patterns which defines
2379 // CPSR and the implicit def of CPSR is not needed.
2380 defm t2RSBS : T2I_rbin_s_is <ARMsubc>;
2382 // (sub X, imm) gets canonicalized to (add X, -imm). Match this form.
2383 // The assume-no-carry-in form uses the negation of the input since add/sub
2384 // assume opposite meanings of the carry flag (i.e., carry == !borrow).
2385 // See the definition of AddWithCarry() in the ARM ARM A2.2.1 for the gory
2387 // The AddedComplexity preferences the first variant over the others since
2388 // it can be shrunk to a 16-bit wide encoding, while the others cannot.
2389 let AddedComplexity = 1 in
2390 def : T2Pat<(add rGPR:$src, imm1_255_neg:$imm),
2391 (t2SUBri rGPR:$src, imm1_255_neg:$imm)>;
2392 def : T2Pat<(add rGPR:$src, t2_so_imm_neg:$imm),
2393 (t2SUBri rGPR:$src, t2_so_imm_neg:$imm)>;
2394 def : T2Pat<(add rGPR:$src, imm0_4095_neg:$imm),
2395 (t2SUBri12 rGPR:$src, imm0_4095_neg:$imm)>;
2396 def : T2Pat<(add GPR:$src, imm0_65535_neg:$imm),
2397 (t2SUBrr GPR:$src, (t2MOVi16 (imm_neg_XFORM imm:$imm)))>;
2399 // Do the same for v8m targets since they support movw with a 16-bit value.
2400 def : T1Pat<(add tGPR:$src, imm0_65535_neg:$imm),
2401 (tSUBrr tGPR:$src, (t2MOVi16 (imm_neg_XFORM imm:$imm)))>,
2402 Requires<[HasV8MBaseline]>;
2404 let AddedComplexity = 1 in
2405 def : T2Pat<(ARMaddc rGPR:$src, imm1_255_neg:$imm),
2406 (t2SUBSri rGPR:$src, imm1_255_neg:$imm)>;
2407 def : T2Pat<(ARMaddc rGPR:$src, t2_so_imm_neg:$imm),
2408 (t2SUBSri rGPR:$src, t2_so_imm_neg:$imm)>;
2409 def : T2Pat<(ARMaddc rGPR:$src, imm0_65535_neg:$imm),
2410 (t2SUBSrr rGPR:$src, (t2MOVi16 (imm_neg_XFORM imm:$imm)))>;
2411 // The with-carry-in form matches bitwise not instead of the negation.
2412 // Effectively, the inverse interpretation of the carry flag already accounts
2413 // for part of the negation.
2414 let AddedComplexity = 1 in
2415 def : T2Pat<(ARMadde rGPR:$src, imm0_255_not:$imm, CPSR),
2416 (t2SBCri rGPR:$src, imm0_255_not:$imm)>;
2417 def : T2Pat<(ARMadde rGPR:$src, t2_so_imm_not:$imm, CPSR),
2418 (t2SBCri rGPR:$src, t2_so_imm_not:$imm)>;
2419 def : T2Pat<(ARMadde rGPR:$src, imm0_65535_neg:$imm, CPSR),
2420 (t2SBCrr rGPR:$src, (t2MOVi16 (imm_not_XFORM imm:$imm)))>;
2422 def t2SEL : T2ThreeReg<(outs GPR:$Rd), (ins GPR:$Rn, GPR:$Rm),
2423 NoItinerary, "sel", "\t$Rd, $Rn, $Rm",
2424 [(set GPR:$Rd, (int_arm_sel GPR:$Rn, GPR:$Rm))]>,
2425 Requires<[IsThumb2, HasDSP]> {
2426 let Inst{31-27} = 0b11111;
2427 let Inst{26-24} = 0b010;
2429 let Inst{22-20} = 0b010;
2430 let Inst{15-12} = 0b1111;
2432 let Inst{6-4} = 0b000;
2435 // A6.3.13, A6.3.14, A6.3.15 Parallel addition and subtraction (signed/unsigned)
2436 // And Miscellaneous operations -- for disassembly only
2437 class T2I_pam<bits<3> op22_20, bits<4> op7_4, string opc,
2438 list<dag> pat, dag iops, string asm>
2439 : T2I<(outs rGPR:$Rd), iops, NoItinerary, opc, asm, pat>,
2440 Requires<[IsThumb2, HasDSP]> {
2441 let Inst{31-27} = 0b11111;
2442 let Inst{26-23} = 0b0101;
2443 let Inst{22-20} = op22_20;
2444 let Inst{15-12} = 0b1111;
2445 let Inst{7-4} = op7_4;
2451 let Inst{11-8} = Rd;
2452 let Inst{19-16} = Rn;
2456 class T2I_pam_intrinsics<bits<3> op22_20, bits<4> op7_4, string opc,
2457 Intrinsic intrinsic>
2458 : T2I_pam<op22_20, op7_4, opc,
2459 [(set rGPR:$Rd, (intrinsic rGPR:$Rn, rGPR:$Rm))],
2460 (ins rGPR:$Rn, rGPR:$Rm), "\t$Rd, $Rn, $Rm">;
2462 class T2I_pam_intrinsics_rev<bits<3> op22_20, bits<4> op7_4, string opc>
2463 : T2I_pam<op22_20, op7_4, opc, [],
2464 (ins rGPR:$Rm, rGPR:$Rn), "\t$Rd, $Rm, $Rn">;
2466 // Saturating add/subtract
2467 def t2QADD16 : T2I_pam_intrinsics<0b001, 0b0001, "qadd16", int_arm_qadd16>;
2468 def t2QADD8 : T2I_pam_intrinsics<0b000, 0b0001, "qadd8", int_arm_qadd8>;
2469 def t2QASX : T2I_pam_intrinsics<0b010, 0b0001, "qasx", int_arm_qasx>;
2470 def t2UQSUB8 : T2I_pam_intrinsics<0b100, 0b0101, "uqsub8", int_arm_uqsub8>;
2471 def t2QSAX : T2I_pam_intrinsics<0b110, 0b0001, "qsax", int_arm_qsax>;
2472 def t2QSUB16 : T2I_pam_intrinsics<0b101, 0b0001, "qsub16", int_arm_qsub16>;
2473 def t2QSUB8 : T2I_pam_intrinsics<0b100, 0b0001, "qsub8", int_arm_qsub8>;
2474 def t2UQADD16 : T2I_pam_intrinsics<0b001, 0b0101, "uqadd16", int_arm_uqadd16>;
2475 def t2UQADD8 : T2I_pam_intrinsics<0b000, 0b0101, "uqadd8", int_arm_uqadd8>;
2476 def t2UQASX : T2I_pam_intrinsics<0b010, 0b0101, "uqasx", int_arm_uqasx>;
2477 def t2UQSAX : T2I_pam_intrinsics<0b110, 0b0101, "uqsax", int_arm_uqsax>;
2478 def t2UQSUB16 : T2I_pam_intrinsics<0b101, 0b0101, "uqsub16", int_arm_uqsub16>;
2479 def t2QADD : T2I_pam_intrinsics_rev<0b000, 0b1000, "qadd">;
2480 def t2QSUB : T2I_pam_intrinsics_rev<0b000, 0b1010, "qsub">;
2481 def t2QDADD : T2I_pam_intrinsics_rev<0b000, 0b1001, "qdadd">;
2482 def t2QDSUB : T2I_pam_intrinsics_rev<0b000, 0b1011, "qdsub">;
2484 def : Thumb2DSPPat<(int_arm_qadd rGPR:$Rm, rGPR:$Rn),
2485 (t2QADD rGPR:$Rm, rGPR:$Rn)>;
2486 def : Thumb2DSPPat<(int_arm_qsub rGPR:$Rm, rGPR:$Rn),
2487 (t2QSUB rGPR:$Rm, rGPR:$Rn)>;
2488 def : Thumb2DSPPat<(int_arm_qadd rGPR:$Rm, (int_arm_qadd rGPR:$Rn, rGPR:$Rn)),
2489 (t2QDADD rGPR:$Rm, rGPR:$Rn)>;
2490 def : Thumb2DSPPat<(int_arm_qsub rGPR:$Rm, (int_arm_qadd rGPR:$Rn, rGPR:$Rn)),
2491 (t2QDSUB rGPR:$Rm, rGPR:$Rn)>;
2493 def : Thumb2DSPPat<(saddsat rGPR:$Rm, rGPR:$Rn),
2494 (t2QADD rGPR:$Rm, rGPR:$Rn)>;
2495 def : Thumb2DSPPat<(ssubsat rGPR:$Rm, rGPR:$Rn),
2496 (t2QSUB rGPR:$Rm, rGPR:$Rn)>;
2497 def : Thumb2DSPPat<(saddsat rGPR:$Rm, (saddsat rGPR:$Rn, rGPR:$Rn)),
2498 (t2QDADD rGPR:$Rm, rGPR:$Rn)>;
2499 def : Thumb2DSPPat<(ssubsat rGPR:$Rm, (saddsat rGPR:$Rn, rGPR:$Rn)),
2500 (t2QDSUB rGPR:$Rm, rGPR:$Rn)>;
2501 def : Thumb2DSPPat<(ARMqadd8b rGPR:$Rm, rGPR:$Rn),
2502 (t2QADD8 rGPR:$Rm, rGPR:$Rn)>;
2503 def : Thumb2DSPPat<(ARMqsub8b rGPR:$Rm, rGPR:$Rn),
2504 (t2QSUB8 rGPR:$Rm, rGPR:$Rn)>;
2505 def : Thumb2DSPPat<(ARMqadd16b rGPR:$Rm, rGPR:$Rn),
2506 (t2QADD16 rGPR:$Rm, rGPR:$Rn)>;
2507 def : Thumb2DSPPat<(ARMqsub16b rGPR:$Rm, rGPR:$Rn),
2508 (t2QSUB16 rGPR:$Rm, rGPR:$Rn)>;
2510 // Signed/Unsigned add/subtract
2512 def t2SASX : T2I_pam_intrinsics<0b010, 0b0000, "sasx", int_arm_sasx>;
2513 def t2SADD16 : T2I_pam_intrinsics<0b001, 0b0000, "sadd16", int_arm_sadd16>;
2514 def t2SADD8 : T2I_pam_intrinsics<0b000, 0b0000, "sadd8", int_arm_sadd8>;
2515 def t2SSAX : T2I_pam_intrinsics<0b110, 0b0000, "ssax", int_arm_ssax>;
2516 def t2SSUB16 : T2I_pam_intrinsics<0b101, 0b0000, "ssub16", int_arm_ssub16>;
2517 def t2SSUB8 : T2I_pam_intrinsics<0b100, 0b0000, "ssub8", int_arm_ssub8>;
2518 def t2UASX : T2I_pam_intrinsics<0b010, 0b0100, "uasx", int_arm_uasx>;
2519 def t2UADD16 : T2I_pam_intrinsics<0b001, 0b0100, "uadd16", int_arm_uadd16>;
2520 def t2UADD8 : T2I_pam_intrinsics<0b000, 0b0100, "uadd8", int_arm_uadd8>;
2521 def t2USAX : T2I_pam_intrinsics<0b110, 0b0100, "usax", int_arm_usax>;
2522 def t2USUB16 : T2I_pam_intrinsics<0b101, 0b0100, "usub16", int_arm_usub16>;
2523 def t2USUB8 : T2I_pam_intrinsics<0b100, 0b0100, "usub8", int_arm_usub8>;
2525 // Signed/Unsigned halving add/subtract
2527 def t2SHASX : T2I_pam_intrinsics<0b010, 0b0010, "shasx", int_arm_shasx>;
2528 def t2SHADD16 : T2I_pam_intrinsics<0b001, 0b0010, "shadd16", int_arm_shadd16>;
2529 def t2SHADD8 : T2I_pam_intrinsics<0b000, 0b0010, "shadd8", int_arm_shadd8>;
2530 def t2SHSAX : T2I_pam_intrinsics<0b110, 0b0010, "shsax", int_arm_shsax>;
2531 def t2SHSUB16 : T2I_pam_intrinsics<0b101, 0b0010, "shsub16", int_arm_shsub16>;
2532 def t2SHSUB8 : T2I_pam_intrinsics<0b100, 0b0010, "shsub8", int_arm_shsub8>;
2533 def t2UHASX : T2I_pam_intrinsics<0b010, 0b0110, "uhasx", int_arm_uhasx>;
2534 def t2UHADD16 : T2I_pam_intrinsics<0b001, 0b0110, "uhadd16", int_arm_uhadd16>;
2535 def t2UHADD8 : T2I_pam_intrinsics<0b000, 0b0110, "uhadd8", int_arm_uhadd8>;
2536 def t2UHSAX : T2I_pam_intrinsics<0b110, 0b0110, "uhsax", int_arm_uhsax>;
2537 def t2UHSUB16 : T2I_pam_intrinsics<0b101, 0b0110, "uhsub16", int_arm_uhsub16>;
2538 def t2UHSUB8 : T2I_pam_intrinsics<0b100, 0b0110, "uhsub8", int_arm_uhsub8>;
2540 // Helper class for disassembly only
2541 // A6.3.16 & A6.3.17
2542 // T2Imac - Thumb2 multiply [accumulate, and absolute difference] instructions.
2543 class T2ThreeReg_mac<bit long, bits<3> op22_20, bits<4> op7_4, dag oops,
2544 dag iops, InstrItinClass itin, string opc, string asm, list<dag> pattern>
2545 : T2ThreeReg<oops, iops, itin, opc, asm, pattern> {
2546 let Inst{31-27} = 0b11111;
2547 let Inst{26-24} = 0b011;
2548 let Inst{23} = long;
2549 let Inst{22-20} = op22_20;
2550 let Inst{7-4} = op7_4;
2553 class T2FourReg_mac<bit long, bits<3> op22_20, bits<4> op7_4, dag oops,
2554 dag iops, InstrItinClass itin, string opc, string asm, list<dag> pattern>
2555 : T2FourReg<oops, iops, itin, opc, asm, pattern> {
2556 let Inst{31-27} = 0b11111;
2557 let Inst{26-24} = 0b011;
2558 let Inst{23} = long;
2559 let Inst{22-20} = op22_20;
2560 let Inst{7-4} = op7_4;
2563 // Unsigned Sum of Absolute Differences [and Accumulate].
2564 def t2USAD8 : T2ThreeReg_mac<0, 0b111, 0b0000, (outs rGPR:$Rd),
2565 (ins rGPR:$Rn, rGPR:$Rm),
2566 NoItinerary, "usad8", "\t$Rd, $Rn, $Rm",
2567 [(set rGPR:$Rd, (int_arm_usad8 rGPR:$Rn, rGPR:$Rm))]>,
2568 Requires<[IsThumb2, HasDSP]> {
2569 let Inst{15-12} = 0b1111;
2571 def t2USADA8 : T2FourReg_mac<0, 0b111, 0b0000, (outs rGPR:$Rd),
2572 (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), NoItinerary,
2573 "usada8", "\t$Rd, $Rn, $Rm, $Ra",
2574 [(set rGPR:$Rd, (int_arm_usada8 rGPR:$Rn, rGPR:$Rm, rGPR:$Ra))]>,
2575 Requires<[IsThumb2, HasDSP]>;
2577 // Signed/Unsigned saturate.
2578 let hasSideEffects = 1 in
2579 class T2SatI<dag iops, string opc, string asm>
2580 : T2I<(outs rGPR:$Rd), iops, NoItinerary, opc, asm, []> {
2586 let Inst{31-24} = 0b11110011;
2587 let Inst{21} = sh{5};
2589 let Inst{19-16} = Rn;
2591 let Inst{14-12} = sh{4-2};
2592 let Inst{11-8} = Rd;
2593 let Inst{7-6} = sh{1-0};
2595 let Inst{4-0} = sat_imm;
2598 def t2SSAT: T2SatI<(ins imm1_32:$sat_imm, rGPR:$Rn, t2_shift_imm:$sh),
2599 "ssat", "\t$Rd, $sat_imm, $Rn$sh">,
2600 Requires<[IsThumb2]>, Sched<[WriteALU]> {
2601 let Inst{23-22} = 0b00;
2605 def t2SSAT16: T2SatI<(ins imm1_16:$sat_imm, rGPR:$Rn),
2606 "ssat16", "\t$Rd, $sat_imm, $Rn">,
2607 Requires<[IsThumb2, HasDSP]>, Sched<[WriteALU]> {
2608 let Inst{23-22} = 0b00;
2613 def t2USAT: T2SatI<(ins imm0_31:$sat_imm, rGPR:$Rn, t2_shift_imm:$sh),
2614 "usat", "\t$Rd, $sat_imm, $Rn$sh">,
2615 Requires<[IsThumb2]>, Sched<[WriteALU]> {
2616 let Inst{23-22} = 0b10;
2619 def t2USAT16: T2SatI<(ins imm0_15:$sat_imm, rGPR:$Rn),
2620 "usat16", "\t$Rd, $sat_imm, $Rn">,
2621 Requires<[IsThumb2, HasDSP]>, Sched<[WriteALU]> {
2622 let Inst{23-22} = 0b10;
2627 def : T2Pat<(ARMssatnoshift GPRnopc:$Rn, imm0_31:$imm),
2628 (t2SSAT imm0_31:$imm, GPRnopc:$Rn, 0)>;
2629 def : T2Pat<(ARMusatnoshift GPRnopc:$Rn, imm0_31:$imm),
2630 (t2USAT imm0_31:$imm, GPRnopc:$Rn, 0)>;
2631 def : T2Pat<(int_arm_ssat GPR:$a, imm1_32:$pos),
2632 (t2SSAT imm1_32:$pos, GPR:$a, 0)>;
2633 def : T2Pat<(int_arm_usat GPR:$a, imm0_31:$pos),
2634 (t2USAT imm0_31:$pos, GPR:$a, 0)>;
2635 def : T2Pat<(int_arm_ssat16 GPR:$a, imm1_16:$pos),
2636 (t2SSAT16 imm1_16:$pos, GPR:$a)>;
2637 def : T2Pat<(int_arm_usat16 GPR:$a, imm0_15:$pos),
2638 (t2USAT16 imm0_15:$pos, GPR:$a)>;
2640 //===----------------------------------------------------------------------===//
2641 // Shift and rotate Instructions.
2644 defm t2LSL : T2I_sh_ir<0b00, "lsl", imm1_31, shl>;
2645 defm t2LSR : T2I_sh_ir<0b01, "lsr", imm_sr, srl>;
2646 defm t2ASR : T2I_sh_ir<0b10, "asr", imm_sr, sra>;
2647 defm t2ROR : T2I_sh_ir<0b11, "ror", imm0_31, rotr>;
2649 // LSL #0 is actually MOV, and has slightly different permitted registers to
2650 // LSL with non-zero shift
2651 def : t2InstAlias<"lsl${s}${p} $Rd, $Rm, #0",
2652 (t2MOVr GPRnopc:$Rd, GPRnopc:$Rm, pred:$p, cc_out:$s)>;
2653 def : t2InstAlias<"lsl${s}${p}.w $Rd, $Rm, #0",
2654 (t2MOVr GPRnopc:$Rd, GPRnopc:$Rm, pred:$p, cc_out:$s)>;
2656 // (rotr x, (and y, 0x...1f)) ==> (ROR x, y)
2657 def : T2Pat<(rotr rGPR:$lhs, (and rGPR:$rhs, lo5AllOne)),
2658 (t2RORrr rGPR:$lhs, rGPR:$rhs)>;
2660 let Uses = [CPSR] in {
2661 def t2RRX : T2sTwoReg<(outs rGPR:$Rd), (ins rGPR:$Rm), IIC_iMOVsi,
2662 "rrx", "\t$Rd, $Rm",
2663 [(set rGPR:$Rd, (ARMrrx rGPR:$Rm))]>, Sched<[WriteALU]> {
2664 let Inst{31-27} = 0b11101;
2665 let Inst{26-25} = 0b01;
2666 let Inst{24-21} = 0b0010;
2667 let Inst{19-16} = 0b1111; // Rn
2669 let Unpredictable{15} = 0b1;
2670 let Inst{14-12} = 0b000;
2671 let Inst{7-4} = 0b0011;
2675 let isCodeGenOnly = 1, Defs = [CPSR] in {
2676 def t2MOVsrl_flag : T2TwoRegShiftImm<
2677 (outs rGPR:$Rd), (ins rGPR:$Rm), IIC_iMOVsi,
2678 "lsrs", ".w\t$Rd, $Rm, #1",
2679 [(set rGPR:$Rd, (ARMsrl_flag rGPR:$Rm))]>,
2681 let Inst{31-27} = 0b11101;
2682 let Inst{26-25} = 0b01;
2683 let Inst{24-21} = 0b0010;
2684 let Inst{20} = 1; // The S bit.
2685 let Inst{19-16} = 0b1111; // Rn
2686 let Inst{5-4} = 0b01; // Shift type.
2687 // Shift amount = Inst{14-12:7-6} = 1.
2688 let Inst{14-12} = 0b000;
2689 let Inst{7-6} = 0b01;
2691 def t2MOVsra_flag : T2TwoRegShiftImm<
2692 (outs rGPR:$Rd), (ins rGPR:$Rm), IIC_iMOVsi,
2693 "asrs", ".w\t$Rd, $Rm, #1",
2694 [(set rGPR:$Rd, (ARMsra_flag rGPR:$Rm))]>,
2696 let Inst{31-27} = 0b11101;
2697 let Inst{26-25} = 0b01;
2698 let Inst{24-21} = 0b0010;
2699 let Inst{20} = 1; // The S bit.
2700 let Inst{19-16} = 0b1111; // Rn
2701 let Inst{5-4} = 0b10; // Shift type.
2702 // Shift amount = Inst{14-12:7-6} = 1.
2703 let Inst{14-12} = 0b000;
2704 let Inst{7-6} = 0b01;
2708 //===----------------------------------------------------------------------===//
2709 // Bitwise Instructions.
2712 defm t2AND : T2I_bin_w_irs<0b0000, "and",
2713 IIC_iBITi, IIC_iBITr, IIC_iBITsi, and, 1>;
2714 defm t2ORR : T2I_bin_w_irs<0b0010, "orr",
2715 IIC_iBITi, IIC_iBITr, IIC_iBITsi, or, 1>;
2716 defm t2EOR : T2I_bin_w_irs<0b0100, "eor",
2717 IIC_iBITi, IIC_iBITr, IIC_iBITsi, xor, 1>;
2719 defm t2BIC : T2I_bin_w_irs<0b0001, "bic",
2720 IIC_iBITi, IIC_iBITr, IIC_iBITsi,
2721 BinOpFrag<(and node:$LHS, (not node:$RHS))>>;
2723 class T2BitFI<dag oops, dag iops, InstrItinClass itin,
2724 string opc, string asm, list<dag> pattern>
2725 : T2I<oops, iops, itin, opc, asm, pattern> {
2730 let Inst{11-8} = Rd;
2731 let Inst{4-0} = msb{4-0};
2732 let Inst{14-12} = lsb{4-2};
2733 let Inst{7-6} = lsb{1-0};
2736 class T2TwoRegBitFI<dag oops, dag iops, InstrItinClass itin,
2737 string opc, string asm, list<dag> pattern>
2738 : T2BitFI<oops, iops, itin, opc, asm, pattern> {
2741 let Inst{19-16} = Rn;
2744 let Constraints = "$src = $Rd" in
2745 def t2BFC : T2BitFI<(outs rGPR:$Rd), (ins rGPR:$src, bf_inv_mask_imm:$imm),
2746 IIC_iUNAsi, "bfc", "\t$Rd, $imm",
2747 [(set rGPR:$Rd, (and rGPR:$src, bf_inv_mask_imm:$imm))]>, Sched<[WriteALU]> {
2748 let Inst{31-27} = 0b11110;
2749 let Inst{26} = 0; // should be 0.
2751 let Inst{24-20} = 0b10110;
2752 let Inst{19-16} = 0b1111; // Rn
2754 let Inst{5} = 0; // should be 0.
2757 let msb{4-0} = imm{9-5};
2758 let lsb{4-0} = imm{4-0};
2761 def t2SBFX: T2TwoRegBitFI<
2762 (outs rGPR:$Rd), (ins rGPR:$Rn, imm0_31:$lsb, imm1_32:$msb),
2763 IIC_iUNAsi, "sbfx", "\t$Rd, $Rn, $lsb, $msb", []>, Sched<[WriteALU]> {
2764 let Inst{31-27} = 0b11110;
2766 let Inst{24-20} = 0b10100;
2769 let hasSideEffects = 0;
2772 def t2UBFX: T2TwoRegBitFI<
2773 (outs rGPR:$Rd), (ins rGPR:$Rn, imm0_31:$lsb, imm1_32:$msb),
2774 IIC_iUNAsi, "ubfx", "\t$Rd, $Rn, $lsb, $msb", []>, Sched<[WriteALU]> {
2775 let Inst{31-27} = 0b11110;
2777 let Inst{24-20} = 0b11100;
2780 let hasSideEffects = 0;
2783 // A8.8.247 UDF - Undefined (Encoding T2)
2784 def t2UDF : T2XI<(outs), (ins imm0_65535:$imm16), IIC_Br, "udf.w\t$imm16",
2785 [(int_arm_undefined imm0_65535:$imm16)]> {
2787 let Inst{31-29} = 0b111;
2788 let Inst{28-27} = 0b10;
2789 let Inst{26-20} = 0b1111111;
2790 let Inst{19-16} = imm16{15-12};
2792 let Inst{14-12} = 0b010;
2793 let Inst{11-0} = imm16{11-0};
2796 // A8.6.18 BFI - Bitfield insert (Encoding T1)
2797 let Constraints = "$src = $Rd" in {
2798 def t2BFI : T2TwoRegBitFI<(outs rGPR:$Rd),
2799 (ins rGPR:$src, rGPR:$Rn, bf_inv_mask_imm:$imm),
2800 IIC_iBITi, "bfi", "\t$Rd, $Rn, $imm",
2801 [(set rGPR:$Rd, (ARMbfi rGPR:$src, rGPR:$Rn,
2802 bf_inv_mask_imm:$imm))]>, Sched<[WriteALU]> {
2803 let Inst{31-27} = 0b11110;
2804 let Inst{26} = 0; // should be 0.
2806 let Inst{24-20} = 0b10110;
2808 let Inst{5} = 0; // should be 0.
2811 let msb{4-0} = imm{9-5};
2812 let lsb{4-0} = imm{4-0};
2816 defm t2ORN : T2I_bin_irs<0b0011, "orn",
2817 IIC_iBITi, IIC_iBITr, IIC_iBITsi,
2818 BinOpFrag<(or node:$LHS, (not node:$RHS))>, 0, "">;
2820 /// T2I_un_irs - Defines a set of (op reg, {so_imm|r|so_reg}) patterns for a
2821 /// unary operation that produces a value. These are predicable and can be
2822 /// changed to modify CPSR.
2823 multiclass T2I_un_irs<bits<4> opcod, string opc,
2824 InstrItinClass iii, InstrItinClass iir, InstrItinClass iis,
2826 bit Cheap = 0, bit ReMat = 0, bit MoveImm = 0> {
2828 def i : T2sOneRegImm<(outs rGPR:$Rd), (ins t2_so_imm:$imm), iii,
2830 [(set rGPR:$Rd, (opnode t2_so_imm:$imm))]>, Sched<[WriteALU]> {
2831 let isAsCheapAsAMove = Cheap;
2832 let isReMaterializable = ReMat;
2833 let isMoveImm = MoveImm;
2834 let Inst{31-27} = 0b11110;
2836 let Inst{24-21} = opcod;
2837 let Inst{19-16} = 0b1111; // Rn
2841 def r : T2sTwoReg<(outs rGPR:$Rd), (ins rGPR:$Rm), iir,
2842 opc, ".w\t$Rd, $Rm",
2843 [(set rGPR:$Rd, (opnode rGPR:$Rm))]>, Sched<[WriteALU]> {
2844 let Inst{31-27} = 0b11101;
2845 let Inst{26-25} = 0b01;
2846 let Inst{24-21} = opcod;
2847 let Inst{19-16} = 0b1111; // Rn
2848 let Inst{14-12} = 0b000; // imm3
2849 let Inst{7-6} = 0b00; // imm2
2850 let Inst{5-4} = 0b00; // type
2853 def s : T2sOneRegShiftedReg<(outs rGPR:$Rd), (ins t2_so_reg:$ShiftedRm), iis,
2854 opc, ".w\t$Rd, $ShiftedRm",
2855 [(set rGPR:$Rd, (opnode t2_so_reg:$ShiftedRm))]>,
2857 let Inst{31-27} = 0b11101;
2858 let Inst{26-25} = 0b01;
2859 let Inst{24-21} = opcod;
2860 let Inst{19-16} = 0b1111; // Rn
2864 // Prefer over of t2EORri ra, rb, -1 because mvn has 16-bit version
2865 let AddedComplexity = 1 in
2866 defm t2MVN : T2I_un_irs <0b0011, "mvn",
2867 IIC_iMVNi, IIC_iMVNr, IIC_iMVNsi,
2870 let AddedComplexity = 1 in
2871 def : T2Pat<(and rGPR:$src, t2_so_imm_not:$imm),
2872 (t2BICri rGPR:$src, t2_so_imm_not:$imm)>;
2874 // top16Zero - answer true if the upper 16 bits of $src are 0, false otherwise
2875 def top16Zero: PatLeaf<(i32 rGPR:$src), [{
2876 return !SDValue(N,0)->getValueType(0).isVector() &&
2877 CurDAG->MaskedValueIsZero(SDValue(N,0), APInt::getHighBitsSet(32, 16));
2880 // so_imm_notSext is needed instead of so_imm_not, as the value of imm
2881 // will match the extended, not the original bitWidth for $src.
2882 def : T2Pat<(and top16Zero:$src, t2_so_imm_notSext:$imm),
2883 (t2BICri rGPR:$src, t2_so_imm_notSext:$imm)>;
2886 // FIXME: Disable this pattern on Darwin to workaround an assembler bug.
2887 def : T2Pat<(or rGPR:$src, t2_so_imm_not:$imm),
2888 (t2ORNri rGPR:$src, t2_so_imm_not:$imm)>,
2889 Requires<[IsThumb2]>;
2891 def : T2Pat<(t2_so_imm_not:$src),
2892 (t2MVNi t2_so_imm_not:$src)>;
2894 // There are shorter Thumb encodings for ADD than ORR, so to increase
2895 // Thumb2SizeReduction's chances later on we select a t2ADD for an or where
2897 def : T2Pat<(or AddLikeOrOp:$Rn, t2_so_imm:$imm),
2898 (t2ADDri rGPR:$Rn, t2_so_imm:$imm)>;
2900 def : T2Pat<(or AddLikeOrOp:$Rn, imm0_4095:$Rm),
2901 (t2ADDri12 rGPR:$Rn, imm0_4095:$Rm)>;
2903 def : T2Pat<(or AddLikeOrOp:$Rn, non_imm32:$Rm),
2904 (t2ADDrr $Rn, $Rm)>;
2906 //===----------------------------------------------------------------------===//
2907 // Multiply Instructions.
2909 let isCommutable = 1 in
2910 def t2MUL: T2ThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iMUL32,
2911 "mul", "\t$Rd, $Rn, $Rm",
2912 [(set rGPR:$Rd, (mul rGPR:$Rn, rGPR:$Rm))]>,
2913 Sched<[WriteMUL32, ReadMUL, ReadMUL]> {
2914 let Inst{31-27} = 0b11111;
2915 let Inst{26-23} = 0b0110;
2916 let Inst{22-20} = 0b000;
2917 let Inst{15-12} = 0b1111; // Ra = 0b1111 (no accumulate)
2918 let Inst{7-4} = 0b0000; // Multiply
2921 class T2FourRegMLA<bits<4> op7_4, string opc, list<dag> pattern>
2922 : T2FourReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC32,
2923 opc, "\t$Rd, $Rn, $Rm, $Ra", pattern>,
2924 Requires<[IsThumb2, UseMulOps]>,
2925 Sched<[WriteMAC32, ReadMUL, ReadMUL, ReadMAC]> {
2926 let Inst{31-27} = 0b11111;
2927 let Inst{26-23} = 0b0110;
2928 let Inst{22-20} = 0b000;
2929 let Inst{7-4} = op7_4;
2932 def t2MLA : T2FourRegMLA<0b0000, "mla",
2933 [(set rGPR:$Rd, (add (mul rGPR:$Rn, rGPR:$Rm),
2935 def t2MLS: T2FourRegMLA<0b0001, "mls",
2936 [(set rGPR:$Rd, (sub rGPR:$Ra, (mul rGPR:$Rn,
2939 // Extra precision multiplies with low / high results
2940 let hasSideEffects = 0 in {
2941 let isCommutable = 1 in {
2942 def t2SMULL : T2MulLong<0b000, 0b0000, "smull",
2943 [(set rGPR:$RdLo, rGPR:$RdHi,
2944 (smullohi rGPR:$Rn, rGPR:$Rm))]>;
2945 def t2UMULL : T2MulLong<0b010, 0b0000, "umull",
2946 [(set rGPR:$RdLo, rGPR:$RdHi,
2947 (umullohi rGPR:$Rn, rGPR:$Rm))]>;
2950 // Multiply + accumulate
2951 def t2SMLAL : T2MlaLong<0b100, 0b0000, "smlal">;
2952 def t2UMLAL : T2MlaLong<0b110, 0b0000, "umlal">;
2953 def t2UMAAL : T2MlaLong<0b110, 0b0110, "umaal">, Requires<[IsThumb2, HasDSP]>;
2956 // Rounding variants of the below included for disassembly only
2958 // Most significant word multiply
2959 class T2SMMUL<bits<4> op7_4, string opc, list<dag> pattern>
2960 : T2ThreeReg<(outs rGPR:$Rd),
2961 (ins rGPR:$Rn, rGPR:$Rm), IIC_iMUL32,
2962 opc, "\t$Rd, $Rn, $Rm", pattern>,
2963 Requires<[IsThumb2, HasDSP]>,
2964 Sched<[WriteMUL32, ReadMUL, ReadMUL]> {
2965 let Inst{31-27} = 0b11111;
2966 let Inst{26-23} = 0b0110;
2967 let Inst{22-20} = 0b101;
2968 let Inst{15-12} = 0b1111; // Ra = 0b1111 (no accumulate)
2969 let Inst{7-4} = op7_4;
2971 def t2SMMUL : T2SMMUL<0b0000, "smmul", [(set rGPR:$Rd, (mulhs rGPR:$Rn,
2974 T2SMMUL<0b0001, "smmulr",
2975 [(set rGPR:$Rd, (ARMsmmlar rGPR:$Rn, rGPR:$Rm, (i32 0)))]>;
2977 class T2FourRegSMMLA<bits<3> op22_20, bits<4> op7_4, string opc,
2979 : T2FourReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC32,
2980 opc, "\t$Rd, $Rn, $Rm, $Ra", pattern>,
2981 Requires<[IsThumb2, HasDSP, UseMulOps]>,
2982 Sched<[WriteMAC32, ReadMUL, ReadMUL, ReadMAC]> {
2983 let Inst{31-27} = 0b11111;
2984 let Inst{26-23} = 0b0110;
2985 let Inst{22-20} = op22_20;
2986 let Inst{7-4} = op7_4;
2989 def t2SMMLA : T2FourRegSMMLA<0b101, 0b0000, "smmla",
2990 [(set rGPR:$Rd, (add (mulhs rGPR:$Rm, rGPR:$Rn), rGPR:$Ra))]>;
2991 def t2SMMLAR: T2FourRegSMMLA<0b101, 0b0001, "smmlar",
2992 [(set rGPR:$Rd, (ARMsmmlar rGPR:$Rn, rGPR:$Rm, rGPR:$Ra))]>;
2993 def t2SMMLS: T2FourRegSMMLA<0b110, 0b0000, "smmls", []>;
2994 def t2SMMLSR: T2FourRegSMMLA<0b110, 0b0001, "smmlsr",
2995 [(set rGPR:$Rd, (ARMsmmlsr rGPR:$Rn, rGPR:$Rm, rGPR:$Ra))]>;
2997 class T2ThreeRegSMUL<bits<3> op22_20, bits<2> op5_4, string opc,
2999 : T2ThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iMUL16, opc,
3000 "\t$Rd, $Rn, $Rm", pattern>,
3001 Requires<[IsThumb2, HasDSP]>,
3002 Sched<[WriteMUL16, ReadMUL, ReadMUL]> {
3003 let Inst{31-27} = 0b11111;
3004 let Inst{26-23} = 0b0110;
3005 let Inst{22-20} = op22_20;
3006 let Inst{15-12} = 0b1111; // Ra = 0b1111 (no accumulate)
3007 let Inst{7-6} = 0b00;
3008 let Inst{5-4} = op5_4;
3011 def t2SMULBB : T2ThreeRegSMUL<0b001, 0b00, "smulbb",
3012 [(set rGPR:$Rd, (bb_mul rGPR:$Rn, rGPR:$Rm))]>;
3013 def t2SMULBT : T2ThreeRegSMUL<0b001, 0b01, "smulbt",
3014 [(set rGPR:$Rd, (bt_mul rGPR:$Rn, rGPR:$Rm))]>;
3015 def t2SMULTB : T2ThreeRegSMUL<0b001, 0b10, "smultb",
3016 [(set rGPR:$Rd, (tb_mul rGPR:$Rn, rGPR:$Rm))]>;
3017 def t2SMULTT : T2ThreeRegSMUL<0b001, 0b11, "smultt",
3018 [(set rGPR:$Rd, (tt_mul rGPR:$Rn, rGPR:$Rm))]>;
3019 def t2SMULWB : T2ThreeRegSMUL<0b011, 0b00, "smulwb",
3020 [(set rGPR:$Rd, (ARMsmulwb rGPR:$Rn, rGPR:$Rm))]>;
3021 def t2SMULWT : T2ThreeRegSMUL<0b011, 0b01, "smulwt",
3022 [(set rGPR:$Rd, (ARMsmulwt rGPR:$Rn, rGPR:$Rm))]>;
3024 def : Thumb2DSPPat<(mul sext_16_node:$Rn, (sext_bottom_16 rGPR:$Rm)),
3025 (t2SMULBB rGPR:$Rn, rGPR:$Rm)>;
3026 def : Thumb2DSPPat<(mul sext_16_node:$Rn, (sext_top_16 rGPR:$Rm)),
3027 (t2SMULBT rGPR:$Rn, rGPR:$Rm)>;
3028 def : Thumb2DSPPat<(mul (sext_top_16 rGPR:$Rn), sext_16_node:$Rm),
3029 (t2SMULTB rGPR:$Rn, rGPR:$Rm)>;
3031 def : Thumb2DSPPat<(int_arm_smulbb rGPR:$Rn, rGPR:$Rm),
3032 (t2SMULBB rGPR:$Rn, rGPR:$Rm)>;
3033 def : Thumb2DSPPat<(int_arm_smulbt rGPR:$Rn, rGPR:$Rm),
3034 (t2SMULBT rGPR:$Rn, rGPR:$Rm)>;
3035 def : Thumb2DSPPat<(int_arm_smultb rGPR:$Rn, rGPR:$Rm),
3036 (t2SMULTB rGPR:$Rn, rGPR:$Rm)>;
3037 def : Thumb2DSPPat<(int_arm_smultt rGPR:$Rn, rGPR:$Rm),
3038 (t2SMULTT rGPR:$Rn, rGPR:$Rm)>;
3039 def : Thumb2DSPPat<(int_arm_smulwb rGPR:$Rn, rGPR:$Rm),
3040 (t2SMULWB rGPR:$Rn, rGPR:$Rm)>;
3041 def : Thumb2DSPPat<(int_arm_smulwt rGPR:$Rn, rGPR:$Rm),
3042 (t2SMULWT rGPR:$Rn, rGPR:$Rm)>;
3044 class T2FourRegSMLA<bits<3> op22_20, bits<2> op5_4, string opc,
3046 : T2FourReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMUL16,
3047 opc, "\t$Rd, $Rn, $Rm, $Ra", pattern>,
3048 Requires<[IsThumb2, HasDSP, UseMulOps]>,
3049 Sched<[WriteMAC16, ReadMUL, ReadMUL, ReadMAC]> {
3050 let Inst{31-27} = 0b11111;
3051 let Inst{26-23} = 0b0110;
3052 let Inst{22-20} = op22_20;
3053 let Inst{7-6} = 0b00;
3054 let Inst{5-4} = op5_4;
3057 def t2SMLABB : T2FourRegSMLA<0b001, 0b00, "smlabb",
3058 [(set rGPR:$Rd, (add rGPR:$Ra, (bb_mul rGPR:$Rn, rGPR:$Rm)))]>;
3059 def t2SMLABT : T2FourRegSMLA<0b001, 0b01, "smlabt",
3060 [(set rGPR:$Rd, (add rGPR:$Ra, (bt_mul rGPR:$Rn, rGPR:$Rm)))]>;
3061 def t2SMLATB : T2FourRegSMLA<0b001, 0b10, "smlatb",
3062 [(set rGPR:$Rd, (add rGPR:$Ra, (tb_mul rGPR:$Rn, rGPR:$Rm)))]>;
3063 def t2SMLATT : T2FourRegSMLA<0b001, 0b11, "smlatt",
3064 [(set rGPR:$Rd, (add rGPR:$Ra, (tt_mul rGPR:$Rn, rGPR:$Rm)))]>;
3065 def t2SMLAWB : T2FourRegSMLA<0b011, 0b00, "smlawb",
3066 [(set rGPR:$Rd, (add rGPR:$Ra, (ARMsmulwb rGPR:$Rn, rGPR:$Rm)))]>;
3067 def t2SMLAWT : T2FourRegSMLA<0b011, 0b01, "smlawt",
3068 [(set rGPR:$Rd, (add rGPR:$Ra, (ARMsmulwt rGPR:$Rn, rGPR:$Rm)))]>;
3070 def : Thumb2DSPMulPat<(add rGPR:$Ra, (mul sext_16_node:$Rn, sext_16_node:$Rm)),
3071 (t2SMLABB rGPR:$Rn, rGPR:$Rm, rGPR:$Ra)>;
3072 def : Thumb2DSPMulPat<(add rGPR:$Ra, (mul sext_16_node:$Rn,
3073 (sext_bottom_16 rGPR:$Rm))),
3074 (t2SMLABB rGPR:$Rn, rGPR:$Rm, rGPR:$Ra)>;
3075 def : Thumb2DSPMulPat<(add rGPR:$Ra, (mul sext_16_node:$Rn,
3076 (sext_top_16 rGPR:$Rm))),
3077 (t2SMLABT rGPR:$Rn, rGPR:$Rm, rGPR:$Ra)>;
3078 def : Thumb2DSPMulPat<(add rGPR:$Ra, (mul (sext_top_16 rGPR:$Rn),
3080 (t2SMLATB rGPR:$Rn, rGPR:$Rm, rGPR:$Ra)>;
3082 def : Thumb2DSPPat<(int_arm_smlabb GPR:$a, GPR:$b, GPR:$acc),
3083 (t2SMLABB GPR:$a, GPR:$b, GPR:$acc)>;
3084 def : Thumb2DSPPat<(int_arm_smlabt GPR:$a, GPR:$b, GPR:$acc),
3085 (t2SMLABT GPR:$a, GPR:$b, GPR:$acc)>;
3086 def : Thumb2DSPPat<(int_arm_smlatb GPR:$a, GPR:$b, GPR:$acc),
3087 (t2SMLATB GPR:$a, GPR:$b, GPR:$acc)>;
3088 def : Thumb2DSPPat<(int_arm_smlatt GPR:$a, GPR:$b, GPR:$acc),
3089 (t2SMLATT GPR:$a, GPR:$b, GPR:$acc)>;
3090 def : Thumb2DSPPat<(int_arm_smlawb GPR:$a, GPR:$b, GPR:$acc),
3091 (t2SMLAWB GPR:$a, GPR:$b, GPR:$acc)>;
3092 def : Thumb2DSPPat<(int_arm_smlawt GPR:$a, GPR:$b, GPR:$acc),
3093 (t2SMLAWT GPR:$a, GPR:$b, GPR:$acc)>;
3095 // Halfword multiple accumulate long: SMLAL<x><y>
3096 def t2SMLALBB : T2MlaLong<0b100, 0b1000, "smlalbb">,
3097 Requires<[IsThumb2, HasDSP]>;
3098 def t2SMLALBT : T2MlaLong<0b100, 0b1001, "smlalbt">,
3099 Requires<[IsThumb2, HasDSP]>;
3100 def t2SMLALTB : T2MlaLong<0b100, 0b1010, "smlaltb">,
3101 Requires<[IsThumb2, HasDSP]>;
3102 def t2SMLALTT : T2MlaLong<0b100, 0b1011, "smlaltt">,
3103 Requires<[IsThumb2, HasDSP]>;
3105 def : Thumb2DSPPat<(ARMsmlalbb GPR:$Rn, GPR:$Rm, GPR:$RLo, GPR:$RHi),
3106 (t2SMLALBB $Rn, $Rm, $RLo, $RHi)>;
3107 def : Thumb2DSPPat<(ARMsmlalbt GPR:$Rn, GPR:$Rm, GPR:$RLo, GPR:$RHi),
3108 (t2SMLALBT $Rn, $Rm, $RLo, $RHi)>;
3109 def : Thumb2DSPPat<(ARMsmlaltb GPR:$Rn, GPR:$Rm, GPR:$RLo, GPR:$RHi),
3110 (t2SMLALTB $Rn, $Rm, $RLo, $RHi)>;
3111 def : Thumb2DSPPat<(ARMsmlaltt GPR:$Rn, GPR:$Rm, GPR:$RLo, GPR:$RHi),
3112 (t2SMLALTT $Rn, $Rm, $RLo, $RHi)>;
3114 class T2DualHalfMul<bits<3> op22_20, bits<4> op7_4, string opc,
3115 Intrinsic intrinsic>
3116 : T2ThreeReg_mac<0, op22_20, op7_4,
3118 (ins rGPR:$Rn, rGPR:$Rm),
3119 IIC_iMAC32, opc, "\t$Rd, $Rn, $Rm",
3120 [(set rGPR:$Rd, (intrinsic rGPR:$Rn, rGPR:$Rm))]>,
3121 Requires<[IsThumb2, HasDSP]>,
3122 Sched<[WriteMAC32, ReadMUL, ReadMUL, ReadMAC]> {
3123 let Inst{15-12} = 0b1111;
3126 // Dual halfword multiple: SMUAD, SMUSD, SMLAD, SMLSD, SMLALD, SMLSLD
3127 def t2SMUAD: T2DualHalfMul<0b010, 0b0000, "smuad", int_arm_smuad>;
3128 def t2SMUADX: T2DualHalfMul<0b010, 0b0001, "smuadx", int_arm_smuadx>;
3129 def t2SMUSD: T2DualHalfMul<0b100, 0b0000, "smusd", int_arm_smusd>;
3130 def t2SMUSDX: T2DualHalfMul<0b100, 0b0001, "smusdx", int_arm_smusdx>;
3132 class T2DualHalfMulAdd<bits<3> op22_20, bits<4> op7_4, string opc,
3133 Intrinsic intrinsic>
3134 : T2FourReg_mac<0, op22_20, op7_4,
3136 (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra),
3137 IIC_iMAC32, opc, "\t$Rd, $Rn, $Rm, $Ra",
3138 [(set rGPR:$Rd, (intrinsic rGPR:$Rn, rGPR:$Rm, rGPR:$Ra))]>,
3139 Requires<[IsThumb2, HasDSP]>;
3141 def t2SMLAD : T2DualHalfMulAdd<0b010, 0b0000, "smlad", int_arm_smlad>;
3142 def t2SMLADX : T2DualHalfMulAdd<0b010, 0b0001, "smladx", int_arm_smladx>;
3143 def t2SMLSD : T2DualHalfMulAdd<0b100, 0b0000, "smlsd", int_arm_smlsd>;
3144 def t2SMLSDX : T2DualHalfMulAdd<0b100, 0b0001, "smlsdx", int_arm_smlsdx>;
3146 class T2DualHalfMulAddLong<bits<3> op22_20, bits<4> op7_4, string opc>
3147 : T2FourReg_mac<1, op22_20, op7_4,
3148 (outs rGPR:$Ra, rGPR:$Rd),
3149 (ins rGPR:$Rn, rGPR:$Rm, rGPR:$RLo, rGPR:$RHi),
3150 IIC_iMAC64, opc, "\t$Ra, $Rd, $Rn, $Rm", []>,
3151 RegConstraint<"$Ra = $RLo, $Rd = $RHi">,
3152 Requires<[IsThumb2, HasDSP]>,
3153 Sched<[WriteMAC64Lo, WriteMAC64Hi, ReadMUL, ReadMUL, ReadMAC, ReadMAC]>;
3155 def t2SMLALD : T2DualHalfMulAddLong<0b100, 0b1100, "smlald">;
3156 def t2SMLALDX : T2DualHalfMulAddLong<0b100, 0b1101, "smlaldx">;
3157 def t2SMLSLD : T2DualHalfMulAddLong<0b101, 0b1100, "smlsld">;
3158 def t2SMLSLDX : T2DualHalfMulAddLong<0b101, 0b1101, "smlsldx">;
3160 def : Thumb2DSPPat<(ARMSmlald rGPR:$Rn, rGPR:$Rm, rGPR:$RLo, rGPR:$RHi),
3161 (t2SMLALD rGPR:$Rn, rGPR:$Rm, rGPR:$RLo, rGPR:$RHi)>;
3162 def : Thumb2DSPPat<(ARMSmlaldx rGPR:$Rn, rGPR:$Rm, rGPR:$RLo, rGPR:$RHi),
3163 (t2SMLALDX rGPR:$Rn, rGPR:$Rm, rGPR:$RLo, rGPR:$RHi)>;
3164 def : Thumb2DSPPat<(ARMSmlsld rGPR:$Rn, rGPR:$Rm, rGPR:$RLo, rGPR:$RHi),
3165 (t2SMLSLD rGPR:$Rn, rGPR:$Rm, rGPR:$RLo, rGPR:$RHi)>;
3166 def : Thumb2DSPPat<(ARMSmlsldx rGPR:$Rn, rGPR:$Rm, rGPR:$RLo, rGPR:$RHi),
3167 (t2SMLSLDX rGPR:$Rn, rGPR:$Rm, rGPR:$RLo, rGPR:$RHi)>;
3169 //===----------------------------------------------------------------------===//
3170 // Division Instructions.
3171 // Signed and unsigned division on v7-M
3173 def t2SDIV : T2ThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iDIV,
3174 "sdiv", "\t$Rd, $Rn, $Rm",
3175 [(set rGPR:$Rd, (sdiv rGPR:$Rn, rGPR:$Rm))]>,
3176 Requires<[HasDivideInThumb, IsThumb, HasV8MBaseline]>,
3178 let Inst{31-27} = 0b11111;
3179 let Inst{26-21} = 0b011100;
3181 let Inst{15-12} = 0b1111;
3182 let Inst{7-4} = 0b1111;
3185 def t2UDIV : T2ThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iDIV,
3186 "udiv", "\t$Rd, $Rn, $Rm",
3187 [(set rGPR:$Rd, (udiv rGPR:$Rn, rGPR:$Rm))]>,
3188 Requires<[HasDivideInThumb, IsThumb, HasV8MBaseline]>,
3190 let Inst{31-27} = 0b11111;
3191 let Inst{26-21} = 0b011101;
3193 let Inst{15-12} = 0b1111;
3194 let Inst{7-4} = 0b1111;
3197 //===----------------------------------------------------------------------===//
3198 // Misc. Arithmetic Instructions.
3201 class T2I_misc<bits<2> op1, bits<2> op2, dag oops, dag iops,
3202 InstrItinClass itin, string opc, string asm, list<dag> pattern>
3203 : T2ThreeReg<oops, iops, itin, opc, asm, pattern> {
3204 let Inst{31-27} = 0b11111;
3205 let Inst{26-22} = 0b01010;
3206 let Inst{21-20} = op1;
3207 let Inst{15-12} = 0b1111;
3208 let Inst{7-6} = 0b10;
3209 let Inst{5-4} = op2;
3213 def t2CLZ : T2I_misc<0b11, 0b00, (outs rGPR:$Rd), (ins rGPR:$Rm), IIC_iUNAr,
3214 "clz", "\t$Rd, $Rm", [(set rGPR:$Rd, (ctlz rGPR:$Rm))]>,
3217 def t2RBIT : T2I_misc<0b01, 0b10, (outs rGPR:$Rd), (ins rGPR:$Rm), IIC_iUNAr,
3218 "rbit", "\t$Rd, $Rm",
3219 [(set rGPR:$Rd, (bitreverse rGPR:$Rm))]>,
3222 def t2REV : T2I_misc<0b01, 0b00, (outs rGPR:$Rd), (ins rGPR:$Rm), IIC_iUNAr,
3223 "rev", ".w\t$Rd, $Rm", [(set rGPR:$Rd, (bswap rGPR:$Rm))]>,
3226 def t2REV16 : T2I_misc<0b01, 0b01, (outs rGPR:$Rd), (ins rGPR:$Rm), IIC_iUNAr,
3227 "rev16", ".w\t$Rd, $Rm",
3228 [(set rGPR:$Rd, (rotr (bswap rGPR:$Rm), (i32 16)))]>,
3231 def t2REVSH : T2I_misc<0b01, 0b11, (outs rGPR:$Rd), (ins rGPR:$Rm), IIC_iUNAr,
3232 "revsh", ".w\t$Rd, $Rm",
3233 [(set rGPR:$Rd, (sra (bswap rGPR:$Rm), (i32 16)))]>,
3236 def : T2Pat<(or (sra (shl rGPR:$Rm, (i32 24)), (i32 16)),
3237 (and (srl rGPR:$Rm, (i32 8)), 0xFF)),
3238 (t2REVSH rGPR:$Rm)>;
3240 def t2PKHBT : T2ThreeReg<
3241 (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, pkh_lsl_amt:$sh),
3242 IIC_iBITsi, "pkhbt", "\t$Rd, $Rn, $Rm$sh",
3243 [(set rGPR:$Rd, (or (and rGPR:$Rn, 0xFFFF),
3244 (and (shl rGPR:$Rm, pkh_lsl_amt:$sh),
3246 Requires<[HasDSP, IsThumb2]>,
3247 Sched<[WriteALUsi, ReadALU]> {
3248 let Inst{31-27} = 0b11101;
3249 let Inst{26-25} = 0b01;
3250 let Inst{24-20} = 0b01100;
3251 let Inst{5} = 0; // BT form
3255 let Inst{14-12} = sh{4-2};
3256 let Inst{7-6} = sh{1-0};
3259 // Alternate cases for PKHBT where identities eliminate some nodes.
3260 def : T2Pat<(or (and rGPR:$src1, 0xFFFF), (and rGPR:$src2, 0xFFFF0000)),
3261 (t2PKHBT rGPR:$src1, rGPR:$src2, 0)>,
3262 Requires<[HasDSP, IsThumb2]>;
3263 def : T2Pat<(or (and rGPR:$src1, 0xFFFF), (shl rGPR:$src2, imm16_31:$sh)),
3264 (t2PKHBT rGPR:$src1, rGPR:$src2, imm16_31:$sh)>,
3265 Requires<[HasDSP, IsThumb2]>;
3267 // Note: Shifts of 1-15 bits will be transformed to srl instead of sra and
3268 // will match the pattern below.
3269 def t2PKHTB : T2ThreeReg<
3270 (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, pkh_asr_amt:$sh),
3271 IIC_iBITsi, "pkhtb", "\t$Rd, $Rn, $Rm$sh",
3272 [(set rGPR:$Rd, (or (and rGPR:$Rn, 0xFFFF0000),
3273 (and (sra rGPR:$Rm, pkh_asr_amt:$sh),
3275 Requires<[HasDSP, IsThumb2]>,
3276 Sched<[WriteALUsi, ReadALU]> {
3277 let Inst{31-27} = 0b11101;
3278 let Inst{26-25} = 0b01;
3279 let Inst{24-20} = 0b01100;
3280 let Inst{5} = 1; // TB form
3284 let Inst{14-12} = sh{4-2};
3285 let Inst{7-6} = sh{1-0};
3288 // Alternate cases for PKHTB where identities eliminate some nodes. Note that
3289 // a shift amount of 0 is *not legal* here, it is PKHBT instead.
3290 // We also can not replace a srl (17..31) by an arithmetic shift we would use in
3291 // pkhtb src1, src2, asr (17..31).
3292 def : T2Pat<(or (and rGPR:$src1, 0xFFFF0000), (srl rGPR:$src2, imm16:$sh)),
3293 (t2PKHTB rGPR:$src1, rGPR:$src2, imm16:$sh)>,
3294 Requires<[HasDSP, IsThumb2]>;
3295 def : T2Pat<(or (and rGPR:$src1, 0xFFFF0000), (sra rGPR:$src2, imm16_31:$sh)),
3296 (t2PKHTB rGPR:$src1, rGPR:$src2, imm16_31:$sh)>,
3297 Requires<[HasDSP, IsThumb2]>;
3298 def : T2Pat<(or (and rGPR:$src1, 0xFFFF0000),
3299 (and (srl rGPR:$src2, imm1_15:$sh), 0xFFFF)),
3300 (t2PKHTB rGPR:$src1, rGPR:$src2, imm1_15:$sh)>,
3301 Requires<[HasDSP, IsThumb2]>;
3303 //===----------------------------------------------------------------------===//
3304 // CRC32 Instructions
3307 // + CRC32{B,H,W} 0x04C11DB7
3308 // + CRC32C{B,H,W} 0x1EDC6F41
3311 class T2I_crc32<bit C, bits<2> sz, string suffix, SDPatternOperator builtin>
3312 : T2ThreeRegNoP<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), NoItinerary,
3313 !strconcat("crc32", suffix, "\t$Rd, $Rn, $Rm"),
3314 [(set rGPR:$Rd, (builtin rGPR:$Rn, rGPR:$Rm))]>,
3315 Requires<[IsThumb2, HasV8, HasCRC]> {
3316 let Inst{31-27} = 0b11111;
3317 let Inst{26-21} = 0b010110;
3319 let Inst{15-12} = 0b1111;
3320 let Inst{7-6} = 0b10;
3324 def t2CRC32B : T2I_crc32<0, 0b00, "b", int_arm_crc32b>;
3325 def t2CRC32CB : T2I_crc32<1, 0b00, "cb", int_arm_crc32cb>;
3326 def t2CRC32H : T2I_crc32<0, 0b01, "h", int_arm_crc32h>;
3327 def t2CRC32CH : T2I_crc32<1, 0b01, "ch", int_arm_crc32ch>;
3328 def t2CRC32W : T2I_crc32<0, 0b10, "w", int_arm_crc32w>;
3329 def t2CRC32CW : T2I_crc32<1, 0b10, "cw", int_arm_crc32cw>;
3331 //===----------------------------------------------------------------------===//
3332 // Comparison Instructions...
3334 defm t2CMP : T2I_cmp_irs<0b1101, "cmp", GPRnopc,
3335 IIC_iCMPi, IIC_iCMPr, IIC_iCMPsi, ARMcmp>;
3337 def : T2Pat<(ARMcmpZ GPRnopc:$lhs, t2_so_imm:$imm),
3338 (t2CMPri GPRnopc:$lhs, t2_so_imm:$imm)>;
3339 def : T2Pat<(ARMcmpZ GPRnopc:$lhs, rGPR:$rhs),
3340 (t2CMPrr GPRnopc:$lhs, rGPR:$rhs)>;
3341 def : T2Pat<(ARMcmpZ GPRnopc:$lhs, t2_so_reg:$rhs),
3342 (t2CMPrs GPRnopc:$lhs, t2_so_reg:$rhs)>;
3344 let isCompare = 1, Defs = [CPSR] in {
3346 def t2CMNri : T2OneRegCmpImm<
3347 (outs), (ins GPRnopc:$Rn, t2_so_imm:$imm), IIC_iCMPi,
3348 "cmn", ".w\t$Rn, $imm",
3349 [(ARMcmn GPRnopc:$Rn, (ineg t2_so_imm:$imm))]>,
3350 Sched<[WriteCMP, ReadALU]> {
3351 let Inst{31-27} = 0b11110;
3353 let Inst{24-21} = 0b1000;
3354 let Inst{20} = 1; // The S bit.
3356 let Inst{11-8} = 0b1111; // Rd
3359 def t2CMNzrr : T2TwoRegCmp<
3360 (outs), (ins GPRnopc:$Rn, rGPR:$Rm), IIC_iCMPr,
3361 "cmn", ".w\t$Rn, $Rm",
3362 [(BinOpFrag<(ARMcmpZ node:$LHS,(ineg node:$RHS))>
3363 GPRnopc:$Rn, rGPR:$Rm)]>, Sched<[WriteCMP, ReadALU, ReadALU]> {
3364 let Inst{31-27} = 0b11101;
3365 let Inst{26-25} = 0b01;
3366 let Inst{24-21} = 0b1000;
3367 let Inst{20} = 1; // The S bit.
3368 let Inst{14-12} = 0b000; // imm3
3369 let Inst{11-8} = 0b1111; // Rd
3370 let Inst{7-6} = 0b00; // imm2
3371 let Inst{5-4} = 0b00; // type
3374 def t2CMNzrs : T2OneRegCmpShiftedReg<
3375 (outs), (ins GPRnopc:$Rn, t2_so_reg:$ShiftedRm), IIC_iCMPsi,
3376 "cmn", ".w\t$Rn, $ShiftedRm",
3377 [(BinOpFrag<(ARMcmpZ node:$LHS,(ineg node:$RHS))>
3378 GPRnopc:$Rn, t2_so_reg:$ShiftedRm)]>,
3379 Sched<[WriteCMPsi, ReadALU, ReadALU]> {
3380 let Inst{31-27} = 0b11101;
3381 let Inst{26-25} = 0b01;
3382 let Inst{24-21} = 0b1000;
3383 let Inst{20} = 1; // The S bit.
3384 let Inst{11-8} = 0b1111; // Rd
3388 // Assembler aliases w/o the ".w" suffix.
3389 // No alias here for 'rr' version as not all instantiations of this multiclass
3390 // want one (CMP in particular, does not).
3391 def : t2InstAlias<"cmn${p} $Rn, $imm",
3392 (t2CMNri GPRnopc:$Rn, t2_so_imm:$imm, pred:$p)>;
3393 def : t2InstAlias<"cmn${p} $Rn, $shift",
3394 (t2CMNzrs GPRnopc:$Rn, t2_so_reg:$shift, pred:$p)>;
3396 def : T2Pat<(ARMcmp GPR:$src, t2_so_imm_neg:$imm),
3397 (t2CMNri GPR:$src, t2_so_imm_neg:$imm)>;
3399 def : T2Pat<(ARMcmpZ GPRnopc:$src, t2_so_imm_neg:$imm),
3400 (t2CMNri GPRnopc:$src, t2_so_imm_neg:$imm)>;
3402 defm t2TST : T2I_cmp_irs<0b0000, "tst", rGPR,
3403 IIC_iTSTi, IIC_iTSTr, IIC_iTSTsi,
3404 BinOpFrag<(ARMcmpZ (and_su node:$LHS, node:$RHS), 0)>>;
3405 defm t2TEQ : T2I_cmp_irs<0b0100, "teq", rGPR,
3406 IIC_iTSTi, IIC_iTSTr, IIC_iTSTsi,
3407 BinOpFrag<(ARMcmpZ (xor_su node:$LHS, node:$RHS), 0)>>;
3409 // Conditional moves
3410 let hasSideEffects = 0 in {
3412 let isCommutable = 1, isSelect = 1 in
3413 def t2MOVCCr : t2PseudoInst<(outs rGPR:$Rd),
3414 (ins rGPR:$false, rGPR:$Rm, cmovpred:$p),
3416 [(set rGPR:$Rd, (ARMcmov rGPR:$false, rGPR:$Rm,
3418 RegConstraint<"$false = $Rd">, Sched<[WriteALU]>;
3420 let isMoveImm = 1 in
3422 : t2PseudoInst<(outs rGPR:$Rd),
3423 (ins rGPR:$false, t2_so_imm:$imm, cmovpred:$p),
3425 [(set rGPR:$Rd, (ARMcmov rGPR:$false,t2_so_imm:$imm,
3427 RegConstraint<"$false = $Rd">, Sched<[WriteALU]>;
3429 let isCodeGenOnly = 1 in {
3430 let isMoveImm = 1 in
3432 : t2PseudoInst<(outs rGPR:$Rd),
3433 (ins rGPR:$false, imm0_65535_expr:$imm, cmovpred:$p),
3435 [(set rGPR:$Rd, (ARMcmov rGPR:$false, imm0_65535:$imm,
3437 RegConstraint<"$false = $Rd">, Sched<[WriteALU]>;
3439 let isMoveImm = 1 in
3441 : t2PseudoInst<(outs rGPR:$Rd),
3442 (ins rGPR:$false, t2_so_imm:$imm, cmovpred:$p),
3445 (ARMcmov rGPR:$false, t2_so_imm_not:$imm,
3447 RegConstraint<"$false = $Rd">, Sched<[WriteALU]>;
3449 class MOVCCShPseudo<SDPatternOperator opnode, Operand ty>
3450 : t2PseudoInst<(outs rGPR:$Rd),
3451 (ins rGPR:$false, rGPR:$Rm, i32imm:$imm, cmovpred:$p),
3453 [(set rGPR:$Rd, (ARMcmov rGPR:$false,
3454 (opnode rGPR:$Rm, (i32 ty:$imm)),
3456 RegConstraint<"$false = $Rd">, Sched<[WriteALU]>;
3458 def t2MOVCClsl : MOVCCShPseudo<shl, imm0_31>;
3459 def t2MOVCClsr : MOVCCShPseudo<srl, imm_sr>;
3460 def t2MOVCCasr : MOVCCShPseudo<sra, imm_sr>;
3461 def t2MOVCCror : MOVCCShPseudo<rotr, imm0_31>;
3463 let isMoveImm = 1 in
3465 : t2PseudoInst<(outs rGPR:$dst),
3466 (ins rGPR:$false, i32imm:$src, cmovpred:$p),
3468 [(set rGPR:$dst, (ARMcmov rGPR:$false, imm:$src,
3470 RegConstraint<"$false = $dst">;
3471 } // isCodeGenOnly = 1
3475 //===----------------------------------------------------------------------===//
3476 // Atomic operations intrinsics
3479 // memory barriers protect the atomic sequences
3480 let hasSideEffects = 1 in {
3481 def t2DMB : T2I<(outs), (ins memb_opt:$opt), NoItinerary,
3482 "dmb", "\t$opt", [(int_arm_dmb (i32 imm0_15:$opt))]>,
3483 Requires<[IsThumb, HasDB]> {
3485 let Inst{31-4} = 0xf3bf8f5;
3486 let Inst{3-0} = opt;
3489 def t2DSB : T2I<(outs), (ins memb_opt:$opt), NoItinerary,
3490 "dsb", "\t$opt", [(int_arm_dsb (i32 imm0_15:$opt))]>,
3491 Requires<[IsThumb, HasDB]> {
3493 let Inst{31-4} = 0xf3bf8f4;
3494 let Inst{3-0} = opt;
3497 def t2ISB : T2I<(outs), (ins instsyncb_opt:$opt), NoItinerary,
3498 "isb", "\t$opt", [(int_arm_isb (i32 imm0_15:$opt))]>,
3499 Requires<[IsThumb, HasDB]> {
3501 let Inst{31-4} = 0xf3bf8f6;
3502 let Inst{3-0} = opt;
3505 let hasNoSchedulingInfo = 1 in
3506 def t2TSB : T2I<(outs), (ins tsb_opt:$opt), NoItinerary,
3507 "tsb", "\t$opt", []>, Requires<[IsThumb, HasV8_4a]> {
3508 let Inst{31-0} = 0xf3af8012;
3512 // Armv8.5-A speculation barrier
3513 def t2SB : Thumb2XI<(outs), (ins), AddrModeNone, 4, NoItinerary, "sb", "", []>,
3514 Requires<[IsThumb2, HasSB]>, Sched<[]> {
3515 let Inst{31-0} = 0xf3bf8f70;
3516 let Unpredictable = 0x000f2f0f;
3517 let hasSideEffects = 1;
3520 class T2I_ldrex<bits<4> opcod, dag oops, dag iops, AddrMode am, int sz,
3521 InstrItinClass itin, string opc, string asm, string cstr,
3522 list<dag> pattern, bits<4> rt2 = 0b1111>
3523 : Thumb2I<oops, iops, am, sz, itin, opc, asm, cstr, pattern> {
3524 let Inst{31-27} = 0b11101;
3525 let Inst{26-20} = 0b0001101;
3526 let Inst{11-8} = rt2;
3527 let Inst{7-4} = opcod;
3528 let Inst{3-0} = 0b1111;
3532 let Inst{19-16} = addr;
3533 let Inst{15-12} = Rt;
3535 class T2I_strex<bits<4> opcod, dag oops, dag iops, AddrMode am, int sz,
3536 InstrItinClass itin, string opc, string asm, string cstr,
3537 list<dag> pattern, bits<4> rt2 = 0b1111>
3538 : Thumb2I<oops, iops, am, sz, itin, opc, asm, cstr, pattern> {
3539 let Inst{31-27} = 0b11101;
3540 let Inst{26-20} = 0b0001100;
3541 let Inst{11-8} = rt2;
3542 let Inst{7-4} = opcod;
3548 let Inst{19-16} = addr;
3549 let Inst{15-12} = Rt;
3552 let mayLoad = 1 in {
3553 def t2LDREXB : T2I_ldrex<0b0100, (outs rGPR:$Rt), (ins addr_offset_none:$addr),
3554 AddrModeNone, 4, NoItinerary,
3555 "ldrexb", "\t$Rt, $addr", "",
3556 [(set rGPR:$Rt, (ldrex_1 addr_offset_none:$addr))]>,
3557 Requires<[IsThumb, HasV8MBaseline]>, Sched<[WriteLd]>;
3558 def t2LDREXH : T2I_ldrex<0b0101, (outs rGPR:$Rt), (ins addr_offset_none:$addr),
3559 AddrModeNone, 4, NoItinerary,
3560 "ldrexh", "\t$Rt, $addr", "",
3561 [(set rGPR:$Rt, (ldrex_2 addr_offset_none:$addr))]>,
3562 Requires<[IsThumb, HasV8MBaseline]>, Sched<[WriteLd]>;
3563 def t2LDREX : Thumb2I<(outs rGPR:$Rt), (ins t2addrmode_imm0_1020s4:$addr),
3564 AddrModeT2_ldrex, 4, NoItinerary,
3565 "ldrex", "\t$Rt, $addr", "",
3566 [(set rGPR:$Rt, (ldrex_4 t2addrmode_imm0_1020s4:$addr))]>,
3567 Requires<[IsThumb, HasV8MBaseline]>, Sched<[WriteLd]> {
3570 let Inst{31-27} = 0b11101;
3571 let Inst{26-20} = 0b0000101;
3572 let Inst{19-16} = addr{11-8};
3573 let Inst{15-12} = Rt;
3574 let Inst{11-8} = 0b1111;
3575 let Inst{7-0} = addr{7-0};
3577 let hasExtraDefRegAllocReq = 1 in
3578 def t2LDREXD : T2I_ldrex<0b0111, (outs rGPR:$Rt, rGPR:$Rt2),
3579 (ins addr_offset_none:$addr),
3580 AddrModeNone, 4, NoItinerary,
3581 "ldrexd", "\t$Rt, $Rt2, $addr", "",
3583 Requires<[IsThumb2, IsNotMClass]>, Sched<[WriteLd]> {
3585 let Inst{11-8} = Rt2;
3587 def t2LDAEXB : T2I_ldrex<0b1100, (outs rGPR:$Rt), (ins addr_offset_none:$addr),
3588 AddrModeNone, 4, NoItinerary,
3589 "ldaexb", "\t$Rt, $addr", "",
3590 [(set rGPR:$Rt, (ldaex_1 addr_offset_none:$addr))]>,
3591 Requires<[IsThumb, HasAcquireRelease, HasV7Clrex]>, Sched<[WriteLd]>;
3592 def t2LDAEXH : T2I_ldrex<0b1101, (outs rGPR:$Rt), (ins addr_offset_none:$addr),
3593 AddrModeNone, 4, NoItinerary,
3594 "ldaexh", "\t$Rt, $addr", "",
3595 [(set rGPR:$Rt, (ldaex_2 addr_offset_none:$addr))]>,
3596 Requires<[IsThumb, HasAcquireRelease, HasV7Clrex]>, Sched<[WriteLd]>;
3597 def t2LDAEX : Thumb2I<(outs rGPR:$Rt), (ins addr_offset_none:$addr),
3598 AddrModeNone, 4, NoItinerary,
3599 "ldaex", "\t$Rt, $addr", "",
3600 [(set rGPR:$Rt, (ldaex_4 addr_offset_none:$addr))]>,
3601 Requires<[IsThumb, HasAcquireRelease, HasV7Clrex]>, Sched<[WriteLd]> {
3604 let Inst{31-27} = 0b11101;
3605 let Inst{26-20} = 0b0001101;
3606 let Inst{19-16} = addr;
3607 let Inst{15-12} = Rt;
3608 let Inst{11-8} = 0b1111;
3609 let Inst{7-0} = 0b11101111;
3611 let hasExtraDefRegAllocReq = 1 in
3612 def t2LDAEXD : T2I_ldrex<0b1111, (outs rGPR:$Rt, rGPR:$Rt2),
3613 (ins addr_offset_none:$addr),
3614 AddrModeNone, 4, NoItinerary,
3615 "ldaexd", "\t$Rt, $Rt2, $addr", "",
3616 [], {?, ?, ?, ?}>, Requires<[IsThumb,
3617 HasAcquireRelease, HasV7Clrex, IsNotMClass]>, Sched<[WriteLd]> {
3619 let Inst{11-8} = Rt2;
3625 let mayStore = 1, Constraints = "@earlyclobber $Rd" in {
3626 def t2STREXB : T2I_strex<0b0100, (outs rGPR:$Rd),
3627 (ins rGPR:$Rt, addr_offset_none:$addr),
3628 AddrModeNone, 4, NoItinerary,
3629 "strexb", "\t$Rd, $Rt, $addr", "",
3631 (strex_1 rGPR:$Rt, addr_offset_none:$addr))]>,
3632 Requires<[IsThumb, HasV8MBaseline]>, Sched<[WriteST]>;
3633 def t2STREXH : T2I_strex<0b0101, (outs rGPR:$Rd),
3634 (ins rGPR:$Rt, addr_offset_none:$addr),
3635 AddrModeNone, 4, NoItinerary,
3636 "strexh", "\t$Rd, $Rt, $addr", "",
3638 (strex_2 rGPR:$Rt, addr_offset_none:$addr))]>,
3639 Requires<[IsThumb, HasV8MBaseline]>, Sched<[WriteST]>;
3641 def t2STREX : Thumb2I<(outs rGPR:$Rd), (ins rGPR:$Rt,
3642 t2addrmode_imm0_1020s4:$addr),
3643 AddrModeT2_ldrex, 4, NoItinerary,
3644 "strex", "\t$Rd, $Rt, $addr", "",
3646 (strex_4 rGPR:$Rt, t2addrmode_imm0_1020s4:$addr))]>,
3647 Requires<[IsThumb, HasV8MBaseline]>, Sched<[WriteST]> {
3651 let Inst{31-27} = 0b11101;
3652 let Inst{26-20} = 0b0000100;
3653 let Inst{19-16} = addr{11-8};
3654 let Inst{15-12} = Rt;
3655 let Inst{11-8} = Rd;
3656 let Inst{7-0} = addr{7-0};
3658 let hasExtraSrcRegAllocReq = 1 in
3659 def t2STREXD : T2I_strex<0b0111, (outs rGPR:$Rd),
3660 (ins rGPR:$Rt, rGPR:$Rt2, addr_offset_none:$addr),
3661 AddrModeNone, 4, NoItinerary,
3662 "strexd", "\t$Rd, $Rt, $Rt2, $addr", "", [],
3664 Requires<[IsThumb2, IsNotMClass]>, Sched<[WriteST]> {
3666 let Inst{11-8} = Rt2;
3668 def t2STLEXB : T2I_strex<0b1100, (outs rGPR:$Rd),
3669 (ins rGPR:$Rt, addr_offset_none:$addr),
3670 AddrModeNone, 4, NoItinerary,
3671 "stlexb", "\t$Rd, $Rt, $addr", "",
3673 (stlex_1 rGPR:$Rt, addr_offset_none:$addr))]>,
3674 Requires<[IsThumb, HasAcquireRelease,
3675 HasV7Clrex]>, Sched<[WriteST]>;
3677 def t2STLEXH : T2I_strex<0b1101, (outs rGPR:$Rd),
3678 (ins rGPR:$Rt, addr_offset_none:$addr),
3679 AddrModeNone, 4, NoItinerary,
3680 "stlexh", "\t$Rd, $Rt, $addr", "",
3682 (stlex_2 rGPR:$Rt, addr_offset_none:$addr))]>,
3683 Requires<[IsThumb, HasAcquireRelease,
3684 HasV7Clrex]>, Sched<[WriteST]>;
3686 def t2STLEX : Thumb2I<(outs rGPR:$Rd), (ins rGPR:$Rt,
3687 addr_offset_none:$addr),
3688 AddrModeNone, 4, NoItinerary,
3689 "stlex", "\t$Rd, $Rt, $addr", "",
3691 (stlex_4 rGPR:$Rt, addr_offset_none:$addr))]>,
3692 Requires<[IsThumb, HasAcquireRelease, HasV7Clrex]>,
3697 let Inst{31-27} = 0b11101;
3698 let Inst{26-20} = 0b0001100;
3699 let Inst{19-16} = addr;
3700 let Inst{15-12} = Rt;
3701 let Inst{11-4} = 0b11111110;
3704 let hasExtraSrcRegAllocReq = 1 in
3705 def t2STLEXD : T2I_strex<0b1111, (outs rGPR:$Rd),
3706 (ins rGPR:$Rt, rGPR:$Rt2, addr_offset_none:$addr),
3707 AddrModeNone, 4, NoItinerary,
3708 "stlexd", "\t$Rd, $Rt, $Rt2, $addr", "", [],
3709 {?, ?, ?, ?}>, Requires<[IsThumb, HasAcquireRelease,
3710 HasV7Clrex, IsNotMClass]>, Sched<[WriteST]> {
3712 let Inst{11-8} = Rt2;
3716 def t2CLREX : T2I<(outs), (ins), NoItinerary, "clrex", "", [(int_arm_clrex)]>,
3717 Requires<[IsThumb, HasV7Clrex]> {
3718 let Inst{31-16} = 0xf3bf;
3719 let Inst{15-14} = 0b10;
3722 let Inst{11-8} = 0b1111;
3723 let Inst{7-4} = 0b0010;
3724 let Inst{3-0} = 0b1111;
3727 def : T2Pat<(and (ldrex_1 addr_offset_none:$addr), 0xff),
3728 (t2LDREXB addr_offset_none:$addr)>,
3729 Requires<[IsThumb, HasV8MBaseline]>;
3730 def : T2Pat<(and (ldrex_2 addr_offset_none:$addr), 0xffff),
3731 (t2LDREXH addr_offset_none:$addr)>,
3732 Requires<[IsThumb, HasV8MBaseline]>;
3733 def : T2Pat<(strex_1 (and GPR:$Rt, 0xff), addr_offset_none:$addr),
3734 (t2STREXB GPR:$Rt, addr_offset_none:$addr)>,
3735 Requires<[IsThumb, HasV8MBaseline]>;
3736 def : T2Pat<(strex_2 (and GPR:$Rt, 0xffff), addr_offset_none:$addr),
3737 (t2STREXH GPR:$Rt, addr_offset_none:$addr)>,
3738 Requires<[IsThumb, HasV8MBaseline]>;
3740 def : T2Pat<(and (ldaex_1 addr_offset_none:$addr), 0xff),
3741 (t2LDAEXB addr_offset_none:$addr)>,
3742 Requires<[IsThumb, HasAcquireRelease, HasV7Clrex]>;
3743 def : T2Pat<(and (ldaex_2 addr_offset_none:$addr), 0xffff),
3744 (t2LDAEXH addr_offset_none:$addr)>,
3745 Requires<[IsThumb, HasAcquireRelease, HasV7Clrex]>;
3746 def : T2Pat<(stlex_1 (and GPR:$Rt, 0xff), addr_offset_none:$addr),
3747 (t2STLEXB GPR:$Rt, addr_offset_none:$addr)>,
3748 Requires<[IsThumb, HasAcquireRelease, HasV7Clrex]>;
3749 def : T2Pat<(stlex_2 (and GPR:$Rt, 0xffff), addr_offset_none:$addr),
3750 (t2STLEXH GPR:$Rt, addr_offset_none:$addr)>,
3751 Requires<[IsThumb, HasAcquireRelease, HasV7Clrex]>;
3753 //===----------------------------------------------------------------------===//
3754 // SJLJ Exception handling intrinsics
3755 // eh_sjlj_setjmp() is an instruction sequence to store the return
3756 // address and save #0 in R0 for the non-longjmp case.
3757 // Since by its nature we may be coming from some other function to get
3758 // here, and we're using the stack frame for the containing function to
3759 // save/restore registers, we can't keep anything live in regs across
3760 // the eh_sjlj_setjmp(), else it will almost certainly have been tromped upon
3761 // when we get here from a longjmp(). We force everything out of registers
3762 // except for our own input by listing the relevant registers in Defs. By
3763 // doing so, we also cause the prologue/epilogue code to actively preserve
3764 // all of the callee-saved registers, which is exactly what we want.
3765 // $val is a scratch register for our use.
3767 [ R0, R1, R2, R3, R4, R5, R6, R7, R8, R9, R10, R11, R12, LR, CPSR,
3768 Q0, Q1, Q2, Q3, Q8, Q9, Q10, Q11, Q12, Q13, Q14, Q15],
3769 hasSideEffects = 1, isBarrier = 1, isCodeGenOnly = 1,
3770 usesCustomInserter = 1 in {
3771 def t2Int_eh_sjlj_setjmp : Thumb2XI<(outs), (ins tGPR:$src, tGPR:$val),
3772 AddrModeNone, 0, NoItinerary, "", "",
3773 [(set R0, (ARMeh_sjlj_setjmp tGPR:$src, tGPR:$val))]>,
3774 Requires<[IsThumb2, HasVFP2]>;
3778 [ R0, R1, R2, R3, R4, R5, R6, R7, R8, R9, R10, R11, R12, LR, CPSR ],
3779 hasSideEffects = 1, isBarrier = 1, isCodeGenOnly = 1,
3780 usesCustomInserter = 1 in {
3781 def t2Int_eh_sjlj_setjmp_nofp : Thumb2XI<(outs), (ins tGPR:$src, tGPR:$val),
3782 AddrModeNone, 0, NoItinerary, "", "",
3783 [(set R0, (ARMeh_sjlj_setjmp tGPR:$src, tGPR:$val))]>,
3784 Requires<[IsThumb2, NoVFP]>;
3788 //===----------------------------------------------------------------------===//
3789 // Control-Flow Instructions
3792 // FIXME: remove when we have a way to marking a MI with these properties.
3793 // FIXME: Should pc be an implicit operand like PICADD, etc?
3794 let isReturn = 1, isTerminator = 1, isBarrier = 1, mayLoad = 1,
3795 hasExtraDefRegAllocReq = 1, isCodeGenOnly = 1 in
3796 def t2LDMIA_RET: t2PseudoExpand<(outs GPR:$wb), (ins GPR:$Rn, pred:$p,
3797 reglist:$regs, variable_ops),
3798 4, IIC_iLoad_mBr, [],
3799 (t2LDMIA_UPD GPR:$wb, GPR:$Rn, pred:$p, reglist:$regs)>,
3800 RegConstraint<"$Rn = $wb">;
3802 let isBranch = 1, isTerminator = 1, isBarrier = 1 in {
3803 let isPredicable = 1 in
3804 def t2B : T2I<(outs), (ins thumb_br_target:$target), IIC_Br,
3806 [(br bb:$target)]>, Sched<[WriteBr]>,
3807 Requires<[IsThumb, HasV8MBaseline]> {
3808 let Inst{31-27} = 0b11110;
3809 let Inst{15-14} = 0b10;
3813 let Inst{26} = target{23};
3814 let Inst{13} = target{22};
3815 let Inst{11} = target{21};
3816 let Inst{25-16} = target{20-11};
3817 let Inst{10-0} = target{10-0};
3818 let DecoderMethod = "DecodeT2BInstruction";
3819 let AsmMatchConverter = "cvtThumbBranches";
3822 let Size = 4, isNotDuplicable = 1, isBranch = 1, isTerminator = 1,
3823 isBarrier = 1, isIndirectBranch = 1 in {
3825 // available in both v8-M.Baseline and Thumb2 targets
3826 def t2BR_JT : t2basePseudoInst<(outs),
3827 (ins GPR:$target, GPR:$index, i32imm:$jt),
3829 [(ARMbr2jt GPR:$target, GPR:$index, tjumptable:$jt)]>,
3832 // FIXME: Add a case that can be predicated.
3833 def t2TBB_JT : t2PseudoInst<(outs),
3834 (ins GPR:$base, GPR:$index, i32imm:$jt, i32imm:$pclbl), 0, IIC_Br, []>,
3837 def t2TBH_JT : t2PseudoInst<(outs),
3838 (ins GPR:$base, GPR:$index, i32imm:$jt, i32imm:$pclbl), 0, IIC_Br, []>,
3841 def t2TBB : T2I<(outs), (ins addrmode_tbb:$addr), IIC_Br,
3842 "tbb", "\t$addr", []>, Sched<[WriteBrTbl]> {
3845 let Inst{31-20} = 0b111010001101;
3846 let Inst{19-16} = Rn;
3847 let Inst{15-5} = 0b11110000000;
3848 let Inst{4} = 0; // B form
3851 let DecoderMethod = "DecodeThumbTableBranch";
3854 def t2TBH : T2I<(outs), (ins addrmode_tbh:$addr), IIC_Br,
3855 "tbh", "\t$addr", []>, Sched<[WriteBrTbl]> {
3858 let Inst{31-20} = 0b111010001101;
3859 let Inst{19-16} = Rn;
3860 let Inst{15-5} = 0b11110000000;
3861 let Inst{4} = 1; // H form
3864 let DecoderMethod = "DecodeThumbTableBranch";
3866 } // isNotDuplicable, isIndirectBranch
3868 } // isBranch, isTerminator, isBarrier
3870 // FIXME: should be able to write a pattern for ARMBrcond, but can't use
3871 // a two-value operand where a dag node expects ", "two operands. :(
3872 let isBranch = 1, isTerminator = 1 in
3873 def t2Bcc : T2I<(outs), (ins brtarget:$target), IIC_Br,
3875 [/*(ARMbrcond bb:$target, imm:$cc)*/]>, Sched<[WriteBr]> {
3876 let Inst{31-27} = 0b11110;
3877 let Inst{15-14} = 0b10;
3881 let Inst{25-22} = p;
3884 let Inst{26} = target{20};
3885 let Inst{11} = target{19};
3886 let Inst{13} = target{18};
3887 let Inst{21-16} = target{17-12};
3888 let Inst{10-0} = target{11-1};
3890 let DecoderMethod = "DecodeThumb2BCCInstruction";
3891 let AsmMatchConverter = "cvtThumbBranches";
3894 // Tail calls. The MachO version of thumb tail calls uses a t2 branch, so
3896 let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1 in {
3899 def tTAILJMPd: tPseudoExpand<(outs),
3900 (ins thumb_br_target:$dst, pred:$p),
3902 (t2B thumb_br_target:$dst, pred:$p)>,
3903 Requires<[IsThumb2, IsMachO]>, Sched<[WriteBr]>;
3907 let Defs = [ITSTATE] in
3908 def t2IT : Thumb2XI<(outs), (ins it_pred:$cc, it_mask:$mask),
3909 AddrModeNone, 2, IIC_iALUx,
3910 "it$mask\t$cc", "", []>,
3911 ComplexDeprecationPredicate<"IT"> {
3912 // 16-bit instruction.
3913 let Inst{31-16} = 0x0000;
3914 let Inst{15-8} = 0b10111111;
3919 let Inst{3-0} = mask;
3921 let DecoderMethod = "DecodeIT";
3924 // Branch and Exchange Jazelle -- for disassembly only
3926 let isBranch = 1, isTerminator = 1, isBarrier = 1, isIndirectBranch = 1 in
3927 def t2BXJ : T2I<(outs), (ins GPRnopc:$func), NoItinerary, "bxj", "\t$func", []>,
3928 Sched<[WriteBr]>, Requires<[IsThumb2, IsNotMClass]> {
3930 let Inst{31-27} = 0b11110;
3932 let Inst{25-20} = 0b111100;
3933 let Inst{19-16} = func;
3934 let Inst{15-0} = 0b1000111100000000;
3937 // Compare and branch on zero / non-zero
3938 let isBranch = 1, isTerminator = 1 in {
3939 def tCBZ : T1I<(outs), (ins tGPR:$Rn, thumb_cb_target:$target), IIC_Br,
3940 "cbz\t$Rn, $target", []>,
3941 T1Misc<{0,0,?,1,?,?,?}>,
3942 Requires<[IsThumb, HasV8MBaseline]>, Sched<[WriteBr]> {
3946 let Inst{9} = target{5};
3947 let Inst{7-3} = target{4-0};
3951 def tCBNZ : T1I<(outs), (ins tGPR:$Rn, thumb_cb_target:$target), IIC_Br,
3952 "cbnz\t$Rn, $target", []>,
3953 T1Misc<{1,0,?,1,?,?,?}>,
3954 Requires<[IsThumb, HasV8MBaseline]>, Sched<[WriteBr]> {
3958 let Inst{9} = target{5};
3959 let Inst{7-3} = target{4-0};
3965 // Change Processor State is a system instruction.
3966 // FIXME: Since the asm parser has currently no clean way to handle optional
3967 // operands, create 3 versions of the same instruction. Once there's a clean
3968 // framework to represent optional operands, change this behavior.
3969 class t2CPS<dag iops, string asm_op> : T2XI<(outs), iops, NoItinerary,
3970 !strconcat("cps", asm_op), []>,
3971 Requires<[IsThumb2, IsNotMClass]> {
3977 let Inst{31-11} = 0b111100111010111110000;
3978 let Inst{10-9} = imod;
3980 let Inst{7-5} = iflags;
3981 let Inst{4-0} = mode;
3982 let DecoderMethod = "DecodeT2CPSInstruction";
3986 def t2CPS3p : t2CPS<(ins imod_op:$imod, iflags_op:$iflags, i32imm:$mode),
3987 "$imod\t$iflags, $mode">;
3988 let mode = 0, M = 0 in
3989 def t2CPS2p : t2CPS<(ins imod_op:$imod, iflags_op:$iflags),
3990 "$imod.w\t$iflags">;
3991 let imod = 0, iflags = 0, M = 1 in
3992 def t2CPS1p : t2CPS<(ins imm0_31:$mode), "\t$mode">;
3994 def : t2InstAlias<"cps$imod.w $iflags, $mode",
3995 (t2CPS3p imod_op:$imod, iflags_op:$iflags, i32imm:$mode), 0>;
3996 def : t2InstAlias<"cps.w $mode", (t2CPS1p imm0_31:$mode), 0>;
3998 // A6.3.4 Branches and miscellaneous control
3999 // Table A6-14 Change Processor State, and hint instructions
4000 def t2HINT : T2I<(outs), (ins imm0_239:$imm), NoItinerary, "hint", ".w\t$imm",
4001 [(int_arm_hint imm0_239:$imm)]> {
4003 let Inst{31-3} = 0b11110011101011111000000000000;
4004 let Inst{7-0} = imm;
4007 def : t2InstAlias<"hint$p $imm", (t2HINT imm0_239:$imm, pred:$p), 0>;
4008 def : t2InstAlias<"nop$p.w", (t2HINT 0, pred:$p), 1>;
4009 def : t2InstAlias<"yield$p.w", (t2HINT 1, pred:$p), 1>;
4010 def : t2InstAlias<"wfe$p.w", (t2HINT 2, pred:$p), 1>;
4011 def : t2InstAlias<"wfi$p.w", (t2HINT 3, pred:$p), 1>;
4012 def : t2InstAlias<"sev$p.w", (t2HINT 4, pred:$p), 1>;
4013 def : t2InstAlias<"sevl$p.w", (t2HINT 5, pred:$p), 1> {
4014 let Predicates = [IsThumb2, HasV8];
4016 def : t2InstAlias<"esb$p.w", (t2HINT 16, pred:$p), 1> {
4017 let Predicates = [IsThumb2, HasRAS];
4019 def : t2InstAlias<"esb$p", (t2HINT 16, pred:$p), 0> {
4020 let Predicates = [IsThumb2, HasRAS];
4022 def : t2InstAlias<"csdb$p.w", (t2HINT 20, pred:$p), 0>;
4023 def : t2InstAlias<"csdb$p", (t2HINT 20, pred:$p), 1>;
4025 def t2DBG : T2I<(outs), (ins imm0_15:$opt), NoItinerary, "dbg", "\t$opt",
4026 [(int_arm_dbg imm0_15:$opt)]> {
4028 let Inst{31-20} = 0b111100111010;
4029 let Inst{19-16} = 0b1111;
4030 let Inst{15-8} = 0b10000000;
4031 let Inst{7-4} = 0b1111;
4032 let Inst{3-0} = opt;
4035 // Secure Monitor Call is a system instruction.
4036 // Option = Inst{19-16}
4037 let isCall = 1, Uses = [SP] in
4038 def t2SMC : T2I<(outs), (ins imm0_15:$opt), NoItinerary, "smc", "\t$opt",
4039 []>, Requires<[IsThumb2, HasTrustZone]> {
4040 let Inst{31-27} = 0b11110;
4041 let Inst{26-20} = 0b1111111;
4042 let Inst{15-12} = 0b1000;
4045 let Inst{19-16} = opt;
4048 class T2DCPS<bits<2> opt, string opc>
4049 : T2I<(outs), (ins), NoItinerary, opc, "", []>, Requires<[IsThumb2, HasV8]> {
4050 let Inst{31-27} = 0b11110;
4051 let Inst{26-20} = 0b1111000;
4052 let Inst{19-16} = 0b1111;
4053 let Inst{15-12} = 0b1000;
4054 let Inst{11-2} = 0b0000000000;
4055 let Inst{1-0} = opt;
4058 def t2DCPS1 : T2DCPS<0b01, "dcps1">;
4059 def t2DCPS2 : T2DCPS<0b10, "dcps2">;
4060 def t2DCPS3 : T2DCPS<0b11, "dcps3">;
4062 class T2SRS<bits<2> Op, bit W, dag oops, dag iops, InstrItinClass itin,
4063 string opc, string asm, list<dag> pattern>
4064 : T2I<oops, iops, itin, opc, asm, pattern>,
4065 Requires<[IsThumb2,IsNotMClass]> {
4067 let Inst{31-25} = 0b1110100;
4068 let Inst{24-23} = Op;
4071 let Inst{20-16} = 0b01101;
4072 let Inst{15-5} = 0b11000000000;
4073 let Inst{4-0} = mode{4-0};
4076 // Store Return State is a system instruction.
4077 def t2SRSDB_UPD : T2SRS<0b00, 1, (outs), (ins imm0_31:$mode), NoItinerary,
4078 "srsdb", "\tsp!, $mode", []>;
4079 def t2SRSDB : T2SRS<0b00, 0, (outs), (ins imm0_31:$mode), NoItinerary,
4080 "srsdb","\tsp, $mode", []>;
4081 def t2SRSIA_UPD : T2SRS<0b11, 1, (outs), (ins imm0_31:$mode), NoItinerary,
4082 "srsia","\tsp!, $mode", []>;
4083 def t2SRSIA : T2SRS<0b11, 0, (outs), (ins imm0_31:$mode), NoItinerary,
4084 "srsia","\tsp, $mode", []>;
4087 def : t2InstAlias<"srsdb${p} $mode", (t2SRSDB imm0_31:$mode, pred:$p)>;
4088 def : t2InstAlias<"srsdb${p} $mode!", (t2SRSDB_UPD imm0_31:$mode, pred:$p)>;
4090 def : t2InstAlias<"srsia${p} $mode", (t2SRSIA imm0_31:$mode, pred:$p)>;
4091 def : t2InstAlias<"srsia${p} $mode!", (t2SRSIA_UPD imm0_31:$mode, pred:$p)>;
4093 // Return From Exception is a system instruction.
4094 let isReturn = 1, isBarrier = 1, isTerminator = 1, Defs = [PC] in
4095 class T2RFE<bits<12> op31_20, dag oops, dag iops, InstrItinClass itin,
4096 string opc, string asm, list<dag> pattern>
4097 : T2I<oops, iops, itin, opc, asm, pattern>,
4098 Requires<[IsThumb2,IsNotMClass]> {
4099 let Inst{31-20} = op31_20{11-0};
4102 let Inst{19-16} = Rn;
4103 let Inst{15-0} = 0xc000;
4106 def t2RFEDBW : T2RFE<0b111010000011,
4107 (outs), (ins GPR:$Rn), NoItinerary, "rfedb", "\t$Rn!",
4108 [/* For disassembly only; pattern left blank */]>;
4109 def t2RFEDB : T2RFE<0b111010000001,
4110 (outs), (ins GPR:$Rn), NoItinerary, "rfedb", "\t$Rn",
4111 [/* For disassembly only; pattern left blank */]>;
4112 def t2RFEIAW : T2RFE<0b111010011011,
4113 (outs), (ins GPR:$Rn), NoItinerary, "rfeia", "\t$Rn!",
4114 [/* For disassembly only; pattern left blank */]>;
4115 def t2RFEIA : T2RFE<0b111010011001,
4116 (outs), (ins GPR:$Rn), NoItinerary, "rfeia", "\t$Rn",
4117 [/* For disassembly only; pattern left blank */]>;
4119 // B9.3.19 SUBS PC, LR, #imm (Thumb2) system instruction.
4120 // Exception return instruction is "subs pc, lr, #imm".
4121 let isReturn = 1, isBarrier = 1, isTerminator = 1, Defs = [PC] in
4122 def t2SUBS_PC_LR : T2I <(outs), (ins imm0_255:$imm), NoItinerary,
4123 "subs", "\tpc, lr, $imm",
4124 [(ARMintretflag imm0_255:$imm)]>,
4125 Requires<[IsThumb2,IsNotMClass]> {
4126 let Inst{31-8} = 0b111100111101111010001111;
4129 let Inst{7-0} = imm;
4132 // Hypervisor Call is a system instruction.
4134 def t2HVC : T2XI <(outs), (ins imm0_65535:$imm16), IIC_Br, "hvc.w\t$imm16", []>,
4135 Requires<[IsThumb2, HasVirtualization]>, Sched<[WriteBr]> {
4137 let Inst{31-20} = 0b111101111110;
4138 let Inst{19-16} = imm16{15-12};
4139 let Inst{15-12} = 0b1000;
4140 let Inst{11-0} = imm16{11-0};
4144 // Alias for HVC without the ".w" optional width specifier
4145 def : t2InstAlias<"hvc\t$imm16", (t2HVC imm0_65535:$imm16)>;
4147 // ERET - Return from exception in Hypervisor mode.
4148 // B9.3.3, B9.3.20: ERET is an alias for "SUBS PC, LR, #0" in an implementation that
4149 // includes virtualization extensions.
4150 def t2ERET : InstAlias<"eret${p}", (t2SUBS_PC_LR 0, pred:$p), 1>,
4151 Requires<[IsThumb2, HasVirtualization]>;
4153 //===----------------------------------------------------------------------===//
4154 // Non-Instruction Patterns
4157 // 32-bit immediate using movw + movt.
4158 // This is a single pseudo instruction to make it re-materializable.
4159 // FIXME: Remove this when we can do generalized remat.
4160 let isReMaterializable = 1, isMoveImm = 1 in
4161 def t2MOVi32imm : PseudoInst<(outs rGPR:$dst), (ins i32imm:$src), IIC_iMOVix2,
4162 [(set rGPR:$dst, (i32 imm:$src))]>,
4163 Requires<[IsThumb, UseMovt]>;
4165 // Pseudo instruction that combines movw + movt + add pc (if pic).
4166 // It also makes it possible to rematerialize the instructions.
4167 // FIXME: Remove this when we can do generalized remat and when machine licm
4168 // can properly the instructions.
4169 let isReMaterializable = 1 in {
4170 def t2MOV_ga_pcrel : PseudoInst<(outs rGPR:$dst), (ins i32imm:$addr),
4172 [(set rGPR:$dst, (ARMWrapperPIC tglobaladdr:$addr))]>,
4173 Requires<[IsThumb, HasV8MBaseline, UseMovtInPic]>;
4177 def : T2Pat<(ARMWrapperPIC tglobaltlsaddr :$dst),
4178 (t2MOV_ga_pcrel tglobaltlsaddr:$dst)>,
4179 Requires<[IsThumb2, UseMovtInPic]>;
4180 def : T2Pat<(ARMWrapper tglobaltlsaddr:$dst),
4181 (t2MOVi32imm tglobaltlsaddr:$dst)>,
4182 Requires<[IsThumb2, UseMovt]>;
4184 // ConstantPool, GlobalAddress, and JumpTable
4185 def : T2Pat<(ARMWrapper tconstpool :$dst), (t2LEApcrel tconstpool :$dst)>;
4186 def : T2Pat<(ARMWrapper texternalsym :$dst), (t2MOVi32imm texternalsym :$dst)>,
4187 Requires<[IsThumb, HasV8MBaseline, UseMovt]>;
4188 def : T2Pat<(ARMWrapper tglobaladdr :$dst), (t2MOVi32imm tglobaladdr :$dst)>,
4189 Requires<[IsThumb, HasV8MBaseline, UseMovt]>;
4191 def : T2Pat<(ARMWrapperJT tjumptable:$dst), (t2LEApcrelJT tjumptable:$dst)>;
4193 // Pseudo instruction that combines ldr from constpool and add pc. This should
4194 // be expanded into two instructions late to allow if-conversion and
4196 let canFoldAsLoad = 1, isReMaterializable = 1 in
4197 def t2LDRpci_pic : PseudoInst<(outs rGPR:$dst), (ins i32imm:$addr, pclabel:$cp),
4199 [(set rGPR:$dst, (ARMpic_add (load (ARMWrapper tconstpool:$addr)),
4201 Requires<[IsThumb2]>;
4203 // Pseudo instruction that combines movs + predicated rsbmi
4204 // to implement integer ABS
4205 let usesCustomInserter = 1, Defs = [CPSR], hasNoSchedulingInfo = 1 in {
4206 def t2ABS : PseudoInst<(outs rGPR:$dst), (ins rGPR:$src),
4207 NoItinerary, []>, Requires<[IsThumb2]>;
4210 //===----------------------------------------------------------------------===//
4211 // Coprocessor load/store -- for disassembly only
4213 class T2CI<bits<4> op31_28, dag oops, dag iops, string opc, string asm, list<dag> pattern>
4214 : T2I<oops, iops, NoItinerary, opc, asm, pattern> {
4215 let Inst{31-28} = op31_28;
4216 let Inst{27-25} = 0b110;
4219 multiclass t2LdStCop<bits<4> op31_28, bit load, bit Dbit, string asm, list<dag> pattern> {
4220 def _OFFSET : T2CI<op31_28,
4221 (outs), (ins p_imm:$cop, c_imm:$CRd, addrmode5:$addr),
4222 asm, "\t$cop, $CRd, $addr", pattern> {
4226 let Inst{24} = 1; // P = 1
4227 let Inst{23} = addr{8};
4228 let Inst{22} = Dbit;
4229 let Inst{21} = 0; // W = 0
4230 let Inst{20} = load;
4231 let Inst{19-16} = addr{12-9};
4232 let Inst{15-12} = CRd;
4233 let Inst{11-8} = cop;
4234 let Inst{7-0} = addr{7-0};
4235 let DecoderMethod = "DecodeCopMemInstruction";
4237 def _PRE : T2CI<op31_28,
4238 (outs), (ins p_imm:$cop, c_imm:$CRd, addrmode5_pre:$addr),
4239 asm, "\t$cop, $CRd, $addr!", []> {
4243 let Inst{24} = 1; // P = 1
4244 let Inst{23} = addr{8};
4245 let Inst{22} = Dbit;
4246 let Inst{21} = 1; // W = 1
4247 let Inst{20} = load;
4248 let Inst{19-16} = addr{12-9};
4249 let Inst{15-12} = CRd;
4250 let Inst{11-8} = cop;
4251 let Inst{7-0} = addr{7-0};
4252 let DecoderMethod = "DecodeCopMemInstruction";
4254 def _POST: T2CI<op31_28,
4255 (outs), (ins p_imm:$cop, c_imm:$CRd, addr_offset_none:$addr,
4256 postidx_imm8s4:$offset),
4257 asm, "\t$cop, $CRd, $addr, $offset", []> {
4262 let Inst{24} = 0; // P = 0
4263 let Inst{23} = offset{8};
4264 let Inst{22} = Dbit;
4265 let Inst{21} = 1; // W = 1
4266 let Inst{20} = load;
4267 let Inst{19-16} = addr;
4268 let Inst{15-12} = CRd;
4269 let Inst{11-8} = cop;
4270 let Inst{7-0} = offset{7-0};
4271 let DecoderMethod = "DecodeCopMemInstruction";
4273 def _OPTION : T2CI<op31_28, (outs),
4274 (ins p_imm:$cop, c_imm:$CRd, addr_offset_none:$addr,
4275 coproc_option_imm:$option),
4276 asm, "\t$cop, $CRd, $addr, $option", []> {
4281 let Inst{24} = 0; // P = 0
4282 let Inst{23} = 1; // U = 1
4283 let Inst{22} = Dbit;
4284 let Inst{21} = 0; // W = 0
4285 let Inst{20} = load;
4286 let Inst{19-16} = addr;
4287 let Inst{15-12} = CRd;
4288 let Inst{11-8} = cop;
4289 let Inst{7-0} = option;
4290 let DecoderMethod = "DecodeCopMemInstruction";
4294 let DecoderNamespace = "Thumb2CoProc" in {
4295 defm t2LDC : t2LdStCop<0b1110, 1, 0, "ldc", [(int_arm_ldc timm:$cop, timm:$CRd, addrmode5:$addr)]>;
4296 defm t2LDCL : t2LdStCop<0b1110, 1, 1, "ldcl", [(int_arm_ldcl timm:$cop, timm:$CRd, addrmode5:$addr)]>;
4297 defm t2LDC2 : t2LdStCop<0b1111, 1, 0, "ldc2", [(int_arm_ldc2 timm:$cop, timm:$CRd, addrmode5:$addr)]>, Requires<[PreV8,IsThumb2]>;
4298 defm t2LDC2L : t2LdStCop<0b1111, 1, 1, "ldc2l", [(int_arm_ldc2l timm:$cop, timm:$CRd, addrmode5:$addr)]>, Requires<[PreV8,IsThumb2]>;
4300 defm t2STC : t2LdStCop<0b1110, 0, 0, "stc", [(int_arm_stc timm:$cop, timm:$CRd, addrmode5:$addr)]>;
4301 defm t2STCL : t2LdStCop<0b1110, 0, 1, "stcl", [(int_arm_stcl timm:$cop, timm:$CRd, addrmode5:$addr)]>;
4302 defm t2STC2 : t2LdStCop<0b1111, 0, 0, "stc2", [(int_arm_stc2 timm:$cop, timm:$CRd, addrmode5:$addr)]>, Requires<[PreV8,IsThumb2]>;
4303 defm t2STC2L : t2LdStCop<0b1111, 0, 1, "stc2l", [(int_arm_stc2l timm:$cop, timm:$CRd, addrmode5:$addr)]>, Requires<[PreV8,IsThumb2]>;
4307 //===----------------------------------------------------------------------===//
4308 // Move between special register and ARM core register -- for disassembly only
4310 // Move to ARM core register from Special Register
4314 // A/R class can only move from CPSR or SPSR.
4315 def t2MRS_AR : T2I<(outs GPR:$Rd), (ins), NoItinerary, "mrs", "\t$Rd, apsr",
4316 []>, Requires<[IsThumb2,IsNotMClass]> {
4318 let Inst{31-12} = 0b11110011111011111000;
4319 let Inst{11-8} = Rd;
4320 let Inst{7-0} = 0b00000000;
4323 def : t2InstAlias<"mrs${p} $Rd, cpsr", (t2MRS_AR GPR:$Rd, pred:$p)>;
4325 def t2MRSsys_AR: T2I<(outs GPR:$Rd), (ins), NoItinerary, "mrs", "\t$Rd, spsr",
4326 []>, Requires<[IsThumb2,IsNotMClass]> {
4328 let Inst{31-12} = 0b11110011111111111000;
4329 let Inst{11-8} = Rd;
4330 let Inst{7-0} = 0b00000000;
4333 def t2MRSbanked : T2I<(outs rGPR:$Rd), (ins banked_reg:$banked),
4334 NoItinerary, "mrs", "\t$Rd, $banked", []>,
4335 Requires<[IsThumb, HasVirtualization]> {
4339 let Inst{31-21} = 0b11110011111;
4340 let Inst{20} = banked{5}; // R bit
4341 let Inst{19-16} = banked{3-0};
4342 let Inst{15-12} = 0b1000;
4343 let Inst{11-8} = Rd;
4344 let Inst{7-5} = 0b001;
4345 let Inst{4} = banked{4};
4346 let Inst{3-0} = 0b0000;
4352 // This MRS has a mask field in bits 7-0 and can take more values than
4353 // the A/R class (a full msr_mask).
4354 def t2MRS_M : T2I<(outs rGPR:$Rd), (ins msr_mask:$SYSm), NoItinerary,
4355 "mrs", "\t$Rd, $SYSm", []>,
4356 Requires<[IsThumb,IsMClass]> {
4359 let Inst{31-12} = 0b11110011111011111000;
4360 let Inst{11-8} = Rd;
4361 let Inst{7-0} = SYSm;
4363 let Unpredictable{20-16} = 0b11111;
4364 let Unpredictable{13} = 0b1;
4368 // Move from ARM core register to Special Register
4372 // No need to have both system and application versions, the encodings are the
4373 // same and the assembly parser has no way to distinguish between them. The mask
4374 // operand contains the special register (R Bit) in bit 4 and bits 3-0 contains
4375 // the mask with the fields to be accessed in the special register.
4376 let Defs = [CPSR] in
4377 def t2MSR_AR : T2I<(outs), (ins msr_mask:$mask, rGPR:$Rn),
4378 NoItinerary, "msr", "\t$mask, $Rn", []>,
4379 Requires<[IsThumb2,IsNotMClass]> {
4382 let Inst{31-21} = 0b11110011100;
4383 let Inst{20} = mask{4}; // R Bit
4384 let Inst{19-16} = Rn;
4385 let Inst{15-12} = 0b1000;
4386 let Inst{11-8} = mask{3-0};
4390 // However, the MSR (banked register) system instruction (ARMv7VE) *does* have a
4391 // separate encoding (distinguished by bit 5.
4392 def t2MSRbanked : T2I<(outs), (ins banked_reg:$banked, rGPR:$Rn),
4393 NoItinerary, "msr", "\t$banked, $Rn", []>,
4394 Requires<[IsThumb, HasVirtualization]> {
4398 let Inst{31-21} = 0b11110011100;
4399 let Inst{20} = banked{5}; // R bit
4400 let Inst{19-16} = Rn;
4401 let Inst{15-12} = 0b1000;
4402 let Inst{11-8} = banked{3-0};
4403 let Inst{7-5} = 0b001;
4404 let Inst{4} = banked{4};
4405 let Inst{3-0} = 0b0000;
4411 // Move from ARM core register to Special Register
4412 let Defs = [CPSR] in
4413 def t2MSR_M : T2I<(outs), (ins msr_mask:$SYSm, rGPR:$Rn),
4414 NoItinerary, "msr", "\t$SYSm, $Rn", []>,
4415 Requires<[IsThumb,IsMClass]> {
4418 let Inst{31-21} = 0b11110011100;
4420 let Inst{19-16} = Rn;
4421 let Inst{15-12} = 0b1000;
4422 let Inst{11-10} = SYSm{11-10};
4423 let Inst{9-8} = 0b00;
4424 let Inst{7-0} = SYSm{7-0};
4426 let Unpredictable{20} = 0b1;
4427 let Unpredictable{13} = 0b1;
4428 let Unpredictable{9-8} = 0b11;
4432 //===----------------------------------------------------------------------===//
4433 // Move between coprocessor and ARM core register
4436 class t2MovRCopro<bits<4> Op, string opc, bit direction, dag oops, dag iops,
4438 : T2Cop<Op, oops, iops, opc, "\t$cop, $opc1, $Rt, $CRn, $CRm, $opc2",
4440 let Inst{27-24} = 0b1110;
4441 let Inst{20} = direction;
4451 let Inst{15-12} = Rt;
4452 let Inst{11-8} = cop;
4453 let Inst{23-21} = opc1;
4454 let Inst{7-5} = opc2;
4455 let Inst{3-0} = CRm;
4456 let Inst{19-16} = CRn;
4458 let DecoderNamespace = "Thumb2CoProc";
4461 class t2MovRRCopro<bits<4> Op, string opc, bit direction, dag oops, dag iops,
4462 list<dag> pattern = []>
4463 : T2Cop<Op, oops, iops, opc, "\t$cop, $opc1, $Rt, $Rt2, $CRm", pattern> {
4464 let Inst{27-24} = 0b1100;
4465 let Inst{23-21} = 0b010;
4466 let Inst{20} = direction;
4474 let Inst{15-12} = Rt;
4475 let Inst{19-16} = Rt2;
4476 let Inst{11-8} = cop;
4477 let Inst{7-4} = opc1;
4478 let Inst{3-0} = CRm;
4480 let DecoderNamespace = "Thumb2CoProc";
4483 /* from ARM core register to coprocessor */
4484 def t2MCR : t2MovRCopro<0b1110, "mcr", 0,
4486 (ins p_imm:$cop, imm0_7:$opc1, GPR:$Rt, c_imm:$CRn,
4487 c_imm:$CRm, imm0_7:$opc2),
4488 [(int_arm_mcr timm:$cop, timm:$opc1, GPR:$Rt, timm:$CRn,
4489 timm:$CRm, timm:$opc2)]>,
4490 ComplexDeprecationPredicate<"MCR">;
4491 def : t2InstAlias<"mcr${p} $cop, $opc1, $Rt, $CRn, $CRm",
4492 (t2MCR p_imm:$cop, imm0_7:$opc1, GPR:$Rt, c_imm:$CRn,
4493 c_imm:$CRm, 0, pred:$p)>;
4494 def t2MCR2 : t2MovRCopro<0b1111, "mcr2", 0,
4495 (outs), (ins p_imm:$cop, imm0_7:$opc1, GPR:$Rt, c_imm:$CRn,
4496 c_imm:$CRm, imm0_7:$opc2),
4497 [(int_arm_mcr2 timm:$cop, timm:$opc1, GPR:$Rt, timm:$CRn,
4498 timm:$CRm, timm:$opc2)]> {
4499 let Predicates = [IsThumb2, PreV8];
4501 def : t2InstAlias<"mcr2${p} $cop, $opc1, $Rt, $CRn, $CRm",
4502 (t2MCR2 p_imm:$cop, imm0_7:$opc1, GPR:$Rt, c_imm:$CRn,
4503 c_imm:$CRm, 0, pred:$p)>;
4505 /* from coprocessor to ARM core register */
4506 def t2MRC : t2MovRCopro<0b1110, "mrc", 1,
4507 (outs GPRwithAPSR:$Rt), (ins p_imm:$cop, imm0_7:$opc1, c_imm:$CRn,
4508 c_imm:$CRm, imm0_7:$opc2), []>;
4509 def : t2InstAlias<"mrc${p} $cop, $opc1, $Rt, $CRn, $CRm",
4510 (t2MRC GPRwithAPSR:$Rt, p_imm:$cop, imm0_7:$opc1, c_imm:$CRn,
4511 c_imm:$CRm, 0, pred:$p)>;
4513 def t2MRC2 : t2MovRCopro<0b1111, "mrc2", 1,
4514 (outs GPRwithAPSR:$Rt), (ins p_imm:$cop, imm0_7:$opc1, c_imm:$CRn,
4515 c_imm:$CRm, imm0_7:$opc2), []> {
4516 let Predicates = [IsThumb2, PreV8];
4518 def : t2InstAlias<"mrc2${p} $cop, $opc1, $Rt, $CRn, $CRm",
4519 (t2MRC2 GPRwithAPSR:$Rt, p_imm:$cop, imm0_7:$opc1, c_imm:$CRn,
4520 c_imm:$CRm, 0, pred:$p)>;
4522 def : T2v6Pat<(int_arm_mrc timm:$cop, timm:$opc1, timm:$CRn, timm:$CRm, timm:$opc2),
4523 (t2MRC p_imm:$cop, imm0_7:$opc1, c_imm:$CRn, c_imm:$CRm, imm0_7:$opc2)>;
4525 def : T2v6Pat<(int_arm_mrc2 timm:$cop, timm:$opc1, timm:$CRn, timm:$CRm, timm:$opc2),
4526 (t2MRC2 p_imm:$cop, imm0_7:$opc1, c_imm:$CRn, c_imm:$CRm, imm0_7:$opc2)>;
4529 /* from ARM core register to coprocessor */
4530 def t2MCRR : t2MovRRCopro<0b1110, "mcrr", 0, (outs),
4531 (ins p_imm:$cop, imm0_15:$opc1, GPR:$Rt, GPR:$Rt2,
4533 [(int_arm_mcrr timm:$cop, timm:$opc1, GPR:$Rt, GPR:$Rt2,
4535 def t2MCRR2 : t2MovRRCopro<0b1111, "mcrr2", 0, (outs),
4536 (ins p_imm:$cop, imm0_15:$opc1, GPR:$Rt, GPR:$Rt2,
4538 [(int_arm_mcrr2 timm:$cop, timm:$opc1, GPR:$Rt,
4539 GPR:$Rt2, timm:$CRm)]> {
4540 let Predicates = [IsThumb2, PreV8];
4543 /* from coprocessor to ARM core register */
4544 def t2MRRC : t2MovRRCopro<0b1110, "mrrc", 1, (outs GPR:$Rt, GPR:$Rt2),
4545 (ins p_imm:$cop, imm0_15:$opc1, c_imm:$CRm)>;
4547 def t2MRRC2 : t2MovRRCopro<0b1111, "mrrc2", 1, (outs GPR:$Rt, GPR:$Rt2),
4548 (ins p_imm:$cop, imm0_15:$opc1, c_imm:$CRm)> {
4549 let Predicates = [IsThumb2, PreV8];
4552 //===----------------------------------------------------------------------===//
4553 // Other Coprocessor Instructions.
4556 def t2CDP : T2Cop<0b1110, (outs), (ins p_imm:$cop, imm0_15:$opc1,
4557 c_imm:$CRd, c_imm:$CRn, c_imm:$CRm, imm0_7:$opc2),
4558 "cdp", "\t$cop, $opc1, $CRd, $CRn, $CRm, $opc2",
4559 [(int_arm_cdp timm:$cop, timm:$opc1, timm:$CRd, timm:$CRn,
4560 timm:$CRm, timm:$opc2)]> {
4561 let Inst{27-24} = 0b1110;
4570 let Inst{3-0} = CRm;
4572 let Inst{7-5} = opc2;
4573 let Inst{11-8} = cop;
4574 let Inst{15-12} = CRd;
4575 let Inst{19-16} = CRn;
4576 let Inst{23-20} = opc1;
4578 let Predicates = [IsThumb2, PreV8];
4579 let DecoderNamespace = "Thumb2CoProc";
4582 def t2CDP2 : T2Cop<0b1111, (outs), (ins p_imm:$cop, imm0_15:$opc1,
4583 c_imm:$CRd, c_imm:$CRn, c_imm:$CRm, imm0_7:$opc2),
4584 "cdp2", "\t$cop, $opc1, $CRd, $CRn, $CRm, $opc2",
4585 [(int_arm_cdp2 timm:$cop, timm:$opc1, timm:$CRd, timm:$CRn,
4586 timm:$CRm, timm:$opc2)]> {
4587 let Inst{27-24} = 0b1110;
4596 let Inst{3-0} = CRm;
4598 let Inst{7-5} = opc2;
4599 let Inst{11-8} = cop;
4600 let Inst{15-12} = CRd;
4601 let Inst{19-16} = CRn;
4602 let Inst{23-20} = opc1;
4604 let Predicates = [IsThumb2, PreV8];
4605 let DecoderNamespace = "Thumb2CoProc";
4610 //===----------------------------------------------------------------------===//
4611 // ARMv8.1 Privilege Access Never extension
4615 def t2SETPAN : T1I<(outs), (ins imm0_1:$imm), NoItinerary, "setpan\t$imm", []>,
4616 T1Misc<0b0110000>, Requires<[IsThumb2, HasV8, HasV8_1a]> {
4621 let Inst{2-0} = 0b000;
4623 let Unpredictable{4} = 0b1;
4624 let Unpredictable{2-0} = 0b111;
4627 //===----------------------------------------------------------------------===//
4628 // ARMv8-M Security Extensions instructions
4631 let hasSideEffects = 1 in
4632 def t2SG : T2I<(outs), (ins), NoItinerary, "sg", "", []>,
4633 Requires<[Has8MSecExt]> {
4634 let Inst = 0xe97fe97f;
4637 class T2TT<bits<2> at, string asm, list<dag> pattern>
4638 : T2I<(outs rGPR:$Rt), (ins GPRnopc:$Rn), NoItinerary, asm, "\t$Rt, $Rn",
4643 let Inst{31-20} = 0b111010000100;
4644 let Inst{19-16} = Rn;
4645 let Inst{15-12} = 0b1111;
4646 let Inst{11-8} = Rt;
4648 let Inst{5-0} = 0b000000;
4650 let Unpredictable{5-0} = 0b111111;
4653 def t2TT : T2TT<0b00, "tt",
4654 [(set rGPR:$Rt, (int_arm_cmse_tt GPRnopc:$Rn))]>,
4655 Requires<[IsThumb, Has8MSecExt]>;
4656 def t2TTT : T2TT<0b01, "ttt",
4657 [(set rGPR:$Rt, (int_arm_cmse_ttt GPRnopc:$Rn))]>,
4658 Requires<[IsThumb, Has8MSecExt]>;
4659 def t2TTA : T2TT<0b10, "tta",
4660 [(set rGPR:$Rt, (int_arm_cmse_tta GPRnopc:$Rn))]>,
4661 Requires<[IsThumb, Has8MSecExt]>;
4662 def t2TTAT : T2TT<0b11, "ttat",
4663 [(set rGPR:$Rt, (int_arm_cmse_ttat GPRnopc:$Rn))]>,
4664 Requires<[IsThumb, Has8MSecExt]>;
4666 //===----------------------------------------------------------------------===//
4667 // Non-Instruction Patterns
4670 // SXT/UXT with no rotate
4671 let AddedComplexity = 16 in {
4672 def : T2Pat<(and rGPR:$Rm, 0x000000FF), (t2UXTB rGPR:$Rm, 0)>,
4673 Requires<[IsThumb2]>;
4674 def : T2Pat<(and rGPR:$Rm, 0x0000FFFF), (t2UXTH rGPR:$Rm, 0)>,
4675 Requires<[IsThumb2]>;
4676 def : T2Pat<(and rGPR:$Rm, 0x00FF00FF), (t2UXTB16 rGPR:$Rm, 0)>,
4677 Requires<[HasDSP, IsThumb2]>;
4678 def : T2Pat<(add rGPR:$Rn, (and rGPR:$Rm, 0x00FF)),
4679 (t2UXTAB rGPR:$Rn, rGPR:$Rm, 0)>,
4680 Requires<[HasDSP, IsThumb2]>;
4681 def : T2Pat<(add rGPR:$Rn, (and rGPR:$Rm, 0xFFFF)),
4682 (t2UXTAH rGPR:$Rn, rGPR:$Rm, 0)>,
4683 Requires<[HasDSP, IsThumb2]>;
4686 def : T2Pat<(sext_inreg rGPR:$Src, i8), (t2SXTB rGPR:$Src, 0)>,
4687 Requires<[IsThumb2]>;
4688 def : T2Pat<(sext_inreg rGPR:$Src, i16), (t2SXTH rGPR:$Src, 0)>,
4689 Requires<[IsThumb2]>;
4690 def : T2Pat<(add rGPR:$Rn, (sext_inreg rGPR:$Rm, i8)),
4691 (t2SXTAB rGPR:$Rn, rGPR:$Rm, 0)>,
4692 Requires<[HasDSP, IsThumb2]>;
4693 def : T2Pat<(add rGPR:$Rn, (sext_inreg rGPR:$Rm, i16)),
4694 (t2SXTAH rGPR:$Rn, rGPR:$Rm, 0)>,
4695 Requires<[HasDSP, IsThumb2]>;
4697 // Atomic load/store patterns
4698 def : T2Pat<(atomic_load_8 t2addrmode_imm12:$addr),
4699 (t2LDRBi12 t2addrmode_imm12:$addr)>;
4700 def : T2Pat<(atomic_load_8 t2addrmode_negimm8:$addr),
4701 (t2LDRBi8 t2addrmode_negimm8:$addr)>;
4702 def : T2Pat<(atomic_load_8 t2addrmode_so_reg:$addr),
4703 (t2LDRBs t2addrmode_so_reg:$addr)>;
4704 def : T2Pat<(atomic_load_16 t2addrmode_imm12:$addr),
4705 (t2LDRHi12 t2addrmode_imm12:$addr)>;
4706 def : T2Pat<(atomic_load_16 t2addrmode_negimm8:$addr),
4707 (t2LDRHi8 t2addrmode_negimm8:$addr)>;
4708 def : T2Pat<(atomic_load_16 t2addrmode_so_reg:$addr),
4709 (t2LDRHs t2addrmode_so_reg:$addr)>;
4710 def : T2Pat<(atomic_load_32 t2addrmode_imm12:$addr),
4711 (t2LDRi12 t2addrmode_imm12:$addr)>;
4712 def : T2Pat<(atomic_load_32 t2addrmode_negimm8:$addr),
4713 (t2LDRi8 t2addrmode_negimm8:$addr)>;
4714 def : T2Pat<(atomic_load_32 t2addrmode_so_reg:$addr),
4715 (t2LDRs t2addrmode_so_reg:$addr)>;
4716 def : T2Pat<(atomic_store_8 t2addrmode_imm12:$addr, GPR:$val),
4717 (t2STRBi12 GPR:$val, t2addrmode_imm12:$addr)>;
4718 def : T2Pat<(atomic_store_8 t2addrmode_negimm8:$addr, GPR:$val),
4719 (t2STRBi8 GPR:$val, t2addrmode_negimm8:$addr)>;
4720 def : T2Pat<(atomic_store_8 t2addrmode_so_reg:$addr, GPR:$val),
4721 (t2STRBs GPR:$val, t2addrmode_so_reg:$addr)>;
4722 def : T2Pat<(atomic_store_16 t2addrmode_imm12:$addr, GPR:$val),
4723 (t2STRHi12 GPR:$val, t2addrmode_imm12:$addr)>;
4724 def : T2Pat<(atomic_store_16 t2addrmode_negimm8:$addr, GPR:$val),
4725 (t2STRHi8 GPR:$val, t2addrmode_negimm8:$addr)>;
4726 def : T2Pat<(atomic_store_16 t2addrmode_so_reg:$addr, GPR:$val),
4727 (t2STRHs GPR:$val, t2addrmode_so_reg:$addr)>;
4728 def : T2Pat<(atomic_store_32 t2addrmode_imm12:$addr, GPR:$val),
4729 (t2STRi12 GPR:$val, t2addrmode_imm12:$addr)>;
4730 def : T2Pat<(atomic_store_32 t2addrmode_negimm8:$addr, GPR:$val),
4731 (t2STRi8 GPR:$val, t2addrmode_negimm8:$addr)>;
4732 def : T2Pat<(atomic_store_32 t2addrmode_so_reg:$addr, GPR:$val),
4733 (t2STRs GPR:$val, t2addrmode_so_reg:$addr)>;
4735 let AddedComplexity = 8, Predicates = [IsThumb, HasAcquireRelease, HasV7Clrex] in {
4736 def : Pat<(atomic_load_acquire_8 addr_offset_none:$addr), (t2LDAB addr_offset_none:$addr)>;
4737 def : Pat<(atomic_load_acquire_16 addr_offset_none:$addr), (t2LDAH addr_offset_none:$addr)>;
4738 def : Pat<(atomic_load_acquire_32 addr_offset_none:$addr), (t2LDA addr_offset_none:$addr)>;
4739 def : Pat<(atomic_store_release_8 addr_offset_none:$addr, GPR:$val), (t2STLB GPR:$val, addr_offset_none:$addr)>;
4740 def : Pat<(atomic_store_release_16 addr_offset_none:$addr, GPR:$val), (t2STLH GPR:$val, addr_offset_none:$addr)>;
4741 def : Pat<(atomic_store_release_32 addr_offset_none:$addr, GPR:$val), (t2STL GPR:$val, addr_offset_none:$addr)>;
4745 //===----------------------------------------------------------------------===//
4746 // Assembler aliases
4749 // Aliases for ADC without the ".w" optional width specifier.
4750 def : t2InstAlias<"adc${s}${p} $Rd, $Rn, $Rm",
4751 (t2ADCrr rGPR:$Rd, rGPR:$Rn, rGPR:$Rm, pred:$p, cc_out:$s)>;
4752 def : t2InstAlias<"adc${s}${p} $Rd, $Rn, $ShiftedRm",
4753 (t2ADCrs rGPR:$Rd, rGPR:$Rn, t2_so_reg:$ShiftedRm,
4754 pred:$p, cc_out:$s)>;
4756 // Aliases for SBC without the ".w" optional width specifier.
4757 def : t2InstAlias<"sbc${s}${p} $Rd, $Rn, $Rm",
4758 (t2SBCrr rGPR:$Rd, rGPR:$Rn, rGPR:$Rm, pred:$p, cc_out:$s)>;
4759 def : t2InstAlias<"sbc${s}${p} $Rd, $Rn, $ShiftedRm",
4760 (t2SBCrs rGPR:$Rd, rGPR:$Rn, t2_so_reg:$ShiftedRm,
4761 pred:$p, cc_out:$s)>;
4763 // Aliases for ADD without the ".w" optional width specifier.
4764 def : t2InstAlias<"add${s}${p} $Rd, $Rn, $imm",
4765 (t2ADDri rGPR:$Rd, GPRnopc:$Rn, t2_so_imm:$imm, pred:$p,
4767 def : t2InstAlias<"add${p} $Rd, $Rn, $imm",
4768 (t2ADDri12 rGPR:$Rd, GPR:$Rn, imm0_4095:$imm, pred:$p)>;
4769 def : t2InstAlias<"add${s}${p} $Rd, $Rn, $Rm",
4770 (t2ADDrr GPRnopc:$Rd, GPRnopc:$Rn, rGPR:$Rm, pred:$p, cc_out:$s)>;
4771 def : t2InstAlias<"add${s}${p} $Rd, $Rn, $ShiftedRm",
4772 (t2ADDrs GPRnopc:$Rd, GPRnopc:$Rn, t2_so_reg:$ShiftedRm,
4773 pred:$p, cc_out:$s)>;
4774 // ... and with the destination and source register combined.
4775 def : t2InstAlias<"add${s}${p} $Rdn, $imm",
4776 (t2ADDri rGPR:$Rdn, rGPR:$Rdn, t2_so_imm:$imm, pred:$p, cc_out:$s)>;
4777 def : t2InstAlias<"add${p} $Rdn, $imm",
4778 (t2ADDri12 rGPR:$Rdn, rGPR:$Rdn, imm0_4095:$imm, pred:$p)>;
4779 def : t2InstAlias<"addw${p} $Rdn, $imm",
4780 (t2ADDri12 rGPR:$Rdn, rGPR:$Rdn, imm0_4095:$imm, pred:$p)>;
4781 def : t2InstAlias<"add${s}${p} $Rdn, $Rm",
4782 (t2ADDrr GPRnopc:$Rdn, GPRnopc:$Rdn, rGPR:$Rm, pred:$p, cc_out:$s)>;
4783 def : t2InstAlias<"add${s}${p} $Rdn, $ShiftedRm",
4784 (t2ADDrs GPRnopc:$Rdn, GPRnopc:$Rdn, t2_so_reg:$ShiftedRm,
4785 pred:$p, cc_out:$s)>;
4787 // add w/ negative immediates is just a sub.
4788 def : t2InstSubst<"add${s}${p} $Rd, $Rn, $imm",
4789 (t2SUBri rGPR:$Rd, GPRnopc:$Rn, t2_so_imm_neg:$imm, pred:$p,
4791 def : t2InstSubst<"add${p} $Rd, $Rn, $imm",
4792 (t2SUBri12 rGPR:$Rd, GPR:$Rn, imm0_4095_neg:$imm, pred:$p)>;
4793 def : t2InstSubst<"add${s}${p} $Rdn, $imm",
4794 (t2SUBri rGPR:$Rdn, rGPR:$Rdn, t2_so_imm_neg:$imm, pred:$p,
4796 def : t2InstSubst<"add${p} $Rdn, $imm",
4797 (t2SUBri12 rGPR:$Rdn, rGPR:$Rdn, imm0_4095_neg:$imm, pred:$p)>;
4799 def : t2InstSubst<"add${s}${p}.w $Rd, $Rn, $imm",
4800 (t2SUBri rGPR:$Rd, GPRnopc:$Rn, t2_so_imm_neg:$imm, pred:$p,
4802 def : t2InstSubst<"addw${p} $Rd, $Rn, $imm",
4803 (t2SUBri12 rGPR:$Rd, rGPR:$Rn, imm0_4095_neg:$imm, pred:$p)>;
4804 def : t2InstSubst<"add${s}${p}.w $Rdn, $imm",
4805 (t2SUBri rGPR:$Rdn, rGPR:$Rdn, t2_so_imm_neg:$imm, pred:$p,
4807 def : t2InstSubst<"addw${p} $Rdn, $imm",
4808 (t2SUBri12 rGPR:$Rdn, rGPR:$Rdn, imm0_4095_neg:$imm, pred:$p)>;
4811 // Aliases for SUB without the ".w" optional width specifier.
4812 def : t2InstAlias<"sub${s}${p} $Rd, $Rn, $imm",
4813 (t2SUBri rGPR:$Rd, GPRnopc:$Rn, t2_so_imm:$imm, pred:$p, cc_out:$s)>;
4814 def : t2InstAlias<"sub${p} $Rd, $Rn, $imm",
4815 (t2SUBri12 rGPR:$Rd, GPR:$Rn, imm0_4095:$imm, pred:$p)>;
4816 def : t2InstAlias<"sub${s}${p} $Rd, $Rn, $Rm",
4817 (t2SUBrr GPRnopc:$Rd, GPRnopc:$Rn, rGPR:$Rm, pred:$p, cc_out:$s)>;
4818 def : t2InstAlias<"sub${s}${p} $Rd, $Rn, $ShiftedRm",
4819 (t2SUBrs GPRnopc:$Rd, GPRnopc:$Rn, t2_so_reg:$ShiftedRm,
4820 pred:$p, cc_out:$s)>;
4821 // ... and with the destination and source register combined.
4822 def : t2InstAlias<"sub${s}${p} $Rdn, $imm",
4823 (t2SUBri rGPR:$Rdn, rGPR:$Rdn, t2_so_imm:$imm, pred:$p, cc_out:$s)>;
4824 def : t2InstAlias<"sub${p} $Rdn, $imm",
4825 (t2SUBri12 rGPR:$Rdn, rGPR:$Rdn, imm0_4095:$imm, pred:$p)>;
4826 def : t2InstAlias<"subw${p} $Rdn, $imm",
4827 (t2SUBri12 rGPR:$Rdn, rGPR:$Rdn, imm0_4095:$imm, pred:$p)>;
4828 def : t2InstAlias<"sub${s}${p}.w $Rdn, $Rm",
4829 (t2SUBrr GPRnopc:$Rdn, GPRnopc:$Rdn, rGPR:$Rm, pred:$p, cc_out:$s)>;
4830 def : t2InstAlias<"sub${s}${p} $Rdn, $Rm",
4831 (t2SUBrr GPRnopc:$Rdn, GPRnopc:$Rdn, rGPR:$Rm, pred:$p, cc_out:$s)>;
4832 def : t2InstAlias<"sub${s}${p} $Rdn, $ShiftedRm",
4833 (t2SUBrs GPRnopc:$Rdn, GPRnopc:$Rdn, t2_so_reg:$ShiftedRm,
4834 pred:$p, cc_out:$s)>;
4836 // SP to SP alike aliases
4837 // Aliases for ADD without the ".w" optional width specifier.
4838 def : t2InstAlias<"add${s}${p} $Rd, $Rn, $imm",
4839 (t2ADDspImm GPRsp:$Rd, GPRsp:$Rn, t2_so_imm:$imm, pred:$p,
4841 def : t2InstAlias<"add${p} $Rd, $Rn, $imm",
4842 (t2ADDspImm12 GPRsp:$Rd, GPRsp:$Rn, imm0_4095:$imm, pred:$p)>;
4843 // ... and with the destination and source register combined.
4844 def : t2InstAlias<"add${s}${p} $Rdn, $imm",
4845 (t2ADDspImm GPRsp:$Rdn, GPRsp:$Rdn, t2_so_imm:$imm, pred:$p, cc_out:$s)>;
4847 def : t2InstAlias<"add${s}${p}.w $Rdn, $imm",
4848 (t2ADDspImm GPRsp:$Rdn, GPRsp:$Rdn, t2_so_imm:$imm, pred:$p, cc_out:$s)>;
4850 def : t2InstAlias<"add${p} $Rdn, $imm",
4851 (t2ADDspImm12 GPRsp:$Rdn, GPRsp:$Rdn, imm0_4095:$imm, pred:$p)>;
4853 def : t2InstAlias<"addw${p} $Rdn, $imm",
4854 (t2ADDspImm12 GPRsp:$Rdn, GPRsp:$Rdn, imm0_4095:$imm, pred:$p)>;
4856 // add w/ negative immediates is just a sub.
4857 def : t2InstSubst<"add${s}${p} $Rd, $Rn, $imm",
4858 (t2SUBspImm GPRsp:$Rd, GPRsp:$Rn, t2_so_imm_neg:$imm, pred:$p,
4860 def : t2InstSubst<"add${p} $Rd, $Rn, $imm",
4861 (t2SUBspImm12 GPRsp:$Rd, GPRsp:$Rn, imm0_4095_neg:$imm, pred:$p)>;
4862 def : t2InstSubst<"add${s}${p} $Rdn, $imm",
4863 (t2SUBspImm GPRsp:$Rdn, GPRsp:$Rdn, t2_so_imm_neg:$imm, pred:$p,
4865 def : t2InstSubst<"add${p} $Rdn, $imm",
4866 (t2SUBspImm12 GPRsp:$Rdn, GPRsp:$Rdn, imm0_4095_neg:$imm, pred:$p)>;
4868 def : t2InstSubst<"add${s}${p}.w $Rd, $Rn, $imm",
4869 (t2SUBspImm GPRsp:$Rd, GPRsp:$Rn, t2_so_imm_neg:$imm, pred:$p,
4871 def : t2InstSubst<"addw${p} $Rd, $Rn, $imm",
4872 (t2SUBspImm12 GPRsp:$Rd, GPRsp:$Rn, imm0_4095_neg:$imm, pred:$p)>;
4873 def : t2InstSubst<"add${s}${p}.w $Rdn, $imm",
4874 (t2SUBspImm GPRsp:$Rdn, GPRsp:$Rdn, t2_so_imm_neg:$imm, pred:$p,
4876 def : t2InstSubst<"addw${p} $Rdn, $imm",
4877 (t2SUBspImm12 GPRsp:$Rdn, GPRsp:$Rdn, imm0_4095_neg:$imm, pred:$p)>;
4880 // Aliases for SUB without the ".w" optional width specifier.
4881 def : t2InstAlias<"sub${s}${p} $Rd, $Rn, $imm",
4882 (t2SUBspImm GPRsp:$Rd, GPRsp:$Rn, t2_so_imm:$imm, pred:$p, cc_out:$s)>;
4883 def : t2InstAlias<"sub${p} $Rd, $Rn, $imm",
4884 (t2SUBspImm12 GPRsp:$Rd, GPRsp:$Rn, imm0_4095:$imm, pred:$p)>;
4885 // ... and with the destination and source register combined.
4886 def : t2InstAlias<"sub${s}${p} $Rdn, $imm",
4887 (t2SUBspImm GPRsp:$Rdn, GPRsp:$Rdn, t2_so_imm:$imm, pred:$p, cc_out:$s)>;
4888 def : t2InstAlias<"sub${s}${p}.w $Rdn, $imm",
4889 (t2SUBspImm GPRsp:$Rdn, GPRsp:$Rdn, t2_so_imm:$imm, pred:$p, cc_out:$s)>;
4890 def : t2InstAlias<"sub${p} $Rdn, $imm",
4891 (t2SUBspImm12 GPRsp:$Rdn, GPRsp:$Rdn, imm0_4095:$imm, pred:$p)>;
4892 def : t2InstAlias<"subw${p} $Rdn, $imm",
4893 (t2SUBspImm12 GPRsp:$Rdn, GPRsp:$Rdn, imm0_4095:$imm, pred:$p)>;
4895 // Alias for compares without the ".w" optional width specifier.
4896 def : t2InstAlias<"cmn${p} $Rn, $Rm",
4897 (t2CMNzrr GPRnopc:$Rn, rGPR:$Rm, pred:$p)>;
4898 def : t2InstAlias<"teq${p} $Rn, $Rm",
4899 (t2TEQrr rGPR:$Rn, rGPR:$Rm, pred:$p)>;
4900 def : t2InstAlias<"tst${p} $Rn, $Rm",
4901 (t2TSTrr rGPR:$Rn, rGPR:$Rm, pred:$p)>;
4904 def : InstAlias<"dmb${p}.w\t$opt", (t2DMB memb_opt:$opt, pred:$p), 0>, Requires<[HasDB]>;
4905 def : InstAlias<"dmb${p}", (t2DMB 0xf, pred:$p), 0>, Requires<[HasDB]>;
4906 def : InstAlias<"dmb${p}.w", (t2DMB 0xf, pred:$p), 0>, Requires<[HasDB]>;
4907 def : InstAlias<"dsb${p}.w\t$opt", (t2DSB memb_opt:$opt, pred:$p), 0>, Requires<[HasDB]>;
4908 def : InstAlias<"dsb${p}", (t2DSB 0xf, pred:$p), 0>, Requires<[HasDB]>;
4909 def : InstAlias<"dsb${p}.w", (t2DSB 0xf, pred:$p), 0>, Requires<[HasDB]>;
4910 def : InstAlias<"isb${p}.w\t$opt", (t2ISB memb_opt:$opt, pred:$p), 0>, Requires<[HasDB]>;
4911 def : InstAlias<"isb${p}", (t2ISB 0xf, pred:$p), 0>, Requires<[HasDB]>;
4912 def : InstAlias<"isb${p}.w", (t2ISB 0xf, pred:$p), 0>, Requires<[HasDB]>;
4914 // Non-predicable aliases of a predicable DSB: the predicate is (14, 0) where
4915 // 14 = AL (always execute) and 0 = "instruction doesn't read the CPSR".
4916 def : InstAlias<"ssbb", (t2DSB 0x0, 14, 0), 1>, Requires<[HasDB, IsThumb2]>;
4917 def : InstAlias<"pssbb", (t2DSB 0x4, 14, 0), 1>, Requires<[HasDB, IsThumb2]>;
4919 // Armv8-R 'Data Full Barrier'
4920 def : InstAlias<"dfb${p}", (t2DSB 0xc, pred:$p), 1>, Requires<[HasDFB]>;
4922 // Alias for LDR, LDRB, LDRH, LDRSB, and LDRSH without the ".w" optional
4924 def : t2InstAlias<"ldr${p} $Rt, $addr",
4925 (t2LDRi12 GPR:$Rt, t2addrmode_imm12:$addr, pred:$p)>;
4926 def : t2InstAlias<"ldrb${p} $Rt, $addr",
4927 (t2LDRBi12 rGPR:$Rt, t2addrmode_imm12:$addr, pred:$p)>;
4928 def : t2InstAlias<"ldrh${p} $Rt, $addr",
4929 (t2LDRHi12 rGPR:$Rt, t2addrmode_imm12:$addr, pred:$p)>;
4930 def : t2InstAlias<"ldrsb${p} $Rt, $addr",
4931 (t2LDRSBi12 rGPR:$Rt, t2addrmode_imm12:$addr, pred:$p)>;
4932 def : t2InstAlias<"ldrsh${p} $Rt, $addr",
4933 (t2LDRSHi12 rGPR:$Rt, t2addrmode_imm12:$addr, pred:$p)>;
4935 def : t2InstAlias<"ldr${p} $Rt, $addr",
4936 (t2LDRs GPR:$Rt, t2addrmode_so_reg:$addr, pred:$p)>;
4937 def : t2InstAlias<"ldrb${p} $Rt, $addr",
4938 (t2LDRBs rGPR:$Rt, t2addrmode_so_reg:$addr, pred:$p)>;
4939 def : t2InstAlias<"ldrh${p} $Rt, $addr",
4940 (t2LDRHs rGPR:$Rt, t2addrmode_so_reg:$addr, pred:$p)>;
4941 def : t2InstAlias<"ldrsb${p} $Rt, $addr",
4942 (t2LDRSBs rGPR:$Rt, t2addrmode_so_reg:$addr, pred:$p)>;
4943 def : t2InstAlias<"ldrsh${p} $Rt, $addr",
4944 (t2LDRSHs rGPR:$Rt, t2addrmode_so_reg:$addr, pred:$p)>;
4946 def : t2InstAlias<"ldr${p} $Rt, $addr",
4947 (t2LDRpci GPR:$Rt, t2ldrlabel:$addr, pred:$p)>;
4948 def : t2InstAlias<"ldrb${p} $Rt, $addr",
4949 (t2LDRBpci rGPR:$Rt, t2ldrlabel:$addr, pred:$p)>;
4950 def : t2InstAlias<"ldrh${p} $Rt, $addr",
4951 (t2LDRHpci rGPR:$Rt, t2ldrlabel:$addr, pred:$p)>;
4952 def : t2InstAlias<"ldrsb${p} $Rt, $addr",
4953 (t2LDRSBpci rGPR:$Rt, t2ldrlabel:$addr, pred:$p)>;
4954 def : t2InstAlias<"ldrsh${p} $Rt, $addr",
4955 (t2LDRSHpci rGPR:$Rt, t2ldrlabel:$addr, pred:$p)>;
4957 // Alias for MVN with(out) the ".w" optional width specifier.
4958 def : t2InstAlias<"mvn${s}${p}.w $Rd, $imm",
4959 (t2MVNi rGPR:$Rd, t2_so_imm:$imm, pred:$p, cc_out:$s)>;
4960 def : t2InstAlias<"mvn${s}${p} $Rd, $Rm",
4961 (t2MVNr rGPR:$Rd, rGPR:$Rm, pred:$p, cc_out:$s)>;
4962 def : t2InstAlias<"mvn${s}${p} $Rd, $ShiftedRm",
4963 (t2MVNs rGPR:$Rd, t2_so_reg:$ShiftedRm, pred:$p, cc_out:$s)>;
4965 // PKHBT/PKHTB with default shift amount. PKHTB is equivalent to PKHBT with the
4966 // input operands swapped when the shift amount is zero (i.e., unspecified).
4967 def : InstAlias<"pkhbt${p} $Rd, $Rn, $Rm",
4968 (t2PKHBT rGPR:$Rd, rGPR:$Rn, rGPR:$Rm, 0, pred:$p), 0>,
4969 Requires<[HasDSP, IsThumb2]>;
4970 def : InstAlias<"pkhtb${p} $Rd, $Rn, $Rm",
4971 (t2PKHBT rGPR:$Rd, rGPR:$Rm, rGPR:$Rn, 0, pred:$p), 0>,
4972 Requires<[HasDSP, IsThumb2]>;
4974 // PUSH/POP aliases for STM/LDM
4975 def : t2InstAlias<"push${p}.w $regs", (t2STMDB_UPD SP, pred:$p, reglist:$regs)>;
4976 def : t2InstAlias<"push${p} $regs", (t2STMDB_UPD SP, pred:$p, reglist:$regs)>;
4977 def : t2InstAlias<"pop${p}.w $regs", (t2LDMIA_UPD SP, pred:$p, reglist:$regs)>;
4978 def : t2InstAlias<"pop${p} $regs", (t2LDMIA_UPD SP, pred:$p, reglist:$regs)>;
4980 // STMIA/STMIA_UPD aliases w/o the optional .w suffix
4981 def : t2InstAlias<"stm${p} $Rn, $regs",
4982 (t2STMIA GPR:$Rn, pred:$p, reglist:$regs)>;
4983 def : t2InstAlias<"stm${p} $Rn!, $regs",
4984 (t2STMIA_UPD GPR:$Rn, pred:$p, reglist:$regs)>;
4986 // LDMIA/LDMIA_UPD aliases w/o the optional .w suffix
4987 def : t2InstAlias<"ldm${p} $Rn, $regs",
4988 (t2LDMIA GPR:$Rn, pred:$p, reglist:$regs)>;
4989 def : t2InstAlias<"ldm${p} $Rn!, $regs",
4990 (t2LDMIA_UPD GPR:$Rn, pred:$p, reglist:$regs)>;
4992 // STMDB/STMDB_UPD aliases w/ the optional .w suffix
4993 def : t2InstAlias<"stmdb${p}.w $Rn, $regs",
4994 (t2STMDB GPR:$Rn, pred:$p, reglist:$regs)>;
4995 def : t2InstAlias<"stmdb${p}.w $Rn!, $regs",
4996 (t2STMDB_UPD GPR:$Rn, pred:$p, reglist:$regs)>;
4998 // LDMDB/LDMDB_UPD aliases w/ the optional .w suffix
4999 def : t2InstAlias<"ldmdb${p}.w $Rn, $regs",
5000 (t2LDMDB GPR:$Rn, pred:$p, reglist:$regs)>;
5001 def : t2InstAlias<"ldmdb${p}.w $Rn!, $regs",
5002 (t2LDMDB_UPD GPR:$Rn, pred:$p, reglist:$regs)>;
5004 // Alias for REV/REV16/REVSH without the ".w" optional width specifier.
5005 def : t2InstAlias<"rev${p} $Rd, $Rm", (t2REV rGPR:$Rd, rGPR:$Rm, pred:$p)>;
5006 def : t2InstAlias<"rev16${p} $Rd, $Rm", (t2REV16 rGPR:$Rd, rGPR:$Rm, pred:$p)>;
5007 def : t2InstAlias<"revsh${p} $Rd, $Rm", (t2REVSH rGPR:$Rd, rGPR:$Rm, pred:$p)>;
5010 // Alias for RSB without the ".w" optional width specifier, and with optional
5011 // implied destination register.
5012 def : t2InstAlias<"rsb${s}${p} $Rd, $Rn, $imm",
5013 (t2RSBri rGPR:$Rd, rGPR:$Rn, t2_so_imm:$imm, pred:$p, cc_out:$s)>;
5014 def : t2InstAlias<"rsb${s}${p} $Rdn, $imm",
5015 (t2RSBri rGPR:$Rdn, rGPR:$Rdn, t2_so_imm:$imm, pred:$p, cc_out:$s)>;
5016 def : t2InstAlias<"rsb${s}${p} $Rdn, $Rm",
5017 (t2RSBrr rGPR:$Rdn, rGPR:$Rdn, rGPR:$Rm, pred:$p, cc_out:$s)>;
5018 def : t2InstAlias<"rsb${s}${p} $Rdn, $ShiftedRm",
5019 (t2RSBrs rGPR:$Rdn, rGPR:$Rdn, t2_so_reg:$ShiftedRm, pred:$p,
5022 // SSAT/USAT optional shift operand.
5023 def : t2InstAlias<"ssat${p} $Rd, $sat_imm, $Rn",
5024 (t2SSAT rGPR:$Rd, imm1_32:$sat_imm, rGPR:$Rn, 0, pred:$p)>;
5025 def : t2InstAlias<"usat${p} $Rd, $sat_imm, $Rn",
5026 (t2USAT rGPR:$Rd, imm0_31:$sat_imm, rGPR:$Rn, 0, pred:$p)>;
5028 // STM w/o the .w suffix.
5029 def : t2InstAlias<"stm${p} $Rn, $regs",
5030 (t2STMIA GPR:$Rn, pred:$p, reglist:$regs)>;
5032 // Alias for STR, STRB, and STRH without the ".w" optional
5034 def : t2InstAlias<"str${p} $Rt, $addr",
5035 (t2STRi12 GPR:$Rt, t2addrmode_imm12:$addr, pred:$p)>;
5036 def : t2InstAlias<"strb${p} $Rt, $addr",
5037 (t2STRBi12 rGPR:$Rt, t2addrmode_imm12:$addr, pred:$p)>;
5038 def : t2InstAlias<"strh${p} $Rt, $addr",
5039 (t2STRHi12 rGPR:$Rt, t2addrmode_imm12:$addr, pred:$p)>;
5041 def : t2InstAlias<"str${p} $Rt, $addr",
5042 (t2STRs GPR:$Rt, t2addrmode_so_reg:$addr, pred:$p)>;
5043 def : t2InstAlias<"strb${p} $Rt, $addr",
5044 (t2STRBs rGPR:$Rt, t2addrmode_so_reg:$addr, pred:$p)>;
5045 def : t2InstAlias<"strh${p} $Rt, $addr",
5046 (t2STRHs rGPR:$Rt, t2addrmode_so_reg:$addr, pred:$p)>;
5048 // Extend instruction optional rotate operand.
5049 def : InstAlias<"sxtab${p} $Rd, $Rn, $Rm",
5050 (t2SXTAB rGPR:$Rd, rGPR:$Rn, rGPR:$Rm, 0, pred:$p), 0>,
5051 Requires<[HasDSP, IsThumb2]>;
5052 def : InstAlias<"sxtah${p} $Rd, $Rn, $Rm",
5053 (t2SXTAH rGPR:$Rd, rGPR:$Rn, rGPR:$Rm, 0, pred:$p), 0>,
5054 Requires<[HasDSP, IsThumb2]>;
5055 def : InstAlias<"sxtab16${p} $Rd, $Rn, $Rm",
5056 (t2SXTAB16 rGPR:$Rd, rGPR:$Rn, rGPR:$Rm, 0, pred:$p), 0>,
5057 Requires<[HasDSP, IsThumb2]>;
5058 def : InstAlias<"sxtb16${p} $Rd, $Rm",
5059 (t2SXTB16 rGPR:$Rd, rGPR:$Rm, 0, pred:$p), 0>,
5060 Requires<[HasDSP, IsThumb2]>;
5062 def : t2InstAlias<"sxtb${p} $Rd, $Rm",
5063 (t2SXTB rGPR:$Rd, rGPR:$Rm, 0, pred:$p)>;
5064 def : t2InstAlias<"sxth${p} $Rd, $Rm",
5065 (t2SXTH rGPR:$Rd, rGPR:$Rm, 0, pred:$p)>;
5066 def : t2InstAlias<"sxtb${p}.w $Rd, $Rm",
5067 (t2SXTB rGPR:$Rd, rGPR:$Rm, 0, pred:$p)>;
5068 def : t2InstAlias<"sxth${p}.w $Rd, $Rm",
5069 (t2SXTH rGPR:$Rd, rGPR:$Rm, 0, pred:$p)>;
5071 def : InstAlias<"uxtab${p} $Rd, $Rn, $Rm",
5072 (t2UXTAB rGPR:$Rd, rGPR:$Rn, rGPR:$Rm, 0, pred:$p), 0>,
5073 Requires<[HasDSP, IsThumb2]>;
5074 def : InstAlias<"uxtah${p} $Rd, $Rn, $Rm",
5075 (t2UXTAH rGPR:$Rd, rGPR:$Rn, rGPR:$Rm, 0, pred:$p), 0>,
5076 Requires<[HasDSP, IsThumb2]>;
5077 def : InstAlias<"uxtab16${p} $Rd, $Rn, $Rm",
5078 (t2UXTAB16 rGPR:$Rd, rGPR:$Rn, rGPR:$Rm, 0, pred:$p), 0>,
5079 Requires<[HasDSP, IsThumb2]>;
5080 def : InstAlias<"uxtb16${p} $Rd, $Rm",
5081 (t2UXTB16 rGPR:$Rd, rGPR:$Rm, 0, pred:$p), 0>,
5082 Requires<[HasDSP, IsThumb2]>;
5084 def : t2InstAlias<"uxtb${p} $Rd, $Rm",
5085 (t2UXTB rGPR:$Rd, rGPR:$Rm, 0, pred:$p)>;
5086 def : t2InstAlias<"uxth${p} $Rd, $Rm",
5087 (t2UXTH rGPR:$Rd, rGPR:$Rm, 0, pred:$p)>;
5088 def : t2InstAlias<"uxtb${p}.w $Rd, $Rm",
5089 (t2UXTB rGPR:$Rd, rGPR:$Rm, 0, pred:$p)>;
5090 def : t2InstAlias<"uxth${p}.w $Rd, $Rm",
5091 (t2UXTH rGPR:$Rd, rGPR:$Rm, 0, pred:$p)>;
5093 // Extend instruction w/o the ".w" optional width specifier.
5094 def : t2InstAlias<"uxtb${p} $Rd, $Rm$rot",
5095 (t2UXTB rGPR:$Rd, rGPR:$Rm, rot_imm:$rot, pred:$p)>;
5096 def : InstAlias<"uxtb16${p} $Rd, $Rm$rot",
5097 (t2UXTB16 rGPR:$Rd, rGPR:$Rm, rot_imm:$rot, pred:$p), 0>,
5098 Requires<[HasDSP, IsThumb2]>;
5099 def : t2InstAlias<"uxth${p} $Rd, $Rm$rot",
5100 (t2UXTH rGPR:$Rd, rGPR:$Rm, rot_imm:$rot, pred:$p)>;
5102 def : t2InstAlias<"sxtb${p} $Rd, $Rm$rot",
5103 (t2SXTB rGPR:$Rd, rGPR:$Rm, rot_imm:$rot, pred:$p)>;
5104 def : InstAlias<"sxtb16${p} $Rd, $Rm$rot",
5105 (t2SXTB16 rGPR:$Rd, rGPR:$Rm, rot_imm:$rot, pred:$p), 0>,
5106 Requires<[HasDSP, IsThumb2]>;
5107 def : t2InstAlias<"sxth${p} $Rd, $Rm$rot",
5108 (t2SXTH rGPR:$Rd, rGPR:$Rm, rot_imm:$rot, pred:$p)>;
5111 // "mov Rd, t2_so_imm_not" can be handled via "mvn" in assembly, just like
5113 def : t2InstSubst<"mov${p} $Rd, $imm",
5114 (t2MVNi rGPR:$Rd, t2_so_imm_not:$imm, pred:$p, zero_reg)>;
5115 def : t2InstSubst<"mvn${s}${p} $Rd, $imm",
5116 (t2MOVi rGPR:$Rd, t2_so_imm_not:$imm, pred:$p, s_cc_out:$s)>;
5117 // Same for AND <--> BIC
5118 def : t2InstSubst<"bic${s}${p} $Rd, $Rn, $imm",
5119 (t2ANDri rGPR:$Rd, rGPR:$Rn, t2_so_imm_not:$imm,
5120 pred:$p, cc_out:$s)>;
5121 def : t2InstSubst<"bic${s}${p} $Rdn, $imm",
5122 (t2ANDri rGPR:$Rdn, rGPR:$Rdn, t2_so_imm_not:$imm,
5123 pred:$p, cc_out:$s)>;
5124 def : t2InstSubst<"bic${s}${p}.w $Rd, $Rn, $imm",
5125 (t2ANDri rGPR:$Rd, rGPR:$Rn, t2_so_imm_not:$imm,
5126 pred:$p, cc_out:$s)>;
5127 def : t2InstSubst<"bic${s}${p}.w $Rdn, $imm",
5128 (t2ANDri rGPR:$Rdn, rGPR:$Rdn, t2_so_imm_not:$imm,
5129 pred:$p, cc_out:$s)>;
5130 def : t2InstSubst<"and${s}${p} $Rd, $Rn, $imm",
5131 (t2BICri rGPR:$Rd, rGPR:$Rn, t2_so_imm_not:$imm,
5132 pred:$p, cc_out:$s)>;
5133 def : t2InstSubst<"and${s}${p} $Rdn, $imm",
5134 (t2BICri rGPR:$Rdn, rGPR:$Rdn, t2_so_imm_not:$imm,
5135 pred:$p, cc_out:$s)>;
5136 def : t2InstSubst<"and${s}${p}.w $Rd, $Rn, $imm",
5137 (t2BICri rGPR:$Rd, rGPR:$Rn, t2_so_imm_not:$imm,
5138 pred:$p, cc_out:$s)>;
5139 def : t2InstSubst<"and${s}${p}.w $Rdn, $imm",
5140 (t2BICri rGPR:$Rdn, rGPR:$Rdn, t2_so_imm_not:$imm,
5141 pred:$p, cc_out:$s)>;
5143 def : t2InstSubst<"orn${s}${p} $Rd, $Rn, $imm",
5144 (t2ORRri rGPR:$Rd, rGPR:$Rn, t2_so_imm_not:$imm,
5145 pred:$p, cc_out:$s)>;
5146 def : t2InstSubst<"orn${s}${p} $Rdn, $imm",
5147 (t2ORRri rGPR:$Rdn, rGPR:$Rdn, t2_so_imm_not:$imm,
5148 pred:$p, cc_out:$s)>;
5149 def : t2InstSubst<"orr${s}${p} $Rd, $Rn, $imm",
5150 (t2ORNri rGPR:$Rd, rGPR:$Rn, t2_so_imm_not:$imm,
5151 pred:$p, cc_out:$s)>;
5152 def : t2InstSubst<"orr${s}${p} $Rdn, $imm",
5153 (t2ORNri rGPR:$Rdn, rGPR:$Rdn, t2_so_imm_not:$imm,
5154 pred:$p, cc_out:$s)>;
5155 // Likewise, "add Rd, t2_so_imm_neg" -> sub
5156 def : t2InstSubst<"add${s}${p} $Rd, $Rn, $imm",
5157 (t2SUBri rGPR:$Rd, GPRnopc:$Rn, t2_so_imm_neg:$imm,
5158 pred:$p, cc_out:$s)>;
5159 def : t2InstSubst<"add${s}${p} $Rd, $Rn, $imm",
5160 (t2SUBspImm GPRsp:$Rd, GPRsp:$Rn, t2_so_imm_neg:$imm,
5161 pred:$p, cc_out:$s)>;
5162 def : t2InstSubst<"add${s}${p} $Rd, $imm",
5163 (t2SUBri rGPR:$Rd, rGPR:$Rd, t2_so_imm_neg:$imm,
5164 pred:$p, cc_out:$s)>;
5165 def : t2InstSubst<"add${s}${p} $Rd, $imm",
5166 (t2SUBspImm GPRsp:$Rd, GPRsp:$Rd, t2_so_imm_neg:$imm,
5167 pred:$p, cc_out:$s)>;
5168 // Same for CMP <--> CMN via t2_so_imm_neg
5169 def : t2InstSubst<"cmp${p} $Rd, $imm",
5170 (t2CMNri rGPR:$Rd, t2_so_imm_neg:$imm, pred:$p)>;
5171 def : t2InstSubst<"cmn${p} $Rd, $imm",
5172 (t2CMPri rGPR:$Rd, t2_so_imm_neg:$imm, pred:$p)>;
5175 // Wide 'mul' encoding can be specified with only two operands.
5176 def : t2InstAlias<"mul${p} $Rn, $Rm",
5177 (t2MUL rGPR:$Rn, rGPR:$Rm, rGPR:$Rn, pred:$p)>;
5179 // "neg" is and alias for "rsb rd, rn, #0"
5180 def : t2InstAlias<"neg${s}${p} $Rd, $Rm",
5181 (t2RSBri rGPR:$Rd, rGPR:$Rm, 0, pred:$p, cc_out:$s)>;
5183 // MOV so_reg assembler pseudos. InstAlias isn't expressive enough for
5184 // these, unfortunately.
5185 // FIXME: LSL #0 in the shift should allow SP to be used as either the
5186 // source or destination (but not both).
5187 def t2MOVsi: t2AsmPseudo<"mov${p} $Rd, $shift",
5188 (ins rGPR:$Rd, t2_so_reg:$shift, pred:$p)>;
5189 def t2MOVSsi: t2AsmPseudo<"movs${p} $Rd, $shift",
5190 (ins rGPR:$Rd, t2_so_reg:$shift, pred:$p)>;
5192 def t2MOVsr: t2AsmPseudo<"mov${p} $Rd, $shift",
5193 (ins rGPR:$Rd, so_reg_reg:$shift, pred:$p)>;
5194 def t2MOVSsr: t2AsmPseudo<"movs${p} $Rd, $shift",
5195 (ins rGPR:$Rd, so_reg_reg:$shift, pred:$p)>;
5197 // Aliases for the above with the .w qualifier
5198 def : t2InstAlias<"mov${p}.w $Rd, $shift",
5199 (t2MOVsi rGPR:$Rd, t2_so_reg:$shift, pred:$p)>;
5200 def : t2InstAlias<"movs${p}.w $Rd, $shift",
5201 (t2MOVSsi rGPR:$Rd, t2_so_reg:$shift, pred:$p)>;
5202 def : t2InstAlias<"mov${p}.w $Rd, $shift",
5203 (t2MOVsr rGPR:$Rd, so_reg_reg:$shift, pred:$p)>;
5204 def : t2InstAlias<"movs${p}.w $Rd, $shift",
5205 (t2MOVSsr rGPR:$Rd, so_reg_reg:$shift, pred:$p)>;
5207 // ADR w/o the .w suffix
5208 def : t2InstAlias<"adr${p} $Rd, $addr",
5209 (t2ADR rGPR:$Rd, t2adrlabel:$addr, pred:$p)>;
5211 // LDR(literal) w/ alternate [pc, #imm] syntax.
5212 def t2LDRpcrel : t2AsmPseudo<"ldr${p} $Rt, $addr",
5213 (ins GPR:$Rt, t2ldr_pcrel_imm12:$addr, pred:$p)>;
5214 def t2LDRBpcrel : t2AsmPseudo<"ldrb${p} $Rt, $addr",
5215 (ins GPRnopc:$Rt, t2ldr_pcrel_imm12:$addr, pred:$p)>;
5216 def t2LDRHpcrel : t2AsmPseudo<"ldrh${p} $Rt, $addr",
5217 (ins GPRnopc:$Rt, t2ldr_pcrel_imm12:$addr, pred:$p)>;
5218 def t2LDRSBpcrel : t2AsmPseudo<"ldrsb${p} $Rt, $addr",
5219 (ins GPRnopc:$Rt, t2ldr_pcrel_imm12:$addr, pred:$p)>;
5220 def t2LDRSHpcrel : t2AsmPseudo<"ldrsh${p} $Rt, $addr",
5221 (ins GPRnopc:$Rt, t2ldr_pcrel_imm12:$addr, pred:$p)>;
5222 // Version w/ the .w suffix.
5223 def : t2InstAlias<"ldr${p}.w $Rt, $addr",
5224 (t2LDRpcrel GPR:$Rt, t2ldr_pcrel_imm12:$addr, pred:$p), 0>;
5225 def : t2InstAlias<"ldrb${p}.w $Rt, $addr",
5226 (t2LDRBpcrel GPRnopc:$Rt, t2ldr_pcrel_imm12:$addr, pred:$p)>;
5227 def : t2InstAlias<"ldrh${p}.w $Rt, $addr",
5228 (t2LDRHpcrel GPRnopc:$Rt, t2ldr_pcrel_imm12:$addr, pred:$p)>;
5229 def : t2InstAlias<"ldrsb${p}.w $Rt, $addr",
5230 (t2LDRSBpcrel GPRnopc:$Rt, t2ldr_pcrel_imm12:$addr, pred:$p)>;
5231 def : t2InstAlias<"ldrsh${p}.w $Rt, $addr",
5232 (t2LDRSHpcrel GPRnopc:$Rt, t2ldr_pcrel_imm12:$addr, pred:$p)>;
5234 def : t2InstAlias<"add${p} $Rd, pc, $imm",
5235 (t2ADR rGPR:$Rd, imm0_4095:$imm, pred:$p)>;
5237 // Pseudo instruction ldr Rt, =immediate
5239 : t2AsmPseudo<"ldr${p} $Rt, $immediate",
5240 (ins GPR:$Rt, const_pool_asm_imm:$immediate, pred:$p)>;
5241 // Version w/ the .w suffix.
5242 def : t2InstAlias<"ldr${p}.w $Rt, $immediate",
5243 (t2LDRConstPool GPRnopc:$Rt,
5244 const_pool_asm_imm:$immediate, pred:$p)>;
5246 //===----------------------------------------------------------------------===//
5247 // ARMv8.1m instructions
5250 class V8_1MI<dag oops, dag iops, AddrMode am, InstrItinClass itin, string asm,
5251 string ops, string cstr, list<dag> pattern>
5252 : Thumb2XI<oops, iops, am, 4, itin, !strconcat(asm, "\t", ops), cstr,
5254 Requires<[HasV8_1MMainline]>;
5256 def t2CLRM : V8_1MI<(outs),
5257 (ins pred:$p, reglist_with_apsr:$regs, variable_ops),
5258 AddrModeNone, NoItinerary, "clrm${p}", "$regs", "", []> {
5261 let Inst{31-16} = 0b1110100010011111;
5262 let Inst{15-14} = regs{15-14};
5264 let Inst{12-0} = regs{12-0};
5267 class t2BF<dag iops, string asm, string ops>
5268 : V8_1MI<(outs ), iops, AddrModeNone, NoItinerary, asm, ops, "", []> {
5270 let Inst{31-27} = 0b11110;
5271 let Inst{15-14} = 0b11;
5275 let Predicates = [IsThumb2, HasV8_1MMainline, HasLOB];
5278 def t2BF_LabelPseudo
5279 : t2PseudoInst<(outs ), (ins pclabel:$cp), 0, NoItinerary, []> {
5280 let isTerminator = 1;
5281 let Predicates = [IsThumb2, HasV8_1MMainline, HasLOB];
5282 let hasNoSchedulingInfo = 1;
5285 def t2BFi : t2BF<(ins bflabel_u4:$b_label, bflabel_s16:$label, pred:$p),
5286 !strconcat("bf", "${p}"), "$b_label, $label"> {
5290 let Inst{26-23} = b_label{3-0};
5291 let Inst{22-21} = 0b10;
5292 let Inst{20-16} = label{15-11};
5294 let Inst{11} = label{0};
5295 let Inst{10-1} = label{10-1};
5298 def t2BFic : t2BF<(ins bflabel_u4:$b_label, bflabel_s12:$label,
5299 bfafter_target:$ba_label, pred_noal:$bcond), "bfcsel",
5300 "$b_label, $label, $ba_label, $bcond"> {
5306 let Inst{26-23} = b_label{3-0};
5308 let Inst{21-18} = bcond{3-0};
5309 let Inst{17} = ba_label{0};
5310 let Inst{16} = label{11};
5312 let Inst{11} = label{0};
5313 let Inst{10-1} = label{10-1};
5316 def t2BFr : t2BF<(ins bflabel_u4:$b_label, rGPR:$Rn, pred:$p),
5317 !strconcat("bfx", "${p}"), "$b_label, $Rn"> {
5321 let Inst{26-23} = b_label{3-0};
5322 let Inst{22-20} = 0b110;
5323 let Inst{19-16} = Rn{3-0};
5324 let Inst{13-1} = 0b1000000000000;
5327 def t2BFLi : t2BF<(ins bflabel_u4:$b_label, bflabel_s18:$label, pred:$p),
5328 !strconcat("bfl", "${p}"), "$b_label, $label"> {
5332 let Inst{26-23} = b_label{3-0};
5333 let Inst{22-16} = label{17-11};
5335 let Inst{11} = label{0};
5336 let Inst{10-1} = label{10-1};
5339 def t2BFLr : t2BF<(ins bflabel_u4:$b_label, rGPR:$Rn, pred:$p),
5340 !strconcat("bflx", "${p}"), "$b_label, $Rn"> {
5344 let Inst{26-23} = b_label{3-0};
5345 let Inst{22-20} = 0b111;
5346 let Inst{19-16} = Rn{3-0};
5347 let Inst{13-1} = 0b1000000000000;
5350 class t2LOL<dag oops, dag iops, string asm, string ops>
5351 : V8_1MI<oops, iops, AddrModeNone, NoItinerary, asm, ops, "", [] > {
5352 let Inst{31-23} = 0b111100000;
5353 let Inst{15-14} = 0b11;
5355 let DecoderMethod = "DecodeLOLoop";
5356 let Predicates = [IsThumb2, HasV8_1MMainline, HasLOB];
5359 let isNotDuplicable = 1 in {
5360 def t2WLS : t2LOL<(outs GPRlr:$LR),
5361 (ins rGPR:$Rn, wlslabel_u11:$label),
5362 "wls", "$LR, $Rn, $label"> {
5365 let Inst{22-20} = 0b100;
5366 let Inst{19-16} = Rn{3-0};
5367 let Inst{13-12} = 0b00;
5368 let Inst{11} = label{0};
5369 let Inst{10-1} = label{10-1};
5370 let usesCustomInserter = 1;
5372 let isTerminator = 1;
5375 def t2DLS : t2LOL<(outs GPRlr:$LR), (ins rGPR:$Rn),
5376 "dls", "$LR, $Rn"> {
5378 let Inst{22-20} = 0b100;
5379 let Inst{19-16} = Rn{3-0};
5380 let Inst{13-1} = 0b1000000000000;
5381 let usesCustomInserter = 1;
5384 def t2LEUpdate : t2LOL<(outs GPRlr:$LRout),
5385 (ins GPRlr:$LRin, lelabel_u11:$label),
5386 "le", "$LRin, $label"> {
5388 let Inst{22-16} = 0b0001111;
5389 let Inst{13-12} = 0b00;
5390 let Inst{11} = label{0};
5391 let Inst{10-1} = label{10-1};
5392 let usesCustomInserter = 1;
5394 let isTerminator = 1;
5397 def t2LE : t2LOL<(outs ), (ins lelabel_u11:$label), "le", "$label"> {
5399 let Inst{22-16} = 0b0101111;
5400 let Inst{13-12} = 0b00;
5401 let Inst{11} = label{0};
5402 let Inst{10-1} = label{10-1};
5404 let isTerminator = 1;
5408 t2PseudoInst<(outs), (ins rGPR:$elts), 4, IIC_Br,
5409 [(int_set_loop_iterations rGPR:$elts)]>, Sched<[WriteBr]>;
5411 let hasSideEffects = 0 in
5413 t2PseudoInst<(outs GPRlr:$Rm), (ins GPRlr:$Rn, imm0_7:$size),
5414 4, IIC_Br, []>, Sched<[WriteBr]>;
5416 let isBranch = 1, isTerminator = 1, hasSideEffects = 1, Defs = [CPSR] in {
5417 // Set WhileLoopStart and LoopEnd to occupy 8 bytes because they may
5418 // get converted into t2CMP and t2Bcc.
5419 def t2WhileLoopStart :
5420 t2PseudoInst<(outs),
5421 (ins rGPR:$elts, brtarget:$target),
5426 t2PseudoInst<(outs), (ins GPRlr:$elts, brtarget:$target),
5427 8, IIC_Br, []>, Sched<[WriteBr]>;
5429 } // end isBranch, isTerminator, hasSideEffects
5431 } // end isNotDuplicable
5433 class CS<string iname, bits<4> opcode, list<dag> pattern=[]>
5434 : V8_1MI<(outs rGPR:$Rd), (ins GPRwithZRnosp:$Rn, GPRwithZRnosp:$Rm, pred_noal:$fcond),
5435 AddrModeNone, NoItinerary, iname, "$Rd, $Rn, $Rm, $fcond", "", pattern> {
5441 let Inst{31-20} = 0b111010100101;
5442 let Inst{19-16} = Rn{3-0};
5443 let Inst{15-12} = opcode;
5444 let Inst{11-8} = Rd{3-0};
5445 let Inst{7-4} = fcond{3-0};
5446 let Inst{3-0} = Rm{3-0};
5451 def t2CSEL : CS<"csel", 0b1000>;
5452 def t2CSINC : CS<"csinc", 0b1001>;
5453 def t2CSINV : CS<"csinv", 0b1010>;
5454 def t2CSNEG : CS<"csneg", 0b1011>;
5456 let Predicates = [HasV8_1MMainline] in {
5457 def : T2Pat<(ARMcsinc GPRwithZR:$tval, GPRwithZR:$fval, imm0_31:$imm),
5458 (t2CSINC GPRwithZR:$tval, GPRwithZR:$fval, imm0_31:$imm)>;
5459 def : T2Pat<(ARMcsinv GPRwithZR:$tval, GPRwithZR:$fval, imm0_31:$imm),
5460 (t2CSINV GPRwithZR:$tval, GPRwithZR:$fval, imm0_31:$imm)>;
5461 def : T2Pat<(ARMcsneg GPRwithZR:$tval, GPRwithZR:$fval, imm0_31:$imm),
5462 (t2CSNEG GPRwithZR:$tval, GPRwithZR:$fval, imm0_31:$imm)>;
5464 multiclass ModifiedV8_1CSEL<Instruction Insn, dag modvalue> {
5465 def : T2Pat<(ARMcmov modvalue, GPRwithZR:$tval, cmovpred:$imm),
5466 (Insn GPRwithZR:$tval, GPRwithZR:$fval, imm0_31:$imm)>;
5467 def : T2Pat<(ARMcmov GPRwithZR:$tval, modvalue, cmovpred:$imm),
5468 (Insn GPRwithZR:$tval, GPRwithZR:$fval,
5469 (i32 (inv_cond_XFORM imm:$imm)))>;
5471 defm : ModifiedV8_1CSEL<t2CSINC, (add rGPR:$fval, 1)>;
5472 defm : ModifiedV8_1CSEL<t2CSINV, (xor rGPR:$fval, -1)>;
5473 defm : ModifiedV8_1CSEL<t2CSNEG, (sub 0, rGPR:$fval)>;
5477 let Predicates = [HasV8_1MMainline] in {
5478 def : InstAlias<"csetm\t$Rd, $fcond",
5479 (t2CSINV rGPR:$Rd, ZR, ZR, pred_noal_inv:$fcond)>;
5481 def : InstAlias<"cset\t$Rd, $fcond",
5482 (t2CSINC rGPR:$Rd, ZR, ZR, pred_noal_inv:$fcond)>;
5484 def : InstAlias<"cinc\t$Rd, $Rn, $fcond",
5485 (t2CSINC rGPR:$Rd, GPRwithZRnosp:$Rn, GPRwithZRnosp:$Rn, pred_noal_inv:$fcond)>;
5487 def : InstAlias<"cinv\t$Rd, $Rn, $fcond",
5488 (t2CSINV rGPR:$Rd, GPRwithZRnosp:$Rn, GPRwithZRnosp:$Rn, pred_noal_inv:$fcond)>;
5490 def : InstAlias<"cneg\t$Rd, $Rn, $fcond",
5491 (t2CSNEG rGPR:$Rd, GPRwithZRnosp:$Rn, GPRwithZRnosp:$Rn, pred_noal_inv:$fcond)>;