1 //===- ARMInstrThumb2.td - Thumb2 support for ARM -------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file describes the Thumb2 instruction set.
12 //===----------------------------------------------------------------------===//
14 // IT block predicate field
15 def it_pred : Operand<i32> {
16 let PrintMethod = "printMandatoryPredicateOperand";
19 // IT block condition mask
20 def it_mask : Operand<i32> {
21 let PrintMethod = "printThumbITMask";
24 // Shifted operands. No register controlled shifts for Thumb2.
25 // Note: We do not support rrx shifted operands yet.
26 def t2_so_reg : Operand<i32>, // reg imm
27 ComplexPattern<i32, 2, "SelectT2ShifterOperandReg",
29 let EncoderMethod = "getT2SORegOpValue";
30 let PrintMethod = "printT2SOOperand";
31 let MIOperandInfo = (ops rGPR, i32imm);
34 // t2_so_imm_not_XFORM - Return the complement of a t2_so_imm value
35 def t2_so_imm_not_XFORM : SDNodeXForm<imm, [{
36 return CurDAG->getTargetConstant(~((uint32_t)N->getZExtValue()), MVT::i32);
39 // t2_so_imm_neg_XFORM - Return the negation of a t2_so_imm value
40 def t2_so_imm_neg_XFORM : SDNodeXForm<imm, [{
41 return CurDAG->getTargetConstant(-((int)N->getZExtValue()), MVT::i32);
44 // t2_so_imm - Match a 32-bit immediate operand, which is an
45 // 8-bit immediate rotated by an arbitrary number of bits, or an 8-bit
46 // immediate splatted into multiple bytes of the word.
47 def t2_so_imm : Operand<i32>, ImmLeaf<i32, [{
48 return ARM_AM::getT2SOImmVal(Imm) != -1;
50 let EncoderMethod = "getT2SOImmOpValue";
53 // t2_so_imm_not - Match an immediate that is a complement
55 def t2_so_imm_not : Operand<i32>,
57 return ARM_AM::getT2SOImmVal(~((uint32_t)N->getZExtValue())) != -1;
58 }], t2_so_imm_not_XFORM>;
60 // t2_so_imm_neg - Match an immediate that is a negation of a t2_so_imm.
61 def t2_so_imm_neg : Operand<i32>,
63 return ARM_AM::getT2SOImmVal(-((uint32_t)N->getZExtValue())) != -1;
64 }], t2_so_imm_neg_XFORM>;
66 /// imm1_31 predicate - True if the 32-bit immediate is in the range [1,31].
67 def imm1_31 : ImmLeaf<i32, [{
68 return (int32_t)Imm >= 1 && (int32_t)Imm < 32;
71 /// imm0_4095 predicate - True if the 32-bit immediate is in the range [0.4095].
72 def imm0_4095 : Operand<i32>,
74 return Imm >= 0 && Imm < 4096;
77 def imm0_4095_neg : PatLeaf<(i32 imm), [{
78 return (uint32_t)(-N->getZExtValue()) < 4096;
81 def imm0_255_neg : PatLeaf<(i32 imm), [{
82 return (uint32_t)(-N->getZExtValue()) < 255;
85 def imm0_255_not : PatLeaf<(i32 imm), [{
86 return (uint32_t)(~N->getZExtValue()) < 255;
89 def lo5AllOne : PatLeaf<(i32 imm), [{
90 // Returns true if all low 5-bits are 1.
91 return (((uint32_t)N->getZExtValue()) & 0x1FUL) == 0x1FUL;
94 // Define Thumb2 specific addressing modes.
96 // t2addrmode_imm12 := reg + imm12
97 def t2addrmode_imm12 : Operand<i32>,
98 ComplexPattern<i32, 2, "SelectT2AddrModeImm12", []> {
99 let PrintMethod = "printAddrModeImm12Operand";
100 let EncoderMethod = "getAddrModeImm12OpValue";
101 let MIOperandInfo = (ops GPR:$base, i32imm:$offsimm);
102 let ParserMatchClass = MemMode5AsmOperand;
105 // t2ldrlabel := imm12
106 def t2ldrlabel : Operand<i32> {
107 let EncoderMethod = "getAddrModeImm12OpValue";
111 // ADR instruction labels.
112 def t2adrlabel : Operand<i32> {
113 let EncoderMethod = "getT2AdrLabelOpValue";
117 // t2addrmode_imm8 := reg +/- imm8
118 def t2addrmode_imm8 : Operand<i32>,
119 ComplexPattern<i32, 2, "SelectT2AddrModeImm8", []> {
120 let PrintMethod = "printT2AddrModeImm8Operand";
121 let EncoderMethod = "getT2AddrModeImm8OpValue";
122 let MIOperandInfo = (ops GPR:$base, i32imm:$offsimm);
123 let ParserMatchClass = MemMode5AsmOperand;
126 def t2am_imm8_offset : Operand<i32>,
127 ComplexPattern<i32, 1, "SelectT2AddrModeImm8Offset",
128 [], [SDNPWantRoot]> {
129 let PrintMethod = "printT2AddrModeImm8OffsetOperand";
130 let EncoderMethod = "getT2AddrModeImm8OffsetOpValue";
131 let ParserMatchClass = MemMode5AsmOperand;
134 // t2addrmode_imm8s4 := reg +/- (imm8 << 2)
135 def t2addrmode_imm8s4 : Operand<i32> {
136 let PrintMethod = "printT2AddrModeImm8s4Operand";
137 let EncoderMethod = "getT2AddrModeImm8s4OpValue";
138 let MIOperandInfo = (ops GPR:$base, i32imm:$offsimm);
139 let ParserMatchClass = MemMode5AsmOperand;
142 def t2am_imm8s4_offset : Operand<i32> {
143 let PrintMethod = "printT2AddrModeImm8s4OffsetOperand";
146 // t2addrmode_so_reg := reg + (reg << imm2)
147 def t2addrmode_so_reg : Operand<i32>,
148 ComplexPattern<i32, 3, "SelectT2AddrModeSoReg", []> {
149 let PrintMethod = "printT2AddrModeSoRegOperand";
150 let EncoderMethod = "getT2AddrModeSORegOpValue";
151 let MIOperandInfo = (ops GPR:$base, rGPR:$offsreg, i32imm:$offsimm);
152 let ParserMatchClass = MemMode5AsmOperand;
155 // t2addrmode_reg := reg
156 // Used by load/store exclusive instructions. Useful to enable right assembly
157 // parsing and printing. Not used for any codegen matching.
159 def t2addrmode_reg : Operand<i32> {
160 let PrintMethod = "printAddrMode7Operand";
161 let MIOperandInfo = (ops tGPR);
162 let ParserMatchClass = MemMode7AsmOperand;
165 //===----------------------------------------------------------------------===//
166 // Multiclass helpers...
170 class T2OneRegImm<dag oops, dag iops, InstrItinClass itin,
171 string opc, string asm, list<dag> pattern>
172 : T2I<oops, iops, itin, opc, asm, pattern> {
177 let Inst{26} = imm{11};
178 let Inst{14-12} = imm{10-8};
179 let Inst{7-0} = imm{7-0};
183 class T2sOneRegImm<dag oops, dag iops, InstrItinClass itin,
184 string opc, string asm, list<dag> pattern>
185 : T2sI<oops, iops, itin, opc, asm, pattern> {
191 let Inst{26} = imm{11};
192 let Inst{14-12} = imm{10-8};
193 let Inst{7-0} = imm{7-0};
196 class T2OneRegCmpImm<dag oops, dag iops, InstrItinClass itin,
197 string opc, string asm, list<dag> pattern>
198 : T2I<oops, iops, itin, opc, asm, pattern> {
202 let Inst{19-16} = Rn;
203 let Inst{26} = imm{11};
204 let Inst{14-12} = imm{10-8};
205 let Inst{7-0} = imm{7-0};
209 class T2OneRegShiftedReg<dag oops, dag iops, InstrItinClass itin,
210 string opc, string asm, list<dag> pattern>
211 : T2I<oops, iops, itin, opc, asm, pattern> {
216 let Inst{3-0} = ShiftedRm{3-0};
217 let Inst{5-4} = ShiftedRm{6-5};
218 let Inst{14-12} = ShiftedRm{11-9};
219 let Inst{7-6} = ShiftedRm{8-7};
222 class T2sOneRegShiftedReg<dag oops, dag iops, InstrItinClass itin,
223 string opc, string asm, list<dag> pattern>
224 : T2sI<oops, iops, itin, opc, asm, pattern> {
229 let Inst{3-0} = ShiftedRm{3-0};
230 let Inst{5-4} = ShiftedRm{6-5};
231 let Inst{14-12} = ShiftedRm{11-9};
232 let Inst{7-6} = ShiftedRm{8-7};
235 class T2OneRegCmpShiftedReg<dag oops, dag iops, InstrItinClass itin,
236 string opc, string asm, list<dag> pattern>
237 : T2I<oops, iops, itin, opc, asm, pattern> {
241 let Inst{19-16} = Rn;
242 let Inst{3-0} = ShiftedRm{3-0};
243 let Inst{5-4} = ShiftedRm{6-5};
244 let Inst{14-12} = ShiftedRm{11-9};
245 let Inst{7-6} = ShiftedRm{8-7};
248 class T2TwoReg<dag oops, dag iops, InstrItinClass itin,
249 string opc, string asm, list<dag> pattern>
250 : T2I<oops, iops, itin, opc, asm, pattern> {
258 class T2sTwoReg<dag oops, dag iops, InstrItinClass itin,
259 string opc, string asm, list<dag> pattern>
260 : T2sI<oops, iops, itin, opc, asm, pattern> {
268 class T2TwoRegCmp<dag oops, dag iops, InstrItinClass itin,
269 string opc, string asm, list<dag> pattern>
270 : T2I<oops, iops, itin, opc, asm, pattern> {
274 let Inst{19-16} = Rn;
279 class T2TwoRegImm<dag oops, dag iops, InstrItinClass itin,
280 string opc, string asm, list<dag> pattern>
281 : T2I<oops, iops, itin, opc, asm, pattern> {
287 let Inst{19-16} = Rn;
288 let Inst{26} = imm{11};
289 let Inst{14-12} = imm{10-8};
290 let Inst{7-0} = imm{7-0};
293 class T2sTwoRegImm<dag oops, dag iops, InstrItinClass itin,
294 string opc, string asm, list<dag> pattern>
295 : T2sI<oops, iops, itin, opc, asm, pattern> {
301 let Inst{19-16} = Rn;
302 let Inst{26} = imm{11};
303 let Inst{14-12} = imm{10-8};
304 let Inst{7-0} = imm{7-0};
307 class T2TwoRegShiftImm<dag oops, dag iops, InstrItinClass itin,
308 string opc, string asm, list<dag> pattern>
309 : T2I<oops, iops, itin, opc, asm, pattern> {
316 let Inst{14-12} = imm{4-2};
317 let Inst{7-6} = imm{1-0};
320 class T2sTwoRegShiftImm<dag oops, dag iops, InstrItinClass itin,
321 string opc, string asm, list<dag> pattern>
322 : T2sI<oops, iops, itin, opc, asm, pattern> {
329 let Inst{14-12} = imm{4-2};
330 let Inst{7-6} = imm{1-0};
333 class T2ThreeReg<dag oops, dag iops, InstrItinClass itin,
334 string opc, string asm, list<dag> pattern>
335 : T2I<oops, iops, itin, opc, asm, pattern> {
341 let Inst{19-16} = Rn;
345 class T2sThreeReg<dag oops, dag iops, InstrItinClass itin,
346 string opc, string asm, list<dag> pattern>
347 : T2sI<oops, iops, itin, opc, asm, pattern> {
353 let Inst{19-16} = Rn;
357 class T2TwoRegShiftedReg<dag oops, dag iops, InstrItinClass itin,
358 string opc, string asm, list<dag> pattern>
359 : T2I<oops, iops, itin, opc, asm, pattern> {
365 let Inst{19-16} = Rn;
366 let Inst{3-0} = ShiftedRm{3-0};
367 let Inst{5-4} = ShiftedRm{6-5};
368 let Inst{14-12} = ShiftedRm{11-9};
369 let Inst{7-6} = ShiftedRm{8-7};
372 class T2sTwoRegShiftedReg<dag oops, dag iops, InstrItinClass itin,
373 string opc, string asm, list<dag> pattern>
374 : T2sI<oops, iops, itin, opc, asm, pattern> {
380 let Inst{19-16} = Rn;
381 let Inst{3-0} = ShiftedRm{3-0};
382 let Inst{5-4} = ShiftedRm{6-5};
383 let Inst{14-12} = ShiftedRm{11-9};
384 let Inst{7-6} = ShiftedRm{8-7};
387 class T2FourReg<dag oops, dag iops, InstrItinClass itin,
388 string opc, string asm, list<dag> pattern>
389 : T2I<oops, iops, itin, opc, asm, pattern> {
395 let Inst{19-16} = Rn;
396 let Inst{15-12} = Ra;
401 class T2MulLong<bits<3> opc22_20, bits<4> opc7_4,
402 dag oops, dag iops, InstrItinClass itin,
403 string opc, string asm, list<dag> pattern>
404 : T2I<oops, iops, itin, opc, asm, pattern> {
410 let Inst{31-23} = 0b111110111;
411 let Inst{22-20} = opc22_20;
412 let Inst{19-16} = Rn;
413 let Inst{15-12} = RdLo;
414 let Inst{11-8} = RdHi;
415 let Inst{7-4} = opc7_4;
420 /// T2I_un_irs - Defines a set of (op reg, {so_imm|r|so_reg}) patterns for a
421 /// unary operation that produces a value. These are predicable and can be
422 /// changed to modify CPSR.
423 multiclass T2I_un_irs<bits<4> opcod, string opc,
424 InstrItinClass iii, InstrItinClass iir, InstrItinClass iis,
425 PatFrag opnode, bit Cheap = 0, bit ReMat = 0> {
427 def i : T2sOneRegImm<(outs rGPR:$Rd), (ins t2_so_imm:$imm), iii,
429 [(set rGPR:$Rd, (opnode t2_so_imm:$imm))]> {
430 let isAsCheapAsAMove = Cheap;
431 let isReMaterializable = ReMat;
432 let Inst{31-27} = 0b11110;
434 let Inst{24-21} = opcod;
435 let Inst{19-16} = 0b1111; // Rn
439 def r : T2sTwoReg<(outs rGPR:$Rd), (ins rGPR:$Rm), iir,
441 [(set rGPR:$Rd, (opnode rGPR:$Rm))]> {
442 let Inst{31-27} = 0b11101;
443 let Inst{26-25} = 0b01;
444 let Inst{24-21} = opcod;
445 let Inst{19-16} = 0b1111; // Rn
446 let Inst{14-12} = 0b000; // imm3
447 let Inst{7-6} = 0b00; // imm2
448 let Inst{5-4} = 0b00; // type
451 def s : T2sOneRegShiftedReg<(outs rGPR:$Rd), (ins t2_so_reg:$ShiftedRm), iis,
452 opc, ".w\t$Rd, $ShiftedRm",
453 [(set rGPR:$Rd, (opnode t2_so_reg:$ShiftedRm))]> {
454 let Inst{31-27} = 0b11101;
455 let Inst{26-25} = 0b01;
456 let Inst{24-21} = opcod;
457 let Inst{19-16} = 0b1111; // Rn
461 /// T2I_bin_irs - Defines a set of (op reg, {so_imm|r|so_reg}) patterns for a
462 /// binary operation that produces a value. These are predicable and can be
463 /// changed to modify CPSR.
464 multiclass T2I_bin_irs<bits<4> opcod, string opc,
465 InstrItinClass iii, InstrItinClass iir, InstrItinClass iis,
466 PatFrag opnode, bit Commutable = 0, string wide = ""> {
468 def ri : T2sTwoRegImm<
469 (outs rGPR:$Rd), (ins rGPR:$Rn, t2_so_imm:$imm), iii,
470 opc, "\t$Rd, $Rn, $imm",
471 [(set rGPR:$Rd, (opnode rGPR:$Rn, t2_so_imm:$imm))]> {
472 let Inst{31-27} = 0b11110;
474 let Inst{24-21} = opcod;
478 def rr : T2sThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), iir,
479 opc, !strconcat(wide, "\t$Rd, $Rn, $Rm"),
480 [(set rGPR:$Rd, (opnode rGPR:$Rn, rGPR:$Rm))]> {
481 let isCommutable = Commutable;
482 let Inst{31-27} = 0b11101;
483 let Inst{26-25} = 0b01;
484 let Inst{24-21} = opcod;
485 let Inst{14-12} = 0b000; // imm3
486 let Inst{7-6} = 0b00; // imm2
487 let Inst{5-4} = 0b00; // type
490 def rs : T2sTwoRegShiftedReg<
491 (outs rGPR:$Rd), (ins rGPR:$Rn, t2_so_reg:$ShiftedRm), iis,
492 opc, !strconcat(wide, "\t$Rd, $Rn, $ShiftedRm"),
493 [(set rGPR:$Rd, (opnode rGPR:$Rn, t2_so_reg:$ShiftedRm))]> {
494 let Inst{31-27} = 0b11101;
495 let Inst{26-25} = 0b01;
496 let Inst{24-21} = opcod;
500 /// T2I_bin_w_irs - Same as T2I_bin_irs except these operations need
501 // the ".w" prefix to indicate that they are wide.
502 multiclass T2I_bin_w_irs<bits<4> opcod, string opc,
503 InstrItinClass iii, InstrItinClass iir, InstrItinClass iis,
504 PatFrag opnode, bit Commutable = 0> :
505 T2I_bin_irs<opcod, opc, iii, iir, iis, opnode, Commutable, ".w">;
507 /// T2I_rbin_is - Same as T2I_bin_irs except the order of operands are
508 /// reversed. The 'rr' form is only defined for the disassembler; for codegen
509 /// it is equivalent to the T2I_bin_irs counterpart.
510 multiclass T2I_rbin_irs<bits<4> opcod, string opc, PatFrag opnode> {
512 def ri : T2sTwoRegImm<
513 (outs rGPR:$Rd), (ins rGPR:$Rn, t2_so_imm:$imm), IIC_iALUi,
514 opc, ".w\t$Rd, $Rn, $imm",
515 [(set rGPR:$Rd, (opnode t2_so_imm:$imm, rGPR:$Rn))]> {
516 let Inst{31-27} = 0b11110;
518 let Inst{24-21} = opcod;
522 def rr : T2sThreeReg<
523 (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iALUr,
524 opc, "\t$Rd, $Rn, $Rm",
525 [/* For disassembly only; pattern left blank */]> {
526 let Inst{31-27} = 0b11101;
527 let Inst{26-25} = 0b01;
528 let Inst{24-21} = opcod;
529 let Inst{14-12} = 0b000; // imm3
530 let Inst{7-6} = 0b00; // imm2
531 let Inst{5-4} = 0b00; // type
534 def rs : T2sTwoRegShiftedReg<
535 (outs rGPR:$Rd), (ins rGPR:$Rn, t2_so_reg:$ShiftedRm),
536 IIC_iALUsir, opc, "\t$Rd, $Rn, $ShiftedRm",
537 [(set rGPR:$Rd, (opnode t2_so_reg:$ShiftedRm, rGPR:$Rn))]> {
538 let Inst{31-27} = 0b11101;
539 let Inst{26-25} = 0b01;
540 let Inst{24-21} = opcod;
544 /// T2I_bin_s_irs - Similar to T2I_bin_irs except it sets the 's' bit so the
545 /// instruction modifies the CPSR register.
546 let isCodeGenOnly = 1, Defs = [CPSR] in {
547 multiclass T2I_bin_s_irs<bits<4> opcod, string opc,
548 InstrItinClass iii, InstrItinClass iir, InstrItinClass iis,
549 PatFrag opnode, bit Commutable = 0> {
551 def ri : T2TwoRegImm<
552 (outs rGPR:$Rd), (ins GPR:$Rn, t2_so_imm:$imm), iii,
553 !strconcat(opc, "s"), ".w\t$Rd, $Rn, $imm",
554 [(set rGPR:$Rd, (opnode GPR:$Rn, t2_so_imm:$imm))]> {
555 let Inst{31-27} = 0b11110;
557 let Inst{24-21} = opcod;
558 let Inst{20} = 1; // The S bit.
563 (outs rGPR:$Rd), (ins GPR:$Rn, rGPR:$Rm), iir,
564 !strconcat(opc, "s"), ".w\t$Rd, $Rn, $Rm",
565 [(set rGPR:$Rd, (opnode GPR:$Rn, rGPR:$Rm))]> {
566 let isCommutable = Commutable;
567 let Inst{31-27} = 0b11101;
568 let Inst{26-25} = 0b01;
569 let Inst{24-21} = opcod;
570 let Inst{20} = 1; // The S bit.
571 let Inst{14-12} = 0b000; // imm3
572 let Inst{7-6} = 0b00; // imm2
573 let Inst{5-4} = 0b00; // type
576 def rs : T2TwoRegShiftedReg<
577 (outs rGPR:$Rd), (ins GPR:$Rn, t2_so_reg:$ShiftedRm), iis,
578 !strconcat(opc, "s"), ".w\t$Rd, $Rn, $ShiftedRm",
579 [(set rGPR:$Rd, (opnode GPR:$Rn, t2_so_reg:$ShiftedRm))]> {
580 let Inst{31-27} = 0b11101;
581 let Inst{26-25} = 0b01;
582 let Inst{24-21} = opcod;
583 let Inst{20} = 1; // The S bit.
588 /// T2I_bin_ii12rs - Defines a set of (op reg, {so_imm|imm0_4095|r|so_reg})
589 /// patterns for a binary operation that produces a value.
590 multiclass T2I_bin_ii12rs<bits<3> op23_21, string opc, PatFrag opnode,
591 bit Commutable = 0> {
593 // The register-immediate version is re-materializable. This is useful
594 // in particular for taking the address of a local.
595 let isReMaterializable = 1 in {
596 def ri : T2sTwoRegImm<
597 (outs rGPR:$Rd), (ins GPR:$Rn, t2_so_imm:$imm), IIC_iALUi,
598 opc, ".w\t$Rd, $Rn, $imm",
599 [(set rGPR:$Rd, (opnode GPR:$Rn, t2_so_imm:$imm))]> {
600 let Inst{31-27} = 0b11110;
603 let Inst{23-21} = op23_21;
609 (outs rGPR:$Rd), (ins GPR:$Rn, imm0_4095:$imm), IIC_iALUi,
610 !strconcat(opc, "w"), "\t$Rd, $Rn, $imm",
611 [(set rGPR:$Rd, (opnode GPR:$Rn, imm0_4095:$imm))]> {
615 let Inst{31-27} = 0b11110;
616 let Inst{26} = imm{11};
617 let Inst{25-24} = 0b10;
618 let Inst{23-21} = op23_21;
619 let Inst{20} = 0; // The S bit.
620 let Inst{19-16} = Rn;
622 let Inst{14-12} = imm{10-8};
624 let Inst{7-0} = imm{7-0};
627 def rr : T2sThreeReg<(outs rGPR:$Rd), (ins GPR:$Rn, rGPR:$Rm), IIC_iALUr,
628 opc, ".w\t$Rd, $Rn, $Rm",
629 [(set rGPR:$Rd, (opnode GPR:$Rn, rGPR:$Rm))]> {
630 let isCommutable = Commutable;
631 let Inst{31-27} = 0b11101;
632 let Inst{26-25} = 0b01;
634 let Inst{23-21} = op23_21;
635 let Inst{14-12} = 0b000; // imm3
636 let Inst{7-6} = 0b00; // imm2
637 let Inst{5-4} = 0b00; // type
640 def rs : T2sTwoRegShiftedReg<
641 (outs rGPR:$Rd), (ins GPR:$Rn, t2_so_reg:$ShiftedRm),
642 IIC_iALUsi, opc, ".w\t$Rd, $Rn, $ShiftedRm",
643 [(set rGPR:$Rd, (opnode GPR:$Rn, t2_so_reg:$ShiftedRm))]> {
644 let Inst{31-27} = 0b11101;
645 let Inst{26-25} = 0b01;
647 let Inst{23-21} = op23_21;
651 /// T2I_adde_sube_irs - Defines a set of (op reg, {so_imm|r|so_reg}) patterns
652 /// for a binary operation that produces a value and use the carry
653 /// bit. It's not predicable.
654 let Uses = [CPSR] in {
655 multiclass T2I_adde_sube_irs<bits<4> opcod, string opc, PatFrag opnode,
656 bit Commutable = 0> {
658 def ri : T2sTwoRegImm<(outs rGPR:$Rd), (ins rGPR:$Rn, t2_so_imm:$imm),
659 IIC_iALUi, opc, "\t$Rd, $Rn, $imm",
660 [(set rGPR:$Rd, (opnode rGPR:$Rn, t2_so_imm:$imm))]>,
661 Requires<[IsThumb2]> {
662 let Inst{31-27} = 0b11110;
664 let Inst{24-21} = opcod;
668 def rr : T2sThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iALUr,
669 opc, ".w\t$Rd, $Rn, $Rm",
670 [(set rGPR:$Rd, (opnode rGPR:$Rn, rGPR:$Rm))]>,
671 Requires<[IsThumb2]> {
672 let isCommutable = Commutable;
673 let Inst{31-27} = 0b11101;
674 let Inst{26-25} = 0b01;
675 let Inst{24-21} = opcod;
676 let Inst{14-12} = 0b000; // imm3
677 let Inst{7-6} = 0b00; // imm2
678 let Inst{5-4} = 0b00; // type
681 def rs : T2sTwoRegShiftedReg<
682 (outs rGPR:$Rd), (ins rGPR:$Rn, t2_so_reg:$ShiftedRm),
683 IIC_iALUsi, opc, ".w\t$Rd, $Rn, $ShiftedRm",
684 [(set rGPR:$Rd, (opnode rGPR:$Rn, t2_so_reg:$ShiftedRm))]>,
685 Requires<[IsThumb2]> {
686 let Inst{31-27} = 0b11101;
687 let Inst{26-25} = 0b01;
688 let Inst{24-21} = opcod;
693 // Carry setting variants
694 // NOTE: CPSR def omitted because it will be handled by the custom inserter.
695 let usesCustomInserter = 1 in {
696 multiclass T2I_adde_sube_s_irs<PatFrag opnode, bit Commutable = 0> {
698 def ri : t2PseudoInst<(outs rGPR:$Rd), (ins rGPR:$Rn, t2_so_imm:$imm),
699 Size4Bytes, IIC_iALUi,
700 [(set rGPR:$Rd, (opnode rGPR:$Rn, t2_so_imm:$imm))]>;
702 def rr : t2PseudoInst<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm),
703 Size4Bytes, IIC_iALUr,
704 [(set rGPR:$Rd, (opnode rGPR:$Rn, rGPR:$Rm))]> {
705 let isCommutable = Commutable;
708 def rs : t2PseudoInst<
709 (outs rGPR:$Rd), (ins rGPR:$Rn, t2_so_reg:$ShiftedRm),
710 Size4Bytes, IIC_iALUsi,
711 [(set rGPR:$Rd, (opnode rGPR:$Rn, t2_so_reg:$ShiftedRm))]>;
715 /// T2I_rbin_s_is - Same as T2I_rbin_irs except sets 's' bit and the register
716 /// version is not needed since this is only for codegen.
717 let isCodeGenOnly = 1, Defs = [CPSR] in {
718 multiclass T2I_rbin_s_is<bits<4> opcod, string opc, PatFrag opnode> {
720 def ri : T2TwoRegImm<
721 (outs rGPR:$Rd), (ins rGPR:$Rn, t2_so_imm:$imm), IIC_iALUi,
722 !strconcat(opc, "s"), ".w\t$Rd, $Rn, $imm",
723 [(set rGPR:$Rd, (opnode t2_so_imm:$imm, rGPR:$Rn))]> {
724 let Inst{31-27} = 0b11110;
726 let Inst{24-21} = opcod;
727 let Inst{20} = 1; // The S bit.
731 def rs : T2TwoRegShiftedReg<
732 (outs rGPR:$Rd), (ins rGPR:$Rn, t2_so_reg:$ShiftedRm),
733 IIC_iALUsi, !strconcat(opc, "s"), "\t$Rd, $Rn, $ShiftedRm",
734 [(set rGPR:$Rd, (opnode t2_so_reg:$ShiftedRm, rGPR:$Rn))]> {
735 let Inst{31-27} = 0b11101;
736 let Inst{26-25} = 0b01;
737 let Inst{24-21} = opcod;
738 let Inst{20} = 1; // The S bit.
743 /// T2I_sh_ir - Defines a set of (op reg, {so_imm|r}) patterns for a shift /
744 // rotate operation that produces a value.
745 multiclass T2I_sh_ir<bits<2> opcod, string opc, PatFrag opnode> {
747 def ri : T2sTwoRegShiftImm<
748 (outs rGPR:$Rd), (ins rGPR:$Rm, i32imm:$imm), IIC_iMOVsi,
749 opc, ".w\t$Rd, $Rm, $imm",
750 [(set rGPR:$Rd, (opnode rGPR:$Rm, imm1_31:$imm))]> {
751 let Inst{31-27} = 0b11101;
752 let Inst{26-21} = 0b010010;
753 let Inst{19-16} = 0b1111; // Rn
754 let Inst{5-4} = opcod;
757 def rr : T2sThreeReg<
758 (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iMOVsr,
759 opc, ".w\t$Rd, $Rn, $Rm",
760 [(set rGPR:$Rd, (opnode rGPR:$Rn, rGPR:$Rm))]> {
761 let Inst{31-27} = 0b11111;
762 let Inst{26-23} = 0b0100;
763 let Inst{22-21} = opcod;
764 let Inst{15-12} = 0b1111;
765 let Inst{7-4} = 0b0000;
769 /// T2I_cmp_irs - Defines a set of (op r, {so_imm|r|so_reg}) cmp / test
770 /// patterns. Similar to T2I_bin_irs except the instruction does not produce
771 /// a explicit result, only implicitly set CPSR.
772 let isCompare = 1, Defs = [CPSR] in {
773 multiclass T2I_cmp_irs<bits<4> opcod, string opc,
774 InstrItinClass iii, InstrItinClass iir, InstrItinClass iis,
777 def ri : T2OneRegCmpImm<
778 (outs), (ins GPR:$Rn, t2_so_imm:$imm), iii,
779 opc, ".w\t$Rn, $imm",
780 [(opnode GPR:$Rn, t2_so_imm:$imm)]> {
781 let Inst{31-27} = 0b11110;
783 let Inst{24-21} = opcod;
784 let Inst{20} = 1; // The S bit.
786 let Inst{11-8} = 0b1111; // Rd
789 def rr : T2TwoRegCmp<
790 (outs), (ins GPR:$lhs, rGPR:$rhs), iir,
791 opc, ".w\t$lhs, $rhs",
792 [(opnode GPR:$lhs, rGPR:$rhs)]> {
793 let Inst{31-27} = 0b11101;
794 let Inst{26-25} = 0b01;
795 let Inst{24-21} = opcod;
796 let Inst{20} = 1; // The S bit.
797 let Inst{14-12} = 0b000; // imm3
798 let Inst{11-8} = 0b1111; // Rd
799 let Inst{7-6} = 0b00; // imm2
800 let Inst{5-4} = 0b00; // type
803 def rs : T2OneRegCmpShiftedReg<
804 (outs), (ins GPR:$Rn, t2_so_reg:$ShiftedRm), iis,
805 opc, ".w\t$Rn, $ShiftedRm",
806 [(opnode GPR:$Rn, t2_so_reg:$ShiftedRm)]> {
807 let Inst{31-27} = 0b11101;
808 let Inst{26-25} = 0b01;
809 let Inst{24-21} = opcod;
810 let Inst{20} = 1; // The S bit.
811 let Inst{11-8} = 0b1111; // Rd
816 /// T2I_ld - Defines a set of (op r, {imm12|imm8|so_reg}) load patterns.
817 multiclass T2I_ld<bit signed, bits<2> opcod, string opc,
818 InstrItinClass iii, InstrItinClass iis, PatFrag opnode> {
819 def i12 : T2Ii12<(outs GPR:$Rt), (ins t2addrmode_imm12:$addr), iii,
820 opc, ".w\t$Rt, $addr",
821 [(set GPR:$Rt, (opnode t2addrmode_imm12:$addr))]> {
822 let Inst{31-27} = 0b11111;
823 let Inst{26-25} = 0b00;
824 let Inst{24} = signed;
826 let Inst{22-21} = opcod;
827 let Inst{20} = 1; // load
830 let Inst{15-12} = Rt;
833 let addr{12} = 1; // add = TRUE
834 let Inst{19-16} = addr{16-13}; // Rn
835 let Inst{23} = addr{12}; // U
836 let Inst{11-0} = addr{11-0}; // imm
838 def i8 : T2Ii8 <(outs GPR:$Rt), (ins t2addrmode_imm8:$addr), iii,
840 [(set GPR:$Rt, (opnode t2addrmode_imm8:$addr))]> {
841 let Inst{31-27} = 0b11111;
842 let Inst{26-25} = 0b00;
843 let Inst{24} = signed;
845 let Inst{22-21} = opcod;
846 let Inst{20} = 1; // load
848 // Offset: index==TRUE, wback==FALSE
849 let Inst{10} = 1; // The P bit.
850 let Inst{8} = 0; // The W bit.
853 let Inst{15-12} = Rt;
856 let Inst{19-16} = addr{12-9}; // Rn
857 let Inst{9} = addr{8}; // U
858 let Inst{7-0} = addr{7-0}; // imm
860 def s : T2Iso <(outs GPR:$Rt), (ins t2addrmode_so_reg:$addr), iis,
861 opc, ".w\t$Rt, $addr",
862 [(set GPR:$Rt, (opnode t2addrmode_so_reg:$addr))]> {
863 let Inst{31-27} = 0b11111;
864 let Inst{26-25} = 0b00;
865 let Inst{24} = signed;
867 let Inst{22-21} = opcod;
868 let Inst{20} = 1; // load
869 let Inst{11-6} = 0b000000;
872 let Inst{15-12} = Rt;
875 let Inst{19-16} = addr{9-6}; // Rn
876 let Inst{3-0} = addr{5-2}; // Rm
877 let Inst{5-4} = addr{1-0}; // imm
880 // FIXME: Is the pci variant actually needed?
881 def pci : T2Ipc <(outs GPR:$Rt), (ins t2ldrlabel:$addr), iii,
882 opc, ".w\t$Rt, $addr",
883 [(set GPR:$Rt, (opnode (ARMWrapper tconstpool:$addr)))]> {
884 let isReMaterializable = 1;
885 let Inst{31-27} = 0b11111;
886 let Inst{26-25} = 0b00;
887 let Inst{24} = signed;
888 let Inst{23} = ?; // add = (U == '1')
889 let Inst{22-21} = opcod;
890 let Inst{20} = 1; // load
891 let Inst{19-16} = 0b1111; // Rn
894 let Inst{15-12} = Rt{3-0};
895 let Inst{11-0} = addr{11-0};
899 /// T2I_st - Defines a set of (op r, {imm12|imm8|so_reg}) store patterns.
900 multiclass T2I_st<bits<2> opcod, string opc,
901 InstrItinClass iii, InstrItinClass iis, PatFrag opnode> {
902 def i12 : T2Ii12<(outs), (ins GPR:$Rt, t2addrmode_imm12:$addr), iii,
903 opc, ".w\t$Rt, $addr",
904 [(opnode GPR:$Rt, t2addrmode_imm12:$addr)]> {
905 let Inst{31-27} = 0b11111;
906 let Inst{26-23} = 0b0001;
907 let Inst{22-21} = opcod;
908 let Inst{20} = 0; // !load
911 let Inst{15-12} = Rt;
914 let addr{12} = 1; // add = TRUE
915 let Inst{19-16} = addr{16-13}; // Rn
916 let Inst{23} = addr{12}; // U
917 let Inst{11-0} = addr{11-0}; // imm
919 def i8 : T2Ii8 <(outs), (ins GPR:$Rt, t2addrmode_imm8:$addr), iii,
921 [(opnode GPR:$Rt, t2addrmode_imm8:$addr)]> {
922 let Inst{31-27} = 0b11111;
923 let Inst{26-23} = 0b0000;
924 let Inst{22-21} = opcod;
925 let Inst{20} = 0; // !load
927 // Offset: index==TRUE, wback==FALSE
928 let Inst{10} = 1; // The P bit.
929 let Inst{8} = 0; // The W bit.
932 let Inst{15-12} = Rt;
935 let Inst{19-16} = addr{12-9}; // Rn
936 let Inst{9} = addr{8}; // U
937 let Inst{7-0} = addr{7-0}; // imm
939 def s : T2Iso <(outs), (ins GPR:$Rt, t2addrmode_so_reg:$addr), iis,
940 opc, ".w\t$Rt, $addr",
941 [(opnode GPR:$Rt, t2addrmode_so_reg:$addr)]> {
942 let Inst{31-27} = 0b11111;
943 let Inst{26-23} = 0b0000;
944 let Inst{22-21} = opcod;
945 let Inst{20} = 0; // !load
946 let Inst{11-6} = 0b000000;
949 let Inst{15-12} = Rt;
952 let Inst{19-16} = addr{9-6}; // Rn
953 let Inst{3-0} = addr{5-2}; // Rm
954 let Inst{5-4} = addr{1-0}; // imm
958 /// T2I_ext_rrot - A unary operation with two forms: one whose operand is a
959 /// register and one whose operand is a register rotated by 8/16/24.
960 multiclass T2I_ext_rrot<bits<3> opcod, string opc, PatFrag opnode> {
961 def r : T2TwoReg<(outs rGPR:$Rd), (ins rGPR:$Rm), IIC_iEXTr,
963 [(set rGPR:$Rd, (opnode rGPR:$Rm))]> {
964 let Inst{31-27} = 0b11111;
965 let Inst{26-23} = 0b0100;
966 let Inst{22-20} = opcod;
967 let Inst{19-16} = 0b1111; // Rn
968 let Inst{15-12} = 0b1111;
970 let Inst{5-4} = 0b00; // rotate
972 def r_rot : T2TwoReg<(outs rGPR:$Rd), (ins rGPR:$Rm, rot_imm:$rot), IIC_iEXTr,
973 opc, ".w\t$Rd, $Rm, ror $rot",
974 [(set rGPR:$Rd, (opnode (rotr rGPR:$Rm, rot_imm:$rot)))]> {
975 let Inst{31-27} = 0b11111;
976 let Inst{26-23} = 0b0100;
977 let Inst{22-20} = opcod;
978 let Inst{19-16} = 0b1111; // Rn
979 let Inst{15-12} = 0b1111;
983 let Inst{5-4} = rot{1-0}; // rotate
987 // UXTB16 - Requres T2ExtractPack, does not need the .w qualifier.
988 multiclass T2I_ext_rrot_uxtb16<bits<3> opcod, string opc, PatFrag opnode> {
989 def r : T2TwoReg<(outs rGPR:$Rd), (ins rGPR:$Rm), IIC_iEXTr,
991 [(set rGPR:$Rd, (opnode rGPR:$Rm))]>,
992 Requires<[HasT2ExtractPack, IsThumb2]> {
993 let Inst{31-27} = 0b11111;
994 let Inst{26-23} = 0b0100;
995 let Inst{22-20} = opcod;
996 let Inst{19-16} = 0b1111; // Rn
997 let Inst{15-12} = 0b1111;
999 let Inst{5-4} = 0b00; // rotate
1001 def r_rot : T2TwoReg<(outs rGPR:$dst), (ins rGPR:$Rm, rot_imm:$rot),
1002 IIC_iEXTr, opc, "\t$dst, $Rm, ror $rot",
1003 [(set rGPR:$dst, (opnode (rotr rGPR:$Rm, rot_imm:$rot)))]>,
1004 Requires<[HasT2ExtractPack, IsThumb2]> {
1005 let Inst{31-27} = 0b11111;
1006 let Inst{26-23} = 0b0100;
1007 let Inst{22-20} = opcod;
1008 let Inst{19-16} = 0b1111; // Rn
1009 let Inst{15-12} = 0b1111;
1013 let Inst{5-4} = rot{1-0}; // rotate
1017 // SXTB16 - Requres T2ExtractPack, does not need the .w qualifier, no pattern
1019 multiclass T2I_ext_rrot_sxtb16<bits<3> opcod, string opc> {
1020 def r : T2TwoReg<(outs rGPR:$Rd), (ins rGPR:$Rm), IIC_iEXTr,
1021 opc, "\t$Rd, $Rm", []> {
1022 let Inst{31-27} = 0b11111;
1023 let Inst{26-23} = 0b0100;
1024 let Inst{22-20} = opcod;
1025 let Inst{19-16} = 0b1111; // Rn
1026 let Inst{15-12} = 0b1111;
1028 let Inst{5-4} = 0b00; // rotate
1030 def r_rot : T2TwoReg<(outs rGPR:$Rd), (ins rGPR:$Rm, i32imm:$rot), IIC_iEXTr,
1031 opc, "\t$Rd, $Rm, ror $rot", []> {
1032 let Inst{31-27} = 0b11111;
1033 let Inst{26-23} = 0b0100;
1034 let Inst{22-20} = opcod;
1035 let Inst{19-16} = 0b1111; // Rn
1036 let Inst{15-12} = 0b1111;
1040 let Inst{5-4} = rot{1-0}; // rotate
1044 /// T2I_exta_rrot - A binary operation with two forms: one whose operand is a
1045 /// register and one whose operand is a register rotated by 8/16/24.
1046 multiclass T2I_exta_rrot<bits<3> opcod, string opc, PatFrag opnode> {
1047 def rr : T2ThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iEXTAr,
1048 opc, "\t$Rd, $Rn, $Rm",
1049 [(set rGPR:$Rd, (opnode rGPR:$Rn, rGPR:$Rm))]>,
1050 Requires<[HasT2ExtractPack, IsThumb2]> {
1051 let Inst{31-27} = 0b11111;
1052 let Inst{26-23} = 0b0100;
1053 let Inst{22-20} = opcod;
1054 let Inst{15-12} = 0b1111;
1056 let Inst{5-4} = 0b00; // rotate
1058 def rr_rot : T2ThreeReg<(outs rGPR:$Rd),
1059 (ins rGPR:$Rn, rGPR:$Rm, rot_imm:$rot),
1060 IIC_iEXTAsr, opc, "\t$Rd, $Rn, $Rm, ror $rot",
1061 [(set rGPR:$Rd, (opnode rGPR:$Rn,
1062 (rotr rGPR:$Rm, rot_imm:$rot)))]>,
1063 Requires<[HasT2ExtractPack, IsThumb2]> {
1064 let Inst{31-27} = 0b11111;
1065 let Inst{26-23} = 0b0100;
1066 let Inst{22-20} = opcod;
1067 let Inst{15-12} = 0b1111;
1071 let Inst{5-4} = rot{1-0}; // rotate
1075 // DO variant - disassembly only, no pattern
1077 multiclass T2I_exta_rrot_DO<bits<3> opcod, string opc> {
1078 def rr : T2ThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iEXTAr,
1079 opc, "\t$Rd, $Rn, $Rm", []> {
1080 let Inst{31-27} = 0b11111;
1081 let Inst{26-23} = 0b0100;
1082 let Inst{22-20} = opcod;
1083 let Inst{15-12} = 0b1111;
1085 let Inst{5-4} = 0b00; // rotate
1087 def rr_rot : T2ThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, i32imm:$rot),
1088 IIC_iEXTAsr, opc, "\t$Rd, $Rn, $Rm, ror $rot", []> {
1089 let Inst{31-27} = 0b11111;
1090 let Inst{26-23} = 0b0100;
1091 let Inst{22-20} = opcod;
1092 let Inst{15-12} = 0b1111;
1096 let Inst{5-4} = rot{1-0}; // rotate
1100 //===----------------------------------------------------------------------===//
1102 //===----------------------------------------------------------------------===//
1104 //===----------------------------------------------------------------------===//
1105 // Miscellaneous Instructions.
1108 class T2PCOneRegImm<dag oops, dag iops, InstrItinClass itin,
1109 string asm, list<dag> pattern>
1110 : T2XI<oops, iops, itin, asm, pattern> {
1114 let Inst{11-8} = Rd;
1115 let Inst{26} = label{11};
1116 let Inst{14-12} = label{10-8};
1117 let Inst{7-0} = label{7-0};
1120 // LEApcrel - Load a pc-relative address into a register without offending the
1122 def t2ADR : T2PCOneRegImm<(outs rGPR:$Rd),
1123 (ins t2adrlabel:$addr, pred:$p),
1124 IIC_iALUi, "adr{$p}.w\t$Rd, #$addr", []> {
1125 let Inst{31-27} = 0b11110;
1126 let Inst{25-24} = 0b10;
1127 // Inst{23:21} = '11' (add = FALSE) or '00' (add = TRUE)
1130 let Inst{19-16} = 0b1111; // Rn
1135 let Inst{11-8} = Rd;
1136 let Inst{23} = addr{12};
1137 let Inst{21} = addr{12};
1138 let Inst{26} = addr{11};
1139 let Inst{14-12} = addr{10-8};
1140 let Inst{7-0} = addr{7-0};
1143 let neverHasSideEffects = 1, isReMaterializable = 1 in
1144 def t2LEApcrel : t2PseudoInst<(outs rGPR:$Rd), (ins i32imm:$label, pred:$p),
1145 Size4Bytes, IIC_iALUi, []>;
1146 def t2LEApcrelJT : t2PseudoInst<(outs rGPR:$Rd),
1147 (ins i32imm:$label, nohash_imm:$id, pred:$p),
1148 Size4Bytes, IIC_iALUi,
1152 // FIXME: None of these add/sub SP special instructions should be necessary
1153 // at all for thumb2 since they use the same encodings as the generic
1154 // add/sub instructions. In thumb1 we need them since they have dedicated
1155 // encodings. At the least, they should be pseudo instructions.
1156 // ADD r, sp, {so_imm|i12}
1157 let isCodeGenOnly = 1 in {
1158 def t2ADDrSPi : T2sTwoRegImm<(outs GPR:$Rd), (ins GPR:$Rn, t2_so_imm:$imm),
1159 IIC_iALUi, "add", ".w\t$Rd, $Rn, $imm", []> {
1160 let Inst{31-27} = 0b11110;
1162 let Inst{24-21} = 0b1000;
1165 def t2ADDrSPi12 : T2TwoRegImm<(outs GPR:$Rd), (ins GPR:$Rn, imm0_4095:$imm),
1166 IIC_iALUi, "addw", "\t$Rd, $Rn, $imm", []> {
1167 let Inst{31-27} = 0b11110;
1168 let Inst{25-20} = 0b100000;
1172 // ADD r, sp, so_reg
1173 def t2ADDrSPs : T2sTwoRegShiftedReg<
1174 (outs GPR:$Rd), (ins GPR:$Rn, t2_so_reg:$ShiftedRm),
1175 IIC_iALUsi, "add", ".w\t$Rd, $Rn, $ShiftedRm", []> {
1176 let Inst{31-27} = 0b11101;
1177 let Inst{26-25} = 0b01;
1178 let Inst{24-21} = 0b1000;
1182 // SUB r, sp, {so_imm|i12}
1183 def t2SUBrSPi : T2sTwoRegImm<(outs GPR:$Rd), (ins GPR:$Rn, t2_so_imm:$imm),
1184 IIC_iALUi, "sub", ".w\t$Rd, $Rn, $imm", []> {
1185 let Inst{31-27} = 0b11110;
1187 let Inst{24-21} = 0b1101;
1190 def t2SUBrSPi12 : T2TwoRegImm<(outs GPR:$Rd), (ins GPR:$Rn, imm0_4095:$imm),
1191 IIC_iALUi, "subw", "\t$Rd, $Rn, $imm", []> {
1192 let Inst{31-27} = 0b11110;
1193 let Inst{25-20} = 0b101010;
1197 // SUB r, sp, so_reg
1198 def t2SUBrSPs : T2sTwoRegImm<(outs GPR:$Rd), (ins GPR:$Rn, t2_so_reg:$imm),
1200 "sub", "\t$Rd, $Rn, $imm", []> {
1201 let Inst{31-27} = 0b11101;
1202 let Inst{26-25} = 0b01;
1203 let Inst{24-21} = 0b1101;
1204 let Inst{19-16} = 0b1101; // Rn = sp
1207 } // end isCodeGenOnly = 1
1209 // Signed and unsigned division on v7-M
1210 def t2SDIV : T2ThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iALUi,
1211 "sdiv", "\t$Rd, $Rn, $Rm",
1212 [(set rGPR:$Rd, (sdiv rGPR:$Rn, rGPR:$Rm))]>,
1213 Requires<[HasDivide, IsThumb2]> {
1214 let Inst{31-27} = 0b11111;
1215 let Inst{26-21} = 0b011100;
1217 let Inst{15-12} = 0b1111;
1218 let Inst{7-4} = 0b1111;
1221 def t2UDIV : T2ThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iALUi,
1222 "udiv", "\t$Rd, $Rn, $Rm",
1223 [(set rGPR:$Rd, (udiv rGPR:$Rn, rGPR:$Rm))]>,
1224 Requires<[HasDivide, IsThumb2]> {
1225 let Inst{31-27} = 0b11111;
1226 let Inst{26-21} = 0b011101;
1228 let Inst{15-12} = 0b1111;
1229 let Inst{7-4} = 0b1111;
1232 //===----------------------------------------------------------------------===//
1233 // Load / store Instructions.
1237 let canFoldAsLoad = 1, isReMaterializable = 1 in
1238 defm t2LDR : T2I_ld<0, 0b10, "ldr", IIC_iLoad_i, IIC_iLoad_si,
1239 UnOpFrag<(load node:$Src)>>;
1241 // Loads with zero extension
1242 defm t2LDRH : T2I_ld<0, 0b01, "ldrh", IIC_iLoad_bh_i, IIC_iLoad_bh_si,
1243 UnOpFrag<(zextloadi16 node:$Src)>>;
1244 defm t2LDRB : T2I_ld<0, 0b00, "ldrb", IIC_iLoad_bh_i, IIC_iLoad_bh_si,
1245 UnOpFrag<(zextloadi8 node:$Src)>>;
1247 // Loads with sign extension
1248 defm t2LDRSH : T2I_ld<1, 0b01, "ldrsh", IIC_iLoad_bh_i, IIC_iLoad_bh_si,
1249 UnOpFrag<(sextloadi16 node:$Src)>>;
1250 defm t2LDRSB : T2I_ld<1, 0b00, "ldrsb", IIC_iLoad_bh_i, IIC_iLoad_bh_si,
1251 UnOpFrag<(sextloadi8 node:$Src)>>;
1253 let mayLoad = 1, neverHasSideEffects = 1, hasExtraDefRegAllocReq = 1 in {
1255 def t2LDRDi8 : T2Ii8s4<1, 0, 1, (outs rGPR:$Rt, rGPR:$Rt2),
1256 (ins t2addrmode_imm8s4:$addr),
1257 IIC_iLoad_d_i, "ldrd", "\t$Rt, $Rt2, $addr", []>;
1258 } // mayLoad = 1, neverHasSideEffects = 1, hasExtraDefRegAllocReq = 1
1260 // zextload i1 -> zextload i8
1261 def : T2Pat<(zextloadi1 t2addrmode_imm12:$addr),
1262 (t2LDRBi12 t2addrmode_imm12:$addr)>;
1263 def : T2Pat<(zextloadi1 t2addrmode_imm8:$addr),
1264 (t2LDRBi8 t2addrmode_imm8:$addr)>;
1265 def : T2Pat<(zextloadi1 t2addrmode_so_reg:$addr),
1266 (t2LDRBs t2addrmode_so_reg:$addr)>;
1267 def : T2Pat<(zextloadi1 (ARMWrapper tconstpool:$addr)),
1268 (t2LDRBpci tconstpool:$addr)>;
1270 // extload -> zextload
1271 // FIXME: Reduce the number of patterns by legalizing extload to zextload
1273 def : T2Pat<(extloadi1 t2addrmode_imm12:$addr),
1274 (t2LDRBi12 t2addrmode_imm12:$addr)>;
1275 def : T2Pat<(extloadi1 t2addrmode_imm8:$addr),
1276 (t2LDRBi8 t2addrmode_imm8:$addr)>;
1277 def : T2Pat<(extloadi1 t2addrmode_so_reg:$addr),
1278 (t2LDRBs t2addrmode_so_reg:$addr)>;
1279 def : T2Pat<(extloadi1 (ARMWrapper tconstpool:$addr)),
1280 (t2LDRBpci tconstpool:$addr)>;
1282 def : T2Pat<(extloadi8 t2addrmode_imm12:$addr),
1283 (t2LDRBi12 t2addrmode_imm12:$addr)>;
1284 def : T2Pat<(extloadi8 t2addrmode_imm8:$addr),
1285 (t2LDRBi8 t2addrmode_imm8:$addr)>;
1286 def : T2Pat<(extloadi8 t2addrmode_so_reg:$addr),
1287 (t2LDRBs t2addrmode_so_reg:$addr)>;
1288 def : T2Pat<(extloadi8 (ARMWrapper tconstpool:$addr)),
1289 (t2LDRBpci tconstpool:$addr)>;
1291 def : T2Pat<(extloadi16 t2addrmode_imm12:$addr),
1292 (t2LDRHi12 t2addrmode_imm12:$addr)>;
1293 def : T2Pat<(extloadi16 t2addrmode_imm8:$addr),
1294 (t2LDRHi8 t2addrmode_imm8:$addr)>;
1295 def : T2Pat<(extloadi16 t2addrmode_so_reg:$addr),
1296 (t2LDRHs t2addrmode_so_reg:$addr)>;
1297 def : T2Pat<(extloadi16 (ARMWrapper tconstpool:$addr)),
1298 (t2LDRHpci tconstpool:$addr)>;
1300 // FIXME: The destination register of the loads and stores can't be PC, but
1301 // can be SP. We need another regclass (similar to rGPR) to represent
1302 // that. Not a pressing issue since these are selected manually,
1307 let mayLoad = 1, neverHasSideEffects = 1 in {
1308 def t2LDR_PRE : T2Iidxldst<0, 0b10, 1, 1, (outs GPR:$Rt, GPR:$Rn),
1309 (ins t2addrmode_imm8:$addr),
1310 AddrModeT2_i8, IndexModePre, IIC_iLoad_iu,
1311 "ldr", "\t$Rt, $addr!", "$addr.base = $Rn",
1314 def t2LDR_POST : T2Iidxldst<0, 0b10, 1, 0, (outs GPR:$Rt, GPR:$Rn),
1315 (ins GPR:$base, t2am_imm8_offset:$addr),
1316 AddrModeT2_i8, IndexModePost, IIC_iLoad_iu,
1317 "ldr", "\t$Rt, [$Rn], $addr", "$base = $Rn",
1320 def t2LDRB_PRE : T2Iidxldst<0, 0b00, 1, 1, (outs GPR:$Rt, GPR:$Rn),
1321 (ins t2addrmode_imm8:$addr),
1322 AddrModeT2_i8, IndexModePre, IIC_iLoad_bh_iu,
1323 "ldrb", "\t$Rt, $addr!", "$addr.base = $Rn",
1325 def t2LDRB_POST : T2Iidxldst<0, 0b00, 1, 0, (outs GPR:$Rt, GPR:$Rn),
1326 (ins GPR:$base, t2am_imm8_offset:$addr),
1327 AddrModeT2_i8, IndexModePost, IIC_iLoad_bh_iu,
1328 "ldrb", "\t$Rt, [$Rn], $addr", "$base = $Rn",
1331 def t2LDRH_PRE : T2Iidxldst<0, 0b01, 1, 1, (outs GPR:$Rt, GPR:$Rn),
1332 (ins t2addrmode_imm8:$addr),
1333 AddrModeT2_i8, IndexModePre, IIC_iLoad_bh_iu,
1334 "ldrh", "\t$Rt, $addr!", "$addr.base = $Rn",
1336 def t2LDRH_POST : T2Iidxldst<0, 0b01, 1, 0, (outs GPR:$Rt, GPR:$Rn),
1337 (ins GPR:$base, t2am_imm8_offset:$addr),
1338 AddrModeT2_i8, IndexModePost, IIC_iLoad_bh_iu,
1339 "ldrh", "\t$Rt, [$Rn], $addr", "$base = $Rn",
1342 def t2LDRSB_PRE : T2Iidxldst<1, 0b00, 1, 1, (outs GPR:$Rt, GPR:$Rn),
1343 (ins t2addrmode_imm8:$addr),
1344 AddrModeT2_i8, IndexModePre, IIC_iLoad_bh_iu,
1345 "ldrsb", "\t$Rt, $addr!", "$addr.base = $Rn",
1347 def t2LDRSB_POST : T2Iidxldst<1, 0b00, 1, 0, (outs GPR:$Rt, GPR:$Rn),
1348 (ins GPR:$base, t2am_imm8_offset:$addr),
1349 AddrModeT2_i8, IndexModePost, IIC_iLoad_bh_iu,
1350 "ldrsb", "\t$Rt, [$Rn], $addr", "$base = $Rn",
1353 def t2LDRSH_PRE : T2Iidxldst<1, 0b01, 1, 1, (outs GPR:$Rt, GPR:$Rn),
1354 (ins t2addrmode_imm8:$addr),
1355 AddrModeT2_i8, IndexModePre, IIC_iLoad_bh_iu,
1356 "ldrsh", "\t$Rt, $addr!", "$addr.base = $Rn",
1358 def t2LDRSH_POST : T2Iidxldst<1, 0b01, 1, 0, (outs GPR:$dst, GPR:$Rn),
1359 (ins GPR:$base, t2am_imm8_offset:$addr),
1360 AddrModeT2_i8, IndexModePost, IIC_iLoad_bh_iu,
1361 "ldrsh", "\t$dst, [$Rn], $addr", "$base = $Rn",
1363 } // mayLoad = 1, neverHasSideEffects = 1
1365 // LDRT, LDRBT, LDRHT, LDRSBT, LDRSHT all have offset mode (PUW=0b110) and are
1366 // for disassembly only.
1367 // Ref: A8.6.57 LDR (immediate, Thumb) Encoding T4
1368 class T2IldT<bit signed, bits<2> type, string opc, InstrItinClass ii>
1369 : T2Ii8<(outs rGPR:$Rt), (ins t2addrmode_imm8:$addr), ii, opc,
1370 "\t$Rt, $addr", []> {
1371 let Inst{31-27} = 0b11111;
1372 let Inst{26-25} = 0b00;
1373 let Inst{24} = signed;
1375 let Inst{22-21} = type;
1376 let Inst{20} = 1; // load
1378 let Inst{10-8} = 0b110; // PUW.
1382 let Inst{15-12} = Rt;
1383 let Inst{19-16} = addr{12-9};
1384 let Inst{7-0} = addr{7-0};
1387 def t2LDRT : T2IldT<0, 0b10, "ldrt", IIC_iLoad_i>;
1388 def t2LDRBT : T2IldT<0, 0b00, "ldrbt", IIC_iLoad_bh_i>;
1389 def t2LDRHT : T2IldT<0, 0b01, "ldrht", IIC_iLoad_bh_i>;
1390 def t2LDRSBT : T2IldT<1, 0b00, "ldrsbt", IIC_iLoad_bh_i>;
1391 def t2LDRSHT : T2IldT<1, 0b01, "ldrsht", IIC_iLoad_bh_i>;
1394 defm t2STR :T2I_st<0b10,"str", IIC_iStore_i, IIC_iStore_si,
1395 BinOpFrag<(store node:$LHS, node:$RHS)>>;
1396 defm t2STRB:T2I_st<0b00,"strb", IIC_iStore_bh_i, IIC_iStore_bh_si,
1397 BinOpFrag<(truncstorei8 node:$LHS, node:$RHS)>>;
1398 defm t2STRH:T2I_st<0b01,"strh", IIC_iStore_bh_i, IIC_iStore_bh_si,
1399 BinOpFrag<(truncstorei16 node:$LHS, node:$RHS)>>;
1402 let mayLoad = 1, neverHasSideEffects = 1, hasExtraSrcRegAllocReq = 1 in
1403 def t2STRDi8 : T2Ii8s4<1, 0, 0, (outs),
1404 (ins GPR:$Rt, GPR:$Rt2, t2addrmode_imm8s4:$addr),
1405 IIC_iStore_d_r, "strd", "\t$Rt, $Rt2, $addr", []>;
1408 def t2STR_PRE : T2Iidxldst<0, 0b10, 0, 1, (outs GPR:$base_wb),
1409 (ins GPR:$Rt, GPR:$Rn, t2am_imm8_offset:$addr),
1410 AddrModeT2_i8, IndexModePre, IIC_iStore_iu,
1411 "str", "\t$Rt, [$Rn, $addr]!",
1412 "$Rn = $base_wb,@earlyclobber $base_wb",
1414 (pre_store GPR:$Rt, GPR:$Rn, t2am_imm8_offset:$addr))]>;
1416 def t2STR_POST : T2Iidxldst<0, 0b10, 0, 0, (outs GPR:$base_wb),
1417 (ins GPR:$Rt, GPR:$Rn, t2am_imm8_offset:$addr),
1418 AddrModeT2_i8, IndexModePost, IIC_iStore_iu,
1419 "str", "\t$Rt, [$Rn], $addr",
1420 "$Rn = $base_wb,@earlyclobber $base_wb",
1422 (post_store GPR:$Rt, GPR:$Rn, t2am_imm8_offset:$addr))]>;
1424 def t2STRH_PRE : T2Iidxldst<0, 0b01, 0, 1, (outs GPR:$base_wb),
1425 (ins GPR:$Rt, GPR:$Rn, t2am_imm8_offset:$addr),
1426 AddrModeT2_i8, IndexModePre, IIC_iStore_iu,
1427 "strh", "\t$Rt, [$Rn, $addr]!",
1428 "$Rn = $base_wb,@earlyclobber $base_wb",
1430 (pre_truncsti16 GPR:$Rt, GPR:$Rn, t2am_imm8_offset:$addr))]>;
1432 def t2STRH_POST : T2Iidxldst<0, 0b01, 0, 0, (outs GPR:$base_wb),
1433 (ins GPR:$Rt, GPR:$Rn, t2am_imm8_offset:$addr),
1434 AddrModeT2_i8, IndexModePost, IIC_iStore_bh_iu,
1435 "strh", "\t$Rt, [$Rn], $addr",
1436 "$Rn = $base_wb,@earlyclobber $base_wb",
1438 (post_truncsti16 GPR:$Rt, GPR:$Rn, t2am_imm8_offset:$addr))]>;
1440 def t2STRB_PRE : T2Iidxldst<0, 0b00, 0, 1, (outs GPR:$base_wb),
1441 (ins GPR:$Rt, GPR:$Rn, t2am_imm8_offset:$addr),
1442 AddrModeT2_i8, IndexModePre, IIC_iStore_bh_iu,
1443 "strb", "\t$Rt, [$Rn, $addr]!",
1444 "$Rn = $base_wb,@earlyclobber $base_wb",
1446 (pre_truncsti8 GPR:$Rt, GPR:$Rn, t2am_imm8_offset:$addr))]>;
1448 def t2STRB_POST : T2Iidxldst<0, 0b00, 0, 0, (outs GPR:$base_wb),
1449 (ins GPR:$Rt, GPR:$Rn, t2am_imm8_offset:$addr),
1450 AddrModeT2_i8, IndexModePost, IIC_iStore_bh_iu,
1451 "strb", "\t$Rt, [$Rn], $addr",
1452 "$Rn = $base_wb,@earlyclobber $base_wb",
1454 (post_truncsti8 GPR:$Rt, GPR:$Rn, t2am_imm8_offset:$addr))]>;
1456 // STRT, STRBT, STRHT all have offset mode (PUW=0b110) and are for disassembly
1458 // Ref: A8.6.193 STR (immediate, Thumb) Encoding T4
1459 class T2IstT<bits<2> type, string opc, InstrItinClass ii>
1460 : T2Ii8<(outs rGPR:$Rt), (ins t2addrmode_imm8:$addr), ii, opc,
1461 "\t$Rt, $addr", []> {
1462 let Inst{31-27} = 0b11111;
1463 let Inst{26-25} = 0b00;
1464 let Inst{24} = 0; // not signed
1466 let Inst{22-21} = type;
1467 let Inst{20} = 0; // store
1469 let Inst{10-8} = 0b110; // PUW
1473 let Inst{15-12} = Rt;
1474 let Inst{19-16} = addr{12-9};
1475 let Inst{7-0} = addr{7-0};
1478 def t2STRT : T2IstT<0b10, "strt", IIC_iStore_i>;
1479 def t2STRBT : T2IstT<0b00, "strbt", IIC_iStore_bh_i>;
1480 def t2STRHT : T2IstT<0b01, "strht", IIC_iStore_bh_i>;
1482 // ldrd / strd pre / post variants
1483 // For disassembly only.
1485 def t2LDRD_PRE : T2Ii8s4<1, 1, 1, (outs rGPR:$Rt, rGPR:$Rt2),
1486 (ins GPR:$base, t2am_imm8s4_offset:$imm), IIC_iLoad_d_ru,
1487 "ldrd", "\t$Rt, $Rt2, [$base, $imm]!", []>;
1489 def t2LDRD_POST : T2Ii8s4<0, 1, 1, (outs rGPR:$Rt, rGPR:$Rt2),
1490 (ins GPR:$base, t2am_imm8s4_offset:$imm), IIC_iLoad_d_ru,
1491 "ldrd", "\t$Rt, $Rt2, [$base], $imm", []>;
1493 def t2STRD_PRE : T2Ii8s4<1, 1, 0, (outs),
1494 (ins rGPR:$Rt, rGPR:$Rt2, GPR:$base, t2am_imm8s4_offset:$imm),
1495 IIC_iStore_d_ru, "strd", "\t$Rt, $Rt2, [$base, $imm]!", []>;
1497 def t2STRD_POST : T2Ii8s4<0, 1, 0, (outs),
1498 (ins rGPR:$Rt, rGPR:$Rt2, GPR:$base, t2am_imm8s4_offset:$imm),
1499 IIC_iStore_d_ru, "strd", "\t$Rt, $Rt2, [$base], $imm", []>;
1501 // T2Ipl (Preload Data/Instruction) signals the memory system of possible future
1502 // data/instruction access. These are for disassembly only.
1503 // instr_write is inverted for Thumb mode: (prefetch 3) -> (preload 0),
1504 // (prefetch 1) -> (preload 2), (prefetch 2) -> (preload 1).
1505 multiclass T2Ipl<bits<1> write, bits<1> instr, string opc> {
1507 def i12 : T2Ii12<(outs), (ins t2addrmode_imm12:$addr), IIC_Preload, opc,
1509 [(ARMPreload t2addrmode_imm12:$addr, (i32 write), (i32 instr))]> {
1510 let Inst{31-25} = 0b1111100;
1511 let Inst{24} = instr;
1513 let Inst{21} = write;
1515 let Inst{15-12} = 0b1111;
1518 let addr{12} = 1; // add = TRUE
1519 let Inst{19-16} = addr{16-13}; // Rn
1520 let Inst{23} = addr{12}; // U
1521 let Inst{11-0} = addr{11-0}; // imm12
1524 def i8 : T2Ii8<(outs), (ins t2addrmode_imm8:$addr), IIC_Preload, opc,
1526 [(ARMPreload t2addrmode_imm8:$addr, (i32 write), (i32 instr))]> {
1527 let Inst{31-25} = 0b1111100;
1528 let Inst{24} = instr;
1529 let Inst{23} = 0; // U = 0
1531 let Inst{21} = write;
1533 let Inst{15-12} = 0b1111;
1534 let Inst{11-8} = 0b1100;
1537 let Inst{19-16} = addr{12-9}; // Rn
1538 let Inst{7-0} = addr{7-0}; // imm8
1541 def s : T2Iso<(outs), (ins t2addrmode_so_reg:$addr), IIC_Preload, opc,
1543 [(ARMPreload t2addrmode_so_reg:$addr, (i32 write), (i32 instr))]> {
1544 let Inst{31-25} = 0b1111100;
1545 let Inst{24} = instr;
1546 let Inst{23} = 0; // add = TRUE for T1
1548 let Inst{21} = write;
1550 let Inst{15-12} = 0b1111;
1551 let Inst{11-6} = 0000000;
1554 let Inst{19-16} = addr{9-6}; // Rn
1555 let Inst{3-0} = addr{5-2}; // Rm
1556 let Inst{5-4} = addr{1-0}; // imm2
1560 defm t2PLD : T2Ipl<0, 0, "pld">, Requires<[IsThumb2]>;
1561 defm t2PLDW : T2Ipl<1, 0, "pldw">, Requires<[IsThumb2,HasV7,HasMP]>;
1562 defm t2PLI : T2Ipl<0, 1, "pli">, Requires<[IsThumb2,HasV7]>;
1564 //===----------------------------------------------------------------------===//
1565 // Load / store multiple Instructions.
1568 multiclass thumb2_ldst_mult<string asm, InstrItinClass itin,
1569 InstrItinClass itin_upd, bit L_bit> {
1571 T2XI<(outs), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops),
1572 itin, !strconcat(asm, "ia${p}.w\t$Rn, $regs"), []> {
1576 let Inst{31-27} = 0b11101;
1577 let Inst{26-25} = 0b00;
1578 let Inst{24-23} = 0b01; // Increment After
1580 let Inst{21} = 0; // No writeback
1581 let Inst{20} = L_bit;
1582 let Inst{19-16} = Rn;
1583 let Inst{15-0} = regs;
1586 T2XIt<(outs GPR:$wb), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops),
1587 itin_upd, !strconcat(asm, "ia${p}.w\t$Rn!, $regs"), "$Rn = $wb", []> {
1591 let Inst{31-27} = 0b11101;
1592 let Inst{26-25} = 0b00;
1593 let Inst{24-23} = 0b01; // Increment After
1595 let Inst{21} = 1; // Writeback
1596 let Inst{20} = L_bit;
1597 let Inst{19-16} = Rn;
1598 let Inst{15-0} = regs;
1601 T2XI<(outs), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops),
1602 itin, !strconcat(asm, "db${p}.w\t$Rn, $regs"), []> {
1606 let Inst{31-27} = 0b11101;
1607 let Inst{26-25} = 0b00;
1608 let Inst{24-23} = 0b10; // Decrement Before
1610 let Inst{21} = 0; // No writeback
1611 let Inst{20} = L_bit;
1612 let Inst{19-16} = Rn;
1613 let Inst{15-0} = regs;
1616 T2XIt<(outs GPR:$wb), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops),
1617 itin_upd, !strconcat(asm, "db${p}.w\t$Rn, $regs"), "$Rn = $wb", []> {
1621 let Inst{31-27} = 0b11101;
1622 let Inst{26-25} = 0b00;
1623 let Inst{24-23} = 0b10; // Decrement Before
1625 let Inst{21} = 1; // Writeback
1626 let Inst{20} = L_bit;
1627 let Inst{19-16} = Rn;
1628 let Inst{15-0} = regs;
1632 let neverHasSideEffects = 1 in {
1634 let mayLoad = 1, hasExtraDefRegAllocReq = 1 in
1635 defm t2LDM : thumb2_ldst_mult<"ldm", IIC_iLoad_m, IIC_iLoad_mu, 1>;
1637 let mayStore = 1, hasExtraSrcRegAllocReq = 1 in
1638 defm t2STM : thumb2_ldst_mult<"stm", IIC_iStore_m, IIC_iStore_mu, 0>;
1640 } // neverHasSideEffects
1643 //===----------------------------------------------------------------------===//
1644 // Move Instructions.
1647 let neverHasSideEffects = 1 in
1648 def t2MOVr : T2sTwoReg<(outs GPR:$Rd), (ins GPR:$Rm), IIC_iMOVr,
1649 "mov", ".w\t$Rd, $Rm", []> {
1650 let Inst{31-27} = 0b11101;
1651 let Inst{26-25} = 0b01;
1652 let Inst{24-21} = 0b0010;
1653 let Inst{19-16} = 0b1111; // Rn
1654 let Inst{14-12} = 0b000;
1655 let Inst{7-4} = 0b0000;
1658 // AddedComplexity to ensure isel tries t2MOVi before t2MOVi16.
1659 let isReMaterializable = 1, isAsCheapAsAMove = 1, isMoveImm = 1,
1660 AddedComplexity = 1 in
1661 def t2MOVi : T2sOneRegImm<(outs rGPR:$Rd), (ins t2_so_imm:$imm), IIC_iMOVi,
1662 "mov", ".w\t$Rd, $imm",
1663 [(set rGPR:$Rd, t2_so_imm:$imm)]> {
1664 let Inst{31-27} = 0b11110;
1666 let Inst{24-21} = 0b0010;
1667 let Inst{19-16} = 0b1111; // Rn
1671 let isReMaterializable = 1, isAsCheapAsAMove = 1, isMoveImm = 1 in
1672 def t2MOVi16 : T2I<(outs rGPR:$Rd), (ins i32imm_hilo16:$imm), IIC_iMOVi,
1673 "movw", "\t$Rd, $imm",
1674 [(set rGPR:$Rd, imm0_65535:$imm)]> {
1675 let Inst{31-27} = 0b11110;
1677 let Inst{24-21} = 0b0010;
1678 let Inst{20} = 0; // The S bit.
1684 let Inst{11-8} = Rd;
1685 let Inst{19-16} = imm{15-12};
1686 let Inst{26} = imm{11};
1687 let Inst{14-12} = imm{10-8};
1688 let Inst{7-0} = imm{7-0};
1691 def t2MOVi16_ga_pcrel : PseudoInst<(outs rGPR:$Rd),
1692 (ins i32imm:$addr, pclabel:$id), IIC_iMOVi, []>;
1694 let Constraints = "$src = $Rd" in {
1695 def t2MOVTi16 : T2I<(outs rGPR:$Rd),
1696 (ins rGPR:$src, i32imm_hilo16:$imm), IIC_iMOVi,
1697 "movt", "\t$Rd, $imm",
1699 (or (and rGPR:$src, 0xffff), lo16AllZero:$imm))]> {
1700 let Inst{31-27} = 0b11110;
1702 let Inst{24-21} = 0b0110;
1703 let Inst{20} = 0; // The S bit.
1709 let Inst{11-8} = Rd;
1710 let Inst{19-16} = imm{15-12};
1711 let Inst{26} = imm{11};
1712 let Inst{14-12} = imm{10-8};
1713 let Inst{7-0} = imm{7-0};
1716 def t2MOVTi16_ga_pcrel : PseudoInst<(outs rGPR:$Rd),
1717 (ins rGPR:$src, i32imm:$addr, pclabel:$id), IIC_iMOVi, []>;
1720 def : T2Pat<(or rGPR:$src, 0xffff0000), (t2MOVTi16 rGPR:$src, 0xffff)>;
1722 //===----------------------------------------------------------------------===//
1723 // Extend Instructions.
1728 defm t2SXTB : T2I_ext_rrot<0b100, "sxtb",
1729 UnOpFrag<(sext_inreg node:$Src, i8)>>;
1730 defm t2SXTH : T2I_ext_rrot<0b000, "sxth",
1731 UnOpFrag<(sext_inreg node:$Src, i16)>>;
1732 defm t2SXTB16 : T2I_ext_rrot_sxtb16<0b010, "sxtb16">;
1734 defm t2SXTAB : T2I_exta_rrot<0b100, "sxtab",
1735 BinOpFrag<(add node:$LHS, (sext_inreg node:$RHS, i8))>>;
1736 defm t2SXTAH : T2I_exta_rrot<0b000, "sxtah",
1737 BinOpFrag<(add node:$LHS, (sext_inreg node:$RHS,i16))>>;
1738 defm t2SXTAB16 : T2I_exta_rrot_DO<0b010, "sxtab16">;
1740 // TODO: SXT(A){B|H}16 - done for disassembly only
1744 let AddedComplexity = 16 in {
1745 defm t2UXTB : T2I_ext_rrot<0b101, "uxtb",
1746 UnOpFrag<(and node:$Src, 0x000000FF)>>;
1747 defm t2UXTH : T2I_ext_rrot<0b001, "uxth",
1748 UnOpFrag<(and node:$Src, 0x0000FFFF)>>;
1749 defm t2UXTB16 : T2I_ext_rrot_uxtb16<0b011, "uxtb16",
1750 UnOpFrag<(and node:$Src, 0x00FF00FF)>>;
1752 // FIXME: This pattern incorrectly assumes the shl operator is a rotate.
1753 // The transformation should probably be done as a combiner action
1754 // instead so we can include a check for masking back in the upper
1755 // eight bits of the source into the lower eight bits of the result.
1756 //def : T2Pat<(and (shl rGPR:$Src, (i32 8)), 0xFF00FF),
1757 // (t2UXTB16r_rot rGPR:$Src, 24)>,
1758 // Requires<[HasT2ExtractPack, IsThumb2]>;
1759 def : T2Pat<(and (srl rGPR:$Src, (i32 8)), 0xFF00FF),
1760 (t2UXTB16r_rot rGPR:$Src, 8)>,
1761 Requires<[HasT2ExtractPack, IsThumb2]>;
1763 defm t2UXTAB : T2I_exta_rrot<0b101, "uxtab",
1764 BinOpFrag<(add node:$LHS, (and node:$RHS, 0x00FF))>>;
1765 defm t2UXTAH : T2I_exta_rrot<0b001, "uxtah",
1766 BinOpFrag<(add node:$LHS, (and node:$RHS, 0xFFFF))>>;
1767 defm t2UXTAB16 : T2I_exta_rrot_DO<0b011, "uxtab16">;
1770 //===----------------------------------------------------------------------===//
1771 // Arithmetic Instructions.
1774 defm t2ADD : T2I_bin_ii12rs<0b000, "add",
1775 BinOpFrag<(add node:$LHS, node:$RHS)>, 1>;
1776 defm t2SUB : T2I_bin_ii12rs<0b101, "sub",
1777 BinOpFrag<(sub node:$LHS, node:$RHS)>>;
1779 // ADD and SUB with 's' bit set. No 12-bit immediate (T4) variants.
1780 defm t2ADDS : T2I_bin_s_irs <0b1000, "add",
1781 IIC_iALUi, IIC_iALUr, IIC_iALUsi,
1782 BinOpFrag<(addc node:$LHS, node:$RHS)>, 1>;
1783 defm t2SUBS : T2I_bin_s_irs <0b1101, "sub",
1784 IIC_iALUi, IIC_iALUr, IIC_iALUsi,
1785 BinOpFrag<(subc node:$LHS, node:$RHS)>>;
1787 defm t2ADC : T2I_adde_sube_irs<0b1010, "adc",
1788 BinOpFrag<(adde_dead_carry node:$LHS, node:$RHS)>, 1>;
1789 defm t2SBC : T2I_adde_sube_irs<0b1011, "sbc",
1790 BinOpFrag<(sube_dead_carry node:$LHS, node:$RHS)>>;
1791 defm t2ADCS : T2I_adde_sube_s_irs<BinOpFrag<(adde_live_carry node:$LHS, node:$RHS)>, 1>;
1792 defm t2SBCS : T2I_adde_sube_s_irs<BinOpFrag<(sube_live_carry node:$LHS, node:$RHS)>>;
1795 defm t2RSB : T2I_rbin_irs <0b1110, "rsb",
1796 BinOpFrag<(sub node:$LHS, node:$RHS)>>;
1797 defm t2RSBS : T2I_rbin_s_is <0b1110, "rsb",
1798 BinOpFrag<(subc node:$LHS, node:$RHS)>>;
1800 // (sub X, imm) gets canonicalized to (add X, -imm). Match this form.
1801 // The assume-no-carry-in form uses the negation of the input since add/sub
1802 // assume opposite meanings of the carry flag (i.e., carry == !borrow).
1803 // See the definition of AddWithCarry() in the ARM ARM A2.2.1 for the gory
1805 // The AddedComplexity preferences the first variant over the others since
1806 // it can be shrunk to a 16-bit wide encoding, while the others cannot.
1807 let AddedComplexity = 1 in
1808 def : T2Pat<(add GPR:$src, imm0_255_neg:$imm),
1809 (t2SUBri GPR:$src, imm0_255_neg:$imm)>;
1810 def : T2Pat<(add GPR:$src, t2_so_imm_neg:$imm),
1811 (t2SUBri GPR:$src, t2_so_imm_neg:$imm)>;
1812 def : T2Pat<(add GPR:$src, imm0_4095_neg:$imm),
1813 (t2SUBri12 GPR:$src, imm0_4095_neg:$imm)>;
1814 let AddedComplexity = 1 in
1815 def : T2Pat<(addc rGPR:$src, imm0_255_neg:$imm),
1816 (t2SUBSri rGPR:$src, imm0_255_neg:$imm)>;
1817 def : T2Pat<(addc rGPR:$src, t2_so_imm_neg:$imm),
1818 (t2SUBSri rGPR:$src, t2_so_imm_neg:$imm)>;
1819 // The with-carry-in form matches bitwise not instead of the negation.
1820 // Effectively, the inverse interpretation of the carry flag already accounts
1821 // for part of the negation.
1822 let AddedComplexity = 1 in
1823 def : T2Pat<(adde_dead_carry rGPR:$src, imm0_255_not:$imm),
1824 (t2SBCri rGPR:$src, imm0_255_not:$imm)>;
1825 def : T2Pat<(adde_dead_carry rGPR:$src, t2_so_imm_not:$imm),
1826 (t2SBCri rGPR:$src, t2_so_imm_not:$imm)>;
1827 let AddedComplexity = 1 in
1828 def : T2Pat<(adde_live_carry rGPR:$src, imm0_255_not:$imm),
1829 (t2SBCSri rGPR:$src, imm0_255_not:$imm)>;
1830 def : T2Pat<(adde_live_carry rGPR:$src, t2_so_imm_not:$imm),
1831 (t2SBCSri rGPR:$src, t2_so_imm_not:$imm)>;
1833 // Select Bytes -- for disassembly only
1835 def t2SEL : T2ThreeReg<(outs GPR:$Rd), (ins GPR:$Rn, GPR:$Rm),
1836 NoItinerary, "sel", "\t$Rd, $Rn, $Rm", []> {
1837 let Inst{31-27} = 0b11111;
1838 let Inst{26-24} = 0b010;
1840 let Inst{22-20} = 0b010;
1841 let Inst{15-12} = 0b1111;
1843 let Inst{6-4} = 0b000;
1846 // A6.3.13, A6.3.14, A6.3.15 Parallel addition and subtraction (signed/unsigned)
1847 // And Miscellaneous operations -- for disassembly only
1848 class T2I_pam<bits<3> op22_20, bits<4> op7_4, string opc,
1849 list<dag> pat = [/* For disassembly only; pattern left blank */],
1850 dag iops = (ins rGPR:$Rn, rGPR:$Rm),
1851 string asm = "\t$Rd, $Rn, $Rm">
1852 : T2I<(outs rGPR:$Rd), iops, NoItinerary, opc, asm, pat> {
1853 let Inst{31-27} = 0b11111;
1854 let Inst{26-23} = 0b0101;
1855 let Inst{22-20} = op22_20;
1856 let Inst{15-12} = 0b1111;
1857 let Inst{7-4} = op7_4;
1863 let Inst{11-8} = Rd;
1864 let Inst{19-16} = Rn;
1868 // Saturating add/subtract -- for disassembly only
1870 def t2QADD : T2I_pam<0b000, 0b1000, "qadd",
1871 [(set rGPR:$Rd, (int_arm_qadd rGPR:$Rn, rGPR:$Rm))],
1872 (ins rGPR:$Rm, rGPR:$Rn), "\t$Rd, $Rm, $Rn">;
1873 def t2QADD16 : T2I_pam<0b001, 0b0001, "qadd16">;
1874 def t2QADD8 : T2I_pam<0b000, 0b0001, "qadd8">;
1875 def t2QASX : T2I_pam<0b010, 0b0001, "qasx">;
1876 def t2QDADD : T2I_pam<0b000, 0b1001, "qdadd", [],
1877 (ins rGPR:$Rm, rGPR:$Rn), "\t$Rd, $Rm, $Rn">;
1878 def t2QDSUB : T2I_pam<0b000, 0b1011, "qdsub", [],
1879 (ins rGPR:$Rm, rGPR:$Rn), "\t$Rd, $Rm, $Rn">;
1880 def t2QSAX : T2I_pam<0b110, 0b0001, "qsax">;
1881 def t2QSUB : T2I_pam<0b000, 0b1010, "qsub",
1882 [(set rGPR:$Rd, (int_arm_qsub rGPR:$Rn, rGPR:$Rm))],
1883 (ins rGPR:$Rm, rGPR:$Rn), "\t$Rd, $Rm, $Rn">;
1884 def t2QSUB16 : T2I_pam<0b101, 0b0001, "qsub16">;
1885 def t2QSUB8 : T2I_pam<0b100, 0b0001, "qsub8">;
1886 def t2UQADD16 : T2I_pam<0b001, 0b0101, "uqadd16">;
1887 def t2UQADD8 : T2I_pam<0b000, 0b0101, "uqadd8">;
1888 def t2UQASX : T2I_pam<0b010, 0b0101, "uqasx">;
1889 def t2UQSAX : T2I_pam<0b110, 0b0101, "uqsax">;
1890 def t2UQSUB16 : T2I_pam<0b101, 0b0101, "uqsub16">;
1891 def t2UQSUB8 : T2I_pam<0b100, 0b0101, "uqsub8">;
1893 // Signed/Unsigned add/subtract -- for disassembly only
1895 def t2SASX : T2I_pam<0b010, 0b0000, "sasx">;
1896 def t2SADD16 : T2I_pam<0b001, 0b0000, "sadd16">;
1897 def t2SADD8 : T2I_pam<0b000, 0b0000, "sadd8">;
1898 def t2SSAX : T2I_pam<0b110, 0b0000, "ssax">;
1899 def t2SSUB16 : T2I_pam<0b101, 0b0000, "ssub16">;
1900 def t2SSUB8 : T2I_pam<0b100, 0b0000, "ssub8">;
1901 def t2UASX : T2I_pam<0b010, 0b0100, "uasx">;
1902 def t2UADD16 : T2I_pam<0b001, 0b0100, "uadd16">;
1903 def t2UADD8 : T2I_pam<0b000, 0b0100, "uadd8">;
1904 def t2USAX : T2I_pam<0b110, 0b0100, "usax">;
1905 def t2USUB16 : T2I_pam<0b101, 0b0100, "usub16">;
1906 def t2USUB8 : T2I_pam<0b100, 0b0100, "usub8">;
1908 // Signed/Unsigned halving add/subtract -- for disassembly only
1910 def t2SHASX : T2I_pam<0b010, 0b0010, "shasx">;
1911 def t2SHADD16 : T2I_pam<0b001, 0b0010, "shadd16">;
1912 def t2SHADD8 : T2I_pam<0b000, 0b0010, "shadd8">;
1913 def t2SHSAX : T2I_pam<0b110, 0b0010, "shsax">;
1914 def t2SHSUB16 : T2I_pam<0b101, 0b0010, "shsub16">;
1915 def t2SHSUB8 : T2I_pam<0b100, 0b0010, "shsub8">;
1916 def t2UHASX : T2I_pam<0b010, 0b0110, "uhasx">;
1917 def t2UHADD16 : T2I_pam<0b001, 0b0110, "uhadd16">;
1918 def t2UHADD8 : T2I_pam<0b000, 0b0110, "uhadd8">;
1919 def t2UHSAX : T2I_pam<0b110, 0b0110, "uhsax">;
1920 def t2UHSUB16 : T2I_pam<0b101, 0b0110, "uhsub16">;
1921 def t2UHSUB8 : T2I_pam<0b100, 0b0110, "uhsub8">;
1923 // Helper class for disassembly only
1924 // A6.3.16 & A6.3.17
1925 // T2Imac - Thumb2 multiply [accumulate, and absolute difference] instructions.
1926 class T2ThreeReg_mac<bit long, bits<3> op22_20, bits<4> op7_4, dag oops,
1927 dag iops, InstrItinClass itin, string opc, string asm, list<dag> pattern>
1928 : T2ThreeReg<oops, iops, itin, opc, asm, pattern> {
1929 let Inst{31-27} = 0b11111;
1930 let Inst{26-24} = 0b011;
1931 let Inst{23} = long;
1932 let Inst{22-20} = op22_20;
1933 let Inst{7-4} = op7_4;
1936 class T2FourReg_mac<bit long, bits<3> op22_20, bits<4> op7_4, dag oops,
1937 dag iops, InstrItinClass itin, string opc, string asm, list<dag> pattern>
1938 : T2FourReg<oops, iops, itin, opc, asm, pattern> {
1939 let Inst{31-27} = 0b11111;
1940 let Inst{26-24} = 0b011;
1941 let Inst{23} = long;
1942 let Inst{22-20} = op22_20;
1943 let Inst{7-4} = op7_4;
1946 // Unsigned Sum of Absolute Differences [and Accumulate] -- for disassembly only
1948 def t2USAD8 : T2ThreeReg_mac<0, 0b111, 0b0000, (outs rGPR:$Rd),
1949 (ins rGPR:$Rn, rGPR:$Rm),
1950 NoItinerary, "usad8", "\t$Rd, $Rn, $Rm", []> {
1951 let Inst{15-12} = 0b1111;
1953 def t2USADA8 : T2FourReg_mac<0, 0b111, 0b0000, (outs rGPR:$Rd),
1954 (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), NoItinerary,
1955 "usada8", "\t$Rd, $Rn, $Rm, $Ra", []>;
1957 // Signed/Unsigned saturate -- for disassembly only
1959 class T2SatI<dag oops, dag iops, InstrItinClass itin,
1960 string opc, string asm, list<dag> pattern>
1961 : T2I<oops, iops, itin, opc, asm, pattern> {
1967 let Inst{11-8} = Rd;
1968 let Inst{19-16} = Rn;
1969 let Inst{4-0} = sat_imm{4-0};
1970 let Inst{21} = sh{6};
1971 let Inst{14-12} = sh{4-2};
1972 let Inst{7-6} = sh{1-0};
1976 (outs rGPR:$Rd), (ins i32imm:$sat_imm, rGPR:$Rn, shift_imm:$sh),
1977 NoItinerary, "ssat", "\t$Rd, $sat_imm, $Rn$sh",
1978 [/* For disassembly only; pattern left blank */]> {
1979 let Inst{31-27} = 0b11110;
1980 let Inst{25-22} = 0b1100;
1985 def t2SSAT16: T2SatI<
1986 (outs rGPR:$Rd), (ins i32imm:$sat_imm, rGPR:$Rn), NoItinerary,
1987 "ssat16", "\t$Rd, $sat_imm, $Rn",
1988 [/* For disassembly only; pattern left blank */]> {
1989 let Inst{31-27} = 0b11110;
1990 let Inst{25-22} = 0b1100;
1993 let Inst{21} = 1; // sh = '1'
1994 let Inst{14-12} = 0b000; // imm3 = '000'
1995 let Inst{7-6} = 0b00; // imm2 = '00'
1999 (outs rGPR:$Rd), (ins i32imm:$sat_imm, rGPR:$Rn, shift_imm:$sh),
2000 NoItinerary, "usat", "\t$Rd, $sat_imm, $Rn$sh",
2001 [/* For disassembly only; pattern left blank */]> {
2002 let Inst{31-27} = 0b11110;
2003 let Inst{25-22} = 0b1110;
2008 def t2USAT16: T2SatI<
2009 (outs rGPR:$dst), (ins i32imm:$sat_imm, rGPR:$Rn), NoItinerary,
2010 "usat16", "\t$dst, $sat_imm, $Rn",
2011 [/* For disassembly only; pattern left blank */]> {
2012 let Inst{31-27} = 0b11110;
2013 let Inst{25-22} = 0b1110;
2016 let Inst{21} = 1; // sh = '1'
2017 let Inst{14-12} = 0b000; // imm3 = '000'
2018 let Inst{7-6} = 0b00; // imm2 = '00'
2021 def : T2Pat<(int_arm_ssat GPR:$a, imm:$pos), (t2SSAT imm:$pos, GPR:$a, 0)>;
2022 def : T2Pat<(int_arm_usat GPR:$a, imm:$pos), (t2USAT imm:$pos, GPR:$a, 0)>;
2024 //===----------------------------------------------------------------------===//
2025 // Shift and rotate Instructions.
2028 defm t2LSL : T2I_sh_ir<0b00, "lsl", BinOpFrag<(shl node:$LHS, node:$RHS)>>;
2029 defm t2LSR : T2I_sh_ir<0b01, "lsr", BinOpFrag<(srl node:$LHS, node:$RHS)>>;
2030 defm t2ASR : T2I_sh_ir<0b10, "asr", BinOpFrag<(sra node:$LHS, node:$RHS)>>;
2031 defm t2ROR : T2I_sh_ir<0b11, "ror", BinOpFrag<(rotr node:$LHS, node:$RHS)>>;
2033 // (rotr x, (and y, 0x...1f)) ==> (ROR x, y)
2034 def : Pat<(rotr rGPR:$lhs, (and rGPR:$rhs, lo5AllOne)),
2035 (t2RORrr rGPR:$lhs, rGPR:$rhs)>;
2037 let Uses = [CPSR] in {
2038 def t2RRX : T2sTwoReg<(outs rGPR:$Rd), (ins rGPR:$Rm), IIC_iMOVsi,
2039 "rrx", "\t$Rd, $Rm",
2040 [(set rGPR:$Rd, (ARMrrx rGPR:$Rm))]> {
2041 let Inst{31-27} = 0b11101;
2042 let Inst{26-25} = 0b01;
2043 let Inst{24-21} = 0b0010;
2044 let Inst{19-16} = 0b1111; // Rn
2045 let Inst{14-12} = 0b000;
2046 let Inst{7-4} = 0b0011;
2050 let isCodeGenOnly = 1, Defs = [CPSR] in {
2051 def t2MOVsrl_flag : T2TwoRegShiftImm<
2052 (outs rGPR:$Rd), (ins rGPR:$Rm), IIC_iMOVsi,
2053 "lsrs", ".w\t$Rd, $Rm, #1",
2054 [(set rGPR:$Rd, (ARMsrl_flag rGPR:$Rm))]> {
2055 let Inst{31-27} = 0b11101;
2056 let Inst{26-25} = 0b01;
2057 let Inst{24-21} = 0b0010;
2058 let Inst{20} = 1; // The S bit.
2059 let Inst{19-16} = 0b1111; // Rn
2060 let Inst{5-4} = 0b01; // Shift type.
2061 // Shift amount = Inst{14-12:7-6} = 1.
2062 let Inst{14-12} = 0b000;
2063 let Inst{7-6} = 0b01;
2065 def t2MOVsra_flag : T2TwoRegShiftImm<
2066 (outs rGPR:$Rd), (ins rGPR:$Rm), IIC_iMOVsi,
2067 "asrs", ".w\t$Rd, $Rm, #1",
2068 [(set rGPR:$Rd, (ARMsra_flag rGPR:$Rm))]> {
2069 let Inst{31-27} = 0b11101;
2070 let Inst{26-25} = 0b01;
2071 let Inst{24-21} = 0b0010;
2072 let Inst{20} = 1; // The S bit.
2073 let Inst{19-16} = 0b1111; // Rn
2074 let Inst{5-4} = 0b10; // Shift type.
2075 // Shift amount = Inst{14-12:7-6} = 1.
2076 let Inst{14-12} = 0b000;
2077 let Inst{7-6} = 0b01;
2081 //===----------------------------------------------------------------------===//
2082 // Bitwise Instructions.
2085 defm t2AND : T2I_bin_w_irs<0b0000, "and",
2086 IIC_iBITi, IIC_iBITr, IIC_iBITsi,
2087 BinOpFrag<(and node:$LHS, node:$RHS)>, 1>;
2088 defm t2ORR : T2I_bin_w_irs<0b0010, "orr",
2089 IIC_iBITi, IIC_iBITr, IIC_iBITsi,
2090 BinOpFrag<(or node:$LHS, node:$RHS)>, 1>;
2091 defm t2EOR : T2I_bin_w_irs<0b0100, "eor",
2092 IIC_iBITi, IIC_iBITr, IIC_iBITsi,
2093 BinOpFrag<(xor node:$LHS, node:$RHS)>, 1>;
2095 defm t2BIC : T2I_bin_w_irs<0b0001, "bic",
2096 IIC_iBITi, IIC_iBITr, IIC_iBITsi,
2097 BinOpFrag<(and node:$LHS, (not node:$RHS))>>;
2099 class T2BitFI<dag oops, dag iops, InstrItinClass itin,
2100 string opc, string asm, list<dag> pattern>
2101 : T2I<oops, iops, itin, opc, asm, pattern> {
2106 let Inst{11-8} = Rd;
2107 let Inst{4-0} = msb{4-0};
2108 let Inst{14-12} = lsb{4-2};
2109 let Inst{7-6} = lsb{1-0};
2112 class T2TwoRegBitFI<dag oops, dag iops, InstrItinClass itin,
2113 string opc, string asm, list<dag> pattern>
2114 : T2BitFI<oops, iops, itin, opc, asm, pattern> {
2117 let Inst{19-16} = Rn;
2120 let Constraints = "$src = $Rd" in
2121 def t2BFC : T2BitFI<(outs rGPR:$Rd), (ins rGPR:$src, bf_inv_mask_imm:$imm),
2122 IIC_iUNAsi, "bfc", "\t$Rd, $imm",
2123 [(set rGPR:$Rd, (and rGPR:$src, bf_inv_mask_imm:$imm))]> {
2124 let Inst{31-27} = 0b11110;
2125 let Inst{26} = 0; // should be 0.
2127 let Inst{24-20} = 0b10110;
2128 let Inst{19-16} = 0b1111; // Rn
2130 let Inst{5} = 0; // should be 0.
2133 let msb{4-0} = imm{9-5};
2134 let lsb{4-0} = imm{4-0};
2137 def t2SBFX: T2TwoRegBitFI<
2138 (outs rGPR:$Rd), (ins rGPR:$Rn, imm0_31:$lsb, imm0_31_m1:$msb),
2139 IIC_iUNAsi, "sbfx", "\t$Rd, $Rn, $lsb, $msb", []> {
2140 let Inst{31-27} = 0b11110;
2142 let Inst{24-20} = 0b10100;
2146 def t2UBFX: T2TwoRegBitFI<
2147 (outs rGPR:$Rd), (ins rGPR:$Rn, imm0_31:$lsb, imm0_31_m1:$msb),
2148 IIC_iUNAsi, "ubfx", "\t$Rd, $Rn, $lsb, $msb", []> {
2149 let Inst{31-27} = 0b11110;
2151 let Inst{24-20} = 0b11100;
2155 // A8.6.18 BFI - Bitfield insert (Encoding T1)
2156 let Constraints = "$src = $Rd" in {
2157 def t2BFI : T2TwoRegBitFI<(outs rGPR:$Rd),
2158 (ins rGPR:$src, rGPR:$Rn, bf_inv_mask_imm:$imm),
2159 IIC_iBITi, "bfi", "\t$Rd, $Rn, $imm",
2160 [(set rGPR:$Rd, (ARMbfi rGPR:$src, rGPR:$Rn,
2161 bf_inv_mask_imm:$imm))]> {
2162 let Inst{31-27} = 0b11110;
2163 let Inst{26} = 0; // should be 0.
2165 let Inst{24-20} = 0b10110;
2167 let Inst{5} = 0; // should be 0.
2170 let msb{4-0} = imm{9-5};
2171 let lsb{4-0} = imm{4-0};
2174 // GNU as only supports this form of bfi (w/ 4 arguments)
2175 let isAsmParserOnly = 1 in
2176 def t2BFI4p : T2TwoRegBitFI<(outs rGPR:$Rd),
2177 (ins rGPR:$src, rGPR:$Rn, lsb_pos_imm:$lsbit,
2179 IIC_iBITi, "bfi", "\t$Rd, $Rn, $lsbit, $width",
2181 let Inst{31-27} = 0b11110;
2182 let Inst{26} = 0; // should be 0.
2184 let Inst{24-20} = 0b10110;
2186 let Inst{5} = 0; // should be 0.
2190 let msb{4-0} = width; // Custom encoder => lsb+width-1
2191 let lsb{4-0} = lsbit;
2195 defm t2ORN : T2I_bin_irs<0b0011, "orn",
2196 IIC_iBITi, IIC_iBITr, IIC_iBITsi,
2197 BinOpFrag<(or node:$LHS, (not node:$RHS))>, 0, "">;
2199 // Prefer over of t2EORri ra, rb, -1 because mvn has 16-bit version
2200 let AddedComplexity = 1 in
2201 defm t2MVN : T2I_un_irs <0b0011, "mvn",
2202 IIC_iMVNi, IIC_iMVNr, IIC_iMVNsi,
2203 UnOpFrag<(not node:$Src)>, 1, 1>;
2206 let AddedComplexity = 1 in
2207 def : T2Pat<(and rGPR:$src, t2_so_imm_not:$imm),
2208 (t2BICri rGPR:$src, t2_so_imm_not:$imm)>;
2210 // FIXME: Disable this pattern on Darwin to workaround an assembler bug.
2211 def : T2Pat<(or rGPR:$src, t2_so_imm_not:$imm),
2212 (t2ORNri rGPR:$src, t2_so_imm_not:$imm)>,
2213 Requires<[IsThumb2]>;
2215 def : T2Pat<(t2_so_imm_not:$src),
2216 (t2MVNi t2_so_imm_not:$src)>;
2218 //===----------------------------------------------------------------------===//
2219 // Multiply Instructions.
2221 let isCommutable = 1 in
2222 def t2MUL: T2ThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iMUL32,
2223 "mul", "\t$Rd, $Rn, $Rm",
2224 [(set rGPR:$Rd, (mul rGPR:$Rn, rGPR:$Rm))]> {
2225 let Inst{31-27} = 0b11111;
2226 let Inst{26-23} = 0b0110;
2227 let Inst{22-20} = 0b000;
2228 let Inst{15-12} = 0b1111; // Ra = 0b1111 (no accumulate)
2229 let Inst{7-4} = 0b0000; // Multiply
2232 def t2MLA: T2FourReg<
2233 (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC32,
2234 "mla", "\t$Rd, $Rn, $Rm, $Ra",
2235 [(set rGPR:$Rd, (add (mul rGPR:$Rn, rGPR:$Rm), rGPR:$Ra))]> {
2236 let Inst{31-27} = 0b11111;
2237 let Inst{26-23} = 0b0110;
2238 let Inst{22-20} = 0b000;
2239 let Inst{7-4} = 0b0000; // Multiply
2242 def t2MLS: T2FourReg<
2243 (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC32,
2244 "mls", "\t$Rd, $Rn, $Rm, $Ra",
2245 [(set rGPR:$Rd, (sub rGPR:$Ra, (mul rGPR:$Rn, rGPR:$Rm)))]> {
2246 let Inst{31-27} = 0b11111;
2247 let Inst{26-23} = 0b0110;
2248 let Inst{22-20} = 0b000;
2249 let Inst{7-4} = 0b0001; // Multiply and Subtract
2252 // Extra precision multiplies with low / high results
2253 let neverHasSideEffects = 1 in {
2254 let isCommutable = 1 in {
2255 def t2SMULL : T2MulLong<0b000, 0b0000,
2256 (outs rGPR:$Rd, rGPR:$Ra),
2257 (ins rGPR:$Rn, rGPR:$Rm), IIC_iMUL64,
2258 "smull", "\t$Rd, $Ra, $Rn, $Rm", []>;
2260 def t2UMULL : T2MulLong<0b010, 0b0000,
2261 (outs rGPR:$RdLo, rGPR:$RdHi),
2262 (ins rGPR:$Rn, rGPR:$Rm), IIC_iMUL64,
2263 "umull", "\t$RdLo, $RdHi, $Rn, $Rm", []>;
2266 // Multiply + accumulate
2267 def t2SMLAL : T2MulLong<0b100, 0b0000,
2268 (outs rGPR:$RdLo, rGPR:$RdHi),
2269 (ins rGPR:$Rn, rGPR:$Rm), IIC_iMAC64,
2270 "smlal", "\t$RdLo, $RdHi, $Rn, $Rm", []>;
2272 def t2UMLAL : T2MulLong<0b110, 0b0000,
2273 (outs rGPR:$RdLo, rGPR:$RdHi),
2274 (ins rGPR:$Rn, rGPR:$Rm), IIC_iMAC64,
2275 "umlal", "\t$RdLo, $RdHi, $Rn, $Rm", []>;
2277 def t2UMAAL : T2MulLong<0b110, 0b0110,
2278 (outs rGPR:$RdLo, rGPR:$RdHi),
2279 (ins rGPR:$Rn, rGPR:$Rm), IIC_iMAC64,
2280 "umaal", "\t$RdLo, $RdHi, $Rn, $Rm", []>;
2281 } // neverHasSideEffects
2283 // Rounding variants of the below included for disassembly only
2285 // Most significant word multiply
2286 def t2SMMUL : T2ThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iMUL32,
2287 "smmul", "\t$Rd, $Rn, $Rm",
2288 [(set rGPR:$Rd, (mulhs rGPR:$Rn, rGPR:$Rm))]> {
2289 let Inst{31-27} = 0b11111;
2290 let Inst{26-23} = 0b0110;
2291 let Inst{22-20} = 0b101;
2292 let Inst{15-12} = 0b1111; // Ra = 0b1111 (no accumulate)
2293 let Inst{7-4} = 0b0000; // No Rounding (Inst{4} = 0)
2296 def t2SMMULR : T2ThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iMUL32,
2297 "smmulr", "\t$Rd, $Rn, $Rm", []> {
2298 let Inst{31-27} = 0b11111;
2299 let Inst{26-23} = 0b0110;
2300 let Inst{22-20} = 0b101;
2301 let Inst{15-12} = 0b1111; // Ra = 0b1111 (no accumulate)
2302 let Inst{7-4} = 0b0001; // Rounding (Inst{4} = 1)
2305 def t2SMMLA : T2FourReg<
2306 (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC32,
2307 "smmla", "\t$Rd, $Rn, $Rm, $Ra",
2308 [(set rGPR:$Rd, (add (mulhs rGPR:$Rm, rGPR:$Rn), rGPR:$Ra))]> {
2309 let Inst{31-27} = 0b11111;
2310 let Inst{26-23} = 0b0110;
2311 let Inst{22-20} = 0b101;
2312 let Inst{7-4} = 0b0000; // No Rounding (Inst{4} = 0)
2315 def t2SMMLAR: T2FourReg<
2316 (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC32,
2317 "smmlar", "\t$Rd, $Rn, $Rm, $Ra", []> {
2318 let Inst{31-27} = 0b11111;
2319 let Inst{26-23} = 0b0110;
2320 let Inst{22-20} = 0b101;
2321 let Inst{7-4} = 0b0001; // Rounding (Inst{4} = 1)
2324 def t2SMMLS: T2FourReg<
2325 (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC32,
2326 "smmls", "\t$Rd, $Rn, $Rm, $Ra",
2327 [(set rGPR:$Rd, (sub rGPR:$Ra, (mulhs rGPR:$Rn, rGPR:$Rm)))]> {
2328 let Inst{31-27} = 0b11111;
2329 let Inst{26-23} = 0b0110;
2330 let Inst{22-20} = 0b110;
2331 let Inst{7-4} = 0b0000; // No Rounding (Inst{4} = 0)
2334 def t2SMMLSR:T2FourReg<
2335 (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC32,
2336 "smmlsr", "\t$Rd, $Rn, $Rm, $Ra", []> {
2337 let Inst{31-27} = 0b11111;
2338 let Inst{26-23} = 0b0110;
2339 let Inst{22-20} = 0b110;
2340 let Inst{7-4} = 0b0001; // Rounding (Inst{4} = 1)
2343 multiclass T2I_smul<string opc, PatFrag opnode> {
2344 def BB : T2ThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iMUL16,
2345 !strconcat(opc, "bb"), "\t$Rd, $Rn, $Rm",
2346 [(set rGPR:$Rd, (opnode (sext_inreg rGPR:$Rn, i16),
2347 (sext_inreg rGPR:$Rm, i16)))]> {
2348 let Inst{31-27} = 0b11111;
2349 let Inst{26-23} = 0b0110;
2350 let Inst{22-20} = 0b001;
2351 let Inst{15-12} = 0b1111; // Ra = 0b1111 (no accumulate)
2352 let Inst{7-6} = 0b00;
2353 let Inst{5-4} = 0b00;
2356 def BT : T2ThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iMUL16,
2357 !strconcat(opc, "bt"), "\t$Rd, $Rn, $Rm",
2358 [(set rGPR:$Rd, (opnode (sext_inreg rGPR:$Rn, i16),
2359 (sra rGPR:$Rm, (i32 16))))]> {
2360 let Inst{31-27} = 0b11111;
2361 let Inst{26-23} = 0b0110;
2362 let Inst{22-20} = 0b001;
2363 let Inst{15-12} = 0b1111; // Ra = 0b1111 (no accumulate)
2364 let Inst{7-6} = 0b00;
2365 let Inst{5-4} = 0b01;
2368 def TB : T2ThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iMUL16,
2369 !strconcat(opc, "tb"), "\t$Rd, $Rn, $Rm",
2370 [(set rGPR:$Rd, (opnode (sra rGPR:$Rn, (i32 16)),
2371 (sext_inreg rGPR:$Rm, i16)))]> {
2372 let Inst{31-27} = 0b11111;
2373 let Inst{26-23} = 0b0110;
2374 let Inst{22-20} = 0b001;
2375 let Inst{15-12} = 0b1111; // Ra = 0b1111 (no accumulate)
2376 let Inst{7-6} = 0b00;
2377 let Inst{5-4} = 0b10;
2380 def TT : T2ThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iMUL16,
2381 !strconcat(opc, "tt"), "\t$Rd, $Rn, $Rm",
2382 [(set rGPR:$Rd, (opnode (sra rGPR:$Rn, (i32 16)),
2383 (sra rGPR:$Rm, (i32 16))))]> {
2384 let Inst{31-27} = 0b11111;
2385 let Inst{26-23} = 0b0110;
2386 let Inst{22-20} = 0b001;
2387 let Inst{15-12} = 0b1111; // Ra = 0b1111 (no accumulate)
2388 let Inst{7-6} = 0b00;
2389 let Inst{5-4} = 0b11;
2392 def WB : T2ThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iMUL16,
2393 !strconcat(opc, "wb"), "\t$Rd, $Rn, $Rm",
2394 [(set rGPR:$Rd, (sra (opnode rGPR:$Rn,
2395 (sext_inreg rGPR:$Rm, i16)), (i32 16)))]> {
2396 let Inst{31-27} = 0b11111;
2397 let Inst{26-23} = 0b0110;
2398 let Inst{22-20} = 0b011;
2399 let Inst{15-12} = 0b1111; // Ra = 0b1111 (no accumulate)
2400 let Inst{7-6} = 0b00;
2401 let Inst{5-4} = 0b00;
2404 def WT : T2ThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iMUL16,
2405 !strconcat(opc, "wt"), "\t$Rd, $Rn, $Rm",
2406 [(set rGPR:$Rd, (sra (opnode rGPR:$Rn,
2407 (sra rGPR:$Rm, (i32 16))), (i32 16)))]> {
2408 let Inst{31-27} = 0b11111;
2409 let Inst{26-23} = 0b0110;
2410 let Inst{22-20} = 0b011;
2411 let Inst{15-12} = 0b1111; // Ra = 0b1111 (no accumulate)
2412 let Inst{7-6} = 0b00;
2413 let Inst{5-4} = 0b01;
2418 multiclass T2I_smla<string opc, PatFrag opnode> {
2420 (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC16,
2421 !strconcat(opc, "bb"), "\t$Rd, $Rn, $Rm, $Ra",
2422 [(set rGPR:$Rd, (add rGPR:$Ra,
2423 (opnode (sext_inreg rGPR:$Rn, i16),
2424 (sext_inreg rGPR:$Rm, i16))))]> {
2425 let Inst{31-27} = 0b11111;
2426 let Inst{26-23} = 0b0110;
2427 let Inst{22-20} = 0b001;
2428 let Inst{7-6} = 0b00;
2429 let Inst{5-4} = 0b00;
2433 (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC16,
2434 !strconcat(opc, "bt"), "\t$Rd, $Rn, $Rm, $Ra",
2435 [(set rGPR:$Rd, (add rGPR:$Ra, (opnode (sext_inreg rGPR:$Rn, i16),
2436 (sra rGPR:$Rm, (i32 16)))))]> {
2437 let Inst{31-27} = 0b11111;
2438 let Inst{26-23} = 0b0110;
2439 let Inst{22-20} = 0b001;
2440 let Inst{7-6} = 0b00;
2441 let Inst{5-4} = 0b01;
2445 (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC16,
2446 !strconcat(opc, "tb"), "\t$Rd, $Rn, $Rm, $Ra",
2447 [(set rGPR:$Rd, (add rGPR:$Ra, (opnode (sra rGPR:$Rn, (i32 16)),
2448 (sext_inreg rGPR:$Rm, i16))))]> {
2449 let Inst{31-27} = 0b11111;
2450 let Inst{26-23} = 0b0110;
2451 let Inst{22-20} = 0b001;
2452 let Inst{7-6} = 0b00;
2453 let Inst{5-4} = 0b10;
2457 (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC16,
2458 !strconcat(opc, "tt"), "\t$Rd, $Rn, $Rm, $Ra",
2459 [(set rGPR:$Rd, (add rGPR:$Ra, (opnode (sra rGPR:$Rn, (i32 16)),
2460 (sra rGPR:$Rm, (i32 16)))))]> {
2461 let Inst{31-27} = 0b11111;
2462 let Inst{26-23} = 0b0110;
2463 let Inst{22-20} = 0b001;
2464 let Inst{7-6} = 0b00;
2465 let Inst{5-4} = 0b11;
2469 (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC16,
2470 !strconcat(opc, "wb"), "\t$Rd, $Rn, $Rm, $Ra",
2471 [(set rGPR:$Rd, (add rGPR:$Ra, (sra (opnode rGPR:$Rn,
2472 (sext_inreg rGPR:$Rm, i16)), (i32 16))))]> {
2473 let Inst{31-27} = 0b11111;
2474 let Inst{26-23} = 0b0110;
2475 let Inst{22-20} = 0b011;
2476 let Inst{7-6} = 0b00;
2477 let Inst{5-4} = 0b00;
2481 (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC16,
2482 !strconcat(opc, "wt"), "\t$Rd, $Rn, $Rm, $Ra",
2483 [(set rGPR:$Rd, (add rGPR:$Ra, (sra (opnode rGPR:$Rn,
2484 (sra rGPR:$Rm, (i32 16))), (i32 16))))]> {
2485 let Inst{31-27} = 0b11111;
2486 let Inst{26-23} = 0b0110;
2487 let Inst{22-20} = 0b011;
2488 let Inst{7-6} = 0b00;
2489 let Inst{5-4} = 0b01;
2493 defm t2SMUL : T2I_smul<"smul", BinOpFrag<(mul node:$LHS, node:$RHS)>>;
2494 defm t2SMLA : T2I_smla<"smla", BinOpFrag<(mul node:$LHS, node:$RHS)>>;
2496 // Halfword multiple accumulate long: SMLAL<x><y> -- for disassembly only
2497 def t2SMLALBB : T2FourReg_mac<1, 0b100, 0b1000, (outs rGPR:$Ra,rGPR:$Rd),
2498 (ins rGPR:$Rn,rGPR:$Rm), IIC_iMAC64, "smlalbb", "\t$Ra, $Rd, $Rn, $Rm",
2499 [/* For disassembly only; pattern left blank */]>;
2500 def t2SMLALBT : T2FourReg_mac<1, 0b100, 0b1001, (outs rGPR:$Ra,rGPR:$Rd),
2501 (ins rGPR:$Rn,rGPR:$Rm), IIC_iMAC64, "smlalbt", "\t$Ra, $Rd, $Rn, $Rm",
2502 [/* For disassembly only; pattern left blank */]>;
2503 def t2SMLALTB : T2FourReg_mac<1, 0b100, 0b1010, (outs rGPR:$Ra,rGPR:$Rd),
2504 (ins rGPR:$Rn,rGPR:$Rm), IIC_iMAC64, "smlaltb", "\t$Ra, $Rd, $Rn, $Rm",
2505 [/* For disassembly only; pattern left blank */]>;
2506 def t2SMLALTT : T2FourReg_mac<1, 0b100, 0b1011, (outs rGPR:$Ra,rGPR:$Rd),
2507 (ins rGPR:$Rn,rGPR:$Rm), IIC_iMAC64, "smlaltt", "\t$Ra, $Rd, $Rn, $Rm",
2508 [/* For disassembly only; pattern left blank */]>;
2510 // Dual halfword multiple: SMUAD, SMUSD, SMLAD, SMLSD, SMLALD, SMLSLD
2511 // These are for disassembly only.
2513 def t2SMUAD: T2ThreeReg_mac<
2514 0, 0b010, 0b0000, (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm),
2515 IIC_iMAC32, "smuad", "\t$Rd, $Rn, $Rm", []> {
2516 let Inst{15-12} = 0b1111;
2518 def t2SMUADX:T2ThreeReg_mac<
2519 0, 0b010, 0b0001, (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm),
2520 IIC_iMAC32, "smuadx", "\t$Rd, $Rn, $Rm", []> {
2521 let Inst{15-12} = 0b1111;
2523 def t2SMUSD: T2ThreeReg_mac<
2524 0, 0b100, 0b0000, (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm),
2525 IIC_iMAC32, "smusd", "\t$Rd, $Rn, $Rm", []> {
2526 let Inst{15-12} = 0b1111;
2528 def t2SMUSDX:T2ThreeReg_mac<
2529 0, 0b100, 0b0001, (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm),
2530 IIC_iMAC32, "smusdx", "\t$Rd, $Rn, $Rm", []> {
2531 let Inst{15-12} = 0b1111;
2533 def t2SMLAD : T2ThreeReg_mac<
2534 0, 0b010, 0b0000, (outs rGPR:$Rd),
2535 (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC32, "smlad",
2536 "\t$Rd, $Rn, $Rm, $Ra", []>;
2537 def t2SMLADX : T2FourReg_mac<
2538 0, 0b010, 0b0001, (outs rGPR:$Rd),
2539 (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC32, "smladx",
2540 "\t$Rd, $Rn, $Rm, $Ra", []>;
2541 def t2SMLSD : T2FourReg_mac<0, 0b100, 0b0000, (outs rGPR:$Rd),
2542 (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC32, "smlsd",
2543 "\t$Rd, $Rn, $Rm, $Ra", []>;
2544 def t2SMLSDX : T2FourReg_mac<0, 0b100, 0b0001, (outs rGPR:$Rd),
2545 (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC32, "smlsdx",
2546 "\t$Rd, $Rn, $Rm, $Ra", []>;
2547 def t2SMLALD : T2FourReg_mac<1, 0b100, 0b1100, (outs rGPR:$Ra,rGPR:$Rd),
2548 (ins rGPR:$Rm, rGPR:$Rn), IIC_iMAC64, "smlald",
2549 "\t$Ra, $Rd, $Rm, $Rn", []>;
2550 def t2SMLALDX : T2FourReg_mac<1, 0b100, 0b1101, (outs rGPR:$Ra,rGPR:$Rd),
2551 (ins rGPR:$Rm,rGPR:$Rn), IIC_iMAC64, "smlaldx",
2552 "\t$Ra, $Rd, $Rm, $Rn", []>;
2553 def t2SMLSLD : T2FourReg_mac<1, 0b101, 0b1100, (outs rGPR:$Ra,rGPR:$Rd),
2554 (ins rGPR:$Rm,rGPR:$Rn), IIC_iMAC64, "smlsld",
2555 "\t$Ra, $Rd, $Rm, $Rn", []>;
2556 def t2SMLSLDX : T2FourReg_mac<1, 0b101, 0b1101, (outs rGPR:$Ra,rGPR:$Rd),
2557 (ins rGPR:$Rm,rGPR:$Rn), IIC_iMAC64, "smlsldx",
2558 "\t$Ra, $Rd, $Rm, $Rn", []>;
2560 //===----------------------------------------------------------------------===//
2561 // Misc. Arithmetic Instructions.
2564 class T2I_misc<bits<2> op1, bits<2> op2, dag oops, dag iops,
2565 InstrItinClass itin, string opc, string asm, list<dag> pattern>
2566 : T2ThreeReg<oops, iops, itin, opc, asm, pattern> {
2567 let Inst{31-27} = 0b11111;
2568 let Inst{26-22} = 0b01010;
2569 let Inst{21-20} = op1;
2570 let Inst{15-12} = 0b1111;
2571 let Inst{7-6} = 0b10;
2572 let Inst{5-4} = op2;
2576 def t2CLZ : T2I_misc<0b11, 0b00, (outs rGPR:$Rd), (ins rGPR:$Rm), IIC_iUNAr,
2577 "clz", "\t$Rd, $Rm", [(set rGPR:$Rd, (ctlz rGPR:$Rm))]>;
2579 def t2RBIT : T2I_misc<0b01, 0b10, (outs rGPR:$Rd), (ins rGPR:$Rm), IIC_iUNAr,
2580 "rbit", "\t$Rd, $Rm",
2581 [(set rGPR:$Rd, (ARMrbit rGPR:$Rm))]>;
2583 def t2REV : T2I_misc<0b01, 0b00, (outs rGPR:$Rd), (ins rGPR:$Rm), IIC_iUNAr,
2584 "rev", ".w\t$Rd, $Rm", [(set rGPR:$Rd, (bswap rGPR:$Rm))]>;
2586 def t2REV16 : T2I_misc<0b01, 0b01, (outs rGPR:$Rd), (ins rGPR:$Rm), IIC_iUNAr,
2587 "rev16", ".w\t$Rd, $Rm",
2589 (or (and (srl rGPR:$Rm, (i32 8)), 0xFF),
2590 (or (and (shl rGPR:$Rm, (i32 8)), 0xFF00),
2591 (or (and (srl rGPR:$Rm, (i32 8)), 0xFF0000),
2592 (and (shl rGPR:$Rm, (i32 8)), 0xFF000000)))))]>;
2594 def t2REVSH : T2I_misc<0b01, 0b11, (outs rGPR:$Rd), (ins rGPR:$Rm), IIC_iUNAr,
2595 "revsh", ".w\t$Rd, $Rm",
2598 (or (srl rGPR:$Rm, (i32 8)),
2599 (shl rGPR:$Rm, (i32 8))), i16))]>;
2601 def : T2Pat<(sext_inreg (or (srl (and rGPR:$Rm, 0xFF00), (i32 8)),
2602 (shl rGPR:$Rm, (i32 8))), i16),
2603 (t2REVSH rGPR:$Rm)>;
2605 def : T2Pat<(sra (bswap rGPR:$Rm), (i32 16)), (t2REVSH rGPR:$Rm)>;
2607 def t2PKHBT : T2ThreeReg<
2608 (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, shift_imm:$sh),
2609 IIC_iBITsi, "pkhbt", "\t$Rd, $Rn, $Rm$sh",
2610 [(set rGPR:$Rd, (or (and rGPR:$Rn, 0xFFFF),
2611 (and (shl rGPR:$Rm, lsl_amt:$sh),
2613 Requires<[HasT2ExtractPack, IsThumb2]> {
2614 let Inst{31-27} = 0b11101;
2615 let Inst{26-25} = 0b01;
2616 let Inst{24-20} = 0b01100;
2617 let Inst{5} = 0; // BT form
2621 let Inst{14-12} = sh{7-5};
2622 let Inst{7-6} = sh{4-3};
2625 // Alternate cases for PKHBT where identities eliminate some nodes.
2626 def : T2Pat<(or (and rGPR:$src1, 0xFFFF), (and rGPR:$src2, 0xFFFF0000)),
2627 (t2PKHBT rGPR:$src1, rGPR:$src2, 0)>,
2628 Requires<[HasT2ExtractPack, IsThumb2]>;
2629 def : T2Pat<(or (and rGPR:$src1, 0xFFFF), (shl rGPR:$src2, imm16_31:$sh)),
2630 (t2PKHBT rGPR:$src1, rGPR:$src2, (lsl_shift_imm imm16_31:$sh))>,
2631 Requires<[HasT2ExtractPack, IsThumb2]>;
2633 // Note: Shifts of 1-15 bits will be transformed to srl instead of sra and
2634 // will match the pattern below.
2635 def t2PKHTB : T2ThreeReg<
2636 (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, shift_imm:$sh),
2637 IIC_iBITsi, "pkhtb", "\t$Rd, $Rn, $Rm$sh",
2638 [(set rGPR:$Rd, (or (and rGPR:$Rn, 0xFFFF0000),
2639 (and (sra rGPR:$Rm, asr_amt:$sh),
2641 Requires<[HasT2ExtractPack, IsThumb2]> {
2642 let Inst{31-27} = 0b11101;
2643 let Inst{26-25} = 0b01;
2644 let Inst{24-20} = 0b01100;
2645 let Inst{5} = 1; // TB form
2649 let Inst{14-12} = sh{7-5};
2650 let Inst{7-6} = sh{4-3};
2653 // Alternate cases for PKHTB where identities eliminate some nodes. Note that
2654 // a shift amount of 0 is *not legal* here, it is PKHBT instead.
2655 def : T2Pat<(or (and rGPR:$src1, 0xFFFF0000), (srl rGPR:$src2, imm16_31:$sh)),
2656 (t2PKHTB rGPR:$src1, rGPR:$src2, (asr_shift_imm imm16_31:$sh))>,
2657 Requires<[HasT2ExtractPack, IsThumb2]>;
2658 def : T2Pat<(or (and rGPR:$src1, 0xFFFF0000),
2659 (and (srl rGPR:$src2, imm1_15:$sh), 0xFFFF)),
2660 (t2PKHTB rGPR:$src1, rGPR:$src2, (asr_shift_imm imm1_15:$sh))>,
2661 Requires<[HasT2ExtractPack, IsThumb2]>;
2663 //===----------------------------------------------------------------------===//
2664 // Comparison Instructions...
2666 defm t2CMP : T2I_cmp_irs<0b1101, "cmp",
2667 IIC_iCMPi, IIC_iCMPr, IIC_iCMPsi,
2668 BinOpFrag<(ARMcmp node:$LHS, node:$RHS)>>;
2670 def : T2Pat<(ARMcmpZ GPR:$lhs, t2_so_imm:$imm),
2671 (t2CMPri GPR:$lhs, t2_so_imm:$imm)>;
2672 def : T2Pat<(ARMcmpZ GPR:$lhs, rGPR:$rhs),
2673 (t2CMPrr GPR:$lhs, rGPR:$rhs)>;
2674 def : T2Pat<(ARMcmpZ GPR:$lhs, t2_so_reg:$rhs),
2675 (t2CMPrs GPR:$lhs, t2_so_reg:$rhs)>;
2677 //FIXME: Disable CMN, as CCodes are backwards from compare expectations
2678 // Compare-to-zero still works out, just not the relationals
2679 //defm t2CMN : T2I_cmp_irs<0b1000, "cmn",
2680 // BinOpFrag<(ARMcmp node:$LHS,(ineg node:$RHS))>>;
2681 defm t2CMNz : T2I_cmp_irs<0b1000, "cmn",
2682 IIC_iCMPi, IIC_iCMPr, IIC_iCMPsi,
2683 BinOpFrag<(ARMcmpZ node:$LHS,(ineg node:$RHS))>>;
2685 //def : T2Pat<(ARMcmp GPR:$src, t2_so_imm_neg:$imm),
2686 // (t2CMNri GPR:$src, t2_so_imm_neg:$imm)>;
2688 def : T2Pat<(ARMcmpZ GPR:$src, t2_so_imm_neg:$imm),
2689 (t2CMNzri GPR:$src, t2_so_imm_neg:$imm)>;
2691 defm t2TST : T2I_cmp_irs<0b0000, "tst",
2692 IIC_iTSTi, IIC_iTSTr, IIC_iTSTsi,
2693 BinOpFrag<(ARMcmpZ (and_su node:$LHS, node:$RHS), 0)>>;
2694 defm t2TEQ : T2I_cmp_irs<0b0100, "teq",
2695 IIC_iTSTi, IIC_iTSTr, IIC_iTSTsi,
2696 BinOpFrag<(ARMcmpZ (xor_su node:$LHS, node:$RHS), 0)>>;
2698 // Conditional moves
2699 // FIXME: should be able to write a pattern for ARMcmov, but can't use
2700 // a two-value operand where a dag node expects two operands. :(
2701 let neverHasSideEffects = 1 in {
2702 def t2MOVCCr : T2TwoReg<
2703 (outs rGPR:$Rd), (ins rGPR:$false, rGPR:$Rm), IIC_iCMOVr,
2704 "mov", ".w\t$Rd, $Rm",
2705 [/*(set rGPR:$Rd, (ARMcmov rGPR:$false, rGPR:$Rm, imm:$cc, CCR:$ccr))*/]>,
2706 RegConstraint<"$false = $Rd"> {
2707 let Inst{31-27} = 0b11101;
2708 let Inst{26-25} = 0b01;
2709 let Inst{24-21} = 0b0010;
2710 let Inst{20} = 0; // The S bit.
2711 let Inst{19-16} = 0b1111; // Rn
2712 let Inst{14-12} = 0b000;
2713 let Inst{7-4} = 0b0000;
2716 let isMoveImm = 1 in
2717 def t2MOVCCi : T2OneRegImm<(outs rGPR:$Rd), (ins rGPR:$false, t2_so_imm:$imm),
2718 IIC_iCMOVi, "mov", ".w\t$Rd, $imm",
2719 [/*(set rGPR:$Rd,(ARMcmov rGPR:$false,t2_so_imm:$imm, imm:$cc, CCR:$ccr))*/]>,
2720 RegConstraint<"$false = $Rd"> {
2721 let Inst{31-27} = 0b11110;
2723 let Inst{24-21} = 0b0010;
2724 let Inst{20} = 0; // The S bit.
2725 let Inst{19-16} = 0b1111; // Rn
2729 let isMoveImm = 1 in
2730 def t2MOVCCi16 : T2I<(outs rGPR:$Rd), (ins rGPR:$false, i32imm_hilo16:$imm),
2732 "movw", "\t$Rd, $imm", []>,
2733 RegConstraint<"$false = $Rd"> {
2734 let Inst{31-27} = 0b11110;
2736 let Inst{24-21} = 0b0010;
2737 let Inst{20} = 0; // The S bit.
2743 let Inst{11-8} = Rd;
2744 let Inst{19-16} = imm{15-12};
2745 let Inst{26} = imm{11};
2746 let Inst{14-12} = imm{10-8};
2747 let Inst{7-0} = imm{7-0};
2750 let isMoveImm = 1 in
2751 def t2MOVCCi32imm : PseudoInst<(outs rGPR:$dst),
2752 (ins rGPR:$false, i32imm:$src, pred:$p),
2753 IIC_iCMOVix2, []>, RegConstraint<"$false = $dst">;
2755 let isMoveImm = 1 in
2756 def t2MVNCCi : T2OneRegImm<(outs rGPR:$Rd), (ins rGPR:$false, t2_so_imm:$imm),
2757 IIC_iCMOVi, "mvn", ".w\t$Rd, $imm",
2758 [/*(set rGPR:$Rd,(ARMcmov rGPR:$false,t2_so_imm_not:$imm,
2759 imm:$cc, CCR:$ccr))*/]>,
2760 RegConstraint<"$false = $Rd"> {
2761 let Inst{31-27} = 0b11110;
2763 let Inst{24-21} = 0b0011;
2764 let Inst{20} = 0; // The S bit.
2765 let Inst{19-16} = 0b1111; // Rn
2769 class T2I_movcc_sh<bits<2> opcod, dag oops, dag iops, InstrItinClass itin,
2770 string opc, string asm, list<dag> pattern>
2771 : T2TwoRegShiftImm<oops, iops, itin, opc, asm, pattern> {
2772 let Inst{31-27} = 0b11101;
2773 let Inst{26-25} = 0b01;
2774 let Inst{24-21} = 0b0010;
2775 let Inst{20} = 0; // The S bit.
2776 let Inst{19-16} = 0b1111; // Rn
2777 let Inst{5-4} = opcod; // Shift type.
2779 def t2MOVCClsl : T2I_movcc_sh<0b00, (outs rGPR:$Rd),
2780 (ins rGPR:$false, rGPR:$Rm, i32imm:$imm),
2781 IIC_iCMOVsi, "lsl", ".w\t$Rd, $Rm, $imm", []>,
2782 RegConstraint<"$false = $Rd">;
2783 def t2MOVCClsr : T2I_movcc_sh<0b01, (outs rGPR:$Rd),
2784 (ins rGPR:$false, rGPR:$Rm, i32imm:$imm),
2785 IIC_iCMOVsi, "lsr", ".w\t$Rd, $Rm, $imm", []>,
2786 RegConstraint<"$false = $Rd">;
2787 def t2MOVCCasr : T2I_movcc_sh<0b10, (outs rGPR:$Rd),
2788 (ins rGPR:$false, rGPR:$Rm, i32imm:$imm),
2789 IIC_iCMOVsi, "asr", ".w\t$Rd, $Rm, $imm", []>,
2790 RegConstraint<"$false = $Rd">;
2791 def t2MOVCCror : T2I_movcc_sh<0b11, (outs rGPR:$Rd),
2792 (ins rGPR:$false, rGPR:$Rm, i32imm:$imm),
2793 IIC_iCMOVsi, "ror", ".w\t$Rd, $Rm, $imm", []>,
2794 RegConstraint<"$false = $Rd">;
2795 } // neverHasSideEffects
2797 //===----------------------------------------------------------------------===//
2798 // Atomic operations intrinsics
2801 // memory barriers protect the atomic sequences
2802 let hasSideEffects = 1 in {
2803 def t2DMB : AInoP<(outs), (ins memb_opt:$opt), ThumbFrm, NoItinerary,
2804 "dmb", "\t$opt", [(ARMMemBarrier (i32 imm:$opt))]>,
2805 Requires<[IsThumb, HasDB]> {
2807 let Inst{31-4} = 0xf3bf8f5;
2808 let Inst{3-0} = opt;
2812 def t2DSB : AInoP<(outs), (ins memb_opt:$opt), ThumbFrm, NoItinerary,
2814 [/* For disassembly only; pattern left blank */]>,
2815 Requires<[IsThumb, HasDB]> {
2817 let Inst{31-4} = 0xf3bf8f4;
2818 let Inst{3-0} = opt;
2821 // ISB has only full system option -- for disassembly only
2822 def t2ISB : AInoP<(outs), (ins), ThumbFrm, NoItinerary, "isb", "",
2823 [/* For disassembly only; pattern left blank */]>,
2824 Requires<[IsThumb2, HasV7]> {
2825 let Inst{31-4} = 0xf3bf8f6;
2826 let Inst{3-0} = 0b1111;
2829 class T2I_ldrex<bits<2> opcod, dag oops, dag iops, AddrMode am, SizeFlagVal sz,
2830 InstrItinClass itin, string opc, string asm, string cstr,
2831 list<dag> pattern, bits<4> rt2 = 0b1111>
2832 : Thumb2I<oops, iops, am, sz, itin, opc, asm, cstr, pattern> {
2833 let Inst{31-27} = 0b11101;
2834 let Inst{26-20} = 0b0001101;
2835 let Inst{11-8} = rt2;
2836 let Inst{7-6} = 0b01;
2837 let Inst{5-4} = opcod;
2838 let Inst{3-0} = 0b1111;
2842 let Inst{19-16} = addr;
2843 let Inst{15-12} = Rt;
2845 class T2I_strex<bits<2> opcod, dag oops, dag iops, AddrMode am, SizeFlagVal sz,
2846 InstrItinClass itin, string opc, string asm, string cstr,
2847 list<dag> pattern, bits<4> rt2 = 0b1111>
2848 : Thumb2I<oops, iops, am, sz, itin, opc, asm, cstr, pattern> {
2849 let Inst{31-27} = 0b11101;
2850 let Inst{26-20} = 0b0001100;
2851 let Inst{11-8} = rt2;
2852 let Inst{7-6} = 0b01;
2853 let Inst{5-4} = opcod;
2859 let Inst{19-16} = addr;
2860 let Inst{15-12} = Rt;
2863 let mayLoad = 1 in {
2864 def t2LDREXB : T2I_ldrex<0b00, (outs rGPR:$Rt), (ins t2addrmode_reg:$addr), AddrModeNone,
2865 Size4Bytes, NoItinerary, "ldrexb", "\t$Rt, $addr",
2867 def t2LDREXH : T2I_ldrex<0b01, (outs rGPR:$Rt), (ins t2addrmode_reg:$addr), AddrModeNone,
2868 Size4Bytes, NoItinerary, "ldrexh", "\t$Rt, $addr",
2870 def t2LDREX : Thumb2I<(outs rGPR:$Rt), (ins t2addrmode_reg:$addr), AddrModeNone,
2871 Size4Bytes, NoItinerary,
2872 "ldrex", "\t$Rt, $addr", "",
2874 let Inst{31-27} = 0b11101;
2875 let Inst{26-20} = 0b0000101;
2876 let Inst{11-8} = 0b1111;
2877 let Inst{7-0} = 0b00000000; // imm8 = 0
2881 let Inst{19-16} = addr;
2882 let Inst{15-12} = Rt;
2884 def t2LDREXD : T2I_ldrex<0b11, (outs rGPR:$Rt, rGPR:$Rt2), (ins t2addrmode_reg:$addr),
2885 AddrModeNone, Size4Bytes, NoItinerary,
2886 "ldrexd", "\t$Rt, $Rt2, $addr", "",
2889 let Inst{11-8} = Rt2;
2893 let mayStore = 1, Constraints = "@earlyclobber $Rd" in {
2894 def t2STREXB : T2I_strex<0b00, (outs rGPR:$Rd), (ins rGPR:$Rt, t2addrmode_reg:$addr),
2895 AddrModeNone, Size4Bytes, NoItinerary,
2896 "strexb", "\t$Rd, $Rt, $addr", "", []>;
2897 def t2STREXH : T2I_strex<0b01, (outs rGPR:$Rd), (ins rGPR:$Rt, t2addrmode_reg:$addr),
2898 AddrModeNone, Size4Bytes, NoItinerary,
2899 "strexh", "\t$Rd, $Rt, $addr", "", []>;
2900 def t2STREX : Thumb2I<(outs rGPR:$Rd), (ins rGPR:$Rt, t2addrmode_reg:$addr),
2901 AddrModeNone, Size4Bytes, NoItinerary,
2902 "strex", "\t$Rd, $Rt, $addr", "",
2904 let Inst{31-27} = 0b11101;
2905 let Inst{26-20} = 0b0000100;
2906 let Inst{7-0} = 0b00000000; // imm8 = 0
2911 let Inst{11-8} = Rd;
2912 let Inst{19-16} = addr;
2913 let Inst{15-12} = Rt;
2915 def t2STREXD : T2I_strex<0b11, (outs rGPR:$Rd),
2916 (ins rGPR:$Rt, rGPR:$Rt2, t2addrmode_reg:$addr),
2917 AddrModeNone, Size4Bytes, NoItinerary,
2918 "strexd", "\t$Rd, $Rt, $Rt2, $addr", "", [],
2921 let Inst{11-8} = Rt2;
2925 // Clear-Exclusive is for disassembly only.
2926 def t2CLREX : T2XI<(outs), (ins), NoItinerary, "clrex",
2927 [/* For disassembly only; pattern left blank */]>,
2928 Requires<[IsThumb2, HasV7]> {
2929 let Inst{31-16} = 0xf3bf;
2930 let Inst{15-14} = 0b10;
2933 let Inst{11-8} = 0b1111;
2934 let Inst{7-4} = 0b0010;
2935 let Inst{3-0} = 0b1111;
2938 //===----------------------------------------------------------------------===//
2942 // __aeabi_read_tp preserves the registers r1-r3.
2944 Defs = [R0, R12, LR, CPSR], Uses = [SP] in {
2945 def t2TPsoft : T2XI<(outs), (ins), IIC_Br,
2946 "bl\t__aeabi_read_tp",
2947 [(set R0, ARMthread_pointer)]> {
2948 let Inst{31-27} = 0b11110;
2949 let Inst{15-14} = 0b11;
2954 //===----------------------------------------------------------------------===//
2955 // SJLJ Exception handling intrinsics
2956 // eh_sjlj_setjmp() is an instruction sequence to store the return
2957 // address and save #0 in R0 for the non-longjmp case.
2958 // Since by its nature we may be coming from some other function to get
2959 // here, and we're using the stack frame for the containing function to
2960 // save/restore registers, we can't keep anything live in regs across
2961 // the eh_sjlj_setjmp(), else it will almost certainly have been tromped upon
2962 // when we get here from a longjmp(). We force everything out of registers
2963 // except for our own input by listing the relevant registers in Defs. By
2964 // doing so, we also cause the prologue/epilogue code to actively preserve
2965 // all of the callee-saved resgisters, which is exactly what we want.
2966 // $val is a scratch register for our use.
2968 [ R0, R1, R2, R3, R4, R5, R6, R7, R8, R9, R10, R11, R12, LR, D0,
2969 D1, D2, D3, D4, D5, D6, D7, D8, D9, D10, D11, D12, D13, D14, D15,
2970 D16, D17, D18, D19, D20, D21, D22, D23, D24, D25, D26, D27, D28, D29, D30,
2971 D31 ], hasSideEffects = 1, isBarrier = 1, isCodeGenOnly = 1 in {
2972 def t2Int_eh_sjlj_setjmp : Thumb2XI<(outs), (ins tGPR:$src, tGPR:$val),
2973 AddrModeNone, SizeSpecial, NoItinerary, "", "",
2974 [(set R0, (ARMeh_sjlj_setjmp tGPR:$src, tGPR:$val))]>,
2975 Requires<[IsThumb2, HasVFP2]>;
2979 [ R0, R1, R2, R3, R4, R5, R6, R7, R8, R9, R10, R11, R12, LR ],
2980 hasSideEffects = 1, isBarrier = 1, isCodeGenOnly = 1 in {
2981 def t2Int_eh_sjlj_setjmp_nofp : Thumb2XI<(outs), (ins tGPR:$src, tGPR:$val),
2982 AddrModeNone, SizeSpecial, NoItinerary, "", "",
2983 [(set R0, (ARMeh_sjlj_setjmp tGPR:$src, tGPR:$val))]>,
2984 Requires<[IsThumb2, NoVFP]>;
2988 //===----------------------------------------------------------------------===//
2989 // Control-Flow Instructions
2992 // FIXME: remove when we have a way to marking a MI with these properties.
2993 // FIXME: $dst1 should be a def. But the extra ops must be in the end of the
2995 // FIXME: Should pc be an implicit operand like PICADD, etc?
2996 let isReturn = 1, isTerminator = 1, isBarrier = 1, mayLoad = 1,
2997 hasExtraDefRegAllocReq = 1, isCodeGenOnly = 1 in
2998 def t2LDMIA_RET: T2XIt<(outs GPR:$wb), (ins GPR:$Rn, pred:$p,
2999 reglist:$regs, variable_ops),
3001 "ldmia${p}.w\t$Rn!, $regs",
3006 let Inst{31-27} = 0b11101;
3007 let Inst{26-25} = 0b00;
3008 let Inst{24-23} = 0b01; // Increment After
3010 let Inst{21} = 1; // Writeback
3012 let Inst{19-16} = Rn;
3013 let Inst{15-0} = regs;
3016 let isBranch = 1, isTerminator = 1, isBarrier = 1 in {
3017 let isPredicable = 1 in
3018 def t2B : T2XI<(outs), (ins uncondbrtarget:$target), IIC_Br,
3020 [(br bb:$target)]> {
3021 let Inst{31-27} = 0b11110;
3022 let Inst{15-14} = 0b10;
3026 let Inst{26} = target{19};
3027 let Inst{11} = target{18};
3028 let Inst{13} = target{17};
3029 let Inst{21-16} = target{16-11};
3030 let Inst{10-0} = target{10-0};
3033 let isNotDuplicable = 1, isIndirectBranch = 1 in {
3034 def t2BR_JT : t2PseudoInst<(outs),
3035 (ins GPR:$target, GPR:$index, i32imm:$jt, i32imm:$id),
3036 SizeSpecial, IIC_Br,
3037 [(ARMbr2jt GPR:$target, GPR:$index, tjumptable:$jt, imm:$id)]>;
3039 // FIXME: Add a non-pc based case that can be predicated.
3040 def t2TBB_JT : t2PseudoInst<(outs),
3041 (ins GPR:$index, i32imm:$jt, i32imm:$id),
3042 SizeSpecial, IIC_Br, []>;
3044 def t2TBH_JT : t2PseudoInst<(outs),
3045 (ins GPR:$index, i32imm:$jt, i32imm:$id),
3046 SizeSpecial, IIC_Br, []>;
3048 def t2TBB : T2I<(outs), (ins GPR:$Rn, GPR:$Rm), IIC_Br,
3049 "tbb", "\t[$Rn, $Rm]", []> {
3052 let Inst{31-20} = 0b111010001101;
3053 let Inst{19-16} = Rn;
3054 let Inst{15-5} = 0b11110000000;
3055 let Inst{4} = 0; // B form
3059 def t2TBH : T2I<(outs), (ins GPR:$Rn, GPR:$Rm), IIC_Br,
3060 "tbh", "\t[$Rn, $Rm, lsl #1]", []> {
3063 let Inst{31-20} = 0b111010001101;
3064 let Inst{19-16} = Rn;
3065 let Inst{15-5} = 0b11110000000;
3066 let Inst{4} = 1; // H form
3069 } // isNotDuplicable, isIndirectBranch
3071 } // isBranch, isTerminator, isBarrier
3073 // FIXME: should be able to write a pattern for ARMBrcond, but can't use
3074 // a two-value operand where a dag node expects two operands. :(
3075 let isBranch = 1, isTerminator = 1 in
3076 def t2Bcc : T2I<(outs), (ins brtarget:$target), IIC_Br,
3078 [/*(ARMbrcond bb:$target, imm:$cc)*/]> {
3079 let Inst{31-27} = 0b11110;
3080 let Inst{15-14} = 0b10;
3084 let Inst{25-22} = p;
3087 let Inst{26} = target{20};
3088 let Inst{11} = target{19};
3089 let Inst{13} = target{18};
3090 let Inst{21-16} = target{17-12};
3091 let Inst{10-0} = target{11-1};
3096 let Defs = [ITSTATE] in
3097 def t2IT : Thumb2XI<(outs), (ins it_pred:$cc, it_mask:$mask),
3098 AddrModeNone, Size2Bytes, IIC_iALUx,
3099 "it$mask\t$cc", "", []> {
3100 // 16-bit instruction.
3101 let Inst{31-16} = 0x0000;
3102 let Inst{15-8} = 0b10111111;
3107 let Inst{3-0} = mask;
3110 // Branch and Exchange Jazelle -- for disassembly only
3112 def t2BXJ : T2I<(outs), (ins rGPR:$func), NoItinerary, "bxj", "\t$func",
3113 [/* For disassembly only; pattern left blank */]> {
3114 let Inst{31-27} = 0b11110;
3116 let Inst{25-20} = 0b111100;
3117 let Inst{15-14} = 0b10;
3121 let Inst{19-16} = func;
3124 // Change Processor State is a system instruction -- for disassembly and
3126 // FIXME: Since the asm parser has currently no clean way to handle optional
3127 // operands, create 3 versions of the same instruction. Once there's a clean
3128 // framework to represent optional operands, change this behavior.
3129 class t2CPS<dag iops, string asm_op> : T2XI<(outs), iops, NoItinerary,
3130 !strconcat("cps", asm_op),
3131 [/* For disassembly only; pattern left blank */]> {
3137 let Inst{31-27} = 0b11110;
3139 let Inst{25-20} = 0b111010;
3140 let Inst{19-16} = 0b1111;
3141 let Inst{15-14} = 0b10;
3143 let Inst{10-9} = imod;
3145 let Inst{7-5} = iflags;
3146 let Inst{4-0} = mode;
3150 def t2CPS3p : t2CPS<(ins imod_op:$imod, iflags_op:$iflags, i32imm:$mode),
3151 "$imod.w\t$iflags, $mode">;
3152 let mode = 0, M = 0 in
3153 def t2CPS2p : t2CPS<(ins imod_op:$imod, iflags_op:$iflags),
3154 "$imod.w\t$iflags">;
3155 let imod = 0, iflags = 0, M = 1 in
3156 def t2CPS1p : t2CPS<(ins i32imm:$mode), "\t$mode">;
3158 // A6.3.4 Branches and miscellaneous control
3159 // Table A6-14 Change Processor State, and hint instructions
3160 // Helper class for disassembly only.
3161 class T2I_hint<bits<8> op7_0, string opc, string asm>
3162 : T2I<(outs), (ins), NoItinerary, opc, asm,
3163 [/* For disassembly only; pattern left blank */]> {
3164 let Inst{31-20} = 0xf3a;
3165 let Inst{19-16} = 0b1111;
3166 let Inst{15-14} = 0b10;
3168 let Inst{10-8} = 0b000;
3169 let Inst{7-0} = op7_0;
3172 def t2NOP : T2I_hint<0b00000000, "nop", ".w">;
3173 def t2YIELD : T2I_hint<0b00000001, "yield", ".w">;
3174 def t2WFE : T2I_hint<0b00000010, "wfe", ".w">;
3175 def t2WFI : T2I_hint<0b00000011, "wfi", ".w">;
3176 def t2SEV : T2I_hint<0b00000100, "sev", ".w">;
3178 def t2DBG : T2I<(outs),(ins i32imm:$opt), NoItinerary, "dbg", "\t$opt",
3179 [/* For disassembly only; pattern left blank */]> {
3180 let Inst{31-20} = 0xf3a;
3181 let Inst{15-14} = 0b10;
3183 let Inst{10-8} = 0b000;
3184 let Inst{7-4} = 0b1111;
3187 let Inst{3-0} = opt;
3190 // Secure Monitor Call is a system instruction -- for disassembly only
3191 // Option = Inst{19-16}
3192 def t2SMC : T2I<(outs), (ins i32imm:$opt), NoItinerary, "smc", "\t$opt",
3193 [/* For disassembly only; pattern left blank */]> {
3194 let Inst{31-27} = 0b11110;
3195 let Inst{26-20} = 0b1111111;
3196 let Inst{15-12} = 0b1000;
3199 let Inst{19-16} = opt;
3202 class T2SRS<bits<12> op31_20,
3203 dag oops, dag iops, InstrItinClass itin,
3204 string opc, string asm, list<dag> pattern>
3205 : T2I<oops, iops, itin, opc, asm, pattern> {
3206 let Inst{31-20} = op31_20{11-0};
3209 let Inst{4-0} = mode{4-0};
3212 // Store Return State is a system instruction -- for disassembly only
3213 def t2SRSDBW : T2SRS<0b111010000010,
3214 (outs),(ins i32imm:$mode),NoItinerary,"srsdb","\tsp!, $mode",
3215 [/* For disassembly only; pattern left blank */]>;
3216 def t2SRSDB : T2SRS<0b111010000000,
3217 (outs),(ins i32imm:$mode),NoItinerary,"srsdb","\tsp, $mode",
3218 [/* For disassembly only; pattern left blank */]>;
3219 def t2SRSIAW : T2SRS<0b111010011010,
3220 (outs),(ins i32imm:$mode),NoItinerary,"srsia","\tsp!, $mode",
3221 [/* For disassembly only; pattern left blank */]>;
3222 def t2SRSIA : T2SRS<0b111010011000,
3223 (outs), (ins i32imm:$mode),NoItinerary,"srsia","\tsp, $mode",
3224 [/* For disassembly only; pattern left blank */]>;
3226 // Return From Exception is a system instruction -- for disassembly only
3228 class T2RFE<bits<12> op31_20, dag oops, dag iops, InstrItinClass itin,
3229 string opc, string asm, list<dag> pattern>
3230 : T2I<oops, iops, itin, opc, asm, pattern> {
3231 let Inst{31-20} = op31_20{11-0};
3234 let Inst{19-16} = Rn;
3235 let Inst{15-0} = 0xc000;
3238 def t2RFEDBW : T2RFE<0b111010000011,
3239 (outs), (ins GPR:$Rn), NoItinerary, "rfedb", "\t$Rn!",
3240 [/* For disassembly only; pattern left blank */]>;
3241 def t2RFEDB : T2RFE<0b111010000001,
3242 (outs), (ins GPR:$Rn), NoItinerary, "rfedb", "\t$Rn",
3243 [/* For disassembly only; pattern left blank */]>;
3244 def t2RFEIAW : T2RFE<0b111010011011,
3245 (outs), (ins GPR:$Rn), NoItinerary, "rfeia", "\t$Rn!",
3246 [/* For disassembly only; pattern left blank */]>;
3247 def t2RFEIA : T2RFE<0b111010011001,
3248 (outs), (ins GPR:$Rn), NoItinerary, "rfeia", "\t$Rn",
3249 [/* For disassembly only; pattern left blank */]>;
3251 //===----------------------------------------------------------------------===//
3252 // Non-Instruction Patterns
3255 // 32-bit immediate using movw + movt.
3256 // This is a single pseudo instruction to make it re-materializable.
3257 // FIXME: Remove this when we can do generalized remat.
3258 let isReMaterializable = 1, isMoveImm = 1 in
3259 def t2MOVi32imm : PseudoInst<(outs rGPR:$dst), (ins i32imm:$src), IIC_iMOVix2,
3260 [(set rGPR:$dst, (i32 imm:$src))]>,
3261 Requires<[IsThumb, HasV6T2]>;
3263 // Pseudo instruction that combines movw + movt + add pc (if pic).
3264 // It also makes it possible to rematerialize the instructions.
3265 // FIXME: Remove this when we can do generalized remat and when machine licm
3266 // can properly the instructions.
3267 let isReMaterializable = 1 in {
3268 def t2MOV_ga_pcrel : PseudoInst<(outs rGPR:$dst), (ins i32imm:$addr),
3270 [(set rGPR:$dst, (ARMWrapperPIC tglobaladdr:$addr))]>,
3271 Requires<[IsThumb2, UseMovt]>;
3273 def t2MOV_ga_dyn : PseudoInst<(outs rGPR:$dst), (ins i32imm:$addr),
3275 [(set rGPR:$dst, (ARMWrapperDYN tglobaladdr:$addr))]>,
3276 Requires<[IsThumb2, UseMovt]>;
3279 // ConstantPool, GlobalAddress, and JumpTable
3280 def : T2Pat<(ARMWrapper tglobaladdr :$dst), (t2LEApcrel tglobaladdr :$dst)>,
3281 Requires<[IsThumb2, DontUseMovt]>;
3282 def : T2Pat<(ARMWrapper tconstpool :$dst), (t2LEApcrel tconstpool :$dst)>;
3283 def : T2Pat<(ARMWrapper tglobaladdr :$dst), (t2MOVi32imm tglobaladdr :$dst)>,
3284 Requires<[IsThumb2, UseMovt]>;
3286 def : T2Pat<(ARMWrapperJT tjumptable:$dst, imm:$id),
3287 (t2LEApcrelJT tjumptable:$dst, imm:$id)>;
3289 // Pseudo instruction that combines ldr from constpool and add pc. This should
3290 // be expanded into two instructions late to allow if-conversion and
3292 let canFoldAsLoad = 1, isReMaterializable = 1 in
3293 def t2LDRpci_pic : PseudoInst<(outs rGPR:$dst), (ins i32imm:$addr, pclabel:$cp),
3295 [(set rGPR:$dst, (ARMpic_add (load (ARMWrapper tconstpool:$addr)),
3297 Requires<[IsThumb2]>;
3299 //===----------------------------------------------------------------------===//
3300 // Move between special register and ARM core register -- for disassembly only
3303 class T2SpecialReg<bits<12> op31_20, bits<2> op15_14, bits<1> op12,
3304 dag oops, dag iops, InstrItinClass itin,
3305 string opc, string asm, list<dag> pattern>
3306 : T2I<oops, iops, itin, opc, asm, pattern> {
3307 let Inst{31-20} = op31_20{11-0};
3308 let Inst{15-14} = op15_14{1-0};
3309 let Inst{12} = op12{0};
3312 class T2MRS<bits<12> op31_20, bits<2> op15_14, bits<1> op12,
3313 dag oops, dag iops, InstrItinClass itin,
3314 string opc, string asm, list<dag> pattern>
3315 : T2SpecialReg<op31_20, op15_14, op12, oops, iops, itin, opc, asm, pattern> {
3317 let Inst{11-8} = Rd;
3318 let Inst{19-16} = 0b1111;
3321 def t2MRS : T2MRS<0b111100111110, 0b10, 0,
3322 (outs rGPR:$Rd), (ins), NoItinerary, "mrs", "\t$Rd, cpsr",
3323 [/* For disassembly only; pattern left blank */]>;
3324 def t2MRSsys : T2MRS<0b111100111111, 0b10, 0,
3325 (outs rGPR:$Rd), (ins), NoItinerary, "mrs", "\t$Rd, spsr",
3326 [/* For disassembly only; pattern left blank */]>;
3328 // Move from ARM core register to Special Register
3330 // No need to have both system and application versions, the encodings are the
3331 // same and the assembly parser has no way to distinguish between them. The mask
3332 // operand contains the special register (R Bit) in bit 4 and bits 3-0 contains
3333 // the mask with the fields to be accessed in the special register.
3334 def t2MSR : T2SpecialReg<0b111100111000 /* op31-20 */, 0b10 /* op15-14 */,
3335 0 /* op12 */, (outs), (ins msr_mask:$mask, rGPR:$Rn),
3336 NoItinerary, "msr", "\t$mask, $Rn",
3337 [/* For disassembly only; pattern left blank */]> {
3340 let Inst{19-16} = Rn;
3341 let Inst{20} = mask{4}; // R Bit
3343 let Inst{11-8} = mask{3-0};
3346 //===----------------------------------------------------------------------===//
3347 // Move between coprocessor and ARM core register -- for disassembly only
3350 class t2MovRCopro<string opc, bit direction, dag oops, dag iops>
3351 : T2Cop<oops, iops, !strconcat(opc, "\t$cop, $opc1, $Rt, $CRn, $CRm, $opc2"),
3352 [/* For disassembly only; pattern left blank */]> {
3353 let Inst{27-24} = 0b1110;
3354 let Inst{20} = direction;
3364 let Inst{15-12} = Rt;
3365 let Inst{11-8} = cop;
3366 let Inst{23-21} = opc1;
3367 let Inst{7-5} = opc2;
3368 let Inst{3-0} = CRm;
3369 let Inst{19-16} = CRn;
3372 def t2MCR2 : t2MovRCopro<"mcr2", 0 /* from ARM core register to coprocessor */,
3373 (outs), (ins p_imm:$cop, i32imm:$opc1, GPR:$Rt, c_imm:$CRn,
3374 c_imm:$CRm, i32imm:$opc2)>;
3375 def t2MRC2 : t2MovRCopro<"mrc2", 1 /* from coprocessor to ARM core register */,
3376 (outs GPR:$Rt), (ins p_imm:$cop, i32imm:$opc1, c_imm:$CRn,
3377 c_imm:$CRm, i32imm:$opc2)>;
3379 class t2MovRRCopro<string opc, bit direction>
3380 : T2Cop<(outs), (ins p_imm:$cop, i32imm:$opc1, GPR:$Rt, GPR:$Rt2, c_imm:$CRm),
3381 !strconcat(opc, "\t$cop, $opc1, $Rt, $Rt2, $CRm"),
3382 [/* For disassembly only; pattern left blank */]> {
3383 let Inst{27-24} = 0b1100;
3384 let Inst{23-21} = 0b010;
3385 let Inst{20} = direction;
3393 let Inst{15-12} = Rt;
3394 let Inst{19-16} = Rt2;
3395 let Inst{11-8} = cop;
3396 let Inst{7-4} = opc1;
3397 let Inst{3-0} = CRm;
3400 def t2MCRR2 : t2MovRRCopro<"mcrr2",
3401 0 /* from ARM core register to coprocessor */>;
3402 def t2MRRC2 : t2MovRRCopro<"mrrc2",
3403 1 /* from coprocessor to ARM core register */>;
3405 //===----------------------------------------------------------------------===//
3406 // Other Coprocessor Instructions. For disassembly only.
3409 def t2CDP2 : T2Cop<(outs), (ins p_imm:$cop, i32imm:$opc1,
3410 c_imm:$CRd, c_imm:$CRn, c_imm:$CRm, i32imm:$opc2),
3411 "cdp2\t$cop, $opc1, $CRd, $CRn, $CRm, $opc2",
3412 [/* For disassembly only; pattern left blank */]> {
3413 let Inst{27-24} = 0b1110;
3422 let Inst{3-0} = CRm;
3424 let Inst{7-5} = opc2;
3425 let Inst{11-8} = cop;
3426 let Inst{15-12} = CRd;
3427 let Inst{19-16} = CRn;
3428 let Inst{23-20} = opc1;