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_asmoperand : AsmOperandClass { let Name = "T2SOImm"; }
48 def t2_so_imm : Operand<i32>, ImmLeaf<i32, [{
49 return ARM_AM::getT2SOImmVal(Imm) != -1;
51 let ParserMatchClass = t2_so_imm_asmoperand;
52 let EncoderMethod = "getT2SOImmOpValue";
55 // t2_so_imm_not - Match an immediate that is a complement
57 def t2_so_imm_not : Operand<i32>,
59 return ARM_AM::getT2SOImmVal(~((uint32_t)N->getZExtValue())) != -1;
60 }], t2_so_imm_not_XFORM>;
62 // t2_so_imm_neg - Match an immediate that is a negation of a t2_so_imm.
63 def t2_so_imm_neg : Operand<i32>,
65 return ARM_AM::getT2SOImmVal(-((uint32_t)N->getZExtValue())) != -1;
66 }], t2_so_imm_neg_XFORM>;
68 /// imm1_31 predicate - True if the 32-bit immediate is in the range [1,31].
69 def imm1_31 : ImmLeaf<i32, [{
70 return (int32_t)Imm >= 1 && (int32_t)Imm < 32;
73 /// imm0_4095 predicate - True if the 32-bit immediate is in the range [0.4095].
74 def imm0_4095 : Operand<i32>,
76 return Imm >= 0 && Imm < 4096;
79 def imm0_4095_neg : PatLeaf<(i32 imm), [{
80 return (uint32_t)(-N->getZExtValue()) < 4096;
83 def imm0_255_neg : PatLeaf<(i32 imm), [{
84 return (uint32_t)(-N->getZExtValue()) < 255;
87 def imm0_255_not : PatLeaf<(i32 imm), [{
88 return (uint32_t)(~N->getZExtValue()) < 255;
91 def lo5AllOne : PatLeaf<(i32 imm), [{
92 // Returns true if all low 5-bits are 1.
93 return (((uint32_t)N->getZExtValue()) & 0x1FUL) == 0x1FUL;
96 // Define Thumb2 specific addressing modes.
98 // t2addrmode_imm12 := reg + imm12
99 def t2addrmode_imm12 : Operand<i32>,
100 ComplexPattern<i32, 2, "SelectT2AddrModeImm12", []> {
101 let PrintMethod = "printAddrModeImm12Operand";
102 let EncoderMethod = "getAddrModeImm12OpValue";
103 let MIOperandInfo = (ops GPR:$base, i32imm:$offsimm);
104 let ParserMatchClass = MemMode5AsmOperand;
107 // t2ldrlabel := imm12
108 def t2ldrlabel : Operand<i32> {
109 let EncoderMethod = "getAddrModeImm12OpValue";
113 // ADR instruction labels.
114 def t2adrlabel : Operand<i32> {
115 let EncoderMethod = "getT2AdrLabelOpValue";
119 // t2addrmode_imm8 := reg +/- imm8
120 def t2addrmode_imm8 : Operand<i32>,
121 ComplexPattern<i32, 2, "SelectT2AddrModeImm8", []> {
122 let PrintMethod = "printT2AddrModeImm8Operand";
123 let EncoderMethod = "getT2AddrModeImm8OpValue";
124 let MIOperandInfo = (ops GPR:$base, i32imm:$offsimm);
125 let ParserMatchClass = MemMode5AsmOperand;
128 def t2am_imm8_offset : Operand<i32>,
129 ComplexPattern<i32, 1, "SelectT2AddrModeImm8Offset",
130 [], [SDNPWantRoot]> {
131 let PrintMethod = "printT2AddrModeImm8OffsetOperand";
132 let EncoderMethod = "getT2AddrModeImm8OffsetOpValue";
133 let ParserMatchClass = MemMode5AsmOperand;
136 // t2addrmode_imm8s4 := reg +/- (imm8 << 2)
137 def t2addrmode_imm8s4 : Operand<i32> {
138 let PrintMethod = "printT2AddrModeImm8s4Operand";
139 let EncoderMethod = "getT2AddrModeImm8s4OpValue";
140 let MIOperandInfo = (ops GPR:$base, i32imm:$offsimm);
141 let ParserMatchClass = MemMode5AsmOperand;
144 def t2am_imm8s4_offset : Operand<i32> {
145 let PrintMethod = "printT2AddrModeImm8s4OffsetOperand";
148 // t2addrmode_so_reg := reg + (reg << imm2)
149 def t2addrmode_so_reg : Operand<i32>,
150 ComplexPattern<i32, 3, "SelectT2AddrModeSoReg", []> {
151 let PrintMethod = "printT2AddrModeSoRegOperand";
152 let EncoderMethod = "getT2AddrModeSORegOpValue";
153 let MIOperandInfo = (ops GPR:$base, rGPR:$offsreg, i32imm:$offsimm);
154 let ParserMatchClass = MemMode5AsmOperand;
157 // t2addrmode_reg := reg
158 // Used by load/store exclusive instructions. Useful to enable right assembly
159 // parsing and printing. Not used for any codegen matching.
161 def t2addrmode_reg : Operand<i32> {
162 let PrintMethod = "printAddrMode7Operand";
163 let MIOperandInfo = (ops GPR);
164 let ParserMatchClass = MemMode7AsmOperand;
167 //===----------------------------------------------------------------------===//
168 // Multiclass helpers...
172 class T2OneRegImm<dag oops, dag iops, InstrItinClass itin,
173 string opc, string asm, list<dag> pattern>
174 : T2I<oops, iops, itin, opc, asm, pattern> {
179 let Inst{26} = imm{11};
180 let Inst{14-12} = imm{10-8};
181 let Inst{7-0} = imm{7-0};
185 class T2sOneRegImm<dag oops, dag iops, InstrItinClass itin,
186 string opc, string asm, list<dag> pattern>
187 : T2sI<oops, iops, itin, opc, asm, pattern> {
193 let Inst{26} = imm{11};
194 let Inst{14-12} = imm{10-8};
195 let Inst{7-0} = imm{7-0};
198 class T2OneRegCmpImm<dag oops, dag iops, InstrItinClass itin,
199 string opc, string asm, list<dag> pattern>
200 : T2I<oops, iops, itin, opc, asm, pattern> {
204 let Inst{19-16} = Rn;
205 let Inst{26} = imm{11};
206 let Inst{14-12} = imm{10-8};
207 let Inst{7-0} = imm{7-0};
211 class T2OneRegShiftedReg<dag oops, dag iops, InstrItinClass itin,
212 string opc, string asm, list<dag> pattern>
213 : T2I<oops, iops, itin, opc, asm, pattern> {
218 let Inst{3-0} = ShiftedRm{3-0};
219 let Inst{5-4} = ShiftedRm{6-5};
220 let Inst{14-12} = ShiftedRm{11-9};
221 let Inst{7-6} = ShiftedRm{8-7};
224 class T2sOneRegShiftedReg<dag oops, dag iops, InstrItinClass itin,
225 string opc, string asm, list<dag> pattern>
226 : T2sI<oops, iops, itin, opc, asm, pattern> {
231 let Inst{3-0} = ShiftedRm{3-0};
232 let Inst{5-4} = ShiftedRm{6-5};
233 let Inst{14-12} = ShiftedRm{11-9};
234 let Inst{7-6} = ShiftedRm{8-7};
237 class T2OneRegCmpShiftedReg<dag oops, dag iops, InstrItinClass itin,
238 string opc, string asm, list<dag> pattern>
239 : T2I<oops, iops, itin, opc, asm, pattern> {
243 let Inst{19-16} = Rn;
244 let Inst{3-0} = ShiftedRm{3-0};
245 let Inst{5-4} = ShiftedRm{6-5};
246 let Inst{14-12} = ShiftedRm{11-9};
247 let Inst{7-6} = ShiftedRm{8-7};
250 class T2TwoReg<dag oops, dag iops, InstrItinClass itin,
251 string opc, string asm, list<dag> pattern>
252 : T2I<oops, iops, itin, opc, asm, pattern> {
260 class T2sTwoReg<dag oops, dag iops, InstrItinClass itin,
261 string opc, string asm, list<dag> pattern>
262 : T2sI<oops, iops, itin, opc, asm, pattern> {
270 class T2TwoRegCmp<dag oops, dag iops, InstrItinClass itin,
271 string opc, string asm, list<dag> pattern>
272 : T2I<oops, iops, itin, opc, asm, pattern> {
276 let Inst{19-16} = Rn;
281 class T2TwoRegImm<dag oops, dag iops, InstrItinClass itin,
282 string opc, string asm, list<dag> pattern>
283 : T2I<oops, iops, itin, opc, asm, pattern> {
289 let Inst{19-16} = Rn;
290 let Inst{26} = imm{11};
291 let Inst{14-12} = imm{10-8};
292 let Inst{7-0} = imm{7-0};
295 class T2sTwoRegImm<dag oops, dag iops, InstrItinClass itin,
296 string opc, string asm, list<dag> pattern>
297 : T2sI<oops, iops, itin, opc, asm, pattern> {
303 let Inst{19-16} = Rn;
304 let Inst{26} = imm{11};
305 let Inst{14-12} = imm{10-8};
306 let Inst{7-0} = imm{7-0};
309 class T2TwoRegShiftImm<dag oops, dag iops, InstrItinClass itin,
310 string opc, string asm, list<dag> pattern>
311 : T2I<oops, iops, itin, opc, asm, pattern> {
318 let Inst{14-12} = imm{4-2};
319 let Inst{7-6} = imm{1-0};
322 class T2sTwoRegShiftImm<dag oops, dag iops, InstrItinClass itin,
323 string opc, string asm, list<dag> pattern>
324 : T2sI<oops, iops, itin, opc, asm, pattern> {
331 let Inst{14-12} = imm{4-2};
332 let Inst{7-6} = imm{1-0};
335 class T2ThreeReg<dag oops, dag iops, InstrItinClass itin,
336 string opc, string asm, list<dag> pattern>
337 : T2I<oops, iops, itin, opc, asm, pattern> {
343 let Inst{19-16} = Rn;
347 class T2sThreeReg<dag oops, dag iops, InstrItinClass itin,
348 string opc, string asm, list<dag> pattern>
349 : T2sI<oops, iops, itin, opc, asm, pattern> {
355 let Inst{19-16} = Rn;
359 class T2TwoRegShiftedReg<dag oops, dag iops, InstrItinClass itin,
360 string opc, string asm, list<dag> pattern>
361 : T2I<oops, iops, itin, opc, asm, pattern> {
367 let Inst{19-16} = Rn;
368 let Inst{3-0} = ShiftedRm{3-0};
369 let Inst{5-4} = ShiftedRm{6-5};
370 let Inst{14-12} = ShiftedRm{11-9};
371 let Inst{7-6} = ShiftedRm{8-7};
374 class T2sTwoRegShiftedReg<dag oops, dag iops, InstrItinClass itin,
375 string opc, string asm, list<dag> pattern>
376 : T2sI<oops, iops, itin, opc, asm, pattern> {
382 let Inst{19-16} = Rn;
383 let Inst{3-0} = ShiftedRm{3-0};
384 let Inst{5-4} = ShiftedRm{6-5};
385 let Inst{14-12} = ShiftedRm{11-9};
386 let Inst{7-6} = ShiftedRm{8-7};
389 class T2FourReg<dag oops, dag iops, InstrItinClass itin,
390 string opc, string asm, list<dag> pattern>
391 : T2I<oops, iops, itin, opc, asm, pattern> {
397 let Inst{19-16} = Rn;
398 let Inst{15-12} = Ra;
403 class T2MulLong<bits<3> opc22_20, bits<4> opc7_4,
404 dag oops, dag iops, InstrItinClass itin,
405 string opc, string asm, list<dag> pattern>
406 : T2I<oops, iops, itin, opc, asm, pattern> {
412 let Inst{31-23} = 0b111110111;
413 let Inst{22-20} = opc22_20;
414 let Inst{19-16} = Rn;
415 let Inst{15-12} = RdLo;
416 let Inst{11-8} = RdHi;
417 let Inst{7-4} = opc7_4;
422 /// T2I_un_irs - Defines a set of (op reg, {so_imm|r|so_reg}) patterns for a
423 /// unary operation that produces a value. These are predicable and can be
424 /// changed to modify CPSR.
425 multiclass T2I_un_irs<bits<4> opcod, string opc,
426 InstrItinClass iii, InstrItinClass iir, InstrItinClass iis,
427 PatFrag opnode, bit Cheap = 0, bit ReMat = 0> {
429 def i : T2sOneRegImm<(outs rGPR:$Rd), (ins t2_so_imm:$imm), iii,
431 [(set rGPR:$Rd, (opnode t2_so_imm:$imm))]> {
432 let isAsCheapAsAMove = Cheap;
433 let isReMaterializable = ReMat;
434 let Inst{31-27} = 0b11110;
436 let Inst{24-21} = opcod;
437 let Inst{19-16} = 0b1111; // Rn
441 def r : T2sTwoReg<(outs rGPR:$Rd), (ins rGPR:$Rm), iir,
443 [(set rGPR:$Rd, (opnode rGPR:$Rm))]> {
444 let Inst{31-27} = 0b11101;
445 let Inst{26-25} = 0b01;
446 let Inst{24-21} = opcod;
447 let Inst{19-16} = 0b1111; // Rn
448 let Inst{14-12} = 0b000; // imm3
449 let Inst{7-6} = 0b00; // imm2
450 let Inst{5-4} = 0b00; // type
453 def s : T2sOneRegShiftedReg<(outs rGPR:$Rd), (ins t2_so_reg:$ShiftedRm), iis,
454 opc, ".w\t$Rd, $ShiftedRm",
455 [(set rGPR:$Rd, (opnode t2_so_reg:$ShiftedRm))]> {
456 let Inst{31-27} = 0b11101;
457 let Inst{26-25} = 0b01;
458 let Inst{24-21} = opcod;
459 let Inst{19-16} = 0b1111; // Rn
463 /// T2I_bin_irs - Defines a set of (op reg, {so_imm|r|so_reg}) patterns for a
464 /// binary operation that produces a value. These are predicable and can be
465 /// changed to modify CPSR.
466 multiclass T2I_bin_irs<bits<4> opcod, string opc,
467 InstrItinClass iii, InstrItinClass iir, InstrItinClass iis,
468 PatFrag opnode, string baseOpc, bit Commutable = 0,
471 def ri : T2sTwoRegImm<
472 (outs rGPR:$Rd), (ins rGPR:$Rn, t2_so_imm:$imm), iii,
473 opc, "\t$Rd, $Rn, $imm",
474 [(set rGPR:$Rd, (opnode rGPR:$Rn, t2_so_imm:$imm))]> {
475 let Inst{31-27} = 0b11110;
477 let Inst{24-21} = opcod;
481 def rr : T2sThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), iir,
482 opc, !strconcat(wide, "\t$Rd, $Rn, $Rm"),
483 [(set rGPR:$Rd, (opnode rGPR:$Rn, rGPR:$Rm))]> {
484 let isCommutable = Commutable;
485 let Inst{31-27} = 0b11101;
486 let Inst{26-25} = 0b01;
487 let Inst{24-21} = opcod;
488 let Inst{14-12} = 0b000; // imm3
489 let Inst{7-6} = 0b00; // imm2
490 let Inst{5-4} = 0b00; // type
493 def rs : T2sTwoRegShiftedReg<
494 (outs rGPR:$Rd), (ins rGPR:$Rn, t2_so_reg:$ShiftedRm), iis,
495 opc, !strconcat(wide, "\t$Rd, $Rn, $ShiftedRm"),
496 [(set rGPR:$Rd, (opnode rGPR:$Rn, t2_so_reg:$ShiftedRm))]> {
497 let Inst{31-27} = 0b11101;
498 let Inst{26-25} = 0b01;
499 let Inst{24-21} = opcod;
501 // Assembly aliases for optional destination operand when it's the same
502 // as the source operand.
503 def : InstAlias<!strconcat(opc, "${s}${p} $Rdn, $imm"),
504 (!cast<Instruction>(!strconcat(baseOpc, "ri")) rGPR:$Rdn, rGPR:$Rdn,
505 t2_so_imm:$imm, pred:$p,
507 Requires<[IsThumb2]>;
508 def : InstAlias<!strconcat(opc, "${s}${p}", wide, " $Rdn, $Rm"),
509 (!cast<Instruction>(!strconcat(baseOpc, "rr")) rGPR:$Rdn, rGPR:$Rdn,
512 Requires<[IsThumb2]>;
513 def : InstAlias<!strconcat(opc, "${s}${p}", wide, " $Rdn, $shift"),
514 (!cast<Instruction>(!strconcat(baseOpc, "rs")) rGPR:$Rdn, rGPR:$Rdn,
515 t2_so_reg:$shift, pred:$p,
517 Requires<[IsThumb2]>;
520 /// T2I_bin_w_irs - Same as T2I_bin_irs except these operations need
521 // the ".w" suffix to indicate that they are wide.
522 multiclass T2I_bin_w_irs<bits<4> opcod, string opc,
523 InstrItinClass iii, InstrItinClass iir, InstrItinClass iis,
524 PatFrag opnode, string baseOpc, bit Commutable = 0> :
525 T2I_bin_irs<opcod, opc, iii, iir, iis, opnode, baseOpc, Commutable, ".w">;
527 /// T2I_rbin_is - Same as T2I_bin_irs except the order of operands are
528 /// reversed. The 'rr' form is only defined for the disassembler; for codegen
529 /// it is equivalent to the T2I_bin_irs counterpart.
530 multiclass T2I_rbin_irs<bits<4> opcod, string opc, PatFrag opnode> {
532 def ri : T2sTwoRegImm<
533 (outs rGPR:$Rd), (ins rGPR:$Rn, t2_so_imm:$imm), IIC_iALUi,
534 opc, ".w\t$Rd, $Rn, $imm",
535 [(set rGPR:$Rd, (opnode t2_so_imm:$imm, rGPR:$Rn))]> {
536 let Inst{31-27} = 0b11110;
538 let Inst{24-21} = opcod;
542 def rr : T2sThreeReg<
543 (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iALUr,
544 opc, "\t$Rd, $Rn, $Rm",
545 [/* For disassembly only; pattern left blank */]> {
546 let Inst{31-27} = 0b11101;
547 let Inst{26-25} = 0b01;
548 let Inst{24-21} = opcod;
549 let Inst{14-12} = 0b000; // imm3
550 let Inst{7-6} = 0b00; // imm2
551 let Inst{5-4} = 0b00; // type
554 def rs : T2sTwoRegShiftedReg<
555 (outs rGPR:$Rd), (ins rGPR:$Rn, t2_so_reg:$ShiftedRm),
556 IIC_iALUsir, opc, "\t$Rd, $Rn, $ShiftedRm",
557 [(set rGPR:$Rd, (opnode t2_so_reg:$ShiftedRm, rGPR:$Rn))]> {
558 let Inst{31-27} = 0b11101;
559 let Inst{26-25} = 0b01;
560 let Inst{24-21} = opcod;
564 /// T2I_bin_s_irs - Similar to T2I_bin_irs except it sets the 's' bit so the
565 /// instruction modifies the CPSR register.
566 let isCodeGenOnly = 1, Defs = [CPSR] in {
567 multiclass T2I_bin_s_irs<bits<4> opcod, string opc,
568 InstrItinClass iii, InstrItinClass iir, InstrItinClass iis,
569 PatFrag opnode, bit Commutable = 0> {
571 def ri : T2TwoRegImm<
572 (outs rGPR:$Rd), (ins GPR:$Rn, t2_so_imm:$imm), iii,
573 !strconcat(opc, "s"), ".w\t$Rd, $Rn, $imm",
574 [(set rGPR:$Rd, (opnode GPR:$Rn, t2_so_imm:$imm))]> {
575 let Inst{31-27} = 0b11110;
577 let Inst{24-21} = opcod;
578 let Inst{20} = 1; // The S bit.
583 (outs rGPR:$Rd), (ins GPR:$Rn, rGPR:$Rm), iir,
584 !strconcat(opc, "s"), ".w\t$Rd, $Rn, $Rm",
585 [(set rGPR:$Rd, (opnode GPR:$Rn, rGPR:$Rm))]> {
586 let isCommutable = Commutable;
587 let Inst{31-27} = 0b11101;
588 let Inst{26-25} = 0b01;
589 let Inst{24-21} = opcod;
590 let Inst{20} = 1; // The S bit.
591 let Inst{14-12} = 0b000; // imm3
592 let Inst{7-6} = 0b00; // imm2
593 let Inst{5-4} = 0b00; // type
596 def rs : T2TwoRegShiftedReg<
597 (outs rGPR:$Rd), (ins GPR:$Rn, t2_so_reg:$ShiftedRm), iis,
598 !strconcat(opc, "s"), ".w\t$Rd, $Rn, $ShiftedRm",
599 [(set rGPR:$Rd, (opnode GPR:$Rn, t2_so_reg:$ShiftedRm))]> {
600 let Inst{31-27} = 0b11101;
601 let Inst{26-25} = 0b01;
602 let Inst{24-21} = opcod;
603 let Inst{20} = 1; // The S bit.
608 /// T2I_bin_ii12rs - Defines a set of (op reg, {so_imm|imm0_4095|r|so_reg})
609 /// patterns for a binary operation that produces a value.
610 multiclass T2I_bin_ii12rs<bits<3> op23_21, string opc, PatFrag opnode,
611 bit Commutable = 0> {
613 // The register-immediate version is re-materializable. This is useful
614 // in particular for taking the address of a local.
615 let isReMaterializable = 1 in {
616 def ri : T2sTwoRegImm<
617 (outs rGPR:$Rd), (ins GPR:$Rn, t2_so_imm:$imm), IIC_iALUi,
618 opc, ".w\t$Rd, $Rn, $imm",
619 [(set rGPR:$Rd, (opnode GPR:$Rn, t2_so_imm:$imm))]> {
620 let Inst{31-27} = 0b11110;
623 let Inst{23-21} = op23_21;
629 (outs rGPR:$Rd), (ins GPR:$Rn, imm0_4095:$imm), IIC_iALUi,
630 !strconcat(opc, "w"), "\t$Rd, $Rn, $imm",
631 [(set rGPR:$Rd, (opnode GPR:$Rn, imm0_4095:$imm))]> {
635 let Inst{31-27} = 0b11110;
636 let Inst{26} = imm{11};
637 let Inst{25-24} = 0b10;
638 let Inst{23-21} = op23_21;
639 let Inst{20} = 0; // The S bit.
640 let Inst{19-16} = Rn;
642 let Inst{14-12} = imm{10-8};
644 let Inst{7-0} = imm{7-0};
647 def rr : T2sThreeReg<(outs rGPR:$Rd), (ins GPR:$Rn, rGPR:$Rm), IIC_iALUr,
648 opc, ".w\t$Rd, $Rn, $Rm",
649 [(set rGPR:$Rd, (opnode GPR:$Rn, rGPR:$Rm))]> {
650 let isCommutable = Commutable;
651 let Inst{31-27} = 0b11101;
652 let Inst{26-25} = 0b01;
654 let Inst{23-21} = op23_21;
655 let Inst{14-12} = 0b000; // imm3
656 let Inst{7-6} = 0b00; // imm2
657 let Inst{5-4} = 0b00; // type
660 def rs : T2sTwoRegShiftedReg<
661 (outs rGPR:$Rd), (ins GPR:$Rn, t2_so_reg:$ShiftedRm),
662 IIC_iALUsi, opc, ".w\t$Rd, $Rn, $ShiftedRm",
663 [(set rGPR:$Rd, (opnode GPR:$Rn, t2_so_reg:$ShiftedRm))]> {
664 let Inst{31-27} = 0b11101;
665 let Inst{26-25} = 0b01;
667 let Inst{23-21} = op23_21;
671 /// T2I_adde_sube_irs - Defines a set of (op reg, {so_imm|r|so_reg}) patterns
672 /// for a binary operation that produces a value and use the carry
673 /// bit. It's not predicable.
674 let Uses = [CPSR] in {
675 multiclass T2I_adde_sube_irs<bits<4> opcod, string opc, PatFrag opnode,
676 bit Commutable = 0> {
678 def ri : T2sTwoRegImm<(outs rGPR:$Rd), (ins rGPR:$Rn, t2_so_imm:$imm),
679 IIC_iALUi, opc, "\t$Rd, $Rn, $imm",
680 [(set rGPR:$Rd, (opnode rGPR:$Rn, t2_so_imm:$imm))]>,
681 Requires<[IsThumb2]> {
682 let Inst{31-27} = 0b11110;
684 let Inst{24-21} = opcod;
688 def rr : T2sThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iALUr,
689 opc, ".w\t$Rd, $Rn, $Rm",
690 [(set rGPR:$Rd, (opnode rGPR:$Rn, rGPR:$Rm))]>,
691 Requires<[IsThumb2]> {
692 let isCommutable = Commutable;
693 let Inst{31-27} = 0b11101;
694 let Inst{26-25} = 0b01;
695 let Inst{24-21} = opcod;
696 let Inst{14-12} = 0b000; // imm3
697 let Inst{7-6} = 0b00; // imm2
698 let Inst{5-4} = 0b00; // type
701 def rs : T2sTwoRegShiftedReg<
702 (outs rGPR:$Rd), (ins rGPR:$Rn, t2_so_reg:$ShiftedRm),
703 IIC_iALUsi, opc, ".w\t$Rd, $Rn, $ShiftedRm",
704 [(set rGPR:$Rd, (opnode rGPR:$Rn, t2_so_reg:$ShiftedRm))]>,
705 Requires<[IsThumb2]> {
706 let Inst{31-27} = 0b11101;
707 let Inst{26-25} = 0b01;
708 let Inst{24-21} = opcod;
713 // Carry setting variants
714 // NOTE: CPSR def omitted because it will be handled by the custom inserter.
715 let usesCustomInserter = 1 in {
716 multiclass T2I_adde_sube_s_irs<PatFrag opnode, bit Commutable = 0> {
718 def ri : t2PseudoInst<(outs rGPR:$Rd), (ins rGPR:$Rn, t2_so_imm:$imm),
719 Size4Bytes, IIC_iALUi,
720 [(set rGPR:$Rd, (opnode rGPR:$Rn, t2_so_imm:$imm))]>;
722 def rr : t2PseudoInst<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm),
723 Size4Bytes, IIC_iALUr,
724 [(set rGPR:$Rd, (opnode rGPR:$Rn, rGPR:$Rm))]> {
725 let isCommutable = Commutable;
728 def rs : t2PseudoInst<
729 (outs rGPR:$Rd), (ins rGPR:$Rn, t2_so_reg:$ShiftedRm),
730 Size4Bytes, IIC_iALUsi,
731 [(set rGPR:$Rd, (opnode rGPR:$Rn, t2_so_reg:$ShiftedRm))]>;
735 /// T2I_rbin_s_is - Same as T2I_rbin_irs except sets 's' bit and the register
736 /// version is not needed since this is only for codegen.
737 let isCodeGenOnly = 1, Defs = [CPSR] in {
738 multiclass T2I_rbin_s_is<bits<4> opcod, string opc, PatFrag opnode> {
740 def ri : T2TwoRegImm<
741 (outs rGPR:$Rd), (ins rGPR:$Rn, t2_so_imm:$imm), IIC_iALUi,
742 !strconcat(opc, "s"), ".w\t$Rd, $Rn, $imm",
743 [(set rGPR:$Rd, (opnode t2_so_imm:$imm, rGPR:$Rn))]> {
744 let Inst{31-27} = 0b11110;
746 let Inst{24-21} = opcod;
747 let Inst{20} = 1; // The S bit.
751 def rs : T2TwoRegShiftedReg<
752 (outs rGPR:$Rd), (ins rGPR:$Rn, t2_so_reg:$ShiftedRm),
753 IIC_iALUsi, !strconcat(opc, "s"), "\t$Rd, $Rn, $ShiftedRm",
754 [(set rGPR:$Rd, (opnode t2_so_reg:$ShiftedRm, rGPR:$Rn))]> {
755 let Inst{31-27} = 0b11101;
756 let Inst{26-25} = 0b01;
757 let Inst{24-21} = opcod;
758 let Inst{20} = 1; // The S bit.
763 /// T2I_sh_ir - Defines a set of (op reg, {so_imm|r}) patterns for a shift /
764 // rotate operation that produces a value.
765 multiclass T2I_sh_ir<bits<2> opcod, string opc, PatFrag opnode> {
767 def ri : T2sTwoRegShiftImm<
768 (outs rGPR:$Rd), (ins rGPR:$Rm, i32imm:$imm), IIC_iMOVsi,
769 opc, ".w\t$Rd, $Rm, $imm",
770 [(set rGPR:$Rd, (opnode rGPR:$Rm, imm1_31:$imm))]> {
771 let Inst{31-27} = 0b11101;
772 let Inst{26-21} = 0b010010;
773 let Inst{19-16} = 0b1111; // Rn
774 let Inst{5-4} = opcod;
777 def rr : T2sThreeReg<
778 (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iMOVsr,
779 opc, ".w\t$Rd, $Rn, $Rm",
780 [(set rGPR:$Rd, (opnode rGPR:$Rn, rGPR:$Rm))]> {
781 let Inst{31-27} = 0b11111;
782 let Inst{26-23} = 0b0100;
783 let Inst{22-21} = opcod;
784 let Inst{15-12} = 0b1111;
785 let Inst{7-4} = 0b0000;
789 /// T2I_cmp_irs - Defines a set of (op r, {so_imm|r|so_reg}) cmp / test
790 /// patterns. Similar to T2I_bin_irs except the instruction does not produce
791 /// a explicit result, only implicitly set CPSR.
792 let isCompare = 1, Defs = [CPSR] in {
793 multiclass T2I_cmp_irs<bits<4> opcod, string opc,
794 InstrItinClass iii, InstrItinClass iir, InstrItinClass iis,
797 def ri : T2OneRegCmpImm<
798 (outs), (ins GPR:$Rn, t2_so_imm:$imm), iii,
799 opc, ".w\t$Rn, $imm",
800 [(opnode GPR:$Rn, t2_so_imm:$imm)]> {
801 let Inst{31-27} = 0b11110;
803 let Inst{24-21} = opcod;
804 let Inst{20} = 1; // The S bit.
806 let Inst{11-8} = 0b1111; // Rd
809 def rr : T2TwoRegCmp<
810 (outs), (ins GPR:$lhs, rGPR:$rhs), iir,
811 opc, ".w\t$lhs, $rhs",
812 [(opnode GPR:$lhs, rGPR:$rhs)]> {
813 let Inst{31-27} = 0b11101;
814 let Inst{26-25} = 0b01;
815 let Inst{24-21} = opcod;
816 let Inst{20} = 1; // The S bit.
817 let Inst{14-12} = 0b000; // imm3
818 let Inst{11-8} = 0b1111; // Rd
819 let Inst{7-6} = 0b00; // imm2
820 let Inst{5-4} = 0b00; // type
823 def rs : T2OneRegCmpShiftedReg<
824 (outs), (ins GPR:$Rn, t2_so_reg:$ShiftedRm), iis,
825 opc, ".w\t$Rn, $ShiftedRm",
826 [(opnode GPR:$Rn, t2_so_reg:$ShiftedRm)]> {
827 let Inst{31-27} = 0b11101;
828 let Inst{26-25} = 0b01;
829 let Inst{24-21} = opcod;
830 let Inst{20} = 1; // The S bit.
831 let Inst{11-8} = 0b1111; // Rd
836 /// T2I_ld - Defines a set of (op r, {imm12|imm8|so_reg}) load patterns.
837 multiclass T2I_ld<bit signed, bits<2> opcod, string opc,
838 InstrItinClass iii, InstrItinClass iis, PatFrag opnode> {
839 def i12 : T2Ii12<(outs GPR:$Rt), (ins t2addrmode_imm12:$addr), iii,
840 opc, ".w\t$Rt, $addr",
841 [(set GPR:$Rt, (opnode t2addrmode_imm12:$addr))]> {
842 let Inst{31-27} = 0b11111;
843 let Inst{26-25} = 0b00;
844 let Inst{24} = signed;
846 let Inst{22-21} = opcod;
847 let Inst{20} = 1; // load
850 let Inst{15-12} = Rt;
853 let addr{12} = 1; // add = TRUE
854 let Inst{19-16} = addr{16-13}; // Rn
855 let Inst{23} = addr{12}; // U
856 let Inst{11-0} = addr{11-0}; // imm
858 def i8 : T2Ii8 <(outs GPR:$Rt), (ins t2addrmode_imm8:$addr), iii,
860 [(set GPR:$Rt, (opnode t2addrmode_imm8:$addr))]> {
861 let Inst{31-27} = 0b11111;
862 let Inst{26-25} = 0b00;
863 let Inst{24} = signed;
865 let Inst{22-21} = opcod;
866 let Inst{20} = 1; // load
868 // Offset: index==TRUE, wback==FALSE
869 let Inst{10} = 1; // The P bit.
870 let Inst{8} = 0; // The W bit.
873 let Inst{15-12} = Rt;
876 let Inst{19-16} = addr{12-9}; // Rn
877 let Inst{9} = addr{8}; // U
878 let Inst{7-0} = addr{7-0}; // imm
880 def s : T2Iso <(outs GPR:$Rt), (ins t2addrmode_so_reg:$addr), iis,
881 opc, ".w\t$Rt, $addr",
882 [(set GPR:$Rt, (opnode t2addrmode_so_reg:$addr))]> {
883 let Inst{31-27} = 0b11111;
884 let Inst{26-25} = 0b00;
885 let Inst{24} = signed;
887 let Inst{22-21} = opcod;
888 let Inst{20} = 1; // load
889 let Inst{11-6} = 0b000000;
892 let Inst{15-12} = Rt;
895 let Inst{19-16} = addr{9-6}; // Rn
896 let Inst{3-0} = addr{5-2}; // Rm
897 let Inst{5-4} = addr{1-0}; // imm
900 // FIXME: Is the pci variant actually needed?
901 def pci : T2Ipc <(outs GPR:$Rt), (ins t2ldrlabel:$addr), iii,
902 opc, ".w\t$Rt, $addr",
903 [(set GPR:$Rt, (opnode (ARMWrapper tconstpool:$addr)))]> {
904 let isReMaterializable = 1;
905 let Inst{31-27} = 0b11111;
906 let Inst{26-25} = 0b00;
907 let Inst{24} = signed;
908 let Inst{23} = ?; // add = (U == '1')
909 let Inst{22-21} = opcod;
910 let Inst{20} = 1; // load
911 let Inst{19-16} = 0b1111; // Rn
914 let Inst{15-12} = Rt{3-0};
915 let Inst{11-0} = addr{11-0};
919 /// T2I_st - Defines a set of (op r, {imm12|imm8|so_reg}) store patterns.
920 multiclass T2I_st<bits<2> opcod, string opc,
921 InstrItinClass iii, InstrItinClass iis, PatFrag opnode> {
922 def i12 : T2Ii12<(outs), (ins GPR:$Rt, t2addrmode_imm12:$addr), iii,
923 opc, ".w\t$Rt, $addr",
924 [(opnode GPR:$Rt, t2addrmode_imm12:$addr)]> {
925 let Inst{31-27} = 0b11111;
926 let Inst{26-23} = 0b0001;
927 let Inst{22-21} = opcod;
928 let Inst{20} = 0; // !load
931 let Inst{15-12} = Rt;
934 let addr{12} = 1; // add = TRUE
935 let Inst{19-16} = addr{16-13}; // Rn
936 let Inst{23} = addr{12}; // U
937 let Inst{11-0} = addr{11-0}; // imm
939 def i8 : T2Ii8 <(outs), (ins GPR:$Rt, t2addrmode_imm8:$addr), iii,
941 [(opnode GPR:$Rt, t2addrmode_imm8:$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
947 // Offset: index==TRUE, wback==FALSE
948 let Inst{10} = 1; // The P bit.
949 let Inst{8} = 0; // The W bit.
952 let Inst{15-12} = Rt;
955 let Inst{19-16} = addr{12-9}; // Rn
956 let Inst{9} = addr{8}; // U
957 let Inst{7-0} = addr{7-0}; // imm
959 def s : T2Iso <(outs), (ins GPR:$Rt, t2addrmode_so_reg:$addr), iis,
960 opc, ".w\t$Rt, $addr",
961 [(opnode GPR:$Rt, t2addrmode_so_reg:$addr)]> {
962 let Inst{31-27} = 0b11111;
963 let Inst{26-23} = 0b0000;
964 let Inst{22-21} = opcod;
965 let Inst{20} = 0; // !load
966 let Inst{11-6} = 0b000000;
969 let Inst{15-12} = Rt;
972 let Inst{19-16} = addr{9-6}; // Rn
973 let Inst{3-0} = addr{5-2}; // Rm
974 let Inst{5-4} = addr{1-0}; // imm
978 /// T2I_ext_rrot - A unary operation with two forms: one whose operand is a
979 /// register and one whose operand is a register rotated by 8/16/24.
980 multiclass T2I_ext_rrot<bits<3> opcod, string opc, PatFrag opnode> {
981 def r : T2TwoReg<(outs rGPR:$Rd), (ins rGPR:$Rm), IIC_iEXTr,
983 [(set rGPR:$Rd, (opnode rGPR:$Rm))]> {
984 let Inst{31-27} = 0b11111;
985 let Inst{26-23} = 0b0100;
986 let Inst{22-20} = opcod;
987 let Inst{19-16} = 0b1111; // Rn
988 let Inst{15-12} = 0b1111;
990 let Inst{5-4} = 0b00; // rotate
992 def r_rot : T2TwoReg<(outs rGPR:$Rd), (ins rGPR:$Rm, rot_imm:$rot), IIC_iEXTr,
993 opc, ".w\t$Rd, $Rm, ror $rot",
994 [(set rGPR:$Rd, (opnode (rotr rGPR:$Rm, rot_imm:$rot)))]> {
995 let Inst{31-27} = 0b11111;
996 let Inst{26-23} = 0b0100;
997 let Inst{22-20} = opcod;
998 let Inst{19-16} = 0b1111; // Rn
999 let Inst{15-12} = 0b1111;
1003 let Inst{5-4} = rot{1-0}; // rotate
1007 // UXTB16 - Requres T2ExtractPack, does not need the .w qualifier.
1008 multiclass T2I_ext_rrot_uxtb16<bits<3> opcod, string opc, PatFrag opnode> {
1009 def r : T2TwoReg<(outs rGPR:$Rd), (ins rGPR:$Rm), IIC_iEXTr,
1011 [(set rGPR:$Rd, (opnode rGPR:$Rm))]>,
1012 Requires<[HasT2ExtractPack, IsThumb2]> {
1013 let Inst{31-27} = 0b11111;
1014 let Inst{26-23} = 0b0100;
1015 let Inst{22-20} = opcod;
1016 let Inst{19-16} = 0b1111; // Rn
1017 let Inst{15-12} = 0b1111;
1019 let Inst{5-4} = 0b00; // rotate
1021 def r_rot : T2TwoReg<(outs rGPR:$dst), (ins rGPR:$Rm, rot_imm:$rot),
1022 IIC_iEXTr, opc, "\t$dst, $Rm, ror $rot",
1023 [(set rGPR:$dst, (opnode (rotr rGPR:$Rm, rot_imm:$rot)))]>,
1024 Requires<[HasT2ExtractPack, IsThumb2]> {
1025 let Inst{31-27} = 0b11111;
1026 let Inst{26-23} = 0b0100;
1027 let Inst{22-20} = opcod;
1028 let Inst{19-16} = 0b1111; // Rn
1029 let Inst{15-12} = 0b1111;
1033 let Inst{5-4} = rot{1-0}; // rotate
1037 // SXTB16 - Requres T2ExtractPack, does not need the .w qualifier, no pattern
1039 multiclass T2I_ext_rrot_sxtb16<bits<3> opcod, string opc> {
1040 def r : T2TwoReg<(outs rGPR:$Rd), (ins rGPR:$Rm), IIC_iEXTr,
1041 opc, "\t$Rd, $Rm", []>,
1042 Requires<[IsThumb2, HasT2ExtractPack]> {
1043 let Inst{31-27} = 0b11111;
1044 let Inst{26-23} = 0b0100;
1045 let Inst{22-20} = opcod;
1046 let Inst{19-16} = 0b1111; // Rn
1047 let Inst{15-12} = 0b1111;
1049 let Inst{5-4} = 0b00; // rotate
1051 def r_rot : T2TwoReg<(outs rGPR:$Rd), (ins rGPR:$Rm, i32imm:$rot), IIC_iEXTr,
1052 opc, "\t$Rd, $Rm, ror $rot", []>,
1053 Requires<[IsThumb2, HasT2ExtractPack]> {
1054 let Inst{31-27} = 0b11111;
1055 let Inst{26-23} = 0b0100;
1056 let Inst{22-20} = opcod;
1057 let Inst{19-16} = 0b1111; // Rn
1058 let Inst{15-12} = 0b1111;
1062 let Inst{5-4} = rot{1-0}; // rotate
1066 /// T2I_exta_rrot - A binary operation with two forms: one whose operand is a
1067 /// register and one whose operand is a register rotated by 8/16/24.
1068 multiclass T2I_exta_rrot<bits<3> opcod, string opc, PatFrag opnode> {
1069 def rr : T2ThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iEXTAr,
1070 opc, "\t$Rd, $Rn, $Rm",
1071 [(set rGPR:$Rd, (opnode rGPR:$Rn, rGPR:$Rm))]>,
1072 Requires<[HasT2ExtractPack, IsThumb2]> {
1073 let Inst{31-27} = 0b11111;
1074 let Inst{26-23} = 0b0100;
1075 let Inst{22-20} = opcod;
1076 let Inst{15-12} = 0b1111;
1078 let Inst{5-4} = 0b00; // rotate
1080 def rr_rot : T2ThreeReg<(outs rGPR:$Rd),
1081 (ins rGPR:$Rn, rGPR:$Rm, rot_imm:$rot),
1082 IIC_iEXTAsr, opc, "\t$Rd, $Rn, $Rm, ror $rot",
1083 [(set rGPR:$Rd, (opnode rGPR:$Rn,
1084 (rotr rGPR:$Rm, rot_imm:$rot)))]>,
1085 Requires<[HasT2ExtractPack, IsThumb2]> {
1086 let Inst{31-27} = 0b11111;
1087 let Inst{26-23} = 0b0100;
1088 let Inst{22-20} = opcod;
1089 let Inst{15-12} = 0b1111;
1093 let Inst{5-4} = rot{1-0}; // rotate
1097 // DO variant - disassembly only, no pattern
1099 multiclass T2I_exta_rrot_DO<bits<3> opcod, string opc> {
1100 def rr : T2ThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iEXTAr,
1101 opc, "\t$Rd, $Rn, $Rm", []> {
1102 let Inst{31-27} = 0b11111;
1103 let Inst{26-23} = 0b0100;
1104 let Inst{22-20} = opcod;
1105 let Inst{15-12} = 0b1111;
1107 let Inst{5-4} = 0b00; // rotate
1109 def rr_rot :T2ThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, i32imm:$rot),
1110 IIC_iEXTAsr, opc, "\t$Rd, $Rn, $Rm, ror $rot", []> {
1111 let Inst{31-27} = 0b11111;
1112 let Inst{26-23} = 0b0100;
1113 let Inst{22-20} = opcod;
1114 let Inst{15-12} = 0b1111;
1118 let Inst{5-4} = rot{1-0}; // rotate
1122 //===----------------------------------------------------------------------===//
1124 //===----------------------------------------------------------------------===//
1126 //===----------------------------------------------------------------------===//
1127 // Miscellaneous Instructions.
1130 class T2PCOneRegImm<dag oops, dag iops, InstrItinClass itin,
1131 string asm, list<dag> pattern>
1132 : T2XI<oops, iops, itin, asm, pattern> {
1136 let Inst{11-8} = Rd;
1137 let Inst{26} = label{11};
1138 let Inst{14-12} = label{10-8};
1139 let Inst{7-0} = label{7-0};
1142 // LEApcrel - Load a pc-relative address into a register without offending the
1144 def t2ADR : T2PCOneRegImm<(outs rGPR:$Rd),
1145 (ins t2adrlabel:$addr, pred:$p),
1146 IIC_iALUi, "adr{$p}.w\t$Rd, #$addr", []> {
1147 let Inst{31-27} = 0b11110;
1148 let Inst{25-24} = 0b10;
1149 // Inst{23:21} = '11' (add = FALSE) or '00' (add = TRUE)
1152 let Inst{19-16} = 0b1111; // Rn
1157 let Inst{11-8} = Rd;
1158 let Inst{23} = addr{12};
1159 let Inst{21} = addr{12};
1160 let Inst{26} = addr{11};
1161 let Inst{14-12} = addr{10-8};
1162 let Inst{7-0} = addr{7-0};
1165 let neverHasSideEffects = 1, isReMaterializable = 1 in
1166 def t2LEApcrel : t2PseudoInst<(outs rGPR:$Rd), (ins i32imm:$label, pred:$p),
1167 Size4Bytes, IIC_iALUi, []>;
1168 def t2LEApcrelJT : t2PseudoInst<(outs rGPR:$Rd),
1169 (ins i32imm:$label, nohash_imm:$id, pred:$p),
1170 Size4Bytes, IIC_iALUi,
1174 //===----------------------------------------------------------------------===//
1175 // Load / store Instructions.
1179 let canFoldAsLoad = 1, isReMaterializable = 1 in
1180 defm t2LDR : T2I_ld<0, 0b10, "ldr", IIC_iLoad_i, IIC_iLoad_si,
1181 UnOpFrag<(load node:$Src)>>;
1183 // Loads with zero extension
1184 defm t2LDRH : T2I_ld<0, 0b01, "ldrh", IIC_iLoad_bh_i, IIC_iLoad_bh_si,
1185 UnOpFrag<(zextloadi16 node:$Src)>>;
1186 defm t2LDRB : T2I_ld<0, 0b00, "ldrb", IIC_iLoad_bh_i, IIC_iLoad_bh_si,
1187 UnOpFrag<(zextloadi8 node:$Src)>>;
1189 // Loads with sign extension
1190 defm t2LDRSH : T2I_ld<1, 0b01, "ldrsh", IIC_iLoad_bh_i, IIC_iLoad_bh_si,
1191 UnOpFrag<(sextloadi16 node:$Src)>>;
1192 defm t2LDRSB : T2I_ld<1, 0b00, "ldrsb", IIC_iLoad_bh_i, IIC_iLoad_bh_si,
1193 UnOpFrag<(sextloadi8 node:$Src)>>;
1195 let mayLoad = 1, neverHasSideEffects = 1, hasExtraDefRegAllocReq = 1 in {
1197 def t2LDRDi8 : T2Ii8s4<1, 0, 1, (outs rGPR:$Rt, rGPR:$Rt2),
1198 (ins t2addrmode_imm8s4:$addr),
1199 IIC_iLoad_d_i, "ldrd", "\t$Rt, $Rt2, $addr", []>;
1200 } // mayLoad = 1, neverHasSideEffects = 1, hasExtraDefRegAllocReq = 1
1202 // zextload i1 -> zextload i8
1203 def : T2Pat<(zextloadi1 t2addrmode_imm12:$addr),
1204 (t2LDRBi12 t2addrmode_imm12:$addr)>;
1205 def : T2Pat<(zextloadi1 t2addrmode_imm8:$addr),
1206 (t2LDRBi8 t2addrmode_imm8:$addr)>;
1207 def : T2Pat<(zextloadi1 t2addrmode_so_reg:$addr),
1208 (t2LDRBs t2addrmode_so_reg:$addr)>;
1209 def : T2Pat<(zextloadi1 (ARMWrapper tconstpool:$addr)),
1210 (t2LDRBpci tconstpool:$addr)>;
1212 // extload -> zextload
1213 // FIXME: Reduce the number of patterns by legalizing extload to zextload
1215 def : T2Pat<(extloadi1 t2addrmode_imm12:$addr),
1216 (t2LDRBi12 t2addrmode_imm12:$addr)>;
1217 def : T2Pat<(extloadi1 t2addrmode_imm8:$addr),
1218 (t2LDRBi8 t2addrmode_imm8:$addr)>;
1219 def : T2Pat<(extloadi1 t2addrmode_so_reg:$addr),
1220 (t2LDRBs t2addrmode_so_reg:$addr)>;
1221 def : T2Pat<(extloadi1 (ARMWrapper tconstpool:$addr)),
1222 (t2LDRBpci tconstpool:$addr)>;
1224 def : T2Pat<(extloadi8 t2addrmode_imm12:$addr),
1225 (t2LDRBi12 t2addrmode_imm12:$addr)>;
1226 def : T2Pat<(extloadi8 t2addrmode_imm8:$addr),
1227 (t2LDRBi8 t2addrmode_imm8:$addr)>;
1228 def : T2Pat<(extloadi8 t2addrmode_so_reg:$addr),
1229 (t2LDRBs t2addrmode_so_reg:$addr)>;
1230 def : T2Pat<(extloadi8 (ARMWrapper tconstpool:$addr)),
1231 (t2LDRBpci tconstpool:$addr)>;
1233 def : T2Pat<(extloadi16 t2addrmode_imm12:$addr),
1234 (t2LDRHi12 t2addrmode_imm12:$addr)>;
1235 def : T2Pat<(extloadi16 t2addrmode_imm8:$addr),
1236 (t2LDRHi8 t2addrmode_imm8:$addr)>;
1237 def : T2Pat<(extloadi16 t2addrmode_so_reg:$addr),
1238 (t2LDRHs t2addrmode_so_reg:$addr)>;
1239 def : T2Pat<(extloadi16 (ARMWrapper tconstpool:$addr)),
1240 (t2LDRHpci tconstpool:$addr)>;
1242 // FIXME: The destination register of the loads and stores can't be PC, but
1243 // can be SP. We need another regclass (similar to rGPR) to represent
1244 // that. Not a pressing issue since these are selected manually,
1249 let mayLoad = 1, neverHasSideEffects = 1 in {
1250 def t2LDR_PRE : T2Iidxldst<0, 0b10, 1, 1, (outs GPR:$Rt, GPR:$Rn),
1251 (ins t2addrmode_imm8:$addr),
1252 AddrModeT2_i8, IndexModePre, IIC_iLoad_iu,
1253 "ldr", "\t$Rt, $addr!", "$addr.base = $Rn",
1256 def t2LDR_POST : T2Iidxldst<0, 0b10, 1, 0, (outs GPR:$Rt, GPR:$Rn),
1257 (ins GPR:$base, t2am_imm8_offset:$addr),
1258 AddrModeT2_i8, IndexModePost, IIC_iLoad_iu,
1259 "ldr", "\t$Rt, [$Rn], $addr", "$base = $Rn",
1262 def t2LDRB_PRE : T2Iidxldst<0, 0b00, 1, 1, (outs GPR:$Rt, GPR:$Rn),
1263 (ins t2addrmode_imm8:$addr),
1264 AddrModeT2_i8, IndexModePre, IIC_iLoad_bh_iu,
1265 "ldrb", "\t$Rt, $addr!", "$addr.base = $Rn",
1267 def t2LDRB_POST : T2Iidxldst<0, 0b00, 1, 0, (outs GPR:$Rt, GPR:$Rn),
1268 (ins GPR:$base, t2am_imm8_offset:$addr),
1269 AddrModeT2_i8, IndexModePost, IIC_iLoad_bh_iu,
1270 "ldrb", "\t$Rt, [$Rn], $addr", "$base = $Rn",
1273 def t2LDRH_PRE : T2Iidxldst<0, 0b01, 1, 1, (outs GPR:$Rt, GPR:$Rn),
1274 (ins t2addrmode_imm8:$addr),
1275 AddrModeT2_i8, IndexModePre, IIC_iLoad_bh_iu,
1276 "ldrh", "\t$Rt, $addr!", "$addr.base = $Rn",
1278 def t2LDRH_POST : T2Iidxldst<0, 0b01, 1, 0, (outs GPR:$Rt, GPR:$Rn),
1279 (ins GPR:$base, t2am_imm8_offset:$addr),
1280 AddrModeT2_i8, IndexModePost, IIC_iLoad_bh_iu,
1281 "ldrh", "\t$Rt, [$Rn], $addr", "$base = $Rn",
1284 def t2LDRSB_PRE : T2Iidxldst<1, 0b00, 1, 1, (outs GPR:$Rt, GPR:$Rn),
1285 (ins t2addrmode_imm8:$addr),
1286 AddrModeT2_i8, IndexModePre, IIC_iLoad_bh_iu,
1287 "ldrsb", "\t$Rt, $addr!", "$addr.base = $Rn",
1289 def t2LDRSB_POST : T2Iidxldst<1, 0b00, 1, 0, (outs GPR:$Rt, GPR:$Rn),
1290 (ins GPR:$base, t2am_imm8_offset:$addr),
1291 AddrModeT2_i8, IndexModePost, IIC_iLoad_bh_iu,
1292 "ldrsb", "\t$Rt, [$Rn], $addr", "$base = $Rn",
1295 def t2LDRSH_PRE : T2Iidxldst<1, 0b01, 1, 1, (outs GPR:$Rt, GPR:$Rn),
1296 (ins t2addrmode_imm8:$addr),
1297 AddrModeT2_i8, IndexModePre, IIC_iLoad_bh_iu,
1298 "ldrsh", "\t$Rt, $addr!", "$addr.base = $Rn",
1300 def t2LDRSH_POST : T2Iidxldst<1, 0b01, 1, 0, (outs GPR:$dst, GPR:$Rn),
1301 (ins GPR:$base, t2am_imm8_offset:$addr),
1302 AddrModeT2_i8, IndexModePost, IIC_iLoad_bh_iu,
1303 "ldrsh", "\t$dst, [$Rn], $addr", "$base = $Rn",
1305 } // mayLoad = 1, neverHasSideEffects = 1
1307 // LDRT, LDRBT, LDRHT, LDRSBT, LDRSHT all have offset mode (PUW=0b110) and are
1308 // for disassembly only.
1309 // Ref: A8.6.57 LDR (immediate, Thumb) Encoding T4
1310 class T2IldT<bit signed, bits<2> type, string opc, InstrItinClass ii>
1311 : T2Ii8<(outs rGPR:$Rt), (ins t2addrmode_imm8:$addr), ii, opc,
1312 "\t$Rt, $addr", []> {
1313 let Inst{31-27} = 0b11111;
1314 let Inst{26-25} = 0b00;
1315 let Inst{24} = signed;
1317 let Inst{22-21} = type;
1318 let Inst{20} = 1; // load
1320 let Inst{10-8} = 0b110; // PUW.
1324 let Inst{15-12} = Rt;
1325 let Inst{19-16} = addr{12-9};
1326 let Inst{7-0} = addr{7-0};
1329 def t2LDRT : T2IldT<0, 0b10, "ldrt", IIC_iLoad_i>;
1330 def t2LDRBT : T2IldT<0, 0b00, "ldrbt", IIC_iLoad_bh_i>;
1331 def t2LDRHT : T2IldT<0, 0b01, "ldrht", IIC_iLoad_bh_i>;
1332 def t2LDRSBT : T2IldT<1, 0b00, "ldrsbt", IIC_iLoad_bh_i>;
1333 def t2LDRSHT : T2IldT<1, 0b01, "ldrsht", IIC_iLoad_bh_i>;
1336 defm t2STR :T2I_st<0b10,"str", IIC_iStore_i, IIC_iStore_si,
1337 BinOpFrag<(store node:$LHS, node:$RHS)>>;
1338 defm t2STRB:T2I_st<0b00,"strb", IIC_iStore_bh_i, IIC_iStore_bh_si,
1339 BinOpFrag<(truncstorei8 node:$LHS, node:$RHS)>>;
1340 defm t2STRH:T2I_st<0b01,"strh", IIC_iStore_bh_i, IIC_iStore_bh_si,
1341 BinOpFrag<(truncstorei16 node:$LHS, node:$RHS)>>;
1344 let mayLoad = 1, neverHasSideEffects = 1, hasExtraSrcRegAllocReq = 1 in
1345 def t2STRDi8 : T2Ii8s4<1, 0, 0, (outs),
1346 (ins GPR:$Rt, GPR:$Rt2, t2addrmode_imm8s4:$addr),
1347 IIC_iStore_d_r, "strd", "\t$Rt, $Rt2, $addr", []>;
1350 def t2STR_PRE : T2Iidxldst<0, 0b10, 0, 1, (outs GPR:$base_wb),
1351 (ins GPR:$Rt, GPR:$Rn, t2am_imm8_offset:$addr),
1352 AddrModeT2_i8, IndexModePre, IIC_iStore_iu,
1353 "str", "\t$Rt, [$Rn, $addr]!",
1354 "$Rn = $base_wb,@earlyclobber $base_wb",
1356 (pre_store GPR:$Rt, GPR:$Rn, t2am_imm8_offset:$addr))]>;
1358 def t2STR_POST : T2Iidxldst<0, 0b10, 0, 0, (outs GPR:$base_wb),
1359 (ins GPR:$Rt, GPR:$Rn, t2am_imm8_offset:$addr),
1360 AddrModeT2_i8, IndexModePost, IIC_iStore_iu,
1361 "str", "\t$Rt, [$Rn], $addr",
1362 "$Rn = $base_wb,@earlyclobber $base_wb",
1364 (post_store GPR:$Rt, GPR:$Rn, t2am_imm8_offset:$addr))]>;
1366 def t2STRH_PRE : T2Iidxldst<0, 0b01, 0, 1, (outs GPR:$base_wb),
1367 (ins GPR:$Rt, GPR:$Rn, t2am_imm8_offset:$addr),
1368 AddrModeT2_i8, IndexModePre, IIC_iStore_iu,
1369 "strh", "\t$Rt, [$Rn, $addr]!",
1370 "$Rn = $base_wb,@earlyclobber $base_wb",
1372 (pre_truncsti16 GPR:$Rt, GPR:$Rn, t2am_imm8_offset:$addr))]>;
1374 def t2STRH_POST : T2Iidxldst<0, 0b01, 0, 0, (outs GPR:$base_wb),
1375 (ins GPR:$Rt, GPR:$Rn, t2am_imm8_offset:$addr),
1376 AddrModeT2_i8, IndexModePost, IIC_iStore_bh_iu,
1377 "strh", "\t$Rt, [$Rn], $addr",
1378 "$Rn = $base_wb,@earlyclobber $base_wb",
1380 (post_truncsti16 GPR:$Rt, GPR:$Rn, t2am_imm8_offset:$addr))]>;
1382 def t2STRB_PRE : T2Iidxldst<0, 0b00, 0, 1, (outs GPR:$base_wb),
1383 (ins GPR:$Rt, GPR:$Rn, t2am_imm8_offset:$addr),
1384 AddrModeT2_i8, IndexModePre, IIC_iStore_bh_iu,
1385 "strb", "\t$Rt, [$Rn, $addr]!",
1386 "$Rn = $base_wb,@earlyclobber $base_wb",
1388 (pre_truncsti8 GPR:$Rt, GPR:$Rn, t2am_imm8_offset:$addr))]>;
1390 def t2STRB_POST : T2Iidxldst<0, 0b00, 0, 0, (outs GPR:$base_wb),
1391 (ins GPR:$Rt, GPR:$Rn, t2am_imm8_offset:$addr),
1392 AddrModeT2_i8, IndexModePost, IIC_iStore_bh_iu,
1393 "strb", "\t$Rt, [$Rn], $addr",
1394 "$Rn = $base_wb,@earlyclobber $base_wb",
1396 (post_truncsti8 GPR:$Rt, GPR:$Rn, t2am_imm8_offset:$addr))]>;
1398 // STRT, STRBT, STRHT all have offset mode (PUW=0b110) and are for disassembly
1400 // Ref: A8.6.193 STR (immediate, Thumb) Encoding T4
1401 class T2IstT<bits<2> type, string opc, InstrItinClass ii>
1402 : T2Ii8<(outs rGPR:$Rt), (ins t2addrmode_imm8:$addr), ii, opc,
1403 "\t$Rt, $addr", []> {
1404 let Inst{31-27} = 0b11111;
1405 let Inst{26-25} = 0b00;
1406 let Inst{24} = 0; // not signed
1408 let Inst{22-21} = type;
1409 let Inst{20} = 0; // store
1411 let Inst{10-8} = 0b110; // PUW
1415 let Inst{15-12} = Rt;
1416 let Inst{19-16} = addr{12-9};
1417 let Inst{7-0} = addr{7-0};
1420 def t2STRT : T2IstT<0b10, "strt", IIC_iStore_i>;
1421 def t2STRBT : T2IstT<0b00, "strbt", IIC_iStore_bh_i>;
1422 def t2STRHT : T2IstT<0b01, "strht", IIC_iStore_bh_i>;
1424 // ldrd / strd pre / post variants
1425 // For disassembly only.
1427 def t2LDRD_PRE : T2Ii8s4<1, 1, 1, (outs rGPR:$Rt, rGPR:$Rt2),
1428 (ins GPR:$base, t2am_imm8s4_offset:$imm), IIC_iLoad_d_ru,
1429 "ldrd", "\t$Rt, $Rt2, [$base, $imm]!", []>;
1431 def t2LDRD_POST : T2Ii8s4<0, 1, 1, (outs rGPR:$Rt, rGPR:$Rt2),
1432 (ins GPR:$base, t2am_imm8s4_offset:$imm), IIC_iLoad_d_ru,
1433 "ldrd", "\t$Rt, $Rt2, [$base], $imm", []>;
1435 def t2STRD_PRE : T2Ii8s4<1, 1, 0, (outs),
1436 (ins rGPR:$Rt, rGPR:$Rt2, GPR:$base, t2am_imm8s4_offset:$imm),
1437 IIC_iStore_d_ru, "strd", "\t$Rt, $Rt2, [$base, $imm]!", []>;
1439 def t2STRD_POST : T2Ii8s4<0, 1, 0, (outs),
1440 (ins rGPR:$Rt, rGPR:$Rt2, GPR:$base, t2am_imm8s4_offset:$imm),
1441 IIC_iStore_d_ru, "strd", "\t$Rt, $Rt2, [$base], $imm", []>;
1443 // T2Ipl (Preload Data/Instruction) signals the memory system of possible future
1444 // data/instruction access. These are for disassembly only.
1445 // instr_write is inverted for Thumb mode: (prefetch 3) -> (preload 0),
1446 // (prefetch 1) -> (preload 2), (prefetch 2) -> (preload 1).
1447 multiclass T2Ipl<bits<1> write, bits<1> instr, string opc> {
1449 def i12 : T2Ii12<(outs), (ins t2addrmode_imm12:$addr), IIC_Preload, opc,
1451 [(ARMPreload t2addrmode_imm12:$addr, (i32 write), (i32 instr))]> {
1452 let Inst{31-25} = 0b1111100;
1453 let Inst{24} = instr;
1455 let Inst{21} = write;
1457 let Inst{15-12} = 0b1111;
1460 let addr{12} = 1; // add = TRUE
1461 let Inst{19-16} = addr{16-13}; // Rn
1462 let Inst{23} = addr{12}; // U
1463 let Inst{11-0} = addr{11-0}; // imm12
1466 def i8 : T2Ii8<(outs), (ins t2addrmode_imm8:$addr), IIC_Preload, opc,
1468 [(ARMPreload t2addrmode_imm8:$addr, (i32 write), (i32 instr))]> {
1469 let Inst{31-25} = 0b1111100;
1470 let Inst{24} = instr;
1471 let Inst{23} = 0; // U = 0
1473 let Inst{21} = write;
1475 let Inst{15-12} = 0b1111;
1476 let Inst{11-8} = 0b1100;
1479 let Inst{19-16} = addr{12-9}; // Rn
1480 let Inst{7-0} = addr{7-0}; // imm8
1483 def s : T2Iso<(outs), (ins t2addrmode_so_reg:$addr), IIC_Preload, opc,
1485 [(ARMPreload t2addrmode_so_reg:$addr, (i32 write), (i32 instr))]> {
1486 let Inst{31-25} = 0b1111100;
1487 let Inst{24} = instr;
1488 let Inst{23} = 0; // add = TRUE for T1
1490 let Inst{21} = write;
1492 let Inst{15-12} = 0b1111;
1493 let Inst{11-6} = 0000000;
1496 let Inst{19-16} = addr{9-6}; // Rn
1497 let Inst{3-0} = addr{5-2}; // Rm
1498 let Inst{5-4} = addr{1-0}; // imm2
1502 defm t2PLD : T2Ipl<0, 0, "pld">, Requires<[IsThumb2]>;
1503 defm t2PLDW : T2Ipl<1, 0, "pldw">, Requires<[IsThumb2,HasV7,HasMP]>;
1504 defm t2PLI : T2Ipl<0, 1, "pli">, Requires<[IsThumb2,HasV7]>;
1506 //===----------------------------------------------------------------------===//
1507 // Load / store multiple Instructions.
1510 multiclass thumb2_ldst_mult<string asm, InstrItinClass itin,
1511 InstrItinClass itin_upd, bit L_bit> {
1513 T2XI<(outs), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops),
1514 itin, !strconcat(asm, "ia${p}.w\t$Rn, $regs"), []> {
1518 let Inst{31-27} = 0b11101;
1519 let Inst{26-25} = 0b00;
1520 let Inst{24-23} = 0b01; // Increment After
1522 let Inst{21} = 0; // No writeback
1523 let Inst{20} = L_bit;
1524 let Inst{19-16} = Rn;
1525 let Inst{15-0} = regs;
1528 T2XIt<(outs GPR:$wb), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops),
1529 itin_upd, !strconcat(asm, "ia${p}.w\t$Rn!, $regs"), "$Rn = $wb", []> {
1533 let Inst{31-27} = 0b11101;
1534 let Inst{26-25} = 0b00;
1535 let Inst{24-23} = 0b01; // Increment After
1537 let Inst{21} = 1; // Writeback
1538 let Inst{20} = L_bit;
1539 let Inst{19-16} = Rn;
1540 let Inst{15-0} = regs;
1543 T2XI<(outs), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops),
1544 itin, !strconcat(asm, "db${p}.w\t$Rn, $regs"), []> {
1548 let Inst{31-27} = 0b11101;
1549 let Inst{26-25} = 0b00;
1550 let Inst{24-23} = 0b10; // Decrement Before
1552 let Inst{21} = 0; // No writeback
1553 let Inst{20} = L_bit;
1554 let Inst{19-16} = Rn;
1555 let Inst{15-0} = regs;
1558 T2XIt<(outs GPR:$wb), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops),
1559 itin_upd, !strconcat(asm, "db${p}.w\t$Rn, $regs"), "$Rn = $wb", []> {
1563 let Inst{31-27} = 0b11101;
1564 let Inst{26-25} = 0b00;
1565 let Inst{24-23} = 0b10; // Decrement Before
1567 let Inst{21} = 1; // Writeback
1568 let Inst{20} = L_bit;
1569 let Inst{19-16} = Rn;
1570 let Inst{15-0} = regs;
1574 let neverHasSideEffects = 1 in {
1576 let mayLoad = 1, hasExtraDefRegAllocReq = 1 in
1577 defm t2LDM : thumb2_ldst_mult<"ldm", IIC_iLoad_m, IIC_iLoad_mu, 1>;
1579 let mayStore = 1, hasExtraSrcRegAllocReq = 1 in
1580 defm t2STM : thumb2_ldst_mult<"stm", IIC_iStore_m, IIC_iStore_mu, 0>;
1582 } // neverHasSideEffects
1585 //===----------------------------------------------------------------------===//
1586 // Move Instructions.
1589 let neverHasSideEffects = 1 in
1590 def t2MOVr : T2sTwoReg<(outs GPR:$Rd), (ins GPR:$Rm), IIC_iMOVr,
1591 "mov", ".w\t$Rd, $Rm", []> {
1592 let Inst{31-27} = 0b11101;
1593 let Inst{26-25} = 0b01;
1594 let Inst{24-21} = 0b0010;
1595 let Inst{19-16} = 0b1111; // Rn
1596 let Inst{14-12} = 0b000;
1597 let Inst{7-4} = 0b0000;
1600 // AddedComplexity to ensure isel tries t2MOVi before t2MOVi16.
1601 let isReMaterializable = 1, isAsCheapAsAMove = 1, isMoveImm = 1,
1602 AddedComplexity = 1 in
1603 def t2MOVi : T2sOneRegImm<(outs rGPR:$Rd), (ins t2_so_imm:$imm), IIC_iMOVi,
1604 "mov", ".w\t$Rd, $imm",
1605 [(set rGPR:$Rd, t2_so_imm:$imm)]> {
1606 let Inst{31-27} = 0b11110;
1608 let Inst{24-21} = 0b0010;
1609 let Inst{19-16} = 0b1111; // Rn
1613 def : InstAlias<"mov${s}${p} $Rd, $imm", (t2MOVi rGPR:$Rd, t2_so_imm:$imm,
1614 pred:$p, cc_out:$s)>,
1615 Requires<[IsThumb2]>;
1617 let isReMaterializable = 1, isAsCheapAsAMove = 1, isMoveImm = 1 in
1618 def t2MOVi16 : T2I<(outs rGPR:$Rd), (ins i32imm_hilo16:$imm), IIC_iMOVi,
1619 "movw", "\t$Rd, $imm",
1620 [(set rGPR:$Rd, imm0_65535:$imm)]> {
1621 let Inst{31-27} = 0b11110;
1623 let Inst{24-21} = 0b0010;
1624 let Inst{20} = 0; // The S bit.
1630 let Inst{11-8} = Rd;
1631 let Inst{19-16} = imm{15-12};
1632 let Inst{26} = imm{11};
1633 let Inst{14-12} = imm{10-8};
1634 let Inst{7-0} = imm{7-0};
1637 def t2MOVi16_ga_pcrel : PseudoInst<(outs rGPR:$Rd),
1638 (ins i32imm:$addr, pclabel:$id), IIC_iMOVi, []>;
1640 let Constraints = "$src = $Rd" in {
1641 def t2MOVTi16 : T2I<(outs rGPR:$Rd),
1642 (ins rGPR:$src, i32imm_hilo16:$imm), IIC_iMOVi,
1643 "movt", "\t$Rd, $imm",
1645 (or (and rGPR:$src, 0xffff), lo16AllZero:$imm))]> {
1646 let Inst{31-27} = 0b11110;
1648 let Inst{24-21} = 0b0110;
1649 let Inst{20} = 0; // The S bit.
1655 let Inst{11-8} = Rd;
1656 let Inst{19-16} = imm{15-12};
1657 let Inst{26} = imm{11};
1658 let Inst{14-12} = imm{10-8};
1659 let Inst{7-0} = imm{7-0};
1662 def t2MOVTi16_ga_pcrel : PseudoInst<(outs rGPR:$Rd),
1663 (ins rGPR:$src, i32imm:$addr, pclabel:$id), IIC_iMOVi, []>;
1666 def : T2Pat<(or rGPR:$src, 0xffff0000), (t2MOVTi16 rGPR:$src, 0xffff)>;
1668 //===----------------------------------------------------------------------===//
1669 // Extend Instructions.
1674 defm t2SXTB : T2I_ext_rrot<0b100, "sxtb",
1675 UnOpFrag<(sext_inreg node:$Src, i8)>>;
1676 defm t2SXTH : T2I_ext_rrot<0b000, "sxth",
1677 UnOpFrag<(sext_inreg node:$Src, i16)>>;
1678 defm t2SXTB16 : T2I_ext_rrot_sxtb16<0b010, "sxtb16">;
1680 defm t2SXTAB : T2I_exta_rrot<0b100, "sxtab",
1681 BinOpFrag<(add node:$LHS, (sext_inreg node:$RHS, i8))>>;
1682 defm t2SXTAH : T2I_exta_rrot<0b000, "sxtah",
1683 BinOpFrag<(add node:$LHS, (sext_inreg node:$RHS,i16))>>;
1684 defm t2SXTAB16 : T2I_exta_rrot_DO<0b010, "sxtab16">;
1686 // TODO: SXT(A){B|H}16 - done for disassembly only
1690 let AddedComplexity = 16 in {
1691 defm t2UXTB : T2I_ext_rrot<0b101, "uxtb",
1692 UnOpFrag<(and node:$Src, 0x000000FF)>>;
1693 defm t2UXTH : T2I_ext_rrot<0b001, "uxth",
1694 UnOpFrag<(and node:$Src, 0x0000FFFF)>>;
1695 defm t2UXTB16 : T2I_ext_rrot_uxtb16<0b011, "uxtb16",
1696 UnOpFrag<(and node:$Src, 0x00FF00FF)>>;
1698 // FIXME: This pattern incorrectly assumes the shl operator is a rotate.
1699 // The transformation should probably be done as a combiner action
1700 // instead so we can include a check for masking back in the upper
1701 // eight bits of the source into the lower eight bits of the result.
1702 //def : T2Pat<(and (shl rGPR:$Src, (i32 8)), 0xFF00FF),
1703 // (t2UXTB16r_rot rGPR:$Src, 24)>,
1704 // Requires<[HasT2ExtractPack, IsThumb2]>;
1705 def : T2Pat<(and (srl rGPR:$Src, (i32 8)), 0xFF00FF),
1706 (t2UXTB16r_rot rGPR:$Src, 8)>,
1707 Requires<[HasT2ExtractPack, IsThumb2]>;
1709 defm t2UXTAB : T2I_exta_rrot<0b101, "uxtab",
1710 BinOpFrag<(add node:$LHS, (and node:$RHS, 0x00FF))>>;
1711 defm t2UXTAH : T2I_exta_rrot<0b001, "uxtah",
1712 BinOpFrag<(add node:$LHS, (and node:$RHS, 0xFFFF))>>;
1713 defm t2UXTAB16 : T2I_exta_rrot_DO<0b011, "uxtab16">;
1716 //===----------------------------------------------------------------------===//
1717 // Arithmetic Instructions.
1720 defm t2ADD : T2I_bin_ii12rs<0b000, "add",
1721 BinOpFrag<(add node:$LHS, node:$RHS)>, 1>;
1722 defm t2SUB : T2I_bin_ii12rs<0b101, "sub",
1723 BinOpFrag<(sub node:$LHS, node:$RHS)>>;
1725 // ADD and SUB with 's' bit set. No 12-bit immediate (T4) variants.
1726 defm t2ADDS : T2I_bin_s_irs <0b1000, "add",
1727 IIC_iALUi, IIC_iALUr, IIC_iALUsi,
1728 BinOpFrag<(addc node:$LHS, node:$RHS)>, 1>;
1729 defm t2SUBS : T2I_bin_s_irs <0b1101, "sub",
1730 IIC_iALUi, IIC_iALUr, IIC_iALUsi,
1731 BinOpFrag<(subc node:$LHS, node:$RHS)>>;
1733 defm t2ADC : T2I_adde_sube_irs<0b1010, "adc",
1734 BinOpFrag<(adde_dead_carry node:$LHS, node:$RHS)>, 1>;
1735 defm t2SBC : T2I_adde_sube_irs<0b1011, "sbc",
1736 BinOpFrag<(sube_dead_carry node:$LHS, node:$RHS)>>;
1737 defm t2ADCS : T2I_adde_sube_s_irs<BinOpFrag<(adde_live_carry node:$LHS,
1739 defm t2SBCS : T2I_adde_sube_s_irs<BinOpFrag<(sube_live_carry node:$LHS,
1743 defm t2RSB : T2I_rbin_irs <0b1110, "rsb",
1744 BinOpFrag<(sub node:$LHS, node:$RHS)>>;
1745 defm t2RSBS : T2I_rbin_s_is <0b1110, "rsb",
1746 BinOpFrag<(subc node:$LHS, node:$RHS)>>;
1748 // (sub X, imm) gets canonicalized to (add X, -imm). Match this form.
1749 // The assume-no-carry-in form uses the negation of the input since add/sub
1750 // assume opposite meanings of the carry flag (i.e., carry == !borrow).
1751 // See the definition of AddWithCarry() in the ARM ARM A2.2.1 for the gory
1753 // The AddedComplexity preferences the first variant over the others since
1754 // it can be shrunk to a 16-bit wide encoding, while the others cannot.
1755 let AddedComplexity = 1 in
1756 def : T2Pat<(add GPR:$src, imm0_255_neg:$imm),
1757 (t2SUBri GPR:$src, imm0_255_neg:$imm)>;
1758 def : T2Pat<(add GPR:$src, t2_so_imm_neg:$imm),
1759 (t2SUBri GPR:$src, t2_so_imm_neg:$imm)>;
1760 def : T2Pat<(add GPR:$src, imm0_4095_neg:$imm),
1761 (t2SUBri12 GPR:$src, imm0_4095_neg:$imm)>;
1762 let AddedComplexity = 1 in
1763 def : T2Pat<(addc rGPR:$src, imm0_255_neg:$imm),
1764 (t2SUBSri rGPR:$src, imm0_255_neg:$imm)>;
1765 def : T2Pat<(addc rGPR:$src, t2_so_imm_neg:$imm),
1766 (t2SUBSri rGPR:$src, t2_so_imm_neg:$imm)>;
1767 // The with-carry-in form matches bitwise not instead of the negation.
1768 // Effectively, the inverse interpretation of the carry flag already accounts
1769 // for part of the negation.
1770 let AddedComplexity = 1 in
1771 def : T2Pat<(adde_dead_carry rGPR:$src, imm0_255_not:$imm),
1772 (t2SBCri rGPR:$src, imm0_255_not:$imm)>;
1773 def : T2Pat<(adde_dead_carry rGPR:$src, t2_so_imm_not:$imm),
1774 (t2SBCri rGPR:$src, t2_so_imm_not:$imm)>;
1775 let AddedComplexity = 1 in
1776 def : T2Pat<(adde_live_carry rGPR:$src, imm0_255_not:$imm),
1777 (t2SBCSri rGPR:$src, imm0_255_not:$imm)>;
1778 def : T2Pat<(adde_live_carry rGPR:$src, t2_so_imm_not:$imm),
1779 (t2SBCSri rGPR:$src, t2_so_imm_not:$imm)>;
1781 // Select Bytes -- for disassembly only
1783 def t2SEL : T2ThreeReg<(outs GPR:$Rd), (ins GPR:$Rn, GPR:$Rm),
1784 NoItinerary, "sel", "\t$Rd, $Rn, $Rm", []>,
1785 Requires<[IsThumb2, HasThumb2DSP]> {
1786 let Inst{31-27} = 0b11111;
1787 let Inst{26-24} = 0b010;
1789 let Inst{22-20} = 0b010;
1790 let Inst{15-12} = 0b1111;
1792 let Inst{6-4} = 0b000;
1795 // A6.3.13, A6.3.14, A6.3.15 Parallel addition and subtraction (signed/unsigned)
1796 // And Miscellaneous operations -- for disassembly only
1797 class T2I_pam<bits<3> op22_20, bits<4> op7_4, string opc,
1798 list<dag> pat = [/* For disassembly only; pattern left blank */],
1799 dag iops = (ins rGPR:$Rn, rGPR:$Rm),
1800 string asm = "\t$Rd, $Rn, $Rm">
1801 : T2I<(outs rGPR:$Rd), iops, NoItinerary, opc, asm, pat>,
1802 Requires<[IsThumb2, HasThumb2DSP]> {
1803 let Inst{31-27} = 0b11111;
1804 let Inst{26-23} = 0b0101;
1805 let Inst{22-20} = op22_20;
1806 let Inst{15-12} = 0b1111;
1807 let Inst{7-4} = op7_4;
1813 let Inst{11-8} = Rd;
1814 let Inst{19-16} = Rn;
1818 // Saturating add/subtract -- for disassembly only
1820 def t2QADD : T2I_pam<0b000, 0b1000, "qadd",
1821 [(set rGPR:$Rd, (int_arm_qadd rGPR:$Rn, rGPR:$Rm))],
1822 (ins rGPR:$Rm, rGPR:$Rn), "\t$Rd, $Rm, $Rn">;
1823 def t2QADD16 : T2I_pam<0b001, 0b0001, "qadd16">;
1824 def t2QADD8 : T2I_pam<0b000, 0b0001, "qadd8">;
1825 def t2QASX : T2I_pam<0b010, 0b0001, "qasx">;
1826 def t2QDADD : T2I_pam<0b000, 0b1001, "qdadd", [],
1827 (ins rGPR:$Rm, rGPR:$Rn), "\t$Rd, $Rm, $Rn">;
1828 def t2QDSUB : T2I_pam<0b000, 0b1011, "qdsub", [],
1829 (ins rGPR:$Rm, rGPR:$Rn), "\t$Rd, $Rm, $Rn">;
1830 def t2QSAX : T2I_pam<0b110, 0b0001, "qsax">;
1831 def t2QSUB : T2I_pam<0b000, 0b1010, "qsub",
1832 [(set rGPR:$Rd, (int_arm_qsub rGPR:$Rn, rGPR:$Rm))],
1833 (ins rGPR:$Rm, rGPR:$Rn), "\t$Rd, $Rm, $Rn">;
1834 def t2QSUB16 : T2I_pam<0b101, 0b0001, "qsub16">;
1835 def t2QSUB8 : T2I_pam<0b100, 0b0001, "qsub8">;
1836 def t2UQADD16 : T2I_pam<0b001, 0b0101, "uqadd16">;
1837 def t2UQADD8 : T2I_pam<0b000, 0b0101, "uqadd8">;
1838 def t2UQASX : T2I_pam<0b010, 0b0101, "uqasx">;
1839 def t2UQSAX : T2I_pam<0b110, 0b0101, "uqsax">;
1840 def t2UQSUB16 : T2I_pam<0b101, 0b0101, "uqsub16">;
1841 def t2UQSUB8 : T2I_pam<0b100, 0b0101, "uqsub8">;
1843 // Signed/Unsigned add/subtract -- for disassembly only
1845 def t2SASX : T2I_pam<0b010, 0b0000, "sasx">;
1846 def t2SADD16 : T2I_pam<0b001, 0b0000, "sadd16">;
1847 def t2SADD8 : T2I_pam<0b000, 0b0000, "sadd8">;
1848 def t2SSAX : T2I_pam<0b110, 0b0000, "ssax">;
1849 def t2SSUB16 : T2I_pam<0b101, 0b0000, "ssub16">;
1850 def t2SSUB8 : T2I_pam<0b100, 0b0000, "ssub8">;
1851 def t2UASX : T2I_pam<0b010, 0b0100, "uasx">;
1852 def t2UADD16 : T2I_pam<0b001, 0b0100, "uadd16">;
1853 def t2UADD8 : T2I_pam<0b000, 0b0100, "uadd8">;
1854 def t2USAX : T2I_pam<0b110, 0b0100, "usax">;
1855 def t2USUB16 : T2I_pam<0b101, 0b0100, "usub16">;
1856 def t2USUB8 : T2I_pam<0b100, 0b0100, "usub8">;
1858 // Signed/Unsigned halving add/subtract -- for disassembly only
1860 def t2SHASX : T2I_pam<0b010, 0b0010, "shasx">;
1861 def t2SHADD16 : T2I_pam<0b001, 0b0010, "shadd16">;
1862 def t2SHADD8 : T2I_pam<0b000, 0b0010, "shadd8">;
1863 def t2SHSAX : T2I_pam<0b110, 0b0010, "shsax">;
1864 def t2SHSUB16 : T2I_pam<0b101, 0b0010, "shsub16">;
1865 def t2SHSUB8 : T2I_pam<0b100, 0b0010, "shsub8">;
1866 def t2UHASX : T2I_pam<0b010, 0b0110, "uhasx">;
1867 def t2UHADD16 : T2I_pam<0b001, 0b0110, "uhadd16">;
1868 def t2UHADD8 : T2I_pam<0b000, 0b0110, "uhadd8">;
1869 def t2UHSAX : T2I_pam<0b110, 0b0110, "uhsax">;
1870 def t2UHSUB16 : T2I_pam<0b101, 0b0110, "uhsub16">;
1871 def t2UHSUB8 : T2I_pam<0b100, 0b0110, "uhsub8">;
1873 // Helper class for disassembly only
1874 // A6.3.16 & A6.3.17
1875 // T2Imac - Thumb2 multiply [accumulate, and absolute difference] instructions.
1876 class T2ThreeReg_mac<bit long, bits<3> op22_20, bits<4> op7_4, dag oops,
1877 dag iops, InstrItinClass itin, string opc, string asm, list<dag> pattern>
1878 : T2ThreeReg<oops, iops, itin, opc, asm, pattern> {
1879 let Inst{31-27} = 0b11111;
1880 let Inst{26-24} = 0b011;
1881 let Inst{23} = long;
1882 let Inst{22-20} = op22_20;
1883 let Inst{7-4} = op7_4;
1886 class T2FourReg_mac<bit long, bits<3> op22_20, bits<4> op7_4, dag oops,
1887 dag iops, InstrItinClass itin, string opc, string asm, list<dag> pattern>
1888 : T2FourReg<oops, iops, itin, opc, asm, pattern> {
1889 let Inst{31-27} = 0b11111;
1890 let Inst{26-24} = 0b011;
1891 let Inst{23} = long;
1892 let Inst{22-20} = op22_20;
1893 let Inst{7-4} = op7_4;
1896 // Unsigned Sum of Absolute Differences [and Accumulate] -- for disassembly only
1898 def t2USAD8 : T2ThreeReg_mac<0, 0b111, 0b0000, (outs rGPR:$Rd),
1899 (ins rGPR:$Rn, rGPR:$Rm),
1900 NoItinerary, "usad8", "\t$Rd, $Rn, $Rm", []>,
1901 Requires<[IsThumb2, HasThumb2DSP]> {
1902 let Inst{15-12} = 0b1111;
1904 def t2USADA8 : T2FourReg_mac<0, 0b111, 0b0000, (outs rGPR:$Rd),
1905 (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), NoItinerary,
1906 "usada8", "\t$Rd, $Rn, $Rm, $Ra", []>,
1907 Requires<[IsThumb2, HasThumb2DSP]>;
1909 // Signed/Unsigned saturate -- for disassembly only
1911 class T2SatI<dag oops, dag iops, InstrItinClass itin,
1912 string opc, string asm, list<dag> pattern>
1913 : T2I<oops, iops, itin, opc, asm, pattern> {
1919 let Inst{11-8} = Rd;
1920 let Inst{19-16} = Rn;
1921 let Inst{4-0} = sat_imm{4-0};
1922 let Inst{21} = sh{6};
1923 let Inst{14-12} = sh{4-2};
1924 let Inst{7-6} = sh{1-0};
1928 (outs rGPR:$Rd), (ins ssat_imm:$sat_imm, rGPR:$Rn, shift_imm:$sh),
1929 NoItinerary, "ssat", "\t$Rd, $sat_imm, $Rn$sh",
1930 [/* For disassembly only; pattern left blank */]> {
1931 let Inst{31-27} = 0b11110;
1932 let Inst{25-22} = 0b1100;
1937 def t2SSAT16: T2SatI<
1938 (outs rGPR:$Rd), (ins ssat_imm:$sat_imm, rGPR:$Rn), NoItinerary,
1939 "ssat16", "\t$Rd, $sat_imm, $Rn",
1940 [/* For disassembly only; pattern left blank */]>,
1941 Requires<[IsThumb2, HasThumb2DSP]> {
1942 let Inst{31-27} = 0b11110;
1943 let Inst{25-22} = 0b1100;
1946 let Inst{21} = 1; // sh = '1'
1947 let Inst{14-12} = 0b000; // imm3 = '000'
1948 let Inst{7-6} = 0b00; // imm2 = '00'
1952 (outs rGPR:$Rd), (ins i32imm:$sat_imm, rGPR:$Rn, shift_imm:$sh),
1953 NoItinerary, "usat", "\t$Rd, $sat_imm, $Rn$sh",
1954 [/* For disassembly only; pattern left blank */]> {
1955 let Inst{31-27} = 0b11110;
1956 let Inst{25-22} = 0b1110;
1961 def t2USAT16: T2SatI<(outs rGPR:$dst), (ins i32imm:$sat_imm, rGPR:$Rn),
1963 "usat16", "\t$dst, $sat_imm, $Rn",
1964 [/* For disassembly only; pattern left blank */]>,
1965 Requires<[IsThumb2, HasThumb2DSP]> {
1966 let Inst{31-27} = 0b11110;
1967 let Inst{25-22} = 0b1110;
1970 let Inst{21} = 1; // sh = '1'
1971 let Inst{14-12} = 0b000; // imm3 = '000'
1972 let Inst{7-6} = 0b00; // imm2 = '00'
1975 def : T2Pat<(int_arm_ssat GPR:$a, imm:$pos), (t2SSAT imm:$pos, GPR:$a, 0)>;
1976 def : T2Pat<(int_arm_usat GPR:$a, imm:$pos), (t2USAT imm:$pos, GPR:$a, 0)>;
1978 //===----------------------------------------------------------------------===//
1979 // Shift and rotate Instructions.
1982 defm t2LSL : T2I_sh_ir<0b00, "lsl", BinOpFrag<(shl node:$LHS, node:$RHS)>>;
1983 defm t2LSR : T2I_sh_ir<0b01, "lsr", BinOpFrag<(srl node:$LHS, node:$RHS)>>;
1984 defm t2ASR : T2I_sh_ir<0b10, "asr", BinOpFrag<(sra node:$LHS, node:$RHS)>>;
1985 defm t2ROR : T2I_sh_ir<0b11, "ror", BinOpFrag<(rotr node:$LHS, node:$RHS)>>;
1987 // (rotr x, (and y, 0x...1f)) ==> (ROR x, y)
1988 def : Pat<(rotr rGPR:$lhs, (and rGPR:$rhs, lo5AllOne)),
1989 (t2RORrr rGPR:$lhs, rGPR:$rhs)>;
1991 let Uses = [CPSR] in {
1992 def t2RRX : T2sTwoReg<(outs rGPR:$Rd), (ins rGPR:$Rm), IIC_iMOVsi,
1993 "rrx", "\t$Rd, $Rm",
1994 [(set rGPR:$Rd, (ARMrrx rGPR:$Rm))]> {
1995 let Inst{31-27} = 0b11101;
1996 let Inst{26-25} = 0b01;
1997 let Inst{24-21} = 0b0010;
1998 let Inst{19-16} = 0b1111; // Rn
1999 let Inst{14-12} = 0b000;
2000 let Inst{7-4} = 0b0011;
2004 let isCodeGenOnly = 1, Defs = [CPSR] in {
2005 def t2MOVsrl_flag : T2TwoRegShiftImm<
2006 (outs rGPR:$Rd), (ins rGPR:$Rm), IIC_iMOVsi,
2007 "lsrs", ".w\t$Rd, $Rm, #1",
2008 [(set rGPR:$Rd, (ARMsrl_flag rGPR:$Rm))]> {
2009 let Inst{31-27} = 0b11101;
2010 let Inst{26-25} = 0b01;
2011 let Inst{24-21} = 0b0010;
2012 let Inst{20} = 1; // The S bit.
2013 let Inst{19-16} = 0b1111; // Rn
2014 let Inst{5-4} = 0b01; // Shift type.
2015 // Shift amount = Inst{14-12:7-6} = 1.
2016 let Inst{14-12} = 0b000;
2017 let Inst{7-6} = 0b01;
2019 def t2MOVsra_flag : T2TwoRegShiftImm<
2020 (outs rGPR:$Rd), (ins rGPR:$Rm), IIC_iMOVsi,
2021 "asrs", ".w\t$Rd, $Rm, #1",
2022 [(set rGPR:$Rd, (ARMsra_flag rGPR:$Rm))]> {
2023 let Inst{31-27} = 0b11101;
2024 let Inst{26-25} = 0b01;
2025 let Inst{24-21} = 0b0010;
2026 let Inst{20} = 1; // The S bit.
2027 let Inst{19-16} = 0b1111; // Rn
2028 let Inst{5-4} = 0b10; // Shift type.
2029 // Shift amount = Inst{14-12:7-6} = 1.
2030 let Inst{14-12} = 0b000;
2031 let Inst{7-6} = 0b01;
2035 //===----------------------------------------------------------------------===//
2036 // Bitwise Instructions.
2039 defm t2AND : T2I_bin_w_irs<0b0000, "and",
2040 IIC_iBITi, IIC_iBITr, IIC_iBITsi,
2041 BinOpFrag<(and node:$LHS, node:$RHS)>, "t2AND", 1>;
2042 defm t2ORR : T2I_bin_w_irs<0b0010, "orr",
2043 IIC_iBITi, IIC_iBITr, IIC_iBITsi,
2044 BinOpFrag<(or node:$LHS, node:$RHS)>, "t2ORR", 1>;
2045 defm t2EOR : T2I_bin_w_irs<0b0100, "eor",
2046 IIC_iBITi, IIC_iBITr, IIC_iBITsi,
2047 BinOpFrag<(xor node:$LHS, node:$RHS)>, "t2EOR", 1>;
2049 defm t2BIC : T2I_bin_w_irs<0b0001, "bic",
2050 IIC_iBITi, IIC_iBITr, IIC_iBITsi,
2051 BinOpFrag<(and node:$LHS, (not node:$RHS))>,
2054 class T2BitFI<dag oops, dag iops, InstrItinClass itin,
2055 string opc, string asm, list<dag> pattern>
2056 : T2I<oops, iops, itin, opc, asm, pattern> {
2061 let Inst{11-8} = Rd;
2062 let Inst{4-0} = msb{4-0};
2063 let Inst{14-12} = lsb{4-2};
2064 let Inst{7-6} = lsb{1-0};
2067 class T2TwoRegBitFI<dag oops, dag iops, InstrItinClass itin,
2068 string opc, string asm, list<dag> pattern>
2069 : T2BitFI<oops, iops, itin, opc, asm, pattern> {
2072 let Inst{19-16} = Rn;
2075 let Constraints = "$src = $Rd" in
2076 def t2BFC : T2BitFI<(outs rGPR:$Rd), (ins rGPR:$src, bf_inv_mask_imm:$imm),
2077 IIC_iUNAsi, "bfc", "\t$Rd, $imm",
2078 [(set rGPR:$Rd, (and rGPR:$src, bf_inv_mask_imm:$imm))]> {
2079 let Inst{31-27} = 0b11110;
2080 let Inst{26} = 0; // should be 0.
2082 let Inst{24-20} = 0b10110;
2083 let Inst{19-16} = 0b1111; // Rn
2085 let Inst{5} = 0; // should be 0.
2088 let msb{4-0} = imm{9-5};
2089 let lsb{4-0} = imm{4-0};
2092 def t2SBFX: T2TwoRegBitFI<
2093 (outs rGPR:$Rd), (ins rGPR:$Rn, imm0_31:$lsb, imm0_31_m1:$msb),
2094 IIC_iUNAsi, "sbfx", "\t$Rd, $Rn, $lsb, $msb", []> {
2095 let Inst{31-27} = 0b11110;
2097 let Inst{24-20} = 0b10100;
2101 def t2UBFX: T2TwoRegBitFI<
2102 (outs rGPR:$Rd), (ins rGPR:$Rn, imm0_31:$lsb, imm0_31_m1:$msb),
2103 IIC_iUNAsi, "ubfx", "\t$Rd, $Rn, $lsb, $msb", []> {
2104 let Inst{31-27} = 0b11110;
2106 let Inst{24-20} = 0b11100;
2110 // A8.6.18 BFI - Bitfield insert (Encoding T1)
2111 let Constraints = "$src = $Rd" in {
2112 def t2BFI : T2TwoRegBitFI<(outs rGPR:$Rd),
2113 (ins rGPR:$src, rGPR:$Rn, bf_inv_mask_imm:$imm),
2114 IIC_iBITi, "bfi", "\t$Rd, $Rn, $imm",
2115 [(set rGPR:$Rd, (ARMbfi rGPR:$src, rGPR:$Rn,
2116 bf_inv_mask_imm:$imm))]> {
2117 let Inst{31-27} = 0b11110;
2118 let Inst{26} = 0; // should be 0.
2120 let Inst{24-20} = 0b10110;
2122 let Inst{5} = 0; // should be 0.
2125 let msb{4-0} = imm{9-5};
2126 let lsb{4-0} = imm{4-0};
2129 // GNU as only supports this form of bfi (w/ 4 arguments)
2130 let isAsmParserOnly = 1 in
2131 def t2BFI4p : T2TwoRegBitFI<(outs rGPR:$Rd),
2132 (ins rGPR:$src, rGPR:$Rn, lsb_pos_imm:$lsbit,
2134 IIC_iBITi, "bfi", "\t$Rd, $Rn, $lsbit, $width",
2136 let Inst{31-27} = 0b11110;
2137 let Inst{26} = 0; // should be 0.
2139 let Inst{24-20} = 0b10110;
2141 let Inst{5} = 0; // should be 0.
2145 let msb{4-0} = width; // Custom encoder => lsb+width-1
2146 let lsb{4-0} = lsbit;
2150 defm t2ORN : T2I_bin_irs<0b0011, "orn",
2151 IIC_iBITi, IIC_iBITr, IIC_iBITsi,
2152 BinOpFrag<(or node:$LHS, (not node:$RHS))>,
2155 // Prefer over of t2EORri ra, rb, -1 because mvn has 16-bit version
2156 let AddedComplexity = 1 in
2157 defm t2MVN : T2I_un_irs <0b0011, "mvn",
2158 IIC_iMVNi, IIC_iMVNr, IIC_iMVNsi,
2159 UnOpFrag<(not node:$Src)>, 1, 1>;
2162 let AddedComplexity = 1 in
2163 def : T2Pat<(and rGPR:$src, t2_so_imm_not:$imm),
2164 (t2BICri rGPR:$src, t2_so_imm_not:$imm)>;
2166 // FIXME: Disable this pattern on Darwin to workaround an assembler bug.
2167 def : T2Pat<(or rGPR:$src, t2_so_imm_not:$imm),
2168 (t2ORNri rGPR:$src, t2_so_imm_not:$imm)>,
2169 Requires<[IsThumb2]>;
2171 def : T2Pat<(t2_so_imm_not:$src),
2172 (t2MVNi t2_so_imm_not:$src)>;
2174 //===----------------------------------------------------------------------===//
2175 // Multiply Instructions.
2177 let isCommutable = 1 in
2178 def t2MUL: T2ThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iMUL32,
2179 "mul", "\t$Rd, $Rn, $Rm",
2180 [(set rGPR:$Rd, (mul rGPR:$Rn, rGPR:$Rm))]> {
2181 let Inst{31-27} = 0b11111;
2182 let Inst{26-23} = 0b0110;
2183 let Inst{22-20} = 0b000;
2184 let Inst{15-12} = 0b1111; // Ra = 0b1111 (no accumulate)
2185 let Inst{7-4} = 0b0000; // Multiply
2188 def t2MLA: T2FourReg<
2189 (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC32,
2190 "mla", "\t$Rd, $Rn, $Rm, $Ra",
2191 [(set rGPR:$Rd, (add (mul rGPR:$Rn, rGPR:$Rm), rGPR:$Ra))]> {
2192 let Inst{31-27} = 0b11111;
2193 let Inst{26-23} = 0b0110;
2194 let Inst{22-20} = 0b000;
2195 let Inst{7-4} = 0b0000; // Multiply
2198 def t2MLS: T2FourReg<
2199 (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC32,
2200 "mls", "\t$Rd, $Rn, $Rm, $Ra",
2201 [(set rGPR:$Rd, (sub rGPR:$Ra, (mul rGPR:$Rn, rGPR:$Rm)))]> {
2202 let Inst{31-27} = 0b11111;
2203 let Inst{26-23} = 0b0110;
2204 let Inst{22-20} = 0b000;
2205 let Inst{7-4} = 0b0001; // Multiply and Subtract
2208 // Extra precision multiplies with low / high results
2209 let neverHasSideEffects = 1 in {
2210 let isCommutable = 1 in {
2211 def t2SMULL : T2MulLong<0b000, 0b0000,
2212 (outs rGPR:$Rd, rGPR:$Ra),
2213 (ins rGPR:$Rn, rGPR:$Rm), IIC_iMUL64,
2214 "smull", "\t$Rd, $Ra, $Rn, $Rm", []>;
2216 def t2UMULL : T2MulLong<0b010, 0b0000,
2217 (outs rGPR:$RdLo, rGPR:$RdHi),
2218 (ins rGPR:$Rn, rGPR:$Rm), IIC_iMUL64,
2219 "umull", "\t$RdLo, $RdHi, $Rn, $Rm", []>;
2222 // Multiply + accumulate
2223 def t2SMLAL : T2MulLong<0b100, 0b0000,
2224 (outs rGPR:$RdLo, rGPR:$RdHi),
2225 (ins rGPR:$Rn, rGPR:$Rm), IIC_iMAC64,
2226 "smlal", "\t$RdLo, $RdHi, $Rn, $Rm", []>;
2228 def t2UMLAL : T2MulLong<0b110, 0b0000,
2229 (outs rGPR:$RdLo, rGPR:$RdHi),
2230 (ins rGPR:$Rn, rGPR:$Rm), IIC_iMAC64,
2231 "umlal", "\t$RdLo, $RdHi, $Rn, $Rm", []>;
2233 def t2UMAAL : T2MulLong<0b110, 0b0110,
2234 (outs rGPR:$RdLo, rGPR:$RdHi),
2235 (ins rGPR:$Rn, rGPR:$Rm), IIC_iMAC64,
2236 "umaal", "\t$RdLo, $RdHi, $Rn, $Rm", []>,
2237 Requires<[IsThumb2, HasThumb2DSP]>;
2238 } // neverHasSideEffects
2240 // Rounding variants of the below included for disassembly only
2242 // Most significant word multiply
2243 def t2SMMUL : T2ThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iMUL32,
2244 "smmul", "\t$Rd, $Rn, $Rm",
2245 [(set rGPR:$Rd, (mulhs rGPR:$Rn, rGPR:$Rm))]>,
2246 Requires<[IsThumb2, HasThumb2DSP]> {
2247 let Inst{31-27} = 0b11111;
2248 let Inst{26-23} = 0b0110;
2249 let Inst{22-20} = 0b101;
2250 let Inst{15-12} = 0b1111; // Ra = 0b1111 (no accumulate)
2251 let Inst{7-4} = 0b0000; // No Rounding (Inst{4} = 0)
2254 def t2SMMULR : T2ThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iMUL32,
2255 "smmulr", "\t$Rd, $Rn, $Rm", []>,
2256 Requires<[IsThumb2, HasThumb2DSP]> {
2257 let Inst{31-27} = 0b11111;
2258 let Inst{26-23} = 0b0110;
2259 let Inst{22-20} = 0b101;
2260 let Inst{15-12} = 0b1111; // Ra = 0b1111 (no accumulate)
2261 let Inst{7-4} = 0b0001; // Rounding (Inst{4} = 1)
2264 def t2SMMLA : T2FourReg<
2265 (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC32,
2266 "smmla", "\t$Rd, $Rn, $Rm, $Ra",
2267 [(set rGPR:$Rd, (add (mulhs rGPR:$Rm, rGPR:$Rn), rGPR:$Ra))]>,
2268 Requires<[IsThumb2, HasThumb2DSP]> {
2269 let Inst{31-27} = 0b11111;
2270 let Inst{26-23} = 0b0110;
2271 let Inst{22-20} = 0b101;
2272 let Inst{7-4} = 0b0000; // No Rounding (Inst{4} = 0)
2275 def t2SMMLAR: T2FourReg<
2276 (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC32,
2277 "smmlar", "\t$Rd, $Rn, $Rm, $Ra", []>,
2278 Requires<[IsThumb2, HasThumb2DSP]> {
2279 let Inst{31-27} = 0b11111;
2280 let Inst{26-23} = 0b0110;
2281 let Inst{22-20} = 0b101;
2282 let Inst{7-4} = 0b0001; // Rounding (Inst{4} = 1)
2285 def t2SMMLS: T2FourReg<
2286 (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC32,
2287 "smmls", "\t$Rd, $Rn, $Rm, $Ra",
2288 [(set rGPR:$Rd, (sub rGPR:$Ra, (mulhs rGPR:$Rn, rGPR:$Rm)))]>,
2289 Requires<[IsThumb2, HasThumb2DSP]> {
2290 let Inst{31-27} = 0b11111;
2291 let Inst{26-23} = 0b0110;
2292 let Inst{22-20} = 0b110;
2293 let Inst{7-4} = 0b0000; // No Rounding (Inst{4} = 0)
2296 def t2SMMLSR:T2FourReg<
2297 (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC32,
2298 "smmlsr", "\t$Rd, $Rn, $Rm, $Ra", []>,
2299 Requires<[IsThumb2, HasThumb2DSP]> {
2300 let Inst{31-27} = 0b11111;
2301 let Inst{26-23} = 0b0110;
2302 let Inst{22-20} = 0b110;
2303 let Inst{7-4} = 0b0001; // Rounding (Inst{4} = 1)
2306 multiclass T2I_smul<string opc, PatFrag opnode> {
2307 def BB : T2ThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iMUL16,
2308 !strconcat(opc, "bb"), "\t$Rd, $Rn, $Rm",
2309 [(set rGPR:$Rd, (opnode (sext_inreg rGPR:$Rn, i16),
2310 (sext_inreg rGPR:$Rm, i16)))]>,
2311 Requires<[IsThumb2, HasThumb2DSP]> {
2312 let Inst{31-27} = 0b11111;
2313 let Inst{26-23} = 0b0110;
2314 let Inst{22-20} = 0b001;
2315 let Inst{15-12} = 0b1111; // Ra = 0b1111 (no accumulate)
2316 let Inst{7-6} = 0b00;
2317 let Inst{5-4} = 0b00;
2320 def BT : T2ThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iMUL16,
2321 !strconcat(opc, "bt"), "\t$Rd, $Rn, $Rm",
2322 [(set rGPR:$Rd, (opnode (sext_inreg rGPR:$Rn, i16),
2323 (sra rGPR:$Rm, (i32 16))))]>,
2324 Requires<[IsThumb2, HasThumb2DSP]> {
2325 let Inst{31-27} = 0b11111;
2326 let Inst{26-23} = 0b0110;
2327 let Inst{22-20} = 0b001;
2328 let Inst{15-12} = 0b1111; // Ra = 0b1111 (no accumulate)
2329 let Inst{7-6} = 0b00;
2330 let Inst{5-4} = 0b01;
2333 def TB : T2ThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iMUL16,
2334 !strconcat(opc, "tb"), "\t$Rd, $Rn, $Rm",
2335 [(set rGPR:$Rd, (opnode (sra rGPR:$Rn, (i32 16)),
2336 (sext_inreg rGPR:$Rm, i16)))]>,
2337 Requires<[IsThumb2, HasThumb2DSP]> {
2338 let Inst{31-27} = 0b11111;
2339 let Inst{26-23} = 0b0110;
2340 let Inst{22-20} = 0b001;
2341 let Inst{15-12} = 0b1111; // Ra = 0b1111 (no accumulate)
2342 let Inst{7-6} = 0b00;
2343 let Inst{5-4} = 0b10;
2346 def TT : T2ThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iMUL16,
2347 !strconcat(opc, "tt"), "\t$Rd, $Rn, $Rm",
2348 [(set rGPR:$Rd, (opnode (sra rGPR:$Rn, (i32 16)),
2349 (sra rGPR:$Rm, (i32 16))))]>,
2350 Requires<[IsThumb2, HasThumb2DSP]> {
2351 let Inst{31-27} = 0b11111;
2352 let Inst{26-23} = 0b0110;
2353 let Inst{22-20} = 0b001;
2354 let Inst{15-12} = 0b1111; // Ra = 0b1111 (no accumulate)
2355 let Inst{7-6} = 0b00;
2356 let Inst{5-4} = 0b11;
2359 def WB : T2ThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iMUL16,
2360 !strconcat(opc, "wb"), "\t$Rd, $Rn, $Rm",
2361 [(set rGPR:$Rd, (sra (opnode rGPR:$Rn,
2362 (sext_inreg rGPR:$Rm, i16)), (i32 16)))]>,
2363 Requires<[IsThumb2, HasThumb2DSP]> {
2364 let Inst{31-27} = 0b11111;
2365 let Inst{26-23} = 0b0110;
2366 let Inst{22-20} = 0b011;
2367 let Inst{15-12} = 0b1111; // Ra = 0b1111 (no accumulate)
2368 let Inst{7-6} = 0b00;
2369 let Inst{5-4} = 0b00;
2372 def WT : T2ThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iMUL16,
2373 !strconcat(opc, "wt"), "\t$Rd, $Rn, $Rm",
2374 [(set rGPR:$Rd, (sra (opnode rGPR:$Rn,
2375 (sra rGPR:$Rm, (i32 16))), (i32 16)))]>,
2376 Requires<[IsThumb2, HasThumb2DSP]> {
2377 let Inst{31-27} = 0b11111;
2378 let Inst{26-23} = 0b0110;
2379 let Inst{22-20} = 0b011;
2380 let Inst{15-12} = 0b1111; // Ra = 0b1111 (no accumulate)
2381 let Inst{7-6} = 0b00;
2382 let Inst{5-4} = 0b01;
2387 multiclass T2I_smla<string opc, PatFrag opnode> {
2389 (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC16,
2390 !strconcat(opc, "bb"), "\t$Rd, $Rn, $Rm, $Ra",
2391 [(set rGPR:$Rd, (add rGPR:$Ra,
2392 (opnode (sext_inreg rGPR:$Rn, i16),
2393 (sext_inreg rGPR:$Rm, i16))))]>,
2394 Requires<[IsThumb2, HasThumb2DSP]> {
2395 let Inst{31-27} = 0b11111;
2396 let Inst{26-23} = 0b0110;
2397 let Inst{22-20} = 0b001;
2398 let Inst{7-6} = 0b00;
2399 let Inst{5-4} = 0b00;
2403 (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC16,
2404 !strconcat(opc, "bt"), "\t$Rd, $Rn, $Rm, $Ra",
2405 [(set rGPR:$Rd, (add rGPR:$Ra, (opnode (sext_inreg rGPR:$Rn, i16),
2406 (sra rGPR:$Rm, (i32 16)))))]>,
2407 Requires<[IsThumb2, HasThumb2DSP]> {
2408 let Inst{31-27} = 0b11111;
2409 let Inst{26-23} = 0b0110;
2410 let Inst{22-20} = 0b001;
2411 let Inst{7-6} = 0b00;
2412 let Inst{5-4} = 0b01;
2416 (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC16,
2417 !strconcat(opc, "tb"), "\t$Rd, $Rn, $Rm, $Ra",
2418 [(set rGPR:$Rd, (add rGPR:$Ra, (opnode (sra rGPR:$Rn, (i32 16)),
2419 (sext_inreg rGPR:$Rm, i16))))]>,
2420 Requires<[IsThumb2, HasThumb2DSP]> {
2421 let Inst{31-27} = 0b11111;
2422 let Inst{26-23} = 0b0110;
2423 let Inst{22-20} = 0b001;
2424 let Inst{7-6} = 0b00;
2425 let Inst{5-4} = 0b10;
2429 (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC16,
2430 !strconcat(opc, "tt"), "\t$Rd, $Rn, $Rm, $Ra",
2431 [(set rGPR:$Rd, (add rGPR:$Ra, (opnode (sra rGPR:$Rn, (i32 16)),
2432 (sra rGPR:$Rm, (i32 16)))))]>,
2433 Requires<[IsThumb2, HasThumb2DSP]> {
2434 let Inst{31-27} = 0b11111;
2435 let Inst{26-23} = 0b0110;
2436 let Inst{22-20} = 0b001;
2437 let Inst{7-6} = 0b00;
2438 let Inst{5-4} = 0b11;
2442 (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC16,
2443 !strconcat(opc, "wb"), "\t$Rd, $Rn, $Rm, $Ra",
2444 [(set rGPR:$Rd, (add rGPR:$Ra, (sra (opnode rGPR:$Rn,
2445 (sext_inreg rGPR:$Rm, i16)), (i32 16))))]>,
2446 Requires<[IsThumb2, HasThumb2DSP]> {
2447 let Inst{31-27} = 0b11111;
2448 let Inst{26-23} = 0b0110;
2449 let Inst{22-20} = 0b011;
2450 let Inst{7-6} = 0b00;
2451 let Inst{5-4} = 0b00;
2455 (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC16,
2456 !strconcat(opc, "wt"), "\t$Rd, $Rn, $Rm, $Ra",
2457 [(set rGPR:$Rd, (add rGPR:$Ra, (sra (opnode rGPR:$Rn,
2458 (sra rGPR:$Rm, (i32 16))), (i32 16))))]>,
2459 Requires<[IsThumb2, HasThumb2DSP]> {
2460 let Inst{31-27} = 0b11111;
2461 let Inst{26-23} = 0b0110;
2462 let Inst{22-20} = 0b011;
2463 let Inst{7-6} = 0b00;
2464 let Inst{5-4} = 0b01;
2468 defm t2SMUL : T2I_smul<"smul", BinOpFrag<(mul node:$LHS, node:$RHS)>>;
2469 defm t2SMLA : T2I_smla<"smla", BinOpFrag<(mul node:$LHS, node:$RHS)>>;
2471 // Halfword multiple accumulate long: SMLAL<x><y> -- for disassembly only
2472 def t2SMLALBB : T2FourReg_mac<1, 0b100, 0b1000, (outs rGPR:$Ra,rGPR:$Rd),
2473 (ins rGPR:$Rn,rGPR:$Rm), IIC_iMAC64, "smlalbb", "\t$Ra, $Rd, $Rn, $Rm",
2474 [/* For disassembly only; pattern left blank */]>,
2475 Requires<[IsThumb2, HasThumb2DSP]>;
2476 def t2SMLALBT : T2FourReg_mac<1, 0b100, 0b1001, (outs rGPR:$Ra,rGPR:$Rd),
2477 (ins rGPR:$Rn,rGPR:$Rm), IIC_iMAC64, "smlalbt", "\t$Ra, $Rd, $Rn, $Rm",
2478 [/* For disassembly only; pattern left blank */]>,
2479 Requires<[IsThumb2, HasThumb2DSP]>;
2480 def t2SMLALTB : T2FourReg_mac<1, 0b100, 0b1010, (outs rGPR:$Ra,rGPR:$Rd),
2481 (ins rGPR:$Rn,rGPR:$Rm), IIC_iMAC64, "smlaltb", "\t$Ra, $Rd, $Rn, $Rm",
2482 [/* For disassembly only; pattern left blank */]>,
2483 Requires<[IsThumb2, HasThumb2DSP]>;
2484 def t2SMLALTT : T2FourReg_mac<1, 0b100, 0b1011, (outs rGPR:$Ra,rGPR:$Rd),
2485 (ins rGPR:$Rn,rGPR:$Rm), IIC_iMAC64, "smlaltt", "\t$Ra, $Rd, $Rn, $Rm",
2486 [/* For disassembly only; pattern left blank */]>,
2487 Requires<[IsThumb2, HasThumb2DSP]>;
2489 // Dual halfword multiple: SMUAD, SMUSD, SMLAD, SMLSD, SMLALD, SMLSLD
2490 // These are for disassembly only.
2492 def t2SMUAD: T2ThreeReg_mac<
2493 0, 0b010, 0b0000, (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm),
2494 IIC_iMAC32, "smuad", "\t$Rd, $Rn, $Rm", []>,
2495 Requires<[IsThumb2, HasThumb2DSP]> {
2496 let Inst{15-12} = 0b1111;
2498 def t2SMUADX:T2ThreeReg_mac<
2499 0, 0b010, 0b0001, (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm),
2500 IIC_iMAC32, "smuadx", "\t$Rd, $Rn, $Rm", []>,
2501 Requires<[IsThumb2, HasThumb2DSP]> {
2502 let Inst{15-12} = 0b1111;
2504 def t2SMUSD: T2ThreeReg_mac<
2505 0, 0b100, 0b0000, (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm),
2506 IIC_iMAC32, "smusd", "\t$Rd, $Rn, $Rm", []>,
2507 Requires<[IsThumb2, HasThumb2DSP]> {
2508 let Inst{15-12} = 0b1111;
2510 def t2SMUSDX:T2ThreeReg_mac<
2511 0, 0b100, 0b0001, (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm),
2512 IIC_iMAC32, "smusdx", "\t$Rd, $Rn, $Rm", []>,
2513 Requires<[IsThumb2, HasThumb2DSP]> {
2514 let Inst{15-12} = 0b1111;
2516 def t2SMLAD : T2ThreeReg_mac<
2517 0, 0b010, 0b0000, (outs rGPR:$Rd),
2518 (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC32, "smlad",
2519 "\t$Rd, $Rn, $Rm, $Ra", []>,
2520 Requires<[IsThumb2, HasThumb2DSP]>;
2521 def t2SMLADX : T2FourReg_mac<
2522 0, 0b010, 0b0001, (outs rGPR:$Rd),
2523 (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC32, "smladx",
2524 "\t$Rd, $Rn, $Rm, $Ra", []>,
2525 Requires<[IsThumb2, HasThumb2DSP]>;
2526 def t2SMLSD : T2FourReg_mac<0, 0b100, 0b0000, (outs rGPR:$Rd),
2527 (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC32, "smlsd",
2528 "\t$Rd, $Rn, $Rm, $Ra", []>,
2529 Requires<[IsThumb2, HasThumb2DSP]>;
2530 def t2SMLSDX : T2FourReg_mac<0, 0b100, 0b0001, (outs rGPR:$Rd),
2531 (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC32, "smlsdx",
2532 "\t$Rd, $Rn, $Rm, $Ra", []>,
2533 Requires<[IsThumb2, HasThumb2DSP]>;
2534 def t2SMLALD : T2FourReg_mac<1, 0b100, 0b1100, (outs rGPR:$Ra,rGPR:$Rd),
2535 (ins rGPR:$Rm, rGPR:$Rn), IIC_iMAC64, "smlald",
2536 "\t$Ra, $Rd, $Rm, $Rn", []>,
2537 Requires<[IsThumb2, HasThumb2DSP]>;
2538 def t2SMLALDX : T2FourReg_mac<1, 0b100, 0b1101, (outs rGPR:$Ra,rGPR:$Rd),
2539 (ins rGPR:$Rm,rGPR:$Rn), IIC_iMAC64, "smlaldx",
2540 "\t$Ra, $Rd, $Rm, $Rn", []>,
2541 Requires<[IsThumb2, HasThumb2DSP]>;
2542 def t2SMLSLD : T2FourReg_mac<1, 0b101, 0b1100, (outs rGPR:$Ra,rGPR:$Rd),
2543 (ins rGPR:$Rm,rGPR:$Rn), IIC_iMAC64, "smlsld",
2544 "\t$Ra, $Rd, $Rm, $Rn", []>,
2545 Requires<[IsThumb2, HasThumb2DSP]>;
2546 def t2SMLSLDX : T2FourReg_mac<1, 0b101, 0b1101, (outs rGPR:$Ra,rGPR:$Rd),
2547 (ins rGPR:$Rm,rGPR:$Rn), IIC_iMAC64, "smlsldx",
2548 "\t$Ra, $Rd, $Rm, $Rn", []>,
2549 Requires<[IsThumb2, HasThumb2DSP]>;
2551 //===----------------------------------------------------------------------===//
2552 // Division Instructions.
2553 // Signed and unsigned division on v7-M
2555 def t2SDIV : T2ThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iALUi,
2556 "sdiv", "\t$Rd, $Rn, $Rm",
2557 [(set rGPR:$Rd, (sdiv rGPR:$Rn, rGPR:$Rm))]>,
2558 Requires<[HasDivide, IsThumb2]> {
2559 let Inst{31-27} = 0b11111;
2560 let Inst{26-21} = 0b011100;
2562 let Inst{15-12} = 0b1111;
2563 let Inst{7-4} = 0b1111;
2566 def t2UDIV : T2ThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iALUi,
2567 "udiv", "\t$Rd, $Rn, $Rm",
2568 [(set rGPR:$Rd, (udiv rGPR:$Rn, rGPR:$Rm))]>,
2569 Requires<[HasDivide, IsThumb2]> {
2570 let Inst{31-27} = 0b11111;
2571 let Inst{26-21} = 0b011101;
2573 let Inst{15-12} = 0b1111;
2574 let Inst{7-4} = 0b1111;
2577 //===----------------------------------------------------------------------===//
2578 // Misc. Arithmetic Instructions.
2581 class T2I_misc<bits<2> op1, bits<2> op2, dag oops, dag iops,
2582 InstrItinClass itin, string opc, string asm, list<dag> pattern>
2583 : T2ThreeReg<oops, iops, itin, opc, asm, pattern> {
2584 let Inst{31-27} = 0b11111;
2585 let Inst{26-22} = 0b01010;
2586 let Inst{21-20} = op1;
2587 let Inst{15-12} = 0b1111;
2588 let Inst{7-6} = 0b10;
2589 let Inst{5-4} = op2;
2593 def t2CLZ : T2I_misc<0b11, 0b00, (outs rGPR:$Rd), (ins rGPR:$Rm), IIC_iUNAr,
2594 "clz", "\t$Rd, $Rm", [(set rGPR:$Rd, (ctlz rGPR:$Rm))]>;
2596 def t2RBIT : T2I_misc<0b01, 0b10, (outs rGPR:$Rd), (ins rGPR:$Rm), IIC_iUNAr,
2597 "rbit", "\t$Rd, $Rm",
2598 [(set rGPR:$Rd, (ARMrbit rGPR:$Rm))]>;
2600 def t2REV : T2I_misc<0b01, 0b00, (outs rGPR:$Rd), (ins rGPR:$Rm), IIC_iUNAr,
2601 "rev", ".w\t$Rd, $Rm", [(set rGPR:$Rd, (bswap rGPR:$Rm))]>;
2603 def t2REV16 : T2I_misc<0b01, 0b01, (outs rGPR:$Rd), (ins rGPR:$Rm), IIC_iUNAr,
2604 "rev16", ".w\t$Rd, $Rm",
2605 [(set rGPR:$Rd, (rotr (bswap rGPR:$Rm), (i32 16)))]>;
2607 def t2REVSH : T2I_misc<0b01, 0b11, (outs rGPR:$Rd), (ins rGPR:$Rm), IIC_iUNAr,
2608 "revsh", ".w\t$Rd, $Rm",
2609 [(set rGPR:$Rd, (sra (bswap rGPR:$Rm), (i32 16)))]>;
2611 def : T2Pat<(or (sra (shl rGPR:$Rm, (i32 24)), (i32 16)),
2612 (and (srl rGPR:$Rm, (i32 8)), 0xFF)),
2613 (t2REVSH rGPR:$Rm)>;
2615 def t2PKHBT : T2ThreeReg<
2616 (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, shift_imm:$sh),
2617 IIC_iBITsi, "pkhbt", "\t$Rd, $Rn, $Rm$sh",
2618 [(set rGPR:$Rd, (or (and rGPR:$Rn, 0xFFFF),
2619 (and (shl rGPR:$Rm, lsl_amt:$sh),
2621 Requires<[HasT2ExtractPack, IsThumb2]> {
2622 let Inst{31-27} = 0b11101;
2623 let Inst{26-25} = 0b01;
2624 let Inst{24-20} = 0b01100;
2625 let Inst{5} = 0; // BT form
2629 let Inst{14-12} = sh{7-5};
2630 let Inst{7-6} = sh{4-3};
2633 // Alternate cases for PKHBT where identities eliminate some nodes.
2634 def : T2Pat<(or (and rGPR:$src1, 0xFFFF), (and rGPR:$src2, 0xFFFF0000)),
2635 (t2PKHBT rGPR:$src1, rGPR:$src2, 0)>,
2636 Requires<[HasT2ExtractPack, IsThumb2]>;
2637 def : T2Pat<(or (and rGPR:$src1, 0xFFFF), (shl rGPR:$src2, imm16_31:$sh)),
2638 (t2PKHBT rGPR:$src1, rGPR:$src2, (lsl_shift_imm imm16_31:$sh))>,
2639 Requires<[HasT2ExtractPack, IsThumb2]>;
2641 // Note: Shifts of 1-15 bits will be transformed to srl instead of sra and
2642 // will match the pattern below.
2643 def t2PKHTB : T2ThreeReg<
2644 (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, shift_imm:$sh),
2645 IIC_iBITsi, "pkhtb", "\t$Rd, $Rn, $Rm$sh",
2646 [(set rGPR:$Rd, (or (and rGPR:$Rn, 0xFFFF0000),
2647 (and (sra rGPR:$Rm, asr_amt:$sh),
2649 Requires<[HasT2ExtractPack, IsThumb2]> {
2650 let Inst{31-27} = 0b11101;
2651 let Inst{26-25} = 0b01;
2652 let Inst{24-20} = 0b01100;
2653 let Inst{5} = 1; // TB form
2657 let Inst{14-12} = sh{7-5};
2658 let Inst{7-6} = sh{4-3};
2661 // Alternate cases for PKHTB where identities eliminate some nodes. Note that
2662 // a shift amount of 0 is *not legal* here, it is PKHBT instead.
2663 def : T2Pat<(or (and rGPR:$src1, 0xFFFF0000), (srl rGPR:$src2, imm16_31:$sh)),
2664 (t2PKHTB rGPR:$src1, rGPR:$src2, (asr_shift_imm imm16_31:$sh))>,
2665 Requires<[HasT2ExtractPack, IsThumb2]>;
2666 def : T2Pat<(or (and rGPR:$src1, 0xFFFF0000),
2667 (and (srl rGPR:$src2, imm1_15:$sh), 0xFFFF)),
2668 (t2PKHTB rGPR:$src1, rGPR:$src2, (asr_shift_imm imm1_15:$sh))>,
2669 Requires<[HasT2ExtractPack, IsThumb2]>;
2671 //===----------------------------------------------------------------------===//
2672 // Comparison Instructions...
2674 defm t2CMP : T2I_cmp_irs<0b1101, "cmp",
2675 IIC_iCMPi, IIC_iCMPr, IIC_iCMPsi,
2676 BinOpFrag<(ARMcmp node:$LHS, node:$RHS)>>;
2678 def : T2Pat<(ARMcmpZ GPR:$lhs, t2_so_imm:$imm),
2679 (t2CMPri GPR:$lhs, t2_so_imm:$imm)>;
2680 def : T2Pat<(ARMcmpZ GPR:$lhs, rGPR:$rhs),
2681 (t2CMPrr GPR:$lhs, rGPR:$rhs)>;
2682 def : T2Pat<(ARMcmpZ GPR:$lhs, t2_so_reg:$rhs),
2683 (t2CMPrs GPR:$lhs, t2_so_reg:$rhs)>;
2685 //FIXME: Disable CMN, as CCodes are backwards from compare expectations
2686 // Compare-to-zero still works out, just not the relationals
2687 //defm t2CMN : T2I_cmp_irs<0b1000, "cmn",
2688 // BinOpFrag<(ARMcmp node:$LHS,(ineg node:$RHS))>>;
2689 defm t2CMNz : T2I_cmp_irs<0b1000, "cmn",
2690 IIC_iCMPi, IIC_iCMPr, IIC_iCMPsi,
2691 BinOpFrag<(ARMcmpZ node:$LHS,(ineg node:$RHS))>>;
2693 //def : T2Pat<(ARMcmp GPR:$src, t2_so_imm_neg:$imm),
2694 // (t2CMNri GPR:$src, t2_so_imm_neg:$imm)>;
2696 def : T2Pat<(ARMcmpZ GPR:$src, t2_so_imm_neg:$imm),
2697 (t2CMNzri GPR:$src, t2_so_imm_neg:$imm)>;
2699 defm t2TST : T2I_cmp_irs<0b0000, "tst",
2700 IIC_iTSTi, IIC_iTSTr, IIC_iTSTsi,
2701 BinOpFrag<(ARMcmpZ (and_su node:$LHS, node:$RHS), 0)>>;
2702 defm t2TEQ : T2I_cmp_irs<0b0100, "teq",
2703 IIC_iTSTi, IIC_iTSTr, IIC_iTSTsi,
2704 BinOpFrag<(ARMcmpZ (xor_su node:$LHS, node:$RHS), 0)>>;
2706 // Conditional moves
2707 // FIXME: should be able to write a pattern for ARMcmov, but can't use
2708 // a two-value operand where a dag node expects two operands. :(
2709 let neverHasSideEffects = 1 in {
2710 def t2MOVCCr : t2PseudoInst<(outs rGPR:$Rd),
2711 (ins rGPR:$false, rGPR:$Rm, pred:$p),
2712 Size4Bytes, IIC_iCMOVr,
2713 [/*(set rGPR:$Rd, (ARMcmov rGPR:$false, rGPR:$Rm, imm:$cc, CCR:$ccr))*/]>,
2714 RegConstraint<"$false = $Rd">;
2716 let isMoveImm = 1 in
2717 def t2MOVCCi : t2PseudoInst<(outs rGPR:$Rd),
2718 (ins rGPR:$false, t2_so_imm:$imm, pred:$p),
2719 Size4Bytes, IIC_iCMOVi,
2720 [/*(set rGPR:$Rd,(ARMcmov rGPR:$false,t2_so_imm:$imm, imm:$cc, CCR:$ccr))*/]>,
2721 RegConstraint<"$false = $Rd">;
2723 // FIXME: Pseudo-ize these. For now, just mark codegen only.
2724 let isCodeGenOnly = 1 in {
2725 let isMoveImm = 1 in
2726 def t2MOVCCi16 : T2I<(outs rGPR:$Rd), (ins rGPR:$false, i32imm_hilo16:$imm),
2728 "movw", "\t$Rd, $imm", []>,
2729 RegConstraint<"$false = $Rd"> {
2730 let Inst{31-27} = 0b11110;
2732 let Inst{24-21} = 0b0010;
2733 let Inst{20} = 0; // The S bit.
2739 let Inst{11-8} = Rd;
2740 let Inst{19-16} = imm{15-12};
2741 let Inst{26} = imm{11};
2742 let Inst{14-12} = imm{10-8};
2743 let Inst{7-0} = imm{7-0};
2746 let isMoveImm = 1 in
2747 def t2MOVCCi32imm : PseudoInst<(outs rGPR:$dst),
2748 (ins rGPR:$false, i32imm:$src, pred:$p),
2749 IIC_iCMOVix2, []>, RegConstraint<"$false = $dst">;
2751 let isMoveImm = 1 in
2752 def t2MVNCCi : T2OneRegImm<(outs rGPR:$Rd), (ins rGPR:$false, t2_so_imm:$imm),
2753 IIC_iCMOVi, "mvn", ".w\t$Rd, $imm",
2754 [/*(set rGPR:$Rd,(ARMcmov rGPR:$false,t2_so_imm_not:$imm,
2755 imm:$cc, CCR:$ccr))*/]>,
2756 RegConstraint<"$false = $Rd"> {
2757 let Inst{31-27} = 0b11110;
2759 let Inst{24-21} = 0b0011;
2760 let Inst{20} = 0; // The S bit.
2761 let Inst{19-16} = 0b1111; // Rn
2765 class T2I_movcc_sh<bits<2> opcod, dag oops, dag iops, InstrItinClass itin,
2766 string opc, string asm, list<dag> pattern>
2767 : T2TwoRegShiftImm<oops, iops, itin, opc, asm, pattern> {
2768 let Inst{31-27} = 0b11101;
2769 let Inst{26-25} = 0b01;
2770 let Inst{24-21} = 0b0010;
2771 let Inst{20} = 0; // The S bit.
2772 let Inst{19-16} = 0b1111; // Rn
2773 let Inst{5-4} = opcod; // Shift type.
2775 def t2MOVCClsl : T2I_movcc_sh<0b00, (outs rGPR:$Rd),
2776 (ins rGPR:$false, rGPR:$Rm, i32imm:$imm),
2777 IIC_iCMOVsi, "lsl", ".w\t$Rd, $Rm, $imm", []>,
2778 RegConstraint<"$false = $Rd">;
2779 def t2MOVCClsr : T2I_movcc_sh<0b01, (outs rGPR:$Rd),
2780 (ins rGPR:$false, rGPR:$Rm, i32imm:$imm),
2781 IIC_iCMOVsi, "lsr", ".w\t$Rd, $Rm, $imm", []>,
2782 RegConstraint<"$false = $Rd">;
2783 def t2MOVCCasr : T2I_movcc_sh<0b10, (outs rGPR:$Rd),
2784 (ins rGPR:$false, rGPR:$Rm, i32imm:$imm),
2785 IIC_iCMOVsi, "asr", ".w\t$Rd, $Rm, $imm", []>,
2786 RegConstraint<"$false = $Rd">;
2787 def t2MOVCCror : T2I_movcc_sh<0b11, (outs rGPR:$Rd),
2788 (ins rGPR:$false, rGPR:$Rm, i32imm:$imm),
2789 IIC_iCMOVsi, "ror", ".w\t$Rd, $Rm, $imm", []>,
2790 RegConstraint<"$false = $Rd">;
2791 } // isCodeGenOnly = 1
2792 } // neverHasSideEffects
2794 //===----------------------------------------------------------------------===//
2795 // Atomic operations intrinsics
2798 // memory barriers protect the atomic sequences
2799 let hasSideEffects = 1 in {
2800 def t2DMB : AInoP<(outs), (ins memb_opt:$opt), ThumbFrm, NoItinerary,
2801 "dmb", "\t$opt", [(ARMMemBarrier (i32 imm:$opt))]>,
2802 Requires<[IsThumb, HasDB]> {
2804 let Inst{31-4} = 0xf3bf8f5;
2805 let Inst{3-0} = opt;
2809 def t2DSB : AInoP<(outs), (ins memb_opt:$opt), ThumbFrm, NoItinerary,
2811 [/* For disassembly only; pattern left blank */]>,
2812 Requires<[IsThumb, HasDB]> {
2814 let Inst{31-4} = 0xf3bf8f4;
2815 let Inst{3-0} = opt;
2818 // ISB has only full system option -- for disassembly only
2819 def t2ISB : AInoP<(outs), (ins), ThumbFrm, NoItinerary, "isb", "",
2820 [/* For disassembly only; pattern left blank */]>,
2821 Requires<[IsThumb2, HasV7]> {
2822 let Inst{31-4} = 0xf3bf8f6;
2823 let Inst{3-0} = 0b1111;
2826 class T2I_ldrex<bits<2> opcod, dag oops, dag iops, AddrMode am, SizeFlagVal sz,
2827 InstrItinClass itin, string opc, string asm, string cstr,
2828 list<dag> pattern, bits<4> rt2 = 0b1111>
2829 : Thumb2I<oops, iops, am, sz, itin, opc, asm, cstr, pattern> {
2830 let Inst{31-27} = 0b11101;
2831 let Inst{26-20} = 0b0001101;
2832 let Inst{11-8} = rt2;
2833 let Inst{7-6} = 0b01;
2834 let Inst{5-4} = opcod;
2835 let Inst{3-0} = 0b1111;
2839 let Inst{19-16} = addr;
2840 let Inst{15-12} = Rt;
2842 class T2I_strex<bits<2> opcod, dag oops, dag iops, AddrMode am, SizeFlagVal sz,
2843 InstrItinClass itin, string opc, string asm, string cstr,
2844 list<dag> pattern, bits<4> rt2 = 0b1111>
2845 : Thumb2I<oops, iops, am, sz, itin, opc, asm, cstr, pattern> {
2846 let Inst{31-27} = 0b11101;
2847 let Inst{26-20} = 0b0001100;
2848 let Inst{11-8} = rt2;
2849 let Inst{7-6} = 0b01;
2850 let Inst{5-4} = opcod;
2856 let Inst{19-16} = addr;
2857 let Inst{15-12} = Rt;
2860 let mayLoad = 1 in {
2861 def t2LDREXB : T2I_ldrex<0b00, (outs rGPR:$Rt), (ins t2addrmode_reg:$addr),
2862 AddrModeNone, Size4Bytes, NoItinerary,
2863 "ldrexb", "\t$Rt, $addr", "", []>;
2864 def t2LDREXH : T2I_ldrex<0b01, (outs rGPR:$Rt), (ins t2addrmode_reg:$addr),
2865 AddrModeNone, Size4Bytes, NoItinerary,
2866 "ldrexh", "\t$Rt, $addr", "", []>;
2867 def t2LDREX : Thumb2I<(outs rGPR:$Rt), (ins t2addrmode_reg:$addr),
2868 AddrModeNone, Size4Bytes, NoItinerary,
2869 "ldrex", "\t$Rt, $addr", "", []> {
2870 let Inst{31-27} = 0b11101;
2871 let Inst{26-20} = 0b0000101;
2872 let Inst{11-8} = 0b1111;
2873 let Inst{7-0} = 0b00000000; // imm8 = 0
2877 let Inst{19-16} = addr;
2878 let Inst{15-12} = Rt;
2880 let hasExtraDefRegAllocReq = 1 in
2881 def t2LDREXD : T2I_ldrex<0b11, (outs rGPR:$Rt, rGPR:$Rt2),
2882 (ins t2addrmode_reg:$addr),
2883 AddrModeNone, Size4Bytes, NoItinerary,
2884 "ldrexd", "\t$Rt, $Rt2, $addr", "",
2887 let Inst{11-8} = Rt2;
2891 let mayStore = 1, Constraints = "@earlyclobber $Rd" in {
2892 def t2STREXB : T2I_strex<0b00, (outs rGPR:$Rd),
2893 (ins rGPR:$Rt, t2addrmode_reg:$addr),
2894 AddrModeNone, Size4Bytes, NoItinerary,
2895 "strexb", "\t$Rd, $Rt, $addr", "", []>;
2896 def t2STREXH : T2I_strex<0b01, (outs rGPR:$Rd),
2897 (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;
2917 let hasExtraSrcRegAllocReq = 1, Constraints = "@earlyclobber $Rd" in
2918 def t2STREXD : T2I_strex<0b11, (outs rGPR:$Rd),
2919 (ins rGPR:$Rt, rGPR:$Rt2, t2addrmode_reg:$addr),
2920 AddrModeNone, Size4Bytes, NoItinerary,
2921 "strexd", "\t$Rd, $Rt, $Rt2, $addr", "", [],
2924 let Inst{11-8} = Rt2;
2927 // Clear-Exclusive is for disassembly only.
2928 def t2CLREX : T2XI<(outs), (ins), NoItinerary, "clrex",
2929 [/* For disassembly only; pattern left blank */]>,
2930 Requires<[IsThumb2, HasV7]> {
2931 let Inst{31-16} = 0xf3bf;
2932 let Inst{15-14} = 0b10;
2935 let Inst{11-8} = 0b1111;
2936 let Inst{7-4} = 0b0010;
2937 let Inst{3-0} = 0b1111;
2940 //===----------------------------------------------------------------------===//
2941 // SJLJ Exception handling intrinsics
2942 // eh_sjlj_setjmp() is an instruction sequence to store the return
2943 // address and save #0 in R0 for the non-longjmp case.
2944 // Since by its nature we may be coming from some other function to get
2945 // here, and we're using the stack frame for the containing function to
2946 // save/restore registers, we can't keep anything live in regs across
2947 // the eh_sjlj_setjmp(), else it will almost certainly have been tromped upon
2948 // when we get here from a longjmp(). We force everything out of registers
2949 // except for our own input by listing the relevant registers in Defs. By
2950 // doing so, we also cause the prologue/epilogue code to actively preserve
2951 // all of the callee-saved resgisters, which is exactly what we want.
2952 // $val is a scratch register for our use.
2954 [ R0, R1, R2, R3, R4, R5, R6, R7, R8, R9, R10, R11, R12, LR, CPSR,
2955 QQQQ0, QQQQ1, QQQQ2, QQQQ3 ],
2956 hasSideEffects = 1, isBarrier = 1, isCodeGenOnly = 1 in {
2957 def t2Int_eh_sjlj_setjmp : Thumb2XI<(outs), (ins tGPR:$src, tGPR:$val),
2958 AddrModeNone, SizeSpecial, NoItinerary, "", "",
2959 [(set R0, (ARMeh_sjlj_setjmp tGPR:$src, tGPR:$val))]>,
2960 Requires<[IsThumb2, HasVFP2]>;
2964 [ R0, R1, R2, R3, R4, R5, R6, R7, R8, R9, R10, R11, R12, LR, CPSR ],
2965 hasSideEffects = 1, isBarrier = 1, isCodeGenOnly = 1 in {
2966 def t2Int_eh_sjlj_setjmp_nofp : Thumb2XI<(outs), (ins tGPR:$src, tGPR:$val),
2967 AddrModeNone, SizeSpecial, NoItinerary, "", "",
2968 [(set R0, (ARMeh_sjlj_setjmp tGPR:$src, tGPR:$val))]>,
2969 Requires<[IsThumb2, NoVFP]>;
2973 //===----------------------------------------------------------------------===//
2974 // Control-Flow Instructions
2977 // FIXME: remove when we have a way to marking a MI with these properties.
2978 // FIXME: Should pc be an implicit operand like PICADD, etc?
2979 let isReturn = 1, isTerminator = 1, isBarrier = 1, mayLoad = 1,
2980 hasExtraDefRegAllocReq = 1, isCodeGenOnly = 1 in
2981 def t2LDMIA_RET: t2PseudoExpand<(outs GPR:$wb), (ins GPR:$Rn, pred:$p,
2982 reglist:$regs, variable_ops),
2983 Size4Bytes, IIC_iLoad_mBr, [],
2984 (t2LDMIA_UPD GPR:$wb, GPR:$Rn, pred:$p, reglist:$regs)>,
2985 RegConstraint<"$Rn = $wb">;
2987 let isBranch = 1, isTerminator = 1, isBarrier = 1 in {
2988 let isPredicable = 1 in
2989 def t2B : T2XI<(outs), (ins uncondbrtarget:$target), IIC_Br,
2991 [(br bb:$target)]> {
2992 let Inst{31-27} = 0b11110;
2993 let Inst{15-14} = 0b10;
2997 let Inst{26} = target{19};
2998 let Inst{11} = target{18};
2999 let Inst{13} = target{17};
3000 let Inst{21-16} = target{16-11};
3001 let Inst{10-0} = target{10-0};
3004 let isNotDuplicable = 1, isIndirectBranch = 1 in {
3005 def t2BR_JT : t2PseudoInst<(outs),
3006 (ins GPR:$target, GPR:$index, i32imm:$jt, i32imm:$id),
3007 SizeSpecial, IIC_Br,
3008 [(ARMbr2jt GPR:$target, GPR:$index, tjumptable:$jt, imm:$id)]>;
3010 // FIXME: Add a non-pc based case that can be predicated.
3011 def t2TBB_JT : t2PseudoInst<(outs),
3012 (ins GPR:$index, i32imm:$jt, i32imm:$id),
3013 SizeSpecial, IIC_Br, []>;
3015 def t2TBH_JT : t2PseudoInst<(outs),
3016 (ins GPR:$index, i32imm:$jt, i32imm:$id),
3017 SizeSpecial, IIC_Br, []>;
3019 def t2TBB : T2I<(outs), (ins GPR:$Rn, GPR:$Rm), IIC_Br,
3020 "tbb", "\t[$Rn, $Rm]", []> {
3023 let Inst{31-20} = 0b111010001101;
3024 let Inst{19-16} = Rn;
3025 let Inst{15-5} = 0b11110000000;
3026 let Inst{4} = 0; // B form
3030 def t2TBH : T2I<(outs), (ins GPR:$Rn, GPR:$Rm), IIC_Br,
3031 "tbh", "\t[$Rn, $Rm, lsl #1]", []> {
3034 let Inst{31-20} = 0b111010001101;
3035 let Inst{19-16} = Rn;
3036 let Inst{15-5} = 0b11110000000;
3037 let Inst{4} = 1; // H form
3040 } // isNotDuplicable, isIndirectBranch
3042 } // isBranch, isTerminator, isBarrier
3044 // FIXME: should be able to write a pattern for ARMBrcond, but can't use
3045 // a two-value operand where a dag node expects two operands. :(
3046 let isBranch = 1, isTerminator = 1 in
3047 def t2Bcc : T2I<(outs), (ins brtarget:$target), IIC_Br,
3049 [/*(ARMbrcond bb:$target, imm:$cc)*/]> {
3050 let Inst{31-27} = 0b11110;
3051 let Inst{15-14} = 0b10;
3055 let Inst{25-22} = p;
3058 let Inst{26} = target{20};
3059 let Inst{11} = target{19};
3060 let Inst{13} = target{18};
3061 let Inst{21-16} = target{17-12};
3062 let Inst{10-0} = target{11-1};
3065 // Tail calls. The Darwin version of thumb tail calls uses a t2 branch, so
3067 let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1 in {
3069 let Defs = [R0, R1, R2, R3, R9, R12, QQQQ0, QQQQ2, QQQQ3, PC],
3071 def tTAILJMPd: tPseudoExpand<(outs), (ins uncondbrtarget:$dst, variable_ops),
3072 Size4Bytes, IIC_Br, [],
3073 (t2B uncondbrtarget:$dst)>,
3074 Requires<[IsThumb2, IsDarwin]>;
3078 let Defs = [ITSTATE] in
3079 def t2IT : Thumb2XI<(outs), (ins it_pred:$cc, it_mask:$mask),
3080 AddrModeNone, Size2Bytes, IIC_iALUx,
3081 "it$mask\t$cc", "", []> {
3082 // 16-bit instruction.
3083 let Inst{31-16} = 0x0000;
3084 let Inst{15-8} = 0b10111111;
3089 let Inst{3-0} = mask;
3092 // Branch and Exchange Jazelle -- for disassembly only
3094 def t2BXJ : T2I<(outs), (ins rGPR:$func), NoItinerary, "bxj", "\t$func",
3095 [/* For disassembly only; pattern left blank */]> {
3096 let Inst{31-27} = 0b11110;
3098 let Inst{25-20} = 0b111100;
3099 let Inst{15-14} = 0b10;
3103 let Inst{19-16} = func;
3106 // Change Processor State is a system instruction -- for disassembly and
3108 // FIXME: Since the asm parser has currently no clean way to handle optional
3109 // operands, create 3 versions of the same instruction. Once there's a clean
3110 // framework to represent optional operands, change this behavior.
3111 class t2CPS<dag iops, string asm_op> : T2XI<(outs), iops, NoItinerary,
3112 !strconcat("cps", asm_op),
3113 [/* For disassembly only; pattern left blank */]> {
3119 let Inst{31-27} = 0b11110;
3121 let Inst{25-20} = 0b111010;
3122 let Inst{19-16} = 0b1111;
3123 let Inst{15-14} = 0b10;
3125 let Inst{10-9} = imod;
3127 let Inst{7-5} = iflags;
3128 let Inst{4-0} = mode;
3132 def t2CPS3p : t2CPS<(ins imod_op:$imod, iflags_op:$iflags, i32imm:$mode),
3133 "$imod.w\t$iflags, $mode">;
3134 let mode = 0, M = 0 in
3135 def t2CPS2p : t2CPS<(ins imod_op:$imod, iflags_op:$iflags),
3136 "$imod.w\t$iflags">;
3137 let imod = 0, iflags = 0, M = 1 in
3138 def t2CPS1p : t2CPS<(ins i32imm:$mode), "\t$mode">;
3140 // A6.3.4 Branches and miscellaneous control
3141 // Table A6-14 Change Processor State, and hint instructions
3142 // Helper class for disassembly only.
3143 class T2I_hint<bits<8> op7_0, string opc, string asm>
3144 : T2I<(outs), (ins), NoItinerary, opc, asm,
3145 [/* For disassembly only; pattern left blank */]> {
3146 let Inst{31-20} = 0xf3a;
3147 let Inst{19-16} = 0b1111;
3148 let Inst{15-14} = 0b10;
3150 let Inst{10-8} = 0b000;
3151 let Inst{7-0} = op7_0;
3154 def t2NOP : T2I_hint<0b00000000, "nop", ".w">;
3155 def t2YIELD : T2I_hint<0b00000001, "yield", ".w">;
3156 def t2WFE : T2I_hint<0b00000010, "wfe", ".w">;
3157 def t2WFI : T2I_hint<0b00000011, "wfi", ".w">;
3158 def t2SEV : T2I_hint<0b00000100, "sev", ".w">;
3160 def t2DBG : T2I<(outs),(ins i32imm:$opt), NoItinerary, "dbg", "\t$opt",
3161 [/* For disassembly only; pattern left blank */]> {
3162 let Inst{31-20} = 0xf3a;
3163 let Inst{15-14} = 0b10;
3165 let Inst{10-8} = 0b000;
3166 let Inst{7-4} = 0b1111;
3169 let Inst{3-0} = opt;
3172 // Secure Monitor Call is a system instruction -- for disassembly only
3173 // Option = Inst{19-16}
3174 def t2SMC : T2I<(outs), (ins i32imm:$opt), NoItinerary, "smc", "\t$opt",
3175 [/* For disassembly only; pattern left blank */]> {
3176 let Inst{31-27} = 0b11110;
3177 let Inst{26-20} = 0b1111111;
3178 let Inst{15-12} = 0b1000;
3181 let Inst{19-16} = opt;
3184 class T2SRS<bits<12> op31_20,
3185 dag oops, dag iops, InstrItinClass itin,
3186 string opc, string asm, list<dag> pattern>
3187 : T2I<oops, iops, itin, opc, asm, pattern> {
3188 let Inst{31-20} = op31_20{11-0};
3191 let Inst{4-0} = mode{4-0};
3194 // Store Return State is a system instruction -- for disassembly only
3195 def t2SRSDBW : T2SRS<0b111010000010,
3196 (outs),(ins i32imm:$mode),NoItinerary,"srsdb","\tsp!, $mode",
3197 [/* For disassembly only; pattern left blank */]>;
3198 def t2SRSDB : T2SRS<0b111010000000,
3199 (outs),(ins i32imm:$mode),NoItinerary,"srsdb","\tsp, $mode",
3200 [/* For disassembly only; pattern left blank */]>;
3201 def t2SRSIAW : T2SRS<0b111010011010,
3202 (outs),(ins i32imm:$mode),NoItinerary,"srsia","\tsp!, $mode",
3203 [/* For disassembly only; pattern left blank */]>;
3204 def t2SRSIA : T2SRS<0b111010011000,
3205 (outs), (ins i32imm:$mode),NoItinerary,"srsia","\tsp, $mode",
3206 [/* For disassembly only; pattern left blank */]>;
3208 // Return From Exception is a system instruction -- for disassembly only
3210 class T2RFE<bits<12> op31_20, dag oops, dag iops, InstrItinClass itin,
3211 string opc, string asm, list<dag> pattern>
3212 : T2I<oops, iops, itin, opc, asm, pattern> {
3213 let Inst{31-20} = op31_20{11-0};
3216 let Inst{19-16} = Rn;
3217 let Inst{15-0} = 0xc000;
3220 def t2RFEDBW : T2RFE<0b111010000011,
3221 (outs), (ins GPR:$Rn), NoItinerary, "rfedb", "\t$Rn!",
3222 [/* For disassembly only; pattern left blank */]>;
3223 def t2RFEDB : T2RFE<0b111010000001,
3224 (outs), (ins GPR:$Rn), NoItinerary, "rfedb", "\t$Rn",
3225 [/* For disassembly only; pattern left blank */]>;
3226 def t2RFEIAW : T2RFE<0b111010011011,
3227 (outs), (ins GPR:$Rn), NoItinerary, "rfeia", "\t$Rn!",
3228 [/* For disassembly only; pattern left blank */]>;
3229 def t2RFEIA : T2RFE<0b111010011001,
3230 (outs), (ins GPR:$Rn), NoItinerary, "rfeia", "\t$Rn",
3231 [/* For disassembly only; pattern left blank */]>;
3233 //===----------------------------------------------------------------------===//
3234 // Non-Instruction Patterns
3237 // 32-bit immediate using movw + movt.
3238 // This is a single pseudo instruction to make it re-materializable.
3239 // FIXME: Remove this when we can do generalized remat.
3240 let isReMaterializable = 1, isMoveImm = 1 in
3241 def t2MOVi32imm : PseudoInst<(outs rGPR:$dst), (ins i32imm:$src), IIC_iMOVix2,
3242 [(set rGPR:$dst, (i32 imm:$src))]>,
3243 Requires<[IsThumb, HasV6T2]>;
3245 // Pseudo instruction that combines movw + movt + add pc (if pic).
3246 // It also makes it possible to rematerialize the instructions.
3247 // FIXME: Remove this when we can do generalized remat and when machine licm
3248 // can properly the instructions.
3249 let isReMaterializable = 1 in {
3250 def t2MOV_ga_pcrel : PseudoInst<(outs rGPR:$dst), (ins i32imm:$addr),
3252 [(set rGPR:$dst, (ARMWrapperPIC tglobaladdr:$addr))]>,
3253 Requires<[IsThumb2, UseMovt]>;
3255 def t2MOV_ga_dyn : PseudoInst<(outs rGPR:$dst), (ins i32imm:$addr),
3257 [(set rGPR:$dst, (ARMWrapperDYN tglobaladdr:$addr))]>,
3258 Requires<[IsThumb2, UseMovt]>;
3261 // ConstantPool, GlobalAddress, and JumpTable
3262 def : T2Pat<(ARMWrapper tglobaladdr :$dst), (t2LEApcrel tglobaladdr :$dst)>,
3263 Requires<[IsThumb2, DontUseMovt]>;
3264 def : T2Pat<(ARMWrapper tconstpool :$dst), (t2LEApcrel tconstpool :$dst)>;
3265 def : T2Pat<(ARMWrapper tglobaladdr :$dst), (t2MOVi32imm tglobaladdr :$dst)>,
3266 Requires<[IsThumb2, UseMovt]>;
3268 def : T2Pat<(ARMWrapperJT tjumptable:$dst, imm:$id),
3269 (t2LEApcrelJT tjumptable:$dst, imm:$id)>;
3271 // Pseudo instruction that combines ldr from constpool and add pc. This should
3272 // be expanded into two instructions late to allow if-conversion and
3274 let canFoldAsLoad = 1, isReMaterializable = 1 in
3275 def t2LDRpci_pic : PseudoInst<(outs rGPR:$dst), (ins i32imm:$addr, pclabel:$cp),
3277 [(set rGPR:$dst, (ARMpic_add (load (ARMWrapper tconstpool:$addr)),
3279 Requires<[IsThumb2]>;
3281 //===----------------------------------------------------------------------===//
3282 // Move between special register and ARM core register -- for disassembly only
3285 class T2SpecialReg<bits<12> op31_20, bits<2> op15_14, bits<1> op12,
3286 dag oops, dag iops, InstrItinClass itin,
3287 string opc, string asm, list<dag> pattern>
3288 : T2I<oops, iops, itin, opc, asm, pattern> {
3289 let Inst{31-20} = op31_20{11-0};
3290 let Inst{15-14} = op15_14{1-0};
3291 let Inst{12} = op12{0};
3294 class T2MRS<bits<12> op31_20, bits<2> op15_14, bits<1> op12,
3295 dag oops, dag iops, InstrItinClass itin,
3296 string opc, string asm, list<dag> pattern>
3297 : T2SpecialReg<op31_20, op15_14, op12, oops, iops, itin, opc, asm, pattern> {
3299 let Inst{11-8} = Rd;
3300 let Inst{19-16} = 0b1111;
3303 def t2MRS : T2MRS<0b111100111110, 0b10, 0,
3304 (outs rGPR:$Rd), (ins), NoItinerary, "mrs", "\t$Rd, cpsr",
3305 [/* For disassembly only; pattern left blank */]>;
3306 def t2MRSsys : T2MRS<0b111100111111, 0b10, 0,
3307 (outs rGPR:$Rd), (ins), NoItinerary, "mrs", "\t$Rd, spsr",
3308 [/* For disassembly only; pattern left blank */]>;
3310 // Move from ARM core register to Special Register
3312 // No need to have both system and application versions, the encodings are the
3313 // same and the assembly parser has no way to distinguish between them. The mask
3314 // operand contains the special register (R Bit) in bit 4 and bits 3-0 contains
3315 // the mask with the fields to be accessed in the special register.
3316 def t2MSR : T2SpecialReg<0b111100111000 /* op31-20 */, 0b10 /* op15-14 */,
3317 0 /* op12 */, (outs), (ins msr_mask:$mask, rGPR:$Rn),
3318 NoItinerary, "msr", "\t$mask, $Rn",
3319 [/* For disassembly only; pattern left blank */]> {
3322 let Inst{19-16} = Rn;
3323 let Inst{20} = mask{4}; // R Bit
3325 let Inst{11-8} = mask{3-0};
3328 //===----------------------------------------------------------------------===//
3329 // Move between coprocessor and ARM core register -- for disassembly only
3332 class t2MovRCopro<string opc, bit direction, dag oops, dag iops,
3334 : T2Cop<oops, iops, !strconcat(opc, "\t$cop, $opc1, $Rt, $CRn, $CRm, $opc2"),
3336 let Inst{27-24} = 0b1110;
3337 let Inst{20} = direction;
3347 let Inst{15-12} = Rt;
3348 let Inst{11-8} = cop;
3349 let Inst{23-21} = opc1;
3350 let Inst{7-5} = opc2;
3351 let Inst{3-0} = CRm;
3352 let Inst{19-16} = CRn;
3355 def t2MCR2 : t2MovRCopro<"mcr2", 0 /* from ARM core register to coprocessor */,
3356 (outs), (ins p_imm:$cop, i32imm:$opc1, GPR:$Rt, c_imm:$CRn,
3357 c_imm:$CRm, i32imm:$opc2),
3358 [(int_arm_mcr2 imm:$cop, imm:$opc1, GPR:$Rt, imm:$CRn,
3359 imm:$CRm, imm:$opc2)]>;
3360 def t2MRC2 : t2MovRCopro<"mrc2", 1 /* from coprocessor to ARM core register */,
3361 (outs GPR:$Rt), (ins p_imm:$cop, i32imm:$opc1, c_imm:$CRn,
3362 c_imm:$CRm, i32imm:$opc2), []>;
3364 def : T2v6Pat<(int_arm_mrc2 imm:$cop, imm:$opc1, imm:$CRn,
3365 imm:$CRm, imm:$opc2),
3366 (t2MRC2 imm:$cop, imm:$opc1, imm:$CRn, imm:$CRm, imm:$opc2)>;
3368 class t2MovRRCopro<string opc, bit direction,
3369 list<dag> pattern = [/* For disassembly only */]>
3370 : T2Cop<(outs), (ins p_imm:$cop, i32imm:$opc1, GPR:$Rt, GPR:$Rt2, c_imm:$CRm),
3371 !strconcat(opc, "\t$cop, $opc1, $Rt, $Rt2, $CRm"), pattern> {
3372 let Inst{27-24} = 0b1100;
3373 let Inst{23-21} = 0b010;
3374 let Inst{20} = direction;
3382 let Inst{15-12} = Rt;
3383 let Inst{19-16} = Rt2;
3384 let Inst{11-8} = cop;
3385 let Inst{7-4} = opc1;
3386 let Inst{3-0} = CRm;
3389 def t2MCRR2 : t2MovRRCopro<"mcrr2",
3390 0 /* from ARM core register to coprocessor */,
3391 [(int_arm_mcrr2 imm:$cop, imm:$opc1, GPR:$Rt,
3392 GPR:$Rt2, imm:$CRm)]>;
3393 def t2MRRC2 : t2MovRRCopro<"mrrc2",
3394 1 /* from coprocessor to ARM core register */>;
3396 //===----------------------------------------------------------------------===//
3397 // Other Coprocessor Instructions. For disassembly only.
3400 def t2CDP2 : T2Cop<(outs), (ins p_imm:$cop, i32imm:$opc1,
3401 c_imm:$CRd, c_imm:$CRn, c_imm:$CRm, i32imm:$opc2),
3402 "cdp2\t$cop, $opc1, $CRd, $CRn, $CRm, $opc2",
3403 [(int_arm_cdp2 imm:$cop, imm:$opc1, imm:$CRd, imm:$CRn,
3404 imm:$CRm, imm:$opc2)]> {
3405 let Inst{27-24} = 0b1110;
3414 let Inst{3-0} = CRm;
3416 let Inst{7-5} = opc2;
3417 let Inst{11-8} = cop;
3418 let Inst{15-12} = CRd;
3419 let Inst{19-16} = CRn;
3420 let Inst{23-20} = opc1;