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;
30 // t2_shift_imm: An integer that encodes a shift amount and the type of shift
31 // (asr or lsl). The 6-bit immediate encodes as:
34 // {4-0} imm5 shift amount.
35 // asr #32 not allowed
36 def t2_shift_imm : Operand<i32> {
37 let PrintMethod = "printShiftImmOperand";
38 let ParserMatchClass = ShifterImmAsmOperand;
39 let DecoderMethod = "DecodeT2ShifterImmOperand";
42 // Shifted operands. No register controlled shifts for Thumb2.
43 // Note: We do not support rrx shifted operands yet.
44 def t2_so_reg : Operand<i32>, // reg imm
45 ComplexPattern<i32, 2, "SelectShiftImmShifterOperand",
47 let EncoderMethod = "getT2SORegOpValue";
48 let PrintMethod = "printT2SOOperand";
49 let DecoderMethod = "DecodeSORegImmOperand";
50 let ParserMatchClass = ShiftedImmAsmOperand;
51 let MIOperandInfo = (ops rGPR, i32imm);
54 // t2_so_imm_not_XFORM - Return the complement of a t2_so_imm value
55 def t2_so_imm_not_XFORM : SDNodeXForm<imm, [{
56 return CurDAG->getTargetConstant(~((uint32_t)N->getZExtValue()), SDLoc(N),
60 // t2_so_imm_neg_XFORM - Return the negation of a t2_so_imm value
61 def t2_so_imm_neg_XFORM : SDNodeXForm<imm, [{
62 return CurDAG->getTargetConstant(-((int)N->getZExtValue()), SDLoc(N),
66 // so_imm_notSext_XFORM - Return a so_imm value packed into the format
67 // described for so_imm_notSext def below, with sign extension from 16
69 def t2_so_imm_notSext16_XFORM : SDNodeXForm<imm, [{
70 APInt apIntN = N->getAPIntValue();
71 unsigned N16bitSignExt = apIntN.trunc(16).sext(32).getZExtValue();
72 return CurDAG->getTargetConstant(~N16bitSignExt, SDLoc(N), MVT::i32);
75 // t2_so_imm - Match a 32-bit immediate operand, which is an
76 // 8-bit immediate rotated by an arbitrary number of bits, or an 8-bit
77 // immediate splatted into multiple bytes of the word.
78 def t2_so_imm_asmoperand : AsmOperandClass {
80 let RenderMethod = "addImmOperands";
83 def t2_so_imm : Operand<i32>, ImmLeaf<i32, [{
84 return ARM_AM::getT2SOImmVal(Imm) != -1;
86 let ParserMatchClass = t2_so_imm_asmoperand;
87 let EncoderMethod = "getT2SOImmOpValue";
88 let DecoderMethod = "DecodeT2SOImm";
91 // t2_so_imm_not - Match an immediate that is a complement
93 // Note: this pattern doesn't require an encoder method and such, as it's
94 // only used on aliases (Pat<> and InstAlias<>). The actual encoding
95 // is handled by the destination instructions, which use t2_so_imm.
96 def t2_so_imm_not_asmoperand : AsmOperandClass { let Name = "T2SOImmNot"; }
97 def t2_so_imm_not : Operand<i32>, PatLeaf<(imm), [{
98 return ARM_AM::getT2SOImmVal(~((uint32_t)N->getZExtValue())) != -1;
99 }], t2_so_imm_not_XFORM> {
100 let ParserMatchClass = t2_so_imm_not_asmoperand;
103 // t2_so_imm_notSext - match an immediate that is a complement of a t2_so_imm
104 // if the upper 16 bits are zero.
105 def t2_so_imm_notSext : Operand<i32>, PatLeaf<(imm), [{
106 APInt apIntN = N->getAPIntValue();
107 if (!apIntN.isIntN(16)) return false;
108 unsigned N16bitSignExt = apIntN.trunc(16).sext(32).getZExtValue();
109 return ARM_AM::getT2SOImmVal(~N16bitSignExt) != -1;
110 }], t2_so_imm_notSext16_XFORM> {
111 let ParserMatchClass = t2_so_imm_not_asmoperand;
114 // t2_so_imm_neg - Match an immediate that is a negation of a t2_so_imm.
115 def t2_so_imm_neg_asmoperand : AsmOperandClass { let Name = "T2SOImmNeg"; }
116 def t2_so_imm_neg : Operand<i32>, ImmLeaf<i32, [{
117 return Imm && ARM_AM::getT2SOImmVal(-(uint32_t)Imm) != -1;
118 }], t2_so_imm_neg_XFORM> {
119 let ParserMatchClass = t2_so_imm_neg_asmoperand;
122 /// imm0_4095 predicate - True if the 32-bit immediate is in the range [0,4095].
123 def imm0_4095_asmoperand: ImmAsmOperand<0,4095> { let Name = "Imm0_4095"; }
124 def imm0_4095 : Operand<i32>, ImmLeaf<i32, [{
125 return Imm >= 0 && Imm < 4096;
127 let ParserMatchClass = imm0_4095_asmoperand;
130 def imm0_4095_neg_asmoperand: AsmOperandClass { let Name = "Imm0_4095Neg"; }
131 def imm0_4095_neg : Operand<i32>, PatLeaf<(i32 imm), [{
132 return (uint32_t)(-N->getZExtValue()) < 4096;
134 let ParserMatchClass = imm0_4095_neg_asmoperand;
137 def imm1_255_neg : PatLeaf<(i32 imm), [{
138 uint32_t Val = -N->getZExtValue();
139 return (Val > 0 && Val < 255);
142 def imm0_255_not : PatLeaf<(i32 imm), [{
143 return (uint32_t)(~N->getZExtValue()) < 255;
146 def lo5AllOne : PatLeaf<(i32 imm), [{
147 // Returns true if all low 5-bits are 1.
148 return (((uint32_t)N->getZExtValue()) & 0x1FUL) == 0x1FUL;
151 // Define Thumb2 specific addressing modes.
153 // t2addrmode_imm12 := reg + imm12
154 def t2addrmode_imm12_asmoperand : AsmOperandClass {let Name="MemUImm12Offset";}
155 def t2addrmode_imm12 : MemOperand,
156 ComplexPattern<i32, 2, "SelectT2AddrModeImm12", []> {
157 let PrintMethod = "printAddrModeImm12Operand<false>";
158 let EncoderMethod = "getAddrModeImm12OpValue";
159 let DecoderMethod = "DecodeT2AddrModeImm12";
160 let ParserMatchClass = t2addrmode_imm12_asmoperand;
161 let MIOperandInfo = (ops GPR:$base, i32imm:$offsimm);
164 // t2ldrlabel := imm12
165 def t2ldrlabel : Operand<i32> {
166 let EncoderMethod = "getAddrModeImm12OpValue";
167 let PrintMethod = "printThumbLdrLabelOperand";
170 def t2ldr_pcrel_imm12_asmoperand : AsmOperandClass {let Name = "MemPCRelImm12";}
171 def t2ldr_pcrel_imm12 : Operand<i32> {
172 let ParserMatchClass = t2ldr_pcrel_imm12_asmoperand;
173 // used for assembler pseudo instruction and maps to t2ldrlabel, so
174 // doesn't need encoder or print methods of its own.
177 // ADR instruction labels.
178 def t2adrlabel : Operand<i32> {
179 let EncoderMethod = "getT2AdrLabelOpValue";
180 let PrintMethod = "printAdrLabelOperand<0>";
183 // t2addrmode_posimm8 := reg + imm8
184 def MemPosImm8OffsetAsmOperand : AsmOperandClass {let Name="MemPosImm8Offset";}
185 def t2addrmode_posimm8 : MemOperand {
186 let PrintMethod = "printT2AddrModeImm8Operand<false>";
187 let EncoderMethod = "getT2AddrModeImm8OpValue";
188 let DecoderMethod = "DecodeT2AddrModeImm8";
189 let ParserMatchClass = MemPosImm8OffsetAsmOperand;
190 let MIOperandInfo = (ops GPR:$base, i32imm:$offsimm);
193 // t2addrmode_negimm8 := reg - imm8
194 def MemNegImm8OffsetAsmOperand : AsmOperandClass {let Name="MemNegImm8Offset";}
195 def t2addrmode_negimm8 : MemOperand,
196 ComplexPattern<i32, 2, "SelectT2AddrModeImm8", []> {
197 let PrintMethod = "printT2AddrModeImm8Operand<false>";
198 let EncoderMethod = "getT2AddrModeImm8OpValue";
199 let DecoderMethod = "DecodeT2AddrModeImm8";
200 let ParserMatchClass = MemNegImm8OffsetAsmOperand;
201 let MIOperandInfo = (ops GPR:$base, i32imm:$offsimm);
204 // t2addrmode_imm8 := reg +/- imm8
205 def MemImm8OffsetAsmOperand : AsmOperandClass { let Name = "MemImm8Offset"; }
206 class T2AddrMode_Imm8 : MemOperand,
207 ComplexPattern<i32, 2, "SelectT2AddrModeImm8", []> {
208 let EncoderMethod = "getT2AddrModeImm8OpValue";
209 let DecoderMethod = "DecodeT2AddrModeImm8";
210 let ParserMatchClass = MemImm8OffsetAsmOperand;
211 let MIOperandInfo = (ops GPR:$base, i32imm:$offsimm);
214 def t2addrmode_imm8 : T2AddrMode_Imm8 {
215 let PrintMethod = "printT2AddrModeImm8Operand<false>";
218 def t2addrmode_imm8_pre : T2AddrMode_Imm8 {
219 let PrintMethod = "printT2AddrModeImm8Operand<true>";
222 def t2am_imm8_offset : MemOperand,
223 ComplexPattern<i32, 1, "SelectT2AddrModeImm8Offset",
224 [], [SDNPWantRoot]> {
225 let PrintMethod = "printT2AddrModeImm8OffsetOperand";
226 let EncoderMethod = "getT2AddrModeImm8OffsetOpValue";
227 let DecoderMethod = "DecodeT2Imm8";
230 // t2addrmode_imm8s4 := reg +/- (imm8 << 2)
231 def MemImm8s4OffsetAsmOperand : AsmOperandClass {let Name = "MemImm8s4Offset";}
232 class T2AddrMode_Imm8s4 : MemOperand {
233 let EncoderMethod = "getT2AddrModeImm8s4OpValue";
234 let DecoderMethod = "DecodeT2AddrModeImm8s4";
235 let ParserMatchClass = MemImm8s4OffsetAsmOperand;
236 let MIOperandInfo = (ops GPR:$base, i32imm:$offsimm);
239 def t2addrmode_imm8s4 : T2AddrMode_Imm8s4 {
240 let PrintMethod = "printT2AddrModeImm8s4Operand<false>";
243 def t2addrmode_imm8s4_pre : T2AddrMode_Imm8s4 {
244 let PrintMethod = "printT2AddrModeImm8s4Operand<true>";
247 def t2am_imm8s4_offset_asmoperand : AsmOperandClass { let Name = "Imm8s4"; }
248 def t2am_imm8s4_offset : MemOperand {
249 let PrintMethod = "printT2AddrModeImm8s4OffsetOperand";
250 let EncoderMethod = "getT2Imm8s4OpValue";
251 let DecoderMethod = "DecodeT2Imm8S4";
254 // t2addrmode_imm0_1020s4 := reg + (imm8 << 2)
255 def MemImm0_1020s4OffsetAsmOperand : AsmOperandClass {
256 let Name = "MemImm0_1020s4Offset";
258 def t2addrmode_imm0_1020s4 : MemOperand,
259 ComplexPattern<i32, 2, "SelectT2AddrModeExclusive"> {
260 let PrintMethod = "printT2AddrModeImm0_1020s4Operand";
261 let EncoderMethod = "getT2AddrModeImm0_1020s4OpValue";
262 let DecoderMethod = "DecodeT2AddrModeImm0_1020s4";
263 let ParserMatchClass = MemImm0_1020s4OffsetAsmOperand;
264 let MIOperandInfo = (ops GPRnopc:$base, i32imm:$offsimm);
267 // t2addrmode_so_reg := reg + (reg << imm2)
268 def t2addrmode_so_reg_asmoperand : AsmOperandClass {let Name="T2MemRegOffset";}
269 def t2addrmode_so_reg : MemOperand,
270 ComplexPattern<i32, 3, "SelectT2AddrModeSoReg", []> {
271 let PrintMethod = "printT2AddrModeSoRegOperand";
272 let EncoderMethod = "getT2AddrModeSORegOpValue";
273 let DecoderMethod = "DecodeT2AddrModeSOReg";
274 let ParserMatchClass = t2addrmode_so_reg_asmoperand;
275 let MIOperandInfo = (ops GPRnopc:$base, rGPR:$offsreg, i32imm:$offsimm);
278 // Addresses for the TBB/TBH instructions.
279 def addrmode_tbb_asmoperand : AsmOperandClass { let Name = "MemTBB"; }
280 def addrmode_tbb : MemOperand {
281 let PrintMethod = "printAddrModeTBB";
282 let ParserMatchClass = addrmode_tbb_asmoperand;
283 let MIOperandInfo = (ops GPR:$Rn, rGPR:$Rm);
285 def addrmode_tbh_asmoperand : AsmOperandClass { let Name = "MemTBH"; }
286 def addrmode_tbh : MemOperand {
287 let PrintMethod = "printAddrModeTBH";
288 let ParserMatchClass = addrmode_tbh_asmoperand;
289 let MIOperandInfo = (ops GPR:$Rn, rGPR:$Rm);
292 //===----------------------------------------------------------------------===//
293 // Multiclass helpers...
297 class T2OneRegImm<dag oops, dag iops, InstrItinClass itin,
298 string opc, string asm, list<dag> pattern>
299 : T2I<oops, iops, itin, opc, asm, pattern> {
304 let Inst{26} = imm{11};
305 let Inst{14-12} = imm{10-8};
306 let Inst{7-0} = imm{7-0};
310 class T2sOneRegImm<dag oops, dag iops, InstrItinClass itin,
311 string opc, string asm, list<dag> pattern>
312 : T2sI<oops, iops, itin, opc, asm, pattern> {
318 let Inst{26} = imm{11};
319 let Inst{14-12} = imm{10-8};
320 let Inst{7-0} = imm{7-0};
323 class T2OneRegCmpImm<dag oops, dag iops, InstrItinClass itin,
324 string opc, string asm, list<dag> pattern>
325 : T2I<oops, iops, itin, opc, asm, pattern> {
329 let Inst{19-16} = Rn;
330 let Inst{26} = imm{11};
331 let Inst{14-12} = imm{10-8};
332 let Inst{7-0} = imm{7-0};
336 class T2OneRegShiftedReg<dag oops, dag iops, InstrItinClass itin,
337 string opc, string asm, list<dag> pattern>
338 : T2I<oops, iops, itin, opc, asm, pattern> {
343 let Inst{3-0} = ShiftedRm{3-0};
344 let Inst{5-4} = ShiftedRm{6-5};
345 let Inst{14-12} = ShiftedRm{11-9};
346 let Inst{7-6} = ShiftedRm{8-7};
349 class T2sOneRegShiftedReg<dag oops, dag iops, InstrItinClass itin,
350 string opc, string asm, list<dag> pattern>
351 : T2sI<oops, iops, itin, opc, asm, pattern> {
356 let Inst{3-0} = ShiftedRm{3-0};
357 let Inst{5-4} = ShiftedRm{6-5};
358 let Inst{14-12} = ShiftedRm{11-9};
359 let Inst{7-6} = ShiftedRm{8-7};
362 class T2OneRegCmpShiftedReg<dag oops, dag iops, InstrItinClass itin,
363 string opc, string asm, list<dag> pattern>
364 : T2I<oops, iops, itin, opc, asm, pattern> {
368 let Inst{19-16} = Rn;
369 let Inst{3-0} = ShiftedRm{3-0};
370 let Inst{5-4} = ShiftedRm{6-5};
371 let Inst{14-12} = ShiftedRm{11-9};
372 let Inst{7-6} = ShiftedRm{8-7};
375 class T2TwoReg<dag oops, dag iops, InstrItinClass itin,
376 string opc, string asm, list<dag> pattern>
377 : T2I<oops, iops, itin, opc, asm, pattern> {
385 class T2sTwoReg<dag oops, dag iops, InstrItinClass itin,
386 string opc, string asm, list<dag> pattern>
387 : T2sI<oops, iops, itin, opc, asm, pattern> {
395 class T2TwoRegCmp<dag oops, dag iops, InstrItinClass itin,
396 string opc, string asm, list<dag> pattern>
397 : T2I<oops, iops, itin, opc, asm, pattern> {
401 let Inst{19-16} = Rn;
406 class T2TwoRegImm<dag oops, dag iops, InstrItinClass itin,
407 string opc, string asm, list<dag> pattern>
408 : T2I<oops, iops, itin, opc, asm, pattern> {
414 let Inst{19-16} = Rn;
415 let Inst{26} = imm{11};
416 let Inst{14-12} = imm{10-8};
417 let Inst{7-0} = imm{7-0};
420 class T2sTwoRegImm<dag oops, dag iops, InstrItinClass itin,
421 string opc, string asm, list<dag> pattern>
422 : T2sI<oops, iops, itin, opc, asm, pattern> {
428 let Inst{19-16} = Rn;
429 let Inst{26} = imm{11};
430 let Inst{14-12} = imm{10-8};
431 let Inst{7-0} = imm{7-0};
434 class T2TwoRegShiftImm<dag oops, dag iops, InstrItinClass itin,
435 string opc, string asm, list<dag> pattern>
436 : T2I<oops, iops, itin, opc, asm, pattern> {
443 let Inst{14-12} = imm{4-2};
444 let Inst{7-6} = imm{1-0};
447 class T2sTwoRegShiftImm<dag oops, dag iops, InstrItinClass itin,
448 string opc, string asm, list<dag> pattern>
449 : T2sI<oops, iops, itin, opc, asm, pattern> {
456 let Inst{14-12} = imm{4-2};
457 let Inst{7-6} = imm{1-0};
460 class T2ThreeReg<dag oops, dag iops, InstrItinClass itin,
461 string opc, string asm, list<dag> pattern>
462 : T2I<oops, iops, itin, opc, asm, pattern> {
468 let Inst{19-16} = Rn;
472 class T2ThreeRegNoP<dag oops, dag iops, InstrItinClass itin,
473 string asm, list<dag> pattern>
474 : T2XI<oops, iops, itin, asm, pattern> {
480 let Inst{19-16} = Rn;
484 class T2sThreeReg<dag oops, dag iops, InstrItinClass itin,
485 string opc, string asm, list<dag> pattern>
486 : T2sI<oops, iops, itin, opc, asm, pattern> {
492 let Inst{19-16} = Rn;
496 class T2TwoRegShiftedReg<dag oops, dag iops, InstrItinClass itin,
497 string opc, string asm, list<dag> pattern>
498 : T2I<oops, iops, itin, opc, asm, pattern> {
504 let Inst{19-16} = Rn;
505 let Inst{3-0} = ShiftedRm{3-0};
506 let Inst{5-4} = ShiftedRm{6-5};
507 let Inst{14-12} = ShiftedRm{11-9};
508 let Inst{7-6} = ShiftedRm{8-7};
511 class T2sTwoRegShiftedReg<dag oops, dag iops, InstrItinClass itin,
512 string opc, string asm, list<dag> pattern>
513 : T2sI<oops, iops, itin, opc, asm, pattern> {
519 let Inst{19-16} = Rn;
520 let Inst{3-0} = ShiftedRm{3-0};
521 let Inst{5-4} = ShiftedRm{6-5};
522 let Inst{14-12} = ShiftedRm{11-9};
523 let Inst{7-6} = ShiftedRm{8-7};
526 class T2FourReg<dag oops, dag iops, InstrItinClass itin,
527 string opc, string asm, list<dag> pattern>
528 : T2I<oops, iops, itin, opc, asm, pattern> {
534 let Inst{19-16} = Rn;
535 let Inst{15-12} = Ra;
540 class T2MulLong<bits<3> opc22_20, bits<4> opc7_4,
541 string opc, list<dag> pattern>
542 : T2I<(outs rGPR:$RdLo, rGPR:$RdHi), (ins rGPR:$Rn, rGPR:$Rm), IIC_iMUL64,
543 opc, "\t$RdLo, $RdHi, $Rn, $Rm", pattern>,
544 Sched<[WriteMUL64Lo, WriteMUL64Hi, ReadMUL, ReadMUL]> {
550 let Inst{31-23} = 0b111110111;
551 let Inst{22-20} = opc22_20;
552 let Inst{19-16} = Rn;
553 let Inst{15-12} = RdLo;
554 let Inst{11-8} = RdHi;
555 let Inst{7-4} = opc7_4;
558 class T2MlaLong<bits<3> opc22_20, bits<4> opc7_4, string opc>
559 : T2I<(outs rGPR:$RdLo, rGPR:$RdHi),
560 (ins rGPR:$Rn, rGPR:$Rm, rGPR:$RLo, rGPR:$RHi), IIC_iMAC64,
561 opc, "\t$RdLo, $RdHi, $Rn, $Rm", []>,
562 RegConstraint<"$RLo = $RdLo, $RHi = $RdHi">,
563 Sched<[WriteMAC64Lo, WriteMAC64Hi, ReadMUL, ReadMUL, ReadMAC, ReadMAC]> {
569 let Inst{31-23} = 0b111110111;
570 let Inst{22-20} = opc22_20;
571 let Inst{19-16} = Rn;
572 let Inst{15-12} = RdLo;
573 let Inst{11-8} = RdHi;
574 let Inst{7-4} = opc7_4;
579 /// T2I_bin_irs - Defines a set of (op reg, {so_imm|r|so_reg}) patterns for a
580 /// binary operation that produces a value. These are predicable and can be
581 /// changed to modify CPSR.
582 multiclass T2I_bin_irs<bits<4> opcod, string opc,
583 InstrItinClass iii, InstrItinClass iir, InstrItinClass iis,
584 SDPatternOperator opnode, bit Commutable = 0,
587 def ri : T2sTwoRegImm<
588 (outs rGPR:$Rd), (ins rGPR:$Rn, t2_so_imm:$imm), iii,
589 opc, "\t$Rd, $Rn, $imm",
590 [(set rGPR:$Rd, (opnode rGPR:$Rn, t2_so_imm:$imm))]>,
591 Sched<[WriteALU, ReadALU]> {
592 let Inst{31-27} = 0b11110;
594 let Inst{24-21} = opcod;
598 def rr : T2sThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), iir,
599 opc, !strconcat(wide, "\t$Rd, $Rn, $Rm"),
600 [(set rGPR:$Rd, (opnode rGPR:$Rn, rGPR:$Rm))]>,
601 Sched<[WriteALU, ReadALU, ReadALU]> {
602 let isCommutable = Commutable;
603 let Inst{31-27} = 0b11101;
604 let Inst{26-25} = 0b01;
605 let Inst{24-21} = opcod;
606 let Inst{14-12} = 0b000; // imm3
607 let Inst{7-6} = 0b00; // imm2
608 let Inst{5-4} = 0b00; // type
611 def rs : T2sTwoRegShiftedReg<
612 (outs rGPR:$Rd), (ins rGPR:$Rn, t2_so_reg:$ShiftedRm), iis,
613 opc, !strconcat(wide, "\t$Rd, $Rn, $ShiftedRm"),
614 [(set rGPR:$Rd, (opnode rGPR:$Rn, t2_so_reg:$ShiftedRm))]>,
615 Sched<[WriteALUsi, ReadALU]> {
616 let Inst{31-27} = 0b11101;
617 let Inst{26-25} = 0b01;
618 let Inst{24-21} = opcod;
620 // Assembly aliases for optional destination operand when it's the same
621 // as the source operand.
622 def : t2InstAlias<!strconcat(opc, "${s}${p} $Rdn, $imm"),
623 (!cast<Instruction>(NAME#"ri") rGPR:$Rdn, rGPR:$Rdn,
624 t2_so_imm:$imm, pred:$p,
626 def : t2InstAlias<!strconcat(opc, "${s}${p}", wide, " $Rdn, $Rm"),
627 (!cast<Instruction>(NAME#"rr") rGPR:$Rdn, rGPR:$Rdn,
630 def : t2InstAlias<!strconcat(opc, "${s}${p}", wide, " $Rdn, $shift"),
631 (!cast<Instruction>(NAME#"rs") rGPR:$Rdn, rGPR:$Rdn,
632 t2_so_reg:$shift, pred:$p,
636 /// T2I_bin_w_irs - Same as T2I_bin_irs except these operations need
637 // the ".w" suffix to indicate that they are wide.
638 multiclass T2I_bin_w_irs<bits<4> opcod, string opc,
639 InstrItinClass iii, InstrItinClass iir, InstrItinClass iis,
640 SDPatternOperator opnode, bit Commutable = 0> :
641 T2I_bin_irs<opcod, opc, iii, iir, iis, opnode, Commutable, ".w"> {
642 // Assembler aliases w/ the ".w" suffix.
643 def : t2InstAlias<!strconcat(opc, "${s}${p}.w", " $Rd, $Rn, $imm"),
644 (!cast<Instruction>(NAME#"ri") rGPR:$Rd, rGPR:$Rn, t2_so_imm:$imm, pred:$p,
646 // Assembler aliases w/o the ".w" suffix.
647 def : t2InstAlias<!strconcat(opc, "${s}${p}", " $Rd, $Rn, $Rm"),
648 (!cast<Instruction>(NAME#"rr") rGPR:$Rd, rGPR:$Rn, rGPR:$Rm, pred:$p,
650 def : t2InstAlias<!strconcat(opc, "${s}${p}", " $Rd, $Rn, $shift"),
651 (!cast<Instruction>(NAME#"rs") rGPR:$Rd, rGPR:$Rn, t2_so_reg:$shift,
652 pred:$p, cc_out:$s)>;
654 // and with the optional destination operand, too.
655 def : t2InstAlias<!strconcat(opc, "${s}${p}.w", " $Rdn, $imm"),
656 (!cast<Instruction>(NAME#"ri") rGPR:$Rdn, rGPR:$Rdn, t2_so_imm:$imm,
657 pred:$p, cc_out:$s)>;
658 def : t2InstAlias<!strconcat(opc, "${s}${p}", " $Rdn, $Rm"),
659 (!cast<Instruction>(NAME#"rr") rGPR:$Rdn, rGPR:$Rdn, rGPR:$Rm, pred:$p,
661 def : t2InstAlias<!strconcat(opc, "${s}${p}", " $Rdn, $shift"),
662 (!cast<Instruction>(NAME#"rs") rGPR:$Rdn, rGPR:$Rdn, t2_so_reg:$shift,
663 pred:$p, cc_out:$s)>;
666 /// T2I_rbin_is - Same as T2I_bin_irs except the order of operands are
667 /// reversed. The 'rr' form is only defined for the disassembler; for codegen
668 /// it is equivalent to the T2I_bin_irs counterpart.
669 multiclass T2I_rbin_irs<bits<4> opcod, string opc, SDNode opnode> {
671 def ri : T2sTwoRegImm<
672 (outs rGPR:$Rd), (ins rGPR:$Rn, t2_so_imm:$imm), IIC_iALUi,
673 opc, ".w\t$Rd, $Rn, $imm",
674 [(set rGPR:$Rd, (opnode t2_so_imm:$imm, rGPR:$Rn))]>,
675 Sched<[WriteALU, ReadALU]> {
676 let Inst{31-27} = 0b11110;
678 let Inst{24-21} = opcod;
682 def rr : T2sThreeReg<
683 (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iALUr,
684 opc, "\t$Rd, $Rn, $Rm",
685 [/* For disassembly only; pattern left blank */]>,
686 Sched<[WriteALU, ReadALU, ReadALU]> {
687 let Inst{31-27} = 0b11101;
688 let Inst{26-25} = 0b01;
689 let Inst{24-21} = opcod;
690 let Inst{14-12} = 0b000; // imm3
691 let Inst{7-6} = 0b00; // imm2
692 let Inst{5-4} = 0b00; // type
695 def rs : T2sTwoRegShiftedReg<
696 (outs rGPR:$Rd), (ins rGPR:$Rn, t2_so_reg:$ShiftedRm),
697 IIC_iALUsir, opc, "\t$Rd, $Rn, $ShiftedRm",
698 [(set rGPR:$Rd, (opnode t2_so_reg:$ShiftedRm, rGPR:$Rn))]>,
699 Sched<[WriteALUsi, ReadALU]> {
700 let Inst{31-27} = 0b11101;
701 let Inst{26-25} = 0b01;
702 let Inst{24-21} = opcod;
706 /// T2I_bin_s_irs - Similar to T2I_bin_irs except it sets the 's' bit so the
707 /// instruction modifies the CPSR register.
709 /// These opcodes will be converted to the real non-S opcodes by
710 /// AdjustInstrPostInstrSelection after giving then an optional CPSR operand.
711 let hasPostISelHook = 1, Defs = [CPSR] in {
712 multiclass T2I_bin_s_irs<InstrItinClass iii, InstrItinClass iir,
713 InstrItinClass iis, SDNode opnode,
714 bit Commutable = 0> {
716 def ri : t2PseudoInst<(outs rGPR:$Rd),
717 (ins GPRnopc:$Rn, t2_so_imm:$imm, pred:$p),
719 [(set rGPR:$Rd, CPSR, (opnode GPRnopc:$Rn,
721 Sched<[WriteALU, ReadALU]>;
723 def rr : t2PseudoInst<(outs rGPR:$Rd), (ins GPRnopc:$Rn, rGPR:$Rm, pred:$p),
725 [(set rGPR:$Rd, CPSR, (opnode GPRnopc:$Rn,
727 Sched<[WriteALU, ReadALU, ReadALU]> {
728 let isCommutable = Commutable;
731 def rs : t2PseudoInst<(outs rGPR:$Rd),
732 (ins GPRnopc:$Rn, t2_so_reg:$ShiftedRm, pred:$p),
734 [(set rGPR:$Rd, CPSR, (opnode GPRnopc:$Rn,
735 t2_so_reg:$ShiftedRm))]>,
736 Sched<[WriteALUsi, ReadALUsr]>;
740 /// T2I_rbin_s_is - Same as T2I_bin_s_irs, except selection DAG
741 /// operands are reversed.
742 let hasPostISelHook = 1, Defs = [CPSR] in {
743 multiclass T2I_rbin_s_is<SDNode opnode> {
745 def ri : t2PseudoInst<(outs rGPR:$Rd),
746 (ins rGPR:$Rn, t2_so_imm:$imm, pred:$p),
748 [(set rGPR:$Rd, CPSR, (opnode t2_so_imm:$imm,
750 Sched<[WriteALU, ReadALU]>;
752 def rs : t2PseudoInst<(outs rGPR:$Rd),
753 (ins rGPR:$Rn, t2_so_reg:$ShiftedRm, pred:$p),
755 [(set rGPR:$Rd, CPSR, (opnode t2_so_reg:$ShiftedRm,
757 Sched<[WriteALUsi, ReadALU]>;
761 /// T2I_bin_ii12rs - Defines a set of (op reg, {so_imm|imm0_4095|r|so_reg})
762 /// patterns for a binary operation that produces a value.
763 multiclass T2I_bin_ii12rs<bits<3> op23_21, string opc, SDNode opnode,
764 bit Commutable = 0> {
766 // The register-immediate version is re-materializable. This is useful
767 // in particular for taking the address of a local.
768 let isReMaterializable = 1 in {
769 def ri : T2sTwoRegImm<
770 (outs GPRnopc:$Rd), (ins GPRnopc:$Rn, t2_so_imm:$imm), IIC_iALUi,
771 opc, ".w\t$Rd, $Rn, $imm",
772 [(set GPRnopc:$Rd, (opnode GPRnopc:$Rn, t2_so_imm:$imm))]>,
773 Sched<[WriteALU, ReadALU]> {
774 let Inst{31-27} = 0b11110;
777 let Inst{23-21} = op23_21;
783 (outs GPRnopc:$Rd), (ins GPR:$Rn, imm0_4095:$imm), IIC_iALUi,
784 !strconcat(opc, "w"), "\t$Rd, $Rn, $imm",
785 [(set GPRnopc:$Rd, (opnode GPR:$Rn, imm0_4095:$imm))]>,
786 Sched<[WriteALU, ReadALU]> {
790 let Inst{31-27} = 0b11110;
791 let Inst{26} = imm{11};
792 let Inst{25-24} = 0b10;
793 let Inst{23-21} = op23_21;
794 let Inst{20} = 0; // The S bit.
795 let Inst{19-16} = Rn;
797 let Inst{14-12} = imm{10-8};
799 let Inst{7-0} = imm{7-0};
802 def rr : T2sThreeReg<(outs GPRnopc:$Rd), (ins GPRnopc:$Rn, rGPR:$Rm),
803 IIC_iALUr, opc, ".w\t$Rd, $Rn, $Rm",
804 [(set GPRnopc:$Rd, (opnode GPRnopc:$Rn, rGPR:$Rm))]>,
805 Sched<[WriteALU, ReadALU, ReadALU]> {
806 let isCommutable = Commutable;
807 let Inst{31-27} = 0b11101;
808 let Inst{26-25} = 0b01;
810 let Inst{23-21} = op23_21;
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 GPRnopc:$Rd), (ins GPRnopc:$Rn, t2_so_reg:$ShiftedRm),
818 IIC_iALUsi, opc, ".w\t$Rd, $Rn, $ShiftedRm",
819 [(set GPRnopc:$Rd, (opnode GPRnopc:$Rn, t2_so_reg:$ShiftedRm))]>,
820 Sched<[WriteALUsi, ReadALU]> {
821 let Inst{31-27} = 0b11101;
822 let Inst{26-25} = 0b01;
824 let Inst{23-21} = op23_21;
828 /// T2I_adde_sube_irs - Defines a set of (op reg, {so_imm|r|so_reg}) patterns
829 /// for a binary operation that produces a value and use the carry
830 /// bit. It's not predicable.
831 let Defs = [CPSR], Uses = [CPSR] in {
832 multiclass T2I_adde_sube_irs<bits<4> opcod, string opc, SDNode opnode,
833 bit Commutable = 0> {
835 def ri : T2sTwoRegImm<(outs rGPR:$Rd), (ins rGPR:$Rn, t2_so_imm:$imm),
836 IIC_iALUi, opc, "\t$Rd, $Rn, $imm",
837 [(set rGPR:$Rd, CPSR, (opnode rGPR:$Rn, t2_so_imm:$imm, CPSR))]>,
838 Requires<[IsThumb2]>, Sched<[WriteALU, ReadALU]> {
839 let Inst{31-27} = 0b11110;
841 let Inst{24-21} = opcod;
845 def rr : T2sThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iALUr,
846 opc, ".w\t$Rd, $Rn, $Rm",
847 [(set rGPR:$Rd, CPSR, (opnode rGPR:$Rn, rGPR:$Rm, CPSR))]>,
848 Requires<[IsThumb2]>, Sched<[WriteALU, ReadALU, ReadALU]> {
849 let isCommutable = Commutable;
850 let Inst{31-27} = 0b11101;
851 let Inst{26-25} = 0b01;
852 let Inst{24-21} = opcod;
853 let Inst{14-12} = 0b000; // imm3
854 let Inst{7-6} = 0b00; // imm2
855 let Inst{5-4} = 0b00; // type
858 def rs : T2sTwoRegShiftedReg<
859 (outs rGPR:$Rd), (ins rGPR:$Rn, t2_so_reg:$ShiftedRm),
860 IIC_iALUsi, opc, ".w\t$Rd, $Rn, $ShiftedRm",
861 [(set rGPR:$Rd, CPSR, (opnode rGPR:$Rn, t2_so_reg:$ShiftedRm, CPSR))]>,
862 Requires<[IsThumb2]>, Sched<[WriteALUsi, ReadALU]> {
863 let Inst{31-27} = 0b11101;
864 let Inst{26-25} = 0b01;
865 let Inst{24-21} = opcod;
870 /// T2I_sh_ir - Defines a set of (op reg, {so_imm|r}) patterns for a shift /
871 // rotate operation that produces a value.
872 multiclass T2I_sh_ir<bits<2> opcod, string opc, Operand ty, SDNode opnode> {
874 def ri : T2sTwoRegShiftImm<
875 (outs rGPR:$Rd), (ins rGPR:$Rm, ty:$imm), IIC_iMOVsi,
876 opc, ".w\t$Rd, $Rm, $imm",
877 [(set rGPR:$Rd, (opnode rGPR:$Rm, (i32 ty:$imm)))]>,
879 let Inst{31-27} = 0b11101;
880 let Inst{26-21} = 0b010010;
881 let Inst{19-16} = 0b1111; // Rn
882 let Inst{5-4} = opcod;
885 def rr : T2sThreeReg<
886 (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iMOVsr,
887 opc, ".w\t$Rd, $Rn, $Rm",
888 [(set rGPR:$Rd, (opnode rGPR:$Rn, rGPR:$Rm))]>,
890 let Inst{31-27} = 0b11111;
891 let Inst{26-23} = 0b0100;
892 let Inst{22-21} = opcod;
893 let Inst{15-12} = 0b1111;
894 let Inst{7-4} = 0b0000;
897 // Optional destination register
898 def : t2InstAlias<!strconcat(opc, "${s}${p}", ".w $Rdn, $imm"),
899 (!cast<Instruction>(NAME#"ri") rGPR:$Rdn, rGPR:$Rdn, ty:$imm, pred:$p,
901 def : t2InstAlias<!strconcat(opc, "${s}${p}", ".w $Rdn, $Rm"),
902 (!cast<Instruction>(NAME#"rr") rGPR:$Rdn, rGPR:$Rdn, rGPR:$Rm, pred:$p,
905 // Assembler aliases w/o the ".w" suffix.
906 def : t2InstAlias<!strconcat(opc, "${s}${p}", " $Rd, $Rn, $imm"),
907 (!cast<Instruction>(NAME#"ri") rGPR:$Rd, rGPR:$Rn, ty:$imm, pred:$p,
909 def : t2InstAlias<!strconcat(opc, "${s}${p}", " $Rd, $Rn, $Rm"),
910 (!cast<Instruction>(NAME#"rr") rGPR:$Rd, rGPR:$Rn, rGPR:$Rm, pred:$p,
913 // and with the optional destination operand, too.
914 def : t2InstAlias<!strconcat(opc, "${s}${p}", " $Rdn, $imm"),
915 (!cast<Instruction>(NAME#"ri") rGPR:$Rdn, rGPR:$Rdn, ty:$imm, pred:$p,
917 def : t2InstAlias<!strconcat(opc, "${s}${p}", " $Rdn, $Rm"),
918 (!cast<Instruction>(NAME#"rr") rGPR:$Rdn, rGPR:$Rdn, rGPR:$Rm, pred:$p,
922 /// T2I_cmp_irs - Defines a set of (op r, {so_imm|r|so_reg}) cmp / test
923 /// patterns. Similar to T2I_bin_irs except the instruction does not produce
924 /// a explicit result, only implicitly set CPSR.
925 multiclass T2I_cmp_irs<bits<4> opcod, string opc,
926 InstrItinClass iii, InstrItinClass iir, InstrItinClass iis,
927 SDPatternOperator opnode> {
928 let isCompare = 1, Defs = [CPSR] in {
930 def ri : T2OneRegCmpImm<
931 (outs), (ins GPRnopc:$Rn, t2_so_imm:$imm), iii,
932 opc, ".w\t$Rn, $imm",
933 [(opnode GPRnopc:$Rn, t2_so_imm:$imm)]>, Sched<[WriteCMP]> {
934 let Inst{31-27} = 0b11110;
936 let Inst{24-21} = opcod;
937 let Inst{20} = 1; // The S bit.
939 let Inst{11-8} = 0b1111; // Rd
942 def rr : T2TwoRegCmp<
943 (outs), (ins GPRnopc:$Rn, rGPR:$Rm), iir,
945 [(opnode GPRnopc:$Rn, rGPR:$Rm)]>, Sched<[WriteCMP]> {
946 let Inst{31-27} = 0b11101;
947 let Inst{26-25} = 0b01;
948 let Inst{24-21} = opcod;
949 let Inst{20} = 1; // The S bit.
950 let Inst{14-12} = 0b000; // imm3
951 let Inst{11-8} = 0b1111; // Rd
952 let Inst{7-6} = 0b00; // imm2
953 let Inst{5-4} = 0b00; // type
956 def rs : T2OneRegCmpShiftedReg<
957 (outs), (ins GPRnopc:$Rn, t2_so_reg:$ShiftedRm), iis,
958 opc, ".w\t$Rn, $ShiftedRm",
959 [(opnode GPRnopc:$Rn, t2_so_reg:$ShiftedRm)]>,
960 Sched<[WriteCMPsi]> {
961 let Inst{31-27} = 0b11101;
962 let Inst{26-25} = 0b01;
963 let Inst{24-21} = opcod;
964 let Inst{20} = 1; // The S bit.
965 let Inst{11-8} = 0b1111; // Rd
969 // Assembler aliases w/o the ".w" suffix.
970 // No alias here for 'rr' version as not all instantiations of this
971 // multiclass want one (CMP in particular, does not).
972 def : t2InstAlias<!strconcat(opc, "${p}", " $Rn, $imm"),
973 (!cast<Instruction>(NAME#"ri") GPRnopc:$Rn, t2_so_imm:$imm, pred:$p)>;
974 def : t2InstAlias<!strconcat(opc, "${p}", " $Rn, $shift"),
975 (!cast<Instruction>(NAME#"rs") GPRnopc:$Rn, t2_so_reg:$shift, pred:$p)>;
978 /// T2I_ld - Defines a set of (op r, {imm12|imm8|so_reg}) load patterns.
979 multiclass T2I_ld<bit signed, bits<2> opcod, string opc,
980 InstrItinClass iii, InstrItinClass iis, RegisterClass target,
982 def i12 : T2Ii12<(outs target:$Rt), (ins t2addrmode_imm12:$addr), iii,
983 opc, ".w\t$Rt, $addr",
984 [(set target:$Rt, (opnode t2addrmode_imm12:$addr))]>,
988 let Inst{31-25} = 0b1111100;
989 let Inst{24} = signed;
991 let Inst{22-21} = opcod;
992 let Inst{20} = 1; // load
993 let Inst{19-16} = addr{16-13}; // Rn
994 let Inst{15-12} = Rt;
995 let Inst{11-0} = addr{11-0}; // imm
997 let DecoderMethod = "DecodeT2LoadImm12";
999 def i8 : T2Ii8 <(outs target:$Rt), (ins t2addrmode_negimm8:$addr), iii,
1000 opc, "\t$Rt, $addr",
1001 [(set target:$Rt, (opnode t2addrmode_negimm8:$addr))]>,
1005 let Inst{31-27} = 0b11111;
1006 let Inst{26-25} = 0b00;
1007 let Inst{24} = signed;
1009 let Inst{22-21} = opcod;
1010 let Inst{20} = 1; // load
1011 let Inst{19-16} = addr{12-9}; // Rn
1012 let Inst{15-12} = Rt;
1014 // Offset: index==TRUE, wback==FALSE
1015 let Inst{10} = 1; // The P bit.
1016 let Inst{9} = addr{8}; // U
1017 let Inst{8} = 0; // The W bit.
1018 let Inst{7-0} = addr{7-0}; // imm
1020 let DecoderMethod = "DecodeT2LoadImm8";
1022 def s : T2Iso <(outs target:$Rt), (ins t2addrmode_so_reg:$addr), iis,
1023 opc, ".w\t$Rt, $addr",
1024 [(set target:$Rt, (opnode t2addrmode_so_reg:$addr))]>,
1026 let Inst{31-27} = 0b11111;
1027 let Inst{26-25} = 0b00;
1028 let Inst{24} = signed;
1030 let Inst{22-21} = opcod;
1031 let Inst{20} = 1; // load
1032 let Inst{11-6} = 0b000000;
1035 let Inst{15-12} = Rt;
1038 let Inst{19-16} = addr{9-6}; // Rn
1039 let Inst{3-0} = addr{5-2}; // Rm
1040 let Inst{5-4} = addr{1-0}; // imm
1042 let DecoderMethod = "DecodeT2LoadShift";
1045 // pci variant is very similar to i12, but supports negative offsets
1047 def pci : T2Ipc <(outs target:$Rt), (ins t2ldrlabel:$addr), iii,
1048 opc, ".w\t$Rt, $addr",
1049 [(set target:$Rt, (opnode (ARMWrapper tconstpool:$addr)))]>,
1051 let isReMaterializable = 1;
1052 let Inst{31-27} = 0b11111;
1053 let Inst{26-25} = 0b00;
1054 let Inst{24} = signed;
1055 let Inst{22-21} = opcod;
1056 let Inst{20} = 1; // load
1057 let Inst{19-16} = 0b1111; // Rn
1060 let Inst{15-12} = Rt{3-0};
1063 let Inst{23} = addr{12}; // add = (U == '1')
1064 let Inst{11-0} = addr{11-0};
1066 let DecoderMethod = "DecodeT2LoadLabel";
1070 /// T2I_st - Defines a set of (op r, {imm12|imm8|so_reg}) store patterns.
1071 multiclass T2I_st<bits<2> opcod, string opc,
1072 InstrItinClass iii, InstrItinClass iis, RegisterClass target,
1074 def i12 : T2Ii12<(outs), (ins target:$Rt, t2addrmode_imm12:$addr), iii,
1075 opc, ".w\t$Rt, $addr",
1076 [(opnode target:$Rt, t2addrmode_imm12:$addr)]>,
1078 let Inst{31-27} = 0b11111;
1079 let Inst{26-23} = 0b0001;
1080 let Inst{22-21} = opcod;
1081 let Inst{20} = 0; // !load
1084 let Inst{15-12} = Rt;
1087 let addr{12} = 1; // add = TRUE
1088 let Inst{19-16} = addr{16-13}; // Rn
1089 let Inst{23} = addr{12}; // U
1090 let Inst{11-0} = addr{11-0}; // imm
1092 def i8 : T2Ii8 <(outs), (ins target:$Rt, t2addrmode_negimm8:$addr), iii,
1093 opc, "\t$Rt, $addr",
1094 [(opnode target:$Rt, t2addrmode_negimm8:$addr)]>,
1096 let Inst{31-27} = 0b11111;
1097 let Inst{26-23} = 0b0000;
1098 let Inst{22-21} = opcod;
1099 let Inst{20} = 0; // !load
1101 // Offset: index==TRUE, wback==FALSE
1102 let Inst{10} = 1; // The P bit.
1103 let Inst{8} = 0; // The W bit.
1106 let Inst{15-12} = Rt;
1109 let Inst{19-16} = addr{12-9}; // Rn
1110 let Inst{9} = addr{8}; // U
1111 let Inst{7-0} = addr{7-0}; // imm
1113 def s : T2Iso <(outs), (ins target:$Rt, t2addrmode_so_reg:$addr), iis,
1114 opc, ".w\t$Rt, $addr",
1115 [(opnode target:$Rt, t2addrmode_so_reg:$addr)]>,
1117 let Inst{31-27} = 0b11111;
1118 let Inst{26-23} = 0b0000;
1119 let Inst{22-21} = opcod;
1120 let Inst{20} = 0; // !load
1121 let Inst{11-6} = 0b000000;
1124 let Inst{15-12} = Rt;
1127 let Inst{19-16} = addr{9-6}; // Rn
1128 let Inst{3-0} = addr{5-2}; // Rm
1129 let Inst{5-4} = addr{1-0}; // imm
1133 /// T2I_ext_rrot - A unary operation with two forms: one whose operand is a
1134 /// register and one whose operand is a register rotated by 8/16/24.
1135 class T2I_ext_rrot_base<bits<3> opcod, dag iops, dag oops,
1136 string opc, string oprs,
1138 : T2TwoReg<iops, oops, IIC_iEXTr, opc, oprs, pattern> {
1140 let Inst{31-27} = 0b11111;
1141 let Inst{26-23} = 0b0100;
1142 let Inst{22-20} = opcod;
1143 let Inst{19-16} = 0b1111; // Rn
1144 let Inst{15-12} = 0b1111;
1146 let Inst{5-4} = rot; // rotate
1149 class T2I_ext_rrot<bits<3> opcod, string opc>
1150 : T2I_ext_rrot_base<opcod,
1152 (ins rGPR:$Rm, rot_imm:$rot),
1153 opc, ".w\t$Rd, $Rm$rot", []>,
1154 Requires<[IsThumb2]>,
1155 Sched<[WriteALU, ReadALU]>;
1157 // UXTB16, SXTB16 - Requires HasDSP, does not need the .w qualifier.
1158 class T2I_ext_rrot_xtb16<bits<3> opcod, string opc>
1159 : T2I_ext_rrot_base<opcod,
1161 (ins rGPR:$Rm, rot_imm:$rot),
1162 opc, "\t$Rd, $Rm$rot", []>,
1163 Requires<[HasDSP, IsThumb2]>,
1164 Sched<[WriteALU, ReadALU]>;
1166 /// T2I_exta_rrot - A binary operation with two forms: one whose operand is a
1167 /// register and one whose operand is a register rotated by 8/16/24.
1168 class T2I_exta_rrot<bits<3> opcod, string opc>
1169 : T2ThreeReg<(outs rGPR:$Rd),
1170 (ins rGPR:$Rn, rGPR:$Rm, rot_imm:$rot),
1171 IIC_iEXTAsr, opc, "\t$Rd, $Rn, $Rm$rot", []>,
1172 Requires<[HasDSP, IsThumb2]>,
1173 Sched<[WriteALU, ReadALU]> {
1175 let Inst{31-27} = 0b11111;
1176 let Inst{26-23} = 0b0100;
1177 let Inst{22-20} = opcod;
1178 let Inst{15-12} = 0b1111;
1180 let Inst{5-4} = rot;
1183 //===----------------------------------------------------------------------===//
1185 //===----------------------------------------------------------------------===//
1187 //===----------------------------------------------------------------------===//
1188 // Miscellaneous Instructions.
1191 class T2PCOneRegImm<dag oops, dag iops, InstrItinClass itin,
1192 string asm, list<dag> pattern>
1193 : T2XI<oops, iops, itin, asm, pattern> {
1197 let Inst{11-8} = Rd;
1198 let Inst{26} = label{11};
1199 let Inst{14-12} = label{10-8};
1200 let Inst{7-0} = label{7-0};
1203 // LEApcrel - Load a pc-relative address into a register without offending the
1205 def t2ADR : T2PCOneRegImm<(outs rGPR:$Rd),
1206 (ins t2adrlabel:$addr, pred:$p),
1207 IIC_iALUi, "adr{$p}.w\t$Rd, $addr", []>,
1208 Sched<[WriteALU, ReadALU]> {
1209 let Inst{31-27} = 0b11110;
1210 let Inst{25-24} = 0b10;
1211 // Inst{23:21} = '11' (add = FALSE) or '00' (add = TRUE)
1214 let Inst{19-16} = 0b1111; // Rn
1219 let Inst{11-8} = Rd;
1220 let Inst{23} = addr{12};
1221 let Inst{21} = addr{12};
1222 let Inst{26} = addr{11};
1223 let Inst{14-12} = addr{10-8};
1224 let Inst{7-0} = addr{7-0};
1226 let DecoderMethod = "DecodeT2Adr";
1229 let hasSideEffects = 0, isReMaterializable = 1 in
1230 def t2LEApcrel : t2PseudoInst<(outs rGPR:$Rd), (ins i32imm:$label, pred:$p),
1231 4, IIC_iALUi, []>, Sched<[WriteALU, ReadALU]>;
1232 let hasSideEffects = 1 in
1233 def t2LEApcrelJT : t2PseudoInst<(outs rGPR:$Rd),
1234 (ins i32imm:$label, pred:$p),
1236 []>, Sched<[WriteALU, ReadALU]>;
1239 //===----------------------------------------------------------------------===//
1240 // Load / store Instructions.
1244 let canFoldAsLoad = 1, isReMaterializable = 1 in
1245 defm t2LDR : T2I_ld<0, 0b10, "ldr", IIC_iLoad_i, IIC_iLoad_si, GPR, load>;
1247 // Loads with zero extension
1248 defm t2LDRH : T2I_ld<0, 0b01, "ldrh", IIC_iLoad_bh_i, IIC_iLoad_bh_si,
1249 GPRnopc, zextloadi16>;
1250 defm t2LDRB : T2I_ld<0, 0b00, "ldrb", IIC_iLoad_bh_i, IIC_iLoad_bh_si,
1251 GPRnopc, zextloadi8>;
1253 // Loads with sign extension
1254 defm t2LDRSH : T2I_ld<1, 0b01, "ldrsh", IIC_iLoad_bh_i, IIC_iLoad_bh_si,
1255 GPRnopc, sextloadi16>;
1256 defm t2LDRSB : T2I_ld<1, 0b00, "ldrsb", IIC_iLoad_bh_i, IIC_iLoad_bh_si,
1257 GPRnopc, sextloadi8>;
1259 let mayLoad = 1, hasSideEffects = 0, hasExtraDefRegAllocReq = 1 in {
1261 def t2LDRDi8 : T2Ii8s4<1, 0, 1, (outs rGPR:$Rt, rGPR:$Rt2),
1262 (ins t2addrmode_imm8s4:$addr),
1263 IIC_iLoad_d_i, "ldrd", "\t$Rt, $Rt2, $addr", "", []>,
1265 } // mayLoad = 1, hasSideEffects = 0, hasExtraDefRegAllocReq = 1
1267 // zextload i1 -> zextload i8
1268 def : T2Pat<(zextloadi1 t2addrmode_imm12:$addr),
1269 (t2LDRBi12 t2addrmode_imm12:$addr)>;
1270 def : T2Pat<(zextloadi1 t2addrmode_negimm8:$addr),
1271 (t2LDRBi8 t2addrmode_negimm8:$addr)>;
1272 def : T2Pat<(zextloadi1 t2addrmode_so_reg:$addr),
1273 (t2LDRBs t2addrmode_so_reg:$addr)>;
1274 def : T2Pat<(zextloadi1 (ARMWrapper tconstpool:$addr)),
1275 (t2LDRBpci tconstpool:$addr)>;
1277 // extload -> zextload
1278 // FIXME: Reduce the number of patterns by legalizing extload to zextload
1280 def : T2Pat<(extloadi1 t2addrmode_imm12:$addr),
1281 (t2LDRBi12 t2addrmode_imm12:$addr)>;
1282 def : T2Pat<(extloadi1 t2addrmode_negimm8:$addr),
1283 (t2LDRBi8 t2addrmode_negimm8:$addr)>;
1284 def : T2Pat<(extloadi1 t2addrmode_so_reg:$addr),
1285 (t2LDRBs t2addrmode_so_reg:$addr)>;
1286 def : T2Pat<(extloadi1 (ARMWrapper tconstpool:$addr)),
1287 (t2LDRBpci tconstpool:$addr)>;
1289 def : T2Pat<(extloadi8 t2addrmode_imm12:$addr),
1290 (t2LDRBi12 t2addrmode_imm12:$addr)>;
1291 def : T2Pat<(extloadi8 t2addrmode_negimm8:$addr),
1292 (t2LDRBi8 t2addrmode_negimm8:$addr)>;
1293 def : T2Pat<(extloadi8 t2addrmode_so_reg:$addr),
1294 (t2LDRBs t2addrmode_so_reg:$addr)>;
1295 def : T2Pat<(extloadi8 (ARMWrapper tconstpool:$addr)),
1296 (t2LDRBpci tconstpool:$addr)>;
1298 def : T2Pat<(extloadi16 t2addrmode_imm12:$addr),
1299 (t2LDRHi12 t2addrmode_imm12:$addr)>;
1300 def : T2Pat<(extloadi16 t2addrmode_negimm8:$addr),
1301 (t2LDRHi8 t2addrmode_negimm8:$addr)>;
1302 def : T2Pat<(extloadi16 t2addrmode_so_reg:$addr),
1303 (t2LDRHs t2addrmode_so_reg:$addr)>;
1304 def : T2Pat<(extloadi16 (ARMWrapper tconstpool:$addr)),
1305 (t2LDRHpci tconstpool:$addr)>;
1307 // FIXME: The destination register of the loads and stores can't be PC, but
1308 // can be SP. We need another regclass (similar to rGPR) to represent
1309 // that. Not a pressing issue since these are selected manually,
1314 let mayLoad = 1, hasSideEffects = 0 in {
1315 def t2LDR_PRE : T2Ipreldst<0, 0b10, 1, 1, (outs GPR:$Rt, GPR:$Rn_wb),
1316 (ins t2addrmode_imm8_pre:$addr),
1317 AddrModeT2_i8, IndexModePre, IIC_iLoad_iu,
1318 "ldr", "\t$Rt, $addr!", "$addr.base = $Rn_wb", []>,
1321 def t2LDR_POST : T2Ipostldst<0, 0b10, 1, 0, (outs GPR:$Rt, GPR:$Rn_wb),
1322 (ins addr_offset_none:$Rn, t2am_imm8_offset:$offset),
1323 AddrModeT2_i8, IndexModePost, IIC_iLoad_iu,
1324 "ldr", "\t$Rt, $Rn$offset", "$Rn = $Rn_wb", []>,
1327 def t2LDRB_PRE : T2Ipreldst<0, 0b00, 1, 1, (outs GPR:$Rt, GPR:$Rn_wb),
1328 (ins t2addrmode_imm8_pre:$addr),
1329 AddrModeT2_i8, IndexModePre, IIC_iLoad_bh_iu,
1330 "ldrb", "\t$Rt, $addr!", "$addr.base = $Rn_wb", []>,
1333 def t2LDRB_POST : T2Ipostldst<0, 0b00, 1, 0, (outs GPR:$Rt, GPR:$Rn_wb),
1334 (ins addr_offset_none:$Rn, t2am_imm8_offset:$offset),
1335 AddrModeT2_i8, IndexModePost, IIC_iLoad_bh_iu,
1336 "ldrb", "\t$Rt, $Rn$offset", "$Rn = $Rn_wb", []>;
1338 def t2LDRH_PRE : T2Ipreldst<0, 0b01, 1, 1, (outs GPR:$Rt, GPR:$Rn_wb),
1339 (ins t2addrmode_imm8_pre:$addr),
1340 AddrModeT2_i8, IndexModePre, IIC_iLoad_bh_iu,
1341 "ldrh", "\t$Rt, $addr!", "$addr.base = $Rn_wb", []>,
1344 def t2LDRH_POST : T2Ipostldst<0, 0b01, 1, 0, (outs GPR:$Rt, GPR:$Rn_wb),
1345 (ins addr_offset_none:$Rn, t2am_imm8_offset:$offset),
1346 AddrModeT2_i8, IndexModePost, IIC_iLoad_bh_iu,
1347 "ldrh", "\t$Rt, $Rn$offset", "$Rn = $Rn_wb", []>,
1350 def t2LDRSB_PRE : T2Ipreldst<1, 0b00, 1, 1, (outs GPR:$Rt, GPR:$Rn_wb),
1351 (ins t2addrmode_imm8_pre:$addr),
1352 AddrModeT2_i8, IndexModePre, IIC_iLoad_bh_iu,
1353 "ldrsb", "\t$Rt, $addr!", "$addr.base = $Rn_wb",
1354 []>, Sched<[WriteLd]>;
1356 def t2LDRSB_POST : T2Ipostldst<1, 0b00, 1, 0, (outs GPR:$Rt, GPR:$Rn_wb),
1357 (ins addr_offset_none:$Rn, t2am_imm8_offset:$offset),
1358 AddrModeT2_i8, IndexModePost, IIC_iLoad_bh_iu,
1359 "ldrsb", "\t$Rt, $Rn$offset", "$Rn = $Rn_wb", []>,
1362 def t2LDRSH_PRE : T2Ipreldst<1, 0b01, 1, 1, (outs GPR:$Rt, GPR:$Rn_wb),
1363 (ins t2addrmode_imm8_pre:$addr),
1364 AddrModeT2_i8, IndexModePre, IIC_iLoad_bh_iu,
1365 "ldrsh", "\t$Rt, $addr!", "$addr.base = $Rn_wb",
1366 []>, Sched<[WriteLd]>;
1368 def t2LDRSH_POST : T2Ipostldst<1, 0b01, 1, 0, (outs GPR:$Rt, GPR:$Rn_wb),
1369 (ins addr_offset_none:$Rn, t2am_imm8_offset:$offset),
1370 AddrModeT2_i8, IndexModePost, IIC_iLoad_bh_iu,
1371 "ldrsh", "\t$Rt, $Rn$offset", "$Rn = $Rn_wb", []>,
1373 } // mayLoad = 1, hasSideEffects = 0
1375 // LDRT, LDRBT, LDRHT, LDRSBT, LDRSHT all have offset mode (PUW=0b110).
1376 // Ref: A8.6.57 LDR (immediate, Thumb) Encoding T4
1377 class T2IldT<bit signed, bits<2> type, string opc, InstrItinClass ii>
1378 : T2Ii8<(outs rGPR:$Rt), (ins t2addrmode_posimm8:$addr), ii, opc,
1379 "\t$Rt, $addr", []>, Sched<[WriteLd]> {
1382 let Inst{31-27} = 0b11111;
1383 let Inst{26-25} = 0b00;
1384 let Inst{24} = signed;
1386 let Inst{22-21} = type;
1387 let Inst{20} = 1; // load
1388 let Inst{19-16} = addr{12-9};
1389 let Inst{15-12} = Rt;
1391 let Inst{10-8} = 0b110; // PUW.
1392 let Inst{7-0} = addr{7-0};
1394 let DecoderMethod = "DecodeT2LoadT";
1397 def t2LDRT : T2IldT<0, 0b10, "ldrt", IIC_iLoad_i>;
1398 def t2LDRBT : T2IldT<0, 0b00, "ldrbt", IIC_iLoad_bh_i>;
1399 def t2LDRHT : T2IldT<0, 0b01, "ldrht", IIC_iLoad_bh_i>;
1400 def t2LDRSBT : T2IldT<1, 0b00, "ldrsbt", IIC_iLoad_bh_i>;
1401 def t2LDRSHT : T2IldT<1, 0b01, "ldrsht", IIC_iLoad_bh_i>;
1403 class T2Ildacq<bits<4> bits23_20, bits<2> bit54, dag oops, dag iops,
1404 string opc, string asm, list<dag> pattern>
1405 : Thumb2I<oops, iops, AddrModeNone, 4, NoItinerary,
1406 opc, asm, "", pattern>, Requires<[IsThumb, HasAcquireRelease]> {
1410 let Inst{31-27} = 0b11101;
1411 let Inst{26-24} = 0b000;
1412 let Inst{23-20} = bits23_20;
1413 let Inst{11-6} = 0b111110;
1414 let Inst{5-4} = bit54;
1415 let Inst{3-0} = 0b1111;
1417 // Encode instruction operands
1418 let Inst{19-16} = addr;
1419 let Inst{15-12} = Rt;
1422 def t2LDA : T2Ildacq<0b1101, 0b10, (outs rGPR:$Rt),
1423 (ins addr_offset_none:$addr), "lda", "\t$Rt, $addr", []>,
1425 def t2LDAB : T2Ildacq<0b1101, 0b00, (outs rGPR:$Rt),
1426 (ins addr_offset_none:$addr), "ldab", "\t$Rt, $addr", []>,
1428 def t2LDAH : T2Ildacq<0b1101, 0b01, (outs rGPR:$Rt),
1429 (ins addr_offset_none:$addr), "ldah", "\t$Rt, $addr", []>,
1433 defm t2STR :T2I_st<0b10,"str", IIC_iStore_i, IIC_iStore_si, GPR, store>;
1434 defm t2STRB:T2I_st<0b00,"strb", IIC_iStore_bh_i, IIC_iStore_bh_si,
1435 rGPR, truncstorei8>;
1436 defm t2STRH:T2I_st<0b01,"strh", IIC_iStore_bh_i, IIC_iStore_bh_si,
1437 rGPR, truncstorei16>;
1440 let mayStore = 1, hasSideEffects = 0, hasExtraSrcRegAllocReq = 1 in
1441 def t2STRDi8 : T2Ii8s4<1, 0, 0, (outs),
1442 (ins rGPR:$Rt, rGPR:$Rt2, t2addrmode_imm8s4:$addr),
1443 IIC_iStore_d_r, "strd", "\t$Rt, $Rt2, $addr", "", []>,
1448 let mayStore = 1, hasSideEffects = 0 in {
1449 def t2STR_PRE : T2Ipreldst<0, 0b10, 0, 1, (outs GPRnopc:$Rn_wb),
1450 (ins GPRnopc:$Rt, t2addrmode_imm8_pre:$addr),
1451 AddrModeT2_i8, IndexModePre, IIC_iStore_iu,
1452 "str", "\t$Rt, $addr!",
1453 "$addr.base = $Rn_wb,@earlyclobber $Rn_wb", []>,
1456 def t2STRH_PRE : T2Ipreldst<0, 0b01, 0, 1, (outs GPRnopc:$Rn_wb),
1457 (ins rGPR:$Rt, t2addrmode_imm8_pre:$addr),
1458 AddrModeT2_i8, IndexModePre, IIC_iStore_iu,
1459 "strh", "\t$Rt, $addr!",
1460 "$addr.base = $Rn_wb,@earlyclobber $Rn_wb", []>,
1463 def t2STRB_PRE : T2Ipreldst<0, 0b00, 0, 1, (outs GPRnopc:$Rn_wb),
1464 (ins rGPR:$Rt, t2addrmode_imm8_pre:$addr),
1465 AddrModeT2_i8, IndexModePre, IIC_iStore_bh_iu,
1466 "strb", "\t$Rt, $addr!",
1467 "$addr.base = $Rn_wb,@earlyclobber $Rn_wb", []>,
1469 } // mayStore = 1, hasSideEffects = 0
1471 def t2STR_POST : T2Ipostldst<0, 0b10, 0, 0, (outs GPRnopc:$Rn_wb),
1472 (ins GPRnopc:$Rt, addr_offset_none:$Rn,
1473 t2am_imm8_offset:$offset),
1474 AddrModeT2_i8, IndexModePost, IIC_iStore_iu,
1475 "str", "\t$Rt, $Rn$offset",
1476 "$Rn = $Rn_wb,@earlyclobber $Rn_wb",
1477 [(set GPRnopc:$Rn_wb,
1478 (post_store GPRnopc:$Rt, addr_offset_none:$Rn,
1479 t2am_imm8_offset:$offset))]>,
1482 def t2STRH_POST : T2Ipostldst<0, 0b01, 0, 0, (outs GPRnopc:$Rn_wb),
1483 (ins rGPR:$Rt, addr_offset_none:$Rn,
1484 t2am_imm8_offset:$offset),
1485 AddrModeT2_i8, IndexModePost, IIC_iStore_bh_iu,
1486 "strh", "\t$Rt, $Rn$offset",
1487 "$Rn = $Rn_wb,@earlyclobber $Rn_wb",
1488 [(set GPRnopc:$Rn_wb,
1489 (post_truncsti16 rGPR:$Rt, addr_offset_none:$Rn,
1490 t2am_imm8_offset:$offset))]>,
1493 def t2STRB_POST : T2Ipostldst<0, 0b00, 0, 0, (outs GPRnopc:$Rn_wb),
1494 (ins rGPR:$Rt, addr_offset_none:$Rn,
1495 t2am_imm8_offset:$offset),
1496 AddrModeT2_i8, IndexModePost, IIC_iStore_bh_iu,
1497 "strb", "\t$Rt, $Rn$offset",
1498 "$Rn = $Rn_wb,@earlyclobber $Rn_wb",
1499 [(set GPRnopc:$Rn_wb,
1500 (post_truncsti8 rGPR:$Rt, addr_offset_none:$Rn,
1501 t2am_imm8_offset:$offset))]>,
1504 // Pseudo-instructions for pattern matching the pre-indexed stores. We can't
1505 // put the patterns on the instruction definitions directly as ISel wants
1506 // the address base and offset to be separate operands, not a single
1507 // complex operand like we represent the instructions themselves. The
1508 // pseudos map between the two.
1509 let usesCustomInserter = 1,
1510 Constraints = "$Rn = $Rn_wb,@earlyclobber $Rn_wb" in {
1511 def t2STR_preidx: t2PseudoInst<(outs GPRnopc:$Rn_wb),
1512 (ins rGPR:$Rt, GPRnopc:$Rn, t2am_imm8_offset:$offset, pred:$p),
1514 [(set GPRnopc:$Rn_wb,
1515 (pre_store rGPR:$Rt, GPRnopc:$Rn, t2am_imm8_offset:$offset))]>,
1517 def t2STRB_preidx: t2PseudoInst<(outs GPRnopc:$Rn_wb),
1518 (ins rGPR:$Rt, GPRnopc:$Rn, t2am_imm8_offset:$offset, pred:$p),
1520 [(set GPRnopc:$Rn_wb,
1521 (pre_truncsti8 rGPR:$Rt, GPRnopc:$Rn, t2am_imm8_offset:$offset))]>,
1523 def t2STRH_preidx: t2PseudoInst<(outs GPRnopc:$Rn_wb),
1524 (ins rGPR:$Rt, GPRnopc:$Rn, t2am_imm8_offset:$offset, pred:$p),
1526 [(set GPRnopc:$Rn_wb,
1527 (pre_truncsti16 rGPR:$Rt, GPRnopc:$Rn, t2am_imm8_offset:$offset))]>,
1531 // STRT, STRBT, STRHT all have offset mode (PUW=0b110) and are for disassembly
1533 // Ref: A8.6.193 STR (immediate, Thumb) Encoding T4
1534 class T2IstT<bits<2> type, string opc, InstrItinClass ii>
1535 : T2Ii8<(outs rGPR:$Rt), (ins t2addrmode_imm8:$addr), ii, opc,
1536 "\t$Rt, $addr", []>, Sched<[WriteST]> {
1537 let Inst{31-27} = 0b11111;
1538 let Inst{26-25} = 0b00;
1539 let Inst{24} = 0; // not signed
1541 let Inst{22-21} = type;
1542 let Inst{20} = 0; // store
1544 let Inst{10-8} = 0b110; // PUW
1548 let Inst{15-12} = Rt;
1549 let Inst{19-16} = addr{12-9};
1550 let Inst{7-0} = addr{7-0};
1553 def t2STRT : T2IstT<0b10, "strt", IIC_iStore_i>;
1554 def t2STRBT : T2IstT<0b00, "strbt", IIC_iStore_bh_i>;
1555 def t2STRHT : T2IstT<0b01, "strht", IIC_iStore_bh_i>;
1557 // ldrd / strd pre / post variants
1560 def t2LDRD_PRE : T2Ii8s4<1, 1, 1, (outs rGPR:$Rt, rGPR:$Rt2, GPR:$wb),
1561 (ins t2addrmode_imm8s4_pre:$addr), IIC_iLoad_d_ru,
1562 "ldrd", "\t$Rt, $Rt2, $addr!", "$addr.base = $wb", []>,
1564 let DecoderMethod = "DecodeT2LDRDPreInstruction";
1568 def t2LDRD_POST : T2Ii8s4post<0, 1, 1, (outs rGPR:$Rt, rGPR:$Rt2, GPR:$wb),
1569 (ins addr_offset_none:$addr, t2am_imm8s4_offset:$imm),
1570 IIC_iLoad_d_ru, "ldrd", "\t$Rt, $Rt2, $addr$imm",
1571 "$addr.base = $wb", []>, Sched<[WriteLd]>;
1574 def t2STRD_PRE : T2Ii8s4<1, 1, 0, (outs GPR:$wb),
1575 (ins rGPR:$Rt, rGPR:$Rt2, t2addrmode_imm8s4_pre:$addr),
1576 IIC_iStore_d_ru, "strd", "\t$Rt, $Rt2, $addr!",
1577 "$addr.base = $wb", []>, Sched<[WriteST]> {
1578 let DecoderMethod = "DecodeT2STRDPreInstruction";
1582 def t2STRD_POST : T2Ii8s4post<0, 1, 0, (outs GPR:$wb),
1583 (ins rGPR:$Rt, rGPR:$Rt2, addr_offset_none:$addr,
1584 t2am_imm8s4_offset:$imm),
1585 IIC_iStore_d_ru, "strd", "\t$Rt, $Rt2, $addr$imm",
1586 "$addr.base = $wb", []>, Sched<[WriteST]>;
1588 class T2Istrrel<bits<2> bit54, dag oops, dag iops,
1589 string opc, string asm, list<dag> pattern>
1590 : Thumb2I<oops, iops, AddrModeNone, 4, NoItinerary, opc,
1591 asm, "", pattern>, Requires<[IsThumb, HasAcquireRelease]>,
1596 let Inst{31-27} = 0b11101;
1597 let Inst{26-20} = 0b0001100;
1598 let Inst{11-6} = 0b111110;
1599 let Inst{5-4} = bit54;
1600 let Inst{3-0} = 0b1111;
1602 // Encode instruction operands
1603 let Inst{19-16} = addr;
1604 let Inst{15-12} = Rt;
1607 def t2STL : T2Istrrel<0b10, (outs), (ins rGPR:$Rt, addr_offset_none:$addr),
1608 "stl", "\t$Rt, $addr", []>;
1609 def t2STLB : T2Istrrel<0b00, (outs), (ins rGPR:$Rt, addr_offset_none:$addr),
1610 "stlb", "\t$Rt, $addr", []>;
1611 def t2STLH : T2Istrrel<0b01, (outs), (ins rGPR:$Rt, addr_offset_none:$addr),
1612 "stlh", "\t$Rt, $addr", []>;
1614 // T2Ipl (Preload Data/Instruction) signals the memory system of possible future
1615 // data/instruction access.
1616 // instr_write is inverted for Thumb mode: (prefetch 3) -> (preload 0),
1617 // (prefetch 1) -> (preload 2), (prefetch 2) -> (preload 1).
1618 multiclass T2Ipl<bits<1> write, bits<1> instr, string opc> {
1620 def i12 : T2Ii12<(outs), (ins t2addrmode_imm12:$addr), IIC_Preload, opc,
1622 [(ARMPreload t2addrmode_imm12:$addr, (i32 write), (i32 instr))]>,
1623 Sched<[WritePreLd]> {
1624 let Inst{31-25} = 0b1111100;
1625 let Inst{24} = instr;
1628 let Inst{21} = write;
1630 let Inst{15-12} = 0b1111;
1633 let Inst{19-16} = addr{16-13}; // Rn
1634 let Inst{11-0} = addr{11-0}; // imm12
1636 let DecoderMethod = "DecodeT2LoadImm12";
1639 def i8 : T2Ii8<(outs), (ins t2addrmode_negimm8:$addr), IIC_Preload, opc,
1641 [(ARMPreload t2addrmode_negimm8:$addr, (i32 write), (i32 instr))]>,
1642 Sched<[WritePreLd]> {
1643 let Inst{31-25} = 0b1111100;
1644 let Inst{24} = instr;
1645 let Inst{23} = 0; // U = 0
1647 let Inst{21} = write;
1649 let Inst{15-12} = 0b1111;
1650 let Inst{11-8} = 0b1100;
1653 let Inst{19-16} = addr{12-9}; // Rn
1654 let Inst{7-0} = addr{7-0}; // imm8
1656 let DecoderMethod = "DecodeT2LoadImm8";
1659 def s : T2Iso<(outs), (ins t2addrmode_so_reg:$addr), IIC_Preload, opc,
1661 [(ARMPreload t2addrmode_so_reg:$addr, (i32 write), (i32 instr))]>,
1662 Sched<[WritePreLd]> {
1663 let Inst{31-25} = 0b1111100;
1664 let Inst{24} = instr;
1665 let Inst{23} = 0; // add = TRUE for T1
1667 let Inst{21} = write;
1669 let Inst{15-12} = 0b1111;
1670 let Inst{11-6} = 0b000000;
1673 let Inst{19-16} = addr{9-6}; // Rn
1674 let Inst{3-0} = addr{5-2}; // Rm
1675 let Inst{5-4} = addr{1-0}; // imm2
1677 let DecoderMethod = "DecodeT2LoadShift";
1681 defm t2PLD : T2Ipl<0, 0, "pld">, Requires<[IsThumb2]>;
1682 defm t2PLDW : T2Ipl<1, 0, "pldw">, Requires<[IsThumb2,HasV7,HasMP]>;
1683 defm t2PLI : T2Ipl<0, 1, "pli">, Requires<[IsThumb2,HasV7]>;
1685 // pci variant is very similar to i12, but supports negative offsets
1686 // from the PC. Only PLD and PLI have pci variants (not PLDW)
1687 class T2Iplpci<bits<1> inst, string opc> : T2Iso<(outs), (ins t2ldrlabel:$addr),
1688 IIC_Preload, opc, "\t$addr",
1689 [(ARMPreload (ARMWrapper tconstpool:$addr),
1690 (i32 0), (i32 inst))]>, Sched<[WritePreLd]> {
1691 let Inst{31-25} = 0b1111100;
1692 let Inst{24} = inst;
1693 let Inst{22-20} = 0b001;
1694 let Inst{19-16} = 0b1111;
1695 let Inst{15-12} = 0b1111;
1698 let Inst{23} = addr{12}; // add = (U == '1')
1699 let Inst{11-0} = addr{11-0}; // imm12
1701 let DecoderMethod = "DecodeT2LoadLabel";
1704 def t2PLDpci : T2Iplpci<0, "pld">, Requires<[IsThumb2]>;
1705 def t2PLIpci : T2Iplpci<1, "pli">, Requires<[IsThumb2,HasV7]>;
1707 //===----------------------------------------------------------------------===//
1708 // Load / store multiple Instructions.
1711 multiclass thumb2_ld_mult<string asm, InstrItinClass itin,
1712 InstrItinClass itin_upd, bit L_bit> {
1714 T2XI<(outs), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops),
1715 itin, !strconcat(asm, "${p}.w\t$Rn, $regs"), []> {
1719 let Inst{31-27} = 0b11101;
1720 let Inst{26-25} = 0b00;
1721 let Inst{24-23} = 0b01; // Increment After
1723 let Inst{21} = 0; // No writeback
1724 let Inst{20} = L_bit;
1725 let Inst{19-16} = Rn;
1726 let Inst{15-0} = regs;
1729 T2XIt<(outs GPR:$wb), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops),
1730 itin_upd, !strconcat(asm, "${p}.w\t$Rn!, $regs"), "$Rn = $wb", []> {
1734 let Inst{31-27} = 0b11101;
1735 let Inst{26-25} = 0b00;
1736 let Inst{24-23} = 0b01; // Increment After
1738 let Inst{21} = 1; // Writeback
1739 let Inst{20} = L_bit;
1740 let Inst{19-16} = Rn;
1741 let Inst{15-0} = regs;
1744 T2XI<(outs), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops),
1745 itin, !strconcat(asm, "db${p}\t$Rn, $regs"), []> {
1749 let Inst{31-27} = 0b11101;
1750 let Inst{26-25} = 0b00;
1751 let Inst{24-23} = 0b10; // Decrement Before
1753 let Inst{21} = 0; // No writeback
1754 let Inst{20} = L_bit;
1755 let Inst{19-16} = Rn;
1756 let Inst{15-0} = regs;
1759 T2XIt<(outs GPR:$wb), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops),
1760 itin_upd, !strconcat(asm, "db${p}\t$Rn!, $regs"), "$Rn = $wb", []> {
1764 let Inst{31-27} = 0b11101;
1765 let Inst{26-25} = 0b00;
1766 let Inst{24-23} = 0b10; // Decrement Before
1768 let Inst{21} = 1; // Writeback
1769 let Inst{20} = L_bit;
1770 let Inst{19-16} = Rn;
1771 let Inst{15-0} = regs;
1775 let hasSideEffects = 0 in {
1777 let mayLoad = 1, hasExtraDefRegAllocReq = 1, variadicOpsAreDefs = 1 in
1778 defm t2LDM : thumb2_ld_mult<"ldm", IIC_iLoad_m, IIC_iLoad_mu, 1>;
1780 multiclass thumb2_st_mult<string asm, InstrItinClass itin,
1781 InstrItinClass itin_upd, bit L_bit> {
1783 T2XI<(outs), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops),
1784 itin, !strconcat(asm, "${p}.w\t$Rn, $regs"), []> {
1788 let Inst{31-27} = 0b11101;
1789 let Inst{26-25} = 0b00;
1790 let Inst{24-23} = 0b01; // Increment After
1792 let Inst{21} = 0; // No writeback
1793 let Inst{20} = L_bit;
1794 let Inst{19-16} = Rn;
1796 let Inst{14} = regs{14};
1798 let Inst{12-0} = regs{12-0};
1801 T2XIt<(outs GPR:$wb), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops),
1802 itin_upd, !strconcat(asm, "${p}.w\t$Rn!, $regs"), "$Rn = $wb", []> {
1806 let Inst{31-27} = 0b11101;
1807 let Inst{26-25} = 0b00;
1808 let Inst{24-23} = 0b01; // Increment After
1810 let Inst{21} = 1; // Writeback
1811 let Inst{20} = L_bit;
1812 let Inst{19-16} = Rn;
1814 let Inst{14} = regs{14};
1816 let Inst{12-0} = regs{12-0};
1819 T2XI<(outs), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops),
1820 itin, !strconcat(asm, "db${p}\t$Rn, $regs"), []> {
1824 let Inst{31-27} = 0b11101;
1825 let Inst{26-25} = 0b00;
1826 let Inst{24-23} = 0b10; // Decrement Before
1828 let Inst{21} = 0; // No writeback
1829 let Inst{20} = L_bit;
1830 let Inst{19-16} = Rn;
1832 let Inst{14} = regs{14};
1834 let Inst{12-0} = regs{12-0};
1837 T2XIt<(outs GPR:$wb), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops),
1838 itin_upd, !strconcat(asm, "db${p}\t$Rn!, $regs"), "$Rn = $wb", []> {
1842 let Inst{31-27} = 0b11101;
1843 let Inst{26-25} = 0b00;
1844 let Inst{24-23} = 0b10; // Decrement Before
1846 let Inst{21} = 1; // Writeback
1847 let Inst{20} = L_bit;
1848 let Inst{19-16} = Rn;
1850 let Inst{14} = regs{14};
1852 let Inst{12-0} = regs{12-0};
1857 let mayStore = 1, hasExtraSrcRegAllocReq = 1 in
1858 defm t2STM : thumb2_st_mult<"stm", IIC_iStore_m, IIC_iStore_mu, 0>;
1863 //===----------------------------------------------------------------------===//
1864 // Move Instructions.
1867 let hasSideEffects = 0 in
1868 def t2MOVr : T2sTwoReg<(outs GPRnopc:$Rd), (ins GPRnopc:$Rm), IIC_iMOVr,
1869 "mov", ".w\t$Rd, $Rm", []>, Sched<[WriteALU]> {
1870 let Inst{31-27} = 0b11101;
1871 let Inst{26-25} = 0b01;
1872 let Inst{24-21} = 0b0010;
1873 let Inst{19-16} = 0b1111; // Rn
1874 let Inst{14-12} = 0b000;
1875 let Inst{7-4} = 0b0000;
1877 def : t2InstAlias<"mov${p}.w $Rd, $Rm", (t2MOVr GPRnopc:$Rd, GPRnopc:$Rm,
1878 pred:$p, zero_reg)>;
1879 def : t2InstAlias<"movs${p}.w $Rd, $Rm", (t2MOVr GPRnopc:$Rd, GPRnopc:$Rm,
1881 def : t2InstAlias<"movs${p} $Rd, $Rm", (t2MOVr GPRnopc:$Rd, GPRnopc:$Rm,
1884 // AddedComplexity to ensure isel tries t2MOVi before t2MOVi16.
1885 let isReMaterializable = 1, isAsCheapAsAMove = 1, isMoveImm = 1,
1886 AddedComplexity = 1 in
1887 def t2MOVi : T2sOneRegImm<(outs rGPR:$Rd), (ins t2_so_imm:$imm), IIC_iMOVi,
1888 "mov", ".w\t$Rd, $imm",
1889 [(set rGPR:$Rd, t2_so_imm:$imm)]>, Sched<[WriteALU]> {
1890 let Inst{31-27} = 0b11110;
1892 let Inst{24-21} = 0b0010;
1893 let Inst{19-16} = 0b1111; // Rn
1897 // cc_out is handled as part of the explicit mnemonic in the parser for 'mov'.
1898 // Use aliases to get that to play nice here.
1899 def : t2InstAlias<"movs${p}.w $Rd, $imm", (t2MOVi rGPR:$Rd, t2_so_imm:$imm,
1901 def : t2InstAlias<"movs${p} $Rd, $imm", (t2MOVi rGPR:$Rd, t2_so_imm:$imm,
1904 def : t2InstAlias<"mov${p}.w $Rd, $imm", (t2MOVi rGPR:$Rd, t2_so_imm:$imm,
1905 pred:$p, zero_reg)>;
1906 def : t2InstAlias<"mov${p} $Rd, $imm", (t2MOVi rGPR:$Rd, t2_so_imm:$imm,
1907 pred:$p, zero_reg)>;
1909 let isReMaterializable = 1, isAsCheapAsAMove = 1, isMoveImm = 1 in
1910 def t2MOVi16 : T2I<(outs rGPR:$Rd), (ins imm0_65535_expr:$imm), IIC_iMOVi,
1911 "movw", "\t$Rd, $imm",
1912 [(set rGPR:$Rd, imm0_65535:$imm)]>, Sched<[WriteALU]>,
1913 Requires<[IsThumb, HasV8MBaseline]> {
1914 let Inst{31-27} = 0b11110;
1916 let Inst{24-21} = 0b0010;
1917 let Inst{20} = 0; // The S bit.
1923 let Inst{11-8} = Rd;
1924 let Inst{19-16} = imm{15-12};
1925 let Inst{26} = imm{11};
1926 let Inst{14-12} = imm{10-8};
1927 let Inst{7-0} = imm{7-0};
1928 let DecoderMethod = "DecodeT2MOVTWInstruction";
1931 def : InstAlias<"mov${p} $Rd, $imm",
1932 (t2MOVi16 rGPR:$Rd, imm256_65535_expr:$imm, pred:$p), 0>,
1933 Requires<[IsThumb, HasV8MBaseline]>, Sched<[WriteALU]>;
1935 def t2MOVi16_ga_pcrel : PseudoInst<(outs rGPR:$Rd),
1936 (ins i32imm:$addr, pclabel:$id), IIC_iMOVi, []>,
1939 let Constraints = "$src = $Rd" in {
1940 def t2MOVTi16 : T2I<(outs rGPR:$Rd),
1941 (ins rGPR:$src, imm0_65535_expr:$imm), IIC_iMOVi,
1942 "movt", "\t$Rd, $imm",
1944 (or (and rGPR:$src, 0xffff), lo16AllZero:$imm))]>,
1946 Requires<[IsThumb, HasV8MBaseline]> {
1947 let Inst{31-27} = 0b11110;
1949 let Inst{24-21} = 0b0110;
1950 let Inst{20} = 0; // The S bit.
1956 let Inst{11-8} = Rd;
1957 let Inst{19-16} = imm{15-12};
1958 let Inst{26} = imm{11};
1959 let Inst{14-12} = imm{10-8};
1960 let Inst{7-0} = imm{7-0};
1961 let DecoderMethod = "DecodeT2MOVTWInstruction";
1964 def t2MOVTi16_ga_pcrel : PseudoInst<(outs rGPR:$Rd),
1965 (ins rGPR:$src, i32imm:$addr, pclabel:$id), IIC_iMOVi, []>,
1966 Sched<[WriteALU]>, Requires<[IsThumb, HasV8MBaseline]>;
1969 def : T2Pat<(or rGPR:$src, 0xffff0000), (t2MOVTi16 rGPR:$src, 0xffff)>;
1971 //===----------------------------------------------------------------------===//
1972 // Extend Instructions.
1977 def t2SXTB : T2I_ext_rrot<0b100, "sxtb">;
1978 def t2SXTH : T2I_ext_rrot<0b000, "sxth">;
1979 def t2SXTB16 : T2I_ext_rrot_xtb16<0b010, "sxtb16">;
1981 def t2SXTAB : T2I_exta_rrot<0b100, "sxtab">;
1982 def t2SXTAH : T2I_exta_rrot<0b000, "sxtah">;
1983 def t2SXTAB16 : T2I_exta_rrot<0b010, "sxtab16">;
1985 def : T2Pat<(sext_inreg (rotr rGPR:$Rn, rot_imm:$rot), i8),
1986 (t2SXTB rGPR:$Rn, rot_imm:$rot)>;
1987 def : T2Pat<(sext_inreg (rotr rGPR:$Rn, rot_imm:$rot), i16),
1988 (t2SXTH rGPR:$Rn, rot_imm:$rot)>;
1989 def : Thumb2DSPPat<(add rGPR:$Rn,
1990 (sext_inreg (rotr rGPR:$Rm, rot_imm:$rot), i8)),
1991 (t2SXTAB rGPR:$Rn, rGPR:$Rm, rot_imm:$rot)>;
1992 def : Thumb2DSPPat<(add rGPR:$Rn,
1993 (sext_inreg (rotr rGPR:$Rm, rot_imm:$rot), i16)),
1994 (t2SXTAH rGPR:$Rn, rGPR:$Rm, rot_imm:$rot)>;
1995 def : Thumb2DSPPat<(int_arm_sxtb16 rGPR:$Rn),
1996 (t2SXTB16 rGPR:$Rn, 0)>;
1997 def : Thumb2DSPPat<(int_arm_sxtab16 rGPR:$Rn, rGPR:$Rm),
1998 (t2SXTAB16 rGPR:$Rn, rGPR:$Rm, 0)>;
1999 def : Thumb2DSPPat<(int_arm_sxtb16 (rotr rGPR:$Rn, rot_imm:$rot)),
2000 (t2SXTB16 rGPR:$Rn, rot_imm:$rot)>;
2001 def : Thumb2DSPPat<(int_arm_sxtab16 rGPR:$Rn, (rotr rGPR:$Rm, rot_imm:$rot)),
2002 (t2SXTAB16 rGPR:$Rn, rGPR:$Rm, rot_imm:$rot)>;
2005 // A simple right-shift can also be used in most cases (the exception is the
2006 // SXTH operations with a rotate of 24: there the non-contiguous bits are
2008 def : Thumb2DSPPat<(add rGPR:$Rn, (sext_inreg
2009 (srl rGPR:$Rm, rot_imm:$rot), i8)),
2010 (t2SXTAB rGPR:$Rn, rGPR:$Rm, rot_imm:$rot)>;
2011 def : Thumb2DSPPat<(add rGPR:$Rn, (sext_inreg
2012 (srl rGPR:$Rm, imm8_or_16:$rot), i16)),
2013 (t2SXTAH rGPR:$Rn, rGPR:$Rm, rot_imm:$rot)>;
2014 def : Thumb2DSPPat<(add rGPR:$Rn, (sext_inreg
2015 (rotr rGPR:$Rm, (i32 24)), i16)),
2016 (t2SXTAH rGPR:$Rn, rGPR:$Rm, (i32 3))>;
2017 def : Thumb2DSPPat<(add rGPR:$Rn, (sext_inreg
2018 (or (srl rGPR:$Rm, (i32 24)),
2019 (shl rGPR:$Rm, (i32 8))), i16)),
2020 (t2SXTAH rGPR:$Rn, rGPR:$Rm, (i32 3))>;
2024 let AddedComplexity = 16 in {
2025 def t2UXTB : T2I_ext_rrot<0b101, "uxtb">;
2026 def t2UXTH : T2I_ext_rrot<0b001, "uxth">;
2027 def t2UXTB16 : T2I_ext_rrot_xtb16<0b011, "uxtb16">;
2029 def : Thumb2DSPPat<(and (rotr rGPR:$Rm, rot_imm:$rot), 0x000000FF),
2030 (t2UXTB rGPR:$Rm, rot_imm:$rot)>;
2031 def : Thumb2DSPPat<(and (rotr rGPR:$Rm, rot_imm:$rot), 0x0000FFFF),
2032 (t2UXTH rGPR:$Rm, rot_imm:$rot)>;
2033 def : Thumb2DSPPat<(and (rotr rGPR:$Rm, rot_imm:$rot), 0x00FF00FF),
2034 (t2UXTB16 rGPR:$Rm, rot_imm:$rot)>;
2036 def : Thumb2DSPPat<(int_arm_uxtb16 rGPR:$Rm),
2037 (t2UXTB16 rGPR:$Rm, 0)>;
2038 def : Thumb2DSPPat<(int_arm_uxtb16 (rotr rGPR:$Rn, rot_imm:$rot)),
2039 (t2UXTB16 rGPR:$Rn, rot_imm:$rot)>;
2041 // FIXME: This pattern incorrectly assumes the shl operator is a rotate.
2042 // The transformation should probably be done as a combiner action
2043 // instead so we can include a check for masking back in the upper
2044 // eight bits of the source into the lower eight bits of the result.
2045 //def : T2Pat<(and (shl rGPR:$Src, (i32 8)), 0xFF00FF),
2046 // (t2UXTB16 rGPR:$Src, 3)>,
2047 // Requires<[HasDSP, IsThumb2]>;
2048 def : T2Pat<(and (srl rGPR:$Src, (i32 8)), 0xFF00FF),
2049 (t2UXTB16 rGPR:$Src, 1)>,
2050 Requires<[HasDSP, IsThumb2]>;
2052 def t2UXTAB : T2I_exta_rrot<0b101, "uxtab">;
2053 def t2UXTAH : T2I_exta_rrot<0b001, "uxtah">;
2054 def t2UXTAB16 : T2I_exta_rrot<0b011, "uxtab16">;
2056 def : Thumb2DSPPat<(add rGPR:$Rn, (and (rotr rGPR:$Rm, rot_imm:$rot),
2058 (t2UXTAB rGPR:$Rn, rGPR:$Rm, rot_imm:$rot)>;
2059 def : Thumb2DSPPat<(add rGPR:$Rn, (and (rotr rGPR:$Rm, rot_imm:$rot),
2061 (t2UXTAH rGPR:$Rn, rGPR:$Rm, rot_imm:$rot)>;
2062 def : Thumb2DSPPat<(add rGPR:$Rn, (and (srl rGPR:$Rm, rot_imm:$rot),
2064 (t2UXTAB rGPR:$Rn, rGPR:$Rm, rot_imm:$rot)>;
2065 def : Thumb2DSPPat<(add rGPR:$Rn, (and (srl rGPR:$Rm, imm8_or_16:$rot),
2067 (t2UXTAH rGPR:$Rn, rGPR:$Rm, rot_imm:$rot)>;
2068 def : Thumb2DSPPat<(int_arm_uxtab16 rGPR:$Rn, rGPR:$Rm),
2069 (t2UXTAB16 rGPR:$Rn, rGPR:$Rm, 0)>;
2070 def : Thumb2DSPPat<(int_arm_uxtab16 rGPR:$Rn, (rotr rGPR:$Rm, rot_imm:$rot)),
2071 (t2UXTAB16 rGPR:$Rn, rGPR:$Rm, rot_imm:$rot)>;
2075 //===----------------------------------------------------------------------===//
2076 // Arithmetic Instructions.
2080 defm t2ADD : T2I_bin_ii12rs<0b000, "add", add, 1>;
2081 defm t2SUB : T2I_bin_ii12rs<0b101, "sub", sub>;
2083 // ADD and SUB with 's' bit set. No 12-bit immediate (T4) variants.
2085 // Currently, t2ADDS/t2SUBS are pseudo opcodes that exist only in the
2086 // selection DAG. They are "lowered" to real t2ADD/t2SUB opcodes by
2087 // AdjustInstrPostInstrSelection where we determine whether or not to
2088 // set the "s" bit based on CPSR liveness.
2090 // FIXME: Eliminate t2ADDS/t2SUBS pseudo opcodes after adding tablegen
2091 // support for an optional CPSR definition that corresponds to the DAG
2092 // node's second value. We can then eliminate the implicit def of CPSR.
2093 defm t2ADDS : T2I_bin_s_irs <IIC_iALUi, IIC_iALUr, IIC_iALUsi, ARMaddc, 1>;
2094 defm t2SUBS : T2I_bin_s_irs <IIC_iALUi, IIC_iALUr, IIC_iALUsi, ARMsubc>;
2096 def : T2Pat<(ARMsubs GPRnopc:$Rn, t2_so_imm:$imm),
2097 (t2SUBSri $Rn, t2_so_imm:$imm)>;
2098 def : T2Pat<(ARMsubs GPRnopc:$Rn, rGPR:$Rm), (t2SUBSrr $Rn, $Rm)>;
2099 def : T2Pat<(ARMsubs GPRnopc:$Rn, t2_so_reg:$ShiftedRm),
2100 (t2SUBSrs $Rn, t2_so_reg:$ShiftedRm)>;
2102 let hasPostISelHook = 1 in {
2103 defm t2ADC : T2I_adde_sube_irs<0b1010, "adc", ARMadde, 1>;
2104 defm t2SBC : T2I_adde_sube_irs<0b1011, "sbc", ARMsube>;
2107 def : t2InstSubst<"adc${s}${p} $rd, $rn, $imm",
2108 (t2SBCri rGPR:$rd, rGPR:$rn, t2_so_imm_not:$imm, pred:$p, s_cc_out:$s)>;
2109 def : t2InstSubst<"sbc${s}${p} $rd, $rn, $imm",
2110 (t2ADCri rGPR:$rd, rGPR:$rn, t2_so_imm_not:$imm, pred:$p, s_cc_out:$s)>;
2112 def : t2InstSubst<"add${s}${p}.w $rd, $rn, $imm",
2113 (t2SUBri GPRnopc:$rd, GPRnopc:$rn, t2_so_imm_neg:$imm, pred:$p, s_cc_out:$s)>;
2114 def : t2InstSubst<"addw${p} $rd, $rn, $imm",
2115 (t2SUBri12 GPRnopc:$rd, GPR:$rn, t2_so_imm_neg:$imm, pred:$p)>;
2116 def : t2InstSubst<"sub${s}${p}.w $rd, $rn, $imm",
2117 (t2ADDri GPRnopc:$rd, GPRnopc:$rn, t2_so_imm_neg:$imm, pred:$p, s_cc_out:$s)>;
2118 def : t2InstSubst<"subw${p} $rd, $rn, $imm",
2119 (t2ADDri12 GPRnopc:$rd, GPR:$rn, t2_so_imm_neg:$imm, pred:$p)>;
2120 def : t2InstSubst<"subw${p} $Rd, $Rn, $imm",
2121 (t2ADDri12 GPRnopc:$Rd, GPR:$Rn, imm0_4095_neg:$imm, pred:$p)>;
2122 def : t2InstSubst<"sub${s}${p} $rd, $rn, $imm",
2123 (t2ADDri GPRnopc:$rd, GPRnopc:$rn, t2_so_imm_neg:$imm, pred:$p, s_cc_out:$s)>;
2124 def : t2InstSubst<"sub${p} $rd, $rn, $imm",
2125 (t2ADDri12 GPRnopc:$rd, GPR:$rn, t2_so_imm_neg:$imm, pred:$p)>;
2127 defm t2RSB : T2I_rbin_irs <0b1110, "rsb", sub>;
2129 // FIXME: Eliminate them if we can write def : Pat patterns which defines
2130 // CPSR and the implicit def of CPSR is not needed.
2131 defm t2RSBS : T2I_rbin_s_is <ARMsubc>;
2133 // (sub X, imm) gets canonicalized to (add X, -imm). Match this form.
2134 // The assume-no-carry-in form uses the negation of the input since add/sub
2135 // assume opposite meanings of the carry flag (i.e., carry == !borrow).
2136 // See the definition of AddWithCarry() in the ARM ARM A2.2.1 for the gory
2138 // The AddedComplexity preferences the first variant over the others since
2139 // it can be shrunk to a 16-bit wide encoding, while the others cannot.
2140 let AddedComplexity = 1 in
2141 def : T2Pat<(add GPR:$src, imm1_255_neg:$imm),
2142 (t2SUBri GPR:$src, imm1_255_neg:$imm)>;
2143 def : T2Pat<(add GPR:$src, t2_so_imm_neg:$imm),
2144 (t2SUBri GPR:$src, t2_so_imm_neg:$imm)>;
2145 def : T2Pat<(add GPR:$src, imm0_4095_neg:$imm),
2146 (t2SUBri12 GPR:$src, imm0_4095_neg:$imm)>;
2147 def : T2Pat<(add GPR:$src, imm0_65535_neg:$imm),
2148 (t2SUBrr GPR:$src, (t2MOVi16 (imm_neg_XFORM imm:$imm)))>;
2150 // Do the same for v8m targets since they support movw with a 16-bit value.
2151 def : T1Pat<(add tGPR:$src, imm0_65535_neg:$imm),
2152 (tSUBrr tGPR:$src, (t2MOVi16 (imm_neg_XFORM imm:$imm)))>,
2153 Requires<[HasV8MBaseline]>;
2155 let AddedComplexity = 1 in
2156 def : T2Pat<(ARMaddc rGPR:$src, imm1_255_neg:$imm),
2157 (t2SUBSri rGPR:$src, imm1_255_neg:$imm)>;
2158 def : T2Pat<(ARMaddc rGPR:$src, t2_so_imm_neg:$imm),
2159 (t2SUBSri rGPR:$src, t2_so_imm_neg:$imm)>;
2160 def : T2Pat<(ARMaddc rGPR:$src, imm0_65535_neg:$imm),
2161 (t2SUBSrr rGPR:$src, (t2MOVi16 (imm_neg_XFORM imm:$imm)))>;
2162 // The with-carry-in form matches bitwise not instead of the negation.
2163 // Effectively, the inverse interpretation of the carry flag already accounts
2164 // for part of the negation.
2165 let AddedComplexity = 1 in
2166 def : T2Pat<(ARMadde rGPR:$src, imm0_255_not:$imm, CPSR),
2167 (t2SBCri rGPR:$src, imm0_255_not:$imm)>;
2168 def : T2Pat<(ARMadde rGPR:$src, t2_so_imm_not:$imm, CPSR),
2169 (t2SBCri rGPR:$src, t2_so_imm_not:$imm)>;
2170 def : T2Pat<(ARMadde rGPR:$src, imm0_65535_neg:$imm, CPSR),
2171 (t2SBCrr rGPR:$src, (t2MOVi16 (imm_not_XFORM imm:$imm)))>;
2173 def t2SEL : T2ThreeReg<(outs GPR:$Rd), (ins GPR:$Rn, GPR:$Rm),
2174 NoItinerary, "sel", "\t$Rd, $Rn, $Rm",
2175 [(set GPR:$Rd, (int_arm_sel GPR:$Rn, GPR:$Rm))]>,
2176 Requires<[IsThumb2, HasDSP]> {
2177 let Inst{31-27} = 0b11111;
2178 let Inst{26-24} = 0b010;
2180 let Inst{22-20} = 0b010;
2181 let Inst{15-12} = 0b1111;
2183 let Inst{6-4} = 0b000;
2186 // A6.3.13, A6.3.14, A6.3.15 Parallel addition and subtraction (signed/unsigned)
2187 // And Miscellaneous operations -- for disassembly only
2188 class T2I_pam<bits<3> op22_20, bits<4> op7_4, string opc,
2189 list<dag> pat, dag iops, string asm>
2190 : T2I<(outs rGPR:$Rd), iops, NoItinerary, opc, asm, pat>,
2191 Requires<[IsThumb2, HasDSP]> {
2192 let Inst{31-27} = 0b11111;
2193 let Inst{26-23} = 0b0101;
2194 let Inst{22-20} = op22_20;
2195 let Inst{15-12} = 0b1111;
2196 let Inst{7-4} = op7_4;
2202 let Inst{11-8} = Rd;
2203 let Inst{19-16} = Rn;
2207 class T2I_pam_intrinsics<bits<3> op22_20, bits<4> op7_4, string opc,
2208 Intrinsic intrinsic>
2209 : T2I_pam<op22_20, op7_4, opc,
2210 [(set rGPR:$Rd, (intrinsic rGPR:$Rn, rGPR:$Rm))],
2211 (ins rGPR:$Rn, rGPR:$Rm), "\t$Rd, $Rn, $Rm">;
2213 class T2I_pam_intrinsics_rev<bits<3> op22_20, bits<4> op7_4, string opc>
2214 : T2I_pam<op22_20, op7_4, opc, [],
2215 (ins rGPR:$Rm, rGPR:$Rn), "\t$Rd, $Rm, $Rn">;
2217 // Saturating add/subtract
2218 def t2QADD16 : T2I_pam_intrinsics<0b001, 0b0001, "qadd16", int_arm_qadd16>;
2219 def t2QADD8 : T2I_pam_intrinsics<0b000, 0b0001, "qadd8", int_arm_qadd8>;
2220 def t2QASX : T2I_pam_intrinsics<0b010, 0b0001, "qasx", int_arm_qasx>;
2221 def t2UQSUB8 : T2I_pam_intrinsics<0b100, 0b0101, "uqsub8", int_arm_uqsub8>;
2222 def t2QSAX : T2I_pam_intrinsics<0b110, 0b0001, "qsax", int_arm_qsax>;
2223 def t2QSUB16 : T2I_pam_intrinsics<0b101, 0b0001, "qsub16", int_arm_qsub16>;
2224 def t2QSUB8 : T2I_pam_intrinsics<0b100, 0b0001, "qsub8", int_arm_qsub8>;
2225 def t2UQADD16 : T2I_pam_intrinsics<0b001, 0b0101, "uqadd16", int_arm_uqadd16>;
2226 def t2UQADD8 : T2I_pam_intrinsics<0b000, 0b0101, "uqadd8", int_arm_uqadd8>;
2227 def t2UQASX : T2I_pam_intrinsics<0b010, 0b0101, "uqasx", int_arm_uqasx>;
2228 def t2UQSAX : T2I_pam_intrinsics<0b110, 0b0101, "uqsax", int_arm_uqsax>;
2229 def t2UQSUB16 : T2I_pam_intrinsics<0b101, 0b0101, "uqsub16", int_arm_uqsub16>;
2230 def t2QADD : T2I_pam_intrinsics_rev<0b000, 0b1000, "qadd">;
2231 def t2QSUB : T2I_pam_intrinsics_rev<0b000, 0b1010, "qsub">;
2232 def t2QDADD : T2I_pam_intrinsics_rev<0b000, 0b1001, "qdadd">;
2233 def t2QDSUB : T2I_pam_intrinsics_rev<0b000, 0b1011, "qdsub">;
2235 def : Thumb2DSPPat<(int_arm_qadd rGPR:$Rm, rGPR:$Rn),
2236 (t2QADD rGPR:$Rm, rGPR:$Rn)>;
2237 def : Thumb2DSPPat<(int_arm_qsub rGPR:$Rm, rGPR:$Rn),
2238 (t2QSUB rGPR:$Rm, rGPR:$Rn)>;
2239 def : Thumb2DSPPat<(int_arm_qadd(int_arm_qadd rGPR:$Rm, rGPR:$Rm), rGPR:$Rn),
2240 (t2QDADD rGPR:$Rm, rGPR:$Rn)>;
2241 def : Thumb2DSPPat<(int_arm_qsub rGPR:$Rm, (int_arm_qadd rGPR:$Rn, rGPR:$Rn)),
2242 (t2QDSUB rGPR:$Rm, rGPR:$Rn)>;
2244 // Signed/Unsigned add/subtract
2246 def t2SASX : T2I_pam_intrinsics<0b010, 0b0000, "sasx", int_arm_sasx>;
2247 def t2SADD16 : T2I_pam_intrinsics<0b001, 0b0000, "sadd16", int_arm_sadd16>;
2248 def t2SADD8 : T2I_pam_intrinsics<0b000, 0b0000, "sadd8", int_arm_sadd8>;
2249 def t2SSAX : T2I_pam_intrinsics<0b110, 0b0000, "ssax", int_arm_ssax>;
2250 def t2SSUB16 : T2I_pam_intrinsics<0b101, 0b0000, "ssub16", int_arm_ssub16>;
2251 def t2SSUB8 : T2I_pam_intrinsics<0b100, 0b0000, "ssub8", int_arm_ssub8>;
2252 def t2UASX : T2I_pam_intrinsics<0b010, 0b0100, "uasx", int_arm_uasx>;
2253 def t2UADD16 : T2I_pam_intrinsics<0b001, 0b0100, "uadd16", int_arm_uadd16>;
2254 def t2UADD8 : T2I_pam_intrinsics<0b000, 0b0100, "uadd8", int_arm_uadd8>;
2255 def t2USAX : T2I_pam_intrinsics<0b110, 0b0100, "usax", int_arm_usax>;
2256 def t2USUB16 : T2I_pam_intrinsics<0b101, 0b0100, "usub16", int_arm_usub16>;
2257 def t2USUB8 : T2I_pam_intrinsics<0b100, 0b0100, "usub8", int_arm_usub8>;
2259 // Signed/Unsigned halving add/subtract
2261 def t2SHASX : T2I_pam_intrinsics<0b010, 0b0010, "shasx", int_arm_shasx>;
2262 def t2SHADD16 : T2I_pam_intrinsics<0b001, 0b0010, "shadd16", int_arm_shadd16>;
2263 def t2SHADD8 : T2I_pam_intrinsics<0b000, 0b0010, "shadd8", int_arm_shadd8>;
2264 def t2SHSAX : T2I_pam_intrinsics<0b110, 0b0010, "shsax", int_arm_shsax>;
2265 def t2SHSUB16 : T2I_pam_intrinsics<0b101, 0b0010, "shsub16", int_arm_shsub16>;
2266 def t2SHSUB8 : T2I_pam_intrinsics<0b100, 0b0010, "shsub8", int_arm_shsub8>;
2267 def t2UHASX : T2I_pam_intrinsics<0b010, 0b0110, "uhasx", int_arm_uhasx>;
2268 def t2UHADD16 : T2I_pam_intrinsics<0b001, 0b0110, "uhadd16", int_arm_uhadd16>;
2269 def t2UHADD8 : T2I_pam_intrinsics<0b000, 0b0110, "uhadd8", int_arm_uhadd8>;
2270 def t2UHSAX : T2I_pam_intrinsics<0b110, 0b0110, "uhsax", int_arm_uhsax>;
2271 def t2UHSUB16 : T2I_pam_intrinsics<0b101, 0b0110, "uhsub16", int_arm_uhsub16>;
2272 def t2UHSUB8 : T2I_pam_intrinsics<0b100, 0b0110, "uhsub8", int_arm_uhsub8>;
2274 // Helper class for disassembly only
2275 // A6.3.16 & A6.3.17
2276 // T2Imac - Thumb2 multiply [accumulate, and absolute difference] instructions.
2277 class T2ThreeReg_mac<bit long, bits<3> op22_20, bits<4> op7_4, dag oops,
2278 dag iops, InstrItinClass itin, string opc, string asm, list<dag> pattern>
2279 : T2ThreeReg<oops, iops, itin, opc, asm, pattern> {
2280 let Inst{31-27} = 0b11111;
2281 let Inst{26-24} = 0b011;
2282 let Inst{23} = long;
2283 let Inst{22-20} = op22_20;
2284 let Inst{7-4} = op7_4;
2287 class T2FourReg_mac<bit long, bits<3> op22_20, bits<4> op7_4, dag oops,
2288 dag iops, InstrItinClass itin, string opc, string asm, list<dag> pattern>
2289 : T2FourReg<oops, iops, itin, opc, asm, pattern> {
2290 let Inst{31-27} = 0b11111;
2291 let Inst{26-24} = 0b011;
2292 let Inst{23} = long;
2293 let Inst{22-20} = op22_20;
2294 let Inst{7-4} = op7_4;
2297 // Unsigned Sum of Absolute Differences [and Accumulate].
2298 def t2USAD8 : T2ThreeReg_mac<0, 0b111, 0b0000, (outs rGPR:$Rd),
2299 (ins rGPR:$Rn, rGPR:$Rm),
2300 NoItinerary, "usad8", "\t$Rd, $Rn, $Rm",
2301 [(set rGPR:$Rd, (int_arm_usad8 rGPR:$Rn, rGPR:$Rm))]>,
2302 Requires<[IsThumb2, HasDSP]> {
2303 let Inst{15-12} = 0b1111;
2305 def t2USADA8 : T2FourReg_mac<0, 0b111, 0b0000, (outs rGPR:$Rd),
2306 (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), NoItinerary,
2307 "usada8", "\t$Rd, $Rn, $Rm, $Ra",
2308 [(set rGPR:$Rd, (int_arm_usada8 rGPR:$Rn, rGPR:$Rm, rGPR:$Ra))]>,
2309 Requires<[IsThumb2, HasDSP]>;
2311 // Signed/Unsigned saturate.
2312 let hasSideEffects = 1 in
2313 class T2SatI<dag iops, string opc, string asm>
2314 : T2I<(outs rGPR:$Rd), iops, NoItinerary, opc, asm, []> {
2320 let Inst{31-24} = 0b11110011;
2321 let Inst{21} = sh{5};
2323 let Inst{19-16} = Rn;
2325 let Inst{14-12} = sh{4-2};
2326 let Inst{11-8} = Rd;
2327 let Inst{7-6} = sh{1-0};
2329 let Inst{4-0} = sat_imm;
2332 def t2SSAT: T2SatI<(ins imm1_32:$sat_imm, rGPR:$Rn, t2_shift_imm:$sh),
2333 "ssat", "\t$Rd, $sat_imm, $Rn$sh">,
2334 Requires<[IsThumb2]> {
2335 let Inst{23-22} = 0b00;
2339 def t2SSAT16: T2SatI<(ins imm1_16:$sat_imm, rGPR:$Rn),
2340 "ssat16", "\t$Rd, $sat_imm, $Rn">,
2341 Requires<[IsThumb2, HasDSP]> {
2342 let Inst{23-22} = 0b00;
2347 def t2USAT: T2SatI<(ins imm0_31:$sat_imm, rGPR:$Rn, t2_shift_imm:$sh),
2348 "usat", "\t$Rd, $sat_imm, $Rn$sh">,
2349 Requires<[IsThumb2]> {
2350 let Inst{23-22} = 0b10;
2353 def t2USAT16: T2SatI<(ins imm0_15:$sat_imm, rGPR:$Rn),
2354 "usat16", "\t$Rd, $sat_imm, $Rn">,
2355 Requires<[IsThumb2, HasDSP]> {
2356 let Inst{23-22} = 0b10;
2361 def : T2Pat<(ARMssatnoshift GPRnopc:$Rn, imm0_31:$imm),
2362 (t2SSAT imm0_31:$imm, GPRnopc:$Rn, 0)>;
2363 def : T2Pat<(ARMusatnoshift GPRnopc:$Rn, imm0_31:$imm),
2364 (t2USAT imm0_31:$imm, GPRnopc:$Rn, 0)>;
2365 def : T2Pat<(int_arm_ssat GPR:$a, imm1_32:$pos),
2366 (t2SSAT imm1_32:$pos, GPR:$a, 0)>;
2367 def : T2Pat<(int_arm_usat GPR:$a, imm0_31:$pos),
2368 (t2USAT imm0_31:$pos, GPR:$a, 0)>;
2369 def : T2Pat<(int_arm_ssat16 GPR:$a, imm1_16:$pos),
2370 (t2SSAT16 imm1_16:$pos, GPR:$a)>;
2371 def : T2Pat<(int_arm_usat16 GPR:$a, imm0_15:$pos),
2372 (t2USAT16 imm0_15:$pos, GPR:$a)>;
2374 //===----------------------------------------------------------------------===//
2375 // Shift and rotate Instructions.
2378 defm t2LSL : T2I_sh_ir<0b00, "lsl", imm1_31, shl>;
2379 defm t2LSR : T2I_sh_ir<0b01, "lsr", imm_sr, srl>;
2380 defm t2ASR : T2I_sh_ir<0b10, "asr", imm_sr, sra>;
2381 defm t2ROR : T2I_sh_ir<0b11, "ror", imm0_31, rotr>;
2383 // LSL #0 is actually MOV, and has slightly different permitted registers to
2384 // LSL with non-zero shift
2385 def : t2InstAlias<"lsl${s}${p} $Rd, $Rm, #0",
2386 (t2MOVr GPRnopc:$Rd, GPRnopc:$Rm, pred:$p, cc_out:$s)>;
2387 def : t2InstAlias<"lsl${s}${p}.w $Rd, $Rm, #0",
2388 (t2MOVr GPRnopc:$Rd, GPRnopc:$Rm, pred:$p, cc_out:$s)>;
2390 // (rotr x, (and y, 0x...1f)) ==> (ROR x, y)
2391 def : T2Pat<(rotr rGPR:$lhs, (and rGPR:$rhs, lo5AllOne)),
2392 (t2RORrr rGPR:$lhs, rGPR:$rhs)>;
2394 let Uses = [CPSR] in {
2395 def t2RRX : T2sTwoReg<(outs rGPR:$Rd), (ins rGPR:$Rm), IIC_iMOVsi,
2396 "rrx", "\t$Rd, $Rm",
2397 [(set rGPR:$Rd, (ARMrrx rGPR:$Rm))]>, Sched<[WriteALU]> {
2398 let Inst{31-27} = 0b11101;
2399 let Inst{26-25} = 0b01;
2400 let Inst{24-21} = 0b0010;
2401 let Inst{19-16} = 0b1111; // Rn
2402 let Inst{14-12} = 0b000;
2403 let Inst{7-4} = 0b0011;
2407 let isCodeGenOnly = 1, Defs = [CPSR] in {
2408 def t2MOVsrl_flag : T2TwoRegShiftImm<
2409 (outs rGPR:$Rd), (ins rGPR:$Rm), IIC_iMOVsi,
2410 "lsrs", ".w\t$Rd, $Rm, #1",
2411 [(set rGPR:$Rd, (ARMsrl_flag rGPR:$Rm))]>,
2413 let Inst{31-27} = 0b11101;
2414 let Inst{26-25} = 0b01;
2415 let Inst{24-21} = 0b0010;
2416 let Inst{20} = 1; // The S bit.
2417 let Inst{19-16} = 0b1111; // Rn
2418 let Inst{5-4} = 0b01; // Shift type.
2419 // Shift amount = Inst{14-12:7-6} = 1.
2420 let Inst{14-12} = 0b000;
2421 let Inst{7-6} = 0b01;
2423 def t2MOVsra_flag : T2TwoRegShiftImm<
2424 (outs rGPR:$Rd), (ins rGPR:$Rm), IIC_iMOVsi,
2425 "asrs", ".w\t$Rd, $Rm, #1",
2426 [(set rGPR:$Rd, (ARMsra_flag rGPR:$Rm))]>,
2428 let Inst{31-27} = 0b11101;
2429 let Inst{26-25} = 0b01;
2430 let Inst{24-21} = 0b0010;
2431 let Inst{20} = 1; // The S bit.
2432 let Inst{19-16} = 0b1111; // Rn
2433 let Inst{5-4} = 0b10; // Shift type.
2434 // Shift amount = Inst{14-12:7-6} = 1.
2435 let Inst{14-12} = 0b000;
2436 let Inst{7-6} = 0b01;
2440 //===----------------------------------------------------------------------===//
2441 // Bitwise Instructions.
2444 defm t2AND : T2I_bin_w_irs<0b0000, "and",
2445 IIC_iBITi, IIC_iBITr, IIC_iBITsi, and, 1>;
2446 defm t2ORR : T2I_bin_w_irs<0b0010, "orr",
2447 IIC_iBITi, IIC_iBITr, IIC_iBITsi, or, 1>;
2448 defm t2EOR : T2I_bin_w_irs<0b0100, "eor",
2449 IIC_iBITi, IIC_iBITr, IIC_iBITsi, xor, 1>;
2451 defm t2BIC : T2I_bin_w_irs<0b0001, "bic",
2452 IIC_iBITi, IIC_iBITr, IIC_iBITsi,
2453 BinOpFrag<(and node:$LHS, (not node:$RHS))>>;
2455 class T2BitFI<dag oops, dag iops, InstrItinClass itin,
2456 string opc, string asm, list<dag> pattern>
2457 : T2I<oops, iops, itin, opc, asm, pattern> {
2462 let Inst{11-8} = Rd;
2463 let Inst{4-0} = msb{4-0};
2464 let Inst{14-12} = lsb{4-2};
2465 let Inst{7-6} = lsb{1-0};
2468 class T2TwoRegBitFI<dag oops, dag iops, InstrItinClass itin,
2469 string opc, string asm, list<dag> pattern>
2470 : T2BitFI<oops, iops, itin, opc, asm, pattern> {
2473 let Inst{19-16} = Rn;
2476 let Constraints = "$src = $Rd" in
2477 def t2BFC : T2BitFI<(outs rGPR:$Rd), (ins rGPR:$src, bf_inv_mask_imm:$imm),
2478 IIC_iUNAsi, "bfc", "\t$Rd, $imm",
2479 [(set rGPR:$Rd, (and rGPR:$src, bf_inv_mask_imm:$imm))]> {
2480 let Inst{31-27} = 0b11110;
2481 let Inst{26} = 0; // should be 0.
2483 let Inst{24-20} = 0b10110;
2484 let Inst{19-16} = 0b1111; // Rn
2486 let Inst{5} = 0; // should be 0.
2489 let msb{4-0} = imm{9-5};
2490 let lsb{4-0} = imm{4-0};
2493 def t2SBFX: T2TwoRegBitFI<
2494 (outs rGPR:$Rd), (ins rGPR:$Rn, imm0_31:$lsb, imm1_32:$msb),
2495 IIC_iUNAsi, "sbfx", "\t$Rd, $Rn, $lsb, $msb", []> {
2496 let Inst{31-27} = 0b11110;
2498 let Inst{24-20} = 0b10100;
2502 def t2UBFX: T2TwoRegBitFI<
2503 (outs rGPR:$Rd), (ins rGPR:$Rn, imm0_31:$lsb, imm1_32:$msb),
2504 IIC_iUNAsi, "ubfx", "\t$Rd, $Rn, $lsb, $msb", []> {
2505 let Inst{31-27} = 0b11110;
2507 let Inst{24-20} = 0b11100;
2511 // A8.8.247 UDF - Undefined (Encoding T2)
2512 def t2UDF : T2XI<(outs), (ins imm0_65535:$imm16), IIC_Br, "udf.w\t$imm16",
2513 [(int_arm_undefined imm0_65535:$imm16)]> {
2515 let Inst{31-29} = 0b111;
2516 let Inst{28-27} = 0b10;
2517 let Inst{26-20} = 0b1111111;
2518 let Inst{19-16} = imm16{15-12};
2520 let Inst{14-12} = 0b010;
2521 let Inst{11-0} = imm16{11-0};
2524 // A8.6.18 BFI - Bitfield insert (Encoding T1)
2525 let Constraints = "$src = $Rd" in {
2526 def t2BFI : T2TwoRegBitFI<(outs rGPR:$Rd),
2527 (ins rGPR:$src, rGPR:$Rn, bf_inv_mask_imm:$imm),
2528 IIC_iBITi, "bfi", "\t$Rd, $Rn, $imm",
2529 [(set rGPR:$Rd, (ARMbfi rGPR:$src, rGPR:$Rn,
2530 bf_inv_mask_imm:$imm))]> {
2531 let Inst{31-27} = 0b11110;
2532 let Inst{26} = 0; // should be 0.
2534 let Inst{24-20} = 0b10110;
2536 let Inst{5} = 0; // should be 0.
2539 let msb{4-0} = imm{9-5};
2540 let lsb{4-0} = imm{4-0};
2544 defm t2ORN : T2I_bin_irs<0b0011, "orn",
2545 IIC_iBITi, IIC_iBITr, IIC_iBITsi,
2546 BinOpFrag<(or node:$LHS, (not node:$RHS))>, 0, "">;
2548 /// T2I_un_irs - Defines a set of (op reg, {so_imm|r|so_reg}) patterns for a
2549 /// unary operation that produces a value. These are predicable and can be
2550 /// changed to modify CPSR.
2551 multiclass T2I_un_irs<bits<4> opcod, string opc,
2552 InstrItinClass iii, InstrItinClass iir, InstrItinClass iis,
2554 bit Cheap = 0, bit ReMat = 0, bit MoveImm = 0> {
2556 def i : T2sOneRegImm<(outs rGPR:$Rd), (ins t2_so_imm:$imm), iii,
2558 [(set rGPR:$Rd, (opnode t2_so_imm:$imm))]>, Sched<[WriteALU]> {
2559 let isAsCheapAsAMove = Cheap;
2560 let isReMaterializable = ReMat;
2561 let isMoveImm = MoveImm;
2562 let Inst{31-27} = 0b11110;
2564 let Inst{24-21} = opcod;
2565 let Inst{19-16} = 0b1111; // Rn
2569 def r : T2sTwoReg<(outs rGPR:$Rd), (ins rGPR:$Rm), iir,
2570 opc, ".w\t$Rd, $Rm",
2571 [(set rGPR:$Rd, (opnode rGPR:$Rm))]>, Sched<[WriteALU]> {
2572 let Inst{31-27} = 0b11101;
2573 let Inst{26-25} = 0b01;
2574 let Inst{24-21} = opcod;
2575 let Inst{19-16} = 0b1111; // Rn
2576 let Inst{14-12} = 0b000; // imm3
2577 let Inst{7-6} = 0b00; // imm2
2578 let Inst{5-4} = 0b00; // type
2581 def s : T2sOneRegShiftedReg<(outs rGPR:$Rd), (ins t2_so_reg:$ShiftedRm), iis,
2582 opc, ".w\t$Rd, $ShiftedRm",
2583 [(set rGPR:$Rd, (opnode t2_so_reg:$ShiftedRm))]>,
2585 let Inst{31-27} = 0b11101;
2586 let Inst{26-25} = 0b01;
2587 let Inst{24-21} = opcod;
2588 let Inst{19-16} = 0b1111; // Rn
2592 // Prefer over of t2EORri ra, rb, -1 because mvn has 16-bit version
2593 let AddedComplexity = 1 in
2594 defm t2MVN : T2I_un_irs <0b0011, "mvn",
2595 IIC_iMVNi, IIC_iMVNr, IIC_iMVNsi,
2598 let AddedComplexity = 1 in
2599 def : T2Pat<(and rGPR:$src, t2_so_imm_not:$imm),
2600 (t2BICri rGPR:$src, t2_so_imm_not:$imm)>;
2602 // top16Zero - answer true if the upper 16 bits of $src are 0, false otherwise
2603 def top16Zero: PatLeaf<(i32 rGPR:$src), [{
2604 return CurDAG->MaskedValueIsZero(SDValue(N,0), APInt::getHighBitsSet(32, 16));
2607 // so_imm_notSext is needed instead of so_imm_not, as the value of imm
2608 // will match the extended, not the original bitWidth for $src.
2609 def : T2Pat<(and top16Zero:$src, t2_so_imm_notSext:$imm),
2610 (t2BICri rGPR:$src, t2_so_imm_notSext:$imm)>;
2613 // FIXME: Disable this pattern on Darwin to workaround an assembler bug.
2614 def : T2Pat<(or rGPR:$src, t2_so_imm_not:$imm),
2615 (t2ORNri rGPR:$src, t2_so_imm_not:$imm)>,
2616 Requires<[IsThumb2]>;
2618 def : T2Pat<(t2_so_imm_not:$src),
2619 (t2MVNi t2_so_imm_not:$src)>;
2621 // There are shorter Thumb encodings for ADD than ORR, so to increase
2622 // Thumb2SizeReduction's chances later on we select a t2ADD for an or where
2624 def : T2Pat<(or AddLikeOrOp:$Rn, t2_so_imm:$imm),
2625 (t2ADDri $Rn, t2_so_imm:$imm)>;
2627 def : T2Pat<(or AddLikeOrOp:$Rn, imm0_4095:$Rm),
2628 (t2ADDri12 $Rn, imm0_4095:$Rm)>;
2630 def : T2Pat<(or AddLikeOrOp:$Rn, non_imm32:$Rm),
2631 (t2ADDrr $Rn, $Rm)>;
2633 //===----------------------------------------------------------------------===//
2634 // Multiply Instructions.
2636 let isCommutable = 1 in
2637 def t2MUL: T2ThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iMUL32,
2638 "mul", "\t$Rd, $Rn, $Rm",
2639 [(set rGPR:$Rd, (mul rGPR:$Rn, rGPR:$Rm))]>,
2640 Sched<[WriteMUL32, ReadMUL, ReadMUL]> {
2641 let Inst{31-27} = 0b11111;
2642 let Inst{26-23} = 0b0110;
2643 let Inst{22-20} = 0b000;
2644 let Inst{15-12} = 0b1111; // Ra = 0b1111 (no accumulate)
2645 let Inst{7-4} = 0b0000; // Multiply
2648 class T2FourRegMLA<bits<4> op7_4, string opc, list<dag> pattern>
2649 : T2FourReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC32,
2650 opc, "\t$Rd, $Rn, $Rm, $Ra", pattern>,
2651 Requires<[IsThumb2, UseMulOps]>,
2652 Sched<[WriteMAC32, ReadMUL, ReadMUL, ReadMAC]> {
2653 let Inst{31-27} = 0b11111;
2654 let Inst{26-23} = 0b0110;
2655 let Inst{22-20} = 0b000;
2656 let Inst{7-4} = op7_4;
2659 def t2MLA : T2FourRegMLA<0b0000, "mla",
2660 [(set rGPR:$Rd, (add (mul rGPR:$Rn, rGPR:$Rm),
2662 def t2MLS: T2FourRegMLA<0b0001, "mls",
2663 [(set rGPR:$Rd, (sub rGPR:$Ra, (mul rGPR:$Rn,
2666 // Extra precision multiplies with low / high results
2667 let hasSideEffects = 0 in {
2668 let isCommutable = 1 in {
2669 def t2SMULL : T2MulLong<0b000, 0b0000, "smull",
2670 [(set rGPR:$RdLo, rGPR:$RdHi,
2671 (smullohi rGPR:$Rn, rGPR:$Rm))]>;
2672 def t2UMULL : T2MulLong<0b010, 0b0000, "umull",
2673 [(set rGPR:$RdLo, rGPR:$RdHi,
2674 (umullohi rGPR:$Rn, rGPR:$Rm))]>;
2677 // Multiply + accumulate
2678 def t2SMLAL : T2MlaLong<0b100, 0b0000, "smlal">;
2679 def t2UMLAL : T2MlaLong<0b110, 0b0000, "umlal">;
2680 def t2UMAAL : T2MlaLong<0b110, 0b0110, "umaal">, Requires<[IsThumb2, HasDSP]>;
2683 // Rounding variants of the below included for disassembly only
2685 // Most significant word multiply
2686 class T2SMMUL<bits<4> op7_4, string opc, list<dag> pattern>
2687 : T2ThreeReg<(outs rGPR:$Rd),
2688 (ins rGPR:$Rn, rGPR:$Rm), IIC_iMUL32,
2689 opc, "\t$Rd, $Rn, $Rm", pattern>,
2690 Requires<[IsThumb2, HasDSP]>,
2691 Sched<[WriteMUL32, ReadMUL, ReadMUL]> {
2692 let Inst{31-27} = 0b11111;
2693 let Inst{26-23} = 0b0110;
2694 let Inst{22-20} = 0b101;
2695 let Inst{15-12} = 0b1111; // Ra = 0b1111 (no accumulate)
2696 let Inst{7-4} = op7_4;
2698 def t2SMMUL : T2SMMUL<0b0000, "smmul", [(set rGPR:$Rd, (mulhs rGPR:$Rn,
2701 T2SMMUL<0b0001, "smmulr",
2702 [(set rGPR:$Rd, (ARMsmmlar rGPR:$Rn, rGPR:$Rm, (i32 0)))]>;
2704 class T2FourRegSMMLA<bits<3> op22_20, bits<4> op7_4, string opc,
2706 : T2FourReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC32,
2707 opc, "\t$Rd, $Rn, $Rm, $Ra", pattern>,
2708 Requires<[IsThumb2, HasDSP, UseMulOps]>,
2709 Sched<[WriteMAC32, ReadMUL, ReadMUL, ReadMAC]> {
2710 let Inst{31-27} = 0b11111;
2711 let Inst{26-23} = 0b0110;
2712 let Inst{22-20} = op22_20;
2713 let Inst{7-4} = op7_4;
2716 def t2SMMLA : T2FourRegSMMLA<0b101, 0b0000, "smmla",
2717 [(set rGPR:$Rd, (add (mulhs rGPR:$Rm, rGPR:$Rn), rGPR:$Ra))]>;
2718 def t2SMMLAR: T2FourRegSMMLA<0b101, 0b0001, "smmlar",
2719 [(set rGPR:$Rd, (ARMsmmlar rGPR:$Rn, rGPR:$Rm, rGPR:$Ra))]>;
2720 def t2SMMLS: T2FourRegSMMLA<0b110, 0b0000, "smmls", []>;
2721 def t2SMMLSR: T2FourRegSMMLA<0b110, 0b0001, "smmlsr",
2722 [(set rGPR:$Rd, (ARMsmmlsr rGPR:$Rn, rGPR:$Rm, rGPR:$Ra))]>;
2724 class T2ThreeRegSMUL<bits<3> op22_20, bits<2> op5_4, string opc,
2726 : T2ThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iMUL16, opc,
2727 "\t$Rd, $Rn, $Rm", pattern>,
2728 Requires<[IsThumb2, HasDSP]>,
2729 Sched<[WriteMUL16, ReadMUL, ReadMUL]> {
2730 let Inst{31-27} = 0b11111;
2731 let Inst{26-23} = 0b0110;
2732 let Inst{22-20} = op22_20;
2733 let Inst{15-12} = 0b1111; // Ra = 0b1111 (no accumulate)
2734 let Inst{7-6} = 0b00;
2735 let Inst{5-4} = op5_4;
2738 def t2SMULBB : T2ThreeRegSMUL<0b001, 0b00, "smulbb",
2739 [(set rGPR:$Rd, (bb_mul rGPR:$Rn, rGPR:$Rm))]>;
2740 def t2SMULBT : T2ThreeRegSMUL<0b001, 0b01, "smulbt",
2741 [(set rGPR:$Rd, (bt_mul rGPR:$Rn, rGPR:$Rm))]>;
2742 def t2SMULTB : T2ThreeRegSMUL<0b001, 0b10, "smultb",
2743 [(set rGPR:$Rd, (tb_mul rGPR:$Rn, rGPR:$Rm))]>;
2744 def t2SMULTT : T2ThreeRegSMUL<0b001, 0b11, "smultt",
2745 [(set rGPR:$Rd, (tt_mul rGPR:$Rn, rGPR:$Rm))]>;
2746 def t2SMULWB : T2ThreeRegSMUL<0b011, 0b00, "smulwb",
2747 [(set rGPR:$Rd, (ARMsmulwb rGPR:$Rn, rGPR:$Rm))]>;
2748 def t2SMULWT : T2ThreeRegSMUL<0b011, 0b01, "smulwt",
2749 [(set rGPR:$Rd, (ARMsmulwt rGPR:$Rn, rGPR:$Rm))]>;
2751 def : Thumb2DSPPat<(mul sext_16_node:$Rn, (sext_bottom_16 rGPR:$Rm)),
2752 (t2SMULBB rGPR:$Rn, rGPR:$Rm)>;
2753 def : Thumb2DSPPat<(mul sext_16_node:$Rn, (sext_top_16 rGPR:$Rm)),
2754 (t2SMULBT rGPR:$Rn, rGPR:$Rm)>;
2755 def : Thumb2DSPPat<(mul (sext_top_16 rGPR:$Rn), sext_16_node:$Rm),
2756 (t2SMULTB rGPR:$Rn, rGPR:$Rm)>;
2758 def : Thumb2DSPPat<(int_arm_smulbb rGPR:$Rn, rGPR:$Rm),
2759 (t2SMULBB rGPR:$Rn, rGPR:$Rm)>;
2760 def : Thumb2DSPPat<(int_arm_smulbt rGPR:$Rn, rGPR:$Rm),
2761 (t2SMULBT rGPR:$Rn, rGPR:$Rm)>;
2762 def : Thumb2DSPPat<(int_arm_smultb rGPR:$Rn, rGPR:$Rm),
2763 (t2SMULTB rGPR:$Rn, rGPR:$Rm)>;
2764 def : Thumb2DSPPat<(int_arm_smultt rGPR:$Rn, rGPR:$Rm),
2765 (t2SMULTT rGPR:$Rn, rGPR:$Rm)>;
2766 def : Thumb2DSPPat<(int_arm_smulwb rGPR:$Rn, rGPR:$Rm),
2767 (t2SMULWB rGPR:$Rn, rGPR:$Rm)>;
2768 def : Thumb2DSPPat<(int_arm_smulwt rGPR:$Rn, rGPR:$Rm),
2769 (t2SMULWT rGPR:$Rn, rGPR:$Rm)>;
2771 class T2FourRegSMLA<bits<3> op22_20, bits<2> op5_4, string opc,
2773 : T2FourReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMUL16,
2774 opc, "\t$Rd, $Rn, $Rm, $Ra", pattern>,
2775 Requires<[IsThumb2, HasDSP, UseMulOps]>,
2776 Sched<[WriteMAC16, ReadMUL, ReadMUL, ReadMAC]> {
2777 let Inst{31-27} = 0b11111;
2778 let Inst{26-23} = 0b0110;
2779 let Inst{22-20} = op22_20;
2780 let Inst{7-6} = 0b00;
2781 let Inst{5-4} = op5_4;
2784 def t2SMLABB : T2FourRegSMLA<0b001, 0b00, "smlabb",
2785 [(set rGPR:$Rd, (add rGPR:$Ra, (bb_mul rGPR:$Rn, rGPR:$Rm)))]>;
2786 def t2SMLABT : T2FourRegSMLA<0b001, 0b01, "smlabt",
2787 [(set rGPR:$Rd, (add rGPR:$Ra, (bt_mul rGPR:$Rn, rGPR:$Rm)))]>;
2788 def t2SMLATB : T2FourRegSMLA<0b001, 0b10, "smlatb",
2789 [(set rGPR:$Rd, (add rGPR:$Ra, (tb_mul rGPR:$Rn, rGPR:$Rm)))]>;
2790 def t2SMLATT : T2FourRegSMLA<0b001, 0b11, "smlatt",
2791 [(set rGPR:$Rd, (add rGPR:$Ra, (tt_mul rGPR:$Rn, rGPR:$Rm)))]>;
2792 def t2SMLAWB : T2FourRegSMLA<0b011, 0b00, "smlawb",
2793 [(set rGPR:$Rd, (add rGPR:$Ra, (ARMsmulwb rGPR:$Rn, rGPR:$Rm)))]>;
2794 def t2SMLAWT : T2FourRegSMLA<0b011, 0b01, "smlawt",
2795 [(set rGPR:$Rd, (add rGPR:$Ra, (ARMsmulwt rGPR:$Rn, rGPR:$Rm)))]>;
2797 def : Thumb2DSPMulPat<(add rGPR:$Ra, (mul sext_16_node:$Rn, sext_16_node:$Rm)),
2798 (t2SMLABB rGPR:$Rn, rGPR:$Rm, rGPR:$Ra)>;
2799 def : Thumb2DSPMulPat<(add rGPR:$Ra, (mul sext_16_node:$Rn,
2800 (sext_bottom_16 rGPR:$Rm))),
2801 (t2SMLABB rGPR:$Rn, rGPR:$Rm, rGPR:$Ra)>;
2802 def : Thumb2DSPMulPat<(add rGPR:$Ra, (mul sext_16_node:$Rn,
2803 (sext_top_16 rGPR:$Rm))),
2804 (t2SMLABT rGPR:$Rn, rGPR:$Rm, rGPR:$Ra)>;
2805 def : Thumb2DSPMulPat<(add rGPR:$Ra, (mul (sext_top_16 rGPR:$Rn),
2807 (t2SMLATB rGPR:$Rn, rGPR:$Rm, rGPR:$Ra)>;
2809 def : Thumb2DSPPat<(int_arm_smlabb GPR:$a, GPR:$b, GPR:$acc),
2810 (t2SMLABB GPR:$a, GPR:$b, GPR:$acc)>;
2811 def : Thumb2DSPPat<(int_arm_smlabt GPR:$a, GPR:$b, GPR:$acc),
2812 (t2SMLABT GPR:$a, GPR:$b, GPR:$acc)>;
2813 def : Thumb2DSPPat<(int_arm_smlatb GPR:$a, GPR:$b, GPR:$acc),
2814 (t2SMLATB GPR:$a, GPR:$b, GPR:$acc)>;
2815 def : Thumb2DSPPat<(int_arm_smlatt GPR:$a, GPR:$b, GPR:$acc),
2816 (t2SMLATT GPR:$a, GPR:$b, GPR:$acc)>;
2817 def : Thumb2DSPPat<(int_arm_smlawb GPR:$a, GPR:$b, GPR:$acc),
2818 (t2SMLAWB GPR:$a, GPR:$b, GPR:$acc)>;
2819 def : Thumb2DSPPat<(int_arm_smlawt GPR:$a, GPR:$b, GPR:$acc),
2820 (t2SMLAWT GPR:$a, GPR:$b, GPR:$acc)>;
2822 // Halfword multiple accumulate long: SMLAL<x><y>
2823 def t2SMLALBB : T2MlaLong<0b100, 0b1000, "smlalbb">,
2824 Requires<[IsThumb2, HasDSP]>;
2825 def t2SMLALBT : T2MlaLong<0b100, 0b1001, "smlalbt">,
2826 Requires<[IsThumb2, HasDSP]>;
2827 def t2SMLALTB : T2MlaLong<0b100, 0b1010, "smlaltb">,
2828 Requires<[IsThumb2, HasDSP]>;
2829 def t2SMLALTT : T2MlaLong<0b100, 0b1011, "smlaltt">,
2830 Requires<[IsThumb2, HasDSP]>;
2832 def : Thumb2DSPPat<(ARMsmlalbb GPR:$Rn, GPR:$Rm, GPR:$RLo, GPR:$RHi),
2833 (t2SMLALBB $Rn, $Rm, $RLo, $RHi)>;
2834 def : Thumb2DSPPat<(ARMsmlalbt GPR:$Rn, GPR:$Rm, GPR:$RLo, GPR:$RHi),
2835 (t2SMLALBT $Rn, $Rm, $RLo, $RHi)>;
2836 def : Thumb2DSPPat<(ARMsmlaltb GPR:$Rn, GPR:$Rm, GPR:$RLo, GPR:$RHi),
2837 (t2SMLALTB $Rn, $Rm, $RLo, $RHi)>;
2838 def : Thumb2DSPPat<(ARMsmlaltt GPR:$Rn, GPR:$Rm, GPR:$RLo, GPR:$RHi),
2839 (t2SMLALTT $Rn, $Rm, $RLo, $RHi)>;
2841 class T2DualHalfMul<bits<3> op22_20, bits<4> op7_4, string opc,
2842 Intrinsic intrinsic>
2843 : T2ThreeReg_mac<0, op22_20, op7_4,
2845 (ins rGPR:$Rn, rGPR:$Rm),
2846 IIC_iMAC32, opc, "\t$Rd, $Rn, $Rm",
2847 [(set rGPR:$Rd, (intrinsic rGPR:$Rn, rGPR:$Rm))]>,
2848 Requires<[IsThumb2, HasDSP]>,
2849 Sched<[WriteMAC32, ReadMUL, ReadMUL, ReadMAC]> {
2850 let Inst{15-12} = 0b1111;
2853 // Dual halfword multiple: SMUAD, SMUSD, SMLAD, SMLSD, SMLALD, SMLSLD
2854 def t2SMUAD: T2DualHalfMul<0b010, 0b0000, "smuad", int_arm_smuad>;
2855 def t2SMUADX: T2DualHalfMul<0b010, 0b0001, "smuadx", int_arm_smuadx>;
2856 def t2SMUSD: T2DualHalfMul<0b100, 0b0000, "smusd", int_arm_smusd>;
2857 def t2SMUSDX: T2DualHalfMul<0b100, 0b0001, "smusdx", int_arm_smusdx>;
2859 class T2DualHalfMulAdd<bits<3> op22_20, bits<4> op7_4, string opc,
2860 Intrinsic intrinsic>
2861 : T2FourReg_mac<0, op22_20, op7_4,
2863 (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra),
2864 IIC_iMAC32, opc, "\t$Rd, $Rn, $Rm, $Ra",
2865 [(set rGPR:$Rd, (intrinsic rGPR:$Rn, rGPR:$Rm, rGPR:$Ra))]>,
2866 Requires<[IsThumb2, HasDSP]>;
2868 def t2SMLAD : T2DualHalfMulAdd<0b010, 0b0000, "smlad", int_arm_smlad>;
2869 def t2SMLADX : T2DualHalfMulAdd<0b010, 0b0001, "smladx", int_arm_smladx>;
2870 def t2SMLSD : T2DualHalfMulAdd<0b100, 0b0000, "smlsd", int_arm_smlsd>;
2871 def t2SMLSDX : T2DualHalfMulAdd<0b100, 0b0001, "smlsdx", int_arm_smlsdx>;
2873 class T2DualHalfMulAddLong<bits<3> op22_20, bits<4> op7_4, string opc>
2874 : T2FourReg_mac<1, op22_20, op7_4,
2875 (outs rGPR:$Ra, rGPR:$Rd),
2876 (ins rGPR:$Rn, rGPR:$Rm, rGPR:$RLo, rGPR:$RHi),
2877 IIC_iMAC64, opc, "\t$Ra, $Rd, $Rn, $Rm", []>,
2878 RegConstraint<"$Ra = $RLo, $Rd = $RHi">,
2879 Requires<[IsThumb2, HasDSP]>,
2880 Sched<[WriteMAC64Lo, WriteMAC64Hi, ReadMUL, ReadMUL, ReadMAC, ReadMAC]>;
2882 def t2SMLALD : T2DualHalfMulAddLong<0b100, 0b1100, "smlald">;
2883 def t2SMLALDX : T2DualHalfMulAddLong<0b100, 0b1101, "smlaldx">;
2884 def t2SMLSLD : T2DualHalfMulAddLong<0b101, 0b1100, "smlsld">;
2885 def t2SMLSLDX : T2DualHalfMulAddLong<0b101, 0b1101, "smlsldx">;
2887 def : Thumb2DSPPat<(ARMSmlald rGPR:$Rn, rGPR:$Rm, rGPR:$RLo, rGPR:$RHi),
2888 (t2SMLALD rGPR:$Rn, rGPR:$Rm, rGPR:$RLo, rGPR:$RHi)>;
2889 def : Thumb2DSPPat<(ARMSmlaldx rGPR:$Rn, rGPR:$Rm, rGPR:$RLo, rGPR:$RHi),
2890 (t2SMLALDX rGPR:$Rn, rGPR:$Rm, rGPR:$RLo, rGPR:$RHi)>;
2891 def : Thumb2DSPPat<(ARMSmlsld rGPR:$Rn, rGPR:$Rm, rGPR:$RLo, rGPR:$RHi),
2892 (t2SMLSLD rGPR:$Rn, rGPR:$Rm, rGPR:$RLo, rGPR:$RHi)>;
2893 def : Thumb2DSPPat<(ARMSmlsldx rGPR:$Rn, rGPR:$Rm, rGPR:$RLo, rGPR:$RHi),
2894 (t2SMLSLDX rGPR:$Rn, rGPR:$Rm, rGPR:$RLo, rGPR:$RHi)>;
2896 //===----------------------------------------------------------------------===//
2897 // Division Instructions.
2898 // Signed and unsigned division on v7-M
2900 def t2SDIV : T2ThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iDIV,
2901 "sdiv", "\t$Rd, $Rn, $Rm",
2902 [(set rGPR:$Rd, (sdiv rGPR:$Rn, rGPR:$Rm))]>,
2903 Requires<[HasDivideInThumb, IsThumb, HasV8MBaseline]>,
2905 let Inst{31-27} = 0b11111;
2906 let Inst{26-21} = 0b011100;
2908 let Inst{15-12} = 0b1111;
2909 let Inst{7-4} = 0b1111;
2912 def t2UDIV : T2ThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iDIV,
2913 "udiv", "\t$Rd, $Rn, $Rm",
2914 [(set rGPR:$Rd, (udiv rGPR:$Rn, rGPR:$Rm))]>,
2915 Requires<[HasDivideInThumb, IsThumb, HasV8MBaseline]>,
2917 let Inst{31-27} = 0b11111;
2918 let Inst{26-21} = 0b011101;
2920 let Inst{15-12} = 0b1111;
2921 let Inst{7-4} = 0b1111;
2924 //===----------------------------------------------------------------------===//
2925 // Misc. Arithmetic Instructions.
2928 class T2I_misc<bits<2> op1, bits<2> op2, dag oops, dag iops,
2929 InstrItinClass itin, string opc, string asm, list<dag> pattern>
2930 : T2ThreeReg<oops, iops, itin, opc, asm, pattern> {
2931 let Inst{31-27} = 0b11111;
2932 let Inst{26-22} = 0b01010;
2933 let Inst{21-20} = op1;
2934 let Inst{15-12} = 0b1111;
2935 let Inst{7-6} = 0b10;
2936 let Inst{5-4} = op2;
2940 def t2CLZ : T2I_misc<0b11, 0b00, (outs rGPR:$Rd), (ins rGPR:$Rm), IIC_iUNAr,
2941 "clz", "\t$Rd, $Rm", [(set rGPR:$Rd, (ctlz rGPR:$Rm))]>,
2944 def t2RBIT : T2I_misc<0b01, 0b10, (outs rGPR:$Rd), (ins rGPR:$Rm), IIC_iUNAr,
2945 "rbit", "\t$Rd, $Rm",
2946 [(set rGPR:$Rd, (bitreverse rGPR:$Rm))]>,
2949 def t2REV : T2I_misc<0b01, 0b00, (outs rGPR:$Rd), (ins rGPR:$Rm), IIC_iUNAr,
2950 "rev", ".w\t$Rd, $Rm", [(set rGPR:$Rd, (bswap rGPR:$Rm))]>,
2953 def t2REV16 : T2I_misc<0b01, 0b01, (outs rGPR:$Rd), (ins rGPR:$Rm), IIC_iUNAr,
2954 "rev16", ".w\t$Rd, $Rm",
2955 [(set rGPR:$Rd, (rotr (bswap rGPR:$Rm), (i32 16)))]>,
2958 def t2REVSH : T2I_misc<0b01, 0b11, (outs rGPR:$Rd), (ins rGPR:$Rm), IIC_iUNAr,
2959 "revsh", ".w\t$Rd, $Rm",
2960 [(set rGPR:$Rd, (sra (bswap rGPR:$Rm), (i32 16)))]>,
2963 def : T2Pat<(or (sra (shl rGPR:$Rm, (i32 24)), (i32 16)),
2964 (and (srl rGPR:$Rm, (i32 8)), 0xFF)),
2965 (t2REVSH rGPR:$Rm)>;
2967 def t2PKHBT : T2ThreeReg<
2968 (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, pkh_lsl_amt:$sh),
2969 IIC_iBITsi, "pkhbt", "\t$Rd, $Rn, $Rm$sh",
2970 [(set rGPR:$Rd, (or (and rGPR:$Rn, 0xFFFF),
2971 (and (shl rGPR:$Rm, pkh_lsl_amt:$sh),
2973 Requires<[HasDSP, IsThumb2]>,
2974 Sched<[WriteALUsi, ReadALU]> {
2975 let Inst{31-27} = 0b11101;
2976 let Inst{26-25} = 0b01;
2977 let Inst{24-20} = 0b01100;
2978 let Inst{5} = 0; // BT form
2982 let Inst{14-12} = sh{4-2};
2983 let Inst{7-6} = sh{1-0};
2986 // Alternate cases for PKHBT where identities eliminate some nodes.
2987 def : T2Pat<(or (and rGPR:$src1, 0xFFFF), (and rGPR:$src2, 0xFFFF0000)),
2988 (t2PKHBT rGPR:$src1, rGPR:$src2, 0)>,
2989 Requires<[HasDSP, IsThumb2]>;
2990 def : T2Pat<(or (and rGPR:$src1, 0xFFFF), (shl rGPR:$src2, imm16_31:$sh)),
2991 (t2PKHBT rGPR:$src1, rGPR:$src2, imm16_31:$sh)>,
2992 Requires<[HasDSP, IsThumb2]>;
2994 // Note: Shifts of 1-15 bits will be transformed to srl instead of sra and
2995 // will match the pattern below.
2996 def t2PKHTB : T2ThreeReg<
2997 (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, pkh_asr_amt:$sh),
2998 IIC_iBITsi, "pkhtb", "\t$Rd, $Rn, $Rm$sh",
2999 [(set rGPR:$Rd, (or (and rGPR:$Rn, 0xFFFF0000),
3000 (and (sra rGPR:$Rm, pkh_asr_amt:$sh),
3002 Requires<[HasDSP, IsThumb2]>,
3003 Sched<[WriteALUsi, ReadALU]> {
3004 let Inst{31-27} = 0b11101;
3005 let Inst{26-25} = 0b01;
3006 let Inst{24-20} = 0b01100;
3007 let Inst{5} = 1; // TB form
3011 let Inst{14-12} = sh{4-2};
3012 let Inst{7-6} = sh{1-0};
3015 // Alternate cases for PKHTB where identities eliminate some nodes. Note that
3016 // a shift amount of 0 is *not legal* here, it is PKHBT instead.
3017 // We also can not replace a srl (17..31) by an arithmetic shift we would use in
3018 // pkhtb src1, src2, asr (17..31).
3019 def : T2Pat<(or (and rGPR:$src1, 0xFFFF0000), (srl rGPR:$src2, imm16:$sh)),
3020 (t2PKHTB rGPR:$src1, rGPR:$src2, imm16:$sh)>,
3021 Requires<[HasDSP, IsThumb2]>;
3022 def : T2Pat<(or (and rGPR:$src1, 0xFFFF0000), (sra rGPR:$src2, imm16_31:$sh)),
3023 (t2PKHTB rGPR:$src1, rGPR:$src2, imm16_31:$sh)>,
3024 Requires<[HasDSP, IsThumb2]>;
3025 def : T2Pat<(or (and rGPR:$src1, 0xFFFF0000),
3026 (and (srl rGPR:$src2, imm1_15:$sh), 0xFFFF)),
3027 (t2PKHTB rGPR:$src1, rGPR:$src2, imm1_15:$sh)>,
3028 Requires<[HasDSP, IsThumb2]>;
3030 //===----------------------------------------------------------------------===//
3031 // CRC32 Instructions
3034 // + CRC32{B,H,W} 0x04C11DB7
3035 // + CRC32C{B,H,W} 0x1EDC6F41
3038 class T2I_crc32<bit C, bits<2> sz, string suffix, SDPatternOperator builtin>
3039 : T2ThreeRegNoP<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), NoItinerary,
3040 !strconcat("crc32", suffix, "\t$Rd, $Rn, $Rm"),
3041 [(set rGPR:$Rd, (builtin rGPR:$Rn, rGPR:$Rm))]>,
3042 Requires<[IsThumb2, HasV8, HasCRC]> {
3043 let Inst{31-27} = 0b11111;
3044 let Inst{26-21} = 0b010110;
3046 let Inst{15-12} = 0b1111;
3047 let Inst{7-6} = 0b10;
3051 def t2CRC32B : T2I_crc32<0, 0b00, "b", int_arm_crc32b>;
3052 def t2CRC32CB : T2I_crc32<1, 0b00, "cb", int_arm_crc32cb>;
3053 def t2CRC32H : T2I_crc32<0, 0b01, "h", int_arm_crc32h>;
3054 def t2CRC32CH : T2I_crc32<1, 0b01, "ch", int_arm_crc32ch>;
3055 def t2CRC32W : T2I_crc32<0, 0b10, "w", int_arm_crc32w>;
3056 def t2CRC32CW : T2I_crc32<1, 0b10, "cw", int_arm_crc32cw>;
3058 //===----------------------------------------------------------------------===//
3059 // Comparison Instructions...
3061 defm t2CMP : T2I_cmp_irs<0b1101, "cmp",
3062 IIC_iCMPi, IIC_iCMPr, IIC_iCMPsi, ARMcmp>;
3064 def : T2Pat<(ARMcmpZ GPRnopc:$lhs, t2_so_imm:$imm),
3065 (t2CMPri GPRnopc:$lhs, t2_so_imm:$imm)>;
3066 def : T2Pat<(ARMcmpZ GPRnopc:$lhs, rGPR:$rhs),
3067 (t2CMPrr GPRnopc:$lhs, rGPR:$rhs)>;
3068 def : T2Pat<(ARMcmpZ GPRnopc:$lhs, t2_so_reg:$rhs),
3069 (t2CMPrs GPRnopc:$lhs, t2_so_reg:$rhs)>;
3071 let isCompare = 1, Defs = [CPSR] in {
3073 def t2CMNri : T2OneRegCmpImm<
3074 (outs), (ins GPRnopc:$Rn, t2_so_imm:$imm), IIC_iCMPi,
3075 "cmn", ".w\t$Rn, $imm",
3076 [(ARMcmn GPRnopc:$Rn, (ineg t2_so_imm:$imm))]>,
3077 Sched<[WriteCMP, ReadALU]> {
3078 let Inst{31-27} = 0b11110;
3080 let Inst{24-21} = 0b1000;
3081 let Inst{20} = 1; // The S bit.
3083 let Inst{11-8} = 0b1111; // Rd
3086 def t2CMNzrr : T2TwoRegCmp<
3087 (outs), (ins GPRnopc:$Rn, rGPR:$Rm), IIC_iCMPr,
3088 "cmn", ".w\t$Rn, $Rm",
3089 [(BinOpFrag<(ARMcmpZ node:$LHS,(ineg node:$RHS))>
3090 GPRnopc:$Rn, rGPR:$Rm)]>, Sched<[WriteCMP, ReadALU, ReadALU]> {
3091 let Inst{31-27} = 0b11101;
3092 let Inst{26-25} = 0b01;
3093 let Inst{24-21} = 0b1000;
3094 let Inst{20} = 1; // The S bit.
3095 let Inst{14-12} = 0b000; // imm3
3096 let Inst{11-8} = 0b1111; // Rd
3097 let Inst{7-6} = 0b00; // imm2
3098 let Inst{5-4} = 0b00; // type
3101 def t2CMNzrs : T2OneRegCmpShiftedReg<
3102 (outs), (ins GPRnopc:$Rn, t2_so_reg:$ShiftedRm), IIC_iCMPsi,
3103 "cmn", ".w\t$Rn, $ShiftedRm",
3104 [(BinOpFrag<(ARMcmpZ node:$LHS,(ineg node:$RHS))>
3105 GPRnopc:$Rn, t2_so_reg:$ShiftedRm)]>,
3106 Sched<[WriteCMPsi, ReadALU, ReadALU]> {
3107 let Inst{31-27} = 0b11101;
3108 let Inst{26-25} = 0b01;
3109 let Inst{24-21} = 0b1000;
3110 let Inst{20} = 1; // The S bit.
3111 let Inst{11-8} = 0b1111; // Rd
3115 // Assembler aliases w/o the ".w" suffix.
3116 // No alias here for 'rr' version as not all instantiations of this multiclass
3117 // want one (CMP in particular, does not).
3118 def : t2InstAlias<"cmn${p} $Rn, $imm",
3119 (t2CMNri GPRnopc:$Rn, t2_so_imm:$imm, pred:$p)>;
3120 def : t2InstAlias<"cmn${p} $Rn, $shift",
3121 (t2CMNzrs GPRnopc:$Rn, t2_so_reg:$shift, pred:$p)>;
3123 def : T2Pat<(ARMcmp GPR:$src, t2_so_imm_neg:$imm),
3124 (t2CMNri GPR:$src, t2_so_imm_neg:$imm)>;
3126 def : T2Pat<(ARMcmpZ GPRnopc:$src, t2_so_imm_neg:$imm),
3127 (t2CMNri GPRnopc:$src, t2_so_imm_neg:$imm)>;
3129 defm t2TST : T2I_cmp_irs<0b0000, "tst",
3130 IIC_iTSTi, IIC_iTSTr, IIC_iTSTsi,
3131 BinOpFrag<(ARMcmpZ (and_su node:$LHS, node:$RHS), 0)>>;
3132 defm t2TEQ : T2I_cmp_irs<0b0100, "teq",
3133 IIC_iTSTi, IIC_iTSTr, IIC_iTSTsi,
3134 BinOpFrag<(ARMcmpZ (xor_su node:$LHS, node:$RHS), 0)>>;
3136 // Conditional moves
3137 let hasSideEffects = 0 in {
3139 let isCommutable = 1, isSelect = 1 in
3140 def t2MOVCCr : t2PseudoInst<(outs rGPR:$Rd),
3141 (ins rGPR:$false, rGPR:$Rm, cmovpred:$p),
3143 [(set rGPR:$Rd, (ARMcmov rGPR:$false, rGPR:$Rm,
3145 RegConstraint<"$false = $Rd">, Sched<[WriteALU]>;
3147 let isMoveImm = 1 in
3149 : t2PseudoInst<(outs rGPR:$Rd),
3150 (ins rGPR:$false, t2_so_imm:$imm, cmovpred:$p),
3152 [(set rGPR:$Rd, (ARMcmov rGPR:$false,t2_so_imm:$imm,
3154 RegConstraint<"$false = $Rd">, Sched<[WriteALU]>;
3156 let isCodeGenOnly = 1 in {
3157 let isMoveImm = 1 in
3159 : t2PseudoInst<(outs rGPR:$Rd),
3160 (ins rGPR:$false, imm0_65535_expr:$imm, cmovpred:$p),
3162 [(set rGPR:$Rd, (ARMcmov rGPR:$false, imm0_65535:$imm,
3164 RegConstraint<"$false = $Rd">, Sched<[WriteALU]>;
3166 let isMoveImm = 1 in
3168 : t2PseudoInst<(outs rGPR:$Rd),
3169 (ins rGPR:$false, t2_so_imm:$imm, cmovpred:$p),
3172 (ARMcmov rGPR:$false, t2_so_imm_not:$imm,
3174 RegConstraint<"$false = $Rd">, Sched<[WriteALU]>;
3176 class MOVCCShPseudo<SDPatternOperator opnode, Operand ty>
3177 : t2PseudoInst<(outs rGPR:$Rd),
3178 (ins rGPR:$false, rGPR:$Rm, i32imm:$imm, cmovpred:$p),
3180 [(set rGPR:$Rd, (ARMcmov rGPR:$false,
3181 (opnode rGPR:$Rm, (i32 ty:$imm)),
3183 RegConstraint<"$false = $Rd">, Sched<[WriteALU]>;
3185 def t2MOVCClsl : MOVCCShPseudo<shl, imm0_31>;
3186 def t2MOVCClsr : MOVCCShPseudo<srl, imm_sr>;
3187 def t2MOVCCasr : MOVCCShPseudo<sra, imm_sr>;
3188 def t2MOVCCror : MOVCCShPseudo<rotr, imm0_31>;
3190 let isMoveImm = 1 in
3192 : t2PseudoInst<(outs rGPR:$dst),
3193 (ins rGPR:$false, i32imm:$src, cmovpred:$p),
3195 [(set rGPR:$dst, (ARMcmov rGPR:$false, imm:$src,
3197 RegConstraint<"$false = $dst">;
3198 } // isCodeGenOnly = 1
3202 //===----------------------------------------------------------------------===//
3203 // Atomic operations intrinsics
3206 // memory barriers protect the atomic sequences
3207 let hasSideEffects = 1 in {
3208 def t2DMB : T2I<(outs), (ins memb_opt:$opt), NoItinerary,
3209 "dmb", "\t$opt", [(int_arm_dmb (i32 imm0_15:$opt))]>,
3210 Requires<[IsThumb, HasDB]> {
3212 let Inst{31-4} = 0xf3bf8f5;
3213 let Inst{3-0} = opt;
3216 def t2DSB : T2I<(outs), (ins memb_opt:$opt), NoItinerary,
3217 "dsb", "\t$opt", [(int_arm_dsb (i32 imm0_15:$opt))]>,
3218 Requires<[IsThumb, HasDB]> {
3220 let Inst{31-4} = 0xf3bf8f4;
3221 let Inst{3-0} = opt;
3224 def t2ISB : T2I<(outs), (ins instsyncb_opt:$opt), NoItinerary,
3225 "isb", "\t$opt", [(int_arm_isb (i32 imm0_15:$opt))]>,
3226 Requires<[IsThumb, HasDB]> {
3228 let Inst{31-4} = 0xf3bf8f6;
3229 let Inst{3-0} = opt;
3232 let hasNoSchedulingInfo = 1 in
3233 def t2TSB : T2I<(outs), (ins tsb_opt:$opt), NoItinerary,
3234 "tsb", "\t$opt", []>, Requires<[IsThumb, HasV8_4a]> {
3235 let Inst{31-0} = 0xf3af8012;
3239 // Armv8.5-A speculation barrier
3240 def t2SB : Thumb2XI<(outs), (ins), AddrModeNone, 4, NoItinerary, "sb", "", []>,
3241 Requires<[IsThumb2, HasSB]>, Sched<[]> {
3242 let Inst{31-0} = 0xf3bf8f70;
3243 let Unpredictable = 0x000f2f0f;
3244 let hasSideEffects = 1;
3247 class T2I_ldrex<bits<4> opcod, dag oops, dag iops, AddrMode am, int sz,
3248 InstrItinClass itin, string opc, string asm, string cstr,
3249 list<dag> pattern, bits<4> rt2 = 0b1111>
3250 : Thumb2I<oops, iops, am, sz, itin, opc, asm, cstr, pattern> {
3251 let Inst{31-27} = 0b11101;
3252 let Inst{26-20} = 0b0001101;
3253 let Inst{11-8} = rt2;
3254 let Inst{7-4} = opcod;
3255 let Inst{3-0} = 0b1111;
3259 let Inst{19-16} = addr;
3260 let Inst{15-12} = Rt;
3262 class T2I_strex<bits<4> opcod, dag oops, dag iops, AddrMode am, int sz,
3263 InstrItinClass itin, string opc, string asm, string cstr,
3264 list<dag> pattern, bits<4> rt2 = 0b1111>
3265 : Thumb2I<oops, iops, am, sz, itin, opc, asm, cstr, pattern> {
3266 let Inst{31-27} = 0b11101;
3267 let Inst{26-20} = 0b0001100;
3268 let Inst{11-8} = rt2;
3269 let Inst{7-4} = opcod;
3275 let Inst{19-16} = addr;
3276 let Inst{15-12} = Rt;
3279 let mayLoad = 1 in {
3280 def t2LDREXB : T2I_ldrex<0b0100, (outs rGPR:$Rt), (ins addr_offset_none:$addr),
3281 AddrModeNone, 4, NoItinerary,
3282 "ldrexb", "\t$Rt, $addr", "",
3283 [(set rGPR:$Rt, (ldrex_1 addr_offset_none:$addr))]>,
3284 Requires<[IsThumb, HasV8MBaseline]>;
3285 def t2LDREXH : T2I_ldrex<0b0101, (outs rGPR:$Rt), (ins addr_offset_none:$addr),
3286 AddrModeNone, 4, NoItinerary,
3287 "ldrexh", "\t$Rt, $addr", "",
3288 [(set rGPR:$Rt, (ldrex_2 addr_offset_none:$addr))]>,
3289 Requires<[IsThumb, HasV8MBaseline]>;
3290 def t2LDREX : Thumb2I<(outs rGPR:$Rt), (ins t2addrmode_imm0_1020s4:$addr),
3291 AddrModeT2_ldrex, 4, NoItinerary,
3292 "ldrex", "\t$Rt, $addr", "",
3293 [(set rGPR:$Rt, (ldrex_4 t2addrmode_imm0_1020s4:$addr))]>,
3294 Requires<[IsThumb, HasV8MBaseline]> {
3297 let Inst{31-27} = 0b11101;
3298 let Inst{26-20} = 0b0000101;
3299 let Inst{19-16} = addr{11-8};
3300 let Inst{15-12} = Rt;
3301 let Inst{11-8} = 0b1111;
3302 let Inst{7-0} = addr{7-0};
3304 let hasExtraDefRegAllocReq = 1 in
3305 def t2LDREXD : T2I_ldrex<0b0111, (outs rGPR:$Rt, rGPR:$Rt2),
3306 (ins addr_offset_none:$addr),
3307 AddrModeNone, 4, NoItinerary,
3308 "ldrexd", "\t$Rt, $Rt2, $addr", "",
3310 Requires<[IsThumb2, IsNotMClass]> {
3312 let Inst{11-8} = Rt2;
3314 def t2LDAEXB : T2I_ldrex<0b1100, (outs rGPR:$Rt), (ins addr_offset_none:$addr),
3315 AddrModeNone, 4, NoItinerary,
3316 "ldaexb", "\t$Rt, $addr", "",
3317 [(set rGPR:$Rt, (ldaex_1 addr_offset_none:$addr))]>,
3318 Requires<[IsThumb, HasAcquireRelease, HasV7Clrex]>;
3319 def t2LDAEXH : T2I_ldrex<0b1101, (outs rGPR:$Rt), (ins addr_offset_none:$addr),
3320 AddrModeNone, 4, NoItinerary,
3321 "ldaexh", "\t$Rt, $addr", "",
3322 [(set rGPR:$Rt, (ldaex_2 addr_offset_none:$addr))]>,
3323 Requires<[IsThumb, HasAcquireRelease, HasV7Clrex]>;
3324 def t2LDAEX : Thumb2I<(outs rGPR:$Rt), (ins addr_offset_none:$addr),
3325 AddrModeNone, 4, NoItinerary,
3326 "ldaex", "\t$Rt, $addr", "",
3327 [(set rGPR:$Rt, (ldaex_4 addr_offset_none:$addr))]>,
3328 Requires<[IsThumb, HasAcquireRelease, HasV7Clrex]> {
3331 let Inst{31-27} = 0b11101;
3332 let Inst{26-20} = 0b0001101;
3333 let Inst{19-16} = addr;
3334 let Inst{15-12} = Rt;
3335 let Inst{11-8} = 0b1111;
3336 let Inst{7-0} = 0b11101111;
3338 let hasExtraDefRegAllocReq = 1 in
3339 def t2LDAEXD : T2I_ldrex<0b1111, (outs rGPR:$Rt, rGPR:$Rt2),
3340 (ins addr_offset_none:$addr),
3341 AddrModeNone, 4, NoItinerary,
3342 "ldaexd", "\t$Rt, $Rt2, $addr", "",
3343 [], {?, ?, ?, ?}>, Requires<[IsThumb,
3344 HasAcquireRelease, HasV7Clrex, IsNotMClass]> {
3346 let Inst{11-8} = Rt2;
3352 let mayStore = 1, Constraints = "@earlyclobber $Rd" in {
3353 def t2STREXB : T2I_strex<0b0100, (outs rGPR:$Rd),
3354 (ins rGPR:$Rt, addr_offset_none:$addr),
3355 AddrModeNone, 4, NoItinerary,
3356 "strexb", "\t$Rd, $Rt, $addr", "",
3358 (strex_1 rGPR:$Rt, addr_offset_none:$addr))]>,
3359 Requires<[IsThumb, HasV8MBaseline]>;
3360 def t2STREXH : T2I_strex<0b0101, (outs rGPR:$Rd),
3361 (ins rGPR:$Rt, addr_offset_none:$addr),
3362 AddrModeNone, 4, NoItinerary,
3363 "strexh", "\t$Rd, $Rt, $addr", "",
3365 (strex_2 rGPR:$Rt, addr_offset_none:$addr))]>,
3366 Requires<[IsThumb, HasV8MBaseline]>;
3368 def t2STREX : Thumb2I<(outs rGPR:$Rd), (ins rGPR:$Rt,
3369 t2addrmode_imm0_1020s4:$addr),
3370 AddrModeT2_ldrex, 4, NoItinerary,
3371 "strex", "\t$Rd, $Rt, $addr", "",
3373 (strex_4 rGPR:$Rt, t2addrmode_imm0_1020s4:$addr))]>,
3374 Requires<[IsThumb, HasV8MBaseline]> {
3378 let Inst{31-27} = 0b11101;
3379 let Inst{26-20} = 0b0000100;
3380 let Inst{19-16} = addr{11-8};
3381 let Inst{15-12} = Rt;
3382 let Inst{11-8} = Rd;
3383 let Inst{7-0} = addr{7-0};
3385 let hasExtraSrcRegAllocReq = 1 in
3386 def t2STREXD : T2I_strex<0b0111, (outs rGPR:$Rd),
3387 (ins rGPR:$Rt, rGPR:$Rt2, addr_offset_none:$addr),
3388 AddrModeNone, 4, NoItinerary,
3389 "strexd", "\t$Rd, $Rt, $Rt2, $addr", "", [],
3391 Requires<[IsThumb2, IsNotMClass]> {
3393 let Inst{11-8} = Rt2;
3395 def t2STLEXB : T2I_strex<0b1100, (outs rGPR:$Rd),
3396 (ins rGPR:$Rt, addr_offset_none:$addr),
3397 AddrModeNone, 4, NoItinerary,
3398 "stlexb", "\t$Rd, $Rt, $addr", "",
3400 (stlex_1 rGPR:$Rt, addr_offset_none:$addr))]>,
3401 Requires<[IsThumb, HasAcquireRelease,
3404 def t2STLEXH : T2I_strex<0b1101, (outs rGPR:$Rd),
3405 (ins rGPR:$Rt, addr_offset_none:$addr),
3406 AddrModeNone, 4, NoItinerary,
3407 "stlexh", "\t$Rd, $Rt, $addr", "",
3409 (stlex_2 rGPR:$Rt, addr_offset_none:$addr))]>,
3410 Requires<[IsThumb, HasAcquireRelease,
3413 def t2STLEX : Thumb2I<(outs rGPR:$Rd), (ins rGPR:$Rt,
3414 addr_offset_none:$addr),
3415 AddrModeNone, 4, NoItinerary,
3416 "stlex", "\t$Rd, $Rt, $addr", "",
3418 (stlex_4 rGPR:$Rt, addr_offset_none:$addr))]>,
3419 Requires<[IsThumb, HasAcquireRelease, HasV7Clrex]> {
3423 let Inst{31-27} = 0b11101;
3424 let Inst{26-20} = 0b0001100;
3425 let Inst{19-16} = addr;
3426 let Inst{15-12} = Rt;
3427 let Inst{11-4} = 0b11111110;
3430 let hasExtraSrcRegAllocReq = 1 in
3431 def t2STLEXD : T2I_strex<0b1111, (outs rGPR:$Rd),
3432 (ins rGPR:$Rt, rGPR:$Rt2, addr_offset_none:$addr),
3433 AddrModeNone, 4, NoItinerary,
3434 "stlexd", "\t$Rd, $Rt, $Rt2, $addr", "", [],
3435 {?, ?, ?, ?}>, Requires<[IsThumb, HasAcquireRelease,
3436 HasV7Clrex, IsNotMClass]> {
3438 let Inst{11-8} = Rt2;
3442 def t2CLREX : T2I<(outs), (ins), NoItinerary, "clrex", "", [(int_arm_clrex)]>,
3443 Requires<[IsThumb, HasV7Clrex]> {
3444 let Inst{31-16} = 0xf3bf;
3445 let Inst{15-14} = 0b10;
3448 let Inst{11-8} = 0b1111;
3449 let Inst{7-4} = 0b0010;
3450 let Inst{3-0} = 0b1111;
3453 def : T2Pat<(and (ldrex_1 addr_offset_none:$addr), 0xff),
3454 (t2LDREXB addr_offset_none:$addr)>,
3455 Requires<[IsThumb, HasV8MBaseline]>;
3456 def : T2Pat<(and (ldrex_2 addr_offset_none:$addr), 0xffff),
3457 (t2LDREXH addr_offset_none:$addr)>,
3458 Requires<[IsThumb, HasV8MBaseline]>;
3459 def : T2Pat<(strex_1 (and GPR:$Rt, 0xff), addr_offset_none:$addr),
3460 (t2STREXB GPR:$Rt, addr_offset_none:$addr)>,
3461 Requires<[IsThumb, HasV8MBaseline]>;
3462 def : T2Pat<(strex_2 (and GPR:$Rt, 0xffff), addr_offset_none:$addr),
3463 (t2STREXH GPR:$Rt, addr_offset_none:$addr)>,
3464 Requires<[IsThumb, HasV8MBaseline]>;
3466 def : T2Pat<(and (ldaex_1 addr_offset_none:$addr), 0xff),
3467 (t2LDAEXB addr_offset_none:$addr)>,
3468 Requires<[IsThumb, HasAcquireRelease, HasV7Clrex]>;
3469 def : T2Pat<(and (ldaex_2 addr_offset_none:$addr), 0xffff),
3470 (t2LDAEXH addr_offset_none:$addr)>,
3471 Requires<[IsThumb, HasAcquireRelease, HasV7Clrex]>;
3472 def : T2Pat<(stlex_1 (and GPR:$Rt, 0xff), addr_offset_none:$addr),
3473 (t2STLEXB GPR:$Rt, addr_offset_none:$addr)>,
3474 Requires<[IsThumb, HasAcquireRelease, HasV7Clrex]>;
3475 def : T2Pat<(stlex_2 (and GPR:$Rt, 0xffff), addr_offset_none:$addr),
3476 (t2STLEXH GPR:$Rt, addr_offset_none:$addr)>,
3477 Requires<[IsThumb, HasAcquireRelease, HasV7Clrex]>;
3479 //===----------------------------------------------------------------------===//
3480 // SJLJ Exception handling intrinsics
3481 // eh_sjlj_setjmp() is an instruction sequence to store the return
3482 // address and save #0 in R0 for the non-longjmp case.
3483 // Since by its nature we may be coming from some other function to get
3484 // here, and we're using the stack frame for the containing function to
3485 // save/restore registers, we can't keep anything live in regs across
3486 // the eh_sjlj_setjmp(), else it will almost certainly have been tromped upon
3487 // when we get here from a longjmp(). We force everything out of registers
3488 // except for our own input by listing the relevant registers in Defs. By
3489 // doing so, we also cause the prologue/epilogue code to actively preserve
3490 // all of the callee-saved resgisters, which is exactly what we want.
3491 // $val is a scratch register for our use.
3493 [ R0, R1, R2, R3, R4, R5, R6, R7, R8, R9, R10, R11, R12, LR, CPSR,
3494 Q0, Q1, Q2, Q3, Q8, Q9, Q10, Q11, Q12, Q13, Q14, Q15],
3495 hasSideEffects = 1, isBarrier = 1, isCodeGenOnly = 1,
3496 usesCustomInserter = 1 in {
3497 def t2Int_eh_sjlj_setjmp : Thumb2XI<(outs), (ins tGPR:$src, tGPR:$val),
3498 AddrModeNone, 0, NoItinerary, "", "",
3499 [(set R0, (ARMeh_sjlj_setjmp tGPR:$src, tGPR:$val))]>,
3500 Requires<[IsThumb2, HasVFP2]>;
3504 [ R0, R1, R2, R3, R4, R5, R6, R7, R8, R9, R10, R11, R12, LR, CPSR ],
3505 hasSideEffects = 1, isBarrier = 1, isCodeGenOnly = 1,
3506 usesCustomInserter = 1 in {
3507 def t2Int_eh_sjlj_setjmp_nofp : Thumb2XI<(outs), (ins tGPR:$src, tGPR:$val),
3508 AddrModeNone, 0, NoItinerary, "", "",
3509 [(set R0, (ARMeh_sjlj_setjmp tGPR:$src, tGPR:$val))]>,
3510 Requires<[IsThumb2, NoVFP]>;
3514 //===----------------------------------------------------------------------===//
3515 // Control-Flow Instructions
3518 // FIXME: remove when we have a way to marking a MI with these properties.
3519 // FIXME: Should pc be an implicit operand like PICADD, etc?
3520 let isReturn = 1, isTerminator = 1, isBarrier = 1, mayLoad = 1,
3521 hasExtraDefRegAllocReq = 1, isCodeGenOnly = 1 in
3522 def t2LDMIA_RET: t2PseudoExpand<(outs GPR:$wb), (ins GPR:$Rn, pred:$p,
3523 reglist:$regs, variable_ops),
3524 4, IIC_iLoad_mBr, [],
3525 (t2LDMIA_UPD GPR:$wb, GPR:$Rn, pred:$p, reglist:$regs)>,
3526 RegConstraint<"$Rn = $wb">;
3528 let isBranch = 1, isTerminator = 1, isBarrier = 1 in {
3529 let isPredicable = 1 in
3530 def t2B : T2I<(outs), (ins thumb_br_target:$target), IIC_Br,
3532 [(br bb:$target)]>, Sched<[WriteBr]>,
3533 Requires<[IsThumb, HasV8MBaseline]> {
3534 let Inst{31-27} = 0b11110;
3535 let Inst{15-14} = 0b10;
3539 let Inst{26} = target{23};
3540 let Inst{13} = target{22};
3541 let Inst{11} = target{21};
3542 let Inst{25-16} = target{20-11};
3543 let Inst{10-0} = target{10-0};
3544 let DecoderMethod = "DecodeT2BInstruction";
3545 let AsmMatchConverter = "cvtThumbBranches";
3548 let Size = 4, isNotDuplicable = 1, isBranch = 1, isTerminator = 1,
3549 isBarrier = 1, isIndirectBranch = 1 in {
3551 // available in both v8-M.Baseline and Thumb2 targets
3552 def t2BR_JT : t2basePseudoInst<(outs),
3553 (ins GPR:$target, GPR:$index, i32imm:$jt),
3555 [(ARMbr2jt GPR:$target, GPR:$index, tjumptable:$jt)]>,
3558 // FIXME: Add a case that can be predicated.
3559 def t2TBB_JT : t2PseudoInst<(outs),
3560 (ins GPR:$base, GPR:$index, i32imm:$jt, i32imm:$pclbl), 0, IIC_Br, []>,
3563 def t2TBH_JT : t2PseudoInst<(outs),
3564 (ins GPR:$base, GPR:$index, i32imm:$jt, i32imm:$pclbl), 0, IIC_Br, []>,
3567 def t2TBB : T2I<(outs), (ins addrmode_tbb:$addr), IIC_Br,
3568 "tbb", "\t$addr", []>, Sched<[WriteBrTbl]> {
3571 let Inst{31-20} = 0b111010001101;
3572 let Inst{19-16} = Rn;
3573 let Inst{15-5} = 0b11110000000;
3574 let Inst{4} = 0; // B form
3577 let DecoderMethod = "DecodeThumbTableBranch";
3580 def t2TBH : T2I<(outs), (ins addrmode_tbh:$addr), IIC_Br,
3581 "tbh", "\t$addr", []>, Sched<[WriteBrTbl]> {
3584 let Inst{31-20} = 0b111010001101;
3585 let Inst{19-16} = Rn;
3586 let Inst{15-5} = 0b11110000000;
3587 let Inst{4} = 1; // H form
3590 let DecoderMethod = "DecodeThumbTableBranch";
3592 } // isNotDuplicable, isIndirectBranch
3594 } // isBranch, isTerminator, isBarrier
3596 // FIXME: should be able to write a pattern for ARMBrcond, but can't use
3597 // a two-value operand where a dag node expects ", "two operands. :(
3598 let isBranch = 1, isTerminator = 1 in
3599 def t2Bcc : T2I<(outs), (ins brtarget:$target), IIC_Br,
3601 [/*(ARMbrcond bb:$target, imm:$cc)*/]>, Sched<[WriteBr]> {
3602 let Inst{31-27} = 0b11110;
3603 let Inst{15-14} = 0b10;
3607 let Inst{25-22} = p;
3610 let Inst{26} = target{20};
3611 let Inst{11} = target{19};
3612 let Inst{13} = target{18};
3613 let Inst{21-16} = target{17-12};
3614 let Inst{10-0} = target{11-1};
3616 let DecoderMethod = "DecodeThumb2BCCInstruction";
3617 let AsmMatchConverter = "cvtThumbBranches";
3620 // Tail calls. The MachO version of thumb tail calls uses a t2 branch, so
3622 let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1 in {
3625 def tTAILJMPd: tPseudoExpand<(outs),
3626 (ins thumb_br_target:$dst, pred:$p),
3628 (t2B thumb_br_target:$dst, pred:$p)>,
3629 Requires<[IsThumb2, IsMachO]>, Sched<[WriteBr]>;
3633 let Defs = [ITSTATE] in
3634 def t2IT : Thumb2XI<(outs), (ins it_pred:$cc, it_mask:$mask),
3635 AddrModeNone, 2, IIC_iALUx,
3636 "it$mask\t$cc", "", []>,
3637 ComplexDeprecationPredicate<"IT"> {
3638 // 16-bit instruction.
3639 let Inst{31-16} = 0x0000;
3640 let Inst{15-8} = 0b10111111;
3645 let Inst{3-0} = mask;
3647 let DecoderMethod = "DecodeIT";
3650 // Branch and Exchange Jazelle -- for disassembly only
3652 let isBranch = 1, isTerminator = 1, isBarrier = 1, isIndirectBranch = 1 in
3653 def t2BXJ : T2I<(outs), (ins GPRnopc:$func), NoItinerary, "bxj", "\t$func", []>,
3654 Sched<[WriteBr]>, Requires<[IsThumb2, IsNotMClass]> {
3656 let Inst{31-27} = 0b11110;
3658 let Inst{25-20} = 0b111100;
3659 let Inst{19-16} = func;
3660 let Inst{15-0} = 0b1000111100000000;
3663 // Compare and branch on zero / non-zero
3664 let isBranch = 1, isTerminator = 1 in {
3665 def tCBZ : T1I<(outs), (ins tGPR:$Rn, thumb_cb_target:$target), IIC_Br,
3666 "cbz\t$Rn, $target", []>,
3667 T1Misc<{0,0,?,1,?,?,?}>,
3668 Requires<[IsThumb, HasV8MBaseline]>, Sched<[WriteBr]> {
3672 let Inst{9} = target{5};
3673 let Inst{7-3} = target{4-0};
3677 def tCBNZ : T1I<(outs), (ins tGPR:$Rn, thumb_cb_target:$target), IIC_Br,
3678 "cbnz\t$Rn, $target", []>,
3679 T1Misc<{1,0,?,1,?,?,?}>,
3680 Requires<[IsThumb, HasV8MBaseline]>, Sched<[WriteBr]> {
3684 let Inst{9} = target{5};
3685 let Inst{7-3} = target{4-0};
3691 // Change Processor State is a system instruction.
3692 // FIXME: Since the asm parser has currently no clean way to handle optional
3693 // operands, create 3 versions of the same instruction. Once there's a clean
3694 // framework to represent optional operands, change this behavior.
3695 class t2CPS<dag iops, string asm_op> : T2XI<(outs), iops, NoItinerary,
3696 !strconcat("cps", asm_op), []>,
3697 Requires<[IsThumb2, IsNotMClass]> {
3703 let Inst{31-11} = 0b111100111010111110000;
3704 let Inst{10-9} = imod;
3706 let Inst{7-5} = iflags;
3707 let Inst{4-0} = mode;
3708 let DecoderMethod = "DecodeT2CPSInstruction";
3712 def t2CPS3p : t2CPS<(ins imod_op:$imod, iflags_op:$iflags, i32imm:$mode),
3713 "$imod\t$iflags, $mode">;
3714 let mode = 0, M = 0 in
3715 def t2CPS2p : t2CPS<(ins imod_op:$imod, iflags_op:$iflags),
3716 "$imod.w\t$iflags">;
3717 let imod = 0, iflags = 0, M = 1 in
3718 def t2CPS1p : t2CPS<(ins imm0_31:$mode), "\t$mode">;
3720 def : t2InstAlias<"cps$imod.w $iflags, $mode",
3721 (t2CPS3p imod_op:$imod, iflags_op:$iflags, i32imm:$mode), 0>;
3722 def : t2InstAlias<"cps.w $mode", (t2CPS1p imm0_31:$mode), 0>;
3724 // A6.3.4 Branches and miscellaneous control
3725 // Table A6-14 Change Processor State, and hint instructions
3726 def t2HINT : T2I<(outs), (ins imm0_239:$imm), NoItinerary, "hint", ".w\t$imm",
3727 [(int_arm_hint imm0_239:$imm)]> {
3729 let Inst{31-3} = 0b11110011101011111000000000000;
3730 let Inst{7-0} = imm;
3733 def : t2InstAlias<"hint$p $imm", (t2HINT imm0_239:$imm, pred:$p), 0>;
3734 def : t2InstAlias<"nop$p.w", (t2HINT 0, pred:$p), 1>;
3735 def : t2InstAlias<"yield$p.w", (t2HINT 1, pred:$p), 1>;
3736 def : t2InstAlias<"wfe$p.w", (t2HINT 2, pred:$p), 1>;
3737 def : t2InstAlias<"wfi$p.w", (t2HINT 3, pred:$p), 1>;
3738 def : t2InstAlias<"sev$p.w", (t2HINT 4, pred:$p), 1>;
3739 def : t2InstAlias<"sevl$p.w", (t2HINT 5, pred:$p), 1> {
3740 let Predicates = [IsThumb2, HasV8];
3742 def : t2InstAlias<"esb$p.w", (t2HINT 16, pred:$p), 1> {
3743 let Predicates = [IsThumb2, HasRAS];
3745 def : t2InstAlias<"esb$p", (t2HINT 16, pred:$p), 0> {
3746 let Predicates = [IsThumb2, HasRAS];
3748 def : t2InstAlias<"csdb$p.w", (t2HINT 20, pred:$p), 0>;
3749 def : t2InstAlias<"csdb$p", (t2HINT 20, pred:$p), 1>;
3751 def t2DBG : T2I<(outs), (ins imm0_15:$opt), NoItinerary, "dbg", "\t$opt",
3752 [(int_arm_dbg imm0_15:$opt)]> {
3754 let Inst{31-20} = 0b111100111010;
3755 let Inst{19-16} = 0b1111;
3756 let Inst{15-8} = 0b10000000;
3757 let Inst{7-4} = 0b1111;
3758 let Inst{3-0} = opt;
3761 // Secure Monitor Call is a system instruction.
3762 // Option = Inst{19-16}
3763 let isCall = 1, Uses = [SP] in
3764 def t2SMC : T2I<(outs), (ins imm0_15:$opt), NoItinerary, "smc", "\t$opt",
3765 []>, Requires<[IsThumb2, HasTrustZone]> {
3766 let Inst{31-27} = 0b11110;
3767 let Inst{26-20} = 0b1111111;
3768 let Inst{15-12} = 0b1000;
3771 let Inst{19-16} = opt;
3774 class T2DCPS<bits<2> opt, string opc>
3775 : T2I<(outs), (ins), NoItinerary, opc, "", []>, Requires<[IsThumb2, HasV8]> {
3776 let Inst{31-27} = 0b11110;
3777 let Inst{26-20} = 0b1111000;
3778 let Inst{19-16} = 0b1111;
3779 let Inst{15-12} = 0b1000;
3780 let Inst{11-2} = 0b0000000000;
3781 let Inst{1-0} = opt;
3784 def t2DCPS1 : T2DCPS<0b01, "dcps1">;
3785 def t2DCPS2 : T2DCPS<0b10, "dcps2">;
3786 def t2DCPS3 : T2DCPS<0b11, "dcps3">;
3788 class T2SRS<bits<2> Op, bit W, dag oops, dag iops, InstrItinClass itin,
3789 string opc, string asm, list<dag> pattern>
3790 : T2I<oops, iops, itin, opc, asm, pattern>,
3791 Requires<[IsThumb2,IsNotMClass]> {
3793 let Inst{31-25} = 0b1110100;
3794 let Inst{24-23} = Op;
3797 let Inst{20-16} = 0b01101;
3798 let Inst{15-5} = 0b11000000000;
3799 let Inst{4-0} = mode{4-0};
3802 // Store Return State is a system instruction.
3803 def t2SRSDB_UPD : T2SRS<0b00, 1, (outs), (ins imm0_31:$mode), NoItinerary,
3804 "srsdb", "\tsp!, $mode", []>;
3805 def t2SRSDB : T2SRS<0b00, 0, (outs), (ins imm0_31:$mode), NoItinerary,
3806 "srsdb","\tsp, $mode", []>;
3807 def t2SRSIA_UPD : T2SRS<0b11, 1, (outs), (ins imm0_31:$mode), NoItinerary,
3808 "srsia","\tsp!, $mode", []>;
3809 def t2SRSIA : T2SRS<0b11, 0, (outs), (ins imm0_31:$mode), NoItinerary,
3810 "srsia","\tsp, $mode", []>;
3813 def : t2InstAlias<"srsdb${p} $mode", (t2SRSDB imm0_31:$mode, pred:$p)>;
3814 def : t2InstAlias<"srsdb${p} $mode!", (t2SRSDB_UPD imm0_31:$mode, pred:$p)>;
3816 def : t2InstAlias<"srsia${p} $mode", (t2SRSIA imm0_31:$mode, pred:$p)>;
3817 def : t2InstAlias<"srsia${p} $mode!", (t2SRSIA_UPD imm0_31:$mode, pred:$p)>;
3819 // Return From Exception is a system instruction.
3820 let isReturn = 1, isBarrier = 1, isTerminator = 1, Defs = [PC] in
3821 class T2RFE<bits<12> op31_20, dag oops, dag iops, InstrItinClass itin,
3822 string opc, string asm, list<dag> pattern>
3823 : T2I<oops, iops, itin, opc, asm, pattern>,
3824 Requires<[IsThumb2,IsNotMClass]> {
3825 let Inst{31-20} = op31_20{11-0};
3828 let Inst{19-16} = Rn;
3829 let Inst{15-0} = 0xc000;
3832 def t2RFEDBW : T2RFE<0b111010000011,
3833 (outs), (ins GPR:$Rn), NoItinerary, "rfedb", "\t$Rn!",
3834 [/* For disassembly only; pattern left blank */]>;
3835 def t2RFEDB : T2RFE<0b111010000001,
3836 (outs), (ins GPR:$Rn), NoItinerary, "rfedb", "\t$Rn",
3837 [/* For disassembly only; pattern left blank */]>;
3838 def t2RFEIAW : T2RFE<0b111010011011,
3839 (outs), (ins GPR:$Rn), NoItinerary, "rfeia", "\t$Rn!",
3840 [/* For disassembly only; pattern left blank */]>;
3841 def t2RFEIA : T2RFE<0b111010011001,
3842 (outs), (ins GPR:$Rn), NoItinerary, "rfeia", "\t$Rn",
3843 [/* For disassembly only; pattern left blank */]>;
3845 // B9.3.19 SUBS PC, LR, #imm (Thumb2) system instruction.
3846 // Exception return instruction is "subs pc, lr, #imm".
3847 let isReturn = 1, isBarrier = 1, isTerminator = 1, Defs = [PC] in
3848 def t2SUBS_PC_LR : T2I <(outs), (ins imm0_255:$imm), NoItinerary,
3849 "subs", "\tpc, lr, $imm",
3850 [(ARMintretflag imm0_255:$imm)]>,
3851 Requires<[IsThumb2,IsNotMClass]> {
3852 let Inst{31-8} = 0b111100111101111010001111;
3855 let Inst{7-0} = imm;
3858 // Hypervisor Call is a system instruction.
3860 def t2HVC : T2XI <(outs), (ins imm0_65535:$imm16), IIC_Br, "hvc.w\t$imm16", []>,
3861 Requires<[IsThumb2, HasVirtualization]>, Sched<[WriteBr]> {
3863 let Inst{31-20} = 0b111101111110;
3864 let Inst{19-16} = imm16{15-12};
3865 let Inst{15-12} = 0b1000;
3866 let Inst{11-0} = imm16{11-0};
3870 // Alias for HVC without the ".w" optional width specifier
3871 def : t2InstAlias<"hvc\t$imm16", (t2HVC imm0_65535:$imm16)>;
3873 // ERET - Return from exception in Hypervisor mode.
3874 // B9.3.3, B9.3.20: ERET is an alias for "SUBS PC, LR, #0" in an implementation that
3875 // includes virtualization extensions.
3876 def t2ERET : InstAlias<"eret${p}", (t2SUBS_PC_LR 0, pred:$p), 1>,
3877 Requires<[IsThumb2, HasVirtualization]>;
3879 //===----------------------------------------------------------------------===//
3880 // Non-Instruction Patterns
3883 // 32-bit immediate using movw + movt.
3884 // This is a single pseudo instruction to make it re-materializable.
3885 // FIXME: Remove this when we can do generalized remat.
3886 let isReMaterializable = 1, isMoveImm = 1 in
3887 def t2MOVi32imm : PseudoInst<(outs rGPR:$dst), (ins i32imm:$src), IIC_iMOVix2,
3888 [(set rGPR:$dst, (i32 imm:$src))]>,
3889 Requires<[IsThumb, UseMovt]>;
3891 // Pseudo instruction that combines movw + movt + add pc (if pic).
3892 // It also makes it possible to rematerialize the instructions.
3893 // FIXME: Remove this when we can do generalized remat and when machine licm
3894 // can properly the instructions.
3895 let isReMaterializable = 1 in {
3896 def t2MOV_ga_pcrel : PseudoInst<(outs rGPR:$dst), (ins i32imm:$addr),
3898 [(set rGPR:$dst, (ARMWrapperPIC tglobaladdr:$addr))]>,
3899 Requires<[IsThumb, HasV8MBaseline, UseMovtInPic]>;
3903 def : T2Pat<(ARMWrapperPIC tglobaltlsaddr :$dst),
3904 (t2MOV_ga_pcrel tglobaltlsaddr:$dst)>,
3905 Requires<[IsThumb2, UseMovtInPic]>;
3906 def : T2Pat<(ARMWrapper tglobaltlsaddr:$dst),
3907 (t2MOVi32imm tglobaltlsaddr:$dst)>,
3908 Requires<[IsThumb2, UseMovt]>;
3910 // ConstantPool, GlobalAddress, and JumpTable
3911 def : T2Pat<(ARMWrapper tconstpool :$dst), (t2LEApcrel tconstpool :$dst)>;
3912 def : T2Pat<(ARMWrapper texternalsym :$dst), (t2MOVi32imm texternalsym :$dst)>,
3913 Requires<[IsThumb, HasV8MBaseline, UseMovt]>;
3914 def : T2Pat<(ARMWrapper tglobaladdr :$dst), (t2MOVi32imm tglobaladdr :$dst)>,
3915 Requires<[IsThumb, HasV8MBaseline, UseMovt]>;
3917 def : T2Pat<(ARMWrapperJT tjumptable:$dst), (t2LEApcrelJT tjumptable:$dst)>;
3919 // Pseudo instruction that combines ldr from constpool and add pc. This should
3920 // be expanded into two instructions late to allow if-conversion and
3922 let canFoldAsLoad = 1, isReMaterializable = 1 in
3923 def t2LDRpci_pic : PseudoInst<(outs rGPR:$dst), (ins i32imm:$addr, pclabel:$cp),
3925 [(set rGPR:$dst, (ARMpic_add (load (ARMWrapper tconstpool:$addr)),
3927 Requires<[IsThumb2]>;
3929 // Pseudo isntruction that combines movs + predicated rsbmi
3930 // to implement integer ABS
3931 let usesCustomInserter = 1, Defs = [CPSR] in {
3932 def t2ABS : PseudoInst<(outs rGPR:$dst), (ins rGPR:$src),
3933 NoItinerary, []>, Requires<[IsThumb2]>;
3936 //===----------------------------------------------------------------------===//
3937 // Coprocessor load/store -- for disassembly only
3939 class T2CI<bits<4> op31_28, dag oops, dag iops, string opc, string asm, list<dag> pattern>
3940 : T2I<oops, iops, NoItinerary, opc, asm, pattern> {
3941 let Inst{31-28} = op31_28;
3942 let Inst{27-25} = 0b110;
3945 multiclass t2LdStCop<bits<4> op31_28, bit load, bit Dbit, string asm, list<dag> pattern> {
3946 def _OFFSET : T2CI<op31_28,
3947 (outs), (ins p_imm:$cop, c_imm:$CRd, addrmode5:$addr),
3948 asm, "\t$cop, $CRd, $addr", pattern> {
3952 let Inst{24} = 1; // P = 1
3953 let Inst{23} = addr{8};
3954 let Inst{22} = Dbit;
3955 let Inst{21} = 0; // W = 0
3956 let Inst{20} = load;
3957 let Inst{19-16} = addr{12-9};
3958 let Inst{15-12} = CRd;
3959 let Inst{11-8} = cop;
3960 let Inst{7-0} = addr{7-0};
3961 let DecoderMethod = "DecodeCopMemInstruction";
3963 def _PRE : T2CI<op31_28,
3964 (outs), (ins p_imm:$cop, c_imm:$CRd, addrmode5_pre:$addr),
3965 asm, "\t$cop, $CRd, $addr!", []> {
3969 let Inst{24} = 1; // P = 1
3970 let Inst{23} = addr{8};
3971 let Inst{22} = Dbit;
3972 let Inst{21} = 1; // W = 1
3973 let Inst{20} = load;
3974 let Inst{19-16} = addr{12-9};
3975 let Inst{15-12} = CRd;
3976 let Inst{11-8} = cop;
3977 let Inst{7-0} = addr{7-0};
3978 let DecoderMethod = "DecodeCopMemInstruction";
3980 def _POST: T2CI<op31_28,
3981 (outs), (ins p_imm:$cop, c_imm:$CRd, addr_offset_none:$addr,
3982 postidx_imm8s4:$offset),
3983 asm, "\t$cop, $CRd, $addr, $offset", []> {
3988 let Inst{24} = 0; // P = 0
3989 let Inst{23} = offset{8};
3990 let Inst{22} = Dbit;
3991 let Inst{21} = 1; // W = 1
3992 let Inst{20} = load;
3993 let Inst{19-16} = addr;
3994 let Inst{15-12} = CRd;
3995 let Inst{11-8} = cop;
3996 let Inst{7-0} = offset{7-0};
3997 let DecoderMethod = "DecodeCopMemInstruction";
3999 def _OPTION : T2CI<op31_28, (outs),
4000 (ins p_imm:$cop, c_imm:$CRd, addr_offset_none:$addr,
4001 coproc_option_imm:$option),
4002 asm, "\t$cop, $CRd, $addr, $option", []> {
4007 let Inst{24} = 0; // P = 0
4008 let Inst{23} = 1; // U = 1
4009 let Inst{22} = Dbit;
4010 let Inst{21} = 0; // W = 0
4011 let Inst{20} = load;
4012 let Inst{19-16} = addr;
4013 let Inst{15-12} = CRd;
4014 let Inst{11-8} = cop;
4015 let Inst{7-0} = option;
4016 let DecoderMethod = "DecodeCopMemInstruction";
4020 let DecoderNamespace = "Thumb2CoProc" in {
4021 defm t2LDC : t2LdStCop<0b1110, 1, 0, "ldc", [(int_arm_ldc imm:$cop, imm:$CRd, addrmode5:$addr)]>;
4022 defm t2LDCL : t2LdStCop<0b1110, 1, 1, "ldcl", [(int_arm_ldcl imm:$cop, imm:$CRd, addrmode5:$addr)]>;
4023 defm t2LDC2 : t2LdStCop<0b1111, 1, 0, "ldc2", [(int_arm_ldc2 imm:$cop, imm:$CRd, addrmode5:$addr)]>, Requires<[PreV8,IsThumb2]>;
4024 defm t2LDC2L : t2LdStCop<0b1111, 1, 1, "ldc2l", [(int_arm_ldc2l imm:$cop, imm:$CRd, addrmode5:$addr)]>, Requires<[PreV8,IsThumb2]>;
4026 defm t2STC : t2LdStCop<0b1110, 0, 0, "stc", [(int_arm_stc imm:$cop, imm:$CRd, addrmode5:$addr)]>;
4027 defm t2STCL : t2LdStCop<0b1110, 0, 1, "stcl", [(int_arm_stcl imm:$cop, imm:$CRd, addrmode5:$addr)]>;
4028 defm t2STC2 : t2LdStCop<0b1111, 0, 0, "stc2", [(int_arm_stc2 imm:$cop, imm:$CRd, addrmode5:$addr)]>, Requires<[PreV8,IsThumb2]>;
4029 defm t2STC2L : t2LdStCop<0b1111, 0, 1, "stc2l", [(int_arm_stc2l imm:$cop, imm:$CRd, addrmode5:$addr)]>, Requires<[PreV8,IsThumb2]>;
4033 //===----------------------------------------------------------------------===//
4034 // Move between special register and ARM core register -- for disassembly only
4036 // Move to ARM core register from Special Register
4040 // A/R class can only move from CPSR or SPSR.
4041 def t2MRS_AR : T2I<(outs GPR:$Rd), (ins), NoItinerary, "mrs", "\t$Rd, apsr",
4042 []>, Requires<[IsThumb2,IsNotMClass]> {
4044 let Inst{31-12} = 0b11110011111011111000;
4045 let Inst{11-8} = Rd;
4046 let Inst{7-0} = 0b00000000;
4049 def : t2InstAlias<"mrs${p} $Rd, cpsr", (t2MRS_AR GPR:$Rd, pred:$p)>;
4051 def t2MRSsys_AR: T2I<(outs GPR:$Rd), (ins), NoItinerary, "mrs", "\t$Rd, spsr",
4052 []>, Requires<[IsThumb2,IsNotMClass]> {
4054 let Inst{31-12} = 0b11110011111111111000;
4055 let Inst{11-8} = Rd;
4056 let Inst{7-0} = 0b00000000;
4059 def t2MRSbanked : T2I<(outs rGPR:$Rd), (ins banked_reg:$banked),
4060 NoItinerary, "mrs", "\t$Rd, $banked", []>,
4061 Requires<[IsThumb, HasVirtualization]> {
4065 let Inst{31-21} = 0b11110011111;
4066 let Inst{20} = banked{5}; // R bit
4067 let Inst{19-16} = banked{3-0};
4068 let Inst{15-12} = 0b1000;
4069 let Inst{11-8} = Rd;
4070 let Inst{7-5} = 0b001;
4071 let Inst{4} = banked{4};
4072 let Inst{3-0} = 0b0000;
4078 // This MRS has a mask field in bits 7-0 and can take more values than
4079 // the A/R class (a full msr_mask).
4080 def t2MRS_M : T2I<(outs rGPR:$Rd), (ins msr_mask:$SYSm), NoItinerary,
4081 "mrs", "\t$Rd, $SYSm", []>,
4082 Requires<[IsThumb,IsMClass]> {
4085 let Inst{31-12} = 0b11110011111011111000;
4086 let Inst{11-8} = Rd;
4087 let Inst{7-0} = SYSm;
4089 let Unpredictable{20-16} = 0b11111;
4090 let Unpredictable{13} = 0b1;
4094 // Move from ARM core register to Special Register
4098 // No need to have both system and application versions, the encodings are the
4099 // same and the assembly parser has no way to distinguish between them. The mask
4100 // operand contains the special register (R Bit) in bit 4 and bits 3-0 contains
4101 // the mask with the fields to be accessed in the special register.
4102 let Defs = [CPSR] in
4103 def t2MSR_AR : T2I<(outs), (ins msr_mask:$mask, rGPR:$Rn),
4104 NoItinerary, "msr", "\t$mask, $Rn", []>,
4105 Requires<[IsThumb2,IsNotMClass]> {
4108 let Inst{31-21} = 0b11110011100;
4109 let Inst{20} = mask{4}; // R Bit
4110 let Inst{19-16} = Rn;
4111 let Inst{15-12} = 0b1000;
4112 let Inst{11-8} = mask{3-0};
4116 // However, the MSR (banked register) system instruction (ARMv7VE) *does* have a
4117 // separate encoding (distinguished by bit 5.
4118 def t2MSRbanked : T2I<(outs), (ins banked_reg:$banked, rGPR:$Rn),
4119 NoItinerary, "msr", "\t$banked, $Rn", []>,
4120 Requires<[IsThumb, HasVirtualization]> {
4124 let Inst{31-21} = 0b11110011100;
4125 let Inst{20} = banked{5}; // R bit
4126 let Inst{19-16} = Rn;
4127 let Inst{15-12} = 0b1000;
4128 let Inst{11-8} = banked{3-0};
4129 let Inst{7-5} = 0b001;
4130 let Inst{4} = banked{4};
4131 let Inst{3-0} = 0b0000;
4137 // Move from ARM core register to Special Register
4138 let Defs = [CPSR] in
4139 def t2MSR_M : T2I<(outs), (ins msr_mask:$SYSm, rGPR:$Rn),
4140 NoItinerary, "msr", "\t$SYSm, $Rn", []>,
4141 Requires<[IsThumb,IsMClass]> {
4144 let Inst{31-21} = 0b11110011100;
4146 let Inst{19-16} = Rn;
4147 let Inst{15-12} = 0b1000;
4148 let Inst{11-10} = SYSm{11-10};
4149 let Inst{9-8} = 0b00;
4150 let Inst{7-0} = SYSm{7-0};
4152 let Unpredictable{20} = 0b1;
4153 let Unpredictable{13} = 0b1;
4154 let Unpredictable{9-8} = 0b11;
4158 //===----------------------------------------------------------------------===//
4159 // Move between coprocessor and ARM core register
4162 class t2MovRCopro<bits<4> Op, string opc, bit direction, dag oops, dag iops,
4164 : T2Cop<Op, oops, iops, opc, "\t$cop, $opc1, $Rt, $CRn, $CRm, $opc2",
4166 let Inst{27-24} = 0b1110;
4167 let Inst{20} = direction;
4177 let Inst{15-12} = Rt;
4178 let Inst{11-8} = cop;
4179 let Inst{23-21} = opc1;
4180 let Inst{7-5} = opc2;
4181 let Inst{3-0} = CRm;
4182 let Inst{19-16} = CRn;
4184 let DecoderNamespace = "Thumb2CoProc";
4187 class t2MovRRCopro<bits<4> Op, string opc, bit direction, dag oops, dag iops,
4188 list<dag> pattern = []>
4189 : T2Cop<Op, oops, iops, opc, "\t$cop, $opc1, $Rt, $Rt2, $CRm", pattern> {
4190 let Inst{27-24} = 0b1100;
4191 let Inst{23-21} = 0b010;
4192 let Inst{20} = direction;
4200 let Inst{15-12} = Rt;
4201 let Inst{19-16} = Rt2;
4202 let Inst{11-8} = cop;
4203 let Inst{7-4} = opc1;
4204 let Inst{3-0} = CRm;
4206 let DecoderNamespace = "Thumb2CoProc";
4209 /* from ARM core register to coprocessor */
4210 def t2MCR : t2MovRCopro<0b1110, "mcr", 0,
4212 (ins p_imm:$cop, imm0_7:$opc1, GPR:$Rt, c_imm:$CRn,
4213 c_imm:$CRm, imm0_7:$opc2),
4214 [(int_arm_mcr imm:$cop, imm:$opc1, GPR:$Rt, imm:$CRn,
4215 imm:$CRm, imm:$opc2)]>,
4216 ComplexDeprecationPredicate<"MCR">;
4217 def : t2InstAlias<"mcr${p} $cop, $opc1, $Rt, $CRn, $CRm",
4218 (t2MCR p_imm:$cop, imm0_7:$opc1, GPR:$Rt, c_imm:$CRn,
4219 c_imm:$CRm, 0, pred:$p)>;
4220 def t2MCR2 : t2MovRCopro<0b1111, "mcr2", 0,
4221 (outs), (ins p_imm:$cop, imm0_7:$opc1, GPR:$Rt, c_imm:$CRn,
4222 c_imm:$CRm, imm0_7:$opc2),
4223 [(int_arm_mcr2 imm:$cop, imm:$opc1, GPR:$Rt, imm:$CRn,
4224 imm:$CRm, imm:$opc2)]> {
4225 let Predicates = [IsThumb2, PreV8];
4227 def : t2InstAlias<"mcr2${p} $cop, $opc1, $Rt, $CRn, $CRm",
4228 (t2MCR2 p_imm:$cop, imm0_7:$opc1, GPR:$Rt, c_imm:$CRn,
4229 c_imm:$CRm, 0, pred:$p)>;
4231 /* from coprocessor to ARM core register */
4232 def t2MRC : t2MovRCopro<0b1110, "mrc", 1,
4233 (outs GPRwithAPSR:$Rt), (ins p_imm:$cop, imm0_7:$opc1, c_imm:$CRn,
4234 c_imm:$CRm, imm0_7:$opc2), []>;
4235 def : t2InstAlias<"mrc${p} $cop, $opc1, $Rt, $CRn, $CRm",
4236 (t2MRC GPRwithAPSR:$Rt, p_imm:$cop, imm0_7:$opc1, c_imm:$CRn,
4237 c_imm:$CRm, 0, pred:$p)>;
4239 def t2MRC2 : t2MovRCopro<0b1111, "mrc2", 1,
4240 (outs GPRwithAPSR:$Rt), (ins p_imm:$cop, imm0_7:$opc1, c_imm:$CRn,
4241 c_imm:$CRm, imm0_7:$opc2), []> {
4242 let Predicates = [IsThumb2, PreV8];
4244 def : t2InstAlias<"mrc2${p} $cop, $opc1, $Rt, $CRn, $CRm",
4245 (t2MRC2 GPRwithAPSR:$Rt, p_imm:$cop, imm0_7:$opc1, c_imm:$CRn,
4246 c_imm:$CRm, 0, pred:$p)>;
4248 def : T2v6Pat<(int_arm_mrc imm:$cop, imm:$opc1, imm:$CRn, imm:$CRm, imm:$opc2),
4249 (t2MRC imm:$cop, imm:$opc1, imm:$CRn, imm:$CRm, imm:$opc2)>;
4251 def : T2v6Pat<(int_arm_mrc2 imm:$cop, imm:$opc1, imm:$CRn, imm:$CRm, imm:$opc2),
4252 (t2MRC2 imm:$cop, imm:$opc1, imm:$CRn, imm:$CRm, imm:$opc2)>;
4255 /* from ARM core register to coprocessor */
4256 def t2MCRR : t2MovRRCopro<0b1110, "mcrr", 0, (outs),
4257 (ins p_imm:$cop, imm0_15:$opc1, GPR:$Rt, GPR:$Rt2,
4259 [(int_arm_mcrr imm:$cop, imm:$opc1, GPR:$Rt, GPR:$Rt2,
4261 def t2MCRR2 : t2MovRRCopro<0b1111, "mcrr2", 0, (outs),
4262 (ins p_imm:$cop, imm0_15:$opc1, GPR:$Rt, GPR:$Rt2,
4264 [(int_arm_mcrr2 imm:$cop, imm:$opc1, GPR:$Rt,
4265 GPR:$Rt2, imm:$CRm)]> {
4266 let Predicates = [IsThumb2, PreV8];
4269 /* from coprocessor to ARM core register */
4270 def t2MRRC : t2MovRRCopro<0b1110, "mrrc", 1, (outs GPR:$Rt, GPR:$Rt2),
4271 (ins p_imm:$cop, imm0_15:$opc1, c_imm:$CRm)>;
4273 def t2MRRC2 : t2MovRRCopro<0b1111, "mrrc2", 1, (outs GPR:$Rt, GPR:$Rt2),
4274 (ins p_imm:$cop, imm0_15:$opc1, c_imm:$CRm)> {
4275 let Predicates = [IsThumb2, PreV8];
4278 //===----------------------------------------------------------------------===//
4279 // Other Coprocessor Instructions.
4282 def t2CDP : T2Cop<0b1110, (outs), (ins p_imm:$cop, imm0_15:$opc1,
4283 c_imm:$CRd, c_imm:$CRn, c_imm:$CRm, imm0_7:$opc2),
4284 "cdp", "\t$cop, $opc1, $CRd, $CRn, $CRm, $opc2",
4285 [(int_arm_cdp imm:$cop, imm:$opc1, imm:$CRd, imm:$CRn,
4286 imm:$CRm, imm:$opc2)]> {
4287 let Inst{27-24} = 0b1110;
4296 let Inst{3-0} = CRm;
4298 let Inst{7-5} = opc2;
4299 let Inst{11-8} = cop;
4300 let Inst{15-12} = CRd;
4301 let Inst{19-16} = CRn;
4302 let Inst{23-20} = opc1;
4304 let Predicates = [IsThumb2, PreV8];
4305 let DecoderNamespace = "Thumb2CoProc";
4308 def t2CDP2 : T2Cop<0b1111, (outs), (ins p_imm:$cop, imm0_15:$opc1,
4309 c_imm:$CRd, c_imm:$CRn, c_imm:$CRm, imm0_7:$opc2),
4310 "cdp2", "\t$cop, $opc1, $CRd, $CRn, $CRm, $opc2",
4311 [(int_arm_cdp2 imm:$cop, imm:$opc1, imm:$CRd, imm:$CRn,
4312 imm:$CRm, imm:$opc2)]> {
4313 let Inst{27-24} = 0b1110;
4322 let Inst{3-0} = CRm;
4324 let Inst{7-5} = opc2;
4325 let Inst{11-8} = cop;
4326 let Inst{15-12} = CRd;
4327 let Inst{19-16} = CRn;
4328 let Inst{23-20} = opc1;
4330 let Predicates = [IsThumb2, PreV8];
4331 let DecoderNamespace = "Thumb2CoProc";
4336 //===----------------------------------------------------------------------===//
4337 // ARMv8.1 Privilege Access Never extension
4341 def t2SETPAN : T1I<(outs), (ins imm0_1:$imm), NoItinerary, "setpan\t$imm", []>,
4342 T1Misc<0b0110000>, Requires<[IsThumb2, HasV8, HasV8_1a]> {
4347 let Inst{2-0} = 0b000;
4349 let Unpredictable{4} = 0b1;
4350 let Unpredictable{2-0} = 0b111;
4353 //===----------------------------------------------------------------------===//
4354 // ARMv8-M Security Extensions instructions
4357 let hasSideEffects = 1 in
4358 def t2SG : T2I<(outs), (ins), NoItinerary, "sg", "", []>,
4359 Requires<[Has8MSecExt]> {
4360 let Inst = 0xe97fe97f;
4363 class T2TT<bits<2> at, string asm, list<dag> pattern>
4364 : T2I<(outs rGPR:$Rt), (ins GPRnopc:$Rn), NoItinerary, asm, "\t$Rt, $Rn",
4369 let Inst{31-20} = 0b111010000100;
4370 let Inst{19-16} = Rn;
4371 let Inst{15-12} = 0b1111;
4372 let Inst{11-8} = Rt;
4374 let Inst{5-0} = 0b000000;
4376 let Unpredictable{5-0} = 0b111111;
4379 def t2TT : T2TT<0b00, "tt", []>, Requires<[IsThumb,Has8MSecExt]>;
4380 def t2TTT : T2TT<0b01, "ttt", []>, Requires<[IsThumb,Has8MSecExt]>;
4381 def t2TTA : T2TT<0b10, "tta", []>, Requires<[IsThumb,Has8MSecExt]>;
4382 def t2TTAT : T2TT<0b11, "ttat", []>, Requires<[IsThumb,Has8MSecExt]>;
4384 //===----------------------------------------------------------------------===//
4385 // Non-Instruction Patterns
4388 // SXT/UXT with no rotate
4389 let AddedComplexity = 16 in {
4390 def : T2Pat<(and rGPR:$Rm, 0x000000FF), (t2UXTB rGPR:$Rm, 0)>,
4391 Requires<[IsThumb2]>;
4392 def : T2Pat<(and rGPR:$Rm, 0x0000FFFF), (t2UXTH rGPR:$Rm, 0)>,
4393 Requires<[IsThumb2]>;
4394 def : T2Pat<(and rGPR:$Rm, 0x00FF00FF), (t2UXTB16 rGPR:$Rm, 0)>,
4395 Requires<[HasDSP, IsThumb2]>;
4396 def : T2Pat<(add rGPR:$Rn, (and rGPR:$Rm, 0x00FF)),
4397 (t2UXTAB rGPR:$Rn, rGPR:$Rm, 0)>,
4398 Requires<[HasDSP, IsThumb2]>;
4399 def : T2Pat<(add rGPR:$Rn, (and rGPR:$Rm, 0xFFFF)),
4400 (t2UXTAH rGPR:$Rn, rGPR:$Rm, 0)>,
4401 Requires<[HasDSP, IsThumb2]>;
4404 def : T2Pat<(sext_inreg rGPR:$Src, i8), (t2SXTB rGPR:$Src, 0)>,
4405 Requires<[IsThumb2]>;
4406 def : T2Pat<(sext_inreg rGPR:$Src, i16), (t2SXTH rGPR:$Src, 0)>,
4407 Requires<[IsThumb2]>;
4408 def : T2Pat<(add rGPR:$Rn, (sext_inreg rGPR:$Rm, i8)),
4409 (t2SXTAB rGPR:$Rn, rGPR:$Rm, 0)>,
4410 Requires<[HasDSP, IsThumb2]>;
4411 def : T2Pat<(add rGPR:$Rn, (sext_inreg rGPR:$Rm, i16)),
4412 (t2SXTAH rGPR:$Rn, rGPR:$Rm, 0)>,
4413 Requires<[HasDSP, IsThumb2]>;
4415 // Atomic load/store patterns
4416 def : T2Pat<(atomic_load_8 t2addrmode_imm12:$addr),
4417 (t2LDRBi12 t2addrmode_imm12:$addr)>;
4418 def : T2Pat<(atomic_load_8 t2addrmode_negimm8:$addr),
4419 (t2LDRBi8 t2addrmode_negimm8:$addr)>;
4420 def : T2Pat<(atomic_load_8 t2addrmode_so_reg:$addr),
4421 (t2LDRBs t2addrmode_so_reg:$addr)>;
4422 def : T2Pat<(atomic_load_16 t2addrmode_imm12:$addr),
4423 (t2LDRHi12 t2addrmode_imm12:$addr)>;
4424 def : T2Pat<(atomic_load_16 t2addrmode_negimm8:$addr),
4425 (t2LDRHi8 t2addrmode_negimm8:$addr)>;
4426 def : T2Pat<(atomic_load_16 t2addrmode_so_reg:$addr),
4427 (t2LDRHs t2addrmode_so_reg:$addr)>;
4428 def : T2Pat<(atomic_load_32 t2addrmode_imm12:$addr),
4429 (t2LDRi12 t2addrmode_imm12:$addr)>;
4430 def : T2Pat<(atomic_load_32 t2addrmode_negimm8:$addr),
4431 (t2LDRi8 t2addrmode_negimm8:$addr)>;
4432 def : T2Pat<(atomic_load_32 t2addrmode_so_reg:$addr),
4433 (t2LDRs t2addrmode_so_reg:$addr)>;
4434 def : T2Pat<(atomic_store_8 t2addrmode_imm12:$addr, GPR:$val),
4435 (t2STRBi12 GPR:$val, t2addrmode_imm12:$addr)>;
4436 def : T2Pat<(atomic_store_8 t2addrmode_negimm8:$addr, GPR:$val),
4437 (t2STRBi8 GPR:$val, t2addrmode_negimm8:$addr)>;
4438 def : T2Pat<(atomic_store_8 t2addrmode_so_reg:$addr, GPR:$val),
4439 (t2STRBs GPR:$val, t2addrmode_so_reg:$addr)>;
4440 def : T2Pat<(atomic_store_16 t2addrmode_imm12:$addr, GPR:$val),
4441 (t2STRHi12 GPR:$val, t2addrmode_imm12:$addr)>;
4442 def : T2Pat<(atomic_store_16 t2addrmode_negimm8:$addr, GPR:$val),
4443 (t2STRHi8 GPR:$val, t2addrmode_negimm8:$addr)>;
4444 def : T2Pat<(atomic_store_16 t2addrmode_so_reg:$addr, GPR:$val),
4445 (t2STRHs GPR:$val, t2addrmode_so_reg:$addr)>;
4446 def : T2Pat<(atomic_store_32 t2addrmode_imm12:$addr, GPR:$val),
4447 (t2STRi12 GPR:$val, t2addrmode_imm12:$addr)>;
4448 def : T2Pat<(atomic_store_32 t2addrmode_negimm8:$addr, GPR:$val),
4449 (t2STRi8 GPR:$val, t2addrmode_negimm8:$addr)>;
4450 def : T2Pat<(atomic_store_32 t2addrmode_so_reg:$addr, GPR:$val),
4451 (t2STRs GPR:$val, t2addrmode_so_reg:$addr)>;
4453 let AddedComplexity = 8, Predicates = [IsThumb, HasAcquireRelease, HasV7Clrex] in {
4454 def : Pat<(atomic_load_acquire_8 addr_offset_none:$addr), (t2LDAB addr_offset_none:$addr)>;
4455 def : Pat<(atomic_load_acquire_16 addr_offset_none:$addr), (t2LDAH addr_offset_none:$addr)>;
4456 def : Pat<(atomic_load_acquire_32 addr_offset_none:$addr), (t2LDA addr_offset_none:$addr)>;
4457 def : Pat<(atomic_store_release_8 addr_offset_none:$addr, GPR:$val), (t2STLB GPR:$val, addr_offset_none:$addr)>;
4458 def : Pat<(atomic_store_release_16 addr_offset_none:$addr, GPR:$val), (t2STLH GPR:$val, addr_offset_none:$addr)>;
4459 def : Pat<(atomic_store_release_32 addr_offset_none:$addr, GPR:$val), (t2STL GPR:$val, addr_offset_none:$addr)>;
4463 //===----------------------------------------------------------------------===//
4464 // Assembler aliases
4467 // Aliases for ADC without the ".w" optional width specifier.
4468 def : t2InstAlias<"adc${s}${p} $Rd, $Rn, $Rm",
4469 (t2ADCrr rGPR:$Rd, rGPR:$Rn, rGPR:$Rm, pred:$p, cc_out:$s)>;
4470 def : t2InstAlias<"adc${s}${p} $Rd, $Rn, $ShiftedRm",
4471 (t2ADCrs rGPR:$Rd, rGPR:$Rn, t2_so_reg:$ShiftedRm,
4472 pred:$p, cc_out:$s)>;
4474 // Aliases for SBC without the ".w" optional width specifier.
4475 def : t2InstAlias<"sbc${s}${p} $Rd, $Rn, $Rm",
4476 (t2SBCrr rGPR:$Rd, rGPR:$Rn, rGPR:$Rm, pred:$p, cc_out:$s)>;
4477 def : t2InstAlias<"sbc${s}${p} $Rd, $Rn, $ShiftedRm",
4478 (t2SBCrs rGPR:$Rd, rGPR:$Rn, t2_so_reg:$ShiftedRm,
4479 pred:$p, cc_out:$s)>;
4481 // Aliases for ADD without the ".w" optional width specifier.
4482 def : t2InstAlias<"add${s}${p} $Rd, $Rn, $imm",
4483 (t2ADDri GPRnopc:$Rd, GPRnopc:$Rn, t2_so_imm:$imm, pred:$p,
4485 def : t2InstAlias<"add${p} $Rd, $Rn, $imm",
4486 (t2ADDri12 GPRnopc:$Rd, GPR:$Rn, imm0_4095:$imm, pred:$p)>;
4487 def : t2InstAlias<"add${s}${p} $Rd, $Rn, $Rm",
4488 (t2ADDrr GPRnopc:$Rd, GPRnopc:$Rn, rGPR:$Rm, pred:$p, cc_out:$s)>;
4489 def : t2InstAlias<"add${s}${p} $Rd, $Rn, $ShiftedRm",
4490 (t2ADDrs GPRnopc:$Rd, GPRnopc:$Rn, t2_so_reg:$ShiftedRm,
4491 pred:$p, cc_out:$s)>;
4492 // ... and with the destination and source register combined.
4493 def : t2InstAlias<"add${s}${p} $Rdn, $imm",
4494 (t2ADDri GPRnopc:$Rdn, GPRnopc:$Rdn, t2_so_imm:$imm, pred:$p, cc_out:$s)>;
4495 def : t2InstAlias<"add${p} $Rdn, $imm",
4496 (t2ADDri12 GPRnopc:$Rdn, GPRnopc:$Rdn, imm0_4095:$imm, pred:$p)>;
4497 def : t2InstAlias<"add${s}${p} $Rdn, $Rm",
4498 (t2ADDrr GPRnopc:$Rdn, GPRnopc:$Rdn, rGPR:$Rm, pred:$p, cc_out:$s)>;
4499 def : t2InstAlias<"add${s}${p} $Rdn, $ShiftedRm",
4500 (t2ADDrs GPRnopc:$Rdn, GPRnopc:$Rdn, t2_so_reg:$ShiftedRm,
4501 pred:$p, cc_out:$s)>;
4503 // add w/ negative immediates is just a sub.
4504 def : t2InstSubst<"add${s}${p} $Rd, $Rn, $imm",
4505 (t2SUBri GPRnopc:$Rd, GPRnopc:$Rn, t2_so_imm_neg:$imm, pred:$p,
4507 def : t2InstSubst<"add${p} $Rd, $Rn, $imm",
4508 (t2SUBri12 GPRnopc:$Rd, GPR:$Rn, imm0_4095_neg:$imm, pred:$p)>;
4509 def : t2InstSubst<"add${s}${p} $Rdn, $imm",
4510 (t2SUBri GPRnopc:$Rdn, GPRnopc:$Rdn, t2_so_imm_neg:$imm, pred:$p,
4512 def : t2InstSubst<"add${p} $Rdn, $imm",
4513 (t2SUBri12 GPRnopc:$Rdn, GPRnopc:$Rdn, imm0_4095_neg:$imm, pred:$p)>;
4515 def : t2InstSubst<"add${s}${p}.w $Rd, $Rn, $imm",
4516 (t2SUBri GPRnopc:$Rd, GPRnopc:$Rn, t2_so_imm_neg:$imm, pred:$p,
4518 def : t2InstSubst<"addw${p} $Rd, $Rn, $imm",
4519 (t2SUBri12 GPRnopc:$Rd, GPR:$Rn, imm0_4095_neg:$imm, pred:$p)>;
4520 def : t2InstSubst<"add${s}${p}.w $Rdn, $imm",
4521 (t2SUBri GPRnopc:$Rdn, GPRnopc:$Rdn, t2_so_imm_neg:$imm, pred:$p,
4523 def : t2InstSubst<"addw${p} $Rdn, $imm",
4524 (t2SUBri12 GPRnopc:$Rdn, GPRnopc:$Rdn, imm0_4095_neg:$imm, pred:$p)>;
4527 // Aliases for SUB without the ".w" optional width specifier.
4528 def : t2InstAlias<"sub${s}${p} $Rd, $Rn, $imm",
4529 (t2SUBri GPRnopc:$Rd, GPRnopc:$Rn, t2_so_imm:$imm, pred:$p, cc_out:$s)>;
4530 def : t2InstAlias<"sub${p} $Rd, $Rn, $imm",
4531 (t2SUBri12 GPRnopc:$Rd, GPR:$Rn, imm0_4095:$imm, pred:$p)>;
4532 def : t2InstAlias<"sub${s}${p} $Rd, $Rn, $Rm",
4533 (t2SUBrr GPRnopc:$Rd, GPRnopc:$Rn, rGPR:$Rm, pred:$p, cc_out:$s)>;
4534 def : t2InstAlias<"sub${s}${p} $Rd, $Rn, $ShiftedRm",
4535 (t2SUBrs GPRnopc:$Rd, GPRnopc:$Rn, t2_so_reg:$ShiftedRm,
4536 pred:$p, cc_out:$s)>;
4537 // ... and with the destination and source register combined.
4538 def : t2InstAlias<"sub${s}${p} $Rdn, $imm",
4539 (t2SUBri GPRnopc:$Rdn, GPRnopc:$Rdn, t2_so_imm:$imm, pred:$p, cc_out:$s)>;
4540 def : t2InstAlias<"sub${p} $Rdn, $imm",
4541 (t2SUBri12 GPRnopc:$Rdn, GPRnopc:$Rdn, imm0_4095:$imm, pred:$p)>;
4542 def : t2InstAlias<"sub${s}${p}.w $Rdn, $Rm",
4543 (t2SUBrr GPRnopc:$Rdn, GPRnopc:$Rdn, rGPR:$Rm, pred:$p, cc_out:$s)>;
4544 def : t2InstAlias<"sub${s}${p} $Rdn, $Rm",
4545 (t2SUBrr GPRnopc:$Rdn, GPRnopc:$Rdn, rGPR:$Rm, pred:$p, cc_out:$s)>;
4546 def : t2InstAlias<"sub${s}${p} $Rdn, $ShiftedRm",
4547 (t2SUBrs GPRnopc:$Rdn, GPRnopc:$Rdn, t2_so_reg:$ShiftedRm,
4548 pred:$p, cc_out:$s)>;
4550 // Alias for compares without the ".w" optional width specifier.
4551 def : t2InstAlias<"cmn${p} $Rn, $Rm",
4552 (t2CMNzrr GPRnopc:$Rn, rGPR:$Rm, pred:$p)>;
4553 def : t2InstAlias<"teq${p} $Rn, $Rm",
4554 (t2TEQrr GPRnopc:$Rn, rGPR:$Rm, pred:$p)>;
4555 def : t2InstAlias<"tst${p} $Rn, $Rm",
4556 (t2TSTrr GPRnopc:$Rn, rGPR:$Rm, pred:$p)>;
4559 def : InstAlias<"dmb${p}", (t2DMB 0xf, pred:$p), 0>, Requires<[HasDB]>;
4560 def : InstAlias<"dsb${p}", (t2DSB 0xf, pred:$p), 0>, Requires<[HasDB]>;
4561 def : InstAlias<"isb${p}", (t2ISB 0xf, pred:$p), 0>, Requires<[HasDB]>;
4563 // Non-predicable aliases of a predicable DSB: the predicate is (14, 0) where
4564 // 14 = AL (always execute) and 0 = "instruction doesn't read the CPSR".
4565 def : InstAlias<"ssbb", (t2DSB 0x0, 14, 0), 1>, Requires<[HasDB, IsThumb2]>;
4566 def : InstAlias<"pssbb", (t2DSB 0x4, 14, 0), 1>, Requires<[HasDB, IsThumb2]>;
4568 // Armv8-R 'Data Full Barrier'
4569 def : InstAlias<"dfb${p}", (t2DSB 0xc, pred:$p), 1>, Requires<[HasDFB]>;
4571 // Alias for LDR, LDRB, LDRH, LDRSB, and LDRSH without the ".w" optional
4573 def : t2InstAlias<"ldr${p} $Rt, $addr",
4574 (t2LDRi12 GPR:$Rt, t2addrmode_imm12:$addr, pred:$p)>;
4575 def : t2InstAlias<"ldrb${p} $Rt, $addr",
4576 (t2LDRBi12 rGPR:$Rt, t2addrmode_imm12:$addr, pred:$p)>;
4577 def : t2InstAlias<"ldrh${p} $Rt, $addr",
4578 (t2LDRHi12 rGPR:$Rt, t2addrmode_imm12:$addr, pred:$p)>;
4579 def : t2InstAlias<"ldrsb${p} $Rt, $addr",
4580 (t2LDRSBi12 rGPR:$Rt, t2addrmode_imm12:$addr, pred:$p)>;
4581 def : t2InstAlias<"ldrsh${p} $Rt, $addr",
4582 (t2LDRSHi12 rGPR:$Rt, t2addrmode_imm12:$addr, pred:$p)>;
4584 def : t2InstAlias<"ldr${p} $Rt, $addr",
4585 (t2LDRs GPR:$Rt, t2addrmode_so_reg:$addr, pred:$p)>;
4586 def : t2InstAlias<"ldrb${p} $Rt, $addr",
4587 (t2LDRBs rGPR:$Rt, t2addrmode_so_reg:$addr, pred:$p)>;
4588 def : t2InstAlias<"ldrh${p} $Rt, $addr",
4589 (t2LDRHs rGPR:$Rt, t2addrmode_so_reg:$addr, pred:$p)>;
4590 def : t2InstAlias<"ldrsb${p} $Rt, $addr",
4591 (t2LDRSBs rGPR:$Rt, t2addrmode_so_reg:$addr, pred:$p)>;
4592 def : t2InstAlias<"ldrsh${p} $Rt, $addr",
4593 (t2LDRSHs rGPR:$Rt, t2addrmode_so_reg:$addr, pred:$p)>;
4595 def : t2InstAlias<"ldr${p} $Rt, $addr",
4596 (t2LDRpci GPR:$Rt, t2ldrlabel:$addr, pred:$p)>;
4597 def : t2InstAlias<"ldrb${p} $Rt, $addr",
4598 (t2LDRBpci rGPR:$Rt, t2ldrlabel:$addr, pred:$p)>;
4599 def : t2InstAlias<"ldrh${p} $Rt, $addr",
4600 (t2LDRHpci rGPR:$Rt, t2ldrlabel:$addr, pred:$p)>;
4601 def : t2InstAlias<"ldrsb${p} $Rt, $addr",
4602 (t2LDRSBpci rGPR:$Rt, t2ldrlabel:$addr, pred:$p)>;
4603 def : t2InstAlias<"ldrsh${p} $Rt, $addr",
4604 (t2LDRSHpci rGPR:$Rt, t2ldrlabel:$addr, pred:$p)>;
4606 // Alias for MVN with(out) the ".w" optional width specifier.
4607 def : t2InstAlias<"mvn${s}${p}.w $Rd, $imm",
4608 (t2MVNi rGPR:$Rd, t2_so_imm:$imm, pred:$p, cc_out:$s)>;
4609 def : t2InstAlias<"mvn${s}${p} $Rd, $Rm",
4610 (t2MVNr rGPR:$Rd, rGPR:$Rm, pred:$p, cc_out:$s)>;
4611 def : t2InstAlias<"mvn${s}${p} $Rd, $ShiftedRm",
4612 (t2MVNs rGPR:$Rd, t2_so_reg:$ShiftedRm, pred:$p, cc_out:$s)>;
4614 // PKHBT/PKHTB with default shift amount. PKHTB is equivalent to PKHBT with the
4615 // input operands swapped when the shift amount is zero (i.e., unspecified).
4616 def : InstAlias<"pkhbt${p} $Rd, $Rn, $Rm",
4617 (t2PKHBT rGPR:$Rd, rGPR:$Rn, rGPR:$Rm, 0, pred:$p), 0>,
4618 Requires<[HasDSP, IsThumb2]>;
4619 def : InstAlias<"pkhtb${p} $Rd, $Rn, $Rm",
4620 (t2PKHBT rGPR:$Rd, rGPR:$Rm, rGPR:$Rn, 0, pred:$p), 0>,
4621 Requires<[HasDSP, IsThumb2]>;
4623 // PUSH/POP aliases for STM/LDM
4624 def : t2InstAlias<"push${p}.w $regs", (t2STMDB_UPD SP, pred:$p, reglist:$regs)>;
4625 def : t2InstAlias<"push${p} $regs", (t2STMDB_UPD SP, pred:$p, reglist:$regs)>;
4626 def : t2InstAlias<"pop${p}.w $regs", (t2LDMIA_UPD SP, pred:$p, reglist:$regs)>;
4627 def : t2InstAlias<"pop${p} $regs", (t2LDMIA_UPD SP, pred:$p, reglist:$regs)>;
4629 // STMIA/STMIA_UPD aliases w/o the optional .w suffix
4630 def : t2InstAlias<"stm${p} $Rn, $regs",
4631 (t2STMIA GPR:$Rn, pred:$p, reglist:$regs)>;
4632 def : t2InstAlias<"stm${p} $Rn!, $regs",
4633 (t2STMIA_UPD GPR:$Rn, pred:$p, reglist:$regs)>;
4635 // LDMIA/LDMIA_UPD aliases w/o the optional .w suffix
4636 def : t2InstAlias<"ldm${p} $Rn, $regs",
4637 (t2LDMIA GPR:$Rn, pred:$p, reglist:$regs)>;
4638 def : t2InstAlias<"ldm${p} $Rn!, $regs",
4639 (t2LDMIA_UPD GPR:$Rn, pred:$p, reglist:$regs)>;
4641 // STMDB/STMDB_UPD aliases w/ the optional .w suffix
4642 def : t2InstAlias<"stmdb${p}.w $Rn, $regs",
4643 (t2STMDB GPR:$Rn, pred:$p, reglist:$regs)>;
4644 def : t2InstAlias<"stmdb${p}.w $Rn!, $regs",
4645 (t2STMDB_UPD GPR:$Rn, pred:$p, reglist:$regs)>;
4647 // LDMDB/LDMDB_UPD aliases w/ the optional .w suffix
4648 def : t2InstAlias<"ldmdb${p}.w $Rn, $regs",
4649 (t2LDMDB GPR:$Rn, pred:$p, reglist:$regs)>;
4650 def : t2InstAlias<"ldmdb${p}.w $Rn!, $regs",
4651 (t2LDMDB_UPD GPR:$Rn, pred:$p, reglist:$regs)>;
4653 // Alias for REV/REV16/REVSH without the ".w" optional width specifier.
4654 def : t2InstAlias<"rev${p} $Rd, $Rm", (t2REV rGPR:$Rd, rGPR:$Rm, pred:$p)>;
4655 def : t2InstAlias<"rev16${p} $Rd, $Rm", (t2REV16 rGPR:$Rd, rGPR:$Rm, pred:$p)>;
4656 def : t2InstAlias<"revsh${p} $Rd, $Rm", (t2REVSH rGPR:$Rd, rGPR:$Rm, pred:$p)>;
4659 // Alias for RSB without the ".w" optional width specifier, and with optional
4660 // implied destination register.
4661 def : t2InstAlias<"rsb${s}${p} $Rd, $Rn, $imm",
4662 (t2RSBri rGPR:$Rd, rGPR:$Rn, t2_so_imm:$imm, pred:$p, cc_out:$s)>;
4663 def : t2InstAlias<"rsb${s}${p} $Rdn, $imm",
4664 (t2RSBri rGPR:$Rdn, rGPR:$Rdn, t2_so_imm:$imm, pred:$p, cc_out:$s)>;
4665 def : t2InstAlias<"rsb${s}${p} $Rdn, $Rm",
4666 (t2RSBrr rGPR:$Rdn, rGPR:$Rdn, rGPR:$Rm, pred:$p, cc_out:$s)>;
4667 def : t2InstAlias<"rsb${s}${p} $Rdn, $ShiftedRm",
4668 (t2RSBrs rGPR:$Rdn, rGPR:$Rdn, t2_so_reg:$ShiftedRm, pred:$p,
4671 // SSAT/USAT optional shift operand.
4672 def : t2InstAlias<"ssat${p} $Rd, $sat_imm, $Rn",
4673 (t2SSAT rGPR:$Rd, imm1_32:$sat_imm, rGPR:$Rn, 0, pred:$p)>;
4674 def : t2InstAlias<"usat${p} $Rd, $sat_imm, $Rn",
4675 (t2USAT rGPR:$Rd, imm0_31:$sat_imm, rGPR:$Rn, 0, pred:$p)>;
4677 // STM w/o the .w suffix.
4678 def : t2InstAlias<"stm${p} $Rn, $regs",
4679 (t2STMIA GPR:$Rn, pred:$p, reglist:$regs)>;
4681 // Alias for STR, STRB, and STRH without the ".w" optional
4683 def : t2InstAlias<"str${p} $Rt, $addr",
4684 (t2STRi12 GPR:$Rt, t2addrmode_imm12:$addr, pred:$p)>;
4685 def : t2InstAlias<"strb${p} $Rt, $addr",
4686 (t2STRBi12 rGPR:$Rt, t2addrmode_imm12:$addr, pred:$p)>;
4687 def : t2InstAlias<"strh${p} $Rt, $addr",
4688 (t2STRHi12 rGPR:$Rt, t2addrmode_imm12:$addr, pred:$p)>;
4690 def : t2InstAlias<"str${p} $Rt, $addr",
4691 (t2STRs GPR:$Rt, t2addrmode_so_reg:$addr, pred:$p)>;
4692 def : t2InstAlias<"strb${p} $Rt, $addr",
4693 (t2STRBs rGPR:$Rt, t2addrmode_so_reg:$addr, pred:$p)>;
4694 def : t2InstAlias<"strh${p} $Rt, $addr",
4695 (t2STRHs rGPR:$Rt, t2addrmode_so_reg:$addr, pred:$p)>;
4697 // Extend instruction optional rotate operand.
4698 def : InstAlias<"sxtab${p} $Rd, $Rn, $Rm",
4699 (t2SXTAB rGPR:$Rd, rGPR:$Rn, rGPR:$Rm, 0, pred:$p), 0>,
4700 Requires<[HasDSP, IsThumb2]>;
4701 def : InstAlias<"sxtah${p} $Rd, $Rn, $Rm",
4702 (t2SXTAH rGPR:$Rd, rGPR:$Rn, rGPR:$Rm, 0, pred:$p), 0>,
4703 Requires<[HasDSP, IsThumb2]>;
4704 def : InstAlias<"sxtab16${p} $Rd, $Rn, $Rm",
4705 (t2SXTAB16 rGPR:$Rd, rGPR:$Rn, rGPR:$Rm, 0, pred:$p), 0>,
4706 Requires<[HasDSP, IsThumb2]>;
4707 def : InstAlias<"sxtb16${p} $Rd, $Rm",
4708 (t2SXTB16 rGPR:$Rd, rGPR:$Rm, 0, pred:$p), 0>,
4709 Requires<[HasDSP, IsThumb2]>;
4711 def : t2InstAlias<"sxtb${p} $Rd, $Rm",
4712 (t2SXTB rGPR:$Rd, rGPR:$Rm, 0, pred:$p)>;
4713 def : t2InstAlias<"sxth${p} $Rd, $Rm",
4714 (t2SXTH rGPR:$Rd, rGPR:$Rm, 0, pred:$p)>;
4715 def : t2InstAlias<"sxtb${p}.w $Rd, $Rm",
4716 (t2SXTB rGPR:$Rd, rGPR:$Rm, 0, pred:$p)>;
4717 def : t2InstAlias<"sxth${p}.w $Rd, $Rm",
4718 (t2SXTH rGPR:$Rd, rGPR:$Rm, 0, pred:$p)>;
4720 def : InstAlias<"uxtab${p} $Rd, $Rn, $Rm",
4721 (t2UXTAB rGPR:$Rd, rGPR:$Rn, rGPR:$Rm, 0, pred:$p), 0>,
4722 Requires<[HasDSP, IsThumb2]>;
4723 def : InstAlias<"uxtah${p} $Rd, $Rn, $Rm",
4724 (t2UXTAH rGPR:$Rd, rGPR:$Rn, rGPR:$Rm, 0, pred:$p), 0>,
4725 Requires<[HasDSP, IsThumb2]>;
4726 def : InstAlias<"uxtab16${p} $Rd, $Rn, $Rm",
4727 (t2UXTAB16 rGPR:$Rd, rGPR:$Rn, rGPR:$Rm, 0, pred:$p), 0>,
4728 Requires<[HasDSP, IsThumb2]>;
4729 def : InstAlias<"uxtb16${p} $Rd, $Rm",
4730 (t2UXTB16 rGPR:$Rd, rGPR:$Rm, 0, pred:$p), 0>,
4731 Requires<[HasDSP, IsThumb2]>;
4733 def : t2InstAlias<"uxtb${p} $Rd, $Rm",
4734 (t2UXTB rGPR:$Rd, rGPR:$Rm, 0, pred:$p)>;
4735 def : t2InstAlias<"uxth${p} $Rd, $Rm",
4736 (t2UXTH rGPR:$Rd, rGPR:$Rm, 0, pred:$p)>;
4737 def : t2InstAlias<"uxtb${p}.w $Rd, $Rm",
4738 (t2UXTB rGPR:$Rd, rGPR:$Rm, 0, pred:$p)>;
4739 def : t2InstAlias<"uxth${p}.w $Rd, $Rm",
4740 (t2UXTH rGPR:$Rd, rGPR:$Rm, 0, pred:$p)>;
4742 // Extend instruction w/o the ".w" optional width specifier.
4743 def : t2InstAlias<"uxtb${p} $Rd, $Rm$rot",
4744 (t2UXTB rGPR:$Rd, rGPR:$Rm, rot_imm:$rot, pred:$p)>;
4745 def : InstAlias<"uxtb16${p} $Rd, $Rm$rot",
4746 (t2UXTB16 rGPR:$Rd, rGPR:$Rm, rot_imm:$rot, pred:$p), 0>,
4747 Requires<[HasDSP, IsThumb2]>;
4748 def : t2InstAlias<"uxth${p} $Rd, $Rm$rot",
4749 (t2UXTH rGPR:$Rd, rGPR:$Rm, rot_imm:$rot, pred:$p)>;
4751 def : t2InstAlias<"sxtb${p} $Rd, $Rm$rot",
4752 (t2SXTB rGPR:$Rd, rGPR:$Rm, rot_imm:$rot, pred:$p)>;
4753 def : InstAlias<"sxtb16${p} $Rd, $Rm$rot",
4754 (t2SXTB16 rGPR:$Rd, rGPR:$Rm, rot_imm:$rot, pred:$p), 0>,
4755 Requires<[HasDSP, IsThumb2]>;
4756 def : t2InstAlias<"sxth${p} $Rd, $Rm$rot",
4757 (t2SXTH rGPR:$Rd, rGPR:$Rm, rot_imm:$rot, pred:$p)>;
4760 // "mov Rd, t2_so_imm_not" can be handled via "mvn" in assembly, just like
4762 def : t2InstSubst<"mov${p} $Rd, $imm",
4763 (t2MVNi rGPR:$Rd, t2_so_imm_not:$imm, pred:$p, zero_reg)>;
4764 def : t2InstSubst<"mvn${s}${p} $Rd, $imm",
4765 (t2MOVi rGPR:$Rd, t2_so_imm_not:$imm, pred:$p, s_cc_out:$s)>;
4766 // Same for AND <--> BIC
4767 def : t2InstSubst<"bic${s}${p} $Rd, $Rn, $imm",
4768 (t2ANDri rGPR:$Rd, rGPR:$Rn, t2_so_imm_not:$imm,
4769 pred:$p, cc_out:$s)>;
4770 def : t2InstSubst<"bic${s}${p} $Rdn, $imm",
4771 (t2ANDri rGPR:$Rdn, rGPR:$Rdn, t2_so_imm_not:$imm,
4772 pred:$p, cc_out:$s)>;
4773 def : t2InstSubst<"bic${s}${p}.w $Rd, $Rn, $imm",
4774 (t2ANDri rGPR:$Rd, rGPR:$Rn, t2_so_imm_not:$imm,
4775 pred:$p, cc_out:$s)>;
4776 def : t2InstSubst<"bic${s}${p}.w $Rdn, $imm",
4777 (t2ANDri rGPR:$Rdn, rGPR:$Rdn, t2_so_imm_not:$imm,
4778 pred:$p, cc_out:$s)>;
4779 def : t2InstSubst<"and${s}${p} $Rd, $Rn, $imm",
4780 (t2BICri rGPR:$Rd, rGPR:$Rn, t2_so_imm_not:$imm,
4781 pred:$p, cc_out:$s)>;
4782 def : t2InstSubst<"and${s}${p} $Rdn, $imm",
4783 (t2BICri rGPR:$Rdn, rGPR:$Rdn, t2_so_imm_not:$imm,
4784 pred:$p, cc_out:$s)>;
4785 def : t2InstSubst<"and${s}${p}.w $Rd, $Rn, $imm",
4786 (t2BICri rGPR:$Rd, rGPR:$Rn, t2_so_imm_not:$imm,
4787 pred:$p, cc_out:$s)>;
4788 def : t2InstSubst<"and${s}${p}.w $Rdn, $imm",
4789 (t2BICri rGPR:$Rdn, rGPR:$Rdn, t2_so_imm_not:$imm,
4790 pred:$p, cc_out:$s)>;
4792 def : t2InstSubst<"orn${s}${p} $Rd, $Rn, $imm",
4793 (t2ORRri rGPR:$Rd, rGPR:$Rn, t2_so_imm_not:$imm,
4794 pred:$p, cc_out:$s)>;
4795 def : t2InstSubst<"orn${s}${p} $Rdn, $imm",
4796 (t2ORRri rGPR:$Rdn, rGPR:$Rdn, t2_so_imm_not:$imm,
4797 pred:$p, cc_out:$s)>;
4798 def : t2InstSubst<"orr${s}${p} $Rd, $Rn, $imm",
4799 (t2ORNri rGPR:$Rd, rGPR:$Rn, t2_so_imm_not:$imm,
4800 pred:$p, cc_out:$s)>;
4801 def : t2InstSubst<"orr${s}${p} $Rdn, $imm",
4802 (t2ORNri rGPR:$Rdn, rGPR:$Rdn, t2_so_imm_not:$imm,
4803 pred:$p, cc_out:$s)>;
4804 // Likewise, "add Rd, t2_so_imm_neg" -> sub
4805 def : t2InstSubst<"add${s}${p} $Rd, $Rn, $imm",
4806 (t2SUBri GPRnopc:$Rd, GPRnopc:$Rn, t2_so_imm_neg:$imm,
4807 pred:$p, cc_out:$s)>;
4808 def : t2InstSubst<"add${s}${p} $Rd, $imm",
4809 (t2SUBri GPRnopc:$Rd, GPRnopc:$Rd, t2_so_imm_neg:$imm,
4810 pred:$p, cc_out:$s)>;
4811 // Same for CMP <--> CMN via t2_so_imm_neg
4812 def : t2InstSubst<"cmp${p} $Rd, $imm",
4813 (t2CMNri rGPR:$Rd, t2_so_imm_neg:$imm, pred:$p)>;
4814 def : t2InstSubst<"cmn${p} $Rd, $imm",
4815 (t2CMPri rGPR:$Rd, t2_so_imm_neg:$imm, pred:$p)>;
4818 // Wide 'mul' encoding can be specified with only two operands.
4819 def : t2InstAlias<"mul${p} $Rn, $Rm",
4820 (t2MUL rGPR:$Rn, rGPR:$Rm, rGPR:$Rn, pred:$p)>;
4822 // "neg" is and alias for "rsb rd, rn, #0"
4823 def : t2InstAlias<"neg${s}${p} $Rd, $Rm",
4824 (t2RSBri rGPR:$Rd, rGPR:$Rm, 0, pred:$p, cc_out:$s)>;
4826 // MOV so_reg assembler pseudos. InstAlias isn't expressive enough for
4827 // these, unfortunately.
4828 // FIXME: LSL #0 in the shift should allow SP to be used as either the
4829 // source or destination (but not both).
4830 def t2MOVsi: t2AsmPseudo<"mov${p} $Rd, $shift",
4831 (ins rGPR:$Rd, t2_so_reg:$shift, pred:$p)>;
4832 def t2MOVSsi: t2AsmPseudo<"movs${p} $Rd, $shift",
4833 (ins rGPR:$Rd, t2_so_reg:$shift, pred:$p)>;
4835 def t2MOVsr: t2AsmPseudo<"mov${p} $Rd, $shift",
4836 (ins rGPR:$Rd, so_reg_reg:$shift, pred:$p)>;
4837 def t2MOVSsr: t2AsmPseudo<"movs${p} $Rd, $shift",
4838 (ins rGPR:$Rd, so_reg_reg:$shift, pred:$p)>;
4840 // Aliases for the above with the .w qualifier
4841 def : t2InstAlias<"mov${p}.w $Rd, $shift",
4842 (t2MOVsi rGPR:$Rd, t2_so_reg:$shift, pred:$p)>;
4843 def : t2InstAlias<"movs${p}.w $Rd, $shift",
4844 (t2MOVSsi rGPR:$Rd, t2_so_reg:$shift, pred:$p)>;
4845 def : t2InstAlias<"mov${p}.w $Rd, $shift",
4846 (t2MOVsr rGPR:$Rd, so_reg_reg:$shift, pred:$p)>;
4847 def : t2InstAlias<"movs${p}.w $Rd, $shift",
4848 (t2MOVSsr rGPR:$Rd, so_reg_reg:$shift, pred:$p)>;
4850 // ADR w/o the .w suffix
4851 def : t2InstAlias<"adr${p} $Rd, $addr",
4852 (t2ADR rGPR:$Rd, t2adrlabel:$addr, pred:$p)>;
4854 // LDR(literal) w/ alternate [pc, #imm] syntax.
4855 def t2LDRpcrel : t2AsmPseudo<"ldr${p} $Rt, $addr",
4856 (ins GPR:$Rt, t2ldr_pcrel_imm12:$addr, pred:$p)>;
4857 def t2LDRBpcrel : t2AsmPseudo<"ldrb${p} $Rt, $addr",
4858 (ins GPRnopc:$Rt, t2ldr_pcrel_imm12:$addr, pred:$p)>;
4859 def t2LDRHpcrel : t2AsmPseudo<"ldrh${p} $Rt, $addr",
4860 (ins GPRnopc:$Rt, t2ldr_pcrel_imm12:$addr, pred:$p)>;
4861 def t2LDRSBpcrel : t2AsmPseudo<"ldrsb${p} $Rt, $addr",
4862 (ins GPRnopc:$Rt, t2ldr_pcrel_imm12:$addr, pred:$p)>;
4863 def t2LDRSHpcrel : t2AsmPseudo<"ldrsh${p} $Rt, $addr",
4864 (ins GPRnopc:$Rt, t2ldr_pcrel_imm12:$addr, pred:$p)>;
4865 // Version w/ the .w suffix.
4866 def : t2InstAlias<"ldr${p}.w $Rt, $addr",
4867 (t2LDRpcrel GPR:$Rt, t2ldr_pcrel_imm12:$addr, pred:$p), 0>;
4868 def : t2InstAlias<"ldrb${p}.w $Rt, $addr",
4869 (t2LDRBpcrel GPRnopc:$Rt, t2ldr_pcrel_imm12:$addr, pred:$p)>;
4870 def : t2InstAlias<"ldrh${p}.w $Rt, $addr",
4871 (t2LDRHpcrel GPRnopc:$Rt, t2ldr_pcrel_imm12:$addr, pred:$p)>;
4872 def : t2InstAlias<"ldrsb${p}.w $Rt, $addr",
4873 (t2LDRSBpcrel GPRnopc:$Rt, t2ldr_pcrel_imm12:$addr, pred:$p)>;
4874 def : t2InstAlias<"ldrsh${p}.w $Rt, $addr",
4875 (t2LDRSHpcrel GPRnopc:$Rt, t2ldr_pcrel_imm12:$addr, pred:$p)>;
4877 def : t2InstAlias<"add${p} $Rd, pc, $imm",
4878 (t2ADR rGPR:$Rd, imm0_4095:$imm, pred:$p)>;
4880 // Pseudo instruction ldr Rt, =immediate
4882 : t2AsmPseudo<"ldr${p} $Rt, $immediate",
4883 (ins GPR:$Rt, const_pool_asm_imm:$immediate, pred:$p)>;
4884 // Version w/ the .w suffix.
4885 def : t2InstAlias<"ldr${p}.w $Rt, $immediate",
4886 (t2LDRConstPool GPRnopc:$Rt,
4887 const_pool_asm_imm:$immediate, pred:$p)>;
4889 // PLD/PLDW/PLI with alternate literal form.
4890 def : t2InstAlias<"pld${p} $addr",
4891 (t2PLDpci t2ldr_pcrel_imm12:$addr, pred:$p)>;
4892 def : InstAlias<"pli${p} $addr",
4893 (t2PLIpci t2ldr_pcrel_imm12:$addr, pred:$p), 0>,
4894 Requires<[IsThumb2,HasV7]>;