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 let ParserMatchClass = mve_shift_imm;
50 let DecoderMethod = "DecodeLongShiftOperand";
53 // Shifted operands. No register controlled shifts for Thumb2.
54 // Note: We do not support rrx shifted operands yet.
55 def t2_so_reg : Operand<i32>, // reg imm
56 ComplexPattern<i32, 2, "SelectShiftImmShifterOperand",
58 let EncoderMethod = "getT2SORegOpValue";
59 let PrintMethod = "printT2SOOperand";
60 let DecoderMethod = "DecodeSORegImmOperand";
61 let ParserMatchClass = ShiftedImmAsmOperand;
62 let MIOperandInfo = (ops rGPR, i32imm);
65 // t2_so_imm_not_XFORM - Return the complement of a t2_so_imm value
66 def t2_so_imm_not_XFORM : SDNodeXForm<imm, [{
67 return CurDAG->getTargetConstant(~((uint32_t)N->getZExtValue()), SDLoc(N),
71 // t2_so_imm_neg_XFORM - Return the negation of a t2_so_imm value
72 def t2_so_imm_neg_XFORM : SDNodeXForm<imm, [{
73 return CurDAG->getTargetConstant(-((int)N->getZExtValue()), SDLoc(N),
77 // so_imm_notSext_XFORM - Return a so_imm value packed into the format
78 // described for so_imm_notSext def below, with sign extension from 16
80 def t2_so_imm_notSext16_XFORM : SDNodeXForm<imm, [{
81 APInt apIntN = N->getAPIntValue();
82 unsigned N16bitSignExt = apIntN.trunc(16).sext(32).getZExtValue();
83 return CurDAG->getTargetConstant(~N16bitSignExt, SDLoc(N), MVT::i32);
86 // t2_so_imm - Match a 32-bit immediate operand, which is an
87 // 8-bit immediate rotated by an arbitrary number of bits, or an 8-bit
88 // immediate splatted into multiple bytes of the word.
89 def t2_so_imm_asmoperand : AsmOperandClass {
91 let RenderMethod = "addImmOperands";
94 def t2_so_imm : Operand<i32>, ImmLeaf<i32, [{
95 return ARM_AM::getT2SOImmVal(Imm) != -1;
97 let ParserMatchClass = t2_so_imm_asmoperand;
98 let EncoderMethod = "getT2SOImmOpValue";
99 let DecoderMethod = "DecodeT2SOImm";
102 // t2_so_imm_not - Match an immediate that is a complement
104 // Note: this pattern doesn't require an encoder method and such, as it's
105 // only used on aliases (Pat<> and InstAlias<>). The actual encoding
106 // is handled by the destination instructions, which use t2_so_imm.
107 def t2_so_imm_not_asmoperand : AsmOperandClass { let Name = "T2SOImmNot"; }
108 def t2_so_imm_not : Operand<i32>, PatLeaf<(imm), [{
109 return ARM_AM::getT2SOImmVal(~((uint32_t)N->getZExtValue())) != -1;
110 }], t2_so_imm_not_XFORM> {
111 let ParserMatchClass = t2_so_imm_not_asmoperand;
114 // t2_so_imm_notSext - match an immediate that is a complement of a t2_so_imm
115 // if the upper 16 bits are zero.
116 def t2_so_imm_notSext : Operand<i32>, PatLeaf<(imm), [{
117 APInt apIntN = N->getAPIntValue();
118 if (!apIntN.isIntN(16)) return false;
119 unsigned N16bitSignExt = apIntN.trunc(16).sext(32).getZExtValue();
120 return ARM_AM::getT2SOImmVal(~N16bitSignExt) != -1;
121 }], t2_so_imm_notSext16_XFORM> {
122 let ParserMatchClass = t2_so_imm_not_asmoperand;
125 // t2_so_imm_neg - Match an immediate that is a negation of a t2_so_imm.
126 def t2_so_imm_neg_asmoperand : AsmOperandClass { let Name = "T2SOImmNeg"; }
127 def t2_so_imm_neg : Operand<i32>, ImmLeaf<i32, [{
128 return Imm && ARM_AM::getT2SOImmVal(-(uint32_t)Imm) != -1;
129 }], t2_so_imm_neg_XFORM> {
130 let ParserMatchClass = t2_so_imm_neg_asmoperand;
133 /// imm0_4095 predicate - True if the 32-bit immediate is in the range [0,4095].
134 def imm0_4095_asmoperand: ImmAsmOperand<0,4095> { let Name = "Imm0_4095"; }
135 def imm0_4095 : Operand<i32>, ImmLeaf<i32, [{
136 return Imm >= 0 && Imm < 4096;
138 let ParserMatchClass = imm0_4095_asmoperand;
141 def imm0_4095_neg_asmoperand: AsmOperandClass { let Name = "Imm0_4095Neg"; }
142 def imm0_4095_neg : Operand<i32>, PatLeaf<(i32 imm), [{
143 return (uint32_t)(-N->getZExtValue()) < 4096;
145 let ParserMatchClass = imm0_4095_neg_asmoperand;
148 def imm1_255_neg : PatLeaf<(i32 imm), [{
149 uint32_t Val = -N->getZExtValue();
150 return (Val > 0 && Val < 255);
153 def imm0_255_not : PatLeaf<(i32 imm), [{
154 return (uint32_t)(~N->getZExtValue()) < 255;
157 def lo5AllOne : PatLeaf<(i32 imm), [{
158 // Returns true if all low 5-bits are 1.
159 return (((uint32_t)N->getZExtValue()) & 0x1FUL) == 0x1FUL;
162 // Define Thumb2 specific addressing modes.
164 // t2_addr_offset_none := reg
165 def MemNoOffsetT2AsmOperand
166 : AsmOperandClass { let Name = "MemNoOffsetT2"; }
167 def t2_addr_offset_none : MemOperand {
168 let PrintMethod = "printAddrMode7Operand";
169 let DecoderMethod = "DecodeGPRnopcRegisterClass";
170 let ParserMatchClass = MemNoOffsetT2AsmOperand;
171 let MIOperandInfo = (ops GPRnopc:$base);
174 // t2_nosp_addr_offset_none := reg
175 def MemNoOffsetT2NoSpAsmOperand
176 : AsmOperandClass { let Name = "MemNoOffsetT2NoSp"; }
177 def t2_nosp_addr_offset_none : MemOperand {
178 let PrintMethod = "printAddrMode7Operand";
179 let DecoderMethod = "DecoderGPRRegisterClass";
180 let ParserMatchClass = MemNoOffsetT2NoSpAsmOperand;
181 let MIOperandInfo = (ops rGPR:$base);
184 // t2addrmode_imm12 := reg + imm12
185 def t2addrmode_imm12_asmoperand : AsmOperandClass {let Name="MemUImm12Offset";}
186 def t2addrmode_imm12 : MemOperand,
187 ComplexPattern<i32, 2, "SelectT2AddrModeImm12", []> {
188 let PrintMethod = "printAddrModeImm12Operand<false>";
189 let EncoderMethod = "getAddrModeImm12OpValue";
190 let DecoderMethod = "DecodeT2AddrModeImm12";
191 let ParserMatchClass = t2addrmode_imm12_asmoperand;
192 let MIOperandInfo = (ops GPR:$base, i32imm:$offsimm);
195 // t2ldrlabel := imm12
196 def t2ldrlabel : Operand<i32> {
197 let EncoderMethod = "getAddrModeImm12OpValue";
198 let PrintMethod = "printThumbLdrLabelOperand";
201 def t2ldr_pcrel_imm12_asmoperand : AsmOperandClass {let Name = "MemPCRelImm12";}
202 def t2ldr_pcrel_imm12 : Operand<i32> {
203 let ParserMatchClass = t2ldr_pcrel_imm12_asmoperand;
204 // used for assembler pseudo instruction and maps to t2ldrlabel, so
205 // doesn't need encoder or print methods of its own.
208 // ADR instruction labels.
209 def t2adrlabel : Operand<i32> {
210 let EncoderMethod = "getT2AdrLabelOpValue";
211 let PrintMethod = "printAdrLabelOperand<0>";
214 // t2addrmode_posimm8 := reg + imm8
215 def MemPosImm8OffsetAsmOperand : AsmOperandClass {let Name="MemPosImm8Offset";}
216 def t2addrmode_posimm8 : MemOperand {
217 let PrintMethod = "printT2AddrModeImm8Operand<false>";
218 let EncoderMethod = "getT2AddrModeImm8OpValue";
219 let DecoderMethod = "DecodeT2AddrModeImm8";
220 let ParserMatchClass = MemPosImm8OffsetAsmOperand;
221 let MIOperandInfo = (ops GPR:$base, i32imm:$offsimm);
224 // t2addrmode_negimm8 := reg - imm8
225 def MemNegImm8OffsetAsmOperand : AsmOperandClass {let Name="MemNegImm8Offset";}
226 def t2addrmode_negimm8 : MemOperand,
227 ComplexPattern<i32, 2, "SelectT2AddrModeImm8", []> {
228 let PrintMethod = "printT2AddrModeImm8Operand<false>";
229 let EncoderMethod = "getT2AddrModeImm8OpValue";
230 let DecoderMethod = "DecodeT2AddrModeImm8";
231 let ParserMatchClass = MemNegImm8OffsetAsmOperand;
232 let MIOperandInfo = (ops GPR:$base, i32imm:$offsimm);
235 // t2addrmode_imm8 := reg +/- imm8
236 def MemImm8OffsetAsmOperand : AsmOperandClass { let Name = "MemImm8Offset"; }
237 class T2AddrMode_Imm8 : MemOperand,
238 ComplexPattern<i32, 2, "SelectT2AddrModeImm8", []> {
239 let EncoderMethod = "getT2AddrModeImm8OpValue";
240 let DecoderMethod = "DecodeT2AddrModeImm8";
241 let ParserMatchClass = MemImm8OffsetAsmOperand;
242 let MIOperandInfo = (ops GPR:$base, i32imm:$offsimm);
245 def t2addrmode_imm8 : T2AddrMode_Imm8 {
246 let PrintMethod = "printT2AddrModeImm8Operand<false>";
249 def t2addrmode_imm8_pre : T2AddrMode_Imm8 {
250 let PrintMethod = "printT2AddrModeImm8Operand<true>";
253 def t2am_imm8_offset : MemOperand,
254 ComplexPattern<i32, 1, "SelectT2AddrModeImm8Offset",
255 [], [SDNPWantRoot]> {
256 let PrintMethod = "printT2AddrModeImm8OffsetOperand";
257 let EncoderMethod = "getT2AddrModeImm8OffsetOpValue";
258 let DecoderMethod = "DecodeT2Imm8";
261 // t2addrmode_imm8s4 := reg +/- (imm8 << 2)
262 def MemImm8s4OffsetAsmOperand : AsmOperandClass {let Name = "MemImm8s4Offset";}
263 class T2AddrMode_Imm8s4 : MemOperand {
264 let EncoderMethod = "getT2AddrModeImm8s4OpValue";
265 let DecoderMethod = "DecodeT2AddrModeImm8s4";
266 let ParserMatchClass = MemImm8s4OffsetAsmOperand;
267 let MIOperandInfo = (ops GPR:$base, i32imm:$offsimm);
270 def t2addrmode_imm8s4 : T2AddrMode_Imm8s4 {
271 let PrintMethod = "printT2AddrModeImm8s4Operand<false>";
274 def t2addrmode_imm8s4_pre : T2AddrMode_Imm8s4 {
275 let PrintMethod = "printT2AddrModeImm8s4Operand<true>";
278 def t2am_imm8s4_offset_asmoperand : AsmOperandClass { let Name = "Imm8s4"; }
279 def t2am_imm8s4_offset : MemOperand {
280 let PrintMethod = "printT2AddrModeImm8s4OffsetOperand";
281 let EncoderMethod = "getT2ScaledImmOpValue<8,2>";
282 let DecoderMethod = "DecodeT2Imm8S4";
285 // t2addrmode_imm7s4 := reg +/- (imm7 << 2)
286 def MemImm7s4OffsetAsmOperand : AsmOperandClass {let Name = "MemImm7s4Offset";}
287 class T2AddrMode_Imm7s4 : MemOperand {
288 let EncoderMethod = "getT2AddrModeImm7s4OpValue";
289 let DecoderMethod = "DecodeT2AddrModeImm7<2,0>";
290 let ParserMatchClass = MemImm7s4OffsetAsmOperand;
291 let MIOperandInfo = (ops GPRnopc:$base, i32imm:$offsimm);
294 def t2addrmode_imm7s4 : T2AddrMode_Imm7s4 {
295 // They are printed the same way as the imm8 version
296 let PrintMethod = "printT2AddrModeImm8s4Operand<false>";
299 def t2addrmode_imm7s4_pre : T2AddrMode_Imm7s4 {
300 // They are printed the same way as the imm8 version
301 let PrintMethod = "printT2AddrModeImm8s4Operand<true>";
304 def t2am_imm7s4_offset_asmoperand : AsmOperandClass { let Name = "Imm7s4"; }
305 def t2am_imm7s4_offset : MemOperand {
306 // They are printed the same way as the imm8 version
307 let PrintMethod = "printT2AddrModeImm8s4OffsetOperand";
308 let ParserMatchClass = t2am_imm7s4_offset_asmoperand;
309 let EncoderMethod = "getT2ScaledImmOpValue<7,2>";
310 let DecoderMethod = "DecodeT2Imm7S4";
313 // t2addrmode_imm0_1020s4 := reg + (imm8 << 2)
314 def MemImm0_1020s4OffsetAsmOperand : AsmOperandClass {
315 let Name = "MemImm0_1020s4Offset";
317 def t2addrmode_imm0_1020s4 : MemOperand,
318 ComplexPattern<i32, 2, "SelectT2AddrModeExclusive"> {
319 let PrintMethod = "printT2AddrModeImm0_1020s4Operand";
320 let EncoderMethod = "getT2AddrModeImm0_1020s4OpValue";
321 let DecoderMethod = "DecodeT2AddrModeImm0_1020s4";
322 let ParserMatchClass = MemImm0_1020s4OffsetAsmOperand;
323 let MIOperandInfo = (ops GPRnopc:$base, i32imm:$offsimm);
326 // t2addrmode_so_reg := reg + (reg << imm2)
327 def t2addrmode_so_reg_asmoperand : AsmOperandClass {let Name="T2MemRegOffset";}
328 def t2addrmode_so_reg : MemOperand,
329 ComplexPattern<i32, 3, "SelectT2AddrModeSoReg", []> {
330 let PrintMethod = "printT2AddrModeSoRegOperand";
331 let EncoderMethod = "getT2AddrModeSORegOpValue";
332 let DecoderMethod = "DecodeT2AddrModeSOReg";
333 let ParserMatchClass = t2addrmode_so_reg_asmoperand;
334 let MIOperandInfo = (ops GPRnopc:$base, rGPR:$offsreg, i32imm:$offsimm);
337 // Addresses for the TBB/TBH instructions.
338 def addrmode_tbb_asmoperand : AsmOperandClass { let Name = "MemTBB"; }
339 def addrmode_tbb : MemOperand {
340 let PrintMethod = "printAddrModeTBB";
341 let ParserMatchClass = addrmode_tbb_asmoperand;
342 let MIOperandInfo = (ops GPR:$Rn, rGPR:$Rm);
344 def addrmode_tbh_asmoperand : AsmOperandClass { let Name = "MemTBH"; }
345 def addrmode_tbh : MemOperand {
346 let PrintMethod = "printAddrModeTBH";
347 let ParserMatchClass = addrmode_tbh_asmoperand;
348 let MIOperandInfo = (ops GPR:$Rn, rGPR:$Rm);
351 // Define ARMv8.1-M specific addressing modes.
353 // Label operands for BF/BFL/WLS/DLS/LE
354 class BFLabelOp<string signed, string isNeg, string size, string fixup>
356 let EncoderMethod = !strconcat("getBFTargetOpValue<", isNeg, ", ",
358 let OperandType = "OPERAND_PCREL";
359 let DecoderMethod = !strconcat("DecodeBFLabelOperand<", signed, ", ",
360 isNeg, ", ", size, ">");
362 def bflabel_u4 : BFLabelOp<"false", "false", "4", "ARM::fixup_bf_branch">;
363 def bflabel_s12 : BFLabelOp<"true", "false", "12", "ARM::fixup_bfc_target">;
364 def bflabel_s16 : BFLabelOp<"true", "false", "16", "ARM::fixup_bf_target">;
365 def bflabel_s18 : BFLabelOp<"true", "false", "18", "ARM::fixup_bfl_target">;
366 def wlslabel_u11 : BFLabelOp<"false", "false", "11", "ARM::fixup_wls">;
367 def lelabel_u11 : BFLabelOp<"false", "true", "11", "ARM::fixup_le">;
369 def bfafter_target : Operand<OtherVT> {
370 let EncoderMethod = "getBFAfterTargetOpValue";
371 let OperandType = "OPERAND_PCREL";
372 let DecoderMethod = "DecodeBFAfterTargetOperand";
375 // pred operand excluding AL
376 def pred_noal_asmoperand : AsmOperandClass {
377 let Name = "CondCodeNoAL";
378 let RenderMethod = "addITCondCodeOperands";
379 let PredicateMethod = "isITCondCodeNoAL";
380 let ParserMethod = "parseITCondCode";
382 def pred_noal : Operand<i32> {
383 let PrintMethod = "printMandatoryPredicateOperand";
384 let ParserMatchClass = pred_noal_asmoperand;
385 let DecoderMethod = "DecodePredNoALOperand";
389 // CSEL aliases inverted predicate
390 def pred_noal_inv_asmoperand : AsmOperandClass {
391 let Name = "CondCodeNoALInv";
392 let RenderMethod = "addITCondCodeInvOperands";
393 let PredicateMethod = "isITCondCodeNoAL";
394 let ParserMethod = "parseITCondCode";
396 def pred_noal_inv : Operand<i32> {
397 let PrintMethod = "printMandatoryInvertedPredicateOperand";
398 let ParserMatchClass = pred_noal_inv_asmoperand;
400 //===----------------------------------------------------------------------===//
401 // Multiclass helpers...
405 class T2OneRegImm<dag oops, dag iops, InstrItinClass itin,
406 string opc, string asm, list<dag> pattern>
407 : T2I<oops, iops, itin, opc, asm, pattern> {
412 let Inst{26} = imm{11};
413 let Inst{14-12} = imm{10-8};
414 let Inst{7-0} = imm{7-0};
418 class T2sOneRegImm<dag oops, dag iops, InstrItinClass itin,
419 string opc, string asm, list<dag> pattern>
420 : T2sI<oops, iops, itin, opc, asm, pattern> {
426 let Inst{26} = imm{11};
427 let Inst{14-12} = imm{10-8};
428 let Inst{7-0} = imm{7-0};
431 class T2OneRegCmpImm<dag oops, dag iops, InstrItinClass itin,
432 string opc, string asm, list<dag> pattern>
433 : T2I<oops, iops, itin, opc, asm, pattern> {
437 let Inst{19-16} = Rn;
438 let Inst{26} = imm{11};
439 let Inst{14-12} = imm{10-8};
440 let Inst{7-0} = imm{7-0};
444 class T2OneRegShiftedReg<dag oops, dag iops, InstrItinClass itin,
445 string opc, string asm, list<dag> pattern>
446 : T2I<oops, iops, itin, opc, asm, pattern> {
451 let Inst{3-0} = ShiftedRm{3-0};
452 let Inst{5-4} = ShiftedRm{6-5};
453 let Inst{14-12} = ShiftedRm{11-9};
454 let Inst{7-6} = ShiftedRm{8-7};
457 class T2sOneRegShiftedReg<dag oops, dag iops, InstrItinClass itin,
458 string opc, string asm, list<dag> pattern>
459 : T2sI<oops, iops, itin, opc, asm, pattern> {
464 let Inst{3-0} = ShiftedRm{3-0};
465 let Inst{5-4} = ShiftedRm{6-5};
466 let Inst{14-12} = ShiftedRm{11-9};
467 let Inst{7-6} = ShiftedRm{8-7};
470 class T2OneRegCmpShiftedReg<dag oops, dag iops, InstrItinClass itin,
471 string opc, string asm, list<dag> pattern>
472 : T2I<oops, iops, itin, opc, asm, pattern> {
476 let Inst{19-16} = Rn;
477 let Inst{3-0} = ShiftedRm{3-0};
478 let Inst{5-4} = ShiftedRm{6-5};
479 let Inst{14-12} = ShiftedRm{11-9};
480 let Inst{7-6} = ShiftedRm{8-7};
483 class T2TwoReg<dag oops, dag iops, InstrItinClass itin,
484 string opc, string asm, list<dag> pattern>
485 : T2I<oops, iops, itin, opc, asm, pattern> {
493 class T2sTwoReg<dag oops, dag iops, InstrItinClass itin,
494 string opc, string asm, list<dag> pattern>
495 : T2sI<oops, iops, itin, opc, asm, pattern> {
503 class T2TwoRegCmp<dag oops, dag iops, InstrItinClass itin,
504 string opc, string asm, list<dag> pattern>
505 : T2I<oops, iops, itin, opc, asm, pattern> {
509 let Inst{19-16} = Rn;
514 class T2TwoRegImm<dag oops, dag iops, InstrItinClass itin,
515 string opc, string asm, list<dag> pattern>
516 : T2I<oops, iops, itin, opc, asm, pattern> {
522 let Inst{19-16} = Rn;
523 let Inst{26} = imm{11};
524 let Inst{14-12} = imm{10-8};
525 let Inst{7-0} = imm{7-0};
528 class T2sTwoRegImm<dag oops, dag iops, InstrItinClass itin,
529 string opc, string asm, list<dag> pattern>
530 : T2sI<oops, iops, itin, opc, asm, pattern> {
536 let Inst{19-16} = Rn;
537 let Inst{26} = imm{11};
538 let Inst{14-12} = imm{10-8};
539 let Inst{7-0} = imm{7-0};
542 class T2TwoRegShiftImm<dag oops, dag iops, InstrItinClass itin,
543 string opc, string asm, list<dag> pattern>
544 : T2I<oops, iops, itin, opc, asm, pattern> {
551 let Inst{14-12} = imm{4-2};
552 let Inst{7-6} = imm{1-0};
555 class T2sTwoRegShiftImm<dag oops, dag iops, InstrItinClass itin,
556 string opc, string asm, list<dag> pattern>
557 : T2sI<oops, iops, itin, opc, asm, pattern> {
564 let Inst{14-12} = imm{4-2};
565 let Inst{7-6} = imm{1-0};
568 class T2ThreeReg<dag oops, dag iops, InstrItinClass itin,
569 string opc, string asm, list<dag> pattern>
570 : T2I<oops, iops, itin, opc, asm, pattern> {
576 let Inst{19-16} = Rn;
580 class T2ThreeRegNoP<dag oops, dag iops, InstrItinClass itin,
581 string asm, list<dag> pattern>
582 : T2XI<oops, iops, itin, asm, pattern> {
588 let Inst{19-16} = Rn;
592 class T2sThreeReg<dag oops, dag iops, InstrItinClass itin,
593 string opc, string asm, list<dag> pattern>
594 : T2sI<oops, iops, itin, opc, asm, pattern> {
600 let Inst{19-16} = Rn;
604 class T2TwoRegShiftedReg<dag oops, dag iops, InstrItinClass itin,
605 string opc, string asm, list<dag> pattern>
606 : T2I<oops, iops, itin, opc, asm, pattern> {
612 let Inst{19-16} = Rn;
613 let Inst{3-0} = ShiftedRm{3-0};
614 let Inst{5-4} = ShiftedRm{6-5};
615 let Inst{14-12} = ShiftedRm{11-9};
616 let Inst{7-6} = ShiftedRm{8-7};
619 class T2sTwoRegShiftedReg<dag oops, dag iops, InstrItinClass itin,
620 string opc, string asm, list<dag> pattern>
621 : T2sI<oops, iops, itin, opc, asm, pattern> {
627 let Inst{19-16} = Rn;
628 let Inst{3-0} = ShiftedRm{3-0};
629 let Inst{5-4} = ShiftedRm{6-5};
630 let Inst{14-12} = ShiftedRm{11-9};
631 let Inst{7-6} = ShiftedRm{8-7};
634 class T2FourReg<dag oops, dag iops, InstrItinClass itin,
635 string opc, string asm, list<dag> pattern>
636 : T2I<oops, iops, itin, opc, asm, pattern> {
642 let Inst{19-16} = Rn;
643 let Inst{15-12} = Ra;
648 class T2MulLong<bits<3> opc22_20, bits<4> opc7_4,
649 string opc, list<dag> pattern>
650 : T2I<(outs rGPR:$RdLo, rGPR:$RdHi), (ins rGPR:$Rn, rGPR:$Rm), IIC_iMUL64,
651 opc, "\t$RdLo, $RdHi, $Rn, $Rm", pattern>,
652 Sched<[WriteMUL64Lo, WriteMUL64Hi, ReadMUL, ReadMUL]> {
658 let Inst{31-23} = 0b111110111;
659 let Inst{22-20} = opc22_20;
660 let Inst{19-16} = Rn;
661 let Inst{15-12} = RdLo;
662 let Inst{11-8} = RdHi;
663 let Inst{7-4} = opc7_4;
666 class T2MlaLong<bits<3> opc22_20, bits<4> opc7_4, string opc>
667 : T2I<(outs rGPR:$RdLo, rGPR:$RdHi),
668 (ins rGPR:$Rn, rGPR:$Rm, rGPR:$RLo, rGPR:$RHi), IIC_iMAC64,
669 opc, "\t$RdLo, $RdHi, $Rn, $Rm", []>,
670 RegConstraint<"$RLo = $RdLo, $RHi = $RdHi">,
671 Sched<[WriteMAC64Lo, WriteMAC64Hi, ReadMUL, ReadMUL, ReadMAC, ReadMAC]> {
677 let Inst{31-23} = 0b111110111;
678 let Inst{22-20} = opc22_20;
679 let Inst{19-16} = Rn;
680 let Inst{15-12} = RdLo;
681 let Inst{11-8} = RdHi;
682 let Inst{7-4} = opc7_4;
687 /// T2I_bin_irs - Defines a set of (op reg, {so_imm|r|so_reg}) patterns for a
688 /// binary operation that produces a value. These are predicable and can be
689 /// changed to modify CPSR.
690 multiclass T2I_bin_irs<bits<4> opcod, string opc,
691 InstrItinClass iii, InstrItinClass iir, InstrItinClass iis,
692 SDPatternOperator opnode, bit Commutable = 0,
695 def ri : T2sTwoRegImm<
696 (outs rGPR:$Rd), (ins rGPR:$Rn, t2_so_imm:$imm), iii,
697 opc, "\t$Rd, $Rn, $imm",
698 [(set rGPR:$Rd, (opnode rGPR:$Rn, t2_so_imm:$imm))]>,
699 Sched<[WriteALU, ReadALU]> {
700 let Inst{31-27} = 0b11110;
702 let Inst{24-21} = opcod;
706 def rr : T2sThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), iir,
707 opc, !strconcat(wide, "\t$Rd, $Rn, $Rm"),
708 [(set rGPR:$Rd, (opnode rGPR:$Rn, rGPR:$Rm))]>,
709 Sched<[WriteALU, ReadALU, ReadALU]> {
710 let isCommutable = Commutable;
711 let Inst{31-27} = 0b11101;
712 let Inst{26-25} = 0b01;
713 let Inst{24-21} = opcod;
715 // In most of these instructions, and most versions of the Arm
716 // architecture, bit 15 of this encoding is listed as (0) rather
717 // than 0, i.e. setting it to 1 is UNPREDICTABLE or a soft-fail
718 // rather than a hard failure. In v8.1-M, this requirement is
719 // upgraded to a hard one for ORR, so that the encodings with 1
720 // in this bit can be reused for other instructions (such as
721 // CSEL). Setting Unpredictable{15} = 1 here would reintroduce
722 // that encoding clash in the auto- generated MC decoder, so I
724 let Unpredictable{15} = !if(!eq(opcod, 0b0010), 0b0, 0b1);
725 let Inst{14-12} = 0b000; // imm3
726 let Inst{7-6} = 0b00; // imm2
727 let Inst{5-4} = 0b00; // type
730 def rs : T2sTwoRegShiftedReg<
731 (outs rGPR:$Rd), (ins rGPR:$Rn, t2_so_reg:$ShiftedRm), iis,
732 opc, !strconcat(wide, "\t$Rd, $Rn, $ShiftedRm"),
733 [(set rGPR:$Rd, (opnode rGPR:$Rn, t2_so_reg:$ShiftedRm))]>,
734 Sched<[WriteALUsi, ReadALU]> {
735 let Inst{31-27} = 0b11101;
736 let Inst{26-25} = 0b01;
737 let Inst{24-21} = opcod;
739 let Unpredictable{15} = !if(!eq(opcod, 0b0010), 0b0, 0b1); // see above
741 // Assembly aliases for optional destination operand when it's the same
742 // as the source operand.
743 def : t2InstAlias<!strconcat(opc, "${s}${p} $Rdn, $imm"),
744 (!cast<Instruction>(NAME#"ri") rGPR:$Rdn, rGPR:$Rdn,
745 t2_so_imm:$imm, pred:$p,
747 def : t2InstAlias<!strconcat(opc, "${s}${p}", wide, " $Rdn, $Rm"),
748 (!cast<Instruction>(NAME#"rr") rGPR:$Rdn, rGPR:$Rdn,
751 def : t2InstAlias<!strconcat(opc, "${s}${p}", wide, " $Rdn, $shift"),
752 (!cast<Instruction>(NAME#"rs") rGPR:$Rdn, rGPR:$Rdn,
753 t2_so_reg:$shift, pred:$p,
757 /// T2I_bin_w_irs - Same as T2I_bin_irs except these operations need
758 // the ".w" suffix to indicate that they are wide.
759 multiclass T2I_bin_w_irs<bits<4> opcod, string opc,
760 InstrItinClass iii, InstrItinClass iir, InstrItinClass iis,
761 SDPatternOperator opnode, bit Commutable = 0> :
762 T2I_bin_irs<opcod, opc, iii, iir, iis, opnode, Commutable, ".w"> {
763 // Assembler aliases w/ the ".w" suffix.
764 def : t2InstAlias<!strconcat(opc, "${s}${p}.w", " $Rd, $Rn, $imm"),
765 (!cast<Instruction>(NAME#"ri") rGPR:$Rd, rGPR:$Rn, t2_so_imm:$imm, pred:$p,
767 // Assembler aliases w/o the ".w" suffix.
768 def : t2InstAlias<!strconcat(opc, "${s}${p}", " $Rd, $Rn, $Rm"),
769 (!cast<Instruction>(NAME#"rr") rGPR:$Rd, rGPR:$Rn, rGPR:$Rm, pred:$p,
771 def : t2InstAlias<!strconcat(opc, "${s}${p}", " $Rd, $Rn, $shift"),
772 (!cast<Instruction>(NAME#"rs") rGPR:$Rd, rGPR:$Rn, t2_so_reg:$shift,
773 pred:$p, cc_out:$s)>;
775 // and with the optional destination operand, too.
776 def : t2InstAlias<!strconcat(opc, "${s}${p}.w", " $Rdn, $imm"),
777 (!cast<Instruction>(NAME#"ri") rGPR:$Rdn, rGPR:$Rdn, t2_so_imm:$imm,
778 pred:$p, cc_out:$s)>;
779 def : t2InstAlias<!strconcat(opc, "${s}${p}", " $Rdn, $Rm"),
780 (!cast<Instruction>(NAME#"rr") rGPR:$Rdn, rGPR:$Rdn, rGPR:$Rm, pred:$p,
782 def : t2InstAlias<!strconcat(opc, "${s}${p}", " $Rdn, $shift"),
783 (!cast<Instruction>(NAME#"rs") rGPR:$Rdn, rGPR:$Rdn, t2_so_reg:$shift,
784 pred:$p, cc_out:$s)>;
787 /// T2I_rbin_is - Same as T2I_bin_irs except the order of operands are
788 /// reversed. The 'rr' form is only defined for the disassembler; for codegen
789 /// it is equivalent to the T2I_bin_irs counterpart.
790 multiclass T2I_rbin_irs<bits<4> opcod, string opc, SDNode opnode> {
792 def ri : T2sTwoRegImm<
793 (outs rGPR:$Rd), (ins rGPR:$Rn, t2_so_imm:$imm), IIC_iALUi,
794 opc, ".w\t$Rd, $Rn, $imm",
795 [(set rGPR:$Rd, (opnode t2_so_imm:$imm, rGPR:$Rn))]>,
796 Sched<[WriteALU, ReadALU]> {
797 let Inst{31-27} = 0b11110;
799 let Inst{24-21} = opcod;
803 def rr : T2sThreeReg<
804 (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iALUr,
805 opc, "\t$Rd, $Rn, $Rm",
806 [/* For disassembly only; pattern left blank */]>,
807 Sched<[WriteALU, ReadALU, ReadALU]> {
808 let Inst{31-27} = 0b11101;
809 let Inst{26-25} = 0b01;
810 let Inst{24-21} = opcod;
811 let Inst{14-12} = 0b000; // imm3
812 let Inst{7-6} = 0b00; // imm2
813 let Inst{5-4} = 0b00; // type
816 def rs : T2sTwoRegShiftedReg<
817 (outs rGPR:$Rd), (ins rGPR:$Rn, t2_so_reg:$ShiftedRm),
818 IIC_iALUsir, opc, "\t$Rd, $Rn, $ShiftedRm",
819 [(set rGPR:$Rd, (opnode t2_so_reg:$ShiftedRm, rGPR:$Rn))]>,
820 Sched<[WriteALUsi, ReadALU]> {
821 let Inst{31-27} = 0b11101;
822 let Inst{26-25} = 0b01;
823 let Inst{24-21} = opcod;
827 /// T2I_bin_s_irs - Similar to T2I_bin_irs except it sets the 's' bit so the
828 /// instruction modifies the CPSR register.
830 /// These opcodes will be converted to the real non-S opcodes by
831 /// AdjustInstrPostInstrSelection after giving then an optional CPSR operand.
832 let hasPostISelHook = 1, Defs = [CPSR] in {
833 multiclass T2I_bin_s_irs<InstrItinClass iii, InstrItinClass iir,
834 InstrItinClass iis, SDNode opnode,
835 bit Commutable = 0> {
837 def ri : t2PseudoInst<(outs rGPR:$Rd),
838 (ins GPRnopc:$Rn, t2_so_imm:$imm, pred:$p),
840 [(set rGPR:$Rd, CPSR, (opnode GPRnopc:$Rn,
842 Sched<[WriteALU, ReadALU]>;
844 def rr : t2PseudoInst<(outs rGPR:$Rd), (ins GPRnopc:$Rn, rGPR:$Rm, pred:$p),
846 [(set rGPR:$Rd, CPSR, (opnode GPRnopc:$Rn,
848 Sched<[WriteALU, ReadALU, ReadALU]> {
849 let isCommutable = Commutable;
852 def rs : t2PseudoInst<(outs rGPR:$Rd),
853 (ins GPRnopc:$Rn, t2_so_reg:$ShiftedRm, pred:$p),
855 [(set rGPR:$Rd, CPSR, (opnode GPRnopc:$Rn,
856 t2_so_reg:$ShiftedRm))]>,
857 Sched<[WriteALUsi, ReadALUsr]>;
861 /// T2I_rbin_s_is - Same as T2I_bin_s_irs, except selection DAG
862 /// operands are reversed.
863 let hasPostISelHook = 1, Defs = [CPSR] in {
864 multiclass T2I_rbin_s_is<SDNode opnode> {
866 def ri : t2PseudoInst<(outs rGPR:$Rd),
867 (ins rGPR:$Rn, t2_so_imm:$imm, pred:$p),
869 [(set rGPR:$Rd, CPSR, (opnode t2_so_imm:$imm,
871 Sched<[WriteALU, ReadALU]>;
873 def rs : t2PseudoInst<(outs rGPR:$Rd),
874 (ins rGPR:$Rn, t2_so_reg:$ShiftedRm, pred:$p),
876 [(set rGPR:$Rd, CPSR, (opnode t2_so_reg:$ShiftedRm,
878 Sched<[WriteALUsi, ReadALU]>;
882 /// T2I_bin_ii12rs - Defines a set of (op reg, {so_imm|imm0_4095|r|so_reg})
883 /// patterns for a binary operation that produces a value.
884 multiclass T2I_bin_ii12rs<bits<3> op23_21, string opc, SDNode opnode,
885 bit Commutable = 0> {
887 // The register-immediate version is re-materializable. This is useful
888 // in particular for taking the address of a local.
889 let isReMaterializable = 1 in {
890 def ri : T2sTwoRegImm<
891 (outs GPRnopc:$Rd), (ins GPRnopc:$Rn, t2_so_imm:$imm), IIC_iALUi,
892 opc, ".w\t$Rd, $Rn, $imm",
893 [(set GPRnopc:$Rd, (opnode GPRnopc:$Rn, t2_so_imm:$imm))]>,
894 Sched<[WriteALU, ReadALU]> {
895 let Inst{31-27} = 0b11110;
898 let Inst{23-21} = op23_21;
904 (outs GPRnopc:$Rd), (ins GPR:$Rn, imm0_4095:$imm), IIC_iALUi,
905 !strconcat(opc, "w"), "\t$Rd, $Rn, $imm",
906 [(set GPRnopc:$Rd, (opnode GPR:$Rn, imm0_4095:$imm))]>,
907 Sched<[WriteALU, ReadALU]> {
911 let Inst{31-27} = 0b11110;
912 let Inst{26} = imm{11};
913 let Inst{25-24} = 0b10;
914 let Inst{23-21} = op23_21;
915 let Inst{20} = 0; // The S bit.
916 let Inst{19-16} = Rn;
918 let Inst{14-12} = imm{10-8};
920 let Inst{7-0} = imm{7-0};
923 def rr : T2sThreeReg<(outs GPRnopc:$Rd), (ins GPRnopc:$Rn, rGPR:$Rm),
924 IIC_iALUr, opc, ".w\t$Rd, $Rn, $Rm",
925 [(set GPRnopc:$Rd, (opnode GPRnopc:$Rn, rGPR:$Rm))]>,
926 Sched<[WriteALU, ReadALU, ReadALU]> {
927 let isCommutable = Commutable;
928 let Inst{31-27} = 0b11101;
929 let Inst{26-25} = 0b01;
931 let Inst{23-21} = op23_21;
932 let Inst{14-12} = 0b000; // imm3
933 let Inst{7-6} = 0b00; // imm2
934 let Inst{5-4} = 0b00; // type
937 def rs : T2sTwoRegShiftedReg<
938 (outs GPRnopc:$Rd), (ins GPRnopc:$Rn, t2_so_reg:$ShiftedRm),
939 IIC_iALUsi, opc, ".w\t$Rd, $Rn, $ShiftedRm",
940 [(set GPRnopc:$Rd, (opnode GPRnopc:$Rn, t2_so_reg:$ShiftedRm))]>,
941 Sched<[WriteALUsi, ReadALU]> {
942 let Inst{31-27} = 0b11101;
943 let Inst{26-25} = 0b01;
945 let Inst{23-21} = op23_21;
949 /// T2I_adde_sube_irs - Defines a set of (op reg, {so_imm|r|so_reg}) patterns
950 /// for a binary operation that produces a value and use the carry
951 /// bit. It's not predicable.
952 let Defs = [CPSR], Uses = [CPSR] in {
953 multiclass T2I_adde_sube_irs<bits<4> opcod, string opc, SDNode opnode,
954 bit Commutable = 0> {
956 def ri : T2sTwoRegImm<(outs rGPR:$Rd), (ins rGPR:$Rn, t2_so_imm:$imm),
957 IIC_iALUi, opc, "\t$Rd, $Rn, $imm",
958 [(set rGPR:$Rd, CPSR, (opnode rGPR:$Rn, t2_so_imm:$imm, CPSR))]>,
959 Requires<[IsThumb2]>, Sched<[WriteALU, ReadALU]> {
960 let Inst{31-27} = 0b11110;
962 let Inst{24-21} = opcod;
966 def rr : T2sThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iALUr,
967 opc, ".w\t$Rd, $Rn, $Rm",
968 [(set rGPR:$Rd, CPSR, (opnode rGPR:$Rn, rGPR:$Rm, CPSR))]>,
969 Requires<[IsThumb2]>, Sched<[WriteALU, ReadALU, ReadALU]> {
970 let isCommutable = Commutable;
971 let Inst{31-27} = 0b11101;
972 let Inst{26-25} = 0b01;
973 let Inst{24-21} = opcod;
974 let Inst{14-12} = 0b000; // imm3
975 let Inst{7-6} = 0b00; // imm2
976 let Inst{5-4} = 0b00; // type
979 def rs : T2sTwoRegShiftedReg<
980 (outs rGPR:$Rd), (ins rGPR:$Rn, t2_so_reg:$ShiftedRm),
981 IIC_iALUsi, opc, ".w\t$Rd, $Rn, $ShiftedRm",
982 [(set rGPR:$Rd, CPSR, (opnode rGPR:$Rn, t2_so_reg:$ShiftedRm, CPSR))]>,
983 Requires<[IsThumb2]>, Sched<[WriteALUsi, ReadALU]> {
984 let Inst{31-27} = 0b11101;
985 let Inst{26-25} = 0b01;
986 let Inst{24-21} = opcod;
991 /// T2I_sh_ir - Defines a set of (op reg, {so_imm|r}) patterns for a shift /
992 // rotate operation that produces a value.
993 multiclass T2I_sh_ir<bits<2> opcod, string opc, Operand ty, SDNode opnode> {
995 def ri : T2sTwoRegShiftImm<
996 (outs rGPR:$Rd), (ins rGPR:$Rm, ty:$imm), IIC_iMOVsi,
997 opc, ".w\t$Rd, $Rm, $imm",
998 [(set rGPR:$Rd, (opnode rGPR:$Rm, (i32 ty:$imm)))]>,
1000 let Inst{31-27} = 0b11101;
1001 let Inst{26-21} = 0b010010;
1002 let Inst{19-16} = 0b1111; // Rn
1004 let Inst{5-4} = opcod;
1007 def rr : T2sThreeReg<
1008 (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iMOVsr,
1009 opc, ".w\t$Rd, $Rn, $Rm",
1010 [(set rGPR:$Rd, (opnode rGPR:$Rn, rGPR:$Rm))]>,
1012 let Inst{31-27} = 0b11111;
1013 let Inst{26-23} = 0b0100;
1014 let Inst{22-21} = opcod;
1015 let Inst{15-12} = 0b1111;
1016 let Inst{7-4} = 0b0000;
1019 // Optional destination register
1020 def : t2InstAlias<!strconcat(opc, "${s}${p}", ".w $Rdn, $imm"),
1021 (!cast<Instruction>(NAME#"ri") rGPR:$Rdn, rGPR:$Rdn, ty:$imm, pred:$p,
1023 def : t2InstAlias<!strconcat(opc, "${s}${p}", ".w $Rdn, $Rm"),
1024 (!cast<Instruction>(NAME#"rr") rGPR:$Rdn, rGPR:$Rdn, rGPR:$Rm, pred:$p,
1027 // Assembler aliases w/o the ".w" suffix.
1028 def : t2InstAlias<!strconcat(opc, "${s}${p}", " $Rd, $Rn, $imm"),
1029 (!cast<Instruction>(NAME#"ri") rGPR:$Rd, rGPR:$Rn, ty:$imm, pred:$p,
1031 def : t2InstAlias<!strconcat(opc, "${s}${p}", " $Rd, $Rn, $Rm"),
1032 (!cast<Instruction>(NAME#"rr") rGPR:$Rd, rGPR:$Rn, rGPR:$Rm, pred:$p,
1035 // and with the optional destination operand, too.
1036 def : t2InstAlias<!strconcat(opc, "${s}${p}", " $Rdn, $imm"),
1037 (!cast<Instruction>(NAME#"ri") rGPR:$Rdn, rGPR:$Rdn, ty:$imm, pred:$p,
1039 def : t2InstAlias<!strconcat(opc, "${s}${p}", " $Rdn, $Rm"),
1040 (!cast<Instruction>(NAME#"rr") rGPR:$Rdn, rGPR:$Rdn, rGPR:$Rm, pred:$p,
1044 /// T2I_cmp_irs - Defines a set of (op r, {so_imm|r|so_reg}) cmp / test
1045 /// patterns. Similar to T2I_bin_irs except the instruction does not produce
1046 /// a explicit result, only implicitly set CPSR.
1047 multiclass T2I_cmp_irs<bits<4> opcod, string opc, RegisterClass LHSGPR,
1048 InstrItinClass iii, InstrItinClass iir, InstrItinClass iis,
1049 SDPatternOperator opnode> {
1050 let isCompare = 1, Defs = [CPSR] in {
1052 def ri : T2OneRegCmpImm<
1053 (outs), (ins LHSGPR:$Rn, t2_so_imm:$imm), iii,
1054 opc, ".w\t$Rn, $imm",
1055 [(opnode LHSGPR:$Rn, t2_so_imm:$imm)]>, Sched<[WriteCMP]> {
1056 let Inst{31-27} = 0b11110;
1058 let Inst{24-21} = opcod;
1059 let Inst{20} = 1; // The S bit.
1061 let Inst{11-8} = 0b1111; // Rd
1064 def rr : T2TwoRegCmp<
1065 (outs), (ins LHSGPR:$Rn, rGPR:$Rm), iir,
1066 opc, ".w\t$Rn, $Rm",
1067 [(opnode LHSGPR:$Rn, rGPR:$Rm)]>, Sched<[WriteCMP]> {
1068 let Inst{31-27} = 0b11101;
1069 let Inst{26-25} = 0b01;
1070 let Inst{24-21} = opcod;
1071 let Inst{20} = 1; // The S bit.
1072 let Inst{14-12} = 0b000; // imm3
1073 let Inst{11-8} = 0b1111; // Rd
1074 let Inst{7-6} = 0b00; // imm2
1075 let Inst{5-4} = 0b00; // type
1078 def rs : T2OneRegCmpShiftedReg<
1079 (outs), (ins LHSGPR:$Rn, t2_so_reg:$ShiftedRm), iis,
1080 opc, ".w\t$Rn, $ShiftedRm",
1081 [(opnode LHSGPR:$Rn, t2_so_reg:$ShiftedRm)]>,
1082 Sched<[WriteCMPsi]> {
1083 let Inst{31-27} = 0b11101;
1084 let Inst{26-25} = 0b01;
1085 let Inst{24-21} = opcod;
1086 let Inst{20} = 1; // The S bit.
1087 let Inst{11-8} = 0b1111; // Rd
1091 // Assembler aliases w/o the ".w" suffix.
1092 // No alias here for 'rr' version as not all instantiations of this
1093 // multiclass want one (CMP in particular, does not).
1094 def : t2InstAlias<!strconcat(opc, "${p}", " $Rn, $imm"),
1095 (!cast<Instruction>(NAME#"ri") LHSGPR:$Rn, t2_so_imm:$imm, pred:$p)>;
1096 def : t2InstAlias<!strconcat(opc, "${p}", " $Rn, $shift"),
1097 (!cast<Instruction>(NAME#"rs") LHSGPR:$Rn, t2_so_reg:$shift, pred:$p)>;
1100 /// T2I_ld - Defines a set of (op r, {imm12|imm8|so_reg}) load patterns.
1101 multiclass T2I_ld<bit signed, bits<2> opcod, string opc,
1102 InstrItinClass iii, InstrItinClass iis, RegisterClass target,
1104 def i12 : T2Ii12<(outs target:$Rt), (ins t2addrmode_imm12:$addr), iii,
1105 opc, ".w\t$Rt, $addr",
1106 [(set target:$Rt, (opnode t2addrmode_imm12:$addr))]>,
1110 let Inst{31-25} = 0b1111100;
1111 let Inst{24} = signed;
1113 let Inst{22-21} = opcod;
1114 let Inst{20} = 1; // load
1115 let Inst{19-16} = addr{16-13}; // Rn
1116 let Inst{15-12} = Rt;
1117 let Inst{11-0} = addr{11-0}; // imm
1119 let DecoderMethod = "DecodeT2LoadImm12";
1121 def i8 : T2Ii8 <(outs target:$Rt), (ins t2addrmode_negimm8:$addr), iii,
1122 opc, "\t$Rt, $addr",
1123 [(set target:$Rt, (opnode t2addrmode_negimm8:$addr))]>,
1127 let Inst{31-27} = 0b11111;
1128 let Inst{26-25} = 0b00;
1129 let Inst{24} = signed;
1131 let Inst{22-21} = opcod;
1132 let Inst{20} = 1; // load
1133 let Inst{19-16} = addr{12-9}; // Rn
1134 let Inst{15-12} = Rt;
1136 // Offset: index==TRUE, wback==FALSE
1137 let Inst{10} = 1; // The P bit.
1138 let Inst{9} = addr{8}; // U
1139 let Inst{8} = 0; // The W bit.
1140 let Inst{7-0} = addr{7-0}; // imm
1142 let DecoderMethod = "DecodeT2LoadImm8";
1144 def s : T2Iso <(outs target:$Rt), (ins t2addrmode_so_reg:$addr), iis,
1145 opc, ".w\t$Rt, $addr",
1146 [(set target:$Rt, (opnode t2addrmode_so_reg:$addr))]>,
1148 let Inst{31-27} = 0b11111;
1149 let Inst{26-25} = 0b00;
1150 let Inst{24} = signed;
1152 let Inst{22-21} = opcod;
1153 let Inst{20} = 1; // load
1154 let Inst{11-6} = 0b000000;
1157 let Inst{15-12} = Rt;
1160 let Inst{19-16} = addr{9-6}; // Rn
1161 let Inst{3-0} = addr{5-2}; // Rm
1162 let Inst{5-4} = addr{1-0}; // imm
1164 let DecoderMethod = "DecodeT2LoadShift";
1167 // pci variant is very similar to i12, but supports negative offsets
1169 def pci : T2Ipc <(outs target:$Rt), (ins t2ldrlabel:$addr), iii,
1170 opc, ".w\t$Rt, $addr",
1171 [(set target:$Rt, (opnode (ARMWrapper tconstpool:$addr)))]>,
1173 let isReMaterializable = 1;
1174 let Inst{31-27} = 0b11111;
1175 let Inst{26-25} = 0b00;
1176 let Inst{24} = signed;
1177 let Inst{22-21} = opcod;
1178 let Inst{20} = 1; // load
1179 let Inst{19-16} = 0b1111; // Rn
1182 let Inst{15-12} = Rt{3-0};
1185 let Inst{23} = addr{12}; // add = (U == '1')
1186 let Inst{11-0} = addr{11-0};
1188 let DecoderMethod = "DecodeT2LoadLabel";
1192 /// T2I_st - Defines a set of (op r, {imm12|imm8|so_reg}) store patterns.
1193 multiclass T2I_st<bits<2> opcod, string opc,
1194 InstrItinClass iii, InstrItinClass iis, RegisterClass target,
1196 def i12 : T2Ii12<(outs), (ins target:$Rt, t2addrmode_imm12:$addr), iii,
1197 opc, ".w\t$Rt, $addr",
1198 [(opnode target:$Rt, t2addrmode_imm12:$addr)]>,
1200 let Inst{31-27} = 0b11111;
1201 let Inst{26-23} = 0b0001;
1202 let Inst{22-21} = opcod;
1203 let Inst{20} = 0; // !load
1206 let Inst{15-12} = Rt;
1209 let addr{12} = 1; // add = TRUE
1210 let Inst{19-16} = addr{16-13}; // Rn
1211 let Inst{23} = addr{12}; // U
1212 let Inst{11-0} = addr{11-0}; // imm
1214 def i8 : T2Ii8 <(outs), (ins target:$Rt, t2addrmode_negimm8:$addr), iii,
1215 opc, "\t$Rt, $addr",
1216 [(opnode target:$Rt, t2addrmode_negimm8:$addr)]>,
1218 let Inst{31-27} = 0b11111;
1219 let Inst{26-23} = 0b0000;
1220 let Inst{22-21} = opcod;
1221 let Inst{20} = 0; // !load
1223 // Offset: index==TRUE, wback==FALSE
1224 let Inst{10} = 1; // The P bit.
1225 let Inst{8} = 0; // The W bit.
1228 let Inst{15-12} = Rt;
1231 let Inst{19-16} = addr{12-9}; // Rn
1232 let Inst{9} = addr{8}; // U
1233 let Inst{7-0} = addr{7-0}; // imm
1235 def s : T2Iso <(outs), (ins target:$Rt, t2addrmode_so_reg:$addr), iis,
1236 opc, ".w\t$Rt, $addr",
1237 [(opnode target:$Rt, t2addrmode_so_reg:$addr)]>,
1239 let Inst{31-27} = 0b11111;
1240 let Inst{26-23} = 0b0000;
1241 let Inst{22-21} = opcod;
1242 let Inst{20} = 0; // !load
1243 let Inst{11-6} = 0b000000;
1246 let Inst{15-12} = Rt;
1249 let Inst{19-16} = addr{9-6}; // Rn
1250 let Inst{3-0} = addr{5-2}; // Rm
1251 let Inst{5-4} = addr{1-0}; // imm
1255 /// T2I_ext_rrot - A unary operation with two forms: one whose operand is a
1256 /// register and one whose operand is a register rotated by 8/16/24.
1257 class T2I_ext_rrot_base<bits<3> opcod, dag iops, dag oops,
1258 string opc, string oprs,
1260 : T2TwoReg<iops, oops, IIC_iEXTr, opc, oprs, pattern> {
1262 let Inst{31-27} = 0b11111;
1263 let Inst{26-23} = 0b0100;
1264 let Inst{22-20} = opcod;
1265 let Inst{19-16} = 0b1111; // Rn
1266 let Inst{15-12} = 0b1111;
1268 let Inst{5-4} = rot; // rotate
1271 class T2I_ext_rrot<bits<3> opcod, string opc>
1272 : T2I_ext_rrot_base<opcod,
1274 (ins rGPR:$Rm, rot_imm:$rot),
1275 opc, ".w\t$Rd, $Rm$rot", []>,
1276 Requires<[IsThumb2]>,
1277 Sched<[WriteALU, ReadALU]>;
1279 // UXTB16, SXTB16 - Requires HasDSP, does not need the .w qualifier.
1280 class T2I_ext_rrot_xtb16<bits<3> opcod, string opc>
1281 : T2I_ext_rrot_base<opcod,
1283 (ins rGPR:$Rm, rot_imm:$rot),
1284 opc, "\t$Rd, $Rm$rot", []>,
1285 Requires<[HasDSP, IsThumb2]>,
1286 Sched<[WriteALU, ReadALU]>;
1288 /// T2I_exta_rrot - A binary operation with two forms: one whose operand is a
1289 /// register and one whose operand is a register rotated by 8/16/24.
1290 class T2I_exta_rrot<bits<3> opcod, string opc>
1291 : T2ThreeReg<(outs rGPR:$Rd),
1292 (ins rGPR:$Rn, rGPR:$Rm, rot_imm:$rot),
1293 IIC_iEXTAsr, opc, "\t$Rd, $Rn, $Rm$rot", []>,
1294 Requires<[HasDSP, IsThumb2]>,
1295 Sched<[WriteALU, ReadALU]> {
1297 let Inst{31-27} = 0b11111;
1298 let Inst{26-23} = 0b0100;
1299 let Inst{22-20} = opcod;
1300 let Inst{15-12} = 0b1111;
1302 let Inst{5-4} = rot;
1305 //===----------------------------------------------------------------------===//
1307 //===----------------------------------------------------------------------===//
1309 //===----------------------------------------------------------------------===//
1310 // Miscellaneous Instructions.
1313 class T2PCOneRegImm<dag oops, dag iops, InstrItinClass itin,
1314 string asm, list<dag> pattern>
1315 : T2XI<oops, iops, itin, asm, pattern> {
1319 let Inst{11-8} = Rd;
1320 let Inst{26} = label{11};
1321 let Inst{14-12} = label{10-8};
1322 let Inst{7-0} = label{7-0};
1325 // LEApcrel - Load a pc-relative address into a register without offending the
1327 def t2ADR : T2PCOneRegImm<(outs rGPR:$Rd),
1328 (ins t2adrlabel:$addr, pred:$p),
1329 IIC_iALUi, "adr{$p}.w\t$Rd, $addr", []>,
1330 Sched<[WriteALU, ReadALU]> {
1331 let Inst{31-27} = 0b11110;
1332 let Inst{25-24} = 0b10;
1333 // Inst{23:21} = '11' (add = FALSE) or '00' (add = TRUE)
1336 let Inst{19-16} = 0b1111; // Rn
1341 let Inst{11-8} = Rd;
1342 let Inst{23} = addr{12};
1343 let Inst{21} = addr{12};
1344 let Inst{26} = addr{11};
1345 let Inst{14-12} = addr{10-8};
1346 let Inst{7-0} = addr{7-0};
1348 let DecoderMethod = "DecodeT2Adr";
1351 let hasSideEffects = 0, isReMaterializable = 1 in
1352 def t2LEApcrel : t2PseudoInst<(outs rGPR:$Rd), (ins i32imm:$label, pred:$p),
1353 4, IIC_iALUi, []>, Sched<[WriteALU, ReadALU]>;
1354 let hasSideEffects = 1 in
1355 def t2LEApcrelJT : t2PseudoInst<(outs rGPR:$Rd),
1356 (ins i32imm:$label, pred:$p),
1358 []>, Sched<[WriteALU, ReadALU]>;
1361 //===----------------------------------------------------------------------===//
1362 // Load / store Instructions.
1366 let canFoldAsLoad = 1, isReMaterializable = 1 in
1367 defm t2LDR : T2I_ld<0, 0b10, "ldr", IIC_iLoad_i, IIC_iLoad_si, GPR, load>;
1369 // Loads with zero extension
1370 defm t2LDRH : T2I_ld<0, 0b01, "ldrh", IIC_iLoad_bh_i, IIC_iLoad_bh_si,
1371 GPRnopc, zextloadi16>;
1372 defm t2LDRB : T2I_ld<0, 0b00, "ldrb", IIC_iLoad_bh_i, IIC_iLoad_bh_si,
1373 GPRnopc, zextloadi8>;
1375 // Loads with sign extension
1376 defm t2LDRSH : T2I_ld<1, 0b01, "ldrsh", IIC_iLoad_bh_i, IIC_iLoad_bh_si,
1377 GPRnopc, sextloadi16>;
1378 defm t2LDRSB : T2I_ld<1, 0b00, "ldrsb", IIC_iLoad_bh_i, IIC_iLoad_bh_si,
1379 GPRnopc, sextloadi8>;
1381 let mayLoad = 1, hasSideEffects = 0, hasExtraDefRegAllocReq = 1 in {
1383 def t2LDRDi8 : T2Ii8s4<1, 0, 1, (outs rGPR:$Rt, rGPR:$Rt2),
1384 (ins t2addrmode_imm8s4:$addr),
1385 IIC_iLoad_d_i, "ldrd", "\t$Rt, $Rt2, $addr", "", []>,
1387 } // mayLoad = 1, hasSideEffects = 0, hasExtraDefRegAllocReq = 1
1389 // zextload i1 -> zextload i8
1390 def : T2Pat<(zextloadi1 t2addrmode_imm12:$addr),
1391 (t2LDRBi12 t2addrmode_imm12:$addr)>;
1392 def : T2Pat<(zextloadi1 t2addrmode_negimm8:$addr),
1393 (t2LDRBi8 t2addrmode_negimm8:$addr)>;
1394 def : T2Pat<(zextloadi1 t2addrmode_so_reg:$addr),
1395 (t2LDRBs t2addrmode_so_reg:$addr)>;
1396 def : T2Pat<(zextloadi1 (ARMWrapper tconstpool:$addr)),
1397 (t2LDRBpci tconstpool:$addr)>;
1399 // extload -> zextload
1400 // FIXME: Reduce the number of patterns by legalizing extload to zextload
1402 def : T2Pat<(extloadi1 t2addrmode_imm12:$addr),
1403 (t2LDRBi12 t2addrmode_imm12:$addr)>;
1404 def : T2Pat<(extloadi1 t2addrmode_negimm8:$addr),
1405 (t2LDRBi8 t2addrmode_negimm8:$addr)>;
1406 def : T2Pat<(extloadi1 t2addrmode_so_reg:$addr),
1407 (t2LDRBs t2addrmode_so_reg:$addr)>;
1408 def : T2Pat<(extloadi1 (ARMWrapper tconstpool:$addr)),
1409 (t2LDRBpci tconstpool:$addr)>;
1411 def : T2Pat<(extloadi8 t2addrmode_imm12:$addr),
1412 (t2LDRBi12 t2addrmode_imm12:$addr)>;
1413 def : T2Pat<(extloadi8 t2addrmode_negimm8:$addr),
1414 (t2LDRBi8 t2addrmode_negimm8:$addr)>;
1415 def : T2Pat<(extloadi8 t2addrmode_so_reg:$addr),
1416 (t2LDRBs t2addrmode_so_reg:$addr)>;
1417 def : T2Pat<(extloadi8 (ARMWrapper tconstpool:$addr)),
1418 (t2LDRBpci tconstpool:$addr)>;
1420 def : T2Pat<(extloadi16 t2addrmode_imm12:$addr),
1421 (t2LDRHi12 t2addrmode_imm12:$addr)>;
1422 def : T2Pat<(extloadi16 t2addrmode_negimm8:$addr),
1423 (t2LDRHi8 t2addrmode_negimm8:$addr)>;
1424 def : T2Pat<(extloadi16 t2addrmode_so_reg:$addr),
1425 (t2LDRHs t2addrmode_so_reg:$addr)>;
1426 def : T2Pat<(extloadi16 (ARMWrapper tconstpool:$addr)),
1427 (t2LDRHpci tconstpool:$addr)>;
1429 // FIXME: The destination register of the loads and stores can't be PC, but
1430 // can be SP. We need another regclass (similar to rGPR) to represent
1431 // that. Not a pressing issue since these are selected manually,
1436 let mayLoad = 1, hasSideEffects = 0 in {
1437 def t2LDR_PRE : T2Ipreldst<0, 0b10, 1, 1, (outs GPR:$Rt, GPR:$Rn_wb),
1438 (ins t2addrmode_imm8_pre:$addr),
1439 AddrModeT2_i8, IndexModePre, IIC_iLoad_iu,
1440 "ldr", "\t$Rt, $addr!", "$addr.base = $Rn_wb", []>,
1443 def t2LDR_POST : T2Ipostldst<0, 0b10, 1, 0, (outs GPR:$Rt, GPR:$Rn_wb),
1444 (ins addr_offset_none:$Rn, t2am_imm8_offset:$offset),
1445 AddrModeT2_i8, IndexModePost, IIC_iLoad_iu,
1446 "ldr", "\t$Rt, $Rn$offset", "$Rn = $Rn_wb", []>,
1449 def t2LDRB_PRE : T2Ipreldst<0, 0b00, 1, 1, (outs GPR:$Rt, GPR:$Rn_wb),
1450 (ins t2addrmode_imm8_pre:$addr),
1451 AddrModeT2_i8, IndexModePre, IIC_iLoad_bh_iu,
1452 "ldrb", "\t$Rt, $addr!", "$addr.base = $Rn_wb", []>,
1455 def t2LDRB_POST : T2Ipostldst<0, 0b00, 1, 0, (outs GPR:$Rt, GPR:$Rn_wb),
1456 (ins addr_offset_none:$Rn, t2am_imm8_offset:$offset),
1457 AddrModeT2_i8, IndexModePost, IIC_iLoad_bh_iu,
1458 "ldrb", "\t$Rt, $Rn$offset", "$Rn = $Rn_wb", []>,
1461 def t2LDRH_PRE : T2Ipreldst<0, 0b01, 1, 1, (outs GPR:$Rt, GPR:$Rn_wb),
1462 (ins t2addrmode_imm8_pre:$addr),
1463 AddrModeT2_i8, IndexModePre, IIC_iLoad_bh_iu,
1464 "ldrh", "\t$Rt, $addr!", "$addr.base = $Rn_wb", []>,
1467 def t2LDRH_POST : T2Ipostldst<0, 0b01, 1, 0, (outs GPR:$Rt, GPR:$Rn_wb),
1468 (ins addr_offset_none:$Rn, t2am_imm8_offset:$offset),
1469 AddrModeT2_i8, IndexModePost, IIC_iLoad_bh_iu,
1470 "ldrh", "\t$Rt, $Rn$offset", "$Rn = $Rn_wb", []>,
1473 def t2LDRSB_PRE : T2Ipreldst<1, 0b00, 1, 1, (outs GPR:$Rt, GPR:$Rn_wb),
1474 (ins t2addrmode_imm8_pre:$addr),
1475 AddrModeT2_i8, IndexModePre, IIC_iLoad_bh_iu,
1476 "ldrsb", "\t$Rt, $addr!", "$addr.base = $Rn_wb",
1477 []>, Sched<[WriteLd]>;
1479 def t2LDRSB_POST : T2Ipostldst<1, 0b00, 1, 0, (outs GPR:$Rt, GPR:$Rn_wb),
1480 (ins addr_offset_none:$Rn, t2am_imm8_offset:$offset),
1481 AddrModeT2_i8, IndexModePost, IIC_iLoad_bh_iu,
1482 "ldrsb", "\t$Rt, $Rn$offset", "$Rn = $Rn_wb", []>,
1485 def t2LDRSH_PRE : T2Ipreldst<1, 0b01, 1, 1, (outs GPR:$Rt, GPR:$Rn_wb),
1486 (ins t2addrmode_imm8_pre:$addr),
1487 AddrModeT2_i8, IndexModePre, IIC_iLoad_bh_iu,
1488 "ldrsh", "\t$Rt, $addr!", "$addr.base = $Rn_wb",
1489 []>, Sched<[WriteLd]>;
1491 def t2LDRSH_POST : T2Ipostldst<1, 0b01, 1, 0, (outs GPR:$Rt, GPR:$Rn_wb),
1492 (ins addr_offset_none:$Rn, t2am_imm8_offset:$offset),
1493 AddrModeT2_i8, IndexModePost, IIC_iLoad_bh_iu,
1494 "ldrsh", "\t$Rt, $Rn$offset", "$Rn = $Rn_wb", []>,
1496 } // mayLoad = 1, hasSideEffects = 0
1498 // LDRT, LDRBT, LDRHT, LDRSBT, LDRSHT all have offset mode (PUW=0b110).
1499 // Ref: A8.6.57 LDR (immediate, Thumb) Encoding T4
1500 class T2IldT<bit signed, bits<2> type, string opc, InstrItinClass ii>
1501 : T2Ii8<(outs rGPR:$Rt), (ins t2addrmode_posimm8:$addr), ii, opc,
1502 "\t$Rt, $addr", []>, Sched<[WriteLd]> {
1505 let Inst{31-27} = 0b11111;
1506 let Inst{26-25} = 0b00;
1507 let Inst{24} = signed;
1509 let Inst{22-21} = type;
1510 let Inst{20} = 1; // load
1511 let Inst{19-16} = addr{12-9};
1512 let Inst{15-12} = Rt;
1514 let Inst{10-8} = 0b110; // PUW.
1515 let Inst{7-0} = addr{7-0};
1517 let DecoderMethod = "DecodeT2LoadT";
1520 def t2LDRT : T2IldT<0, 0b10, "ldrt", IIC_iLoad_i>;
1521 def t2LDRBT : T2IldT<0, 0b00, "ldrbt", IIC_iLoad_bh_i>;
1522 def t2LDRHT : T2IldT<0, 0b01, "ldrht", IIC_iLoad_bh_i>;
1523 def t2LDRSBT : T2IldT<1, 0b00, "ldrsbt", IIC_iLoad_bh_i>;
1524 def t2LDRSHT : T2IldT<1, 0b01, "ldrsht", IIC_iLoad_bh_i>;
1526 class T2Ildacq<bits<4> bits23_20, bits<2> bit54, dag oops, dag iops,
1527 string opc, string asm, list<dag> pattern>
1528 : Thumb2I<oops, iops, AddrModeNone, 4, NoItinerary,
1529 opc, asm, "", pattern>, Requires<[IsThumb, HasAcquireRelease]> {
1533 let Inst{31-27} = 0b11101;
1534 let Inst{26-24} = 0b000;
1535 let Inst{23-20} = bits23_20;
1536 let Inst{11-6} = 0b111110;
1537 let Inst{5-4} = bit54;
1538 let Inst{3-0} = 0b1111;
1540 // Encode instruction operands
1541 let Inst{19-16} = addr;
1542 let Inst{15-12} = Rt;
1545 def t2LDA : T2Ildacq<0b1101, 0b10, (outs rGPR:$Rt),
1546 (ins addr_offset_none:$addr), "lda", "\t$Rt, $addr", []>,
1548 def t2LDAB : T2Ildacq<0b1101, 0b00, (outs rGPR:$Rt),
1549 (ins addr_offset_none:$addr), "ldab", "\t$Rt, $addr", []>,
1551 def t2LDAH : T2Ildacq<0b1101, 0b01, (outs rGPR:$Rt),
1552 (ins addr_offset_none:$addr), "ldah", "\t$Rt, $addr", []>,
1556 defm t2STR :T2I_st<0b10,"str", IIC_iStore_i, IIC_iStore_si, GPR, store>;
1557 defm t2STRB:T2I_st<0b00,"strb", IIC_iStore_bh_i, IIC_iStore_bh_si,
1558 rGPR, truncstorei8>;
1559 defm t2STRH:T2I_st<0b01,"strh", IIC_iStore_bh_i, IIC_iStore_bh_si,
1560 rGPR, truncstorei16>;
1563 let mayStore = 1, hasSideEffects = 0, hasExtraSrcRegAllocReq = 1 in
1564 def t2STRDi8 : T2Ii8s4<1, 0, 0, (outs),
1565 (ins rGPR:$Rt, rGPR:$Rt2, t2addrmode_imm8s4:$addr),
1566 IIC_iStore_d_r, "strd", "\t$Rt, $Rt2, $addr", "", []>,
1571 let mayStore = 1, hasSideEffects = 0 in {
1572 def t2STR_PRE : T2Ipreldst<0, 0b10, 0, 1, (outs GPRnopc:$Rn_wb),
1573 (ins GPRnopc:$Rt, t2addrmode_imm8_pre:$addr),
1574 AddrModeT2_i8, IndexModePre, IIC_iStore_iu,
1575 "str", "\t$Rt, $addr!",
1576 "$addr.base = $Rn_wb,@earlyclobber $Rn_wb", []>,
1579 def t2STRH_PRE : T2Ipreldst<0, 0b01, 0, 1, (outs GPRnopc:$Rn_wb),
1580 (ins rGPR:$Rt, t2addrmode_imm8_pre:$addr),
1581 AddrModeT2_i8, IndexModePre, IIC_iStore_iu,
1582 "strh", "\t$Rt, $addr!",
1583 "$addr.base = $Rn_wb,@earlyclobber $Rn_wb", []>,
1586 def t2STRB_PRE : T2Ipreldst<0, 0b00, 0, 1, (outs GPRnopc:$Rn_wb),
1587 (ins rGPR:$Rt, t2addrmode_imm8_pre:$addr),
1588 AddrModeT2_i8, IndexModePre, IIC_iStore_bh_iu,
1589 "strb", "\t$Rt, $addr!",
1590 "$addr.base = $Rn_wb,@earlyclobber $Rn_wb", []>,
1592 } // mayStore = 1, hasSideEffects = 0
1594 def t2STR_POST : T2Ipostldst<0, 0b10, 0, 0, (outs GPRnopc:$Rn_wb),
1595 (ins GPRnopc:$Rt, addr_offset_none:$Rn,
1596 t2am_imm8_offset:$offset),
1597 AddrModeT2_i8, IndexModePost, IIC_iStore_iu,
1598 "str", "\t$Rt, $Rn$offset",
1599 "$Rn = $Rn_wb,@earlyclobber $Rn_wb",
1600 [(set GPRnopc:$Rn_wb,
1601 (post_store GPRnopc:$Rt, addr_offset_none:$Rn,
1602 t2am_imm8_offset:$offset))]>,
1605 def t2STRH_POST : T2Ipostldst<0, 0b01, 0, 0, (outs GPRnopc:$Rn_wb),
1606 (ins rGPR:$Rt, addr_offset_none:$Rn,
1607 t2am_imm8_offset:$offset),
1608 AddrModeT2_i8, IndexModePost, IIC_iStore_bh_iu,
1609 "strh", "\t$Rt, $Rn$offset",
1610 "$Rn = $Rn_wb,@earlyclobber $Rn_wb",
1611 [(set GPRnopc:$Rn_wb,
1612 (post_truncsti16 rGPR:$Rt, addr_offset_none:$Rn,
1613 t2am_imm8_offset:$offset))]>,
1616 def t2STRB_POST : T2Ipostldst<0, 0b00, 0, 0, (outs GPRnopc:$Rn_wb),
1617 (ins rGPR:$Rt, addr_offset_none:$Rn,
1618 t2am_imm8_offset:$offset),
1619 AddrModeT2_i8, IndexModePost, IIC_iStore_bh_iu,
1620 "strb", "\t$Rt, $Rn$offset",
1621 "$Rn = $Rn_wb,@earlyclobber $Rn_wb",
1622 [(set GPRnopc:$Rn_wb,
1623 (post_truncsti8 rGPR:$Rt, addr_offset_none:$Rn,
1624 t2am_imm8_offset:$offset))]>,
1627 // Pseudo-instructions for pattern matching the pre-indexed stores. We can't
1628 // put the patterns on the instruction definitions directly as ISel wants
1629 // the address base and offset to be separate operands, not a single
1630 // complex operand like we represent the instructions themselves. The
1631 // pseudos map between the two.
1632 let usesCustomInserter = 1,
1633 Constraints = "$Rn = $Rn_wb,@earlyclobber $Rn_wb" in {
1634 def t2STR_preidx: t2PseudoInst<(outs GPRnopc:$Rn_wb),
1635 (ins rGPR:$Rt, GPRnopc:$Rn, t2am_imm8_offset:$offset, pred:$p),
1637 [(set GPRnopc:$Rn_wb,
1638 (pre_store rGPR:$Rt, GPRnopc:$Rn, t2am_imm8_offset:$offset))]>,
1640 def t2STRB_preidx: t2PseudoInst<(outs GPRnopc:$Rn_wb),
1641 (ins rGPR:$Rt, GPRnopc:$Rn, t2am_imm8_offset:$offset, pred:$p),
1643 [(set GPRnopc:$Rn_wb,
1644 (pre_truncsti8 rGPR:$Rt, GPRnopc:$Rn, t2am_imm8_offset:$offset))]>,
1646 def t2STRH_preidx: t2PseudoInst<(outs GPRnopc:$Rn_wb),
1647 (ins rGPR:$Rt, GPRnopc:$Rn, t2am_imm8_offset:$offset, pred:$p),
1649 [(set GPRnopc:$Rn_wb,
1650 (pre_truncsti16 rGPR:$Rt, GPRnopc:$Rn, t2am_imm8_offset:$offset))]>,
1654 // STRT, STRBT, STRHT all have offset mode (PUW=0b110) and are for disassembly
1656 // Ref: A8.6.193 STR (immediate, Thumb) Encoding T4
1657 class T2IstT<bits<2> type, string opc, InstrItinClass ii>
1658 : T2Ii8<(outs rGPR:$Rt), (ins t2addrmode_imm8:$addr), ii, opc,
1659 "\t$Rt, $addr", []>, Sched<[WriteST]> {
1660 let Inst{31-27} = 0b11111;
1661 let Inst{26-25} = 0b00;
1662 let Inst{24} = 0; // not signed
1664 let Inst{22-21} = type;
1665 let Inst{20} = 0; // store
1667 let Inst{10-8} = 0b110; // PUW
1671 let Inst{15-12} = Rt;
1672 let Inst{19-16} = addr{12-9};
1673 let Inst{7-0} = addr{7-0};
1676 def t2STRT : T2IstT<0b10, "strt", IIC_iStore_i>;
1677 def t2STRBT : T2IstT<0b00, "strbt", IIC_iStore_bh_i>;
1678 def t2STRHT : T2IstT<0b01, "strht", IIC_iStore_bh_i>;
1680 // ldrd / strd pre / post variants
1683 def t2LDRD_PRE : T2Ii8s4<1, 1, 1, (outs rGPR:$Rt, rGPR:$Rt2, GPR:$wb),
1684 (ins t2addrmode_imm8s4_pre:$addr), IIC_iLoad_d_ru,
1685 "ldrd", "\t$Rt, $Rt2, $addr!", "$addr.base = $wb", []>,
1687 let DecoderMethod = "DecodeT2LDRDPreInstruction";
1691 def t2LDRD_POST : T2Ii8s4post<0, 1, 1, (outs rGPR:$Rt, rGPR:$Rt2, GPR:$wb),
1692 (ins addr_offset_none:$addr, t2am_imm8s4_offset:$imm),
1693 IIC_iLoad_d_ru, "ldrd", "\t$Rt, $Rt2, $addr$imm",
1694 "$addr.base = $wb", []>, Sched<[WriteLd]>;
1697 def t2STRD_PRE : T2Ii8s4<1, 1, 0, (outs GPR:$wb),
1698 (ins rGPR:$Rt, rGPR:$Rt2, t2addrmode_imm8s4_pre:$addr),
1699 IIC_iStore_d_ru, "strd", "\t$Rt, $Rt2, $addr!",
1700 "$addr.base = $wb", []>, Sched<[WriteST]> {
1701 let DecoderMethod = "DecodeT2STRDPreInstruction";
1705 def t2STRD_POST : T2Ii8s4post<0, 1, 0, (outs GPR:$wb),
1706 (ins rGPR:$Rt, rGPR:$Rt2, addr_offset_none:$addr,
1707 t2am_imm8s4_offset:$imm),
1708 IIC_iStore_d_ru, "strd", "\t$Rt, $Rt2, $addr$imm",
1709 "$addr.base = $wb", []>, Sched<[WriteST]>;
1711 class T2Istrrel<bits<2> bit54, dag oops, dag iops,
1712 string opc, string asm, list<dag> pattern>
1713 : Thumb2I<oops, iops, AddrModeNone, 4, NoItinerary, opc,
1714 asm, "", pattern>, Requires<[IsThumb, HasAcquireRelease]>,
1719 let Inst{31-27} = 0b11101;
1720 let Inst{26-20} = 0b0001100;
1721 let Inst{11-6} = 0b111110;
1722 let Inst{5-4} = bit54;
1723 let Inst{3-0} = 0b1111;
1725 // Encode instruction operands
1726 let Inst{19-16} = addr;
1727 let Inst{15-12} = Rt;
1730 def t2STL : T2Istrrel<0b10, (outs), (ins rGPR:$Rt, addr_offset_none:$addr),
1731 "stl", "\t$Rt, $addr", []>;
1732 def t2STLB : T2Istrrel<0b00, (outs), (ins rGPR:$Rt, addr_offset_none:$addr),
1733 "stlb", "\t$Rt, $addr", []>;
1734 def t2STLH : T2Istrrel<0b01, (outs), (ins rGPR:$Rt, addr_offset_none:$addr),
1735 "stlh", "\t$Rt, $addr", []>;
1737 // T2Ipl (Preload Data/Instruction) signals the memory system of possible future
1738 // data/instruction access.
1739 // instr_write is inverted for Thumb mode: (prefetch 3) -> (preload 0),
1740 // (prefetch 1) -> (preload 2), (prefetch 2) -> (preload 1).
1741 multiclass T2Ipl<bits<1> write, bits<1> instr, string opc> {
1743 def i12 : T2Ii12<(outs), (ins t2addrmode_imm12:$addr), IIC_Preload, opc,
1745 [(ARMPreload t2addrmode_imm12:$addr, (i32 write), (i32 instr))]>,
1746 Sched<[WritePreLd]> {
1747 let Inst{31-25} = 0b1111100;
1748 let Inst{24} = instr;
1751 let Inst{21} = write;
1753 let Inst{15-12} = 0b1111;
1756 let Inst{19-16} = addr{16-13}; // Rn
1757 let Inst{11-0} = addr{11-0}; // imm12
1759 let DecoderMethod = "DecodeT2LoadImm12";
1762 def i8 : T2Ii8<(outs), (ins t2addrmode_negimm8:$addr), IIC_Preload, opc,
1764 [(ARMPreload t2addrmode_negimm8:$addr, (i32 write), (i32 instr))]>,
1765 Sched<[WritePreLd]> {
1766 let Inst{31-25} = 0b1111100;
1767 let Inst{24} = instr;
1768 let Inst{23} = 0; // U = 0
1770 let Inst{21} = write;
1772 let Inst{15-12} = 0b1111;
1773 let Inst{11-8} = 0b1100;
1776 let Inst{19-16} = addr{12-9}; // Rn
1777 let Inst{7-0} = addr{7-0}; // imm8
1779 let DecoderMethod = "DecodeT2LoadImm8";
1782 def s : T2Iso<(outs), (ins t2addrmode_so_reg:$addr), IIC_Preload, opc,
1784 [(ARMPreload t2addrmode_so_reg:$addr, (i32 write), (i32 instr))]>,
1785 Sched<[WritePreLd]> {
1786 let Inst{31-25} = 0b1111100;
1787 let Inst{24} = instr;
1788 let Inst{23} = 0; // add = TRUE for T1
1790 let Inst{21} = write;
1792 let Inst{15-12} = 0b1111;
1793 let Inst{11-6} = 0b000000;
1796 let Inst{19-16} = addr{9-6}; // Rn
1797 let Inst{3-0} = addr{5-2}; // Rm
1798 let Inst{5-4} = addr{1-0}; // imm2
1800 let DecoderMethod = "DecodeT2LoadShift";
1804 defm t2PLD : T2Ipl<0, 0, "pld">, Requires<[IsThumb2]>;
1805 defm t2PLDW : T2Ipl<1, 0, "pldw">, Requires<[IsThumb2,HasV7,HasMP]>;
1806 defm t2PLI : T2Ipl<0, 1, "pli">, Requires<[IsThumb2,HasV7]>;
1808 // pci variant is very similar to i12, but supports negative offsets
1809 // from the PC. Only PLD and PLI have pci variants (not PLDW)
1810 class T2Iplpci<bits<1> inst, string opc> : T2Iso<(outs), (ins t2ldrlabel:$addr),
1811 IIC_Preload, opc, "\t$addr",
1812 [(ARMPreload (ARMWrapper tconstpool:$addr),
1813 (i32 0), (i32 inst))]>, Sched<[WritePreLd]> {
1814 let Inst{31-25} = 0b1111100;
1815 let Inst{24} = inst;
1816 let Inst{22-20} = 0b001;
1817 let Inst{19-16} = 0b1111;
1818 let Inst{15-12} = 0b1111;
1821 let Inst{23} = addr{12}; // add = (U == '1')
1822 let Inst{11-0} = addr{11-0}; // imm12
1824 let DecoderMethod = "DecodeT2LoadLabel";
1827 def t2PLDpci : T2Iplpci<0, "pld">, Requires<[IsThumb2]>;
1828 def t2PLIpci : T2Iplpci<1, "pli">, Requires<[IsThumb2,HasV7]>;
1830 //===----------------------------------------------------------------------===//
1831 // Load / store multiple Instructions.
1834 multiclass thumb2_ld_mult<string asm, InstrItinClass itin,
1835 InstrItinClass itin_upd, bit L_bit> {
1837 T2XI<(outs), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops),
1838 itin, !strconcat(asm, "${p}.w\t$Rn, $regs"), []> {
1842 let Inst{31-27} = 0b11101;
1843 let Inst{26-25} = 0b00;
1844 let Inst{24-23} = 0b01; // Increment After
1846 let Inst{21} = 0; // No writeback
1847 let Inst{20} = L_bit;
1848 let Inst{19-16} = Rn;
1849 let Inst{15-0} = regs;
1852 T2XIt<(outs GPR:$wb), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops),
1853 itin_upd, !strconcat(asm, "${p}.w\t$Rn!, $regs"), "$Rn = $wb", []> {
1857 let Inst{31-27} = 0b11101;
1858 let Inst{26-25} = 0b00;
1859 let Inst{24-23} = 0b01; // Increment After
1861 let Inst{21} = 1; // Writeback
1862 let Inst{20} = L_bit;
1863 let Inst{19-16} = Rn;
1864 let Inst{15-0} = regs;
1867 T2XI<(outs), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops),
1868 itin, !strconcat(asm, "db${p}\t$Rn, $regs"), []> {
1872 let Inst{31-27} = 0b11101;
1873 let Inst{26-25} = 0b00;
1874 let Inst{24-23} = 0b10; // Decrement Before
1876 let Inst{21} = 0; // No writeback
1877 let Inst{20} = L_bit;
1878 let Inst{19-16} = Rn;
1879 let Inst{15-0} = regs;
1882 T2XIt<(outs GPR:$wb), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops),
1883 itin_upd, !strconcat(asm, "db${p}\t$Rn!, $regs"), "$Rn = $wb", []> {
1887 let Inst{31-27} = 0b11101;
1888 let Inst{26-25} = 0b00;
1889 let Inst{24-23} = 0b10; // Decrement Before
1891 let Inst{21} = 1; // Writeback
1892 let Inst{20} = L_bit;
1893 let Inst{19-16} = Rn;
1894 let Inst{15-0} = regs;
1898 let hasSideEffects = 0 in {
1900 let mayLoad = 1, hasExtraDefRegAllocReq = 1, variadicOpsAreDefs = 1 in
1901 defm t2LDM : thumb2_ld_mult<"ldm", IIC_iLoad_m, IIC_iLoad_mu, 1>;
1903 multiclass thumb2_st_mult<string asm, InstrItinClass itin,
1904 InstrItinClass itin_upd, bit L_bit> {
1906 T2XI<(outs), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops),
1907 itin, !strconcat(asm, "${p}.w\t$Rn, $regs"), []> {
1911 let Inst{31-27} = 0b11101;
1912 let Inst{26-25} = 0b00;
1913 let Inst{24-23} = 0b01; // Increment After
1915 let Inst{21} = 0; // No writeback
1916 let Inst{20} = L_bit;
1917 let Inst{19-16} = Rn;
1919 let Inst{14} = regs{14};
1921 let Inst{12-0} = regs{12-0};
1924 T2XIt<(outs GPR:$wb), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops),
1925 itin_upd, !strconcat(asm, "${p}.w\t$Rn!, $regs"), "$Rn = $wb", []> {
1929 let Inst{31-27} = 0b11101;
1930 let Inst{26-25} = 0b00;
1931 let Inst{24-23} = 0b01; // Increment After
1933 let Inst{21} = 1; // Writeback
1934 let Inst{20} = L_bit;
1935 let Inst{19-16} = Rn;
1937 let Inst{14} = regs{14};
1939 let Inst{12-0} = regs{12-0};
1942 T2XI<(outs), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops),
1943 itin, !strconcat(asm, "db${p}\t$Rn, $regs"), []> {
1947 let Inst{31-27} = 0b11101;
1948 let Inst{26-25} = 0b00;
1949 let Inst{24-23} = 0b10; // Decrement Before
1951 let Inst{21} = 0; // No writeback
1952 let Inst{20} = L_bit;
1953 let Inst{19-16} = Rn;
1955 let Inst{14} = regs{14};
1957 let Inst{12-0} = regs{12-0};
1960 T2XIt<(outs GPR:$wb), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops),
1961 itin_upd, !strconcat(asm, "db${p}\t$Rn!, $regs"), "$Rn = $wb", []> {
1965 let Inst{31-27} = 0b11101;
1966 let Inst{26-25} = 0b00;
1967 let Inst{24-23} = 0b10; // Decrement Before
1969 let Inst{21} = 1; // Writeback
1970 let Inst{20} = L_bit;
1971 let Inst{19-16} = Rn;
1973 let Inst{14} = regs{14};
1975 let Inst{12-0} = regs{12-0};
1980 let mayStore = 1, hasExtraSrcRegAllocReq = 1 in
1981 defm t2STM : thumb2_st_mult<"stm", IIC_iStore_m, IIC_iStore_mu, 0>;
1986 //===----------------------------------------------------------------------===//
1987 // Move Instructions.
1990 let hasSideEffects = 0 in
1991 def t2MOVr : T2sTwoReg<(outs GPRnopc:$Rd), (ins GPRnopc:$Rm), IIC_iMOVr,
1992 "mov", ".w\t$Rd, $Rm", []>, Sched<[WriteALU]> {
1993 let Inst{31-27} = 0b11101;
1994 let Inst{26-25} = 0b01;
1995 let Inst{24-21} = 0b0010;
1996 let Inst{19-16} = 0b1111; // Rn
1998 let Inst{14-12} = 0b000;
1999 let Inst{7-4} = 0b0000;
2001 def : t2InstAlias<"mov${p}.w $Rd, $Rm", (t2MOVr GPRnopc:$Rd, GPRnopc:$Rm,
2002 pred:$p, zero_reg)>;
2003 def : t2InstAlias<"movs${p}.w $Rd, $Rm", (t2MOVr GPRnopc:$Rd, GPRnopc:$Rm,
2005 def : t2InstAlias<"movs${p} $Rd, $Rm", (t2MOVr GPRnopc:$Rd, GPRnopc:$Rm,
2008 // AddedComplexity to ensure isel tries t2MOVi before t2MOVi16.
2009 let isReMaterializable = 1, isAsCheapAsAMove = 1, isMoveImm = 1,
2010 AddedComplexity = 1 in
2011 def t2MOVi : T2sOneRegImm<(outs rGPR:$Rd), (ins t2_so_imm:$imm), IIC_iMOVi,
2012 "mov", ".w\t$Rd, $imm",
2013 [(set rGPR:$Rd, t2_so_imm:$imm)]>, Sched<[WriteALU]> {
2014 let Inst{31-27} = 0b11110;
2016 let Inst{24-21} = 0b0010;
2017 let Inst{19-16} = 0b1111; // Rn
2021 // cc_out is handled as part of the explicit mnemonic in the parser for 'mov'.
2022 // Use aliases to get that to play nice here.
2023 def : t2InstAlias<"movs${p}.w $Rd, $imm", (t2MOVi rGPR:$Rd, t2_so_imm:$imm,
2025 def : t2InstAlias<"movs${p} $Rd, $imm", (t2MOVi rGPR:$Rd, t2_so_imm:$imm,
2028 def : t2InstAlias<"mov${p}.w $Rd, $imm", (t2MOVi rGPR:$Rd, t2_so_imm:$imm,
2029 pred:$p, zero_reg)>;
2030 def : t2InstAlias<"mov${p} $Rd, $imm", (t2MOVi rGPR:$Rd, t2_so_imm:$imm,
2031 pred:$p, zero_reg)>;
2033 let isReMaterializable = 1, isAsCheapAsAMove = 1, isMoveImm = 1 in
2034 def t2MOVi16 : T2I<(outs rGPR:$Rd), (ins imm0_65535_expr:$imm), IIC_iMOVi,
2035 "movw", "\t$Rd, $imm",
2036 [(set rGPR:$Rd, imm0_65535:$imm)]>, Sched<[WriteALU]>,
2037 Requires<[IsThumb, HasV8MBaseline]> {
2038 let Inst{31-27} = 0b11110;
2040 let Inst{24-21} = 0b0010;
2041 let Inst{20} = 0; // The S bit.
2047 let Inst{11-8} = Rd;
2048 let Inst{19-16} = imm{15-12};
2049 let Inst{26} = imm{11};
2050 let Inst{14-12} = imm{10-8};
2051 let Inst{7-0} = imm{7-0};
2052 let DecoderMethod = "DecodeT2MOVTWInstruction";
2055 def : InstAlias<"mov${p} $Rd, $imm",
2056 (t2MOVi16 rGPR:$Rd, imm256_65535_expr:$imm, pred:$p), 0>,
2057 Requires<[IsThumb, HasV8MBaseline]>, Sched<[WriteALU]>;
2059 def t2MOVi16_ga_pcrel : PseudoInst<(outs rGPR:$Rd),
2060 (ins i32imm:$addr, pclabel:$id), IIC_iMOVi, []>,
2063 let Constraints = "$src = $Rd" in {
2064 def t2MOVTi16 : T2I<(outs rGPR:$Rd),
2065 (ins rGPR:$src, imm0_65535_expr:$imm), IIC_iMOVi,
2066 "movt", "\t$Rd, $imm",
2068 (or (and rGPR:$src, 0xffff), lo16AllZero:$imm))]>,
2070 Requires<[IsThumb, HasV8MBaseline]> {
2071 let Inst{31-27} = 0b11110;
2073 let Inst{24-21} = 0b0110;
2074 let Inst{20} = 0; // The S bit.
2080 let Inst{11-8} = Rd;
2081 let Inst{19-16} = imm{15-12};
2082 let Inst{26} = imm{11};
2083 let Inst{14-12} = imm{10-8};
2084 let Inst{7-0} = imm{7-0};
2085 let DecoderMethod = "DecodeT2MOVTWInstruction";
2088 def t2MOVTi16_ga_pcrel : PseudoInst<(outs rGPR:$Rd),
2089 (ins rGPR:$src, i32imm:$addr, pclabel:$id), IIC_iMOVi, []>,
2090 Sched<[WriteALU]>, Requires<[IsThumb, HasV8MBaseline]>;
2093 def : T2Pat<(or rGPR:$src, 0xffff0000), (t2MOVTi16 rGPR:$src, 0xffff)>;
2095 //===----------------------------------------------------------------------===//
2096 // Extend Instructions.
2101 def t2SXTB : T2I_ext_rrot<0b100, "sxtb">;
2102 def t2SXTH : T2I_ext_rrot<0b000, "sxth">;
2103 def t2SXTB16 : T2I_ext_rrot_xtb16<0b010, "sxtb16">;
2105 def t2SXTAB : T2I_exta_rrot<0b100, "sxtab">;
2106 def t2SXTAH : T2I_exta_rrot<0b000, "sxtah">;
2107 def t2SXTAB16 : T2I_exta_rrot<0b010, "sxtab16">;
2109 def : T2Pat<(sext_inreg (rotr rGPR:$Rn, rot_imm:$rot), i8),
2110 (t2SXTB rGPR:$Rn, rot_imm:$rot)>;
2111 def : T2Pat<(sext_inreg (rotr rGPR:$Rn, rot_imm:$rot), i16),
2112 (t2SXTH rGPR:$Rn, rot_imm:$rot)>;
2113 def : Thumb2DSPPat<(add rGPR:$Rn,
2114 (sext_inreg (rotr rGPR:$Rm, rot_imm:$rot), i8)),
2115 (t2SXTAB rGPR:$Rn, rGPR:$Rm, rot_imm:$rot)>;
2116 def : Thumb2DSPPat<(add rGPR:$Rn,
2117 (sext_inreg (rotr rGPR:$Rm, rot_imm:$rot), i16)),
2118 (t2SXTAH rGPR:$Rn, rGPR:$Rm, rot_imm:$rot)>;
2119 def : Thumb2DSPPat<(int_arm_sxtb16 rGPR:$Rn),
2120 (t2SXTB16 rGPR:$Rn, 0)>;
2121 def : Thumb2DSPPat<(int_arm_sxtab16 rGPR:$Rn, rGPR:$Rm),
2122 (t2SXTAB16 rGPR:$Rn, rGPR:$Rm, 0)>;
2123 def : Thumb2DSPPat<(int_arm_sxtb16 (rotr rGPR:$Rn, rot_imm:$rot)),
2124 (t2SXTB16 rGPR:$Rn, rot_imm:$rot)>;
2125 def : Thumb2DSPPat<(int_arm_sxtab16 rGPR:$Rn, (rotr rGPR:$Rm, rot_imm:$rot)),
2126 (t2SXTAB16 rGPR:$Rn, rGPR:$Rm, rot_imm:$rot)>;
2129 // A simple right-shift can also be used in most cases (the exception is the
2130 // SXTH operations with a rotate of 24: there the non-contiguous bits are
2132 def : Thumb2DSPPat<(add rGPR:$Rn, (sext_inreg
2133 (srl rGPR:$Rm, rot_imm:$rot), i8)),
2134 (t2SXTAB rGPR:$Rn, rGPR:$Rm, rot_imm:$rot)>;
2135 def : Thumb2DSPPat<(add rGPR:$Rn, (sext_inreg
2136 (srl rGPR:$Rm, imm8_or_16:$rot), i16)),
2137 (t2SXTAH rGPR:$Rn, rGPR:$Rm, rot_imm:$rot)>;
2138 def : Thumb2DSPPat<(add rGPR:$Rn, (sext_inreg
2139 (rotr rGPR:$Rm, (i32 24)), i16)),
2140 (t2SXTAH rGPR:$Rn, rGPR:$Rm, (i32 3))>;
2141 def : Thumb2DSPPat<(add rGPR:$Rn, (sext_inreg
2142 (or (srl rGPR:$Rm, (i32 24)),
2143 (shl rGPR:$Rm, (i32 8))), i16)),
2144 (t2SXTAH rGPR:$Rn, rGPR:$Rm, (i32 3))>;
2148 let AddedComplexity = 16 in {
2149 def t2UXTB : T2I_ext_rrot<0b101, "uxtb">;
2150 def t2UXTH : T2I_ext_rrot<0b001, "uxth">;
2151 def t2UXTB16 : T2I_ext_rrot_xtb16<0b011, "uxtb16">;
2153 def : Thumb2DSPPat<(and (rotr rGPR:$Rm, rot_imm:$rot), 0x000000FF),
2154 (t2UXTB rGPR:$Rm, rot_imm:$rot)>;
2155 def : Thumb2DSPPat<(and (rotr rGPR:$Rm, rot_imm:$rot), 0x0000FFFF),
2156 (t2UXTH rGPR:$Rm, rot_imm:$rot)>;
2157 def : Thumb2DSPPat<(and (rotr rGPR:$Rm, rot_imm:$rot), 0x00FF00FF),
2158 (t2UXTB16 rGPR:$Rm, rot_imm:$rot)>;
2160 def : Thumb2DSPPat<(int_arm_uxtb16 rGPR:$Rm),
2161 (t2UXTB16 rGPR:$Rm, 0)>;
2162 def : Thumb2DSPPat<(int_arm_uxtb16 (rotr rGPR:$Rn, rot_imm:$rot)),
2163 (t2UXTB16 rGPR:$Rn, rot_imm:$rot)>;
2165 // FIXME: This pattern incorrectly assumes the shl operator is a rotate.
2166 // The transformation should probably be done as a combiner action
2167 // instead so we can include a check for masking back in the upper
2168 // eight bits of the source into the lower eight bits of the result.
2169 //def : T2Pat<(and (shl rGPR:$Src, (i32 8)), 0xFF00FF),
2170 // (t2UXTB16 rGPR:$Src, 3)>,
2171 // Requires<[HasDSP, IsThumb2]>;
2172 def : T2Pat<(and (srl rGPR:$Src, (i32 8)), 0xFF00FF),
2173 (t2UXTB16 rGPR:$Src, 1)>,
2174 Requires<[HasDSP, IsThumb2]>;
2176 def t2UXTAB : T2I_exta_rrot<0b101, "uxtab">;
2177 def t2UXTAH : T2I_exta_rrot<0b001, "uxtah">;
2178 def t2UXTAB16 : T2I_exta_rrot<0b011, "uxtab16">;
2180 def : Thumb2DSPPat<(add rGPR:$Rn, (and (rotr rGPR:$Rm, rot_imm:$rot),
2182 (t2UXTAB rGPR:$Rn, rGPR:$Rm, rot_imm:$rot)>;
2183 def : Thumb2DSPPat<(add rGPR:$Rn, (and (rotr rGPR:$Rm, rot_imm:$rot),
2185 (t2UXTAH rGPR:$Rn, rGPR:$Rm, rot_imm:$rot)>;
2186 def : Thumb2DSPPat<(add rGPR:$Rn, (and (srl rGPR:$Rm, rot_imm:$rot),
2188 (t2UXTAB rGPR:$Rn, rGPR:$Rm, rot_imm:$rot)>;
2189 def : Thumb2DSPPat<(add rGPR:$Rn, (and (srl rGPR:$Rm, imm8_or_16:$rot),
2191 (t2UXTAH rGPR:$Rn, rGPR:$Rm, rot_imm:$rot)>;
2192 def : Thumb2DSPPat<(int_arm_uxtab16 rGPR:$Rn, rGPR:$Rm),
2193 (t2UXTAB16 rGPR:$Rn, rGPR:$Rm, 0)>;
2194 def : Thumb2DSPPat<(int_arm_uxtab16 rGPR:$Rn, (rotr rGPR:$Rm, rot_imm:$rot)),
2195 (t2UXTAB16 rGPR:$Rn, rGPR:$Rm, rot_imm:$rot)>;
2199 //===----------------------------------------------------------------------===//
2200 // Arithmetic Instructions.
2204 defm t2ADD : T2I_bin_ii12rs<0b000, "add", add, 1>;
2205 defm t2SUB : T2I_bin_ii12rs<0b101, "sub", sub>;
2207 // ADD and SUB with 's' bit set. No 12-bit immediate (T4) variants.
2209 // Currently, t2ADDS/t2SUBS are pseudo opcodes that exist only in the
2210 // selection DAG. They are "lowered" to real t2ADD/t2SUB opcodes by
2211 // AdjustInstrPostInstrSelection where we determine whether or not to
2212 // set the "s" bit based on CPSR liveness.
2214 // FIXME: Eliminate t2ADDS/t2SUBS pseudo opcodes after adding tablegen
2215 // support for an optional CPSR definition that corresponds to the DAG
2216 // node's second value. We can then eliminate the implicit def of CPSR.
2217 defm t2ADDS : T2I_bin_s_irs <IIC_iALUi, IIC_iALUr, IIC_iALUsi, ARMaddc, 1>;
2218 defm t2SUBS : T2I_bin_s_irs <IIC_iALUi, IIC_iALUr, IIC_iALUsi, ARMsubc>;
2220 def : T2Pat<(ARMsubs GPRnopc:$Rn, t2_so_imm:$imm),
2221 (t2SUBSri $Rn, t2_so_imm:$imm)>;
2222 def : T2Pat<(ARMsubs GPRnopc:$Rn, rGPR:$Rm), (t2SUBSrr $Rn, $Rm)>;
2223 def : T2Pat<(ARMsubs GPRnopc:$Rn, t2_so_reg:$ShiftedRm),
2224 (t2SUBSrs $Rn, t2_so_reg:$ShiftedRm)>;
2226 let hasPostISelHook = 1 in {
2227 defm t2ADC : T2I_adde_sube_irs<0b1010, "adc", ARMadde, 1>;
2228 defm t2SBC : T2I_adde_sube_irs<0b1011, "sbc", ARMsube>;
2231 def : t2InstSubst<"adc${s}${p} $rd, $rn, $imm",
2232 (t2SBCri rGPR:$rd, rGPR:$rn, t2_so_imm_not:$imm, pred:$p, s_cc_out:$s)>;
2233 def : t2InstSubst<"sbc${s}${p} $rd, $rn, $imm",
2234 (t2ADCri rGPR:$rd, rGPR:$rn, t2_so_imm_not:$imm, pred:$p, s_cc_out:$s)>;
2236 def : t2InstSubst<"add${s}${p}.w $rd, $rn, $imm",
2237 (t2SUBri GPRnopc:$rd, GPRnopc:$rn, t2_so_imm_neg:$imm, pred:$p, s_cc_out:$s)>;
2238 def : t2InstSubst<"addw${p} $rd, $rn, $imm",
2239 (t2SUBri12 GPRnopc:$rd, GPR:$rn, t2_so_imm_neg:$imm, pred:$p)>;
2240 def : t2InstSubst<"sub${s}${p}.w $rd, $rn, $imm",
2241 (t2ADDri GPRnopc:$rd, GPRnopc:$rn, t2_so_imm_neg:$imm, pred:$p, s_cc_out:$s)>;
2242 def : t2InstSubst<"subw${p} $rd, $rn, $imm",
2243 (t2ADDri12 GPRnopc:$rd, GPR:$rn, t2_so_imm_neg:$imm, pred:$p)>;
2244 def : t2InstSubst<"subw${p} $Rd, $Rn, $imm",
2245 (t2ADDri12 GPRnopc:$Rd, GPR:$Rn, imm0_4095_neg:$imm, pred:$p)>;
2246 def : t2InstSubst<"sub${s}${p} $rd, $rn, $imm",
2247 (t2ADDri GPRnopc:$rd, GPRnopc:$rn, t2_so_imm_neg:$imm, pred:$p, s_cc_out:$s)>;
2248 def : t2InstSubst<"sub${p} $rd, $rn, $imm",
2249 (t2ADDri12 GPRnopc:$rd, GPR:$rn, t2_so_imm_neg:$imm, pred:$p)>;
2251 defm t2RSB : T2I_rbin_irs <0b1110, "rsb", sub>;
2253 // FIXME: Eliminate them if we can write def : Pat patterns which defines
2254 // CPSR and the implicit def of CPSR is not needed.
2255 defm t2RSBS : T2I_rbin_s_is <ARMsubc>;
2257 // (sub X, imm) gets canonicalized to (add X, -imm). Match this form.
2258 // The assume-no-carry-in form uses the negation of the input since add/sub
2259 // assume opposite meanings of the carry flag (i.e., carry == !borrow).
2260 // See the definition of AddWithCarry() in the ARM ARM A2.2.1 for the gory
2262 // The AddedComplexity preferences the first variant over the others since
2263 // it can be shrunk to a 16-bit wide encoding, while the others cannot.
2264 let AddedComplexity = 1 in
2265 def : T2Pat<(add GPR:$src, imm1_255_neg:$imm),
2266 (t2SUBri GPR:$src, imm1_255_neg:$imm)>;
2267 def : T2Pat<(add GPR:$src, t2_so_imm_neg:$imm),
2268 (t2SUBri GPR:$src, t2_so_imm_neg:$imm)>;
2269 def : T2Pat<(add GPR:$src, imm0_4095_neg:$imm),
2270 (t2SUBri12 GPR:$src, imm0_4095_neg:$imm)>;
2271 def : T2Pat<(add GPR:$src, imm0_65535_neg:$imm),
2272 (t2SUBrr GPR:$src, (t2MOVi16 (imm_neg_XFORM imm:$imm)))>;
2274 // Do the same for v8m targets since they support movw with a 16-bit value.
2275 def : T1Pat<(add tGPR:$src, imm0_65535_neg:$imm),
2276 (tSUBrr tGPR:$src, (t2MOVi16 (imm_neg_XFORM imm:$imm)))>,
2277 Requires<[HasV8MBaseline]>;
2279 let AddedComplexity = 1 in
2280 def : T2Pat<(ARMaddc rGPR:$src, imm1_255_neg:$imm),
2281 (t2SUBSri rGPR:$src, imm1_255_neg:$imm)>;
2282 def : T2Pat<(ARMaddc rGPR:$src, t2_so_imm_neg:$imm),
2283 (t2SUBSri rGPR:$src, t2_so_imm_neg:$imm)>;
2284 def : T2Pat<(ARMaddc rGPR:$src, imm0_65535_neg:$imm),
2285 (t2SUBSrr rGPR:$src, (t2MOVi16 (imm_neg_XFORM imm:$imm)))>;
2286 // The with-carry-in form matches bitwise not instead of the negation.
2287 // Effectively, the inverse interpretation of the carry flag already accounts
2288 // for part of the negation.
2289 let AddedComplexity = 1 in
2290 def : T2Pat<(ARMadde rGPR:$src, imm0_255_not:$imm, CPSR),
2291 (t2SBCri rGPR:$src, imm0_255_not:$imm)>;
2292 def : T2Pat<(ARMadde rGPR:$src, t2_so_imm_not:$imm, CPSR),
2293 (t2SBCri rGPR:$src, t2_so_imm_not:$imm)>;
2294 def : T2Pat<(ARMadde rGPR:$src, imm0_65535_neg:$imm, CPSR),
2295 (t2SBCrr rGPR:$src, (t2MOVi16 (imm_not_XFORM imm:$imm)))>;
2297 def t2SEL : T2ThreeReg<(outs GPR:$Rd), (ins GPR:$Rn, GPR:$Rm),
2298 NoItinerary, "sel", "\t$Rd, $Rn, $Rm",
2299 [(set GPR:$Rd, (int_arm_sel GPR:$Rn, GPR:$Rm))]>,
2300 Requires<[IsThumb2, HasDSP]> {
2301 let Inst{31-27} = 0b11111;
2302 let Inst{26-24} = 0b010;
2304 let Inst{22-20} = 0b010;
2305 let Inst{15-12} = 0b1111;
2307 let Inst{6-4} = 0b000;
2310 // A6.3.13, A6.3.14, A6.3.15 Parallel addition and subtraction (signed/unsigned)
2311 // And Miscellaneous operations -- for disassembly only
2312 class T2I_pam<bits<3> op22_20, bits<4> op7_4, string opc,
2313 list<dag> pat, dag iops, string asm>
2314 : T2I<(outs rGPR:$Rd), iops, NoItinerary, opc, asm, pat>,
2315 Requires<[IsThumb2, HasDSP]> {
2316 let Inst{31-27} = 0b11111;
2317 let Inst{26-23} = 0b0101;
2318 let Inst{22-20} = op22_20;
2319 let Inst{15-12} = 0b1111;
2320 let Inst{7-4} = op7_4;
2326 let Inst{11-8} = Rd;
2327 let Inst{19-16} = Rn;
2331 class T2I_pam_intrinsics<bits<3> op22_20, bits<4> op7_4, string opc,
2332 Intrinsic intrinsic>
2333 : T2I_pam<op22_20, op7_4, opc,
2334 [(set rGPR:$Rd, (intrinsic rGPR:$Rn, rGPR:$Rm))],
2335 (ins rGPR:$Rn, rGPR:$Rm), "\t$Rd, $Rn, $Rm">;
2337 class T2I_pam_intrinsics_rev<bits<3> op22_20, bits<4> op7_4, string opc>
2338 : T2I_pam<op22_20, op7_4, opc, [],
2339 (ins rGPR:$Rm, rGPR:$Rn), "\t$Rd, $Rm, $Rn">;
2341 // Saturating add/subtract
2342 def t2QADD16 : T2I_pam_intrinsics<0b001, 0b0001, "qadd16", int_arm_qadd16>;
2343 def t2QADD8 : T2I_pam_intrinsics<0b000, 0b0001, "qadd8", int_arm_qadd8>;
2344 def t2QASX : T2I_pam_intrinsics<0b010, 0b0001, "qasx", int_arm_qasx>;
2345 def t2UQSUB8 : T2I_pam_intrinsics<0b100, 0b0101, "uqsub8", int_arm_uqsub8>;
2346 def t2QSAX : T2I_pam_intrinsics<0b110, 0b0001, "qsax", int_arm_qsax>;
2347 def t2QSUB16 : T2I_pam_intrinsics<0b101, 0b0001, "qsub16", int_arm_qsub16>;
2348 def t2QSUB8 : T2I_pam_intrinsics<0b100, 0b0001, "qsub8", int_arm_qsub8>;
2349 def t2UQADD16 : T2I_pam_intrinsics<0b001, 0b0101, "uqadd16", int_arm_uqadd16>;
2350 def t2UQADD8 : T2I_pam_intrinsics<0b000, 0b0101, "uqadd8", int_arm_uqadd8>;
2351 def t2UQASX : T2I_pam_intrinsics<0b010, 0b0101, "uqasx", int_arm_uqasx>;
2352 def t2UQSAX : T2I_pam_intrinsics<0b110, 0b0101, "uqsax", int_arm_uqsax>;
2353 def t2UQSUB16 : T2I_pam_intrinsics<0b101, 0b0101, "uqsub16", int_arm_uqsub16>;
2354 def t2QADD : T2I_pam_intrinsics_rev<0b000, 0b1000, "qadd">;
2355 def t2QSUB : T2I_pam_intrinsics_rev<0b000, 0b1010, "qsub">;
2356 def t2QDADD : T2I_pam_intrinsics_rev<0b000, 0b1001, "qdadd">;
2357 def t2QDSUB : T2I_pam_intrinsics_rev<0b000, 0b1011, "qdsub">;
2359 def : Thumb2DSPPat<(int_arm_qadd rGPR:$Rm, rGPR:$Rn),
2360 (t2QADD rGPR:$Rm, rGPR:$Rn)>;
2361 def : Thumb2DSPPat<(int_arm_qsub rGPR:$Rm, rGPR:$Rn),
2362 (t2QSUB rGPR:$Rm, rGPR:$Rn)>;
2363 def : Thumb2DSPPat<(int_arm_qadd(int_arm_qadd rGPR:$Rm, rGPR:$Rm), rGPR:$Rn),
2364 (t2QDADD rGPR:$Rm, rGPR:$Rn)>;
2365 def : Thumb2DSPPat<(int_arm_qsub rGPR:$Rm, (int_arm_qadd rGPR:$Rn, rGPR:$Rn)),
2366 (t2QDSUB rGPR:$Rm, rGPR:$Rn)>;
2368 // Signed/Unsigned add/subtract
2370 def t2SASX : T2I_pam_intrinsics<0b010, 0b0000, "sasx", int_arm_sasx>;
2371 def t2SADD16 : T2I_pam_intrinsics<0b001, 0b0000, "sadd16", int_arm_sadd16>;
2372 def t2SADD8 : T2I_pam_intrinsics<0b000, 0b0000, "sadd8", int_arm_sadd8>;
2373 def t2SSAX : T2I_pam_intrinsics<0b110, 0b0000, "ssax", int_arm_ssax>;
2374 def t2SSUB16 : T2I_pam_intrinsics<0b101, 0b0000, "ssub16", int_arm_ssub16>;
2375 def t2SSUB8 : T2I_pam_intrinsics<0b100, 0b0000, "ssub8", int_arm_ssub8>;
2376 def t2UASX : T2I_pam_intrinsics<0b010, 0b0100, "uasx", int_arm_uasx>;
2377 def t2UADD16 : T2I_pam_intrinsics<0b001, 0b0100, "uadd16", int_arm_uadd16>;
2378 def t2UADD8 : T2I_pam_intrinsics<0b000, 0b0100, "uadd8", int_arm_uadd8>;
2379 def t2USAX : T2I_pam_intrinsics<0b110, 0b0100, "usax", int_arm_usax>;
2380 def t2USUB16 : T2I_pam_intrinsics<0b101, 0b0100, "usub16", int_arm_usub16>;
2381 def t2USUB8 : T2I_pam_intrinsics<0b100, 0b0100, "usub8", int_arm_usub8>;
2383 // Signed/Unsigned halving add/subtract
2385 def t2SHASX : T2I_pam_intrinsics<0b010, 0b0010, "shasx", int_arm_shasx>;
2386 def t2SHADD16 : T2I_pam_intrinsics<0b001, 0b0010, "shadd16", int_arm_shadd16>;
2387 def t2SHADD8 : T2I_pam_intrinsics<0b000, 0b0010, "shadd8", int_arm_shadd8>;
2388 def t2SHSAX : T2I_pam_intrinsics<0b110, 0b0010, "shsax", int_arm_shsax>;
2389 def t2SHSUB16 : T2I_pam_intrinsics<0b101, 0b0010, "shsub16", int_arm_shsub16>;
2390 def t2SHSUB8 : T2I_pam_intrinsics<0b100, 0b0010, "shsub8", int_arm_shsub8>;
2391 def t2UHASX : T2I_pam_intrinsics<0b010, 0b0110, "uhasx", int_arm_uhasx>;
2392 def t2UHADD16 : T2I_pam_intrinsics<0b001, 0b0110, "uhadd16", int_arm_uhadd16>;
2393 def t2UHADD8 : T2I_pam_intrinsics<0b000, 0b0110, "uhadd8", int_arm_uhadd8>;
2394 def t2UHSAX : T2I_pam_intrinsics<0b110, 0b0110, "uhsax", int_arm_uhsax>;
2395 def t2UHSUB16 : T2I_pam_intrinsics<0b101, 0b0110, "uhsub16", int_arm_uhsub16>;
2396 def t2UHSUB8 : T2I_pam_intrinsics<0b100, 0b0110, "uhsub8", int_arm_uhsub8>;
2398 // Helper class for disassembly only
2399 // A6.3.16 & A6.3.17
2400 // T2Imac - Thumb2 multiply [accumulate, and absolute difference] instructions.
2401 class T2ThreeReg_mac<bit long, bits<3> op22_20, bits<4> op7_4, dag oops,
2402 dag iops, InstrItinClass itin, string opc, string asm, list<dag> pattern>
2403 : T2ThreeReg<oops, iops, itin, opc, asm, pattern> {
2404 let Inst{31-27} = 0b11111;
2405 let Inst{26-24} = 0b011;
2406 let Inst{23} = long;
2407 let Inst{22-20} = op22_20;
2408 let Inst{7-4} = op7_4;
2411 class T2FourReg_mac<bit long, bits<3> op22_20, bits<4> op7_4, dag oops,
2412 dag iops, InstrItinClass itin, string opc, string asm, list<dag> pattern>
2413 : T2FourReg<oops, iops, itin, opc, asm, pattern> {
2414 let Inst{31-27} = 0b11111;
2415 let Inst{26-24} = 0b011;
2416 let Inst{23} = long;
2417 let Inst{22-20} = op22_20;
2418 let Inst{7-4} = op7_4;
2421 // Unsigned Sum of Absolute Differences [and Accumulate].
2422 def t2USAD8 : T2ThreeReg_mac<0, 0b111, 0b0000, (outs rGPR:$Rd),
2423 (ins rGPR:$Rn, rGPR:$Rm),
2424 NoItinerary, "usad8", "\t$Rd, $Rn, $Rm",
2425 [(set rGPR:$Rd, (int_arm_usad8 rGPR:$Rn, rGPR:$Rm))]>,
2426 Requires<[IsThumb2, HasDSP]> {
2427 let Inst{15-12} = 0b1111;
2429 def t2USADA8 : T2FourReg_mac<0, 0b111, 0b0000, (outs rGPR:$Rd),
2430 (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), NoItinerary,
2431 "usada8", "\t$Rd, $Rn, $Rm, $Ra",
2432 [(set rGPR:$Rd, (int_arm_usada8 rGPR:$Rn, rGPR:$Rm, rGPR:$Ra))]>,
2433 Requires<[IsThumb2, HasDSP]>;
2435 // Signed/Unsigned saturate.
2436 let hasSideEffects = 1 in
2437 class T2SatI<dag iops, string opc, string asm>
2438 : T2I<(outs rGPR:$Rd), iops, NoItinerary, opc, asm, []> {
2444 let Inst{31-24} = 0b11110011;
2445 let Inst{21} = sh{5};
2447 let Inst{19-16} = Rn;
2449 let Inst{14-12} = sh{4-2};
2450 let Inst{11-8} = Rd;
2451 let Inst{7-6} = sh{1-0};
2453 let Inst{4-0} = sat_imm;
2456 def t2SSAT: T2SatI<(ins imm1_32:$sat_imm, rGPR:$Rn, t2_shift_imm:$sh),
2457 "ssat", "\t$Rd, $sat_imm, $Rn$sh">,
2458 Requires<[IsThumb2]>, Sched<[WriteALU]> {
2459 let Inst{23-22} = 0b00;
2463 def t2SSAT16: T2SatI<(ins imm1_16:$sat_imm, rGPR:$Rn),
2464 "ssat16", "\t$Rd, $sat_imm, $Rn">,
2465 Requires<[IsThumb2, HasDSP]>, Sched<[WriteALU]> {
2466 let Inst{23-22} = 0b00;
2471 def t2USAT: T2SatI<(ins imm0_31:$sat_imm, rGPR:$Rn, t2_shift_imm:$sh),
2472 "usat", "\t$Rd, $sat_imm, $Rn$sh">,
2473 Requires<[IsThumb2]>, Sched<[WriteALU]> {
2474 let Inst{23-22} = 0b10;
2477 def t2USAT16: T2SatI<(ins imm0_15:$sat_imm, rGPR:$Rn),
2478 "usat16", "\t$Rd, $sat_imm, $Rn">,
2479 Requires<[IsThumb2, HasDSP]>, Sched<[WriteALU]> {
2480 let Inst{23-22} = 0b10;
2485 def : T2Pat<(ARMssatnoshift GPRnopc:$Rn, imm0_31:$imm),
2486 (t2SSAT imm0_31:$imm, GPRnopc:$Rn, 0)>;
2487 def : T2Pat<(ARMusatnoshift GPRnopc:$Rn, imm0_31:$imm),
2488 (t2USAT imm0_31:$imm, GPRnopc:$Rn, 0)>;
2489 def : T2Pat<(int_arm_ssat GPR:$a, imm1_32:$pos),
2490 (t2SSAT imm1_32:$pos, GPR:$a, 0)>;
2491 def : T2Pat<(int_arm_usat GPR:$a, imm0_31:$pos),
2492 (t2USAT imm0_31:$pos, GPR:$a, 0)>;
2493 def : T2Pat<(int_arm_ssat16 GPR:$a, imm1_16:$pos),
2494 (t2SSAT16 imm1_16:$pos, GPR:$a)>;
2495 def : T2Pat<(int_arm_usat16 GPR:$a, imm0_15:$pos),
2496 (t2USAT16 imm0_15:$pos, GPR:$a)>;
2498 //===----------------------------------------------------------------------===//
2499 // Shift and rotate Instructions.
2502 defm t2LSL : T2I_sh_ir<0b00, "lsl", imm1_31, shl>;
2503 defm t2LSR : T2I_sh_ir<0b01, "lsr", imm_sr, srl>;
2504 defm t2ASR : T2I_sh_ir<0b10, "asr", imm_sr, sra>;
2505 defm t2ROR : T2I_sh_ir<0b11, "ror", imm0_31, rotr>;
2507 // LSL #0 is actually MOV, and has slightly different permitted registers to
2508 // LSL with non-zero shift
2509 def : t2InstAlias<"lsl${s}${p} $Rd, $Rm, #0",
2510 (t2MOVr GPRnopc:$Rd, GPRnopc:$Rm, pred:$p, cc_out:$s)>;
2511 def : t2InstAlias<"lsl${s}${p}.w $Rd, $Rm, #0",
2512 (t2MOVr GPRnopc:$Rd, GPRnopc:$Rm, pred:$p, cc_out:$s)>;
2514 // (rotr x, (and y, 0x...1f)) ==> (ROR x, y)
2515 def : T2Pat<(rotr rGPR:$lhs, (and rGPR:$rhs, lo5AllOne)),
2516 (t2RORrr rGPR:$lhs, rGPR:$rhs)>;
2518 let Uses = [CPSR] in {
2519 def t2RRX : T2sTwoReg<(outs rGPR:$Rd), (ins rGPR:$Rm), IIC_iMOVsi,
2520 "rrx", "\t$Rd, $Rm",
2521 [(set rGPR:$Rd, (ARMrrx rGPR:$Rm))]>, Sched<[WriteALU]> {
2522 let Inst{31-27} = 0b11101;
2523 let Inst{26-25} = 0b01;
2524 let Inst{24-21} = 0b0010;
2525 let Inst{19-16} = 0b1111; // Rn
2527 let Unpredictable{15} = 0b1;
2528 let Inst{14-12} = 0b000;
2529 let Inst{7-4} = 0b0011;
2533 let isCodeGenOnly = 1, Defs = [CPSR] in {
2534 def t2MOVsrl_flag : T2TwoRegShiftImm<
2535 (outs rGPR:$Rd), (ins rGPR:$Rm), IIC_iMOVsi,
2536 "lsrs", ".w\t$Rd, $Rm, #1",
2537 [(set rGPR:$Rd, (ARMsrl_flag rGPR:$Rm))]>,
2539 let Inst{31-27} = 0b11101;
2540 let Inst{26-25} = 0b01;
2541 let Inst{24-21} = 0b0010;
2542 let Inst{20} = 1; // The S bit.
2543 let Inst{19-16} = 0b1111; // Rn
2544 let Inst{5-4} = 0b01; // Shift type.
2545 // Shift amount = Inst{14-12:7-6} = 1.
2546 let Inst{14-12} = 0b000;
2547 let Inst{7-6} = 0b01;
2549 def t2MOVsra_flag : T2TwoRegShiftImm<
2550 (outs rGPR:$Rd), (ins rGPR:$Rm), IIC_iMOVsi,
2551 "asrs", ".w\t$Rd, $Rm, #1",
2552 [(set rGPR:$Rd, (ARMsra_flag rGPR:$Rm))]>,
2554 let Inst{31-27} = 0b11101;
2555 let Inst{26-25} = 0b01;
2556 let Inst{24-21} = 0b0010;
2557 let Inst{20} = 1; // The S bit.
2558 let Inst{19-16} = 0b1111; // Rn
2559 let Inst{5-4} = 0b10; // Shift type.
2560 // Shift amount = Inst{14-12:7-6} = 1.
2561 let Inst{14-12} = 0b000;
2562 let Inst{7-6} = 0b01;
2566 //===----------------------------------------------------------------------===//
2567 // Bitwise Instructions.
2570 defm t2AND : T2I_bin_w_irs<0b0000, "and",
2571 IIC_iBITi, IIC_iBITr, IIC_iBITsi, and, 1>;
2572 defm t2ORR : T2I_bin_w_irs<0b0010, "orr",
2573 IIC_iBITi, IIC_iBITr, IIC_iBITsi, or, 1>;
2574 defm t2EOR : T2I_bin_w_irs<0b0100, "eor",
2575 IIC_iBITi, IIC_iBITr, IIC_iBITsi, xor, 1>;
2577 defm t2BIC : T2I_bin_w_irs<0b0001, "bic",
2578 IIC_iBITi, IIC_iBITr, IIC_iBITsi,
2579 BinOpFrag<(and node:$LHS, (not node:$RHS))>>;
2581 class T2BitFI<dag oops, dag iops, InstrItinClass itin,
2582 string opc, string asm, list<dag> pattern>
2583 : T2I<oops, iops, itin, opc, asm, pattern> {
2588 let Inst{11-8} = Rd;
2589 let Inst{4-0} = msb{4-0};
2590 let Inst{14-12} = lsb{4-2};
2591 let Inst{7-6} = lsb{1-0};
2594 class T2TwoRegBitFI<dag oops, dag iops, InstrItinClass itin,
2595 string opc, string asm, list<dag> pattern>
2596 : T2BitFI<oops, iops, itin, opc, asm, pattern> {
2599 let Inst{19-16} = Rn;
2602 let Constraints = "$src = $Rd" in
2603 def t2BFC : T2BitFI<(outs rGPR:$Rd), (ins rGPR:$src, bf_inv_mask_imm:$imm),
2604 IIC_iUNAsi, "bfc", "\t$Rd, $imm",
2605 [(set rGPR:$Rd, (and rGPR:$src, bf_inv_mask_imm:$imm))]>, Sched<[WriteALU]> {
2606 let Inst{31-27} = 0b11110;
2607 let Inst{26} = 0; // should be 0.
2609 let Inst{24-20} = 0b10110;
2610 let Inst{19-16} = 0b1111; // Rn
2612 let Inst{5} = 0; // should be 0.
2615 let msb{4-0} = imm{9-5};
2616 let lsb{4-0} = imm{4-0};
2619 def t2SBFX: T2TwoRegBitFI<
2620 (outs rGPR:$Rd), (ins rGPR:$Rn, imm0_31:$lsb, imm1_32:$msb),
2621 IIC_iUNAsi, "sbfx", "\t$Rd, $Rn, $lsb, $msb", []>, Sched<[WriteALU]> {
2622 let Inst{31-27} = 0b11110;
2624 let Inst{24-20} = 0b10100;
2628 def t2UBFX: T2TwoRegBitFI<
2629 (outs rGPR:$Rd), (ins rGPR:$Rn, imm0_31:$lsb, imm1_32:$msb),
2630 IIC_iUNAsi, "ubfx", "\t$Rd, $Rn, $lsb, $msb", []>, Sched<[WriteALU]> {
2631 let Inst{31-27} = 0b11110;
2633 let Inst{24-20} = 0b11100;
2637 // A8.8.247 UDF - Undefined (Encoding T2)
2638 def t2UDF : T2XI<(outs), (ins imm0_65535:$imm16), IIC_Br, "udf.w\t$imm16",
2639 [(int_arm_undefined imm0_65535:$imm16)]> {
2641 let Inst{31-29} = 0b111;
2642 let Inst{28-27} = 0b10;
2643 let Inst{26-20} = 0b1111111;
2644 let Inst{19-16} = imm16{15-12};
2646 let Inst{14-12} = 0b010;
2647 let Inst{11-0} = imm16{11-0};
2650 // A8.6.18 BFI - Bitfield insert (Encoding T1)
2651 let Constraints = "$src = $Rd" in {
2652 def t2BFI : T2TwoRegBitFI<(outs rGPR:$Rd),
2653 (ins rGPR:$src, rGPR:$Rn, bf_inv_mask_imm:$imm),
2654 IIC_iBITi, "bfi", "\t$Rd, $Rn, $imm",
2655 [(set rGPR:$Rd, (ARMbfi rGPR:$src, rGPR:$Rn,
2656 bf_inv_mask_imm:$imm))]>, Sched<[WriteALU]> {
2657 let Inst{31-27} = 0b11110;
2658 let Inst{26} = 0; // should be 0.
2660 let Inst{24-20} = 0b10110;
2662 let Inst{5} = 0; // should be 0.
2665 let msb{4-0} = imm{9-5};
2666 let lsb{4-0} = imm{4-0};
2670 defm t2ORN : T2I_bin_irs<0b0011, "orn",
2671 IIC_iBITi, IIC_iBITr, IIC_iBITsi,
2672 BinOpFrag<(or node:$LHS, (not node:$RHS))>, 0, "">;
2674 /// T2I_un_irs - Defines a set of (op reg, {so_imm|r|so_reg}) patterns for a
2675 /// unary operation that produces a value. These are predicable and can be
2676 /// changed to modify CPSR.
2677 multiclass T2I_un_irs<bits<4> opcod, string opc,
2678 InstrItinClass iii, InstrItinClass iir, InstrItinClass iis,
2680 bit Cheap = 0, bit ReMat = 0, bit MoveImm = 0> {
2682 def i : T2sOneRegImm<(outs rGPR:$Rd), (ins t2_so_imm:$imm), iii,
2684 [(set rGPR:$Rd, (opnode t2_so_imm:$imm))]>, Sched<[WriteALU]> {
2685 let isAsCheapAsAMove = Cheap;
2686 let isReMaterializable = ReMat;
2687 let isMoveImm = MoveImm;
2688 let Inst{31-27} = 0b11110;
2690 let Inst{24-21} = opcod;
2691 let Inst{19-16} = 0b1111; // Rn
2695 def r : T2sTwoReg<(outs rGPR:$Rd), (ins rGPR:$Rm), iir,
2696 opc, ".w\t$Rd, $Rm",
2697 [(set rGPR:$Rd, (opnode rGPR:$Rm))]>, Sched<[WriteALU]> {
2698 let Inst{31-27} = 0b11101;
2699 let Inst{26-25} = 0b01;
2700 let Inst{24-21} = opcod;
2701 let Inst{19-16} = 0b1111; // Rn
2702 let Inst{14-12} = 0b000; // imm3
2703 let Inst{7-6} = 0b00; // imm2
2704 let Inst{5-4} = 0b00; // type
2707 def s : T2sOneRegShiftedReg<(outs rGPR:$Rd), (ins t2_so_reg:$ShiftedRm), iis,
2708 opc, ".w\t$Rd, $ShiftedRm",
2709 [(set rGPR:$Rd, (opnode t2_so_reg:$ShiftedRm))]>,
2711 let Inst{31-27} = 0b11101;
2712 let Inst{26-25} = 0b01;
2713 let Inst{24-21} = opcod;
2714 let Inst{19-16} = 0b1111; // Rn
2718 // Prefer over of t2EORri ra, rb, -1 because mvn has 16-bit version
2719 let AddedComplexity = 1 in
2720 defm t2MVN : T2I_un_irs <0b0011, "mvn",
2721 IIC_iMVNi, IIC_iMVNr, IIC_iMVNsi,
2724 let AddedComplexity = 1 in
2725 def : T2Pat<(and rGPR:$src, t2_so_imm_not:$imm),
2726 (t2BICri rGPR:$src, t2_so_imm_not:$imm)>;
2728 // top16Zero - answer true if the upper 16 bits of $src are 0, false otherwise
2729 def top16Zero: PatLeaf<(i32 rGPR:$src), [{
2730 return CurDAG->MaskedValueIsZero(SDValue(N,0), APInt::getHighBitsSet(32, 16));
2733 // so_imm_notSext is needed instead of so_imm_not, as the value of imm
2734 // will match the extended, not the original bitWidth for $src.
2735 def : T2Pat<(and top16Zero:$src, t2_so_imm_notSext:$imm),
2736 (t2BICri rGPR:$src, t2_so_imm_notSext:$imm)>;
2739 // FIXME: Disable this pattern on Darwin to workaround an assembler bug.
2740 def : T2Pat<(or rGPR:$src, t2_so_imm_not:$imm),
2741 (t2ORNri rGPR:$src, t2_so_imm_not:$imm)>,
2742 Requires<[IsThumb2]>;
2744 def : T2Pat<(t2_so_imm_not:$src),
2745 (t2MVNi t2_so_imm_not:$src)>;
2747 // There are shorter Thumb encodings for ADD than ORR, so to increase
2748 // Thumb2SizeReduction's chances later on we select a t2ADD for an or where
2750 def : T2Pat<(or AddLikeOrOp:$Rn, t2_so_imm:$imm),
2751 (t2ADDri $Rn, t2_so_imm:$imm)>;
2753 def : T2Pat<(or AddLikeOrOp:$Rn, imm0_4095:$Rm),
2754 (t2ADDri12 $Rn, imm0_4095:$Rm)>;
2756 def : T2Pat<(or AddLikeOrOp:$Rn, non_imm32:$Rm),
2757 (t2ADDrr $Rn, $Rm)>;
2759 //===----------------------------------------------------------------------===//
2760 // Multiply Instructions.
2762 let isCommutable = 1 in
2763 def t2MUL: T2ThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iMUL32,
2764 "mul", "\t$Rd, $Rn, $Rm",
2765 [(set rGPR:$Rd, (mul rGPR:$Rn, rGPR:$Rm))]>,
2766 Sched<[WriteMUL32, ReadMUL, ReadMUL]> {
2767 let Inst{31-27} = 0b11111;
2768 let Inst{26-23} = 0b0110;
2769 let Inst{22-20} = 0b000;
2770 let Inst{15-12} = 0b1111; // Ra = 0b1111 (no accumulate)
2771 let Inst{7-4} = 0b0000; // Multiply
2774 class T2FourRegMLA<bits<4> op7_4, string opc, list<dag> pattern>
2775 : T2FourReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC32,
2776 opc, "\t$Rd, $Rn, $Rm, $Ra", pattern>,
2777 Requires<[IsThumb2, UseMulOps]>,
2778 Sched<[WriteMAC32, ReadMUL, ReadMUL, ReadMAC]> {
2779 let Inst{31-27} = 0b11111;
2780 let Inst{26-23} = 0b0110;
2781 let Inst{22-20} = 0b000;
2782 let Inst{7-4} = op7_4;
2785 def t2MLA : T2FourRegMLA<0b0000, "mla",
2786 [(set rGPR:$Rd, (add (mul rGPR:$Rn, rGPR:$Rm),
2788 def t2MLS: T2FourRegMLA<0b0001, "mls",
2789 [(set rGPR:$Rd, (sub rGPR:$Ra, (mul rGPR:$Rn,
2792 // Extra precision multiplies with low / high results
2793 let hasSideEffects = 0 in {
2794 let isCommutable = 1 in {
2795 def t2SMULL : T2MulLong<0b000, 0b0000, "smull",
2796 [(set rGPR:$RdLo, rGPR:$RdHi,
2797 (smullohi rGPR:$Rn, rGPR:$Rm))]>;
2798 def t2UMULL : T2MulLong<0b010, 0b0000, "umull",
2799 [(set rGPR:$RdLo, rGPR:$RdHi,
2800 (umullohi rGPR:$Rn, rGPR:$Rm))]>;
2803 // Multiply + accumulate
2804 def t2SMLAL : T2MlaLong<0b100, 0b0000, "smlal">;
2805 def t2UMLAL : T2MlaLong<0b110, 0b0000, "umlal">;
2806 def t2UMAAL : T2MlaLong<0b110, 0b0110, "umaal">, Requires<[IsThumb2, HasDSP]>;
2809 // Rounding variants of the below included for disassembly only
2811 // Most significant word multiply
2812 class T2SMMUL<bits<4> op7_4, string opc, list<dag> pattern>
2813 : T2ThreeReg<(outs rGPR:$Rd),
2814 (ins rGPR:$Rn, rGPR:$Rm), IIC_iMUL32,
2815 opc, "\t$Rd, $Rn, $Rm", pattern>,
2816 Requires<[IsThumb2, HasDSP]>,
2817 Sched<[WriteMUL32, ReadMUL, ReadMUL]> {
2818 let Inst{31-27} = 0b11111;
2819 let Inst{26-23} = 0b0110;
2820 let Inst{22-20} = 0b101;
2821 let Inst{15-12} = 0b1111; // Ra = 0b1111 (no accumulate)
2822 let Inst{7-4} = op7_4;
2824 def t2SMMUL : T2SMMUL<0b0000, "smmul", [(set rGPR:$Rd, (mulhs rGPR:$Rn,
2827 T2SMMUL<0b0001, "smmulr",
2828 [(set rGPR:$Rd, (ARMsmmlar rGPR:$Rn, rGPR:$Rm, (i32 0)))]>;
2830 class T2FourRegSMMLA<bits<3> op22_20, bits<4> op7_4, string opc,
2832 : T2FourReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC32,
2833 opc, "\t$Rd, $Rn, $Rm, $Ra", pattern>,
2834 Requires<[IsThumb2, HasDSP, UseMulOps]>,
2835 Sched<[WriteMAC32, ReadMUL, ReadMUL, ReadMAC]> {
2836 let Inst{31-27} = 0b11111;
2837 let Inst{26-23} = 0b0110;
2838 let Inst{22-20} = op22_20;
2839 let Inst{7-4} = op7_4;
2842 def t2SMMLA : T2FourRegSMMLA<0b101, 0b0000, "smmla",
2843 [(set rGPR:$Rd, (add (mulhs rGPR:$Rm, rGPR:$Rn), rGPR:$Ra))]>;
2844 def t2SMMLAR: T2FourRegSMMLA<0b101, 0b0001, "smmlar",
2845 [(set rGPR:$Rd, (ARMsmmlar rGPR:$Rn, rGPR:$Rm, rGPR:$Ra))]>;
2846 def t2SMMLS: T2FourRegSMMLA<0b110, 0b0000, "smmls", []>;
2847 def t2SMMLSR: T2FourRegSMMLA<0b110, 0b0001, "smmlsr",
2848 [(set rGPR:$Rd, (ARMsmmlsr rGPR:$Rn, rGPR:$Rm, rGPR:$Ra))]>;
2850 class T2ThreeRegSMUL<bits<3> op22_20, bits<2> op5_4, string opc,
2852 : T2ThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iMUL16, opc,
2853 "\t$Rd, $Rn, $Rm", pattern>,
2854 Requires<[IsThumb2, HasDSP]>,
2855 Sched<[WriteMUL16, ReadMUL, ReadMUL]> {
2856 let Inst{31-27} = 0b11111;
2857 let Inst{26-23} = 0b0110;
2858 let Inst{22-20} = op22_20;
2859 let Inst{15-12} = 0b1111; // Ra = 0b1111 (no accumulate)
2860 let Inst{7-6} = 0b00;
2861 let Inst{5-4} = op5_4;
2864 def t2SMULBB : T2ThreeRegSMUL<0b001, 0b00, "smulbb",
2865 [(set rGPR:$Rd, (bb_mul rGPR:$Rn, rGPR:$Rm))]>;
2866 def t2SMULBT : T2ThreeRegSMUL<0b001, 0b01, "smulbt",
2867 [(set rGPR:$Rd, (bt_mul rGPR:$Rn, rGPR:$Rm))]>;
2868 def t2SMULTB : T2ThreeRegSMUL<0b001, 0b10, "smultb",
2869 [(set rGPR:$Rd, (tb_mul rGPR:$Rn, rGPR:$Rm))]>;
2870 def t2SMULTT : T2ThreeRegSMUL<0b001, 0b11, "smultt",
2871 [(set rGPR:$Rd, (tt_mul rGPR:$Rn, rGPR:$Rm))]>;
2872 def t2SMULWB : T2ThreeRegSMUL<0b011, 0b00, "smulwb",
2873 [(set rGPR:$Rd, (ARMsmulwb rGPR:$Rn, rGPR:$Rm))]>;
2874 def t2SMULWT : T2ThreeRegSMUL<0b011, 0b01, "smulwt",
2875 [(set rGPR:$Rd, (ARMsmulwt rGPR:$Rn, rGPR:$Rm))]>;
2877 def : Thumb2DSPPat<(mul sext_16_node:$Rn, (sext_bottom_16 rGPR:$Rm)),
2878 (t2SMULBB rGPR:$Rn, rGPR:$Rm)>;
2879 def : Thumb2DSPPat<(mul sext_16_node:$Rn, (sext_top_16 rGPR:$Rm)),
2880 (t2SMULBT rGPR:$Rn, rGPR:$Rm)>;
2881 def : Thumb2DSPPat<(mul (sext_top_16 rGPR:$Rn), sext_16_node:$Rm),
2882 (t2SMULTB rGPR:$Rn, rGPR:$Rm)>;
2884 def : Thumb2DSPPat<(int_arm_smulbb rGPR:$Rn, rGPR:$Rm),
2885 (t2SMULBB rGPR:$Rn, rGPR:$Rm)>;
2886 def : Thumb2DSPPat<(int_arm_smulbt rGPR:$Rn, rGPR:$Rm),
2887 (t2SMULBT rGPR:$Rn, rGPR:$Rm)>;
2888 def : Thumb2DSPPat<(int_arm_smultb rGPR:$Rn, rGPR:$Rm),
2889 (t2SMULTB rGPR:$Rn, rGPR:$Rm)>;
2890 def : Thumb2DSPPat<(int_arm_smultt rGPR:$Rn, rGPR:$Rm),
2891 (t2SMULTT rGPR:$Rn, rGPR:$Rm)>;
2892 def : Thumb2DSPPat<(int_arm_smulwb rGPR:$Rn, rGPR:$Rm),
2893 (t2SMULWB rGPR:$Rn, rGPR:$Rm)>;
2894 def : Thumb2DSPPat<(int_arm_smulwt rGPR:$Rn, rGPR:$Rm),
2895 (t2SMULWT rGPR:$Rn, rGPR:$Rm)>;
2897 class T2FourRegSMLA<bits<3> op22_20, bits<2> op5_4, string opc,
2899 : T2FourReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMUL16,
2900 opc, "\t$Rd, $Rn, $Rm, $Ra", pattern>,
2901 Requires<[IsThumb2, HasDSP, UseMulOps]>,
2902 Sched<[WriteMAC16, ReadMUL, ReadMUL, ReadMAC]> {
2903 let Inst{31-27} = 0b11111;
2904 let Inst{26-23} = 0b0110;
2905 let Inst{22-20} = op22_20;
2906 let Inst{7-6} = 0b00;
2907 let Inst{5-4} = op5_4;
2910 def t2SMLABB : T2FourRegSMLA<0b001, 0b00, "smlabb",
2911 [(set rGPR:$Rd, (add rGPR:$Ra, (bb_mul rGPR:$Rn, rGPR:$Rm)))]>;
2912 def t2SMLABT : T2FourRegSMLA<0b001, 0b01, "smlabt",
2913 [(set rGPR:$Rd, (add rGPR:$Ra, (bt_mul rGPR:$Rn, rGPR:$Rm)))]>;
2914 def t2SMLATB : T2FourRegSMLA<0b001, 0b10, "smlatb",
2915 [(set rGPR:$Rd, (add rGPR:$Ra, (tb_mul rGPR:$Rn, rGPR:$Rm)))]>;
2916 def t2SMLATT : T2FourRegSMLA<0b001, 0b11, "smlatt",
2917 [(set rGPR:$Rd, (add rGPR:$Ra, (tt_mul rGPR:$Rn, rGPR:$Rm)))]>;
2918 def t2SMLAWB : T2FourRegSMLA<0b011, 0b00, "smlawb",
2919 [(set rGPR:$Rd, (add rGPR:$Ra, (ARMsmulwb rGPR:$Rn, rGPR:$Rm)))]>;
2920 def t2SMLAWT : T2FourRegSMLA<0b011, 0b01, "smlawt",
2921 [(set rGPR:$Rd, (add rGPR:$Ra, (ARMsmulwt rGPR:$Rn, rGPR:$Rm)))]>;
2923 def : Thumb2DSPMulPat<(add rGPR:$Ra, (mul sext_16_node:$Rn, sext_16_node:$Rm)),
2924 (t2SMLABB rGPR:$Rn, rGPR:$Rm, rGPR:$Ra)>;
2925 def : Thumb2DSPMulPat<(add rGPR:$Ra, (mul sext_16_node:$Rn,
2926 (sext_bottom_16 rGPR:$Rm))),
2927 (t2SMLABB rGPR:$Rn, rGPR:$Rm, rGPR:$Ra)>;
2928 def : Thumb2DSPMulPat<(add rGPR:$Ra, (mul sext_16_node:$Rn,
2929 (sext_top_16 rGPR:$Rm))),
2930 (t2SMLABT rGPR:$Rn, rGPR:$Rm, rGPR:$Ra)>;
2931 def : Thumb2DSPMulPat<(add rGPR:$Ra, (mul (sext_top_16 rGPR:$Rn),
2933 (t2SMLATB rGPR:$Rn, rGPR:$Rm, rGPR:$Ra)>;
2935 def : Thumb2DSPPat<(int_arm_smlabb GPR:$a, GPR:$b, GPR:$acc),
2936 (t2SMLABB GPR:$a, GPR:$b, GPR:$acc)>;
2937 def : Thumb2DSPPat<(int_arm_smlabt GPR:$a, GPR:$b, GPR:$acc),
2938 (t2SMLABT GPR:$a, GPR:$b, GPR:$acc)>;
2939 def : Thumb2DSPPat<(int_arm_smlatb GPR:$a, GPR:$b, GPR:$acc),
2940 (t2SMLATB GPR:$a, GPR:$b, GPR:$acc)>;
2941 def : Thumb2DSPPat<(int_arm_smlatt GPR:$a, GPR:$b, GPR:$acc),
2942 (t2SMLATT GPR:$a, GPR:$b, GPR:$acc)>;
2943 def : Thumb2DSPPat<(int_arm_smlawb GPR:$a, GPR:$b, GPR:$acc),
2944 (t2SMLAWB GPR:$a, GPR:$b, GPR:$acc)>;
2945 def : Thumb2DSPPat<(int_arm_smlawt GPR:$a, GPR:$b, GPR:$acc),
2946 (t2SMLAWT GPR:$a, GPR:$b, GPR:$acc)>;
2948 // Halfword multiple accumulate long: SMLAL<x><y>
2949 def t2SMLALBB : T2MlaLong<0b100, 0b1000, "smlalbb">,
2950 Requires<[IsThumb2, HasDSP]>;
2951 def t2SMLALBT : T2MlaLong<0b100, 0b1001, "smlalbt">,
2952 Requires<[IsThumb2, HasDSP]>;
2953 def t2SMLALTB : T2MlaLong<0b100, 0b1010, "smlaltb">,
2954 Requires<[IsThumb2, HasDSP]>;
2955 def t2SMLALTT : T2MlaLong<0b100, 0b1011, "smlaltt">,
2956 Requires<[IsThumb2, HasDSP]>;
2958 def : Thumb2DSPPat<(ARMsmlalbb GPR:$Rn, GPR:$Rm, GPR:$RLo, GPR:$RHi),
2959 (t2SMLALBB $Rn, $Rm, $RLo, $RHi)>;
2960 def : Thumb2DSPPat<(ARMsmlalbt GPR:$Rn, GPR:$Rm, GPR:$RLo, GPR:$RHi),
2961 (t2SMLALBT $Rn, $Rm, $RLo, $RHi)>;
2962 def : Thumb2DSPPat<(ARMsmlaltb GPR:$Rn, GPR:$Rm, GPR:$RLo, GPR:$RHi),
2963 (t2SMLALTB $Rn, $Rm, $RLo, $RHi)>;
2964 def : Thumb2DSPPat<(ARMsmlaltt GPR:$Rn, GPR:$Rm, GPR:$RLo, GPR:$RHi),
2965 (t2SMLALTT $Rn, $Rm, $RLo, $RHi)>;
2967 class T2DualHalfMul<bits<3> op22_20, bits<4> op7_4, string opc,
2968 Intrinsic intrinsic>
2969 : T2ThreeReg_mac<0, op22_20, op7_4,
2971 (ins rGPR:$Rn, rGPR:$Rm),
2972 IIC_iMAC32, opc, "\t$Rd, $Rn, $Rm",
2973 [(set rGPR:$Rd, (intrinsic rGPR:$Rn, rGPR:$Rm))]>,
2974 Requires<[IsThumb2, HasDSP]>,
2975 Sched<[WriteMAC32, ReadMUL, ReadMUL, ReadMAC]> {
2976 let Inst{15-12} = 0b1111;
2979 // Dual halfword multiple: SMUAD, SMUSD, SMLAD, SMLSD, SMLALD, SMLSLD
2980 def t2SMUAD: T2DualHalfMul<0b010, 0b0000, "smuad", int_arm_smuad>;
2981 def t2SMUADX: T2DualHalfMul<0b010, 0b0001, "smuadx", int_arm_smuadx>;
2982 def t2SMUSD: T2DualHalfMul<0b100, 0b0000, "smusd", int_arm_smusd>;
2983 def t2SMUSDX: T2DualHalfMul<0b100, 0b0001, "smusdx", int_arm_smusdx>;
2985 class T2DualHalfMulAdd<bits<3> op22_20, bits<4> op7_4, string opc,
2986 Intrinsic intrinsic>
2987 : T2FourReg_mac<0, op22_20, op7_4,
2989 (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra),
2990 IIC_iMAC32, opc, "\t$Rd, $Rn, $Rm, $Ra",
2991 [(set rGPR:$Rd, (intrinsic rGPR:$Rn, rGPR:$Rm, rGPR:$Ra))]>,
2992 Requires<[IsThumb2, HasDSP]>;
2994 def t2SMLAD : T2DualHalfMulAdd<0b010, 0b0000, "smlad", int_arm_smlad>;
2995 def t2SMLADX : T2DualHalfMulAdd<0b010, 0b0001, "smladx", int_arm_smladx>;
2996 def t2SMLSD : T2DualHalfMulAdd<0b100, 0b0000, "smlsd", int_arm_smlsd>;
2997 def t2SMLSDX : T2DualHalfMulAdd<0b100, 0b0001, "smlsdx", int_arm_smlsdx>;
2999 class T2DualHalfMulAddLong<bits<3> op22_20, bits<4> op7_4, string opc>
3000 : T2FourReg_mac<1, op22_20, op7_4,
3001 (outs rGPR:$Ra, rGPR:$Rd),
3002 (ins rGPR:$Rn, rGPR:$Rm, rGPR:$RLo, rGPR:$RHi),
3003 IIC_iMAC64, opc, "\t$Ra, $Rd, $Rn, $Rm", []>,
3004 RegConstraint<"$Ra = $RLo, $Rd = $RHi">,
3005 Requires<[IsThumb2, HasDSP]>,
3006 Sched<[WriteMAC64Lo, WriteMAC64Hi, ReadMUL, ReadMUL, ReadMAC, ReadMAC]>;
3008 def t2SMLALD : T2DualHalfMulAddLong<0b100, 0b1100, "smlald">;
3009 def t2SMLALDX : T2DualHalfMulAddLong<0b100, 0b1101, "smlaldx">;
3010 def t2SMLSLD : T2DualHalfMulAddLong<0b101, 0b1100, "smlsld">;
3011 def t2SMLSLDX : T2DualHalfMulAddLong<0b101, 0b1101, "smlsldx">;
3013 def : Thumb2DSPPat<(ARMSmlald rGPR:$Rn, rGPR:$Rm, rGPR:$RLo, rGPR:$RHi),
3014 (t2SMLALD rGPR:$Rn, rGPR:$Rm, rGPR:$RLo, rGPR:$RHi)>;
3015 def : Thumb2DSPPat<(ARMSmlaldx rGPR:$Rn, rGPR:$Rm, rGPR:$RLo, rGPR:$RHi),
3016 (t2SMLALDX rGPR:$Rn, rGPR:$Rm, rGPR:$RLo, rGPR:$RHi)>;
3017 def : Thumb2DSPPat<(ARMSmlsld rGPR:$Rn, rGPR:$Rm, rGPR:$RLo, rGPR:$RHi),
3018 (t2SMLSLD rGPR:$Rn, rGPR:$Rm, rGPR:$RLo, rGPR:$RHi)>;
3019 def : Thumb2DSPPat<(ARMSmlsldx rGPR:$Rn, rGPR:$Rm, rGPR:$RLo, rGPR:$RHi),
3020 (t2SMLSLDX rGPR:$Rn, rGPR:$Rm, rGPR:$RLo, rGPR:$RHi)>;
3022 //===----------------------------------------------------------------------===//
3023 // Division Instructions.
3024 // Signed and unsigned division on v7-M
3026 def t2SDIV : T2ThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iDIV,
3027 "sdiv", "\t$Rd, $Rn, $Rm",
3028 [(set rGPR:$Rd, (sdiv rGPR:$Rn, rGPR:$Rm))]>,
3029 Requires<[HasDivideInThumb, IsThumb, HasV8MBaseline]>,
3031 let Inst{31-27} = 0b11111;
3032 let Inst{26-21} = 0b011100;
3034 let Inst{15-12} = 0b1111;
3035 let Inst{7-4} = 0b1111;
3038 def t2UDIV : T2ThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iDIV,
3039 "udiv", "\t$Rd, $Rn, $Rm",
3040 [(set rGPR:$Rd, (udiv rGPR:$Rn, rGPR:$Rm))]>,
3041 Requires<[HasDivideInThumb, IsThumb, HasV8MBaseline]>,
3043 let Inst{31-27} = 0b11111;
3044 let Inst{26-21} = 0b011101;
3046 let Inst{15-12} = 0b1111;
3047 let Inst{7-4} = 0b1111;
3050 //===----------------------------------------------------------------------===//
3051 // Misc. Arithmetic Instructions.
3054 class T2I_misc<bits<2> op1, bits<2> op2, dag oops, dag iops,
3055 InstrItinClass itin, string opc, string asm, list<dag> pattern>
3056 : T2ThreeReg<oops, iops, itin, opc, asm, pattern> {
3057 let Inst{31-27} = 0b11111;
3058 let Inst{26-22} = 0b01010;
3059 let Inst{21-20} = op1;
3060 let Inst{15-12} = 0b1111;
3061 let Inst{7-6} = 0b10;
3062 let Inst{5-4} = op2;
3066 def t2CLZ : T2I_misc<0b11, 0b00, (outs rGPR:$Rd), (ins rGPR:$Rm), IIC_iUNAr,
3067 "clz", "\t$Rd, $Rm", [(set rGPR:$Rd, (ctlz rGPR:$Rm))]>,
3070 def t2RBIT : T2I_misc<0b01, 0b10, (outs rGPR:$Rd), (ins rGPR:$Rm), IIC_iUNAr,
3071 "rbit", "\t$Rd, $Rm",
3072 [(set rGPR:$Rd, (bitreverse rGPR:$Rm))]>,
3075 def t2REV : T2I_misc<0b01, 0b00, (outs rGPR:$Rd), (ins rGPR:$Rm), IIC_iUNAr,
3076 "rev", ".w\t$Rd, $Rm", [(set rGPR:$Rd, (bswap rGPR:$Rm))]>,
3079 def t2REV16 : T2I_misc<0b01, 0b01, (outs rGPR:$Rd), (ins rGPR:$Rm), IIC_iUNAr,
3080 "rev16", ".w\t$Rd, $Rm",
3081 [(set rGPR:$Rd, (rotr (bswap rGPR:$Rm), (i32 16)))]>,
3084 def t2REVSH : T2I_misc<0b01, 0b11, (outs rGPR:$Rd), (ins rGPR:$Rm), IIC_iUNAr,
3085 "revsh", ".w\t$Rd, $Rm",
3086 [(set rGPR:$Rd, (sra (bswap rGPR:$Rm), (i32 16)))]>,
3089 def : T2Pat<(or (sra (shl rGPR:$Rm, (i32 24)), (i32 16)),
3090 (and (srl rGPR:$Rm, (i32 8)), 0xFF)),
3091 (t2REVSH rGPR:$Rm)>;
3093 def t2PKHBT : T2ThreeReg<
3094 (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, pkh_lsl_amt:$sh),
3095 IIC_iBITsi, "pkhbt", "\t$Rd, $Rn, $Rm$sh",
3096 [(set rGPR:$Rd, (or (and rGPR:$Rn, 0xFFFF),
3097 (and (shl rGPR:$Rm, pkh_lsl_amt:$sh),
3099 Requires<[HasDSP, IsThumb2]>,
3100 Sched<[WriteALUsi, ReadALU]> {
3101 let Inst{31-27} = 0b11101;
3102 let Inst{26-25} = 0b01;
3103 let Inst{24-20} = 0b01100;
3104 let Inst{5} = 0; // BT form
3108 let Inst{14-12} = sh{4-2};
3109 let Inst{7-6} = sh{1-0};
3112 // Alternate cases for PKHBT where identities eliminate some nodes.
3113 def : T2Pat<(or (and rGPR:$src1, 0xFFFF), (and rGPR:$src2, 0xFFFF0000)),
3114 (t2PKHBT rGPR:$src1, rGPR:$src2, 0)>,
3115 Requires<[HasDSP, IsThumb2]>;
3116 def : T2Pat<(or (and rGPR:$src1, 0xFFFF), (shl rGPR:$src2, imm16_31:$sh)),
3117 (t2PKHBT rGPR:$src1, rGPR:$src2, imm16_31:$sh)>,
3118 Requires<[HasDSP, IsThumb2]>;
3120 // Note: Shifts of 1-15 bits will be transformed to srl instead of sra and
3121 // will match the pattern below.
3122 def t2PKHTB : T2ThreeReg<
3123 (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, pkh_asr_amt:$sh),
3124 IIC_iBITsi, "pkhtb", "\t$Rd, $Rn, $Rm$sh",
3125 [(set rGPR:$Rd, (or (and rGPR:$Rn, 0xFFFF0000),
3126 (and (sra rGPR:$Rm, pkh_asr_amt:$sh),
3128 Requires<[HasDSP, IsThumb2]>,
3129 Sched<[WriteALUsi, ReadALU]> {
3130 let Inst{31-27} = 0b11101;
3131 let Inst{26-25} = 0b01;
3132 let Inst{24-20} = 0b01100;
3133 let Inst{5} = 1; // TB form
3137 let Inst{14-12} = sh{4-2};
3138 let Inst{7-6} = sh{1-0};
3141 // Alternate cases for PKHTB where identities eliminate some nodes. Note that
3142 // a shift amount of 0 is *not legal* here, it is PKHBT instead.
3143 // We also can not replace a srl (17..31) by an arithmetic shift we would use in
3144 // pkhtb src1, src2, asr (17..31).
3145 def : T2Pat<(or (and rGPR:$src1, 0xFFFF0000), (srl rGPR:$src2, imm16:$sh)),
3146 (t2PKHTB rGPR:$src1, rGPR:$src2, imm16:$sh)>,
3147 Requires<[HasDSP, IsThumb2]>;
3148 def : T2Pat<(or (and rGPR:$src1, 0xFFFF0000), (sra rGPR:$src2, imm16_31:$sh)),
3149 (t2PKHTB rGPR:$src1, rGPR:$src2, imm16_31:$sh)>,
3150 Requires<[HasDSP, IsThumb2]>;
3151 def : T2Pat<(or (and rGPR:$src1, 0xFFFF0000),
3152 (and (srl rGPR:$src2, imm1_15:$sh), 0xFFFF)),
3153 (t2PKHTB rGPR:$src1, rGPR:$src2, imm1_15:$sh)>,
3154 Requires<[HasDSP, IsThumb2]>;
3156 //===----------------------------------------------------------------------===//
3157 // CRC32 Instructions
3160 // + CRC32{B,H,W} 0x04C11DB7
3161 // + CRC32C{B,H,W} 0x1EDC6F41
3164 class T2I_crc32<bit C, bits<2> sz, string suffix, SDPatternOperator builtin>
3165 : T2ThreeRegNoP<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), NoItinerary,
3166 !strconcat("crc32", suffix, "\t$Rd, $Rn, $Rm"),
3167 [(set rGPR:$Rd, (builtin rGPR:$Rn, rGPR:$Rm))]>,
3168 Requires<[IsThumb2, HasV8, HasCRC]> {
3169 let Inst{31-27} = 0b11111;
3170 let Inst{26-21} = 0b010110;
3172 let Inst{15-12} = 0b1111;
3173 let Inst{7-6} = 0b10;
3177 def t2CRC32B : T2I_crc32<0, 0b00, "b", int_arm_crc32b>;
3178 def t2CRC32CB : T2I_crc32<1, 0b00, "cb", int_arm_crc32cb>;
3179 def t2CRC32H : T2I_crc32<0, 0b01, "h", int_arm_crc32h>;
3180 def t2CRC32CH : T2I_crc32<1, 0b01, "ch", int_arm_crc32ch>;
3181 def t2CRC32W : T2I_crc32<0, 0b10, "w", int_arm_crc32w>;
3182 def t2CRC32CW : T2I_crc32<1, 0b10, "cw", int_arm_crc32cw>;
3184 //===----------------------------------------------------------------------===//
3185 // Comparison Instructions...
3187 defm t2CMP : T2I_cmp_irs<0b1101, "cmp", GPRnopc,
3188 IIC_iCMPi, IIC_iCMPr, IIC_iCMPsi, ARMcmp>;
3190 def : T2Pat<(ARMcmpZ GPRnopc:$lhs, t2_so_imm:$imm),
3191 (t2CMPri GPRnopc:$lhs, t2_so_imm:$imm)>;
3192 def : T2Pat<(ARMcmpZ GPRnopc:$lhs, rGPR:$rhs),
3193 (t2CMPrr GPRnopc:$lhs, rGPR:$rhs)>;
3194 def : T2Pat<(ARMcmpZ GPRnopc:$lhs, t2_so_reg:$rhs),
3195 (t2CMPrs GPRnopc:$lhs, t2_so_reg:$rhs)>;
3197 let isCompare = 1, Defs = [CPSR] in {
3199 def t2CMNri : T2OneRegCmpImm<
3200 (outs), (ins GPRnopc:$Rn, t2_so_imm:$imm), IIC_iCMPi,
3201 "cmn", ".w\t$Rn, $imm",
3202 [(ARMcmn GPRnopc:$Rn, (ineg t2_so_imm:$imm))]>,
3203 Sched<[WriteCMP, ReadALU]> {
3204 let Inst{31-27} = 0b11110;
3206 let Inst{24-21} = 0b1000;
3207 let Inst{20} = 1; // The S bit.
3209 let Inst{11-8} = 0b1111; // Rd
3212 def t2CMNzrr : T2TwoRegCmp<
3213 (outs), (ins GPRnopc:$Rn, rGPR:$Rm), IIC_iCMPr,
3214 "cmn", ".w\t$Rn, $Rm",
3215 [(BinOpFrag<(ARMcmpZ node:$LHS,(ineg node:$RHS))>
3216 GPRnopc:$Rn, rGPR:$Rm)]>, Sched<[WriteCMP, ReadALU, ReadALU]> {
3217 let Inst{31-27} = 0b11101;
3218 let Inst{26-25} = 0b01;
3219 let Inst{24-21} = 0b1000;
3220 let Inst{20} = 1; // The S bit.
3221 let Inst{14-12} = 0b000; // imm3
3222 let Inst{11-8} = 0b1111; // Rd
3223 let Inst{7-6} = 0b00; // imm2
3224 let Inst{5-4} = 0b00; // type
3227 def t2CMNzrs : T2OneRegCmpShiftedReg<
3228 (outs), (ins GPRnopc:$Rn, t2_so_reg:$ShiftedRm), IIC_iCMPsi,
3229 "cmn", ".w\t$Rn, $ShiftedRm",
3230 [(BinOpFrag<(ARMcmpZ node:$LHS,(ineg node:$RHS))>
3231 GPRnopc:$Rn, t2_so_reg:$ShiftedRm)]>,
3232 Sched<[WriteCMPsi, ReadALU, ReadALU]> {
3233 let Inst{31-27} = 0b11101;
3234 let Inst{26-25} = 0b01;
3235 let Inst{24-21} = 0b1000;
3236 let Inst{20} = 1; // The S bit.
3237 let Inst{11-8} = 0b1111; // Rd
3241 // Assembler aliases w/o the ".w" suffix.
3242 // No alias here for 'rr' version as not all instantiations of this multiclass
3243 // want one (CMP in particular, does not).
3244 def : t2InstAlias<"cmn${p} $Rn, $imm",
3245 (t2CMNri GPRnopc:$Rn, t2_so_imm:$imm, pred:$p)>;
3246 def : t2InstAlias<"cmn${p} $Rn, $shift",
3247 (t2CMNzrs GPRnopc:$Rn, t2_so_reg:$shift, pred:$p)>;
3249 def : T2Pat<(ARMcmp GPR:$src, t2_so_imm_neg:$imm),
3250 (t2CMNri GPR:$src, t2_so_imm_neg:$imm)>;
3252 def : T2Pat<(ARMcmpZ GPRnopc:$src, t2_so_imm_neg:$imm),
3253 (t2CMNri GPRnopc:$src, t2_so_imm_neg:$imm)>;
3255 defm t2TST : T2I_cmp_irs<0b0000, "tst", rGPR,
3256 IIC_iTSTi, IIC_iTSTr, IIC_iTSTsi,
3257 BinOpFrag<(ARMcmpZ (and_su node:$LHS, node:$RHS), 0)>>;
3258 defm t2TEQ : T2I_cmp_irs<0b0100, "teq", rGPR,
3259 IIC_iTSTi, IIC_iTSTr, IIC_iTSTsi,
3260 BinOpFrag<(ARMcmpZ (xor_su node:$LHS, node:$RHS), 0)>>;
3262 // Conditional moves
3263 let hasSideEffects = 0 in {
3265 let isCommutable = 1, isSelect = 1 in
3266 def t2MOVCCr : t2PseudoInst<(outs rGPR:$Rd),
3267 (ins rGPR:$false, rGPR:$Rm, cmovpred:$p),
3269 [(set rGPR:$Rd, (ARMcmov rGPR:$false, rGPR:$Rm,
3271 RegConstraint<"$false = $Rd">, Sched<[WriteALU]>;
3273 let isMoveImm = 1 in
3275 : t2PseudoInst<(outs rGPR:$Rd),
3276 (ins rGPR:$false, t2_so_imm:$imm, cmovpred:$p),
3278 [(set rGPR:$Rd, (ARMcmov rGPR:$false,t2_so_imm:$imm,
3280 RegConstraint<"$false = $Rd">, Sched<[WriteALU]>;
3282 let isCodeGenOnly = 1 in {
3283 let isMoveImm = 1 in
3285 : t2PseudoInst<(outs rGPR:$Rd),
3286 (ins rGPR:$false, imm0_65535_expr:$imm, cmovpred:$p),
3288 [(set rGPR:$Rd, (ARMcmov rGPR:$false, imm0_65535:$imm,
3290 RegConstraint<"$false = $Rd">, Sched<[WriteALU]>;
3292 let isMoveImm = 1 in
3294 : t2PseudoInst<(outs rGPR:$Rd),
3295 (ins rGPR:$false, t2_so_imm:$imm, cmovpred:$p),
3298 (ARMcmov rGPR:$false, t2_so_imm_not:$imm,
3300 RegConstraint<"$false = $Rd">, Sched<[WriteALU]>;
3302 class MOVCCShPseudo<SDPatternOperator opnode, Operand ty>
3303 : t2PseudoInst<(outs rGPR:$Rd),
3304 (ins rGPR:$false, rGPR:$Rm, i32imm:$imm, cmovpred:$p),
3306 [(set rGPR:$Rd, (ARMcmov rGPR:$false,
3307 (opnode rGPR:$Rm, (i32 ty:$imm)),
3309 RegConstraint<"$false = $Rd">, Sched<[WriteALU]>;
3311 def t2MOVCClsl : MOVCCShPseudo<shl, imm0_31>;
3312 def t2MOVCClsr : MOVCCShPseudo<srl, imm_sr>;
3313 def t2MOVCCasr : MOVCCShPseudo<sra, imm_sr>;
3314 def t2MOVCCror : MOVCCShPseudo<rotr, imm0_31>;
3316 let isMoveImm = 1 in
3318 : t2PseudoInst<(outs rGPR:$dst),
3319 (ins rGPR:$false, i32imm:$src, cmovpred:$p),
3321 [(set rGPR:$dst, (ARMcmov rGPR:$false, imm:$src,
3323 RegConstraint<"$false = $dst">;
3324 } // isCodeGenOnly = 1
3328 //===----------------------------------------------------------------------===//
3329 // Atomic operations intrinsics
3332 // memory barriers protect the atomic sequences
3333 let hasSideEffects = 1 in {
3334 def t2DMB : T2I<(outs), (ins memb_opt:$opt), NoItinerary,
3335 "dmb", "\t$opt", [(int_arm_dmb (i32 imm0_15:$opt))]>,
3336 Requires<[IsThumb, HasDB]> {
3338 let Inst{31-4} = 0xf3bf8f5;
3339 let Inst{3-0} = opt;
3342 def t2DSB : T2I<(outs), (ins memb_opt:$opt), NoItinerary,
3343 "dsb", "\t$opt", [(int_arm_dsb (i32 imm0_15:$opt))]>,
3344 Requires<[IsThumb, HasDB]> {
3346 let Inst{31-4} = 0xf3bf8f4;
3347 let Inst{3-0} = opt;
3350 def t2ISB : T2I<(outs), (ins instsyncb_opt:$opt), NoItinerary,
3351 "isb", "\t$opt", [(int_arm_isb (i32 imm0_15:$opt))]>,
3352 Requires<[IsThumb, HasDB]> {
3354 let Inst{31-4} = 0xf3bf8f6;
3355 let Inst{3-0} = opt;
3358 let hasNoSchedulingInfo = 1 in
3359 def t2TSB : T2I<(outs), (ins tsb_opt:$opt), NoItinerary,
3360 "tsb", "\t$opt", []>, Requires<[IsThumb, HasV8_4a]> {
3361 let Inst{31-0} = 0xf3af8012;
3365 // Armv8.5-A speculation barrier
3366 def t2SB : Thumb2XI<(outs), (ins), AddrModeNone, 4, NoItinerary, "sb", "", []>,
3367 Requires<[IsThumb2, HasSB]>, Sched<[]> {
3368 let Inst{31-0} = 0xf3bf8f70;
3369 let Unpredictable = 0x000f2f0f;
3370 let hasSideEffects = 1;
3373 class T2I_ldrex<bits<4> opcod, dag oops, dag iops, AddrMode am, int sz,
3374 InstrItinClass itin, string opc, string asm, string cstr,
3375 list<dag> pattern, bits<4> rt2 = 0b1111>
3376 : Thumb2I<oops, iops, am, sz, itin, opc, asm, cstr, pattern> {
3377 let Inst{31-27} = 0b11101;
3378 let Inst{26-20} = 0b0001101;
3379 let Inst{11-8} = rt2;
3380 let Inst{7-4} = opcod;
3381 let Inst{3-0} = 0b1111;
3385 let Inst{19-16} = addr;
3386 let Inst{15-12} = Rt;
3388 class T2I_strex<bits<4> opcod, dag oops, dag iops, AddrMode am, int sz,
3389 InstrItinClass itin, string opc, string asm, string cstr,
3390 list<dag> pattern, bits<4> rt2 = 0b1111>
3391 : Thumb2I<oops, iops, am, sz, itin, opc, asm, cstr, pattern> {
3392 let Inst{31-27} = 0b11101;
3393 let Inst{26-20} = 0b0001100;
3394 let Inst{11-8} = rt2;
3395 let Inst{7-4} = opcod;
3401 let Inst{19-16} = addr;
3402 let Inst{15-12} = Rt;
3405 let mayLoad = 1 in {
3406 def t2LDREXB : T2I_ldrex<0b0100, (outs rGPR:$Rt), (ins addr_offset_none:$addr),
3407 AddrModeNone, 4, NoItinerary,
3408 "ldrexb", "\t$Rt, $addr", "",
3409 [(set rGPR:$Rt, (ldrex_1 addr_offset_none:$addr))]>,
3410 Requires<[IsThumb, HasV8MBaseline]>, Sched<[WriteLd]>;
3411 def t2LDREXH : T2I_ldrex<0b0101, (outs rGPR:$Rt), (ins addr_offset_none:$addr),
3412 AddrModeNone, 4, NoItinerary,
3413 "ldrexh", "\t$Rt, $addr", "",
3414 [(set rGPR:$Rt, (ldrex_2 addr_offset_none:$addr))]>,
3415 Requires<[IsThumb, HasV8MBaseline]>, Sched<[WriteLd]>;
3416 def t2LDREX : Thumb2I<(outs rGPR:$Rt), (ins t2addrmode_imm0_1020s4:$addr),
3417 AddrModeT2_ldrex, 4, NoItinerary,
3418 "ldrex", "\t$Rt, $addr", "",
3419 [(set rGPR:$Rt, (ldrex_4 t2addrmode_imm0_1020s4:$addr))]>,
3420 Requires<[IsThumb, HasV8MBaseline]>, Sched<[WriteLd]> {
3423 let Inst{31-27} = 0b11101;
3424 let Inst{26-20} = 0b0000101;
3425 let Inst{19-16} = addr{11-8};
3426 let Inst{15-12} = Rt;
3427 let Inst{11-8} = 0b1111;
3428 let Inst{7-0} = addr{7-0};
3430 let hasExtraDefRegAllocReq = 1 in
3431 def t2LDREXD : T2I_ldrex<0b0111, (outs rGPR:$Rt, rGPR:$Rt2),
3432 (ins addr_offset_none:$addr),
3433 AddrModeNone, 4, NoItinerary,
3434 "ldrexd", "\t$Rt, $Rt2, $addr", "",
3436 Requires<[IsThumb2, IsNotMClass]>, Sched<[WriteLd]> {
3438 let Inst{11-8} = Rt2;
3440 def t2LDAEXB : T2I_ldrex<0b1100, (outs rGPR:$Rt), (ins addr_offset_none:$addr),
3441 AddrModeNone, 4, NoItinerary,
3442 "ldaexb", "\t$Rt, $addr", "",
3443 [(set rGPR:$Rt, (ldaex_1 addr_offset_none:$addr))]>,
3444 Requires<[IsThumb, HasAcquireRelease, HasV7Clrex]>, Sched<[WriteLd]>;
3445 def t2LDAEXH : T2I_ldrex<0b1101, (outs rGPR:$Rt), (ins addr_offset_none:$addr),
3446 AddrModeNone, 4, NoItinerary,
3447 "ldaexh", "\t$Rt, $addr", "",
3448 [(set rGPR:$Rt, (ldaex_2 addr_offset_none:$addr))]>,
3449 Requires<[IsThumb, HasAcquireRelease, HasV7Clrex]>, Sched<[WriteLd]>;
3450 def t2LDAEX : Thumb2I<(outs rGPR:$Rt), (ins addr_offset_none:$addr),
3451 AddrModeNone, 4, NoItinerary,
3452 "ldaex", "\t$Rt, $addr", "",
3453 [(set rGPR:$Rt, (ldaex_4 addr_offset_none:$addr))]>,
3454 Requires<[IsThumb, HasAcquireRelease, HasV7Clrex]>, Sched<[WriteLd]> {
3457 let Inst{31-27} = 0b11101;
3458 let Inst{26-20} = 0b0001101;
3459 let Inst{19-16} = addr;
3460 let Inst{15-12} = Rt;
3461 let Inst{11-8} = 0b1111;
3462 let Inst{7-0} = 0b11101111;
3464 let hasExtraDefRegAllocReq = 1 in
3465 def t2LDAEXD : T2I_ldrex<0b1111, (outs rGPR:$Rt, rGPR:$Rt2),
3466 (ins addr_offset_none:$addr),
3467 AddrModeNone, 4, NoItinerary,
3468 "ldaexd", "\t$Rt, $Rt2, $addr", "",
3469 [], {?, ?, ?, ?}>, Requires<[IsThumb,
3470 HasAcquireRelease, HasV7Clrex, IsNotMClass]>, Sched<[WriteLd]> {
3472 let Inst{11-8} = Rt2;
3478 let mayStore = 1, Constraints = "@earlyclobber $Rd" in {
3479 def t2STREXB : T2I_strex<0b0100, (outs rGPR:$Rd),
3480 (ins rGPR:$Rt, addr_offset_none:$addr),
3481 AddrModeNone, 4, NoItinerary,
3482 "strexb", "\t$Rd, $Rt, $addr", "",
3484 (strex_1 rGPR:$Rt, addr_offset_none:$addr))]>,
3485 Requires<[IsThumb, HasV8MBaseline]>, Sched<[WriteST]>;
3486 def t2STREXH : T2I_strex<0b0101, (outs rGPR:$Rd),
3487 (ins rGPR:$Rt, addr_offset_none:$addr),
3488 AddrModeNone, 4, NoItinerary,
3489 "strexh", "\t$Rd, $Rt, $addr", "",
3491 (strex_2 rGPR:$Rt, addr_offset_none:$addr))]>,
3492 Requires<[IsThumb, HasV8MBaseline]>, Sched<[WriteST]>;
3494 def t2STREX : Thumb2I<(outs rGPR:$Rd), (ins rGPR:$Rt,
3495 t2addrmode_imm0_1020s4:$addr),
3496 AddrModeT2_ldrex, 4, NoItinerary,
3497 "strex", "\t$Rd, $Rt, $addr", "",
3499 (strex_4 rGPR:$Rt, t2addrmode_imm0_1020s4:$addr))]>,
3500 Requires<[IsThumb, HasV8MBaseline]>, Sched<[WriteST]> {
3504 let Inst{31-27} = 0b11101;
3505 let Inst{26-20} = 0b0000100;
3506 let Inst{19-16} = addr{11-8};
3507 let Inst{15-12} = Rt;
3508 let Inst{11-8} = Rd;
3509 let Inst{7-0} = addr{7-0};
3511 let hasExtraSrcRegAllocReq = 1 in
3512 def t2STREXD : T2I_strex<0b0111, (outs rGPR:$Rd),
3513 (ins rGPR:$Rt, rGPR:$Rt2, addr_offset_none:$addr),
3514 AddrModeNone, 4, NoItinerary,
3515 "strexd", "\t$Rd, $Rt, $Rt2, $addr", "", [],
3517 Requires<[IsThumb2, IsNotMClass]>, Sched<[WriteST]> {
3519 let Inst{11-8} = Rt2;
3521 def t2STLEXB : T2I_strex<0b1100, (outs rGPR:$Rd),
3522 (ins rGPR:$Rt, addr_offset_none:$addr),
3523 AddrModeNone, 4, NoItinerary,
3524 "stlexb", "\t$Rd, $Rt, $addr", "",
3526 (stlex_1 rGPR:$Rt, addr_offset_none:$addr))]>,
3527 Requires<[IsThumb, HasAcquireRelease,
3528 HasV7Clrex]>, Sched<[WriteST]>;
3530 def t2STLEXH : T2I_strex<0b1101, (outs rGPR:$Rd),
3531 (ins rGPR:$Rt, addr_offset_none:$addr),
3532 AddrModeNone, 4, NoItinerary,
3533 "stlexh", "\t$Rd, $Rt, $addr", "",
3535 (stlex_2 rGPR:$Rt, addr_offset_none:$addr))]>,
3536 Requires<[IsThumb, HasAcquireRelease,
3537 HasV7Clrex]>, Sched<[WriteST]>;
3539 def t2STLEX : Thumb2I<(outs rGPR:$Rd), (ins rGPR:$Rt,
3540 addr_offset_none:$addr),
3541 AddrModeNone, 4, NoItinerary,
3542 "stlex", "\t$Rd, $Rt, $addr", "",
3544 (stlex_4 rGPR:$Rt, addr_offset_none:$addr))]>,
3545 Requires<[IsThumb, HasAcquireRelease, HasV7Clrex]>,
3550 let Inst{31-27} = 0b11101;
3551 let Inst{26-20} = 0b0001100;
3552 let Inst{19-16} = addr;
3553 let Inst{15-12} = Rt;
3554 let Inst{11-4} = 0b11111110;
3557 let hasExtraSrcRegAllocReq = 1 in
3558 def t2STLEXD : T2I_strex<0b1111, (outs rGPR:$Rd),
3559 (ins rGPR:$Rt, rGPR:$Rt2, addr_offset_none:$addr),
3560 AddrModeNone, 4, NoItinerary,
3561 "stlexd", "\t$Rd, $Rt, $Rt2, $addr", "", [],
3562 {?, ?, ?, ?}>, Requires<[IsThumb, HasAcquireRelease,
3563 HasV7Clrex, IsNotMClass]>, Sched<[WriteST]> {
3565 let Inst{11-8} = Rt2;
3569 def t2CLREX : T2I<(outs), (ins), NoItinerary, "clrex", "", [(int_arm_clrex)]>,
3570 Requires<[IsThumb, HasV7Clrex]> {
3571 let Inst{31-16} = 0xf3bf;
3572 let Inst{15-14} = 0b10;
3575 let Inst{11-8} = 0b1111;
3576 let Inst{7-4} = 0b0010;
3577 let Inst{3-0} = 0b1111;
3580 def : T2Pat<(and (ldrex_1 addr_offset_none:$addr), 0xff),
3581 (t2LDREXB addr_offset_none:$addr)>,
3582 Requires<[IsThumb, HasV8MBaseline]>;
3583 def : T2Pat<(and (ldrex_2 addr_offset_none:$addr), 0xffff),
3584 (t2LDREXH addr_offset_none:$addr)>,
3585 Requires<[IsThumb, HasV8MBaseline]>;
3586 def : T2Pat<(strex_1 (and GPR:$Rt, 0xff), addr_offset_none:$addr),
3587 (t2STREXB GPR:$Rt, addr_offset_none:$addr)>,
3588 Requires<[IsThumb, HasV8MBaseline]>;
3589 def : T2Pat<(strex_2 (and GPR:$Rt, 0xffff), addr_offset_none:$addr),
3590 (t2STREXH GPR:$Rt, addr_offset_none:$addr)>,
3591 Requires<[IsThumb, HasV8MBaseline]>;
3593 def : T2Pat<(and (ldaex_1 addr_offset_none:$addr), 0xff),
3594 (t2LDAEXB addr_offset_none:$addr)>,
3595 Requires<[IsThumb, HasAcquireRelease, HasV7Clrex]>;
3596 def : T2Pat<(and (ldaex_2 addr_offset_none:$addr), 0xffff),
3597 (t2LDAEXH addr_offset_none:$addr)>,
3598 Requires<[IsThumb, HasAcquireRelease, HasV7Clrex]>;
3599 def : T2Pat<(stlex_1 (and GPR:$Rt, 0xff), addr_offset_none:$addr),
3600 (t2STLEXB GPR:$Rt, addr_offset_none:$addr)>,
3601 Requires<[IsThumb, HasAcquireRelease, HasV7Clrex]>;
3602 def : T2Pat<(stlex_2 (and GPR:$Rt, 0xffff), addr_offset_none:$addr),
3603 (t2STLEXH GPR:$Rt, addr_offset_none:$addr)>,
3604 Requires<[IsThumb, HasAcquireRelease, HasV7Clrex]>;
3606 //===----------------------------------------------------------------------===//
3607 // SJLJ Exception handling intrinsics
3608 // eh_sjlj_setjmp() is an instruction sequence to store the return
3609 // address and save #0 in R0 for the non-longjmp case.
3610 // Since by its nature we may be coming from some other function to get
3611 // here, and we're using the stack frame for the containing function to
3612 // save/restore registers, we can't keep anything live in regs across
3613 // the eh_sjlj_setjmp(), else it will almost certainly have been tromped upon
3614 // when we get here from a longjmp(). We force everything out of registers
3615 // except for our own input by listing the relevant registers in Defs. By
3616 // doing so, we also cause the prologue/epilogue code to actively preserve
3617 // all of the callee-saved resgisters, which is exactly what we want.
3618 // $val is a scratch register for our use.
3620 [ R0, R1, R2, R3, R4, R5, R6, R7, R8, R9, R10, R11, R12, LR, CPSR,
3621 Q0, Q1, Q2, Q3, Q8, Q9, Q10, Q11, Q12, Q13, Q14, Q15],
3622 hasSideEffects = 1, isBarrier = 1, isCodeGenOnly = 1,
3623 usesCustomInserter = 1 in {
3624 def t2Int_eh_sjlj_setjmp : Thumb2XI<(outs), (ins tGPR:$src, tGPR:$val),
3625 AddrModeNone, 0, NoItinerary, "", "",
3626 [(set R0, (ARMeh_sjlj_setjmp tGPR:$src, tGPR:$val))]>,
3627 Requires<[IsThumb2, HasVFP2]>;
3631 [ R0, R1, R2, R3, R4, R5, R6, R7, R8, R9, R10, R11, R12, LR, CPSR ],
3632 hasSideEffects = 1, isBarrier = 1, isCodeGenOnly = 1,
3633 usesCustomInserter = 1 in {
3634 def t2Int_eh_sjlj_setjmp_nofp : Thumb2XI<(outs), (ins tGPR:$src, tGPR:$val),
3635 AddrModeNone, 0, NoItinerary, "", "",
3636 [(set R0, (ARMeh_sjlj_setjmp tGPR:$src, tGPR:$val))]>,
3637 Requires<[IsThumb2, NoVFP]>;
3641 //===----------------------------------------------------------------------===//
3642 // Control-Flow Instructions
3645 // FIXME: remove when we have a way to marking a MI with these properties.
3646 // FIXME: Should pc be an implicit operand like PICADD, etc?
3647 let isReturn = 1, isTerminator = 1, isBarrier = 1, mayLoad = 1,
3648 hasExtraDefRegAllocReq = 1, isCodeGenOnly = 1 in
3649 def t2LDMIA_RET: t2PseudoExpand<(outs GPR:$wb), (ins GPR:$Rn, pred:$p,
3650 reglist:$regs, variable_ops),
3651 4, IIC_iLoad_mBr, [],
3652 (t2LDMIA_UPD GPR:$wb, GPR:$Rn, pred:$p, reglist:$regs)>,
3653 RegConstraint<"$Rn = $wb">;
3655 let isBranch = 1, isTerminator = 1, isBarrier = 1 in {
3656 let isPredicable = 1 in
3657 def t2B : T2I<(outs), (ins thumb_br_target:$target), IIC_Br,
3659 [(br bb:$target)]>, Sched<[WriteBr]>,
3660 Requires<[IsThumb, HasV8MBaseline]> {
3661 let Inst{31-27} = 0b11110;
3662 let Inst{15-14} = 0b10;
3666 let Inst{26} = target{23};
3667 let Inst{13} = target{22};
3668 let Inst{11} = target{21};
3669 let Inst{25-16} = target{20-11};
3670 let Inst{10-0} = target{10-0};
3671 let DecoderMethod = "DecodeT2BInstruction";
3672 let AsmMatchConverter = "cvtThumbBranches";
3675 let Size = 4, isNotDuplicable = 1, isBranch = 1, isTerminator = 1,
3676 isBarrier = 1, isIndirectBranch = 1 in {
3678 // available in both v8-M.Baseline and Thumb2 targets
3679 def t2BR_JT : t2basePseudoInst<(outs),
3680 (ins GPR:$target, GPR:$index, i32imm:$jt),
3682 [(ARMbr2jt GPR:$target, GPR:$index, tjumptable:$jt)]>,
3685 // FIXME: Add a case that can be predicated.
3686 def t2TBB_JT : t2PseudoInst<(outs),
3687 (ins GPR:$base, GPR:$index, i32imm:$jt, i32imm:$pclbl), 0, IIC_Br, []>,
3690 def t2TBH_JT : t2PseudoInst<(outs),
3691 (ins GPR:$base, GPR:$index, i32imm:$jt, i32imm:$pclbl), 0, IIC_Br, []>,
3694 def t2TBB : T2I<(outs), (ins addrmode_tbb:$addr), IIC_Br,
3695 "tbb", "\t$addr", []>, Sched<[WriteBrTbl]> {
3698 let Inst{31-20} = 0b111010001101;
3699 let Inst{19-16} = Rn;
3700 let Inst{15-5} = 0b11110000000;
3701 let Inst{4} = 0; // B form
3704 let DecoderMethod = "DecodeThumbTableBranch";
3707 def t2TBH : T2I<(outs), (ins addrmode_tbh:$addr), IIC_Br,
3708 "tbh", "\t$addr", []>, Sched<[WriteBrTbl]> {
3711 let Inst{31-20} = 0b111010001101;
3712 let Inst{19-16} = Rn;
3713 let Inst{15-5} = 0b11110000000;
3714 let Inst{4} = 1; // H form
3717 let DecoderMethod = "DecodeThumbTableBranch";
3719 } // isNotDuplicable, isIndirectBranch
3721 } // isBranch, isTerminator, isBarrier
3723 // FIXME: should be able to write a pattern for ARMBrcond, but can't use
3724 // a two-value operand where a dag node expects ", "two operands. :(
3725 let isBranch = 1, isTerminator = 1 in
3726 def t2Bcc : T2I<(outs), (ins brtarget:$target), IIC_Br,
3728 [/*(ARMbrcond bb:$target, imm:$cc)*/]>, Sched<[WriteBr]> {
3729 let Inst{31-27} = 0b11110;
3730 let Inst{15-14} = 0b10;
3734 let Inst{25-22} = p;
3737 let Inst{26} = target{20};
3738 let Inst{11} = target{19};
3739 let Inst{13} = target{18};
3740 let Inst{21-16} = target{17-12};
3741 let Inst{10-0} = target{11-1};
3743 let DecoderMethod = "DecodeThumb2BCCInstruction";
3744 let AsmMatchConverter = "cvtThumbBranches";
3747 // Tail calls. The MachO version of thumb tail calls uses a t2 branch, so
3749 let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1 in {
3752 def tTAILJMPd: tPseudoExpand<(outs),
3753 (ins thumb_br_target:$dst, pred:$p),
3755 (t2B thumb_br_target:$dst, pred:$p)>,
3756 Requires<[IsThumb2, IsMachO]>, Sched<[WriteBr]>;
3760 let Defs = [ITSTATE] in
3761 def t2IT : Thumb2XI<(outs), (ins it_pred:$cc, it_mask:$mask),
3762 AddrModeNone, 2, IIC_iALUx,
3763 "it$mask\t$cc", "", []>,
3764 ComplexDeprecationPredicate<"IT"> {
3765 // 16-bit instruction.
3766 let Inst{31-16} = 0x0000;
3767 let Inst{15-8} = 0b10111111;
3772 let Inst{3-0} = mask;
3774 let DecoderMethod = "DecodeIT";
3777 // Branch and Exchange Jazelle -- for disassembly only
3779 let isBranch = 1, isTerminator = 1, isBarrier = 1, isIndirectBranch = 1 in
3780 def t2BXJ : T2I<(outs), (ins GPRnopc:$func), NoItinerary, "bxj", "\t$func", []>,
3781 Sched<[WriteBr]>, Requires<[IsThumb2, IsNotMClass]> {
3783 let Inst{31-27} = 0b11110;
3785 let Inst{25-20} = 0b111100;
3786 let Inst{19-16} = func;
3787 let Inst{15-0} = 0b1000111100000000;
3790 // Compare and branch on zero / non-zero
3791 let isBranch = 1, isTerminator = 1 in {
3792 def tCBZ : T1I<(outs), (ins tGPR:$Rn, thumb_cb_target:$target), IIC_Br,
3793 "cbz\t$Rn, $target", []>,
3794 T1Misc<{0,0,?,1,?,?,?}>,
3795 Requires<[IsThumb, HasV8MBaseline]>, Sched<[WriteBr]> {
3799 let Inst{9} = target{5};
3800 let Inst{7-3} = target{4-0};
3804 def tCBNZ : T1I<(outs), (ins tGPR:$Rn, thumb_cb_target:$target), IIC_Br,
3805 "cbnz\t$Rn, $target", []>,
3806 T1Misc<{1,0,?,1,?,?,?}>,
3807 Requires<[IsThumb, HasV8MBaseline]>, Sched<[WriteBr]> {
3811 let Inst{9} = target{5};
3812 let Inst{7-3} = target{4-0};
3818 // Change Processor State is a system instruction.
3819 // FIXME: Since the asm parser has currently no clean way to handle optional
3820 // operands, create 3 versions of the same instruction. Once there's a clean
3821 // framework to represent optional operands, change this behavior.
3822 class t2CPS<dag iops, string asm_op> : T2XI<(outs), iops, NoItinerary,
3823 !strconcat("cps", asm_op), []>,
3824 Requires<[IsThumb2, IsNotMClass]> {
3830 let Inst{31-11} = 0b111100111010111110000;
3831 let Inst{10-9} = imod;
3833 let Inst{7-5} = iflags;
3834 let Inst{4-0} = mode;
3835 let DecoderMethod = "DecodeT2CPSInstruction";
3839 def t2CPS3p : t2CPS<(ins imod_op:$imod, iflags_op:$iflags, i32imm:$mode),
3840 "$imod\t$iflags, $mode">;
3841 let mode = 0, M = 0 in
3842 def t2CPS2p : t2CPS<(ins imod_op:$imod, iflags_op:$iflags),
3843 "$imod.w\t$iflags">;
3844 let imod = 0, iflags = 0, M = 1 in
3845 def t2CPS1p : t2CPS<(ins imm0_31:$mode), "\t$mode">;
3847 def : t2InstAlias<"cps$imod.w $iflags, $mode",
3848 (t2CPS3p imod_op:$imod, iflags_op:$iflags, i32imm:$mode), 0>;
3849 def : t2InstAlias<"cps.w $mode", (t2CPS1p imm0_31:$mode), 0>;
3851 // A6.3.4 Branches and miscellaneous control
3852 // Table A6-14 Change Processor State, and hint instructions
3853 def t2HINT : T2I<(outs), (ins imm0_239:$imm), NoItinerary, "hint", ".w\t$imm",
3854 [(int_arm_hint imm0_239:$imm)]> {
3856 let Inst{31-3} = 0b11110011101011111000000000000;
3857 let Inst{7-0} = imm;
3860 def : t2InstAlias<"hint$p $imm", (t2HINT imm0_239:$imm, pred:$p), 0>;
3861 def : t2InstAlias<"nop$p.w", (t2HINT 0, pred:$p), 1>;
3862 def : t2InstAlias<"yield$p.w", (t2HINT 1, pred:$p), 1>;
3863 def : t2InstAlias<"wfe$p.w", (t2HINT 2, pred:$p), 1>;
3864 def : t2InstAlias<"wfi$p.w", (t2HINT 3, pred:$p), 1>;
3865 def : t2InstAlias<"sev$p.w", (t2HINT 4, pred:$p), 1>;
3866 def : t2InstAlias<"sevl$p.w", (t2HINT 5, pred:$p), 1> {
3867 let Predicates = [IsThumb2, HasV8];
3869 def : t2InstAlias<"esb$p.w", (t2HINT 16, pred:$p), 1> {
3870 let Predicates = [IsThumb2, HasRAS];
3872 def : t2InstAlias<"esb$p", (t2HINT 16, pred:$p), 0> {
3873 let Predicates = [IsThumb2, HasRAS];
3875 def : t2InstAlias<"csdb$p.w", (t2HINT 20, pred:$p), 0>;
3876 def : t2InstAlias<"csdb$p", (t2HINT 20, pred:$p), 1>;
3878 def t2DBG : T2I<(outs), (ins imm0_15:$opt), NoItinerary, "dbg", "\t$opt",
3879 [(int_arm_dbg imm0_15:$opt)]> {
3881 let Inst{31-20} = 0b111100111010;
3882 let Inst{19-16} = 0b1111;
3883 let Inst{15-8} = 0b10000000;
3884 let Inst{7-4} = 0b1111;
3885 let Inst{3-0} = opt;
3888 // Secure Monitor Call is a system instruction.
3889 // Option = Inst{19-16}
3890 let isCall = 1, Uses = [SP] in
3891 def t2SMC : T2I<(outs), (ins imm0_15:$opt), NoItinerary, "smc", "\t$opt",
3892 []>, Requires<[IsThumb2, HasTrustZone]> {
3893 let Inst{31-27} = 0b11110;
3894 let Inst{26-20} = 0b1111111;
3895 let Inst{15-12} = 0b1000;
3898 let Inst{19-16} = opt;
3901 class T2DCPS<bits<2> opt, string opc>
3902 : T2I<(outs), (ins), NoItinerary, opc, "", []>, Requires<[IsThumb2, HasV8]> {
3903 let Inst{31-27} = 0b11110;
3904 let Inst{26-20} = 0b1111000;
3905 let Inst{19-16} = 0b1111;
3906 let Inst{15-12} = 0b1000;
3907 let Inst{11-2} = 0b0000000000;
3908 let Inst{1-0} = opt;
3911 def t2DCPS1 : T2DCPS<0b01, "dcps1">;
3912 def t2DCPS2 : T2DCPS<0b10, "dcps2">;
3913 def t2DCPS3 : T2DCPS<0b11, "dcps3">;
3915 class T2SRS<bits<2> Op, bit W, dag oops, dag iops, InstrItinClass itin,
3916 string opc, string asm, list<dag> pattern>
3917 : T2I<oops, iops, itin, opc, asm, pattern>,
3918 Requires<[IsThumb2,IsNotMClass]> {
3920 let Inst{31-25} = 0b1110100;
3921 let Inst{24-23} = Op;
3924 let Inst{20-16} = 0b01101;
3925 let Inst{15-5} = 0b11000000000;
3926 let Inst{4-0} = mode{4-0};
3929 // Store Return State is a system instruction.
3930 def t2SRSDB_UPD : T2SRS<0b00, 1, (outs), (ins imm0_31:$mode), NoItinerary,
3931 "srsdb", "\tsp!, $mode", []>;
3932 def t2SRSDB : T2SRS<0b00, 0, (outs), (ins imm0_31:$mode), NoItinerary,
3933 "srsdb","\tsp, $mode", []>;
3934 def t2SRSIA_UPD : T2SRS<0b11, 1, (outs), (ins imm0_31:$mode), NoItinerary,
3935 "srsia","\tsp!, $mode", []>;
3936 def t2SRSIA : T2SRS<0b11, 0, (outs), (ins imm0_31:$mode), NoItinerary,
3937 "srsia","\tsp, $mode", []>;
3940 def : t2InstAlias<"srsdb${p} $mode", (t2SRSDB imm0_31:$mode, pred:$p)>;
3941 def : t2InstAlias<"srsdb${p} $mode!", (t2SRSDB_UPD imm0_31:$mode, pred:$p)>;
3943 def : t2InstAlias<"srsia${p} $mode", (t2SRSIA imm0_31:$mode, pred:$p)>;
3944 def : t2InstAlias<"srsia${p} $mode!", (t2SRSIA_UPD imm0_31:$mode, pred:$p)>;
3946 // Return From Exception is a system instruction.
3947 let isReturn = 1, isBarrier = 1, isTerminator = 1, Defs = [PC] in
3948 class T2RFE<bits<12> op31_20, dag oops, dag iops, InstrItinClass itin,
3949 string opc, string asm, list<dag> pattern>
3950 : T2I<oops, iops, itin, opc, asm, pattern>,
3951 Requires<[IsThumb2,IsNotMClass]> {
3952 let Inst{31-20} = op31_20{11-0};
3955 let Inst{19-16} = Rn;
3956 let Inst{15-0} = 0xc000;
3959 def t2RFEDBW : T2RFE<0b111010000011,
3960 (outs), (ins GPR:$Rn), NoItinerary, "rfedb", "\t$Rn!",
3961 [/* For disassembly only; pattern left blank */]>;
3962 def t2RFEDB : T2RFE<0b111010000001,
3963 (outs), (ins GPR:$Rn), NoItinerary, "rfedb", "\t$Rn",
3964 [/* For disassembly only; pattern left blank */]>;
3965 def t2RFEIAW : T2RFE<0b111010011011,
3966 (outs), (ins GPR:$Rn), NoItinerary, "rfeia", "\t$Rn!",
3967 [/* For disassembly only; pattern left blank */]>;
3968 def t2RFEIA : T2RFE<0b111010011001,
3969 (outs), (ins GPR:$Rn), NoItinerary, "rfeia", "\t$Rn",
3970 [/* For disassembly only; pattern left blank */]>;
3972 // B9.3.19 SUBS PC, LR, #imm (Thumb2) system instruction.
3973 // Exception return instruction is "subs pc, lr, #imm".
3974 let isReturn = 1, isBarrier = 1, isTerminator = 1, Defs = [PC] in
3975 def t2SUBS_PC_LR : T2I <(outs), (ins imm0_255:$imm), NoItinerary,
3976 "subs", "\tpc, lr, $imm",
3977 [(ARMintretflag imm0_255:$imm)]>,
3978 Requires<[IsThumb2,IsNotMClass]> {
3979 let Inst{31-8} = 0b111100111101111010001111;
3982 let Inst{7-0} = imm;
3985 // Hypervisor Call is a system instruction.
3987 def t2HVC : T2XI <(outs), (ins imm0_65535:$imm16), IIC_Br, "hvc.w\t$imm16", []>,
3988 Requires<[IsThumb2, HasVirtualization]>, Sched<[WriteBr]> {
3990 let Inst{31-20} = 0b111101111110;
3991 let Inst{19-16} = imm16{15-12};
3992 let Inst{15-12} = 0b1000;
3993 let Inst{11-0} = imm16{11-0};
3997 // Alias for HVC without the ".w" optional width specifier
3998 def : t2InstAlias<"hvc\t$imm16", (t2HVC imm0_65535:$imm16)>;
4000 // ERET - Return from exception in Hypervisor mode.
4001 // B9.3.3, B9.3.20: ERET is an alias for "SUBS PC, LR, #0" in an implementation that
4002 // includes virtualization extensions.
4003 def t2ERET : InstAlias<"eret${p}", (t2SUBS_PC_LR 0, pred:$p), 1>,
4004 Requires<[IsThumb2, HasVirtualization]>;
4006 //===----------------------------------------------------------------------===//
4007 // Non-Instruction Patterns
4010 // 32-bit immediate using movw + movt.
4011 // This is a single pseudo instruction to make it re-materializable.
4012 // FIXME: Remove this when we can do generalized remat.
4013 let isReMaterializable = 1, isMoveImm = 1 in
4014 def t2MOVi32imm : PseudoInst<(outs rGPR:$dst), (ins i32imm:$src), IIC_iMOVix2,
4015 [(set rGPR:$dst, (i32 imm:$src))]>,
4016 Requires<[IsThumb, UseMovt]>;
4018 // Pseudo instruction that combines movw + movt + add pc (if pic).
4019 // It also makes it possible to rematerialize the instructions.
4020 // FIXME: Remove this when we can do generalized remat and when machine licm
4021 // can properly the instructions.
4022 let isReMaterializable = 1 in {
4023 def t2MOV_ga_pcrel : PseudoInst<(outs rGPR:$dst), (ins i32imm:$addr),
4025 [(set rGPR:$dst, (ARMWrapperPIC tglobaladdr:$addr))]>,
4026 Requires<[IsThumb, HasV8MBaseline, UseMovtInPic]>;
4030 def : T2Pat<(ARMWrapperPIC tglobaltlsaddr :$dst),
4031 (t2MOV_ga_pcrel tglobaltlsaddr:$dst)>,
4032 Requires<[IsThumb2, UseMovtInPic]>;
4033 def : T2Pat<(ARMWrapper tglobaltlsaddr:$dst),
4034 (t2MOVi32imm tglobaltlsaddr:$dst)>,
4035 Requires<[IsThumb2, UseMovt]>;
4037 // ConstantPool, GlobalAddress, and JumpTable
4038 def : T2Pat<(ARMWrapper tconstpool :$dst), (t2LEApcrel tconstpool :$dst)>;
4039 def : T2Pat<(ARMWrapper texternalsym :$dst), (t2MOVi32imm texternalsym :$dst)>,
4040 Requires<[IsThumb, HasV8MBaseline, UseMovt]>;
4041 def : T2Pat<(ARMWrapper tglobaladdr :$dst), (t2MOVi32imm tglobaladdr :$dst)>,
4042 Requires<[IsThumb, HasV8MBaseline, UseMovt]>;
4044 def : T2Pat<(ARMWrapperJT tjumptable:$dst), (t2LEApcrelJT tjumptable:$dst)>;
4046 // Pseudo instruction that combines ldr from constpool and add pc. This should
4047 // be expanded into two instructions late to allow if-conversion and
4049 let canFoldAsLoad = 1, isReMaterializable = 1 in
4050 def t2LDRpci_pic : PseudoInst<(outs rGPR:$dst), (ins i32imm:$addr, pclabel:$cp),
4052 [(set rGPR:$dst, (ARMpic_add (load (ARMWrapper tconstpool:$addr)),
4054 Requires<[IsThumb2]>;
4056 // Pseudo isntruction that combines movs + predicated rsbmi
4057 // to implement integer ABS
4058 let usesCustomInserter = 1, Defs = [CPSR] in {
4059 def t2ABS : PseudoInst<(outs rGPR:$dst), (ins rGPR:$src),
4060 NoItinerary, []>, Requires<[IsThumb2]>;
4063 //===----------------------------------------------------------------------===//
4064 // Coprocessor load/store -- for disassembly only
4066 class T2CI<bits<4> op31_28, dag oops, dag iops, string opc, string asm, list<dag> pattern>
4067 : T2I<oops, iops, NoItinerary, opc, asm, pattern> {
4068 let Inst{31-28} = op31_28;
4069 let Inst{27-25} = 0b110;
4072 multiclass t2LdStCop<bits<4> op31_28, bit load, bit Dbit, string asm, list<dag> pattern> {
4073 def _OFFSET : T2CI<op31_28,
4074 (outs), (ins p_imm:$cop, c_imm:$CRd, addrmode5:$addr),
4075 asm, "\t$cop, $CRd, $addr", pattern> {
4079 let Inst{24} = 1; // P = 1
4080 let Inst{23} = addr{8};
4081 let Inst{22} = Dbit;
4082 let Inst{21} = 0; // W = 0
4083 let Inst{20} = load;
4084 let Inst{19-16} = addr{12-9};
4085 let Inst{15-12} = CRd;
4086 let Inst{11-8} = cop;
4087 let Inst{7-0} = addr{7-0};
4088 let DecoderMethod = "DecodeCopMemInstruction";
4090 def _PRE : T2CI<op31_28,
4091 (outs), (ins p_imm:$cop, c_imm:$CRd, addrmode5_pre:$addr),
4092 asm, "\t$cop, $CRd, $addr!", []> {
4096 let Inst{24} = 1; // P = 1
4097 let Inst{23} = addr{8};
4098 let Inst{22} = Dbit;
4099 let Inst{21} = 1; // W = 1
4100 let Inst{20} = load;
4101 let Inst{19-16} = addr{12-9};
4102 let Inst{15-12} = CRd;
4103 let Inst{11-8} = cop;
4104 let Inst{7-0} = addr{7-0};
4105 let DecoderMethod = "DecodeCopMemInstruction";
4107 def _POST: T2CI<op31_28,
4108 (outs), (ins p_imm:$cop, c_imm:$CRd, addr_offset_none:$addr,
4109 postidx_imm8s4:$offset),
4110 asm, "\t$cop, $CRd, $addr, $offset", []> {
4115 let Inst{24} = 0; // P = 0
4116 let Inst{23} = offset{8};
4117 let Inst{22} = Dbit;
4118 let Inst{21} = 1; // W = 1
4119 let Inst{20} = load;
4120 let Inst{19-16} = addr;
4121 let Inst{15-12} = CRd;
4122 let Inst{11-8} = cop;
4123 let Inst{7-0} = offset{7-0};
4124 let DecoderMethod = "DecodeCopMemInstruction";
4126 def _OPTION : T2CI<op31_28, (outs),
4127 (ins p_imm:$cop, c_imm:$CRd, addr_offset_none:$addr,
4128 coproc_option_imm:$option),
4129 asm, "\t$cop, $CRd, $addr, $option", []> {
4134 let Inst{24} = 0; // P = 0
4135 let Inst{23} = 1; // U = 1
4136 let Inst{22} = Dbit;
4137 let Inst{21} = 0; // W = 0
4138 let Inst{20} = load;
4139 let Inst{19-16} = addr;
4140 let Inst{15-12} = CRd;
4141 let Inst{11-8} = cop;
4142 let Inst{7-0} = option;
4143 let DecoderMethod = "DecodeCopMemInstruction";
4147 let DecoderNamespace = "Thumb2CoProc" in {
4148 defm t2LDC : t2LdStCop<0b1110, 1, 0, "ldc", [(int_arm_ldc imm:$cop, imm:$CRd, addrmode5:$addr)]>;
4149 defm t2LDCL : t2LdStCop<0b1110, 1, 1, "ldcl", [(int_arm_ldcl imm:$cop, imm:$CRd, addrmode5:$addr)]>;
4150 defm t2LDC2 : t2LdStCop<0b1111, 1, 0, "ldc2", [(int_arm_ldc2 imm:$cop, imm:$CRd, addrmode5:$addr)]>, Requires<[PreV8,IsThumb2]>;
4151 defm t2LDC2L : t2LdStCop<0b1111, 1, 1, "ldc2l", [(int_arm_ldc2l imm:$cop, imm:$CRd, addrmode5:$addr)]>, Requires<[PreV8,IsThumb2]>;
4153 defm t2STC : t2LdStCop<0b1110, 0, 0, "stc", [(int_arm_stc imm:$cop, imm:$CRd, addrmode5:$addr)]>;
4154 defm t2STCL : t2LdStCop<0b1110, 0, 1, "stcl", [(int_arm_stcl imm:$cop, imm:$CRd, addrmode5:$addr)]>;
4155 defm t2STC2 : t2LdStCop<0b1111, 0, 0, "stc2", [(int_arm_stc2 imm:$cop, imm:$CRd, addrmode5:$addr)]>, Requires<[PreV8,IsThumb2]>;
4156 defm t2STC2L : t2LdStCop<0b1111, 0, 1, "stc2l", [(int_arm_stc2l imm:$cop, imm:$CRd, addrmode5:$addr)]>, Requires<[PreV8,IsThumb2]>;
4160 //===----------------------------------------------------------------------===//
4161 // Move between special register and ARM core register -- for disassembly only
4163 // Move to ARM core register from Special Register
4167 // A/R class can only move from CPSR or SPSR.
4168 def t2MRS_AR : T2I<(outs GPR:$Rd), (ins), NoItinerary, "mrs", "\t$Rd, apsr",
4169 []>, Requires<[IsThumb2,IsNotMClass]> {
4171 let Inst{31-12} = 0b11110011111011111000;
4172 let Inst{11-8} = Rd;
4173 let Inst{7-0} = 0b00000000;
4176 def : t2InstAlias<"mrs${p} $Rd, cpsr", (t2MRS_AR GPR:$Rd, pred:$p)>;
4178 def t2MRSsys_AR: T2I<(outs GPR:$Rd), (ins), NoItinerary, "mrs", "\t$Rd, spsr",
4179 []>, Requires<[IsThumb2,IsNotMClass]> {
4181 let Inst{31-12} = 0b11110011111111111000;
4182 let Inst{11-8} = Rd;
4183 let Inst{7-0} = 0b00000000;
4186 def t2MRSbanked : T2I<(outs rGPR:$Rd), (ins banked_reg:$banked),
4187 NoItinerary, "mrs", "\t$Rd, $banked", []>,
4188 Requires<[IsThumb, HasVirtualization]> {
4192 let Inst{31-21} = 0b11110011111;
4193 let Inst{20} = banked{5}; // R bit
4194 let Inst{19-16} = banked{3-0};
4195 let Inst{15-12} = 0b1000;
4196 let Inst{11-8} = Rd;
4197 let Inst{7-5} = 0b001;
4198 let Inst{4} = banked{4};
4199 let Inst{3-0} = 0b0000;
4205 // This MRS has a mask field in bits 7-0 and can take more values than
4206 // the A/R class (a full msr_mask).
4207 def t2MRS_M : T2I<(outs rGPR:$Rd), (ins msr_mask:$SYSm), NoItinerary,
4208 "mrs", "\t$Rd, $SYSm", []>,
4209 Requires<[IsThumb,IsMClass]> {
4212 let Inst{31-12} = 0b11110011111011111000;
4213 let Inst{11-8} = Rd;
4214 let Inst{7-0} = SYSm;
4216 let Unpredictable{20-16} = 0b11111;
4217 let Unpredictable{13} = 0b1;
4221 // Move from ARM core register to Special Register
4225 // No need to have both system and application versions, the encodings are the
4226 // same and the assembly parser has no way to distinguish between them. The mask
4227 // operand contains the special register (R Bit) in bit 4 and bits 3-0 contains
4228 // the mask with the fields to be accessed in the special register.
4229 let Defs = [CPSR] in
4230 def t2MSR_AR : T2I<(outs), (ins msr_mask:$mask, rGPR:$Rn),
4231 NoItinerary, "msr", "\t$mask, $Rn", []>,
4232 Requires<[IsThumb2,IsNotMClass]> {
4235 let Inst{31-21} = 0b11110011100;
4236 let Inst{20} = mask{4}; // R Bit
4237 let Inst{19-16} = Rn;
4238 let Inst{15-12} = 0b1000;
4239 let Inst{11-8} = mask{3-0};
4243 // However, the MSR (banked register) system instruction (ARMv7VE) *does* have a
4244 // separate encoding (distinguished by bit 5.
4245 def t2MSRbanked : T2I<(outs), (ins banked_reg:$banked, rGPR:$Rn),
4246 NoItinerary, "msr", "\t$banked, $Rn", []>,
4247 Requires<[IsThumb, HasVirtualization]> {
4251 let Inst{31-21} = 0b11110011100;
4252 let Inst{20} = banked{5}; // R bit
4253 let Inst{19-16} = Rn;
4254 let Inst{15-12} = 0b1000;
4255 let Inst{11-8} = banked{3-0};
4256 let Inst{7-5} = 0b001;
4257 let Inst{4} = banked{4};
4258 let Inst{3-0} = 0b0000;
4264 // Move from ARM core register to Special Register
4265 let Defs = [CPSR] in
4266 def t2MSR_M : T2I<(outs), (ins msr_mask:$SYSm, rGPR:$Rn),
4267 NoItinerary, "msr", "\t$SYSm, $Rn", []>,
4268 Requires<[IsThumb,IsMClass]> {
4271 let Inst{31-21} = 0b11110011100;
4273 let Inst{19-16} = Rn;
4274 let Inst{15-12} = 0b1000;
4275 let Inst{11-10} = SYSm{11-10};
4276 let Inst{9-8} = 0b00;
4277 let Inst{7-0} = SYSm{7-0};
4279 let Unpredictable{20} = 0b1;
4280 let Unpredictable{13} = 0b1;
4281 let Unpredictable{9-8} = 0b11;
4285 //===----------------------------------------------------------------------===//
4286 // Move between coprocessor and ARM core register
4289 class t2MovRCopro<bits<4> Op, string opc, bit direction, dag oops, dag iops,
4291 : T2Cop<Op, oops, iops, opc, "\t$cop, $opc1, $Rt, $CRn, $CRm, $opc2",
4293 let Inst{27-24} = 0b1110;
4294 let Inst{20} = direction;
4304 let Inst{15-12} = Rt;
4305 let Inst{11-8} = cop;
4306 let Inst{23-21} = opc1;
4307 let Inst{7-5} = opc2;
4308 let Inst{3-0} = CRm;
4309 let Inst{19-16} = CRn;
4311 let DecoderNamespace = "Thumb2CoProc";
4314 class t2MovRRCopro<bits<4> Op, string opc, bit direction, dag oops, dag iops,
4315 list<dag> pattern = []>
4316 : T2Cop<Op, oops, iops, opc, "\t$cop, $opc1, $Rt, $Rt2, $CRm", pattern> {
4317 let Inst{27-24} = 0b1100;
4318 let Inst{23-21} = 0b010;
4319 let Inst{20} = direction;
4327 let Inst{15-12} = Rt;
4328 let Inst{19-16} = Rt2;
4329 let Inst{11-8} = cop;
4330 let Inst{7-4} = opc1;
4331 let Inst{3-0} = CRm;
4333 let DecoderNamespace = "Thumb2CoProc";
4336 /* from ARM core register to coprocessor */
4337 def t2MCR : t2MovRCopro<0b1110, "mcr", 0,
4339 (ins p_imm:$cop, imm0_7:$opc1, GPR:$Rt, c_imm:$CRn,
4340 c_imm:$CRm, imm0_7:$opc2),
4341 [(int_arm_mcr imm:$cop, imm:$opc1, GPR:$Rt, imm:$CRn,
4342 imm:$CRm, imm:$opc2)]>,
4343 ComplexDeprecationPredicate<"MCR">;
4344 def : t2InstAlias<"mcr${p} $cop, $opc1, $Rt, $CRn, $CRm",
4345 (t2MCR p_imm:$cop, imm0_7:$opc1, GPR:$Rt, c_imm:$CRn,
4346 c_imm:$CRm, 0, pred:$p)>;
4347 def t2MCR2 : t2MovRCopro<0b1111, "mcr2", 0,
4348 (outs), (ins p_imm:$cop, imm0_7:$opc1, GPR:$Rt, c_imm:$CRn,
4349 c_imm:$CRm, imm0_7:$opc2),
4350 [(int_arm_mcr2 imm:$cop, imm:$opc1, GPR:$Rt, imm:$CRn,
4351 imm:$CRm, imm:$opc2)]> {
4352 let Predicates = [IsThumb2, PreV8];
4354 def : t2InstAlias<"mcr2${p} $cop, $opc1, $Rt, $CRn, $CRm",
4355 (t2MCR2 p_imm:$cop, imm0_7:$opc1, GPR:$Rt, c_imm:$CRn,
4356 c_imm:$CRm, 0, pred:$p)>;
4358 /* from coprocessor to ARM core register */
4359 def t2MRC : t2MovRCopro<0b1110, "mrc", 1,
4360 (outs GPRwithAPSR:$Rt), (ins p_imm:$cop, imm0_7:$opc1, c_imm:$CRn,
4361 c_imm:$CRm, imm0_7:$opc2), []>;
4362 def : t2InstAlias<"mrc${p} $cop, $opc1, $Rt, $CRn, $CRm",
4363 (t2MRC GPRwithAPSR:$Rt, p_imm:$cop, imm0_7:$opc1, c_imm:$CRn,
4364 c_imm:$CRm, 0, pred:$p)>;
4366 def t2MRC2 : t2MovRCopro<0b1111, "mrc2", 1,
4367 (outs GPRwithAPSR:$Rt), (ins p_imm:$cop, imm0_7:$opc1, c_imm:$CRn,
4368 c_imm:$CRm, imm0_7:$opc2), []> {
4369 let Predicates = [IsThumb2, PreV8];
4371 def : t2InstAlias<"mrc2${p} $cop, $opc1, $Rt, $CRn, $CRm",
4372 (t2MRC2 GPRwithAPSR:$Rt, p_imm:$cop, imm0_7:$opc1, c_imm:$CRn,
4373 c_imm:$CRm, 0, pred:$p)>;
4375 def : T2v6Pat<(int_arm_mrc imm:$cop, imm:$opc1, imm:$CRn, imm:$CRm, imm:$opc2),
4376 (t2MRC imm:$cop, imm:$opc1, imm:$CRn, imm:$CRm, imm:$opc2)>;
4378 def : T2v6Pat<(int_arm_mrc2 imm:$cop, imm:$opc1, imm:$CRn, imm:$CRm, imm:$opc2),
4379 (t2MRC2 imm:$cop, imm:$opc1, imm:$CRn, imm:$CRm, imm:$opc2)>;
4382 /* from ARM core register to coprocessor */
4383 def t2MCRR : t2MovRRCopro<0b1110, "mcrr", 0, (outs),
4384 (ins p_imm:$cop, imm0_15:$opc1, GPR:$Rt, GPR:$Rt2,
4386 [(int_arm_mcrr imm:$cop, imm:$opc1, GPR:$Rt, GPR:$Rt2,
4388 def t2MCRR2 : t2MovRRCopro<0b1111, "mcrr2", 0, (outs),
4389 (ins p_imm:$cop, imm0_15:$opc1, GPR:$Rt, GPR:$Rt2,
4391 [(int_arm_mcrr2 imm:$cop, imm:$opc1, GPR:$Rt,
4392 GPR:$Rt2, imm:$CRm)]> {
4393 let Predicates = [IsThumb2, PreV8];
4396 /* from coprocessor to ARM core register */
4397 def t2MRRC : t2MovRRCopro<0b1110, "mrrc", 1, (outs GPR:$Rt, GPR:$Rt2),
4398 (ins p_imm:$cop, imm0_15:$opc1, c_imm:$CRm)>;
4400 def t2MRRC2 : t2MovRRCopro<0b1111, "mrrc2", 1, (outs GPR:$Rt, GPR:$Rt2),
4401 (ins p_imm:$cop, imm0_15:$opc1, c_imm:$CRm)> {
4402 let Predicates = [IsThumb2, PreV8];
4405 //===----------------------------------------------------------------------===//
4406 // Other Coprocessor Instructions.
4409 def t2CDP : T2Cop<0b1110, (outs), (ins p_imm:$cop, imm0_15:$opc1,
4410 c_imm:$CRd, c_imm:$CRn, c_imm:$CRm, imm0_7:$opc2),
4411 "cdp", "\t$cop, $opc1, $CRd, $CRn, $CRm, $opc2",
4412 [(int_arm_cdp imm:$cop, imm:$opc1, imm:$CRd, imm:$CRn,
4413 imm:$CRm, imm:$opc2)]> {
4414 let Inst{27-24} = 0b1110;
4423 let Inst{3-0} = CRm;
4425 let Inst{7-5} = opc2;
4426 let Inst{11-8} = cop;
4427 let Inst{15-12} = CRd;
4428 let Inst{19-16} = CRn;
4429 let Inst{23-20} = opc1;
4431 let Predicates = [IsThumb2, PreV8];
4432 let DecoderNamespace = "Thumb2CoProc";
4435 def t2CDP2 : T2Cop<0b1111, (outs), (ins p_imm:$cop, imm0_15:$opc1,
4436 c_imm:$CRd, c_imm:$CRn, c_imm:$CRm, imm0_7:$opc2),
4437 "cdp2", "\t$cop, $opc1, $CRd, $CRn, $CRm, $opc2",
4438 [(int_arm_cdp2 imm:$cop, imm:$opc1, imm:$CRd, imm:$CRn,
4439 imm:$CRm, imm:$opc2)]> {
4440 let Inst{27-24} = 0b1110;
4449 let Inst{3-0} = CRm;
4451 let Inst{7-5} = opc2;
4452 let Inst{11-8} = cop;
4453 let Inst{15-12} = CRd;
4454 let Inst{19-16} = CRn;
4455 let Inst{23-20} = opc1;
4457 let Predicates = [IsThumb2, PreV8];
4458 let DecoderNamespace = "Thumb2CoProc";
4463 //===----------------------------------------------------------------------===//
4464 // ARMv8.1 Privilege Access Never extension
4468 def t2SETPAN : T1I<(outs), (ins imm0_1:$imm), NoItinerary, "setpan\t$imm", []>,
4469 T1Misc<0b0110000>, Requires<[IsThumb2, HasV8, HasV8_1a]> {
4474 let Inst{2-0} = 0b000;
4476 let Unpredictable{4} = 0b1;
4477 let Unpredictable{2-0} = 0b111;
4480 //===----------------------------------------------------------------------===//
4481 // ARMv8-M Security Extensions instructions
4484 let hasSideEffects = 1 in
4485 def t2SG : T2I<(outs), (ins), NoItinerary, "sg", "", []>,
4486 Requires<[Has8MSecExt]> {
4487 let Inst = 0xe97fe97f;
4490 class T2TT<bits<2> at, string asm, list<dag> pattern>
4491 : T2I<(outs rGPR:$Rt), (ins GPRnopc:$Rn), NoItinerary, asm, "\t$Rt, $Rn",
4496 let Inst{31-20} = 0b111010000100;
4497 let Inst{19-16} = Rn;
4498 let Inst{15-12} = 0b1111;
4499 let Inst{11-8} = Rt;
4501 let Inst{5-0} = 0b000000;
4503 let Unpredictable{5-0} = 0b111111;
4506 def t2TT : T2TT<0b00, "tt", []>, Requires<[IsThumb,Has8MSecExt]>;
4507 def t2TTT : T2TT<0b01, "ttt", []>, Requires<[IsThumb,Has8MSecExt]>;
4508 def t2TTA : T2TT<0b10, "tta", []>, Requires<[IsThumb,Has8MSecExt]>;
4509 def t2TTAT : T2TT<0b11, "ttat", []>, Requires<[IsThumb,Has8MSecExt]>;
4511 //===----------------------------------------------------------------------===//
4512 // Non-Instruction Patterns
4515 // SXT/UXT with no rotate
4516 let AddedComplexity = 16 in {
4517 def : T2Pat<(and rGPR:$Rm, 0x000000FF), (t2UXTB rGPR:$Rm, 0)>,
4518 Requires<[IsThumb2]>;
4519 def : T2Pat<(and rGPR:$Rm, 0x0000FFFF), (t2UXTH rGPR:$Rm, 0)>,
4520 Requires<[IsThumb2]>;
4521 def : T2Pat<(and rGPR:$Rm, 0x00FF00FF), (t2UXTB16 rGPR:$Rm, 0)>,
4522 Requires<[HasDSP, IsThumb2]>;
4523 def : T2Pat<(add rGPR:$Rn, (and rGPR:$Rm, 0x00FF)),
4524 (t2UXTAB rGPR:$Rn, rGPR:$Rm, 0)>,
4525 Requires<[HasDSP, IsThumb2]>;
4526 def : T2Pat<(add rGPR:$Rn, (and rGPR:$Rm, 0xFFFF)),
4527 (t2UXTAH rGPR:$Rn, rGPR:$Rm, 0)>,
4528 Requires<[HasDSP, IsThumb2]>;
4531 def : T2Pat<(sext_inreg rGPR:$Src, i8), (t2SXTB rGPR:$Src, 0)>,
4532 Requires<[IsThumb2]>;
4533 def : T2Pat<(sext_inreg rGPR:$Src, i16), (t2SXTH rGPR:$Src, 0)>,
4534 Requires<[IsThumb2]>;
4535 def : T2Pat<(add rGPR:$Rn, (sext_inreg rGPR:$Rm, i8)),
4536 (t2SXTAB rGPR:$Rn, rGPR:$Rm, 0)>,
4537 Requires<[HasDSP, IsThumb2]>;
4538 def : T2Pat<(add rGPR:$Rn, (sext_inreg rGPR:$Rm, i16)),
4539 (t2SXTAH rGPR:$Rn, rGPR:$Rm, 0)>,
4540 Requires<[HasDSP, IsThumb2]>;
4542 // Atomic load/store patterns
4543 def : T2Pat<(atomic_load_8 t2addrmode_imm12:$addr),
4544 (t2LDRBi12 t2addrmode_imm12:$addr)>;
4545 def : T2Pat<(atomic_load_8 t2addrmode_negimm8:$addr),
4546 (t2LDRBi8 t2addrmode_negimm8:$addr)>;
4547 def : T2Pat<(atomic_load_8 t2addrmode_so_reg:$addr),
4548 (t2LDRBs t2addrmode_so_reg:$addr)>;
4549 def : T2Pat<(atomic_load_16 t2addrmode_imm12:$addr),
4550 (t2LDRHi12 t2addrmode_imm12:$addr)>;
4551 def : T2Pat<(atomic_load_16 t2addrmode_negimm8:$addr),
4552 (t2LDRHi8 t2addrmode_negimm8:$addr)>;
4553 def : T2Pat<(atomic_load_16 t2addrmode_so_reg:$addr),
4554 (t2LDRHs t2addrmode_so_reg:$addr)>;
4555 def : T2Pat<(atomic_load_32 t2addrmode_imm12:$addr),
4556 (t2LDRi12 t2addrmode_imm12:$addr)>;
4557 def : T2Pat<(atomic_load_32 t2addrmode_negimm8:$addr),
4558 (t2LDRi8 t2addrmode_negimm8:$addr)>;
4559 def : T2Pat<(atomic_load_32 t2addrmode_so_reg:$addr),
4560 (t2LDRs t2addrmode_so_reg:$addr)>;
4561 def : T2Pat<(atomic_store_8 t2addrmode_imm12:$addr, GPR:$val),
4562 (t2STRBi12 GPR:$val, t2addrmode_imm12:$addr)>;
4563 def : T2Pat<(atomic_store_8 t2addrmode_negimm8:$addr, GPR:$val),
4564 (t2STRBi8 GPR:$val, t2addrmode_negimm8:$addr)>;
4565 def : T2Pat<(atomic_store_8 t2addrmode_so_reg:$addr, GPR:$val),
4566 (t2STRBs GPR:$val, t2addrmode_so_reg:$addr)>;
4567 def : T2Pat<(atomic_store_16 t2addrmode_imm12:$addr, GPR:$val),
4568 (t2STRHi12 GPR:$val, t2addrmode_imm12:$addr)>;
4569 def : T2Pat<(atomic_store_16 t2addrmode_negimm8:$addr, GPR:$val),
4570 (t2STRHi8 GPR:$val, t2addrmode_negimm8:$addr)>;
4571 def : T2Pat<(atomic_store_16 t2addrmode_so_reg:$addr, GPR:$val),
4572 (t2STRHs GPR:$val, t2addrmode_so_reg:$addr)>;
4573 def : T2Pat<(atomic_store_32 t2addrmode_imm12:$addr, GPR:$val),
4574 (t2STRi12 GPR:$val, t2addrmode_imm12:$addr)>;
4575 def : T2Pat<(atomic_store_32 t2addrmode_negimm8:$addr, GPR:$val),
4576 (t2STRi8 GPR:$val, t2addrmode_negimm8:$addr)>;
4577 def : T2Pat<(atomic_store_32 t2addrmode_so_reg:$addr, GPR:$val),
4578 (t2STRs GPR:$val, t2addrmode_so_reg:$addr)>;
4580 let AddedComplexity = 8, Predicates = [IsThumb, HasAcquireRelease, HasV7Clrex] in {
4581 def : Pat<(atomic_load_acquire_8 addr_offset_none:$addr), (t2LDAB addr_offset_none:$addr)>;
4582 def : Pat<(atomic_load_acquire_16 addr_offset_none:$addr), (t2LDAH addr_offset_none:$addr)>;
4583 def : Pat<(atomic_load_acquire_32 addr_offset_none:$addr), (t2LDA addr_offset_none:$addr)>;
4584 def : Pat<(atomic_store_release_8 addr_offset_none:$addr, GPR:$val), (t2STLB GPR:$val, addr_offset_none:$addr)>;
4585 def : Pat<(atomic_store_release_16 addr_offset_none:$addr, GPR:$val), (t2STLH GPR:$val, addr_offset_none:$addr)>;
4586 def : Pat<(atomic_store_release_32 addr_offset_none:$addr, GPR:$val), (t2STL GPR:$val, addr_offset_none:$addr)>;
4590 //===----------------------------------------------------------------------===//
4591 // Assembler aliases
4594 // Aliases for ADC without the ".w" optional width specifier.
4595 def : t2InstAlias<"adc${s}${p} $Rd, $Rn, $Rm",
4596 (t2ADCrr rGPR:$Rd, rGPR:$Rn, rGPR:$Rm, pred:$p, cc_out:$s)>;
4597 def : t2InstAlias<"adc${s}${p} $Rd, $Rn, $ShiftedRm",
4598 (t2ADCrs rGPR:$Rd, rGPR:$Rn, t2_so_reg:$ShiftedRm,
4599 pred:$p, cc_out:$s)>;
4601 // Aliases for SBC without the ".w" optional width specifier.
4602 def : t2InstAlias<"sbc${s}${p} $Rd, $Rn, $Rm",
4603 (t2SBCrr rGPR:$Rd, rGPR:$Rn, rGPR:$Rm, pred:$p, cc_out:$s)>;
4604 def : t2InstAlias<"sbc${s}${p} $Rd, $Rn, $ShiftedRm",
4605 (t2SBCrs rGPR:$Rd, rGPR:$Rn, t2_so_reg:$ShiftedRm,
4606 pred:$p, cc_out:$s)>;
4608 // Aliases for ADD without the ".w" optional width specifier.
4609 def : t2InstAlias<"add${s}${p} $Rd, $Rn, $imm",
4610 (t2ADDri GPRnopc:$Rd, GPRnopc:$Rn, t2_so_imm:$imm, pred:$p,
4612 def : t2InstAlias<"add${p} $Rd, $Rn, $imm",
4613 (t2ADDri12 GPRnopc:$Rd, GPR:$Rn, imm0_4095:$imm, pred:$p)>;
4614 def : t2InstAlias<"add${s}${p} $Rd, $Rn, $Rm",
4615 (t2ADDrr GPRnopc:$Rd, GPRnopc:$Rn, rGPR:$Rm, pred:$p, cc_out:$s)>;
4616 def : t2InstAlias<"add${s}${p} $Rd, $Rn, $ShiftedRm",
4617 (t2ADDrs GPRnopc:$Rd, GPRnopc:$Rn, t2_so_reg:$ShiftedRm,
4618 pred:$p, cc_out:$s)>;
4619 // ... and with the destination and source register combined.
4620 def : t2InstAlias<"add${s}${p} $Rdn, $imm",
4621 (t2ADDri GPRnopc:$Rdn, GPRnopc:$Rdn, t2_so_imm:$imm, pred:$p, cc_out:$s)>;
4622 def : t2InstAlias<"add${p} $Rdn, $imm",
4623 (t2ADDri12 GPRnopc:$Rdn, GPRnopc:$Rdn, imm0_4095:$imm, pred:$p)>;
4624 def : t2InstAlias<"add${s}${p} $Rdn, $Rm",
4625 (t2ADDrr GPRnopc:$Rdn, GPRnopc:$Rdn, rGPR:$Rm, pred:$p, cc_out:$s)>;
4626 def : t2InstAlias<"add${s}${p} $Rdn, $ShiftedRm",
4627 (t2ADDrs GPRnopc:$Rdn, GPRnopc:$Rdn, t2_so_reg:$ShiftedRm,
4628 pred:$p, cc_out:$s)>;
4630 // add w/ negative immediates is just a sub.
4631 def : t2InstSubst<"add${s}${p} $Rd, $Rn, $imm",
4632 (t2SUBri GPRnopc:$Rd, GPRnopc:$Rn, t2_so_imm_neg:$imm, pred:$p,
4634 def : t2InstSubst<"add${p} $Rd, $Rn, $imm",
4635 (t2SUBri12 GPRnopc:$Rd, GPR:$Rn, imm0_4095_neg:$imm, pred:$p)>;
4636 def : t2InstSubst<"add${s}${p} $Rdn, $imm",
4637 (t2SUBri GPRnopc:$Rdn, GPRnopc:$Rdn, t2_so_imm_neg:$imm, pred:$p,
4639 def : t2InstSubst<"add${p} $Rdn, $imm",
4640 (t2SUBri12 GPRnopc:$Rdn, GPRnopc:$Rdn, imm0_4095_neg:$imm, pred:$p)>;
4642 def : t2InstSubst<"add${s}${p}.w $Rd, $Rn, $imm",
4643 (t2SUBri GPRnopc:$Rd, GPRnopc:$Rn, t2_so_imm_neg:$imm, pred:$p,
4645 def : t2InstSubst<"addw${p} $Rd, $Rn, $imm",
4646 (t2SUBri12 GPRnopc:$Rd, GPR:$Rn, imm0_4095_neg:$imm, pred:$p)>;
4647 def : t2InstSubst<"add${s}${p}.w $Rdn, $imm",
4648 (t2SUBri GPRnopc:$Rdn, GPRnopc:$Rdn, t2_so_imm_neg:$imm, pred:$p,
4650 def : t2InstSubst<"addw${p} $Rdn, $imm",
4651 (t2SUBri12 GPRnopc:$Rdn, GPRnopc:$Rdn, imm0_4095_neg:$imm, pred:$p)>;
4654 // Aliases for SUB without the ".w" optional width specifier.
4655 def : t2InstAlias<"sub${s}${p} $Rd, $Rn, $imm",
4656 (t2SUBri GPRnopc:$Rd, GPRnopc:$Rn, t2_so_imm:$imm, pred:$p, cc_out:$s)>;
4657 def : t2InstAlias<"sub${p} $Rd, $Rn, $imm",
4658 (t2SUBri12 GPRnopc:$Rd, GPR:$Rn, imm0_4095:$imm, pred:$p)>;
4659 def : t2InstAlias<"sub${s}${p} $Rd, $Rn, $Rm",
4660 (t2SUBrr GPRnopc:$Rd, GPRnopc:$Rn, rGPR:$Rm, pred:$p, cc_out:$s)>;
4661 def : t2InstAlias<"sub${s}${p} $Rd, $Rn, $ShiftedRm",
4662 (t2SUBrs GPRnopc:$Rd, GPRnopc:$Rn, t2_so_reg:$ShiftedRm,
4663 pred:$p, cc_out:$s)>;
4664 // ... and with the destination and source register combined.
4665 def : t2InstAlias<"sub${s}${p} $Rdn, $imm",
4666 (t2SUBri GPRnopc:$Rdn, GPRnopc:$Rdn, t2_so_imm:$imm, pred:$p, cc_out:$s)>;
4667 def : t2InstAlias<"sub${p} $Rdn, $imm",
4668 (t2SUBri12 GPRnopc:$Rdn, GPRnopc:$Rdn, imm0_4095:$imm, pred:$p)>;
4669 def : t2InstAlias<"sub${s}${p}.w $Rdn, $Rm",
4670 (t2SUBrr GPRnopc:$Rdn, GPRnopc:$Rdn, rGPR:$Rm, pred:$p, cc_out:$s)>;
4671 def : t2InstAlias<"sub${s}${p} $Rdn, $Rm",
4672 (t2SUBrr GPRnopc:$Rdn, GPRnopc:$Rdn, rGPR:$Rm, pred:$p, cc_out:$s)>;
4673 def : t2InstAlias<"sub${s}${p} $Rdn, $ShiftedRm",
4674 (t2SUBrs GPRnopc:$Rdn, GPRnopc:$Rdn, t2_so_reg:$ShiftedRm,
4675 pred:$p, cc_out:$s)>;
4677 // Alias for compares without the ".w" optional width specifier.
4678 def : t2InstAlias<"cmn${p} $Rn, $Rm",
4679 (t2CMNzrr GPRnopc:$Rn, rGPR:$Rm, pred:$p)>;
4680 def : t2InstAlias<"teq${p} $Rn, $Rm",
4681 (t2TEQrr rGPR:$Rn, rGPR:$Rm, pred:$p)>;
4682 def : t2InstAlias<"tst${p} $Rn, $Rm",
4683 (t2TSTrr rGPR:$Rn, rGPR:$Rm, pred:$p)>;
4686 def : InstAlias<"dmb${p}", (t2DMB 0xf, pred:$p), 0>, Requires<[HasDB]>;
4687 def : InstAlias<"dsb${p}", (t2DSB 0xf, pred:$p), 0>, Requires<[HasDB]>;
4688 def : InstAlias<"isb${p}", (t2ISB 0xf, pred:$p), 0>, Requires<[HasDB]>;
4690 // Non-predicable aliases of a predicable DSB: the predicate is (14, 0) where
4691 // 14 = AL (always execute) and 0 = "instruction doesn't read the CPSR".
4692 def : InstAlias<"ssbb", (t2DSB 0x0, 14, 0), 1>, Requires<[HasDB, IsThumb2]>;
4693 def : InstAlias<"pssbb", (t2DSB 0x4, 14, 0), 1>, Requires<[HasDB, IsThumb2]>;
4695 // Armv8-R 'Data Full Barrier'
4696 def : InstAlias<"dfb${p}", (t2DSB 0xc, pred:$p), 1>, Requires<[HasDFB]>;
4698 // Alias for LDR, LDRB, LDRH, LDRSB, and LDRSH without the ".w" optional
4700 def : t2InstAlias<"ldr${p} $Rt, $addr",
4701 (t2LDRi12 GPR:$Rt, t2addrmode_imm12:$addr, pred:$p)>;
4702 def : t2InstAlias<"ldrb${p} $Rt, $addr",
4703 (t2LDRBi12 rGPR:$Rt, t2addrmode_imm12:$addr, pred:$p)>;
4704 def : t2InstAlias<"ldrh${p} $Rt, $addr",
4705 (t2LDRHi12 rGPR:$Rt, t2addrmode_imm12:$addr, pred:$p)>;
4706 def : t2InstAlias<"ldrsb${p} $Rt, $addr",
4707 (t2LDRSBi12 rGPR:$Rt, t2addrmode_imm12:$addr, pred:$p)>;
4708 def : t2InstAlias<"ldrsh${p} $Rt, $addr",
4709 (t2LDRSHi12 rGPR:$Rt, t2addrmode_imm12:$addr, pred:$p)>;
4711 def : t2InstAlias<"ldr${p} $Rt, $addr",
4712 (t2LDRs GPR:$Rt, t2addrmode_so_reg:$addr, pred:$p)>;
4713 def : t2InstAlias<"ldrb${p} $Rt, $addr",
4714 (t2LDRBs rGPR:$Rt, t2addrmode_so_reg:$addr, pred:$p)>;
4715 def : t2InstAlias<"ldrh${p} $Rt, $addr",
4716 (t2LDRHs rGPR:$Rt, t2addrmode_so_reg:$addr, pred:$p)>;
4717 def : t2InstAlias<"ldrsb${p} $Rt, $addr",
4718 (t2LDRSBs rGPR:$Rt, t2addrmode_so_reg:$addr, pred:$p)>;
4719 def : t2InstAlias<"ldrsh${p} $Rt, $addr",
4720 (t2LDRSHs rGPR:$Rt, t2addrmode_so_reg:$addr, pred:$p)>;
4722 def : t2InstAlias<"ldr${p} $Rt, $addr",
4723 (t2LDRpci GPR:$Rt, t2ldrlabel:$addr, pred:$p)>;
4724 def : t2InstAlias<"ldrb${p} $Rt, $addr",
4725 (t2LDRBpci rGPR:$Rt, t2ldrlabel:$addr, pred:$p)>;
4726 def : t2InstAlias<"ldrh${p} $Rt, $addr",
4727 (t2LDRHpci rGPR:$Rt, t2ldrlabel:$addr, pred:$p)>;
4728 def : t2InstAlias<"ldrsb${p} $Rt, $addr",
4729 (t2LDRSBpci rGPR:$Rt, t2ldrlabel:$addr, pred:$p)>;
4730 def : t2InstAlias<"ldrsh${p} $Rt, $addr",
4731 (t2LDRSHpci rGPR:$Rt, t2ldrlabel:$addr, pred:$p)>;
4733 // Alias for MVN with(out) the ".w" optional width specifier.
4734 def : t2InstAlias<"mvn${s}${p}.w $Rd, $imm",
4735 (t2MVNi rGPR:$Rd, t2_so_imm:$imm, pred:$p, cc_out:$s)>;
4736 def : t2InstAlias<"mvn${s}${p} $Rd, $Rm",
4737 (t2MVNr rGPR:$Rd, rGPR:$Rm, pred:$p, cc_out:$s)>;
4738 def : t2InstAlias<"mvn${s}${p} $Rd, $ShiftedRm",
4739 (t2MVNs rGPR:$Rd, t2_so_reg:$ShiftedRm, pred:$p, cc_out:$s)>;
4741 // PKHBT/PKHTB with default shift amount. PKHTB is equivalent to PKHBT with the
4742 // input operands swapped when the shift amount is zero (i.e., unspecified).
4743 def : InstAlias<"pkhbt${p} $Rd, $Rn, $Rm",
4744 (t2PKHBT rGPR:$Rd, rGPR:$Rn, rGPR:$Rm, 0, pred:$p), 0>,
4745 Requires<[HasDSP, IsThumb2]>;
4746 def : InstAlias<"pkhtb${p} $Rd, $Rn, $Rm",
4747 (t2PKHBT rGPR:$Rd, rGPR:$Rm, rGPR:$Rn, 0, pred:$p), 0>,
4748 Requires<[HasDSP, IsThumb2]>;
4750 // PUSH/POP aliases for STM/LDM
4751 def : t2InstAlias<"push${p}.w $regs", (t2STMDB_UPD SP, pred:$p, reglist:$regs)>;
4752 def : t2InstAlias<"push${p} $regs", (t2STMDB_UPD SP, pred:$p, reglist:$regs)>;
4753 def : t2InstAlias<"pop${p}.w $regs", (t2LDMIA_UPD SP, pred:$p, reglist:$regs)>;
4754 def : t2InstAlias<"pop${p} $regs", (t2LDMIA_UPD SP, pred:$p, reglist:$regs)>;
4756 // STMIA/STMIA_UPD aliases w/o the optional .w suffix
4757 def : t2InstAlias<"stm${p} $Rn, $regs",
4758 (t2STMIA GPR:$Rn, pred:$p, reglist:$regs)>;
4759 def : t2InstAlias<"stm${p} $Rn!, $regs",
4760 (t2STMIA_UPD GPR:$Rn, pred:$p, reglist:$regs)>;
4762 // LDMIA/LDMIA_UPD aliases w/o the optional .w suffix
4763 def : t2InstAlias<"ldm${p} $Rn, $regs",
4764 (t2LDMIA GPR:$Rn, pred:$p, reglist:$regs)>;
4765 def : t2InstAlias<"ldm${p} $Rn!, $regs",
4766 (t2LDMIA_UPD GPR:$Rn, pred:$p, reglist:$regs)>;
4768 // STMDB/STMDB_UPD aliases w/ the optional .w suffix
4769 def : t2InstAlias<"stmdb${p}.w $Rn, $regs",
4770 (t2STMDB GPR:$Rn, pred:$p, reglist:$regs)>;
4771 def : t2InstAlias<"stmdb${p}.w $Rn!, $regs",
4772 (t2STMDB_UPD GPR:$Rn, pred:$p, reglist:$regs)>;
4774 // LDMDB/LDMDB_UPD aliases w/ the optional .w suffix
4775 def : t2InstAlias<"ldmdb${p}.w $Rn, $regs",
4776 (t2LDMDB GPR:$Rn, pred:$p, reglist:$regs)>;
4777 def : t2InstAlias<"ldmdb${p}.w $Rn!, $regs",
4778 (t2LDMDB_UPD GPR:$Rn, pred:$p, reglist:$regs)>;
4780 // Alias for REV/REV16/REVSH without the ".w" optional width specifier.
4781 def : t2InstAlias<"rev${p} $Rd, $Rm", (t2REV rGPR:$Rd, rGPR:$Rm, pred:$p)>;
4782 def : t2InstAlias<"rev16${p} $Rd, $Rm", (t2REV16 rGPR:$Rd, rGPR:$Rm, pred:$p)>;
4783 def : t2InstAlias<"revsh${p} $Rd, $Rm", (t2REVSH rGPR:$Rd, rGPR:$Rm, pred:$p)>;
4786 // Alias for RSB without the ".w" optional width specifier, and with optional
4787 // implied destination register.
4788 def : t2InstAlias<"rsb${s}${p} $Rd, $Rn, $imm",
4789 (t2RSBri rGPR:$Rd, rGPR:$Rn, t2_so_imm:$imm, pred:$p, cc_out:$s)>;
4790 def : t2InstAlias<"rsb${s}${p} $Rdn, $imm",
4791 (t2RSBri rGPR:$Rdn, rGPR:$Rdn, t2_so_imm:$imm, pred:$p, cc_out:$s)>;
4792 def : t2InstAlias<"rsb${s}${p} $Rdn, $Rm",
4793 (t2RSBrr rGPR:$Rdn, rGPR:$Rdn, rGPR:$Rm, pred:$p, cc_out:$s)>;
4794 def : t2InstAlias<"rsb${s}${p} $Rdn, $ShiftedRm",
4795 (t2RSBrs rGPR:$Rdn, rGPR:$Rdn, t2_so_reg:$ShiftedRm, pred:$p,
4798 // SSAT/USAT optional shift operand.
4799 def : t2InstAlias<"ssat${p} $Rd, $sat_imm, $Rn",
4800 (t2SSAT rGPR:$Rd, imm1_32:$sat_imm, rGPR:$Rn, 0, pred:$p)>;
4801 def : t2InstAlias<"usat${p} $Rd, $sat_imm, $Rn",
4802 (t2USAT rGPR:$Rd, imm0_31:$sat_imm, rGPR:$Rn, 0, pred:$p)>;
4804 // STM w/o the .w suffix.
4805 def : t2InstAlias<"stm${p} $Rn, $regs",
4806 (t2STMIA GPR:$Rn, pred:$p, reglist:$regs)>;
4808 // Alias for STR, STRB, and STRH without the ".w" optional
4810 def : t2InstAlias<"str${p} $Rt, $addr",
4811 (t2STRi12 GPR:$Rt, t2addrmode_imm12:$addr, pred:$p)>;
4812 def : t2InstAlias<"strb${p} $Rt, $addr",
4813 (t2STRBi12 rGPR:$Rt, t2addrmode_imm12:$addr, pred:$p)>;
4814 def : t2InstAlias<"strh${p} $Rt, $addr",
4815 (t2STRHi12 rGPR:$Rt, t2addrmode_imm12:$addr, pred:$p)>;
4817 def : t2InstAlias<"str${p} $Rt, $addr",
4818 (t2STRs GPR:$Rt, t2addrmode_so_reg:$addr, pred:$p)>;
4819 def : t2InstAlias<"strb${p} $Rt, $addr",
4820 (t2STRBs rGPR:$Rt, t2addrmode_so_reg:$addr, pred:$p)>;
4821 def : t2InstAlias<"strh${p} $Rt, $addr",
4822 (t2STRHs rGPR:$Rt, t2addrmode_so_reg:$addr, pred:$p)>;
4824 // Extend instruction optional rotate operand.
4825 def : InstAlias<"sxtab${p} $Rd, $Rn, $Rm",
4826 (t2SXTAB rGPR:$Rd, rGPR:$Rn, rGPR:$Rm, 0, pred:$p), 0>,
4827 Requires<[HasDSP, IsThumb2]>;
4828 def : InstAlias<"sxtah${p} $Rd, $Rn, $Rm",
4829 (t2SXTAH rGPR:$Rd, rGPR:$Rn, rGPR:$Rm, 0, pred:$p), 0>,
4830 Requires<[HasDSP, IsThumb2]>;
4831 def : InstAlias<"sxtab16${p} $Rd, $Rn, $Rm",
4832 (t2SXTAB16 rGPR:$Rd, rGPR:$Rn, rGPR:$Rm, 0, pred:$p), 0>,
4833 Requires<[HasDSP, IsThumb2]>;
4834 def : InstAlias<"sxtb16${p} $Rd, $Rm",
4835 (t2SXTB16 rGPR:$Rd, rGPR:$Rm, 0, pred:$p), 0>,
4836 Requires<[HasDSP, IsThumb2]>;
4838 def : t2InstAlias<"sxtb${p} $Rd, $Rm",
4839 (t2SXTB rGPR:$Rd, rGPR:$Rm, 0, pred:$p)>;
4840 def : t2InstAlias<"sxth${p} $Rd, $Rm",
4841 (t2SXTH rGPR:$Rd, rGPR:$Rm, 0, pred:$p)>;
4842 def : t2InstAlias<"sxtb${p}.w $Rd, $Rm",
4843 (t2SXTB rGPR:$Rd, rGPR:$Rm, 0, pred:$p)>;
4844 def : t2InstAlias<"sxth${p}.w $Rd, $Rm",
4845 (t2SXTH rGPR:$Rd, rGPR:$Rm, 0, pred:$p)>;
4847 def : InstAlias<"uxtab${p} $Rd, $Rn, $Rm",
4848 (t2UXTAB rGPR:$Rd, rGPR:$Rn, rGPR:$Rm, 0, pred:$p), 0>,
4849 Requires<[HasDSP, IsThumb2]>;
4850 def : InstAlias<"uxtah${p} $Rd, $Rn, $Rm",
4851 (t2UXTAH rGPR:$Rd, rGPR:$Rn, rGPR:$Rm, 0, pred:$p), 0>,
4852 Requires<[HasDSP, IsThumb2]>;
4853 def : InstAlias<"uxtab16${p} $Rd, $Rn, $Rm",
4854 (t2UXTAB16 rGPR:$Rd, rGPR:$Rn, rGPR:$Rm, 0, pred:$p), 0>,
4855 Requires<[HasDSP, IsThumb2]>;
4856 def : InstAlias<"uxtb16${p} $Rd, $Rm",
4857 (t2UXTB16 rGPR:$Rd, rGPR:$Rm, 0, pred:$p), 0>,
4858 Requires<[HasDSP, IsThumb2]>;
4860 def : t2InstAlias<"uxtb${p} $Rd, $Rm",
4861 (t2UXTB rGPR:$Rd, rGPR:$Rm, 0, pred:$p)>;
4862 def : t2InstAlias<"uxth${p} $Rd, $Rm",
4863 (t2UXTH rGPR:$Rd, rGPR:$Rm, 0, pred:$p)>;
4864 def : t2InstAlias<"uxtb${p}.w $Rd, $Rm",
4865 (t2UXTB rGPR:$Rd, rGPR:$Rm, 0, pred:$p)>;
4866 def : t2InstAlias<"uxth${p}.w $Rd, $Rm",
4867 (t2UXTH rGPR:$Rd, rGPR:$Rm, 0, pred:$p)>;
4869 // Extend instruction w/o the ".w" optional width specifier.
4870 def : t2InstAlias<"uxtb${p} $Rd, $Rm$rot",
4871 (t2UXTB rGPR:$Rd, rGPR:$Rm, rot_imm:$rot, pred:$p)>;
4872 def : InstAlias<"uxtb16${p} $Rd, $Rm$rot",
4873 (t2UXTB16 rGPR:$Rd, rGPR:$Rm, rot_imm:$rot, pred:$p), 0>,
4874 Requires<[HasDSP, IsThumb2]>;
4875 def : t2InstAlias<"uxth${p} $Rd, $Rm$rot",
4876 (t2UXTH rGPR:$Rd, rGPR:$Rm, rot_imm:$rot, pred:$p)>;
4878 def : t2InstAlias<"sxtb${p} $Rd, $Rm$rot",
4879 (t2SXTB rGPR:$Rd, rGPR:$Rm, rot_imm:$rot, pred:$p)>;
4880 def : InstAlias<"sxtb16${p} $Rd, $Rm$rot",
4881 (t2SXTB16 rGPR:$Rd, rGPR:$Rm, rot_imm:$rot, pred:$p), 0>,
4882 Requires<[HasDSP, IsThumb2]>;
4883 def : t2InstAlias<"sxth${p} $Rd, $Rm$rot",
4884 (t2SXTH rGPR:$Rd, rGPR:$Rm, rot_imm:$rot, pred:$p)>;
4887 // "mov Rd, t2_so_imm_not" can be handled via "mvn" in assembly, just like
4889 def : t2InstSubst<"mov${p} $Rd, $imm",
4890 (t2MVNi rGPR:$Rd, t2_so_imm_not:$imm, pred:$p, zero_reg)>;
4891 def : t2InstSubst<"mvn${s}${p} $Rd, $imm",
4892 (t2MOVi rGPR:$Rd, t2_so_imm_not:$imm, pred:$p, s_cc_out:$s)>;
4893 // Same for AND <--> BIC
4894 def : t2InstSubst<"bic${s}${p} $Rd, $Rn, $imm",
4895 (t2ANDri rGPR:$Rd, rGPR:$Rn, t2_so_imm_not:$imm,
4896 pred:$p, cc_out:$s)>;
4897 def : t2InstSubst<"bic${s}${p} $Rdn, $imm",
4898 (t2ANDri rGPR:$Rdn, rGPR:$Rdn, t2_so_imm_not:$imm,
4899 pred:$p, cc_out:$s)>;
4900 def : t2InstSubst<"bic${s}${p}.w $Rd, $Rn, $imm",
4901 (t2ANDri rGPR:$Rd, rGPR:$Rn, t2_so_imm_not:$imm,
4902 pred:$p, cc_out:$s)>;
4903 def : t2InstSubst<"bic${s}${p}.w $Rdn, $imm",
4904 (t2ANDri rGPR:$Rdn, rGPR:$Rdn, t2_so_imm_not:$imm,
4905 pred:$p, cc_out:$s)>;
4906 def : t2InstSubst<"and${s}${p} $Rd, $Rn, $imm",
4907 (t2BICri rGPR:$Rd, rGPR:$Rn, t2_so_imm_not:$imm,
4908 pred:$p, cc_out:$s)>;
4909 def : t2InstSubst<"and${s}${p} $Rdn, $imm",
4910 (t2BICri rGPR:$Rdn, rGPR:$Rdn, t2_so_imm_not:$imm,
4911 pred:$p, cc_out:$s)>;
4912 def : t2InstSubst<"and${s}${p}.w $Rd, $Rn, $imm",
4913 (t2BICri rGPR:$Rd, rGPR:$Rn, t2_so_imm_not:$imm,
4914 pred:$p, cc_out:$s)>;
4915 def : t2InstSubst<"and${s}${p}.w $Rdn, $imm",
4916 (t2BICri rGPR:$Rdn, rGPR:$Rdn, t2_so_imm_not:$imm,
4917 pred:$p, cc_out:$s)>;
4919 def : t2InstSubst<"orn${s}${p} $Rd, $Rn, $imm",
4920 (t2ORRri rGPR:$Rd, rGPR:$Rn, t2_so_imm_not:$imm,
4921 pred:$p, cc_out:$s)>;
4922 def : t2InstSubst<"orn${s}${p} $Rdn, $imm",
4923 (t2ORRri rGPR:$Rdn, rGPR:$Rdn, t2_so_imm_not:$imm,
4924 pred:$p, cc_out:$s)>;
4925 def : t2InstSubst<"orr${s}${p} $Rd, $Rn, $imm",
4926 (t2ORNri rGPR:$Rd, rGPR:$Rn, t2_so_imm_not:$imm,
4927 pred:$p, cc_out:$s)>;
4928 def : t2InstSubst<"orr${s}${p} $Rdn, $imm",
4929 (t2ORNri rGPR:$Rdn, rGPR:$Rdn, t2_so_imm_not:$imm,
4930 pred:$p, cc_out:$s)>;
4931 // Likewise, "add Rd, t2_so_imm_neg" -> sub
4932 def : t2InstSubst<"add${s}${p} $Rd, $Rn, $imm",
4933 (t2SUBri GPRnopc:$Rd, GPRnopc:$Rn, t2_so_imm_neg:$imm,
4934 pred:$p, cc_out:$s)>;
4935 def : t2InstSubst<"add${s}${p} $Rd, $imm",
4936 (t2SUBri GPRnopc:$Rd, GPRnopc:$Rd, t2_so_imm_neg:$imm,
4937 pred:$p, cc_out:$s)>;
4938 // Same for CMP <--> CMN via t2_so_imm_neg
4939 def : t2InstSubst<"cmp${p} $Rd, $imm",
4940 (t2CMNri rGPR:$Rd, t2_so_imm_neg:$imm, pred:$p)>;
4941 def : t2InstSubst<"cmn${p} $Rd, $imm",
4942 (t2CMPri rGPR:$Rd, t2_so_imm_neg:$imm, pred:$p)>;
4945 // Wide 'mul' encoding can be specified with only two operands.
4946 def : t2InstAlias<"mul${p} $Rn, $Rm",
4947 (t2MUL rGPR:$Rn, rGPR:$Rm, rGPR:$Rn, pred:$p)>;
4949 // "neg" is and alias for "rsb rd, rn, #0"
4950 def : t2InstAlias<"neg${s}${p} $Rd, $Rm",
4951 (t2RSBri rGPR:$Rd, rGPR:$Rm, 0, pred:$p, cc_out:$s)>;
4953 // MOV so_reg assembler pseudos. InstAlias isn't expressive enough for
4954 // these, unfortunately.
4955 // FIXME: LSL #0 in the shift should allow SP to be used as either the
4956 // source or destination (but not both).
4957 def t2MOVsi: t2AsmPseudo<"mov${p} $Rd, $shift",
4958 (ins rGPR:$Rd, t2_so_reg:$shift, pred:$p)>;
4959 def t2MOVSsi: t2AsmPseudo<"movs${p} $Rd, $shift",
4960 (ins rGPR:$Rd, t2_so_reg:$shift, pred:$p)>;
4962 def t2MOVsr: t2AsmPseudo<"mov${p} $Rd, $shift",
4963 (ins rGPR:$Rd, so_reg_reg:$shift, pred:$p)>;
4964 def t2MOVSsr: t2AsmPseudo<"movs${p} $Rd, $shift",
4965 (ins rGPR:$Rd, so_reg_reg:$shift, pred:$p)>;
4967 // Aliases for the above with the .w qualifier
4968 def : t2InstAlias<"mov${p}.w $Rd, $shift",
4969 (t2MOVsi rGPR:$Rd, t2_so_reg:$shift, pred:$p)>;
4970 def : t2InstAlias<"movs${p}.w $Rd, $shift",
4971 (t2MOVSsi rGPR:$Rd, t2_so_reg:$shift, pred:$p)>;
4972 def : t2InstAlias<"mov${p}.w $Rd, $shift",
4973 (t2MOVsr rGPR:$Rd, so_reg_reg:$shift, pred:$p)>;
4974 def : t2InstAlias<"movs${p}.w $Rd, $shift",
4975 (t2MOVSsr rGPR:$Rd, so_reg_reg:$shift, pred:$p)>;
4977 // ADR w/o the .w suffix
4978 def : t2InstAlias<"adr${p} $Rd, $addr",
4979 (t2ADR rGPR:$Rd, t2adrlabel:$addr, pred:$p)>;
4981 // LDR(literal) w/ alternate [pc, #imm] syntax.
4982 def t2LDRpcrel : t2AsmPseudo<"ldr${p} $Rt, $addr",
4983 (ins GPR:$Rt, t2ldr_pcrel_imm12:$addr, pred:$p)>;
4984 def t2LDRBpcrel : t2AsmPseudo<"ldrb${p} $Rt, $addr",
4985 (ins GPRnopc:$Rt, t2ldr_pcrel_imm12:$addr, pred:$p)>;
4986 def t2LDRHpcrel : t2AsmPseudo<"ldrh${p} $Rt, $addr",
4987 (ins GPRnopc:$Rt, t2ldr_pcrel_imm12:$addr, pred:$p)>;
4988 def t2LDRSBpcrel : t2AsmPseudo<"ldrsb${p} $Rt, $addr",
4989 (ins GPRnopc:$Rt, t2ldr_pcrel_imm12:$addr, pred:$p)>;
4990 def t2LDRSHpcrel : t2AsmPseudo<"ldrsh${p} $Rt, $addr",
4991 (ins GPRnopc:$Rt, t2ldr_pcrel_imm12:$addr, pred:$p)>;
4992 // Version w/ the .w suffix.
4993 def : t2InstAlias<"ldr${p}.w $Rt, $addr",
4994 (t2LDRpcrel GPR:$Rt, t2ldr_pcrel_imm12:$addr, pred:$p), 0>;
4995 def : t2InstAlias<"ldrb${p}.w $Rt, $addr",
4996 (t2LDRBpcrel GPRnopc:$Rt, t2ldr_pcrel_imm12:$addr, pred:$p)>;
4997 def : t2InstAlias<"ldrh${p}.w $Rt, $addr",
4998 (t2LDRHpcrel GPRnopc:$Rt, t2ldr_pcrel_imm12:$addr, pred:$p)>;
4999 def : t2InstAlias<"ldrsb${p}.w $Rt, $addr",
5000 (t2LDRSBpcrel GPRnopc:$Rt, t2ldr_pcrel_imm12:$addr, pred:$p)>;
5001 def : t2InstAlias<"ldrsh${p}.w $Rt, $addr",
5002 (t2LDRSHpcrel GPRnopc:$Rt, t2ldr_pcrel_imm12:$addr, pred:$p)>;
5004 def : t2InstAlias<"add${p} $Rd, pc, $imm",
5005 (t2ADR rGPR:$Rd, imm0_4095:$imm, pred:$p)>;
5007 // Pseudo instruction ldr Rt, =immediate
5009 : t2AsmPseudo<"ldr${p} $Rt, $immediate",
5010 (ins GPR:$Rt, const_pool_asm_imm:$immediate, pred:$p)>;
5011 // Version w/ the .w suffix.
5012 def : t2InstAlias<"ldr${p}.w $Rt, $immediate",
5013 (t2LDRConstPool GPRnopc:$Rt,
5014 const_pool_asm_imm:$immediate, pred:$p)>;
5016 // PLD/PLDW/PLI with alternate literal form.
5017 def : t2InstAlias<"pld${p} $addr",
5018 (t2PLDpci t2ldr_pcrel_imm12:$addr, pred:$p)>;
5019 def : InstAlias<"pli${p} $addr",
5020 (t2PLIpci t2ldr_pcrel_imm12:$addr, pred:$p), 0>,
5021 Requires<[IsThumb2,HasV7]>;
5024 //===----------------------------------------------------------------------===//
5025 // ARMv8.1m instructions
5028 class V8_1MI<dag oops, dag iops, AddrMode am, InstrItinClass itin, string asm,
5029 string ops, string cstr, list<dag> pattern>
5030 : Thumb2XI<oops, iops, am, 4, itin, !strconcat(asm, "\t", ops), cstr,
5032 Requires<[HasV8_1MMainline]>;
5034 def t2CLRM : V8_1MI<(outs),
5035 (ins pred:$p, reglist_with_apsr:$regs, variable_ops),
5036 AddrModeNone, NoItinerary, "clrm", "${p}\t$regs", "", []> {
5039 let Inst{31-16} = 0b1110100010011111;
5040 let Inst{15-14} = regs{15-14};
5042 let Inst{12-0} = regs{12-0};
5045 class t2BF<dag iops, string asm, string ops>
5046 : V8_1MI<(outs ), iops, AddrModeNone, NoItinerary, asm, ops, "", []> {
5048 let Inst{31-27} = 0b11110;
5049 let Inst{15-14} = 0b11;
5053 let Predicates = [IsThumb2, HasV8_1MMainline, HasLOB];
5056 def t2BF_LabelPseudo
5057 : t2PseudoInst<(outs ), (ins pclabel:$cp), 0, NoItinerary, []> {
5058 let isTerminator = 1;
5059 let Predicates = [IsThumb2, HasV8_1MMainline, HasLOB];
5062 def t2BFi : t2BF<(ins bflabel_u4:$b_label, bflabel_s16:$label, pred:$p),
5063 !strconcat("bf", "${p}"), "$b_label, $label"> {
5067 let Inst{26-23} = b_label{3-0};
5068 let Inst{22-21} = 0b10;
5069 let Inst{20-16} = label{15-11};
5071 let Inst{11} = label{0};
5072 let Inst{10-1} = label{10-1};
5075 def t2BFic : t2BF<(ins bflabel_u4:$b_label, bflabel_s12:$label,
5076 bfafter_target:$ba_label, pred_noal:$bcond), "bfcsel",
5077 "$b_label, $label, $ba_label, $bcond"> {
5083 let Inst{26-23} = b_label{3-0};
5085 let Inst{21-18} = bcond{3-0};
5086 let Inst{17} = ba_label{0};
5087 let Inst{16} = label{11};
5089 let Inst{11} = label{0};
5090 let Inst{10-1} = label{10-1};
5093 def t2BFr : t2BF<(ins bflabel_u4:$b_label, rGPR:$Rn, pred:$p),
5094 !strconcat("bfx", "${p}"), "$b_label, $Rn"> {
5098 let Inst{26-23} = b_label{3-0};
5099 let Inst{22-20} = 0b110;
5100 let Inst{19-16} = Rn{3-0};
5101 let Inst{13-1} = 0b1000000000000;
5104 def t2BFLi : t2BF<(ins bflabel_u4:$b_label, bflabel_s18:$label, pred:$p),
5105 !strconcat("bfl", "${p}"), "$b_label, $label"> {
5109 let Inst{26-23} = b_label{3-0};
5110 let Inst{22-16} = label{17-11};
5112 let Inst{11} = label{0};
5113 let Inst{10-1} = label{10-1};
5116 def t2BFLr : t2BF<(ins bflabel_u4:$b_label, rGPR:$Rn, pred:$p),
5117 !strconcat("bflx", "${p}"), "$b_label, $Rn"> {
5121 let Inst{26-23} = b_label{3-0};
5122 let Inst{22-20} = 0b111;
5123 let Inst{19-16} = Rn{3-0};
5124 let Inst{13-1} = 0b1000000000000;
5127 class t2LOL<dag oops, dag iops, string asm, string ops>
5128 : V8_1MI<oops, iops, AddrModeNone, NoItinerary, asm, ops, "", [] > {
5129 let Inst{31-23} = 0b111100000;
5130 let Inst{15-14} = 0b11;
5133 let isTerminator = 1;
5134 let DecoderMethod = "DecodeLOLoop";
5135 let Predicates = [IsThumb2, HasV8_1MMainline, HasLOB];
5138 let isNotDuplicable = 1 in {
5139 def t2WLS : t2LOL<(outs GPRlr:$LR),
5140 (ins rGPR:$Rn, wlslabel_u11:$label),
5141 "wls", "$LR, $Rn, $label"> {
5144 let Inst{22-20} = 0b100;
5145 let Inst{19-16} = Rn{3-0};
5146 let Inst{13-12} = 0b00;
5147 let Inst{11} = label{0};
5148 let Inst{10-1} = label{10-1};
5149 let usesCustomInserter = 1;
5152 def t2DLS : t2LOL<(outs GPRlr:$LR), (ins rGPR:$Rn),
5153 "dls", "$LR, $Rn"> {
5156 let isTerminator = 0;
5157 let Inst{22-20} = 0b100;
5158 let Inst{19-16} = Rn{3-0};
5159 let Inst{13-1} = 0b1000000000000;
5160 let usesCustomInserter = 1;
5163 def t2LEUpdate : t2LOL<(outs GPRlr:$LRout),
5164 (ins GPRlr:$LRin, lelabel_u11:$label),
5165 "le", "$LRin, $label"> {
5167 let Inst{22-16} = 0b0001111;
5168 let Inst{13-12} = 0b00;
5169 let Inst{11} = label{0};
5170 let Inst{10-1} = label{10-1};
5171 let usesCustomInserter = 1;
5174 def t2LE : t2LOL<(outs ), (ins lelabel_u11:$label), "le", "$label"> {
5176 let Inst{22-16} = 0b0101111;
5177 let Inst{13-12} = 0b00;
5178 let Inst{11} = label{0};
5179 let Inst{10-1} = label{10-1};
5183 t2PseudoInst<(outs), (ins rGPR:$elts), 4, IIC_Br,
5184 [(int_set_loop_iterations rGPR:$elts)]>, Sched<[WriteBr]>;
5187 t2PseudoInst<(outs GPRlr:$Rm), (ins GPRlr:$Rn, imm0_7:$size),
5188 4, IIC_Br, []>, Sched<[WriteBr]>;
5190 let isBranch = 1, isTerminator = 1, hasSideEffects = 1 in
5192 t2PseudoInst<(outs), (ins GPRlr:$elts, brtarget:$target),
5193 8, IIC_Br, []>, Sched<[WriteBr]>;
5195 } // end isNotDuplicable
5197 class CS<string iname, bits<4> opcode, list<dag> pattern=[]>
5198 : V8_1MI<(outs rGPR:$Rd), (ins GPRwithZR:$Rn, GPRwithZR:$Rm, pred_noal:$fcond),
5199 AddrModeNone, NoItinerary, iname, "$Rd, $Rn, $Rm, $fcond", "", pattern> {
5205 let Inst{31-20} = 0b111010100101;
5206 let Inst{19-16} = Rn{3-0};
5207 let Inst{15-12} = opcode;
5208 let Inst{11-8} = Rd{3-0};
5209 let Inst{7-4} = fcond{3-0};
5210 let Inst{3-0} = Rm{3-0};
5215 def t2CSEL : CS<"csel", 0b1000>;
5216 def t2CSINC : CS<"csinc", 0b1001>;
5217 def t2CSINV : CS<"csinv", 0b1010>;
5218 def t2CSNEG : CS<"csneg", 0b1011>;
5222 let Predicates = [HasV8_1MMainline] in {
5223 def : InstAlias<"csetm\t$Rd, $fcond",
5224 (t2CSINV rGPR:$Rd, ZR, ZR, pred_noal_inv:$fcond)>;
5226 def : InstAlias<"cset\t$Rd, $fcond",
5227 (t2CSINC rGPR:$Rd, ZR, ZR, pred_noal_inv:$fcond)>;
5229 def : InstAlias<"cinc\t$Rd, $Rn, $fcond",
5230 (t2CSINC rGPR:$Rd, GPRwithZR:$Rn, GPRwithZR:$Rn, pred_noal_inv:$fcond)>;
5232 def : InstAlias<"cinv\t$Rd, $Rn, $fcond",
5233 (t2CSINV rGPR:$Rd, GPRwithZR:$Rn, GPRwithZR:$Rn, pred_noal_inv:$fcond)>;
5235 def : InstAlias<"cneg\t$Rd, $Rn, $fcond",
5236 (t2CSNEG rGPR:$Rd, GPRwithZR:$Rn, GPRwithZR:$Rn, pred_noal_inv:$fcond)>;