ARMInstrThumb2.td revision 0781c1f700886f94f5430380a5e82d7ccf6bbdc0
1//===- ARMInstrThumb2.td - Thumb2 support for ARM -------------------------===//
2//
3//                     The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file describes the Thumb2 instruction set.
11//
12//===----------------------------------------------------------------------===//
13
14// IT block predicate field
15def it_pred_asmoperand : AsmOperandClass {
16  let Name = "ITCondCode";
17  let ParserMethod = "parseITCondCode";
18}
19def it_pred : Operand<i32> {
20  let PrintMethod = "printMandatoryPredicateOperand";
21  let ParserMatchClass = it_pred_asmoperand;
22}
23
24// IT block condition mask
25def it_mask_asmoperand : AsmOperandClass { let Name = "ITMask"; }
26def it_mask : Operand<i32> {
27  let PrintMethod = "printThumbITMask";
28  let ParserMatchClass = it_mask_asmoperand;
29}
30
31// Shifted operands. No register controlled shifts for Thumb2.
32// Note: We do not support rrx shifted operands yet.
33def t2_so_reg : Operand<i32>,    // reg imm
34                ComplexPattern<i32, 2, "SelectT2ShifterOperandReg",
35                               [shl,srl,sra,rotr]> {
36  let EncoderMethod = "getT2SORegOpValue";
37  let PrintMethod = "printT2SOOperand";
38  let DecoderMethod = "DecodeSORegImmOperand";
39  let ParserMatchClass = ShiftedImmAsmOperand;
40  let MIOperandInfo = (ops rGPR, i32imm);
41}
42
43// t2_so_imm_not_XFORM - Return the complement of a t2_so_imm value
44def t2_so_imm_not_XFORM : SDNodeXForm<imm, [{
45  return CurDAG->getTargetConstant(~((uint32_t)N->getZExtValue()), MVT::i32);
46}]>;
47
48// t2_so_imm_neg_XFORM - Return the negation of a t2_so_imm value
49def t2_so_imm_neg_XFORM : SDNodeXForm<imm, [{
50  return CurDAG->getTargetConstant(-((int)N->getZExtValue()), MVT::i32);
51}]>;
52
53// t2_so_imm - Match a 32-bit immediate operand, which is an
54// 8-bit immediate rotated by an arbitrary number of bits, or an 8-bit
55// immediate splatted into multiple bytes of the word.
56def t2_so_imm_asmoperand : AsmOperandClass { let Name = "T2SOImm"; }
57def t2_so_imm : Operand<i32>, ImmLeaf<i32, [{
58    return ARM_AM::getT2SOImmVal(Imm) != -1;
59  }]> {
60  let ParserMatchClass = t2_so_imm_asmoperand;
61  let EncoderMethod = "getT2SOImmOpValue";
62  let DecoderMethod = "DecodeT2SOImm";
63}
64
65// t2_so_imm_not - Match an immediate that is a complement
66// of a t2_so_imm.
67def t2_so_imm_not : Operand<i32>,
68                    PatLeaf<(imm), [{
69  return ARM_AM::getT2SOImmVal(~((uint32_t)N->getZExtValue())) != -1;
70}], t2_so_imm_not_XFORM>;
71
72// t2_so_imm_neg - Match an immediate that is a negation of a t2_so_imm.
73def t2_so_imm_neg : Operand<i32>,
74                    PatLeaf<(imm), [{
75  return ARM_AM::getT2SOImmVal(-((uint32_t)N->getZExtValue())) != -1;
76}], t2_so_imm_neg_XFORM>;
77
78/// imm0_4095 predicate - True if the 32-bit immediate is in the range [0.4095].
79def imm0_4095 : Operand<i32>,
80                ImmLeaf<i32, [{
81  return Imm >= 0 && Imm < 4096;
82}]>;
83
84def imm0_4095_neg : PatLeaf<(i32 imm), [{
85 return (uint32_t)(-N->getZExtValue()) < 4096;
86}], imm_neg_XFORM>;
87
88def imm0_255_neg : PatLeaf<(i32 imm), [{
89  return (uint32_t)(-N->getZExtValue()) < 255;
90}], imm_neg_XFORM>;
91
92def imm0_255_not : PatLeaf<(i32 imm), [{
93  return (uint32_t)(~N->getZExtValue()) < 255;
94}], imm_comp_XFORM>;
95
96def lo5AllOne : PatLeaf<(i32 imm), [{
97  // Returns true if all low 5-bits are 1.
98  return (((uint32_t)N->getZExtValue()) & 0x1FUL) == 0x1FUL;
99}]>;
100
101// Define Thumb2 specific addressing modes.
102
103// t2addrmode_imm12  := reg + imm12
104def t2addrmode_imm12_asmoperand : AsmOperandClass {let Name="MemUImm12Offset";}
105def t2addrmode_imm12 : Operand<i32>,
106                       ComplexPattern<i32, 2, "SelectT2AddrModeImm12", []> {
107  let PrintMethod = "printAddrModeImm12Operand";
108  let EncoderMethod = "getAddrModeImm12OpValue";
109  let DecoderMethod = "DecodeT2AddrModeImm12";
110  let ParserMatchClass = t2addrmode_imm12_asmoperand;
111  let MIOperandInfo = (ops GPR:$base, i32imm:$offsimm);
112}
113
114// t2ldrlabel  := imm12
115def t2ldrlabel : Operand<i32> {
116  let EncoderMethod = "getAddrModeImm12OpValue";
117  let PrintMethod = "printT2LdrLabelOperand";
118}
119
120
121// ADR instruction labels.
122def t2adrlabel : Operand<i32> {
123  let EncoderMethod = "getT2AdrLabelOpValue";
124}
125
126
127// t2addrmode_posimm8  := reg + imm8
128def MemPosImm8OffsetAsmOperand : AsmOperandClass {let Name="MemPosImm8Offset";}
129def t2addrmode_posimm8 : Operand<i32> {
130  let PrintMethod = "printT2AddrModeImm8Operand";
131  let EncoderMethod = "getT2AddrModeImm8OpValue";
132  let DecoderMethod = "DecodeT2AddrModeImm8";
133  let ParserMatchClass = MemPosImm8OffsetAsmOperand;
134  let MIOperandInfo = (ops GPR:$base, i32imm:$offsimm);
135}
136
137// t2addrmode_negimm8  := reg - imm8
138def MemNegImm8OffsetAsmOperand : AsmOperandClass {let Name="MemNegImm8Offset";}
139def t2addrmode_negimm8 : Operand<i32>,
140                      ComplexPattern<i32, 2, "SelectT2AddrModeImm8", []> {
141  let PrintMethod = "printT2AddrModeImm8Operand";
142  let EncoderMethod = "getT2AddrModeImm8OpValue";
143  let DecoderMethod = "DecodeT2AddrModeImm8";
144  let ParserMatchClass = MemNegImm8OffsetAsmOperand;
145  let MIOperandInfo = (ops GPR:$base, i32imm:$offsimm);
146}
147
148// t2addrmode_imm8  := reg +/- imm8
149def MemImm8OffsetAsmOperand : AsmOperandClass { let Name = "MemImm8Offset"; }
150def t2addrmode_imm8 : Operand<i32>,
151                      ComplexPattern<i32, 2, "SelectT2AddrModeImm8", []> {
152  let PrintMethod = "printT2AddrModeImm8Operand";
153  let EncoderMethod = "getT2AddrModeImm8OpValue";
154  let DecoderMethod = "DecodeT2AddrModeImm8";
155  let ParserMatchClass = MemImm8OffsetAsmOperand;
156  let MIOperandInfo = (ops GPR:$base, i32imm:$offsimm);
157}
158
159def t2am_imm8_offset : Operand<i32>,
160                       ComplexPattern<i32, 1, "SelectT2AddrModeImm8Offset",
161                                      [], [SDNPWantRoot]> {
162  let PrintMethod = "printT2AddrModeImm8OffsetOperand";
163  let EncoderMethod = "getT2AddrModeImm8OffsetOpValue";
164  let DecoderMethod = "DecodeT2Imm8";
165}
166
167// t2addrmode_imm8s4  := reg +/- (imm8 << 2)
168def MemImm8s4OffsetAsmOperand : AsmOperandClass {let Name = "MemImm8s4Offset";}
169def t2addrmode_imm8s4 : Operand<i32> {
170  let PrintMethod = "printT2AddrModeImm8s4Operand";
171  let EncoderMethod = "getT2AddrModeImm8s4OpValue";
172  let DecoderMethod = "DecodeT2AddrModeImm8s4";
173  let ParserMatchClass = MemImm8s4OffsetAsmOperand;
174  let MIOperandInfo = (ops GPR:$base, i32imm:$offsimm);
175}
176
177def t2am_imm8s4_offset_asmoperand : AsmOperandClass { let Name = "Imm8s4"; }
178def t2am_imm8s4_offset : Operand<i32> {
179  let PrintMethod = "printT2AddrModeImm8s4OffsetOperand";
180  let EncoderMethod = "getT2Imm8s4OpValue";
181  let DecoderMethod = "DecodeT2Imm8S4";
182}
183
184// t2addrmode_imm0_1020s4  := reg + (imm8 << 2)
185def MemImm0_1020s4OffsetAsmOperand : AsmOperandClass {
186  let Name = "MemImm0_1020s4Offset";
187}
188def t2addrmode_imm0_1020s4 : Operand<i32> {
189  let PrintMethod = "printT2AddrModeImm0_1020s4Operand";
190  let EncoderMethod = "getT2AddrModeImm0_1020s4OpValue";
191  let DecoderMethod = "DecodeT2AddrModeImm0_1020s4";
192  let ParserMatchClass = MemImm0_1020s4OffsetAsmOperand;
193  let MIOperandInfo = (ops GPRnopc:$base, i32imm:$offsimm);
194}
195
196// t2addrmode_so_reg  := reg + (reg << imm2)
197def t2addrmode_so_reg_asmoperand : AsmOperandClass {let Name="T2MemRegOffset";}
198def t2addrmode_so_reg : Operand<i32>,
199                        ComplexPattern<i32, 3, "SelectT2AddrModeSoReg", []> {
200  let PrintMethod = "printT2AddrModeSoRegOperand";
201  let EncoderMethod = "getT2AddrModeSORegOpValue";
202  let DecoderMethod = "DecodeT2AddrModeSOReg";
203  let ParserMatchClass = t2addrmode_so_reg_asmoperand;
204  let MIOperandInfo = (ops GPR:$base, rGPR:$offsreg, i32imm:$offsimm);
205}
206
207// Addresses for the TBB/TBH instructions.
208def addrmode_tbb_asmoperand : AsmOperandClass { let Name = "MemTBB"; }
209def addrmode_tbb : Operand<i32> {
210  let PrintMethod = "printAddrModeTBB";
211  let ParserMatchClass = addrmode_tbb_asmoperand;
212  let MIOperandInfo = (ops GPR:$Rn, rGPR:$Rm);
213}
214def addrmode_tbh_asmoperand : AsmOperandClass { let Name = "MemTBH"; }
215def addrmode_tbh : Operand<i32> {
216  let PrintMethod = "printAddrModeTBH";
217  let ParserMatchClass = addrmode_tbh_asmoperand;
218  let MIOperandInfo = (ops GPR:$Rn, rGPR:$Rm);
219}
220
221//===----------------------------------------------------------------------===//
222// Multiclass helpers...
223//
224
225
226class T2OneRegImm<dag oops, dag iops, InstrItinClass itin,
227           string opc, string asm, list<dag> pattern>
228  : T2I<oops, iops, itin, opc, asm, pattern> {
229  bits<4> Rd;
230  bits<12> imm;
231
232  let Inst{11-8}  = Rd;
233  let Inst{26}    = imm{11};
234  let Inst{14-12} = imm{10-8};
235  let Inst{7-0}   = imm{7-0};
236}
237
238
239class T2sOneRegImm<dag oops, dag iops, InstrItinClass itin,
240           string opc, string asm, list<dag> pattern>
241  : T2sI<oops, iops, itin, opc, asm, pattern> {
242  bits<4> Rd;
243  bits<4> Rn;
244  bits<12> imm;
245
246  let Inst{11-8}  = Rd;
247  let Inst{26}    = imm{11};
248  let Inst{14-12} = imm{10-8};
249  let Inst{7-0}   = imm{7-0};
250}
251
252class T2OneRegCmpImm<dag oops, dag iops, InstrItinClass itin,
253           string opc, string asm, list<dag> pattern>
254  : T2I<oops, iops, itin, opc, asm, pattern> {
255  bits<4> Rn;
256  bits<12> imm;
257
258  let Inst{19-16}  = Rn;
259  let Inst{26}    = imm{11};
260  let Inst{14-12} = imm{10-8};
261  let Inst{7-0}   = imm{7-0};
262}
263
264
265class T2OneRegShiftedReg<dag oops, dag iops, InstrItinClass itin,
266           string opc, string asm, list<dag> pattern>
267  : T2I<oops, iops, itin, opc, asm, pattern> {
268  bits<4> Rd;
269  bits<12> ShiftedRm;
270
271  let Inst{11-8}  = Rd;
272  let Inst{3-0}   = ShiftedRm{3-0};
273  let Inst{5-4}   = ShiftedRm{6-5};
274  let Inst{14-12} = ShiftedRm{11-9};
275  let Inst{7-6}   = ShiftedRm{8-7};
276}
277
278class T2sOneRegShiftedReg<dag oops, dag iops, InstrItinClass itin,
279           string opc, string asm, list<dag> pattern>
280  : T2sI<oops, iops, itin, opc, asm, pattern> {
281  bits<4> Rd;
282  bits<12> ShiftedRm;
283
284  let Inst{11-8}  = Rd;
285  let Inst{3-0}   = ShiftedRm{3-0};
286  let Inst{5-4}   = ShiftedRm{6-5};
287  let Inst{14-12} = ShiftedRm{11-9};
288  let Inst{7-6}   = ShiftedRm{8-7};
289}
290
291class T2OneRegCmpShiftedReg<dag oops, dag iops, InstrItinClass itin,
292           string opc, string asm, list<dag> pattern>
293  : T2I<oops, iops, itin, opc, asm, pattern> {
294  bits<4> Rn;
295  bits<12> ShiftedRm;
296
297  let Inst{19-16} = Rn;
298  let Inst{3-0}   = ShiftedRm{3-0};
299  let Inst{5-4}   = ShiftedRm{6-5};
300  let Inst{14-12} = ShiftedRm{11-9};
301  let Inst{7-6}   = ShiftedRm{8-7};
302}
303
304class T2TwoReg<dag oops, dag iops, InstrItinClass itin,
305           string opc, string asm, list<dag> pattern>
306  : T2I<oops, iops, itin, opc, asm, pattern> {
307  bits<4> Rd;
308  bits<4> Rm;
309
310  let Inst{11-8}  = Rd;
311  let Inst{3-0}   = Rm;
312}
313
314class T2sTwoReg<dag oops, dag iops, InstrItinClass itin,
315           string opc, string asm, list<dag> pattern>
316  : T2sI<oops, iops, itin, opc, asm, pattern> {
317  bits<4> Rd;
318  bits<4> Rm;
319
320  let Inst{11-8}  = Rd;
321  let Inst{3-0}   = Rm;
322}
323
324class T2TwoRegCmp<dag oops, dag iops, InstrItinClass itin,
325           string opc, string asm, list<dag> pattern>
326  : T2I<oops, iops, itin, opc, asm, pattern> {
327  bits<4> Rn;
328  bits<4> Rm;
329
330  let Inst{19-16} = Rn;
331  let Inst{3-0}   = Rm;
332}
333
334
335class T2TwoRegImm<dag oops, dag iops, InstrItinClass itin,
336           string opc, string asm, list<dag> pattern>
337  : T2I<oops, iops, itin, opc, asm, pattern> {
338  bits<4> Rd;
339  bits<4> Rn;
340  bits<12> imm;
341
342  let Inst{11-8}  = Rd;
343  let Inst{19-16} = Rn;
344  let Inst{26}    = imm{11};
345  let Inst{14-12} = imm{10-8};
346  let Inst{7-0}   = imm{7-0};
347}
348
349class T2sTwoRegImm<dag oops, dag iops, InstrItinClass itin,
350           string opc, string asm, list<dag> pattern>
351  : T2sI<oops, iops, itin, opc, asm, pattern> {
352  bits<4> Rd;
353  bits<4> Rn;
354  bits<12> imm;
355
356  let Inst{11-8}  = Rd;
357  let Inst{19-16} = Rn;
358  let Inst{26}    = imm{11};
359  let Inst{14-12} = imm{10-8};
360  let Inst{7-0}   = imm{7-0};
361}
362
363class T2TwoRegShiftImm<dag oops, dag iops, InstrItinClass itin,
364           string opc, string asm, list<dag> pattern>
365  : T2I<oops, iops, itin, opc, asm, pattern> {
366  bits<4> Rd;
367  bits<4> Rm;
368  bits<5> imm;
369
370  let Inst{11-8}  = Rd;
371  let Inst{3-0}   = Rm;
372  let Inst{14-12} = imm{4-2};
373  let Inst{7-6}   = imm{1-0};
374}
375
376class T2sTwoRegShiftImm<dag oops, dag iops, InstrItinClass itin,
377           string opc, string asm, list<dag> pattern>
378  : T2sI<oops, iops, itin, opc, asm, pattern> {
379  bits<4> Rd;
380  bits<4> Rm;
381  bits<5> imm;
382
383  let Inst{11-8}  = Rd;
384  let Inst{3-0}   = Rm;
385  let Inst{14-12} = imm{4-2};
386  let Inst{7-6}   = imm{1-0};
387}
388
389class T2ThreeReg<dag oops, dag iops, InstrItinClass itin,
390           string opc, string asm, list<dag> pattern>
391  : T2I<oops, iops, itin, opc, asm, pattern> {
392  bits<4> Rd;
393  bits<4> Rn;
394  bits<4> Rm;
395
396  let Inst{11-8}  = Rd;
397  let Inst{19-16} = Rn;
398  let Inst{3-0}   = Rm;
399}
400
401class T2sThreeReg<dag oops, dag iops, InstrItinClass itin,
402           string opc, string asm, list<dag> pattern>
403  : T2sI<oops, iops, itin, opc, asm, pattern> {
404  bits<4> Rd;
405  bits<4> Rn;
406  bits<4> Rm;
407
408  let Inst{11-8}  = Rd;
409  let Inst{19-16} = Rn;
410  let Inst{3-0}   = Rm;
411}
412
413class T2TwoRegShiftedReg<dag oops, dag iops, InstrItinClass itin,
414           string opc, string asm, list<dag> pattern>
415  : T2I<oops, iops, itin, opc, asm, pattern> {
416  bits<4> Rd;
417  bits<4> Rn;
418  bits<12> ShiftedRm;
419
420  let Inst{11-8}  = Rd;
421  let Inst{19-16} = Rn;
422  let Inst{3-0}   = ShiftedRm{3-0};
423  let Inst{5-4}   = ShiftedRm{6-5};
424  let Inst{14-12} = ShiftedRm{11-9};
425  let Inst{7-6}   = ShiftedRm{8-7};
426}
427
428class T2sTwoRegShiftedReg<dag oops, dag iops, InstrItinClass itin,
429           string opc, string asm, list<dag> pattern>
430  : T2sI<oops, iops, itin, opc, asm, pattern> {
431  bits<4> Rd;
432  bits<4> Rn;
433  bits<12> ShiftedRm;
434
435  let Inst{11-8}  = Rd;
436  let Inst{19-16} = Rn;
437  let Inst{3-0}   = ShiftedRm{3-0};
438  let Inst{5-4}   = ShiftedRm{6-5};
439  let Inst{14-12} = ShiftedRm{11-9};
440  let Inst{7-6}   = ShiftedRm{8-7};
441}
442
443class T2FourReg<dag oops, dag iops, InstrItinClass itin,
444           string opc, string asm, list<dag> pattern>
445  : T2I<oops, iops, itin, opc, asm, pattern> {
446  bits<4> Rd;
447  bits<4> Rn;
448  bits<4> Rm;
449  bits<4> Ra;
450
451  let Inst{19-16} = Rn;
452  let Inst{15-12} = Ra;
453  let Inst{11-8}  = Rd;
454  let Inst{3-0}   = Rm;
455}
456
457class T2MulLong<bits<3> opc22_20, bits<4> opc7_4,
458                dag oops, dag iops, InstrItinClass itin,
459                string opc, string asm, list<dag> pattern>
460  : T2I<oops, iops, itin, opc, asm, pattern> {
461  bits<4> RdLo;
462  bits<4> RdHi;
463  bits<4> Rn;
464  bits<4> Rm;
465
466  let Inst{31-23} = 0b111110111;
467  let Inst{22-20} = opc22_20;
468  let Inst{19-16} = Rn;
469  let Inst{15-12} = RdLo;
470  let Inst{11-8}  = RdHi;
471  let Inst{7-4}   = opc7_4;
472  let Inst{3-0}   = Rm;
473}
474
475
476/// T2I_bin_irs - Defines a set of (op reg, {so_imm|r|so_reg}) patterns for a
477/// binary operation that produces a value. These are predicable and can be
478/// changed to modify CPSR.
479multiclass T2I_bin_irs<bits<4> opcod, string opc,
480                     InstrItinClass iii, InstrItinClass iir, InstrItinClass iis,
481                       PatFrag opnode, string baseOpc, bit Commutable = 0,
482                       string wide = ""> {
483   // shifted imm
484   def ri : T2sTwoRegImm<
485                (outs rGPR:$Rd), (ins rGPR:$Rn, t2_so_imm:$imm), iii,
486                 opc, "\t$Rd, $Rn, $imm",
487                 [(set rGPR:$Rd, (opnode rGPR:$Rn, t2_so_imm:$imm))]> {
488     let Inst{31-27} = 0b11110;
489     let Inst{25} = 0;
490     let Inst{24-21} = opcod;
491     let Inst{15} = 0;
492   }
493   // register
494   def rr : T2sThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), iir,
495                 opc, !strconcat(wide, "\t$Rd, $Rn, $Rm"),
496                 [(set rGPR:$Rd, (opnode rGPR:$Rn, rGPR:$Rm))]> {
497     let isCommutable = Commutable;
498     let Inst{31-27} = 0b11101;
499     let Inst{26-25} = 0b01;
500     let Inst{24-21} = opcod;
501     let Inst{14-12} = 0b000; // imm3
502     let Inst{7-6} = 0b00; // imm2
503     let Inst{5-4} = 0b00; // type
504   }
505   // shifted register
506   def rs : T2sTwoRegShiftedReg<
507                 (outs rGPR:$Rd), (ins rGPR:$Rn, t2_so_reg:$ShiftedRm), iis,
508                 opc, !strconcat(wide, "\t$Rd, $Rn, $ShiftedRm"),
509                 [(set rGPR:$Rd, (opnode rGPR:$Rn, t2_so_reg:$ShiftedRm))]> {
510     let Inst{31-27} = 0b11101;
511     let Inst{26-25} = 0b01;
512     let Inst{24-21} = opcod;
513   }
514  // Assembly aliases for optional destination operand when it's the same
515  // as the source operand.
516  def : t2InstAlias<!strconcat(opc, "${s}${p} $Rdn, $imm"),
517     (!cast<Instruction>(!strconcat(baseOpc, "ri")) rGPR:$Rdn, rGPR:$Rdn,
518                                                    t2_so_imm:$imm, pred:$p,
519                                                    cc_out:$s)>;
520  def : t2InstAlias<!strconcat(opc, "${s}${p}", wide, " $Rdn, $Rm"),
521     (!cast<Instruction>(!strconcat(baseOpc, "rr")) rGPR:$Rdn, rGPR:$Rdn,
522                                                    rGPR:$Rm, pred:$p,
523                                                    cc_out:$s)>;
524  def : t2InstAlias<!strconcat(opc, "${s}${p}", wide, " $Rdn, $shift"),
525     (!cast<Instruction>(!strconcat(baseOpc, "rs")) rGPR:$Rdn, rGPR:$Rdn,
526                                                    t2_so_reg:$shift, pred:$p,
527                                                    cc_out:$s)>;
528}
529
530/// T2I_bin_w_irs - Same as T2I_bin_irs except these operations need
531//  the ".w" suffix to indicate that they are wide.
532multiclass T2I_bin_w_irs<bits<4> opcod, string opc,
533                     InstrItinClass iii, InstrItinClass iir, InstrItinClass iis,
534                         PatFrag opnode, string baseOpc, bit Commutable = 0> :
535    T2I_bin_irs<opcod, opc, iii, iir, iis, opnode, baseOpc, Commutable, ".w"> {
536  // Assembler aliases w/o the ".w" suffix.
537  def : t2InstAlias<!strconcat(opc, "${s}${p}", " $Rd, $Rn, $Rm"),
538     (!cast<Instruction>(!strconcat(baseOpc, "rr")) rGPR:$Rd, rGPR:$Rn,
539                                                    rGPR:$Rm, pred:$p,
540                                                    cc_out:$s)>;
541  def : t2InstAlias<!strconcat(opc, "${s}${p}", " $Rd, $Rn, $shift"),
542     (!cast<Instruction>(!strconcat(baseOpc, "rs")) rGPR:$Rd, rGPR:$Rn,
543                                                    t2_so_reg:$shift, pred:$p,
544                                                    cc_out:$s)>;
545
546  // and with the optional destination operand, too.
547  def : t2InstAlias<!strconcat(opc, "${s}${p}", " $Rdn, $Rm"),
548     (!cast<Instruction>(!strconcat(baseOpc, "rr")) rGPR:$Rdn, rGPR:$Rdn,
549                                                    rGPR:$Rm, pred:$p,
550                                                    cc_out:$s)>;
551  def : t2InstAlias<!strconcat(opc, "${s}${p}", " $Rdn, $shift"),
552     (!cast<Instruction>(!strconcat(baseOpc, "rs")) rGPR:$Rdn, rGPR:$Rdn,
553                                                    t2_so_reg:$shift, pred:$p,
554                                                    cc_out:$s)>;
555}
556
557/// T2I_rbin_is - Same as T2I_bin_irs except the order of operands are
558/// reversed.  The 'rr' form is only defined for the disassembler; for codegen
559/// it is equivalent to the T2I_bin_irs counterpart.
560multiclass T2I_rbin_irs<bits<4> opcod, string opc, PatFrag opnode> {
561   // shifted imm
562   def ri : T2sTwoRegImm<
563                 (outs rGPR:$Rd), (ins rGPR:$Rn, t2_so_imm:$imm), IIC_iALUi,
564                 opc, ".w\t$Rd, $Rn, $imm",
565                 [(set rGPR:$Rd, (opnode t2_so_imm:$imm, rGPR:$Rn))]> {
566     let Inst{31-27} = 0b11110;
567     let Inst{25} = 0;
568     let Inst{24-21} = opcod;
569     let Inst{15} = 0;
570   }
571   // register
572   def rr : T2sThreeReg<
573                 (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iALUr,
574                 opc, "\t$Rd, $Rn, $Rm",
575                 [/* For disassembly only; pattern left blank */]> {
576     let Inst{31-27} = 0b11101;
577     let Inst{26-25} = 0b01;
578     let Inst{24-21} = opcod;
579     let Inst{14-12} = 0b000; // imm3
580     let Inst{7-6} = 0b00; // imm2
581     let Inst{5-4} = 0b00; // type
582   }
583   // shifted register
584   def rs : T2sTwoRegShiftedReg<
585                 (outs rGPR:$Rd), (ins rGPR:$Rn, t2_so_reg:$ShiftedRm),
586                 IIC_iALUsir, opc, "\t$Rd, $Rn, $ShiftedRm",
587                 [(set rGPR:$Rd, (opnode t2_so_reg:$ShiftedRm, rGPR:$Rn))]> {
588     let Inst{31-27} = 0b11101;
589     let Inst{26-25} = 0b01;
590     let Inst{24-21} = opcod;
591   }
592}
593
594/// T2I_bin_s_irs - Similar to T2I_bin_irs except it sets the 's' bit so the
595/// instruction modifies the CPSR register.
596///
597/// These opcodes will be converted to the real non-S opcodes by
598/// AdjustInstrPostInstrSelection after giving then an optional CPSR operand.
599let hasPostISelHook = 1, isCodeGenOnly = 1, isPseudo = 1, Defs = [CPSR] in {
600multiclass T2I_bin_s_irs<bits<4> opcod, string opc,
601                     InstrItinClass iii, InstrItinClass iir, InstrItinClass iis,
602                         PatFrag opnode, bit Commutable = 0> {
603   // shifted imm
604   def ri : T2sTwoRegImm<
605                (outs rGPR:$Rd), (ins GPR:$Rn, t2_so_imm:$imm), iii,
606                opc, ".w\t$Rd, $Rn, $imm",
607                [(set rGPR:$Rd, CPSR, (opnode GPR:$Rn, t2_so_imm:$imm))]>;
608   // register
609   def rr : T2sThreeReg<
610                (outs rGPR:$Rd), (ins GPR:$Rn, rGPR:$Rm), iir,
611                opc, ".w\t$Rd, $Rn, $Rm",
612                [(set rGPR:$Rd, CPSR, (opnode GPR:$Rn, rGPR:$Rm))]>;
613   // shifted register
614   def rs : T2sTwoRegShiftedReg<
615                (outs rGPR:$Rd), (ins GPR:$Rn, t2_so_reg:$ShiftedRm), iis,
616                opc, ".w\t$Rd, $Rn, $ShiftedRm",
617               [(set rGPR:$Rd, CPSR, (opnode GPR:$Rn, t2_so_reg:$ShiftedRm))]>;
618}
619}
620
621/// T2I_bin_ii12rs - Defines a set of (op reg, {so_imm|imm0_4095|r|so_reg})
622/// patterns for a binary operation that produces a value.
623multiclass T2I_bin_ii12rs<bits<3> op23_21, string opc, PatFrag opnode,
624                          bit Commutable = 0> {
625   // shifted imm
626   // The register-immediate version is re-materializable. This is useful
627   // in particular for taking the address of a local.
628   let isReMaterializable = 1 in {
629   def ri : T2sTwoRegImm<
630                 (outs rGPR:$Rd), (ins GPRnopc:$Rn, t2_so_imm:$imm), IIC_iALUi,
631                 opc, ".w\t$Rd, $Rn, $imm",
632                 [(set rGPR:$Rd, (opnode GPRnopc:$Rn, t2_so_imm:$imm))]> {
633     let Inst{31-27} = 0b11110;
634     let Inst{25} = 0;
635     let Inst{24} = 1;
636     let Inst{23-21} = op23_21;
637     let Inst{15} = 0;
638   }
639   }
640   // 12-bit imm
641   def ri12 : T2I<
642                  (outs rGPR:$Rd), (ins GPR:$Rn, imm0_4095:$imm), IIC_iALUi,
643                  !strconcat(opc, "w"), "\t$Rd, $Rn, $imm",
644                  [(set rGPR:$Rd, (opnode GPR:$Rn, imm0_4095:$imm))]> {
645     bits<4> Rd;
646     bits<4> Rn;
647     bits<12> imm;
648     let Inst{31-27} = 0b11110;
649     let Inst{26} = imm{11};
650     let Inst{25-24} = 0b10;
651     let Inst{23-21} = op23_21;
652     let Inst{20} = 0; // The S bit.
653     let Inst{19-16} = Rn;
654     let Inst{15} = 0;
655     let Inst{14-12} = imm{10-8};
656     let Inst{11-8} = Rd;
657     let Inst{7-0} = imm{7-0};
658   }
659   // register
660   def rr : T2sThreeReg<(outs rGPR:$Rd), (ins GPRnopc:$Rn, rGPR:$Rm), IIC_iALUr,
661                 opc, ".w\t$Rd, $Rn, $Rm",
662                 [(set rGPR:$Rd, (opnode GPRnopc:$Rn, rGPR:$Rm))]> {
663     let isCommutable = Commutable;
664     let Inst{31-27} = 0b11101;
665     let Inst{26-25} = 0b01;
666     let Inst{24} = 1;
667     let Inst{23-21} = op23_21;
668     let Inst{14-12} = 0b000; // imm3
669     let Inst{7-6} = 0b00; // imm2
670     let Inst{5-4} = 0b00; // type
671   }
672   // shifted register
673   def rs : T2sTwoRegShiftedReg<
674                 (outs rGPR:$Rd), (ins GPRnopc:$Rn, t2_so_reg:$ShiftedRm),
675                 IIC_iALUsi, opc, ".w\t$Rd, $Rn, $ShiftedRm",
676                 [(set rGPR:$Rd, (opnode GPRnopc:$Rn, t2_so_reg:$ShiftedRm))]> {
677     let Inst{31-27} = 0b11101;
678     let Inst{26-25} = 0b01;
679     let Inst{24} = 1;
680     let Inst{23-21} = op23_21;
681   }
682}
683
684/// T2I_adde_sube_irs - Defines a set of (op reg, {so_imm|r|so_reg}) patterns
685/// for a binary operation that produces a value and use the carry
686/// bit. It's not predicable.
687let Defs = [CPSR], Uses = [CPSR] in {
688multiclass T2I_adde_sube_irs<bits<4> opcod, string opc, PatFrag opnode,
689                             bit Commutable = 0> {
690   // shifted imm
691   def ri : T2sTwoRegImm<(outs rGPR:$Rd), (ins rGPR:$Rn, t2_so_imm:$imm),
692                 IIC_iALUi, opc, "\t$Rd, $Rn, $imm",
693               [(set rGPR:$Rd, CPSR, (opnode rGPR:$Rn, t2_so_imm:$imm, CPSR))]>,
694                 Requires<[IsThumb2]> {
695     let Inst{31-27} = 0b11110;
696     let Inst{25} = 0;
697     let Inst{24-21} = opcod;
698     let Inst{15} = 0;
699   }
700   // register
701   def rr : T2sThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iALUr,
702                 opc, ".w\t$Rd, $Rn, $Rm",
703                 [(set rGPR:$Rd, CPSR, (opnode rGPR:$Rn, rGPR:$Rm, CPSR))]>,
704                 Requires<[IsThumb2]> {
705     let isCommutable = Commutable;
706     let Inst{31-27} = 0b11101;
707     let Inst{26-25} = 0b01;
708     let Inst{24-21} = opcod;
709     let Inst{14-12} = 0b000; // imm3
710     let Inst{7-6} = 0b00; // imm2
711     let Inst{5-4} = 0b00; // type
712   }
713   // shifted register
714   def rs : T2sTwoRegShiftedReg<
715                 (outs rGPR:$Rd), (ins rGPR:$Rn, t2_so_reg:$ShiftedRm),
716                 IIC_iALUsi, opc, ".w\t$Rd, $Rn, $ShiftedRm",
717         [(set rGPR:$Rd, CPSR, (opnode rGPR:$Rn, t2_so_reg:$ShiftedRm, CPSR))]>,
718                 Requires<[IsThumb2]> {
719     let Inst{31-27} = 0b11101;
720     let Inst{26-25} = 0b01;
721     let Inst{24-21} = opcod;
722   }
723}
724}
725
726/// T2I_rbin_s_is - Same as T2I_rbin_irs except sets 's' bit and the register
727/// version is not needed since this is only for codegen.
728///
729/// These opcodes will be converted to the real non-S opcodes by
730/// AdjustInstrPostInstrSelection after giving then an optional CPSR operand.
731let hasPostISelHook = 1, isCodeGenOnly = 1, isPseudo = 1, Defs = [CPSR] in {
732multiclass T2I_rbin_s_is<bits<4> opcod, string opc, PatFrag opnode> {
733   // shifted imm
734   def ri : T2sTwoRegImm<
735                (outs rGPR:$Rd), (ins rGPR:$Rn, t2_so_imm:$imm), IIC_iALUi,
736                opc, ".w\t$Rd, $Rn, $imm",
737                [(set rGPR:$Rd, CPSR, (opnode t2_so_imm:$imm, rGPR:$Rn))]>;
738   // shifted register
739   def rs : T2sTwoRegShiftedReg<
740                (outs rGPR:$Rd), (ins rGPR:$Rn, t2_so_reg:$ShiftedRm),
741                IIC_iALUsi, opc, "\t$Rd, $Rn, $ShiftedRm",
742              [(set rGPR:$Rd, CPSR, (opnode t2_so_reg:$ShiftedRm, rGPR:$Rn))]>;
743}
744}
745
746/// T2I_sh_ir - Defines a set of (op reg, {so_imm|r}) patterns for a shift /
747//  rotate operation that produces a value.
748multiclass T2I_sh_ir<bits<2> opcod, string opc, Operand ty, PatFrag opnode,
749                     string baseOpc> {
750   // 5-bit imm
751   def ri : T2sTwoRegShiftImm<
752                 (outs rGPR:$Rd), (ins rGPR:$Rm, ty:$imm), IIC_iMOVsi,
753                 opc, ".w\t$Rd, $Rm, $imm",
754                 [(set rGPR:$Rd, (opnode rGPR:$Rm, (i32 ty:$imm)))]> {
755     let Inst{31-27} = 0b11101;
756     let Inst{26-21} = 0b010010;
757     let Inst{19-16} = 0b1111; // Rn
758     let Inst{5-4} = opcod;
759   }
760   // register
761   def rr : T2sThreeReg<
762                 (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iMOVsr,
763                 opc, ".w\t$Rd, $Rn, $Rm",
764                 [(set rGPR:$Rd, (opnode rGPR:$Rn, rGPR:$Rm))]> {
765     let Inst{31-27} = 0b11111;
766     let Inst{26-23} = 0b0100;
767     let Inst{22-21} = opcod;
768     let Inst{15-12} = 0b1111;
769     let Inst{7-4} = 0b0000;
770   }
771
772  // Optional destination register
773  def : t2InstAlias<!strconcat(opc, "${s}${p}", ".w $Rdn, $imm"),
774     (!cast<Instruction>(!strconcat(baseOpc, "ri")) rGPR:$Rdn, rGPR:$Rdn,
775                                                    ty:$imm, pred:$p,
776                                                    cc_out:$s)>;
777  def : t2InstAlias<!strconcat(opc, "${s}${p}", ".w $Rdn, $Rm"),
778     (!cast<Instruction>(!strconcat(baseOpc, "rr")) rGPR:$Rdn, rGPR:$Rdn,
779                                                    rGPR:$Rm, pred:$p,
780                                                    cc_out:$s)>;
781
782  // Assembler aliases w/o the ".w" suffix.
783  def : t2InstAlias<!strconcat(opc, "${s}${p}", " $Rd, $Rn, $imm"),
784     (!cast<Instruction>(!strconcat(baseOpc, "ri")) rGPR:$Rd, rGPR:$Rn,
785                                                    ty:$imm, pred:$p,
786                                                   cc_out:$s)>;
787  def : t2InstAlias<!strconcat(opc, "${s}${p}", " $Rd, $Rn, $Rm"),
788     (!cast<Instruction>(!strconcat(baseOpc, "rr")) rGPR:$Rd, rGPR:$Rn,
789                                                    rGPR:$Rm, pred:$p,
790                                                    cc_out:$s)>;
791
792  // and with the optional destination operand, too.
793  def : t2InstAlias<!strconcat(opc, "${s}${p}", " $Rdn, $imm"),
794     (!cast<Instruction>(!strconcat(baseOpc, "ri")) rGPR:$Rdn, rGPR:$Rdn,
795                                                    ty:$imm, pred:$p,
796                                                    cc_out:$s)>;
797  def : t2InstAlias<!strconcat(opc, "${s}${p}", " $Rdn, $Rm"),
798     (!cast<Instruction>(!strconcat(baseOpc, "rr")) rGPR:$Rdn, rGPR:$Rdn,
799                                                    rGPR:$Rm, pred:$p,
800                                                    cc_out:$s)>;
801}
802
803/// T2I_cmp_irs - Defines a set of (op r, {so_imm|r|so_reg}) cmp / test
804/// patterns. Similar to T2I_bin_irs except the instruction does not produce
805/// a explicit result, only implicitly set CPSR.
806multiclass T2I_cmp_irs<bits<4> opcod, string opc,
807                     InstrItinClass iii, InstrItinClass iir, InstrItinClass iis,
808                       PatFrag opnode, string baseOpc> {
809let isCompare = 1, Defs = [CPSR] in {
810   // shifted imm
811   def ri : T2OneRegCmpImm<
812                (outs), (ins GPRnopc:$Rn, t2_so_imm:$imm), iii,
813                opc, ".w\t$Rn, $imm",
814                [(opnode GPRnopc:$Rn, t2_so_imm:$imm)]> {
815     let Inst{31-27} = 0b11110;
816     let Inst{25} = 0;
817     let Inst{24-21} = opcod;
818     let Inst{20} = 1; // The S bit.
819     let Inst{15} = 0;
820     let Inst{11-8} = 0b1111; // Rd
821   }
822   // register
823   def rr : T2TwoRegCmp<
824                (outs), (ins GPRnopc:$Rn, rGPR:$Rm), iir,
825                opc, ".w\t$Rn, $Rm",
826                [(opnode GPRnopc:$Rn, rGPR:$Rm)]> {
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{14-12} = 0b000; // imm3
832     let Inst{11-8} = 0b1111; // Rd
833     let Inst{7-6} = 0b00; // imm2
834     let Inst{5-4} = 0b00; // type
835   }
836   // shifted register
837   def rs : T2OneRegCmpShiftedReg<
838                (outs), (ins GPRnopc:$Rn, t2_so_reg:$ShiftedRm), iis,
839                opc, ".w\t$Rn, $ShiftedRm",
840                [(opnode GPRnopc:$Rn, t2_so_reg:$ShiftedRm)]> {
841     let Inst{31-27} = 0b11101;
842     let Inst{26-25} = 0b01;
843     let Inst{24-21} = opcod;
844     let Inst{20} = 1; // The S bit.
845     let Inst{11-8} = 0b1111; // Rd
846   }
847}
848
849  // Assembler aliases w/o the ".w" suffix.
850  // No alias here for 'rr' version as not all instantiations of this
851  // multiclass want one (CMP in particular, does not).
852  def : t2InstAlias<!strconcat(opc, "${p}", " $Rn, $imm"),
853     (!cast<Instruction>(!strconcat(baseOpc, "ri")) GPRnopc:$Rn,
854                                                    t2_so_imm:$imm, pred:$p)>;
855  def : t2InstAlias<!strconcat(opc, "${p}", " $Rn, $shift"),
856     (!cast<Instruction>(!strconcat(baseOpc, "rs")) GPRnopc:$Rn,
857                                                    t2_so_reg:$shift,
858                                                    pred:$p)>;
859}
860
861/// T2I_ld - Defines a set of (op r, {imm12|imm8|so_reg}) load patterns.
862multiclass T2I_ld<bit signed, bits<2> opcod, string opc,
863                  InstrItinClass iii, InstrItinClass iis, RegisterClass target,
864                  PatFrag opnode> {
865  def i12 : T2Ii12<(outs target:$Rt), (ins t2addrmode_imm12:$addr), iii,
866                   opc, ".w\t$Rt, $addr",
867                   [(set target:$Rt, (opnode t2addrmode_imm12:$addr))]> {
868    bits<4> Rt;
869    bits<17> addr;
870    let Inst{31-25} = 0b1111100;
871    let Inst{24} = signed;
872    let Inst{23} = 1;
873    let Inst{22-21} = opcod;
874    let Inst{20} = 1; // load
875    let Inst{19-16} = addr{16-13}; // Rn
876    let Inst{15-12} = Rt;
877    let Inst{11-0}  = addr{11-0};  // imm
878  }
879  def i8  : T2Ii8 <(outs target:$Rt), (ins t2addrmode_negimm8:$addr), iii,
880                   opc, "\t$Rt, $addr",
881                   [(set target:$Rt, (opnode t2addrmode_negimm8:$addr))]> {
882    bits<4> Rt;
883    bits<13> addr;
884    let Inst{31-27} = 0b11111;
885    let Inst{26-25} = 0b00;
886    let Inst{24} = signed;
887    let Inst{23} = 0;
888    let Inst{22-21} = opcod;
889    let Inst{20} = 1; // load
890    let Inst{19-16} = addr{12-9}; // Rn
891    let Inst{15-12} = Rt;
892    let Inst{11} = 1;
893    // Offset: index==TRUE, wback==FALSE
894    let Inst{10} = 1; // The P bit.
895    let Inst{9}     = addr{8};    // U
896    let Inst{8} = 0; // The W bit.
897    let Inst{7-0}   = addr{7-0};  // imm
898  }
899  def s   : T2Iso <(outs target:$Rt), (ins t2addrmode_so_reg:$addr), iis,
900                   opc, ".w\t$Rt, $addr",
901                   [(set target:$Rt, (opnode t2addrmode_so_reg:$addr))]> {
902    let Inst{31-27} = 0b11111;
903    let Inst{26-25} = 0b00;
904    let Inst{24} = signed;
905    let Inst{23} = 0;
906    let Inst{22-21} = opcod;
907    let Inst{20} = 1; // load
908    let Inst{11-6} = 0b000000;
909
910    bits<4> Rt;
911    let Inst{15-12} = Rt;
912
913    bits<10> addr;
914    let Inst{19-16} = addr{9-6}; // Rn
915    let Inst{3-0}   = addr{5-2}; // Rm
916    let Inst{5-4}   = addr{1-0}; // imm
917
918    let DecoderMethod = "DecodeT2LoadShift";
919  }
920
921  // FIXME: Is the pci variant actually needed?
922  def pci : T2Ipc <(outs target:$Rt), (ins t2ldrlabel:$addr), iii,
923                   opc, ".w\t$Rt, $addr",
924                   [(set target:$Rt, (opnode (ARMWrapper tconstpool:$addr)))]> {
925    let isReMaterializable = 1;
926    let Inst{31-27} = 0b11111;
927    let Inst{26-25} = 0b00;
928    let Inst{24} = signed;
929    let Inst{23} = ?; // add = (U == '1')
930    let Inst{22-21} = opcod;
931    let Inst{20} = 1; // load
932    let Inst{19-16} = 0b1111; // Rn
933    bits<4> Rt;
934    bits<12> addr;
935    let Inst{15-12} = Rt{3-0};
936    let Inst{11-0}  = addr{11-0};
937  }
938}
939
940/// T2I_st - Defines a set of (op r, {imm12|imm8|so_reg}) store patterns.
941multiclass T2I_st<bits<2> opcod, string opc,
942                  InstrItinClass iii, InstrItinClass iis, RegisterClass target,
943                  PatFrag opnode> {
944  def i12 : T2Ii12<(outs), (ins target:$Rt, t2addrmode_imm12:$addr), iii,
945                   opc, ".w\t$Rt, $addr",
946                   [(opnode target:$Rt, t2addrmode_imm12:$addr)]> {
947    let Inst{31-27} = 0b11111;
948    let Inst{26-23} = 0b0001;
949    let Inst{22-21} = opcod;
950    let Inst{20} = 0; // !load
951
952    bits<4> Rt;
953    let Inst{15-12} = Rt;
954
955    bits<17> addr;
956    let addr{12}    = 1;           // add = TRUE
957    let Inst{19-16} = addr{16-13}; // Rn
958    let Inst{23}    = addr{12};    // U
959    let Inst{11-0}  = addr{11-0};  // imm
960  }
961  def i8  : T2Ii8 <(outs), (ins target:$Rt, t2addrmode_negimm8:$addr), iii,
962                   opc, "\t$Rt, $addr",
963                   [(opnode target:$Rt, t2addrmode_negimm8:$addr)]> {
964    let Inst{31-27} = 0b11111;
965    let Inst{26-23} = 0b0000;
966    let Inst{22-21} = opcod;
967    let Inst{20} = 0; // !load
968    let Inst{11} = 1;
969    // Offset: index==TRUE, wback==FALSE
970    let Inst{10} = 1; // The P bit.
971    let Inst{8} = 0; // The W bit.
972
973    bits<4> Rt;
974    let Inst{15-12} = Rt;
975
976    bits<13> addr;
977    let Inst{19-16} = addr{12-9}; // Rn
978    let Inst{9}     = addr{8};    // U
979    let Inst{7-0}   = addr{7-0};  // imm
980  }
981  def s   : T2Iso <(outs), (ins target:$Rt, t2addrmode_so_reg:$addr), iis,
982                   opc, ".w\t$Rt, $addr",
983                   [(opnode target:$Rt, t2addrmode_so_reg:$addr)]> {
984    let Inst{31-27} = 0b11111;
985    let Inst{26-23} = 0b0000;
986    let Inst{22-21} = opcod;
987    let Inst{20} = 0; // !load
988    let Inst{11-6} = 0b000000;
989
990    bits<4> Rt;
991    let Inst{15-12} = Rt;
992
993    bits<10> addr;
994    let Inst{19-16}   = addr{9-6}; // Rn
995    let Inst{3-0} = addr{5-2}; // Rm
996    let Inst{5-4}   = addr{1-0}; // imm
997  }
998}
999
1000/// T2I_ext_rrot - A unary operation with two forms: one whose operand is a
1001/// register and one whose operand is a register rotated by 8/16/24.
1002class T2I_ext_rrot<bits<3> opcod, string opc, PatFrag opnode>
1003  : T2TwoReg<(outs rGPR:$Rd), (ins rGPR:$Rm, rot_imm:$rot), IIC_iEXTr,
1004             opc, ".w\t$Rd, $Rm$rot",
1005             [(set rGPR:$Rd, (opnode (rotr rGPR:$Rm, rot_imm:$rot)))]>,
1006             Requires<[IsThumb2]> {
1007   let Inst{31-27} = 0b11111;
1008   let Inst{26-23} = 0b0100;
1009   let Inst{22-20} = opcod;
1010   let Inst{19-16} = 0b1111; // Rn
1011   let Inst{15-12} = 0b1111;
1012   let Inst{7} = 1;
1013
1014   bits<2> rot;
1015   let Inst{5-4} = rot{1-0}; // rotate
1016}
1017
1018// UXTB16 - Requres T2ExtractPack, does not need the .w qualifier.
1019class T2I_ext_rrot_uxtb16<bits<3> opcod, string opc, PatFrag opnode>
1020  : T2TwoReg<(outs rGPR:$Rd), (ins rGPR:$Rm, rot_imm:$rot),
1021             IIC_iEXTr, opc, "\t$Rd, $Rm$rot",
1022            [(set rGPR:$Rd, (opnode (rotr rGPR:$Rm, rot_imm:$rot)))]>,
1023          Requires<[HasT2ExtractPack, IsThumb2]> {
1024  bits<2> rot;
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;
1030  let Inst{7} = 1;
1031  let Inst{5-4} = rot;
1032}
1033
1034// SXTB16 - Requres T2ExtractPack, does not need the .w qualifier, no pattern
1035// supported yet.
1036class T2I_ext_rrot_sxtb16<bits<3> opcod, string opc>
1037  : T2TwoReg<(outs rGPR:$Rd), (ins rGPR:$Rm, rot_imm:$rot), IIC_iEXTr,
1038             opc, "\t$Rd, $Rm$rot", []>,
1039          Requires<[IsThumb2, HasT2ExtractPack]> {
1040  bits<2> rot;
1041  let Inst{31-27} = 0b11111;
1042  let Inst{26-23} = 0b0100;
1043  let Inst{22-20} = opcod;
1044  let Inst{19-16} = 0b1111; // Rn
1045  let Inst{15-12} = 0b1111;
1046  let Inst{7} = 1;
1047  let Inst{5-4} = rot;
1048}
1049
1050/// T2I_exta_rrot - A binary operation with two forms: one whose operand is a
1051/// register and one whose operand is a register rotated by 8/16/24.
1052class T2I_exta_rrot<bits<3> opcod, string opc, PatFrag opnode>
1053  : T2ThreeReg<(outs rGPR:$Rd),
1054               (ins rGPR:$Rn, rGPR:$Rm, rot_imm:$rot),
1055               IIC_iEXTAsr, opc, "\t$Rd, $Rn, $Rm$rot",
1056             [(set rGPR:$Rd, (opnode rGPR:$Rn, (rotr rGPR:$Rm,rot_imm:$rot)))]>,
1057           Requires<[HasT2ExtractPack, IsThumb2]> {
1058  bits<2> rot;
1059  let Inst{31-27} = 0b11111;
1060  let Inst{26-23} = 0b0100;
1061  let Inst{22-20} = opcod;
1062  let Inst{15-12} = 0b1111;
1063  let Inst{7} = 1;
1064  let Inst{5-4} = rot;
1065}
1066
1067class T2I_exta_rrot_np<bits<3> opcod, string opc>
1068  : T2ThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm,rot_imm:$rot),
1069               IIC_iEXTAsr, opc, "\t$Rd, $Rn, $Rm$rot", []> {
1070  bits<2> rot;
1071  let Inst{31-27} = 0b11111;
1072  let Inst{26-23} = 0b0100;
1073  let Inst{22-20} = opcod;
1074  let Inst{15-12} = 0b1111;
1075  let Inst{7} = 1;
1076  let Inst{5-4} = rot;
1077}
1078
1079//===----------------------------------------------------------------------===//
1080// Instructions
1081//===----------------------------------------------------------------------===//
1082
1083//===----------------------------------------------------------------------===//
1084//  Miscellaneous Instructions.
1085//
1086
1087class T2PCOneRegImm<dag oops, dag iops, InstrItinClass itin,
1088           string asm, list<dag> pattern>
1089  : T2XI<oops, iops, itin, asm, pattern> {
1090  bits<4> Rd;
1091  bits<12> label;
1092
1093  let Inst{11-8}  = Rd;
1094  let Inst{26}    = label{11};
1095  let Inst{14-12} = label{10-8};
1096  let Inst{7-0}   = label{7-0};
1097}
1098
1099// LEApcrel - Load a pc-relative address into a register without offending the
1100// assembler.
1101def t2ADR : T2PCOneRegImm<(outs rGPR:$Rd),
1102              (ins t2adrlabel:$addr, pred:$p),
1103              IIC_iALUi, "adr{$p}.w\t$Rd, $addr", []> {
1104  let Inst{31-27} = 0b11110;
1105  let Inst{25-24} = 0b10;
1106  // Inst{23:21} = '11' (add = FALSE) or '00' (add = TRUE)
1107  let Inst{22} = 0;
1108  let Inst{20} = 0;
1109  let Inst{19-16} = 0b1111; // Rn
1110  let Inst{15} = 0;
1111
1112  bits<4> Rd;
1113  bits<13> addr;
1114  let Inst{11-8} = Rd;
1115  let Inst{23}    = addr{12};
1116  let Inst{21}    = addr{12};
1117  let Inst{26}    = addr{11};
1118  let Inst{14-12} = addr{10-8};
1119  let Inst{7-0}   = addr{7-0};
1120
1121  let DecoderMethod = "DecodeT2Adr";
1122}
1123
1124let neverHasSideEffects = 1, isReMaterializable = 1 in
1125def t2LEApcrel   : t2PseudoInst<(outs rGPR:$Rd), (ins i32imm:$label, pred:$p),
1126                                4, IIC_iALUi, []>;
1127def t2LEApcrelJT : t2PseudoInst<(outs rGPR:$Rd),
1128                                (ins i32imm:$label, nohash_imm:$id, pred:$p),
1129                                4, IIC_iALUi,
1130                                []>;
1131
1132
1133//===----------------------------------------------------------------------===//
1134//  Load / store Instructions.
1135//
1136
1137// Load
1138let canFoldAsLoad = 1, isReMaterializable = 1  in
1139defm t2LDR   : T2I_ld<0, 0b10, "ldr", IIC_iLoad_i, IIC_iLoad_si, GPR,
1140                      UnOpFrag<(load node:$Src)>>;
1141
1142// Loads with zero extension
1143defm t2LDRH  : T2I_ld<0, 0b01, "ldrh", IIC_iLoad_bh_i, IIC_iLoad_bh_si,
1144                      rGPR, UnOpFrag<(zextloadi16 node:$Src)>>;
1145defm t2LDRB  : T2I_ld<0, 0b00, "ldrb", IIC_iLoad_bh_i, IIC_iLoad_bh_si,
1146                      rGPR, UnOpFrag<(zextloadi8  node:$Src)>>;
1147
1148// Loads with sign extension
1149defm t2LDRSH : T2I_ld<1, 0b01, "ldrsh", IIC_iLoad_bh_i, IIC_iLoad_bh_si,
1150                      rGPR, UnOpFrag<(sextloadi16 node:$Src)>>;
1151defm t2LDRSB : T2I_ld<1, 0b00, "ldrsb", IIC_iLoad_bh_i, IIC_iLoad_bh_si,
1152                      rGPR, UnOpFrag<(sextloadi8  node:$Src)>>;
1153
1154let mayLoad = 1, neverHasSideEffects = 1, hasExtraDefRegAllocReq = 1 in {
1155// Load doubleword
1156def t2LDRDi8  : T2Ii8s4<1, 0, 1, (outs rGPR:$Rt, rGPR:$Rt2),
1157                        (ins t2addrmode_imm8s4:$addr),
1158                        IIC_iLoad_d_i, "ldrd", "\t$Rt, $Rt2, $addr", "", []>;
1159} // mayLoad = 1, neverHasSideEffects = 1, hasExtraDefRegAllocReq = 1
1160
1161// zextload i1 -> zextload i8
1162def : T2Pat<(zextloadi1 t2addrmode_imm12:$addr),
1163            (t2LDRBi12  t2addrmode_imm12:$addr)>;
1164def : T2Pat<(zextloadi1 t2addrmode_negimm8:$addr),
1165            (t2LDRBi8   t2addrmode_negimm8:$addr)>;
1166def : T2Pat<(zextloadi1 t2addrmode_so_reg:$addr),
1167            (t2LDRBs    t2addrmode_so_reg:$addr)>;
1168def : T2Pat<(zextloadi1 (ARMWrapper tconstpool:$addr)),
1169            (t2LDRBpci  tconstpool:$addr)>;
1170
1171// extload -> zextload
1172// FIXME: Reduce the number of patterns by legalizing extload to zextload
1173// earlier?
1174def : T2Pat<(extloadi1  t2addrmode_imm12:$addr),
1175            (t2LDRBi12  t2addrmode_imm12:$addr)>;
1176def : T2Pat<(extloadi1  t2addrmode_negimm8:$addr),
1177            (t2LDRBi8   t2addrmode_negimm8:$addr)>;
1178def : T2Pat<(extloadi1  t2addrmode_so_reg:$addr),
1179            (t2LDRBs    t2addrmode_so_reg:$addr)>;
1180def : T2Pat<(extloadi1  (ARMWrapper tconstpool:$addr)),
1181            (t2LDRBpci  tconstpool:$addr)>;
1182
1183def : T2Pat<(extloadi8  t2addrmode_imm12:$addr),
1184            (t2LDRBi12  t2addrmode_imm12:$addr)>;
1185def : T2Pat<(extloadi8  t2addrmode_negimm8:$addr),
1186            (t2LDRBi8   t2addrmode_negimm8:$addr)>;
1187def : T2Pat<(extloadi8  t2addrmode_so_reg:$addr),
1188            (t2LDRBs    t2addrmode_so_reg:$addr)>;
1189def : T2Pat<(extloadi8  (ARMWrapper tconstpool:$addr)),
1190            (t2LDRBpci  tconstpool:$addr)>;
1191
1192def : T2Pat<(extloadi16 t2addrmode_imm12:$addr),
1193            (t2LDRHi12  t2addrmode_imm12:$addr)>;
1194def : T2Pat<(extloadi16 t2addrmode_negimm8:$addr),
1195            (t2LDRHi8   t2addrmode_negimm8:$addr)>;
1196def : T2Pat<(extloadi16 t2addrmode_so_reg:$addr),
1197            (t2LDRHs    t2addrmode_so_reg:$addr)>;
1198def : T2Pat<(extloadi16 (ARMWrapper tconstpool:$addr)),
1199            (t2LDRHpci  tconstpool:$addr)>;
1200
1201// FIXME: The destination register of the loads and stores can't be PC, but
1202//        can be SP. We need another regclass (similar to rGPR) to represent
1203//        that. Not a pressing issue since these are selected manually,
1204//        not via pattern.
1205
1206// Indexed loads
1207
1208let mayLoad = 1, neverHasSideEffects = 1 in {
1209def t2LDR_PRE  : T2Ipreldst<0, 0b10, 1, 1, (outs GPR:$Rt, GPR:$Rn_wb),
1210                            (ins t2addrmode_imm8:$addr),
1211                            AddrModeT2_i8, IndexModePre, IIC_iLoad_iu,
1212                            "ldr", "\t$Rt, $addr!", "$addr.base = $Rn_wb",
1213                            []> {
1214  let AsmMatchConverter = "cvtLdWriteBackRegT2AddrModeImm8";
1215}
1216
1217def t2LDR_POST : T2Ipostldst<0, 0b10, 1, 0, (outs GPR:$Rt, GPR:$Rn_wb),
1218                          (ins addr_offset_none:$Rn, t2am_imm8_offset:$offset),
1219                          AddrModeT2_i8, IndexModePost, IIC_iLoad_iu,
1220                          "ldr", "\t$Rt, $Rn$offset", "$Rn = $Rn_wb", []>;
1221
1222def t2LDRB_PRE : T2Ipreldst<0, 0b00, 1, 1, (outs GPR:$Rt, GPR:$Rn_wb),
1223                            (ins t2addrmode_imm8:$addr),
1224                            AddrModeT2_i8, IndexModePre, IIC_iLoad_bh_iu,
1225                            "ldrb", "\t$Rt, $addr!", "$addr.base = $Rn_wb",
1226                            []> {
1227  let AsmMatchConverter = "cvtLdWriteBackRegT2AddrModeImm8";
1228}
1229def t2LDRB_POST : T2Ipostldst<0, 0b00, 1, 0, (outs GPR:$Rt, GPR:$Rn_wb),
1230                          (ins addr_offset_none:$Rn, t2am_imm8_offset:$offset),
1231                          AddrModeT2_i8, IndexModePost, IIC_iLoad_bh_iu,
1232                          "ldrb", "\t$Rt, $Rn$offset", "$Rn = $Rn_wb", []>;
1233
1234def t2LDRH_PRE : T2Ipreldst<0, 0b01, 1, 1, (outs GPR:$Rt, GPR:$Rn_wb),
1235                            (ins t2addrmode_imm8:$addr),
1236                            AddrModeT2_i8, IndexModePre, IIC_iLoad_bh_iu,
1237                            "ldrh", "\t$Rt, $addr!", "$addr.base = $Rn_wb",
1238                            []> {
1239  let AsmMatchConverter = "cvtLdWriteBackRegT2AddrModeImm8";
1240}
1241def t2LDRH_POST : T2Ipostldst<0, 0b01, 1, 0, (outs GPR:$Rt, GPR:$Rn_wb),
1242                          (ins addr_offset_none:$Rn, t2am_imm8_offset:$offset),
1243                          AddrModeT2_i8, IndexModePost, IIC_iLoad_bh_iu,
1244                          "ldrh", "\t$Rt, $Rn$offset", "$Rn = $Rn_wb", []>;
1245
1246def t2LDRSB_PRE : T2Ipreldst<1, 0b00, 1, 1, (outs GPR:$Rt, GPR:$Rn_wb),
1247                            (ins t2addrmode_imm8:$addr),
1248                            AddrModeT2_i8, IndexModePre, IIC_iLoad_bh_iu,
1249                            "ldrsb", "\t$Rt, $addr!", "$addr.base = $Rn_wb",
1250                            []> {
1251  let AsmMatchConverter = "cvtLdWriteBackRegT2AddrModeImm8";
1252}
1253def t2LDRSB_POST : T2Ipostldst<1, 0b00, 1, 0, (outs GPR:$Rt, GPR:$Rn_wb),
1254                          (ins addr_offset_none:$Rn, t2am_imm8_offset:$offset),
1255                          AddrModeT2_i8, IndexModePost, IIC_iLoad_bh_iu,
1256                          "ldrsb", "\t$Rt, $Rn$offset", "$Rn = $Rn_wb", []>;
1257
1258def t2LDRSH_PRE : T2Ipreldst<1, 0b01, 1, 1, (outs GPR:$Rt, GPR:$Rn_wb),
1259                            (ins t2addrmode_imm8:$addr),
1260                            AddrModeT2_i8, IndexModePre, IIC_iLoad_bh_iu,
1261                            "ldrsh", "\t$Rt, $addr!", "$addr.base = $Rn_wb",
1262                            []> {
1263  let AsmMatchConverter = "cvtLdWriteBackRegT2AddrModeImm8";
1264}
1265def t2LDRSH_POST : T2Ipostldst<1, 0b01, 1, 0, (outs GPR:$Rt, GPR:$Rn_wb),
1266                          (ins addr_offset_none:$Rn, t2am_imm8_offset:$offset),
1267                          AddrModeT2_i8, IndexModePost, IIC_iLoad_bh_iu,
1268                          "ldrsh", "\t$Rt, $Rn$offset", "$Rn = $Rn_wb", []>;
1269} // mayLoad = 1, neverHasSideEffects = 1
1270
1271// LDRT, LDRBT, LDRHT, LDRSBT, LDRSHT all have offset mode (PUW=0b110).
1272// Ref: A8.6.57 LDR (immediate, Thumb) Encoding T4
1273class T2IldT<bit signed, bits<2> type, string opc, InstrItinClass ii>
1274  : T2Ii8<(outs rGPR:$Rt), (ins t2addrmode_posimm8:$addr), ii, opc,
1275          "\t$Rt, $addr", []> {
1276  bits<4> Rt;
1277  bits<13> addr;
1278  let Inst{31-27} = 0b11111;
1279  let Inst{26-25} = 0b00;
1280  let Inst{24} = signed;
1281  let Inst{23} = 0;
1282  let Inst{22-21} = type;
1283  let Inst{20} = 1; // load
1284  let Inst{19-16} = addr{12-9};
1285  let Inst{15-12} = Rt;
1286  let Inst{11} = 1;
1287  let Inst{10-8} = 0b110; // PUW.
1288  let Inst{7-0} = addr{7-0};
1289}
1290
1291def t2LDRT   : T2IldT<0, 0b10, "ldrt", IIC_iLoad_i>;
1292def t2LDRBT  : T2IldT<0, 0b00, "ldrbt", IIC_iLoad_bh_i>;
1293def t2LDRHT  : T2IldT<0, 0b01, "ldrht", IIC_iLoad_bh_i>;
1294def t2LDRSBT : T2IldT<1, 0b00, "ldrsbt", IIC_iLoad_bh_i>;
1295def t2LDRSHT : T2IldT<1, 0b01, "ldrsht", IIC_iLoad_bh_i>;
1296
1297// Store
1298defm t2STR :T2I_st<0b10,"str", IIC_iStore_i, IIC_iStore_si, GPR,
1299                   BinOpFrag<(store node:$LHS, node:$RHS)>>;
1300defm t2STRB:T2I_st<0b00,"strb", IIC_iStore_bh_i, IIC_iStore_bh_si,
1301                   rGPR, BinOpFrag<(truncstorei8 node:$LHS, node:$RHS)>>;
1302defm t2STRH:T2I_st<0b01,"strh", IIC_iStore_bh_i, IIC_iStore_bh_si,
1303                   rGPR, BinOpFrag<(truncstorei16 node:$LHS, node:$RHS)>>;
1304
1305// Store doubleword
1306let mayLoad = 1, neverHasSideEffects = 1, hasExtraSrcRegAllocReq = 1 in
1307def t2STRDi8 : T2Ii8s4<1, 0, 0, (outs),
1308                       (ins GPR:$Rt, GPR:$Rt2, t2addrmode_imm8s4:$addr),
1309               IIC_iStore_d_r, "strd", "\t$Rt, $Rt2, $addr", "", []>;
1310
1311// Indexed stores
1312def t2STR_PRE  : T2Ipreldst<0, 0b10, 0, 1, (outs GPRnopc:$Rn_wb),
1313                            (ins rGPR:$Rt, t2addrmode_imm8:$addr),
1314                            AddrModeT2_i8, IndexModePre, IIC_iStore_iu,
1315                            "str", "\t$Rt, $addr!",
1316                            "$addr.base = $Rn_wb,@earlyclobber $Rn_wb", []> {
1317  let AsmMatchConverter = "cvtStWriteBackRegT2AddrModeImm8";
1318}
1319def t2STRH_PRE  : T2Ipreldst<0, 0b01, 0, 1, (outs GPRnopc:$Rn_wb),
1320                            (ins rGPR:$Rt, t2addrmode_imm8:$addr),
1321                            AddrModeT2_i8, IndexModePre, IIC_iStore_iu,
1322                        "strh", "\t$Rt, $addr!",
1323                        "$addr.base = $Rn_wb,@earlyclobber $Rn_wb", []> {
1324  let AsmMatchConverter = "cvtStWriteBackRegT2AddrModeImm8";
1325}
1326
1327def t2STRB_PRE  : T2Ipreldst<0, 0b00, 0, 1, (outs GPRnopc:$Rn_wb),
1328                            (ins rGPR:$Rt, t2addrmode_imm8:$addr),
1329                            AddrModeT2_i8, IndexModePre, IIC_iStore_bh_iu,
1330                        "strb", "\t$Rt, $addr!",
1331                        "$addr.base = $Rn_wb,@earlyclobber $Rn_wb", []> {
1332  let AsmMatchConverter = "cvtStWriteBackRegT2AddrModeImm8";
1333}
1334
1335def t2STR_POST : T2Ipostldst<0, 0b10, 0, 0, (outs GPRnopc:$Rn_wb),
1336                            (ins rGPR:$Rt, addr_offset_none:$Rn,
1337                                 t2am_imm8_offset:$offset),
1338                            AddrModeT2_i8, IndexModePost, IIC_iStore_iu,
1339                          "str", "\t$Rt, $Rn$offset",
1340                          "$Rn = $Rn_wb,@earlyclobber $Rn_wb",
1341             [(set GPRnopc:$Rn_wb,
1342                  (post_store rGPR:$Rt, addr_offset_none:$Rn,
1343                              t2am_imm8_offset:$offset))]>;
1344
1345def t2STRH_POST : T2Ipostldst<0, 0b01, 0, 0, (outs GPRnopc:$Rn_wb),
1346                            (ins rGPR:$Rt, addr_offset_none:$Rn,
1347                                 t2am_imm8_offset:$offset),
1348                            AddrModeT2_i8, IndexModePost, IIC_iStore_bh_iu,
1349                         "strh", "\t$Rt, $Rn$offset",
1350                         "$Rn = $Rn_wb,@earlyclobber $Rn_wb",
1351       [(set GPRnopc:$Rn_wb,
1352             (post_truncsti16 rGPR:$Rt, addr_offset_none:$Rn,
1353                              t2am_imm8_offset:$offset))]>;
1354
1355def t2STRB_POST : T2Ipostldst<0, 0b00, 0, 0, (outs GPRnopc:$Rn_wb),
1356                            (ins rGPR:$Rt, addr_offset_none:$Rn,
1357                                 t2am_imm8_offset:$offset),
1358                            AddrModeT2_i8, IndexModePost, IIC_iStore_bh_iu,
1359                         "strb", "\t$Rt, $Rn$offset",
1360                         "$Rn = $Rn_wb,@earlyclobber $Rn_wb",
1361        [(set GPRnopc:$Rn_wb,
1362              (post_truncsti8 rGPR:$Rt, addr_offset_none:$Rn,
1363                              t2am_imm8_offset:$offset))]>;
1364
1365// Pseudo-instructions for pattern matching the pre-indexed stores. We can't
1366// put the patterns on the instruction definitions directly as ISel wants
1367// the address base and offset to be separate operands, not a single
1368// complex operand like we represent the instructions themselves. The
1369// pseudos map between the two.
1370let usesCustomInserter = 1,
1371    Constraints = "$Rn = $Rn_wb,@earlyclobber $Rn_wb" in {
1372def t2STR_preidx: t2PseudoInst<(outs GPRnopc:$Rn_wb),
1373               (ins rGPR:$Rt, GPRnopc:$Rn, t2am_imm8_offset:$offset, pred:$p),
1374               4, IIC_iStore_ru,
1375      [(set GPRnopc:$Rn_wb,
1376            (pre_store rGPR:$Rt, GPRnopc:$Rn, t2am_imm8_offset:$offset))]>;
1377def t2STRB_preidx: t2PseudoInst<(outs GPRnopc:$Rn_wb),
1378               (ins rGPR:$Rt, GPRnopc:$Rn, t2am_imm8_offset:$offset, pred:$p),
1379               4, IIC_iStore_ru,
1380      [(set GPRnopc:$Rn_wb,
1381            (pre_truncsti8 rGPR:$Rt, GPRnopc:$Rn, t2am_imm8_offset:$offset))]>;
1382def t2STRH_preidx: t2PseudoInst<(outs GPRnopc:$Rn_wb),
1383               (ins rGPR:$Rt, GPRnopc:$Rn, t2am_imm8_offset:$offset, pred:$p),
1384               4, IIC_iStore_ru,
1385      [(set GPRnopc:$Rn_wb,
1386            (pre_truncsti16 rGPR:$Rt, GPRnopc:$Rn, t2am_imm8_offset:$offset))]>;
1387}
1388
1389
1390// STRT, STRBT, STRHT all have offset mode (PUW=0b110) and are for disassembly
1391// only.
1392// Ref: A8.6.193 STR (immediate, Thumb) Encoding T4
1393class T2IstT<bits<2> type, string opc, InstrItinClass ii>
1394  : T2Ii8<(outs rGPR:$Rt), (ins t2addrmode_imm8:$addr), ii, opc,
1395          "\t$Rt, $addr", []> {
1396  let Inst{31-27} = 0b11111;
1397  let Inst{26-25} = 0b00;
1398  let Inst{24} = 0; // not signed
1399  let Inst{23} = 0;
1400  let Inst{22-21} = type;
1401  let Inst{20} = 0; // store
1402  let Inst{11} = 1;
1403  let Inst{10-8} = 0b110; // PUW
1404
1405  bits<4> Rt;
1406  bits<13> addr;
1407  let Inst{15-12} = Rt;
1408  let Inst{19-16} = addr{12-9};
1409  let Inst{7-0}   = addr{7-0};
1410}
1411
1412def t2STRT   : T2IstT<0b10, "strt", IIC_iStore_i>;
1413def t2STRBT  : T2IstT<0b00, "strbt", IIC_iStore_bh_i>;
1414def t2STRHT  : T2IstT<0b01, "strht", IIC_iStore_bh_i>;
1415
1416// ldrd / strd pre / post variants
1417// For disassembly only.
1418
1419def t2LDRD_PRE  : T2Ii8s4<1, 1, 1, (outs rGPR:$Rt, rGPR:$Rt2, GPR:$wb),
1420                 (ins t2addrmode_imm8s4:$addr), IIC_iLoad_d_ru,
1421                 "ldrd", "\t$Rt, $Rt2, $addr!", "$addr.base = $wb", []> {
1422  let AsmMatchConverter = "cvtT2LdrdPre";
1423  let DecoderMethod = "DecodeT2LDRDPreInstruction";
1424}
1425
1426def t2LDRD_POST : T2Ii8s4post<0, 1, 1, (outs rGPR:$Rt, rGPR:$Rt2, GPR:$wb),
1427                 (ins addr_offset_none:$addr, t2am_imm8s4_offset:$imm),
1428                 IIC_iLoad_d_ru, "ldrd", "\t$Rt, $Rt2, $addr$imm",
1429                 "$addr.base = $wb", []>;
1430
1431def t2STRD_PRE  : T2Ii8s4<1, 1, 0, (outs GPR:$wb),
1432                 (ins rGPR:$Rt, rGPR:$Rt2, t2addrmode_imm8s4:$addr),
1433                 IIC_iStore_d_ru, "strd", "\t$Rt, $Rt2, $addr!",
1434                 "$addr.base = $wb", []> {
1435  let AsmMatchConverter = "cvtT2StrdPre";
1436  let DecoderMethod = "DecodeT2STRDPreInstruction";
1437}
1438
1439def t2STRD_POST : T2Ii8s4post<0, 1, 0, (outs GPR:$wb),
1440                 (ins rGPR:$Rt, rGPR:$Rt2, addr_offset_none:$addr,
1441                      t2am_imm8s4_offset:$imm),
1442                 IIC_iStore_d_ru, "strd", "\t$Rt, $Rt2, $addr$imm",
1443                 "$addr.base = $wb", []>;
1444
1445// T2Ipl (Preload Data/Instruction) signals the memory system of possible future
1446// data/instruction access.  These are for disassembly only.
1447// instr_write is inverted for Thumb mode: (prefetch 3) -> (preload 0),
1448// (prefetch 1) -> (preload 2),  (prefetch 2) -> (preload 1).
1449multiclass T2Ipl<bits<1> write, bits<1> instr, string opc> {
1450
1451  def i12 : T2Ii12<(outs), (ins t2addrmode_imm12:$addr), IIC_Preload, opc,
1452                "\t$addr",
1453              [(ARMPreload t2addrmode_imm12:$addr, (i32 write), (i32 instr))]> {
1454    let Inst{31-25} = 0b1111100;
1455    let Inst{24} = instr;
1456    let Inst{22} = 0;
1457    let Inst{21} = write;
1458    let Inst{20} = 1;
1459    let Inst{15-12} = 0b1111;
1460
1461    bits<17> addr;
1462    let addr{12}    = 1;           // add = TRUE
1463    let Inst{19-16} = addr{16-13}; // Rn
1464    let Inst{23}    = addr{12};    // U
1465    let Inst{11-0}  = addr{11-0};  // imm12
1466  }
1467
1468  def i8 : T2Ii8<(outs), (ins t2addrmode_negimm8:$addr), IIC_Preload, opc,
1469                "\t$addr",
1470            [(ARMPreload t2addrmode_negimm8:$addr, (i32 write), (i32 instr))]> {
1471    let Inst{31-25} = 0b1111100;
1472    let Inst{24} = instr;
1473    let Inst{23} = 0; // U = 0
1474    let Inst{22} = 0;
1475    let Inst{21} = write;
1476    let Inst{20} = 1;
1477    let Inst{15-12} = 0b1111;
1478    let Inst{11-8} = 0b1100;
1479
1480    bits<13> addr;
1481    let Inst{19-16} = addr{12-9}; // Rn
1482    let Inst{7-0}   = addr{7-0};  // imm8
1483  }
1484
1485  def s : T2Iso<(outs), (ins t2addrmode_so_reg:$addr), IIC_Preload, opc,
1486               "\t$addr",
1487             [(ARMPreload t2addrmode_so_reg:$addr, (i32 write), (i32 instr))]> {
1488    let Inst{31-25} = 0b1111100;
1489    let Inst{24} = instr;
1490    let Inst{23} = 0; // add = TRUE for T1
1491    let Inst{22} = 0;
1492    let Inst{21} = write;
1493    let Inst{20} = 1;
1494    let Inst{15-12} = 0b1111;
1495    let Inst{11-6} = 0000000;
1496
1497    bits<10> addr;
1498    let Inst{19-16} = addr{9-6}; // Rn
1499    let Inst{3-0}   = addr{5-2}; // Rm
1500    let Inst{5-4}   = addr{1-0}; // imm2
1501
1502    let DecoderMethod = "DecodeT2LoadShift";
1503  }
1504}
1505
1506defm t2PLD  : T2Ipl<0, 0, "pld">,  Requires<[IsThumb2]>;
1507defm t2PLDW : T2Ipl<1, 0, "pldw">, Requires<[IsThumb2,HasV7,HasMP]>;
1508defm t2PLI  : T2Ipl<0, 1, "pli">,  Requires<[IsThumb2,HasV7]>;
1509
1510//===----------------------------------------------------------------------===//
1511//  Load / store multiple Instructions.
1512//
1513
1514multiclass thumb2_ld_mult<string asm, InstrItinClass itin,
1515                            InstrItinClass itin_upd, bit L_bit> {
1516  def IA :
1517    T2XI<(outs), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops),
1518         itin, !strconcat(asm, "${p}.w\t$Rn, $regs"), []> {
1519    bits<4>  Rn;
1520    bits<16> regs;
1521
1522    let Inst{31-27} = 0b11101;
1523    let Inst{26-25} = 0b00;
1524    let Inst{24-23} = 0b01;     // Increment After
1525    let Inst{22}    = 0;
1526    let Inst{21}    = 0;        // No writeback
1527    let Inst{20}    = L_bit;
1528    let Inst{19-16} = Rn;
1529    let Inst{15}    = 0;
1530    let Inst{14-0}  = regs{14-0};
1531  }
1532  def IA_UPD :
1533    T2XIt<(outs GPR:$wb), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops),
1534          itin_upd, !strconcat(asm, "${p}.w\t$Rn!, $regs"), "$Rn = $wb", []> {
1535    bits<4>  Rn;
1536    bits<16> regs;
1537
1538    let Inst{31-27} = 0b11101;
1539    let Inst{26-25} = 0b00;
1540    let Inst{24-23} = 0b01;     // Increment After
1541    let Inst{22}    = 0;
1542    let Inst{21}    = 1;        // Writeback
1543    let Inst{20}    = L_bit;
1544    let Inst{19-16} = Rn;
1545    let Inst{15}    = 0;
1546    let Inst{14-0}  = regs{14-0};
1547  }
1548  def DB :
1549    T2XI<(outs), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops),
1550         itin, !strconcat(asm, "db${p}\t$Rn, $regs"), []> {
1551    bits<4>  Rn;
1552    bits<16> regs;
1553
1554    let Inst{31-27} = 0b11101;
1555    let Inst{26-25} = 0b00;
1556    let Inst{24-23} = 0b10;     // Decrement Before
1557    let Inst{22}    = 0;
1558    let Inst{21}    = 0;        // No writeback
1559    let Inst{20}    = L_bit;
1560    let Inst{19-16} = Rn;
1561    let Inst{15}    = 0;
1562    let Inst{14-0}  = regs{14-0};
1563  }
1564  def DB_UPD :
1565    T2XIt<(outs GPR:$wb), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops),
1566          itin_upd, !strconcat(asm, "db${p}\t$Rn!, $regs"), "$Rn = $wb", []> {
1567    bits<4>  Rn;
1568    bits<16> regs;
1569
1570    let Inst{31-27} = 0b11101;
1571    let Inst{26-25} = 0b00;
1572    let Inst{24-23} = 0b10;     // Decrement Before
1573    let Inst{22}    = 0;
1574    let Inst{21}    = 1;        // Writeback
1575    let Inst{20}    = L_bit;
1576    let Inst{19-16} = Rn;
1577    let Inst{15}    = 0;
1578    let Inst{14-0}  = regs{14-0};
1579  }
1580}
1581
1582let neverHasSideEffects = 1 in {
1583
1584let mayLoad = 1, hasExtraDefRegAllocReq = 1 in
1585defm t2LDM : thumb2_ld_mult<"ldm", IIC_iLoad_m, IIC_iLoad_mu, 1>;
1586
1587multiclass thumb2_st_mult<string asm, InstrItinClass itin,
1588                            InstrItinClass itin_upd, bit L_bit> {
1589  def IA :
1590    T2XI<(outs), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops),
1591         itin, !strconcat(asm, "${p}.w\t$Rn, $regs"), []> {
1592    bits<4>  Rn;
1593    bits<16> regs;
1594
1595    let Inst{31-27} = 0b11101;
1596    let Inst{26-25} = 0b00;
1597    let Inst{24-23} = 0b01;     // Increment After
1598    let Inst{22}    = 0;
1599    let Inst{21}    = 0;        // No writeback
1600    let Inst{20}    = L_bit;
1601    let Inst{19-16} = Rn;
1602    let Inst{15}    = 0;
1603    let Inst{14}    = regs{14};
1604    let Inst{13}    = 0;
1605    let Inst{12-0}  = regs{12-0};
1606  }
1607  def IA_UPD :
1608    T2XIt<(outs GPR:$wb), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops),
1609          itin_upd, !strconcat(asm, "${p}.w\t$Rn!, $regs"), "$Rn = $wb", []> {
1610    bits<4>  Rn;
1611    bits<16> regs;
1612
1613    let Inst{31-27} = 0b11101;
1614    let Inst{26-25} = 0b00;
1615    let Inst{24-23} = 0b01;     // Increment After
1616    let Inst{22}    = 0;
1617    let Inst{21}    = 1;        // Writeback
1618    let Inst{20}    = L_bit;
1619    let Inst{19-16} = Rn;
1620    let Inst{15}    = 0;
1621    let Inst{14}    = regs{14};
1622    let Inst{13}    = 0;
1623    let Inst{12-0}  = regs{12-0};
1624  }
1625  def DB :
1626    T2XI<(outs), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops),
1627         itin, !strconcat(asm, "db${p}\t$Rn, $regs"), []> {
1628    bits<4>  Rn;
1629    bits<16> regs;
1630
1631    let Inst{31-27} = 0b11101;
1632    let Inst{26-25} = 0b00;
1633    let Inst{24-23} = 0b10;     // Decrement Before
1634    let Inst{22}    = 0;
1635    let Inst{21}    = 0;        // No writeback
1636    let Inst{20}    = L_bit;
1637    let Inst{19-16} = Rn;
1638    let Inst{15}    = 0;
1639    let Inst{14}    = regs{14};
1640    let Inst{13}    = 0;
1641    let Inst{12-0}  = regs{12-0};
1642  }
1643  def DB_UPD :
1644    T2XIt<(outs GPR:$wb), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops),
1645          itin_upd, !strconcat(asm, "db${p}\t$Rn!, $regs"), "$Rn = $wb", []> {
1646    bits<4>  Rn;
1647    bits<16> regs;
1648
1649    let Inst{31-27} = 0b11101;
1650    let Inst{26-25} = 0b00;
1651    let Inst{24-23} = 0b10;     // Decrement Before
1652    let Inst{22}    = 0;
1653    let Inst{21}    = 1;        // Writeback
1654    let Inst{20}    = L_bit;
1655    let Inst{19-16} = Rn;
1656    let Inst{15}    = 0;
1657    let Inst{14}    = regs{14};
1658    let Inst{13}    = 0;
1659    let Inst{12-0}  = regs{12-0};
1660  }
1661}
1662
1663
1664let mayStore = 1, hasExtraSrcRegAllocReq = 1 in
1665defm t2STM : thumb2_st_mult<"stm", IIC_iStore_m, IIC_iStore_mu, 0>;
1666
1667} // neverHasSideEffects
1668
1669
1670//===----------------------------------------------------------------------===//
1671//  Move Instructions.
1672//
1673
1674let neverHasSideEffects = 1 in
1675def t2MOVr : T2sTwoReg<(outs GPRnopc:$Rd), (ins GPR:$Rm), IIC_iMOVr,
1676                   "mov", ".w\t$Rd, $Rm", []> {
1677  let Inst{31-27} = 0b11101;
1678  let Inst{26-25} = 0b01;
1679  let Inst{24-21} = 0b0010;
1680  let Inst{19-16} = 0b1111; // Rn
1681  let Inst{14-12} = 0b000;
1682  let Inst{7-4} = 0b0000;
1683}
1684def : t2InstAlias<"movs${p}.w $Rd, $Rm", (t2MOVr GPRnopc:$Rd, GPR:$Rm,
1685                                                 pred:$p, CPSR)>;
1686def : t2InstAlias<"movs${p} $Rd, $Rm", (t2MOVr GPRnopc:$Rd, GPR:$Rm,
1687                                               pred:$p, CPSR)>;
1688
1689// AddedComplexity to ensure isel tries t2MOVi before t2MOVi16.
1690let isReMaterializable = 1, isAsCheapAsAMove = 1, isMoveImm = 1,
1691    AddedComplexity = 1 in
1692def t2MOVi : T2sOneRegImm<(outs rGPR:$Rd), (ins t2_so_imm:$imm), IIC_iMOVi,
1693                   "mov", ".w\t$Rd, $imm",
1694                   [(set rGPR:$Rd, t2_so_imm:$imm)]> {
1695  let Inst{31-27} = 0b11110;
1696  let Inst{25} = 0;
1697  let Inst{24-21} = 0b0010;
1698  let Inst{19-16} = 0b1111; // Rn
1699  let Inst{15} = 0;
1700}
1701
1702// cc_out is handled as part of the explicit mnemonic in the parser for 'mov'.
1703// Use aliases to get that to play nice here.
1704def : t2InstAlias<"movs${p}.w $Rd, $imm", (t2MOVi rGPR:$Rd, t2_so_imm:$imm,
1705                                                pred:$p, CPSR)>;
1706def : t2InstAlias<"movs${p} $Rd, $imm", (t2MOVi rGPR:$Rd, t2_so_imm:$imm,
1707                                                pred:$p, CPSR)>;
1708
1709def : t2InstAlias<"mov${p}.w $Rd, $imm", (t2MOVi rGPR:$Rd, t2_so_imm:$imm,
1710                                                 pred:$p, zero_reg)>;
1711def : t2InstAlias<"mov${p} $Rd, $imm", (t2MOVi rGPR:$Rd, t2_so_imm:$imm,
1712                                               pred:$p, zero_reg)>;
1713
1714let isReMaterializable = 1, isAsCheapAsAMove = 1, isMoveImm = 1 in
1715def t2MOVi16 : T2I<(outs rGPR:$Rd), (ins imm0_65535_expr:$imm), IIC_iMOVi,
1716                   "movw", "\t$Rd, $imm",
1717                   [(set rGPR:$Rd, imm0_65535:$imm)]> {
1718  let Inst{31-27} = 0b11110;
1719  let Inst{25} = 1;
1720  let Inst{24-21} = 0b0010;
1721  let Inst{20} = 0; // The S bit.
1722  let Inst{15} = 0;
1723
1724  bits<4> Rd;
1725  bits<16> imm;
1726
1727  let Inst{11-8}  = Rd;
1728  let Inst{19-16} = imm{15-12};
1729  let Inst{26}    = imm{11};
1730  let Inst{14-12} = imm{10-8};
1731  let Inst{7-0}   = imm{7-0};
1732}
1733
1734def t2MOVi16_ga_pcrel : PseudoInst<(outs rGPR:$Rd),
1735                                (ins i32imm:$addr, pclabel:$id), IIC_iMOVi, []>;
1736
1737let Constraints = "$src = $Rd" in {
1738def t2MOVTi16 : T2I<(outs rGPR:$Rd),
1739                    (ins rGPR:$src, imm0_65535_expr:$imm), IIC_iMOVi,
1740                    "movt", "\t$Rd, $imm",
1741                    [(set rGPR:$Rd,
1742                          (or (and rGPR:$src, 0xffff), lo16AllZero:$imm))]> {
1743  let Inst{31-27} = 0b11110;
1744  let Inst{25} = 1;
1745  let Inst{24-21} = 0b0110;
1746  let Inst{20} = 0; // The S bit.
1747  let Inst{15} = 0;
1748
1749  bits<4> Rd;
1750  bits<16> imm;
1751
1752  let Inst{11-8}  = Rd;
1753  let Inst{19-16} = imm{15-12};
1754  let Inst{26}    = imm{11};
1755  let Inst{14-12} = imm{10-8};
1756  let Inst{7-0}   = imm{7-0};
1757}
1758
1759def t2MOVTi16_ga_pcrel : PseudoInst<(outs rGPR:$Rd),
1760                     (ins rGPR:$src, i32imm:$addr, pclabel:$id), IIC_iMOVi, []>;
1761} // Constraints
1762
1763def : T2Pat<(or rGPR:$src, 0xffff0000), (t2MOVTi16 rGPR:$src, 0xffff)>;
1764
1765//===----------------------------------------------------------------------===//
1766//  Extend Instructions.
1767//
1768
1769// Sign extenders
1770
1771def t2SXTB  : T2I_ext_rrot<0b100, "sxtb",
1772                              UnOpFrag<(sext_inreg node:$Src, i8)>>;
1773def t2SXTH  : T2I_ext_rrot<0b000, "sxth",
1774                              UnOpFrag<(sext_inreg node:$Src, i16)>>;
1775def t2SXTB16 : T2I_ext_rrot_sxtb16<0b010, "sxtb16">;
1776
1777def t2SXTAB : T2I_exta_rrot<0b100, "sxtab",
1778                        BinOpFrag<(add node:$LHS, (sext_inreg node:$RHS, i8))>>;
1779def t2SXTAH : T2I_exta_rrot<0b000, "sxtah",
1780                        BinOpFrag<(add node:$LHS, (sext_inreg node:$RHS,i16))>>;
1781def t2SXTAB16 : T2I_exta_rrot_np<0b010, "sxtab16">;
1782
1783// Zero extenders
1784
1785let AddedComplexity = 16 in {
1786def t2UXTB   : T2I_ext_rrot<0b101, "uxtb",
1787                               UnOpFrag<(and node:$Src, 0x000000FF)>>;
1788def t2UXTH   : T2I_ext_rrot<0b001, "uxth",
1789                               UnOpFrag<(and node:$Src, 0x0000FFFF)>>;
1790def t2UXTB16 : T2I_ext_rrot_uxtb16<0b011, "uxtb16",
1791                               UnOpFrag<(and node:$Src, 0x00FF00FF)>>;
1792
1793// FIXME: This pattern incorrectly assumes the shl operator is a rotate.
1794//        The transformation should probably be done as a combiner action
1795//        instead so we can include a check for masking back in the upper
1796//        eight bits of the source into the lower eight bits of the result.
1797//def : T2Pat<(and (shl rGPR:$Src, (i32 8)), 0xFF00FF),
1798//            (t2UXTB16 rGPR:$Src, 3)>,
1799//          Requires<[HasT2ExtractPack, IsThumb2]>;
1800def : T2Pat<(and (srl rGPR:$Src, (i32 8)), 0xFF00FF),
1801            (t2UXTB16 rGPR:$Src, 1)>,
1802        Requires<[HasT2ExtractPack, IsThumb2]>;
1803
1804def t2UXTAB : T2I_exta_rrot<0b101, "uxtab",
1805                           BinOpFrag<(add node:$LHS, (and node:$RHS, 0x00FF))>>;
1806def t2UXTAH : T2I_exta_rrot<0b001, "uxtah",
1807                           BinOpFrag<(add node:$LHS, (and node:$RHS, 0xFFFF))>>;
1808def t2UXTAB16 : T2I_exta_rrot_np<0b011, "uxtab16">;
1809}
1810
1811//===----------------------------------------------------------------------===//
1812//  Arithmetic Instructions.
1813//
1814
1815defm t2ADD  : T2I_bin_ii12rs<0b000, "add",
1816                             BinOpFrag<(add  node:$LHS, node:$RHS)>, 1>;
1817defm t2SUB  : T2I_bin_ii12rs<0b101, "sub",
1818                             BinOpFrag<(sub  node:$LHS, node:$RHS)>>;
1819
1820// ADD and SUB with 's' bit set. No 12-bit immediate (T4) variants.
1821//
1822// Currently, t2ADDS/t2SUBS are pseudo opcodes that exist only in the
1823// selection DAG. They are "lowered" to real t2ADD/t2SUB opcodes by
1824// AdjustInstrPostInstrSelection where we determine whether or not to
1825// set the "s" bit based on CPSR liveness.
1826//
1827// FIXME: Eliminate t2ADDS/t2SUBS pseudo opcodes after adding tablegen
1828// support for an optional CPSR definition that corresponds to the DAG
1829// node's second value. We can then eliminate the implicit def of CPSR.
1830defm t2ADDS : T2I_bin_s_irs <0b1000, "add",
1831                             IIC_iALUi, IIC_iALUr, IIC_iALUsi,
1832                             BinOpFrag<(ARMaddc node:$LHS, node:$RHS)>, 1>;
1833defm t2SUBS : T2I_bin_s_irs <0b1101, "sub",
1834                             IIC_iALUi, IIC_iALUr, IIC_iALUsi,
1835                             BinOpFrag<(ARMsubc node:$LHS, node:$RHS)>>;
1836
1837let hasPostISelHook = 1 in {
1838defm t2ADC  : T2I_adde_sube_irs<0b1010, "adc",
1839              BinOpWithFlagFrag<(ARMadde node:$LHS, node:$RHS, node:$FLAG)>, 1>;
1840defm t2SBC  : T2I_adde_sube_irs<0b1011, "sbc",
1841              BinOpWithFlagFrag<(ARMsube node:$LHS, node:$RHS, node:$FLAG)>>;
1842}
1843
1844// RSB
1845defm t2RSB  : T2I_rbin_irs  <0b1110, "rsb",
1846                             BinOpFrag<(sub  node:$LHS, node:$RHS)>>;
1847
1848// FIXME: Eliminate them if we can write def : Pat patterns which defines
1849// CPSR and the implicit def of CPSR is not needed.
1850defm t2RSBS : T2I_rbin_s_is <0b1110, "rsb",
1851                             BinOpFrag<(ARMsubc node:$LHS, node:$RHS)>>;
1852
1853// (sub X, imm) gets canonicalized to (add X, -imm).  Match this form.
1854// The assume-no-carry-in form uses the negation of the input since add/sub
1855// assume opposite meanings of the carry flag (i.e., carry == !borrow).
1856// See the definition of AddWithCarry() in the ARM ARM A2.2.1 for the gory
1857// details.
1858// The AddedComplexity preferences the first variant over the others since
1859// it can be shrunk to a 16-bit wide encoding, while the others cannot.
1860let AddedComplexity = 1 in
1861def : T2Pat<(add        GPR:$src, imm0_255_neg:$imm),
1862            (t2SUBri    GPR:$src, imm0_255_neg:$imm)>;
1863def : T2Pat<(add        GPR:$src, t2_so_imm_neg:$imm),
1864            (t2SUBri    GPR:$src, t2_so_imm_neg:$imm)>;
1865def : T2Pat<(add        GPR:$src, imm0_4095_neg:$imm),
1866            (t2SUBri12  GPR:$src, imm0_4095_neg:$imm)>;
1867let AddedComplexity = 1 in
1868def : T2Pat<(ARMaddc    rGPR:$src, imm0_255_neg:$imm),
1869            (t2SUBSri   rGPR:$src, imm0_255_neg:$imm)>;
1870def : T2Pat<(ARMaddc    rGPR:$src, t2_so_imm_neg:$imm),
1871            (t2SUBSri   rGPR:$src, t2_so_imm_neg:$imm)>;
1872// The with-carry-in form matches bitwise not instead of the negation.
1873// Effectively, the inverse interpretation of the carry flag already accounts
1874// for part of the negation.
1875let AddedComplexity = 1 in
1876def : T2Pat<(ARMadde    rGPR:$src, imm0_255_not:$imm, CPSR),
1877            (t2SBCri    rGPR:$src, imm0_255_not:$imm)>;
1878def : T2Pat<(ARMadde    rGPR:$src, t2_so_imm_not:$imm, CPSR),
1879            (t2SBCri    rGPR:$src, t2_so_imm_not:$imm)>;
1880
1881// Select Bytes -- for disassembly only
1882
1883def t2SEL : T2ThreeReg<(outs GPR:$Rd), (ins GPR:$Rn, GPR:$Rm),
1884                NoItinerary, "sel", "\t$Rd, $Rn, $Rm", []>,
1885          Requires<[IsThumb2, HasThumb2DSP]> {
1886  let Inst{31-27} = 0b11111;
1887  let Inst{26-24} = 0b010;
1888  let Inst{23} = 0b1;
1889  let Inst{22-20} = 0b010;
1890  let Inst{15-12} = 0b1111;
1891  let Inst{7} = 0b1;
1892  let Inst{6-4} = 0b000;
1893}
1894
1895// A6.3.13, A6.3.14, A6.3.15 Parallel addition and subtraction (signed/unsigned)
1896// And Miscellaneous operations -- for disassembly only
1897class T2I_pam<bits<3> op22_20, bits<4> op7_4, string opc,
1898              list<dag> pat = [/* For disassembly only; pattern left blank */],
1899              dag iops = (ins rGPR:$Rn, rGPR:$Rm),
1900              string asm = "\t$Rd, $Rn, $Rm">
1901  : T2I<(outs rGPR:$Rd), iops, NoItinerary, opc, asm, pat>,
1902    Requires<[IsThumb2, HasThumb2DSP]> {
1903  let Inst{31-27} = 0b11111;
1904  let Inst{26-23} = 0b0101;
1905  let Inst{22-20} = op22_20;
1906  let Inst{15-12} = 0b1111;
1907  let Inst{7-4} = op7_4;
1908
1909  bits<4> Rd;
1910  bits<4> Rn;
1911  bits<4> Rm;
1912
1913  let Inst{11-8}  = Rd;
1914  let Inst{19-16} = Rn;
1915  let Inst{3-0}   = Rm;
1916}
1917
1918// Saturating add/subtract -- for disassembly only
1919
1920def t2QADD    : T2I_pam<0b000, 0b1000, "qadd",
1921                        [(set rGPR:$Rd, (int_arm_qadd rGPR:$Rn, rGPR:$Rm))],
1922                        (ins rGPR:$Rm, rGPR:$Rn), "\t$Rd, $Rm, $Rn">;
1923def t2QADD16  : T2I_pam<0b001, 0b0001, "qadd16">;
1924def t2QADD8   : T2I_pam<0b000, 0b0001, "qadd8">;
1925def t2QASX    : T2I_pam<0b010, 0b0001, "qasx">;
1926def t2QDADD   : T2I_pam<0b000, 0b1001, "qdadd", [],
1927                        (ins rGPR:$Rm, rGPR:$Rn), "\t$Rd, $Rm, $Rn">;
1928def t2QDSUB   : T2I_pam<0b000, 0b1011, "qdsub", [],
1929                        (ins rGPR:$Rm, rGPR:$Rn), "\t$Rd, $Rm, $Rn">;
1930def t2QSAX    : T2I_pam<0b110, 0b0001, "qsax">;
1931def t2QSUB    : T2I_pam<0b000, 0b1010, "qsub",
1932                        [(set rGPR:$Rd, (int_arm_qsub rGPR:$Rn, rGPR:$Rm))],
1933                        (ins rGPR:$Rm, rGPR:$Rn), "\t$Rd, $Rm, $Rn">;
1934def t2QSUB16  : T2I_pam<0b101, 0b0001, "qsub16">;
1935def t2QSUB8   : T2I_pam<0b100, 0b0001, "qsub8">;
1936def t2UQADD16 : T2I_pam<0b001, 0b0101, "uqadd16">;
1937def t2UQADD8  : T2I_pam<0b000, 0b0101, "uqadd8">;
1938def t2UQASX   : T2I_pam<0b010, 0b0101, "uqasx">;
1939def t2UQSAX   : T2I_pam<0b110, 0b0101, "uqsax">;
1940def t2UQSUB16 : T2I_pam<0b101, 0b0101, "uqsub16">;
1941def t2UQSUB8  : T2I_pam<0b100, 0b0101, "uqsub8">;
1942
1943// Signed/Unsigned add/subtract -- for disassembly only
1944
1945def t2SASX    : T2I_pam<0b010, 0b0000, "sasx">;
1946def t2SADD16  : T2I_pam<0b001, 0b0000, "sadd16">;
1947def t2SADD8   : T2I_pam<0b000, 0b0000, "sadd8">;
1948def t2SSAX    : T2I_pam<0b110, 0b0000, "ssax">;
1949def t2SSUB16  : T2I_pam<0b101, 0b0000, "ssub16">;
1950def t2SSUB8   : T2I_pam<0b100, 0b0000, "ssub8">;
1951def t2UASX    : T2I_pam<0b010, 0b0100, "uasx">;
1952def t2UADD16  : T2I_pam<0b001, 0b0100, "uadd16">;
1953def t2UADD8   : T2I_pam<0b000, 0b0100, "uadd8">;
1954def t2USAX    : T2I_pam<0b110, 0b0100, "usax">;
1955def t2USUB16  : T2I_pam<0b101, 0b0100, "usub16">;
1956def t2USUB8   : T2I_pam<0b100, 0b0100, "usub8">;
1957
1958// Signed/Unsigned halving add/subtract -- for disassembly only
1959
1960def t2SHASX   : T2I_pam<0b010, 0b0010, "shasx">;
1961def t2SHADD16 : T2I_pam<0b001, 0b0010, "shadd16">;
1962def t2SHADD8  : T2I_pam<0b000, 0b0010, "shadd8">;
1963def t2SHSAX   : T2I_pam<0b110, 0b0010, "shsax">;
1964def t2SHSUB16 : T2I_pam<0b101, 0b0010, "shsub16">;
1965def t2SHSUB8  : T2I_pam<0b100, 0b0010, "shsub8">;
1966def t2UHASX   : T2I_pam<0b010, 0b0110, "uhasx">;
1967def t2UHADD16 : T2I_pam<0b001, 0b0110, "uhadd16">;
1968def t2UHADD8  : T2I_pam<0b000, 0b0110, "uhadd8">;
1969def t2UHSAX   : T2I_pam<0b110, 0b0110, "uhsax">;
1970def t2UHSUB16 : T2I_pam<0b101, 0b0110, "uhsub16">;
1971def t2UHSUB8  : T2I_pam<0b100, 0b0110, "uhsub8">;
1972
1973// Helper class for disassembly only
1974// A6.3.16 & A6.3.17
1975// T2Imac - Thumb2 multiply [accumulate, and absolute difference] instructions.
1976class T2ThreeReg_mac<bit long, bits<3> op22_20, bits<4> op7_4, dag oops,
1977  dag iops, InstrItinClass itin, string opc, string asm, list<dag> pattern>
1978  : T2ThreeReg<oops, iops, itin, opc, asm, pattern> {
1979  let Inst{31-27} = 0b11111;
1980  let Inst{26-24} = 0b011;
1981  let Inst{23}    = long;
1982  let Inst{22-20} = op22_20;
1983  let Inst{7-4}   = op7_4;
1984}
1985
1986class T2FourReg_mac<bit long, bits<3> op22_20, bits<4> op7_4, dag oops,
1987  dag iops, InstrItinClass itin, string opc, string asm, list<dag> pattern>
1988  : T2FourReg<oops, iops, itin, opc, asm, pattern> {
1989  let Inst{31-27} = 0b11111;
1990  let Inst{26-24} = 0b011;
1991  let Inst{23}    = long;
1992  let Inst{22-20} = op22_20;
1993  let Inst{7-4}   = op7_4;
1994}
1995
1996// Unsigned Sum of Absolute Differences [and Accumulate].
1997def t2USAD8   : T2ThreeReg_mac<0, 0b111, 0b0000, (outs rGPR:$Rd),
1998                                           (ins rGPR:$Rn, rGPR:$Rm),
1999                        NoItinerary, "usad8", "\t$Rd, $Rn, $Rm", []>,
2000          Requires<[IsThumb2, HasThumb2DSP]> {
2001  let Inst{15-12} = 0b1111;
2002}
2003def t2USADA8  : T2FourReg_mac<0, 0b111, 0b0000, (outs rGPR:$Rd),
2004                       (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), NoItinerary,
2005                        "usada8", "\t$Rd, $Rn, $Rm, $Ra", []>,
2006          Requires<[IsThumb2, HasThumb2DSP]>;
2007
2008// Signed/Unsigned saturate.
2009class T2SatI<dag oops, dag iops, InstrItinClass itin,
2010           string opc, string asm, list<dag> pattern>
2011  : T2I<oops, iops, itin, opc, asm, pattern> {
2012  bits<4> Rd;
2013  bits<4> Rn;
2014  bits<5> sat_imm;
2015  bits<7> sh;
2016
2017  let Inst{11-8}  = Rd;
2018  let Inst{19-16} = Rn;
2019  let Inst{4-0}   = sat_imm;
2020  let Inst{21}    = sh{5};
2021  let Inst{14-12} = sh{4-2};
2022  let Inst{7-6}   = sh{1-0};
2023}
2024
2025def t2SSAT: T2SatI<
2026              (outs rGPR:$Rd), (ins imm1_32:$sat_imm, rGPR:$Rn, shift_imm:$sh),
2027              NoItinerary, "ssat", "\t$Rd, $sat_imm, $Rn$sh", []> {
2028  let Inst{31-27} = 0b11110;
2029  let Inst{25-22} = 0b1100;
2030  let Inst{20} = 0;
2031  let Inst{15} = 0;
2032  let Inst{5}  = 0;
2033}
2034
2035def t2SSAT16: T2SatI<
2036                (outs rGPR:$Rd), (ins imm1_16:$sat_imm, rGPR:$Rn), NoItinerary,
2037                "ssat16", "\t$Rd, $sat_imm, $Rn", []>,
2038          Requires<[IsThumb2, HasThumb2DSP]> {
2039  let Inst{31-27} = 0b11110;
2040  let Inst{25-22} = 0b1100;
2041  let Inst{20} = 0;
2042  let Inst{15} = 0;
2043  let Inst{21} = 1;        // sh = '1'
2044  let Inst{14-12} = 0b000; // imm3 = '000'
2045  let Inst{7-6} = 0b00;    // imm2 = '00'
2046  let Inst{5-4} = 0b00;
2047}
2048
2049def t2USAT: T2SatI<
2050               (outs rGPR:$Rd), (ins imm0_31:$sat_imm, rGPR:$Rn, shift_imm:$sh),
2051                NoItinerary, "usat", "\t$Rd, $sat_imm, $Rn$sh", []> {
2052  let Inst{31-27} = 0b11110;
2053  let Inst{25-22} = 0b1110;
2054  let Inst{20} = 0;
2055  let Inst{15} = 0;
2056}
2057
2058def t2USAT16: T2SatI<(outs rGPR:$Rd), (ins imm0_15:$sat_imm, rGPR:$Rn),
2059                     NoItinerary,
2060                     "usat16", "\t$Rd, $sat_imm, $Rn", []>,
2061          Requires<[IsThumb2, HasThumb2DSP]> {
2062  let Inst{31-27} = 0b11110;
2063  let Inst{25-22} = 0b1110;
2064  let Inst{20} = 0;
2065  let Inst{15} = 0;
2066  let Inst{21} = 1;        // sh = '1'
2067  let Inst{14-12} = 0b000; // imm3 = '000'
2068  let Inst{7-6} = 0b00;    // imm2 = '00'
2069}
2070
2071def : T2Pat<(int_arm_ssat GPR:$a, imm:$pos), (t2SSAT imm:$pos, GPR:$a, 0)>;
2072def : T2Pat<(int_arm_usat GPR:$a, imm:$pos), (t2USAT imm:$pos, GPR:$a, 0)>;
2073
2074//===----------------------------------------------------------------------===//
2075//  Shift and rotate Instructions.
2076//
2077
2078defm t2LSL  : T2I_sh_ir<0b00, "lsl", imm0_31,
2079                        BinOpFrag<(shl  node:$LHS, node:$RHS)>, "t2LSL">;
2080defm t2LSR  : T2I_sh_ir<0b01, "lsr", imm_sr,
2081                        BinOpFrag<(srl  node:$LHS, node:$RHS)>, "t2LSR">;
2082defm t2ASR  : T2I_sh_ir<0b10, "asr", imm_sr,
2083                        BinOpFrag<(sra  node:$LHS, node:$RHS)>, "t2ASR">;
2084defm t2ROR  : T2I_sh_ir<0b11, "ror", imm0_31,
2085                        BinOpFrag<(rotr node:$LHS, node:$RHS)>, "t2ROR">;
2086
2087// (rotr x, (and y, 0x...1f)) ==> (ROR x, y)
2088def : Pat<(rotr rGPR:$lhs, (and rGPR:$rhs, lo5AllOne)),
2089          (t2RORrr rGPR:$lhs, rGPR:$rhs)>;
2090
2091let Uses = [CPSR] in {
2092def t2RRX : T2sTwoReg<(outs rGPR:$Rd), (ins rGPR:$Rm), IIC_iMOVsi,
2093                   "rrx", "\t$Rd, $Rm",
2094                   [(set rGPR:$Rd, (ARMrrx rGPR:$Rm))]> {
2095  let Inst{31-27} = 0b11101;
2096  let Inst{26-25} = 0b01;
2097  let Inst{24-21} = 0b0010;
2098  let Inst{19-16} = 0b1111; // Rn
2099  let Inst{14-12} = 0b000;
2100  let Inst{7-4} = 0b0011;
2101}
2102}
2103
2104let isCodeGenOnly = 1, Defs = [CPSR] in {
2105def t2MOVsrl_flag : T2TwoRegShiftImm<
2106                        (outs rGPR:$Rd), (ins rGPR:$Rm), IIC_iMOVsi,
2107                        "lsrs", ".w\t$Rd, $Rm, #1",
2108                        [(set rGPR:$Rd, (ARMsrl_flag rGPR:$Rm))]> {
2109  let Inst{31-27} = 0b11101;
2110  let Inst{26-25} = 0b01;
2111  let Inst{24-21} = 0b0010;
2112  let Inst{20} = 1; // The S bit.
2113  let Inst{19-16} = 0b1111; // Rn
2114  let Inst{5-4} = 0b01; // Shift type.
2115  // Shift amount = Inst{14-12:7-6} = 1.
2116  let Inst{14-12} = 0b000;
2117  let Inst{7-6} = 0b01;
2118}
2119def t2MOVsra_flag : T2TwoRegShiftImm<
2120                        (outs rGPR:$Rd), (ins rGPR:$Rm), IIC_iMOVsi,
2121                        "asrs", ".w\t$Rd, $Rm, #1",
2122                        [(set rGPR:$Rd, (ARMsra_flag rGPR:$Rm))]> {
2123  let Inst{31-27} = 0b11101;
2124  let Inst{26-25} = 0b01;
2125  let Inst{24-21} = 0b0010;
2126  let Inst{20} = 1; // The S bit.
2127  let Inst{19-16} = 0b1111; // Rn
2128  let Inst{5-4} = 0b10; // Shift type.
2129  // Shift amount = Inst{14-12:7-6} = 1.
2130  let Inst{14-12} = 0b000;
2131  let Inst{7-6} = 0b01;
2132}
2133}
2134
2135//===----------------------------------------------------------------------===//
2136//  Bitwise Instructions.
2137//
2138
2139defm t2AND  : T2I_bin_w_irs<0b0000, "and",
2140                            IIC_iBITi, IIC_iBITr, IIC_iBITsi,
2141                            BinOpFrag<(and node:$LHS, node:$RHS)>, "t2AND", 1>;
2142defm t2ORR  : T2I_bin_w_irs<0b0010, "orr",
2143                            IIC_iBITi, IIC_iBITr, IIC_iBITsi,
2144                            BinOpFrag<(or  node:$LHS, node:$RHS)>, "t2ORR", 1>;
2145defm t2EOR  : T2I_bin_w_irs<0b0100, "eor",
2146                            IIC_iBITi, IIC_iBITr, IIC_iBITsi,
2147                            BinOpFrag<(xor node:$LHS, node:$RHS)>, "t2EOR", 1>;
2148
2149defm t2BIC  : T2I_bin_w_irs<0b0001, "bic",
2150                            IIC_iBITi, IIC_iBITr, IIC_iBITsi,
2151                            BinOpFrag<(and node:$LHS, (not node:$RHS))>,
2152                            "t2BIC">;
2153
2154class T2BitFI<dag oops, dag iops, InstrItinClass itin,
2155              string opc, string asm, list<dag> pattern>
2156    : T2I<oops, iops, itin, opc, asm, pattern> {
2157  bits<4> Rd;
2158  bits<5> msb;
2159  bits<5> lsb;
2160
2161  let Inst{11-8}  = Rd;
2162  let Inst{4-0}   = msb{4-0};
2163  let Inst{14-12} = lsb{4-2};
2164  let Inst{7-6}   = lsb{1-0};
2165}
2166
2167class T2TwoRegBitFI<dag oops, dag iops, InstrItinClass itin,
2168              string opc, string asm, list<dag> pattern>
2169    : T2BitFI<oops, iops, itin, opc, asm, pattern> {
2170  bits<4> Rn;
2171
2172  let Inst{19-16} = Rn;
2173}
2174
2175let Constraints = "$src = $Rd" in
2176def t2BFC : T2BitFI<(outs rGPR:$Rd), (ins rGPR:$src, bf_inv_mask_imm:$imm),
2177                IIC_iUNAsi, "bfc", "\t$Rd, $imm",
2178                [(set rGPR:$Rd, (and rGPR:$src, bf_inv_mask_imm:$imm))]> {
2179  let Inst{31-27} = 0b11110;
2180  let Inst{26} = 0; // should be 0.
2181  let Inst{25} = 1;
2182  let Inst{24-20} = 0b10110;
2183  let Inst{19-16} = 0b1111; // Rn
2184  let Inst{15} = 0;
2185  let Inst{5} = 0; // should be 0.
2186
2187  bits<10> imm;
2188  let msb{4-0} = imm{9-5};
2189  let lsb{4-0} = imm{4-0};
2190}
2191
2192def t2SBFX: T2TwoRegBitFI<
2193                (outs rGPR:$Rd), (ins rGPR:$Rn, imm0_31:$lsb, imm1_32:$msb),
2194                 IIC_iUNAsi, "sbfx", "\t$Rd, $Rn, $lsb, $msb", []> {
2195  let Inst{31-27} = 0b11110;
2196  let Inst{25} = 1;
2197  let Inst{24-20} = 0b10100;
2198  let Inst{15} = 0;
2199}
2200
2201def t2UBFX: T2TwoRegBitFI<
2202                (outs rGPR:$Rd), (ins rGPR:$Rn, imm0_31:$lsb, imm1_32:$msb),
2203                 IIC_iUNAsi, "ubfx", "\t$Rd, $Rn, $lsb, $msb", []> {
2204  let Inst{31-27} = 0b11110;
2205  let Inst{25} = 1;
2206  let Inst{24-20} = 0b11100;
2207  let Inst{15} = 0;
2208}
2209
2210// A8.6.18  BFI - Bitfield insert (Encoding T1)
2211let Constraints = "$src = $Rd" in {
2212  def t2BFI : T2TwoRegBitFI<(outs rGPR:$Rd),
2213                  (ins rGPR:$src, rGPR:$Rn, bf_inv_mask_imm:$imm),
2214                  IIC_iBITi, "bfi", "\t$Rd, $Rn, $imm",
2215                  [(set rGPR:$Rd, (ARMbfi rGPR:$src, rGPR:$Rn,
2216                                   bf_inv_mask_imm:$imm))]> {
2217    let Inst{31-27} = 0b11110;
2218    let Inst{26} = 0; // should be 0.
2219    let Inst{25} = 1;
2220    let Inst{24-20} = 0b10110;
2221    let Inst{15} = 0;
2222    let Inst{5} = 0; // should be 0.
2223
2224    bits<10> imm;
2225    let msb{4-0} = imm{9-5};
2226    let lsb{4-0} = imm{4-0};
2227  }
2228}
2229
2230defm t2ORN  : T2I_bin_irs<0b0011, "orn",
2231                          IIC_iBITi, IIC_iBITr, IIC_iBITsi,
2232                          BinOpFrag<(or  node:$LHS, (not node:$RHS))>,
2233                          "t2ORN", 0, "">;
2234
2235/// T2I_un_irs - Defines a set of (op reg, {so_imm|r|so_reg}) patterns for a
2236/// unary operation that produces a value. These are predicable and can be
2237/// changed to modify CPSR.
2238multiclass T2I_un_irs<bits<4> opcod, string opc,
2239                     InstrItinClass iii, InstrItinClass iir, InstrItinClass iis,
2240                      PatFrag opnode, bit Cheap = 0, bit ReMat = 0> {
2241   // shifted imm
2242   def i : T2sOneRegImm<(outs rGPR:$Rd), (ins t2_so_imm:$imm), iii,
2243                opc, "\t$Rd, $imm",
2244                [(set rGPR:$Rd, (opnode t2_so_imm:$imm))]> {
2245     let isAsCheapAsAMove = Cheap;
2246     let isReMaterializable = ReMat;
2247     let Inst{31-27} = 0b11110;
2248     let Inst{25} = 0;
2249     let Inst{24-21} = opcod;
2250     let Inst{19-16} = 0b1111; // Rn
2251     let Inst{15} = 0;
2252   }
2253   // register
2254   def r : T2sTwoReg<(outs rGPR:$Rd), (ins rGPR:$Rm), iir,
2255                opc, ".w\t$Rd, $Rm",
2256                [(set rGPR:$Rd, (opnode rGPR:$Rm))]> {
2257     let Inst{31-27} = 0b11101;
2258     let Inst{26-25} = 0b01;
2259     let Inst{24-21} = opcod;
2260     let Inst{19-16} = 0b1111; // Rn
2261     let Inst{14-12} = 0b000; // imm3
2262     let Inst{7-6} = 0b00; // imm2
2263     let Inst{5-4} = 0b00; // type
2264   }
2265   // shifted register
2266   def s : T2sOneRegShiftedReg<(outs rGPR:$Rd), (ins t2_so_reg:$ShiftedRm), iis,
2267                opc, ".w\t$Rd, $ShiftedRm",
2268                [(set rGPR:$Rd, (opnode t2_so_reg:$ShiftedRm))]> {
2269     let Inst{31-27} = 0b11101;
2270     let Inst{26-25} = 0b01;
2271     let Inst{24-21} = opcod;
2272     let Inst{19-16} = 0b1111; // Rn
2273   }
2274}
2275
2276// Prefer over of t2EORri ra, rb, -1 because mvn has 16-bit version
2277let AddedComplexity = 1 in
2278defm t2MVN  : T2I_un_irs <0b0011, "mvn",
2279                          IIC_iMVNi, IIC_iMVNr, IIC_iMVNsi,
2280                          UnOpFrag<(not node:$Src)>, 1, 1>;
2281
2282let AddedComplexity = 1 in
2283def : T2Pat<(and     rGPR:$src, t2_so_imm_not:$imm),
2284            (t2BICri rGPR:$src, t2_so_imm_not:$imm)>;
2285
2286// FIXME: Disable this pattern on Darwin to workaround an assembler bug.
2287def : T2Pat<(or      rGPR:$src, t2_so_imm_not:$imm),
2288            (t2ORNri rGPR:$src, t2_so_imm_not:$imm)>,
2289            Requires<[IsThumb2]>;
2290
2291def : T2Pat<(t2_so_imm_not:$src),
2292            (t2MVNi t2_so_imm_not:$src)>;
2293
2294//===----------------------------------------------------------------------===//
2295//  Multiply Instructions.
2296//
2297let isCommutable = 1 in
2298def t2MUL: T2ThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iMUL32,
2299                "mul", "\t$Rd, $Rn, $Rm",
2300                [(set rGPR:$Rd, (mul rGPR:$Rn, rGPR:$Rm))]> {
2301  let Inst{31-27} = 0b11111;
2302  let Inst{26-23} = 0b0110;
2303  let Inst{22-20} = 0b000;
2304  let Inst{15-12} = 0b1111; // Ra = 0b1111 (no accumulate)
2305  let Inst{7-4} = 0b0000; // Multiply
2306}
2307
2308def t2MLA: T2FourReg<
2309                (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC32,
2310                "mla", "\t$Rd, $Rn, $Rm, $Ra",
2311                [(set rGPR:$Rd, (add (mul rGPR:$Rn, rGPR:$Rm), rGPR:$Ra))]> {
2312  let Inst{31-27} = 0b11111;
2313  let Inst{26-23} = 0b0110;
2314  let Inst{22-20} = 0b000;
2315  let Inst{7-4} = 0b0000; // Multiply
2316}
2317
2318def t2MLS: T2FourReg<
2319                (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC32,
2320                "mls", "\t$Rd, $Rn, $Rm, $Ra",
2321                [(set rGPR:$Rd, (sub rGPR:$Ra, (mul rGPR:$Rn, rGPR:$Rm)))]> {
2322  let Inst{31-27} = 0b11111;
2323  let Inst{26-23} = 0b0110;
2324  let Inst{22-20} = 0b000;
2325  let Inst{7-4} = 0b0001; // Multiply and Subtract
2326}
2327
2328// Extra precision multiplies with low / high results
2329let neverHasSideEffects = 1 in {
2330let isCommutable = 1 in {
2331def t2SMULL : T2MulLong<0b000, 0b0000,
2332                  (outs rGPR:$RdLo, rGPR:$RdHi),
2333                  (ins rGPR:$Rn, rGPR:$Rm), IIC_iMUL64,
2334                   "smull", "\t$RdLo, $RdHi, $Rn, $Rm", []>;
2335
2336def t2UMULL : T2MulLong<0b010, 0b0000,
2337                  (outs rGPR:$RdLo, rGPR:$RdHi),
2338                  (ins rGPR:$Rn, rGPR:$Rm), IIC_iMUL64,
2339                   "umull", "\t$RdLo, $RdHi, $Rn, $Rm", []>;
2340} // isCommutable
2341
2342// Multiply + accumulate
2343def t2SMLAL : T2MulLong<0b100, 0b0000,
2344                  (outs rGPR:$RdLo, rGPR:$RdHi),
2345                  (ins rGPR:$Rn, rGPR:$Rm), IIC_iMAC64,
2346                  "smlal", "\t$RdLo, $RdHi, $Rn, $Rm", []>;
2347
2348def t2UMLAL : T2MulLong<0b110, 0b0000,
2349                  (outs rGPR:$RdLo, rGPR:$RdHi),
2350                  (ins rGPR:$Rn, rGPR:$Rm), IIC_iMAC64,
2351                  "umlal", "\t$RdLo, $RdHi, $Rn, $Rm", []>;
2352
2353def t2UMAAL : T2MulLong<0b110, 0b0110,
2354                  (outs rGPR:$RdLo, rGPR:$RdHi),
2355                  (ins rGPR:$Rn, rGPR:$Rm), IIC_iMAC64,
2356                  "umaal", "\t$RdLo, $RdHi, $Rn, $Rm", []>,
2357          Requires<[IsThumb2, HasThumb2DSP]>;
2358} // neverHasSideEffects
2359
2360// Rounding variants of the below included for disassembly only
2361
2362// Most significant word multiply
2363def t2SMMUL : T2ThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iMUL32,
2364                  "smmul", "\t$Rd, $Rn, $Rm",
2365                  [(set rGPR:$Rd, (mulhs rGPR:$Rn, rGPR:$Rm))]>,
2366          Requires<[IsThumb2, HasThumb2DSP]> {
2367  let Inst{31-27} = 0b11111;
2368  let Inst{26-23} = 0b0110;
2369  let Inst{22-20} = 0b101;
2370  let Inst{15-12} = 0b1111; // Ra = 0b1111 (no accumulate)
2371  let Inst{7-4} = 0b0000; // No Rounding (Inst{4} = 0)
2372}
2373
2374def t2SMMULR : T2ThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iMUL32,
2375                  "smmulr", "\t$Rd, $Rn, $Rm", []>,
2376          Requires<[IsThumb2, HasThumb2DSP]> {
2377  let Inst{31-27} = 0b11111;
2378  let Inst{26-23} = 0b0110;
2379  let Inst{22-20} = 0b101;
2380  let Inst{15-12} = 0b1111; // Ra = 0b1111 (no accumulate)
2381  let Inst{7-4} = 0b0001; // Rounding (Inst{4} = 1)
2382}
2383
2384def t2SMMLA : T2FourReg<
2385        (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC32,
2386                "smmla", "\t$Rd, $Rn, $Rm, $Ra",
2387                [(set rGPR:$Rd, (add (mulhs rGPR:$Rm, rGPR:$Rn), rGPR:$Ra))]>,
2388          Requires<[IsThumb2, HasThumb2DSP]> {
2389  let Inst{31-27} = 0b11111;
2390  let Inst{26-23} = 0b0110;
2391  let Inst{22-20} = 0b101;
2392  let Inst{7-4} = 0b0000; // No Rounding (Inst{4} = 0)
2393}
2394
2395def t2SMMLAR: T2FourReg<
2396        (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC32,
2397                  "smmlar", "\t$Rd, $Rn, $Rm, $Ra", []>,
2398          Requires<[IsThumb2, HasThumb2DSP]> {
2399  let Inst{31-27} = 0b11111;
2400  let Inst{26-23} = 0b0110;
2401  let Inst{22-20} = 0b101;
2402  let Inst{7-4} = 0b0001; // Rounding (Inst{4} = 1)
2403}
2404
2405def t2SMMLS: T2FourReg<
2406        (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC32,
2407                "smmls", "\t$Rd, $Rn, $Rm, $Ra",
2408                [(set rGPR:$Rd, (sub rGPR:$Ra, (mulhs rGPR:$Rn, rGPR:$Rm)))]>,
2409          Requires<[IsThumb2, HasThumb2DSP]> {
2410  let Inst{31-27} = 0b11111;
2411  let Inst{26-23} = 0b0110;
2412  let Inst{22-20} = 0b110;
2413  let Inst{7-4} = 0b0000; // No Rounding (Inst{4} = 0)
2414}
2415
2416def t2SMMLSR:T2FourReg<
2417        (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC32,
2418                "smmlsr", "\t$Rd, $Rn, $Rm, $Ra", []>,
2419          Requires<[IsThumb2, HasThumb2DSP]> {
2420  let Inst{31-27} = 0b11111;
2421  let Inst{26-23} = 0b0110;
2422  let Inst{22-20} = 0b110;
2423  let Inst{7-4} = 0b0001; // Rounding (Inst{4} = 1)
2424}
2425
2426multiclass T2I_smul<string opc, PatFrag opnode> {
2427  def BB : T2ThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iMUL16,
2428              !strconcat(opc, "bb"), "\t$Rd, $Rn, $Rm",
2429              [(set rGPR:$Rd, (opnode (sext_inreg rGPR:$Rn, i16),
2430                                      (sext_inreg rGPR:$Rm, i16)))]>,
2431          Requires<[IsThumb2, HasThumb2DSP]> {
2432    let Inst{31-27} = 0b11111;
2433    let Inst{26-23} = 0b0110;
2434    let Inst{22-20} = 0b001;
2435    let Inst{15-12} = 0b1111; // Ra = 0b1111 (no accumulate)
2436    let Inst{7-6} = 0b00;
2437    let Inst{5-4} = 0b00;
2438  }
2439
2440  def BT : T2ThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iMUL16,
2441              !strconcat(opc, "bt"), "\t$Rd, $Rn, $Rm",
2442              [(set rGPR:$Rd, (opnode (sext_inreg rGPR:$Rn, i16),
2443                                      (sra rGPR:$Rm, (i32 16))))]>,
2444          Requires<[IsThumb2, HasThumb2DSP]> {
2445    let Inst{31-27} = 0b11111;
2446    let Inst{26-23} = 0b0110;
2447    let Inst{22-20} = 0b001;
2448    let Inst{15-12} = 0b1111; // Ra = 0b1111 (no accumulate)
2449    let Inst{7-6} = 0b00;
2450    let Inst{5-4} = 0b01;
2451  }
2452
2453  def TB : T2ThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iMUL16,
2454              !strconcat(opc, "tb"), "\t$Rd, $Rn, $Rm",
2455              [(set rGPR:$Rd, (opnode (sra rGPR:$Rn, (i32 16)),
2456                                      (sext_inreg rGPR:$Rm, i16)))]>,
2457          Requires<[IsThumb2, HasThumb2DSP]> {
2458    let Inst{31-27} = 0b11111;
2459    let Inst{26-23} = 0b0110;
2460    let Inst{22-20} = 0b001;
2461    let Inst{15-12} = 0b1111; // Ra = 0b1111 (no accumulate)
2462    let Inst{7-6} = 0b00;
2463    let Inst{5-4} = 0b10;
2464  }
2465
2466  def TT : T2ThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iMUL16,
2467              !strconcat(opc, "tt"), "\t$Rd, $Rn, $Rm",
2468              [(set rGPR:$Rd, (opnode (sra rGPR:$Rn, (i32 16)),
2469                                      (sra rGPR:$Rm, (i32 16))))]>,
2470          Requires<[IsThumb2, HasThumb2DSP]> {
2471    let Inst{31-27} = 0b11111;
2472    let Inst{26-23} = 0b0110;
2473    let Inst{22-20} = 0b001;
2474    let Inst{15-12} = 0b1111; // Ra = 0b1111 (no accumulate)
2475    let Inst{7-6} = 0b00;
2476    let Inst{5-4} = 0b11;
2477  }
2478
2479  def WB : T2ThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iMUL16,
2480              !strconcat(opc, "wb"), "\t$Rd, $Rn, $Rm",
2481              [(set rGPR:$Rd, (sra (opnode rGPR:$Rn,
2482                                    (sext_inreg rGPR:$Rm, i16)), (i32 16)))]>,
2483          Requires<[IsThumb2, HasThumb2DSP]> {
2484    let Inst{31-27} = 0b11111;
2485    let Inst{26-23} = 0b0110;
2486    let Inst{22-20} = 0b011;
2487    let Inst{15-12} = 0b1111; // Ra = 0b1111 (no accumulate)
2488    let Inst{7-6} = 0b00;
2489    let Inst{5-4} = 0b00;
2490  }
2491
2492  def WT : T2ThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iMUL16,
2493              !strconcat(opc, "wt"), "\t$Rd, $Rn, $Rm",
2494              [(set rGPR:$Rd, (sra (opnode rGPR:$Rn,
2495                                    (sra rGPR:$Rm, (i32 16))), (i32 16)))]>,
2496          Requires<[IsThumb2, HasThumb2DSP]> {
2497    let Inst{31-27} = 0b11111;
2498    let Inst{26-23} = 0b0110;
2499    let Inst{22-20} = 0b011;
2500    let Inst{15-12} = 0b1111; // Ra = 0b1111 (no accumulate)
2501    let Inst{7-6} = 0b00;
2502    let Inst{5-4} = 0b01;
2503  }
2504}
2505
2506
2507multiclass T2I_smla<string opc, PatFrag opnode> {
2508  def BB : T2FourReg<
2509        (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC16,
2510              !strconcat(opc, "bb"), "\t$Rd, $Rn, $Rm, $Ra",
2511              [(set rGPR:$Rd, (add rGPR:$Ra,
2512                               (opnode (sext_inreg rGPR:$Rn, i16),
2513                                       (sext_inreg rGPR:$Rm, i16))))]>,
2514          Requires<[IsThumb2, HasThumb2DSP]> {
2515    let Inst{31-27} = 0b11111;
2516    let Inst{26-23} = 0b0110;
2517    let Inst{22-20} = 0b001;
2518    let Inst{7-6} = 0b00;
2519    let Inst{5-4} = 0b00;
2520  }
2521
2522  def BT : T2FourReg<
2523       (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC16,
2524             !strconcat(opc, "bt"), "\t$Rd, $Rn, $Rm, $Ra",
2525             [(set rGPR:$Rd, (add rGPR:$Ra, (opnode (sext_inreg rGPR:$Rn, i16),
2526                                                 (sra rGPR:$Rm, (i32 16)))))]>,
2527          Requires<[IsThumb2, HasThumb2DSP]> {
2528    let Inst{31-27} = 0b11111;
2529    let Inst{26-23} = 0b0110;
2530    let Inst{22-20} = 0b001;
2531    let Inst{7-6} = 0b00;
2532    let Inst{5-4} = 0b01;
2533  }
2534
2535  def TB : T2FourReg<
2536        (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC16,
2537              !strconcat(opc, "tb"), "\t$Rd, $Rn, $Rm, $Ra",
2538              [(set rGPR:$Rd, (add rGPR:$Ra, (opnode (sra rGPR:$Rn, (i32 16)),
2539                                               (sext_inreg rGPR:$Rm, i16))))]>,
2540          Requires<[IsThumb2, HasThumb2DSP]> {
2541    let Inst{31-27} = 0b11111;
2542    let Inst{26-23} = 0b0110;
2543    let Inst{22-20} = 0b001;
2544    let Inst{7-6} = 0b00;
2545    let Inst{5-4} = 0b10;
2546  }
2547
2548  def TT : T2FourReg<
2549        (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC16,
2550              !strconcat(opc, "tt"), "\t$Rd, $Rn, $Rm, $Ra",
2551             [(set rGPR:$Rd, (add rGPR:$Ra, (opnode (sra rGPR:$Rn, (i32 16)),
2552                                                 (sra rGPR:$Rm, (i32 16)))))]>,
2553          Requires<[IsThumb2, HasThumb2DSP]> {
2554    let Inst{31-27} = 0b11111;
2555    let Inst{26-23} = 0b0110;
2556    let Inst{22-20} = 0b001;
2557    let Inst{7-6} = 0b00;
2558    let Inst{5-4} = 0b11;
2559  }
2560
2561  def WB : T2FourReg<
2562        (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC16,
2563              !strconcat(opc, "wb"), "\t$Rd, $Rn, $Rm, $Ra",
2564              [(set rGPR:$Rd, (add rGPR:$Ra, (sra (opnode rGPR:$Rn,
2565                                    (sext_inreg rGPR:$Rm, i16)), (i32 16))))]>,
2566          Requires<[IsThumb2, HasThumb2DSP]> {
2567    let Inst{31-27} = 0b11111;
2568    let Inst{26-23} = 0b0110;
2569    let Inst{22-20} = 0b011;
2570    let Inst{7-6} = 0b00;
2571    let Inst{5-4} = 0b00;
2572  }
2573
2574  def WT : T2FourReg<
2575        (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC16,
2576              !strconcat(opc, "wt"), "\t$Rd, $Rn, $Rm, $Ra",
2577              [(set rGPR:$Rd, (add rGPR:$Ra, (sra (opnode rGPR:$Rn,
2578                                      (sra rGPR:$Rm, (i32 16))), (i32 16))))]>,
2579          Requires<[IsThumb2, HasThumb2DSP]> {
2580    let Inst{31-27} = 0b11111;
2581    let Inst{26-23} = 0b0110;
2582    let Inst{22-20} = 0b011;
2583    let Inst{7-6} = 0b00;
2584    let Inst{5-4} = 0b01;
2585  }
2586}
2587
2588defm t2SMUL : T2I_smul<"smul", BinOpFrag<(mul node:$LHS, node:$RHS)>>;
2589defm t2SMLA : T2I_smla<"smla", BinOpFrag<(mul node:$LHS, node:$RHS)>>;
2590
2591// Halfword multiple accumulate long: SMLAL<x><y>
2592def t2SMLALBB : T2FourReg_mac<1, 0b100, 0b1000, (outs rGPR:$Ra,rGPR:$Rd),
2593         (ins rGPR:$Rn,rGPR:$Rm), IIC_iMAC64, "smlalbb", "\t$Ra, $Rd, $Rn, $Rm",
2594           [/* For disassembly only; pattern left blank */]>,
2595          Requires<[IsThumb2, HasThumb2DSP]>;
2596def t2SMLALBT : T2FourReg_mac<1, 0b100, 0b1001, (outs rGPR:$Ra,rGPR:$Rd),
2597         (ins rGPR:$Rn,rGPR:$Rm), IIC_iMAC64, "smlalbt", "\t$Ra, $Rd, $Rn, $Rm",
2598           [/* For disassembly only; pattern left blank */]>,
2599          Requires<[IsThumb2, HasThumb2DSP]>;
2600def t2SMLALTB : T2FourReg_mac<1, 0b100, 0b1010, (outs rGPR:$Ra,rGPR:$Rd),
2601         (ins rGPR:$Rn,rGPR:$Rm), IIC_iMAC64, "smlaltb", "\t$Ra, $Rd, $Rn, $Rm",
2602           [/* For disassembly only; pattern left blank */]>,
2603          Requires<[IsThumb2, HasThumb2DSP]>;
2604def t2SMLALTT : T2FourReg_mac<1, 0b100, 0b1011, (outs rGPR:$Ra,rGPR:$Rd),
2605         (ins rGPR:$Rn,rGPR:$Rm), IIC_iMAC64, "smlaltt", "\t$Ra, $Rd, $Rn, $Rm",
2606           [/* For disassembly only; pattern left blank */]>,
2607          Requires<[IsThumb2, HasThumb2DSP]>;
2608
2609// Dual halfword multiple: SMUAD, SMUSD, SMLAD, SMLSD, SMLALD, SMLSLD
2610def t2SMUAD: T2ThreeReg_mac<
2611            0, 0b010, 0b0000, (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm),
2612            IIC_iMAC32, "smuad", "\t$Rd, $Rn, $Rm", []>,
2613          Requires<[IsThumb2, HasThumb2DSP]> {
2614  let Inst{15-12} = 0b1111;
2615}
2616def t2SMUADX:T2ThreeReg_mac<
2617            0, 0b010, 0b0001, (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm),
2618            IIC_iMAC32, "smuadx", "\t$Rd, $Rn, $Rm", []>,
2619          Requires<[IsThumb2, HasThumb2DSP]> {
2620  let Inst{15-12} = 0b1111;
2621}
2622def t2SMUSD: T2ThreeReg_mac<
2623            0, 0b100, 0b0000, (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm),
2624            IIC_iMAC32, "smusd", "\t$Rd, $Rn, $Rm", []>,
2625          Requires<[IsThumb2, HasThumb2DSP]> {
2626  let Inst{15-12} = 0b1111;
2627}
2628def t2SMUSDX:T2ThreeReg_mac<
2629            0, 0b100, 0b0001, (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm),
2630            IIC_iMAC32, "smusdx", "\t$Rd, $Rn, $Rm", []>,
2631          Requires<[IsThumb2, HasThumb2DSP]> {
2632  let Inst{15-12} = 0b1111;
2633}
2634def t2SMLAD   : T2FourReg_mac<
2635            0, 0b010, 0b0000, (outs rGPR:$Rd),
2636            (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC32, "smlad",
2637            "\t$Rd, $Rn, $Rm, $Ra", []>,
2638          Requires<[IsThumb2, HasThumb2DSP]>;
2639def t2SMLADX  : T2FourReg_mac<
2640            0, 0b010, 0b0001, (outs rGPR:$Rd),
2641            (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC32, "smladx",
2642            "\t$Rd, $Rn, $Rm, $Ra", []>,
2643          Requires<[IsThumb2, HasThumb2DSP]>;
2644def t2SMLSD   : T2FourReg_mac<0, 0b100, 0b0000, (outs rGPR:$Rd),
2645            (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC32, "smlsd",
2646            "\t$Rd, $Rn, $Rm, $Ra", []>,
2647          Requires<[IsThumb2, HasThumb2DSP]>;
2648def t2SMLSDX  : T2FourReg_mac<0, 0b100, 0b0001, (outs rGPR:$Rd),
2649            (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC32, "smlsdx",
2650            "\t$Rd, $Rn, $Rm, $Ra", []>,
2651          Requires<[IsThumb2, HasThumb2DSP]>;
2652def t2SMLALD  : T2FourReg_mac<1, 0b100, 0b1100, (outs rGPR:$Ra,rGPR:$Rd),
2653                        (ins rGPR:$Rn, rGPR:$Rm), IIC_iMAC64, "smlald",
2654                        "\t$Ra, $Rd, $Rn, $Rm", []>,
2655          Requires<[IsThumb2, HasThumb2DSP]>;
2656def t2SMLALDX : T2FourReg_mac<1, 0b100, 0b1101, (outs rGPR:$Ra,rGPR:$Rd),
2657                        (ins rGPR:$Rn,rGPR:$Rm), IIC_iMAC64, "smlaldx",
2658                        "\t$Ra, $Rd, $Rn, $Rm", []>,
2659          Requires<[IsThumb2, HasThumb2DSP]>;
2660def t2SMLSLD  : T2FourReg_mac<1, 0b101, 0b1100, (outs rGPR:$Ra,rGPR:$Rd),
2661                        (ins rGPR:$Rn,rGPR:$Rm), IIC_iMAC64, "smlsld",
2662                        "\t$Ra, $Rd, $Rn, $Rm", []>,
2663          Requires<[IsThumb2, HasThumb2DSP]>;
2664def t2SMLSLDX : T2FourReg_mac<1, 0b101, 0b1101, (outs rGPR:$Ra,rGPR:$Rd),
2665                        (ins rGPR:$Rm,rGPR:$Rn), IIC_iMAC64, "smlsldx",
2666                        "\t$Ra, $Rd, $Rn, $Rm", []>,
2667          Requires<[IsThumb2, HasThumb2DSP]>;
2668
2669//===----------------------------------------------------------------------===//
2670//  Division Instructions.
2671//  Signed and unsigned division on v7-M
2672//
2673def t2SDIV : T2ThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iALUi,
2674                 "sdiv", "\t$Rd, $Rn, $Rm",
2675                 [(set rGPR:$Rd, (sdiv rGPR:$Rn, rGPR:$Rm))]>,
2676                 Requires<[HasDivide, IsThumb2]> {
2677  let Inst{31-27} = 0b11111;
2678  let Inst{26-21} = 0b011100;
2679  let Inst{20} = 0b1;
2680  let Inst{15-12} = 0b1111;
2681  let Inst{7-4} = 0b1111;
2682}
2683
2684def t2UDIV : T2ThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iALUi,
2685                 "udiv", "\t$Rd, $Rn, $Rm",
2686                 [(set rGPR:$Rd, (udiv rGPR:$Rn, rGPR:$Rm))]>,
2687                 Requires<[HasDivide, IsThumb2]> {
2688  let Inst{31-27} = 0b11111;
2689  let Inst{26-21} = 0b011101;
2690  let Inst{20} = 0b1;
2691  let Inst{15-12} = 0b1111;
2692  let Inst{7-4} = 0b1111;
2693}
2694
2695//===----------------------------------------------------------------------===//
2696//  Misc. Arithmetic Instructions.
2697//
2698
2699class T2I_misc<bits<2> op1, bits<2> op2, dag oops, dag iops,
2700      InstrItinClass itin, string opc, string asm, list<dag> pattern>
2701  : T2ThreeReg<oops, iops, itin, opc, asm, pattern> {
2702  let Inst{31-27} = 0b11111;
2703  let Inst{26-22} = 0b01010;
2704  let Inst{21-20} = op1;
2705  let Inst{15-12} = 0b1111;
2706  let Inst{7-6} = 0b10;
2707  let Inst{5-4} = op2;
2708  let Rn{3-0} = Rm;
2709}
2710
2711def t2CLZ : T2I_misc<0b11, 0b00, (outs rGPR:$Rd), (ins rGPR:$Rm), IIC_iUNAr,
2712                    "clz", "\t$Rd, $Rm", [(set rGPR:$Rd, (ctlz rGPR:$Rm))]>;
2713
2714def t2RBIT : T2I_misc<0b01, 0b10, (outs rGPR:$Rd), (ins rGPR:$Rm), IIC_iUNAr,
2715                      "rbit", "\t$Rd, $Rm",
2716                      [(set rGPR:$Rd, (ARMrbit rGPR:$Rm))]>;
2717
2718def t2REV : T2I_misc<0b01, 0b00, (outs rGPR:$Rd), (ins rGPR:$Rm), IIC_iUNAr,
2719                 "rev", ".w\t$Rd, $Rm", [(set rGPR:$Rd, (bswap rGPR:$Rm))]>;
2720
2721def t2REV16 : T2I_misc<0b01, 0b01, (outs rGPR:$Rd), (ins rGPR:$Rm), IIC_iUNAr,
2722                       "rev16", ".w\t$Rd, $Rm",
2723                [(set rGPR:$Rd, (rotr (bswap rGPR:$Rm), (i32 16)))]>;
2724
2725def t2REVSH : T2I_misc<0b01, 0b11, (outs rGPR:$Rd), (ins rGPR:$Rm), IIC_iUNAr,
2726                       "revsh", ".w\t$Rd, $Rm",
2727                 [(set rGPR:$Rd, (sra (bswap rGPR:$Rm), (i32 16)))]>;
2728
2729def : T2Pat<(or (sra (shl rGPR:$Rm, (i32 24)), (i32 16)),
2730                (and (srl rGPR:$Rm, (i32 8)), 0xFF)),
2731            (t2REVSH rGPR:$Rm)>;
2732
2733def t2PKHBT : T2ThreeReg<
2734            (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, pkh_lsl_amt:$sh),
2735                  IIC_iBITsi, "pkhbt", "\t$Rd, $Rn, $Rm$sh",
2736                  [(set rGPR:$Rd, (or (and rGPR:$Rn, 0xFFFF),
2737                                      (and (shl rGPR:$Rm, pkh_lsl_amt:$sh),
2738                                           0xFFFF0000)))]>,
2739                  Requires<[HasT2ExtractPack, IsThumb2]> {
2740  let Inst{31-27} = 0b11101;
2741  let Inst{26-25} = 0b01;
2742  let Inst{24-20} = 0b01100;
2743  let Inst{5} = 0; // BT form
2744  let Inst{4} = 0;
2745
2746  bits<5> sh;
2747  let Inst{14-12} = sh{4-2};
2748  let Inst{7-6}   = sh{1-0};
2749}
2750
2751// Alternate cases for PKHBT where identities eliminate some nodes.
2752def : T2Pat<(or (and rGPR:$src1, 0xFFFF), (and rGPR:$src2, 0xFFFF0000)),
2753            (t2PKHBT rGPR:$src1, rGPR:$src2, 0)>,
2754            Requires<[HasT2ExtractPack, IsThumb2]>;
2755def : T2Pat<(or (and rGPR:$src1, 0xFFFF), (shl rGPR:$src2, imm16_31:$sh)),
2756            (t2PKHBT rGPR:$src1, rGPR:$src2, imm16_31:$sh)>,
2757            Requires<[HasT2ExtractPack, IsThumb2]>;
2758
2759// Note: Shifts of 1-15 bits will be transformed to srl instead of sra and
2760// will match the pattern below.
2761def t2PKHTB : T2ThreeReg<
2762                  (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, pkh_asr_amt:$sh),
2763                  IIC_iBITsi, "pkhtb", "\t$Rd, $Rn, $Rm$sh",
2764                  [(set rGPR:$Rd, (or (and rGPR:$Rn, 0xFFFF0000),
2765                                       (and (sra rGPR:$Rm, pkh_asr_amt:$sh),
2766                                            0xFFFF)))]>,
2767                  Requires<[HasT2ExtractPack, IsThumb2]> {
2768  let Inst{31-27} = 0b11101;
2769  let Inst{26-25} = 0b01;
2770  let Inst{24-20} = 0b01100;
2771  let Inst{5} = 1; // TB form
2772  let Inst{4} = 0;
2773
2774  bits<5> sh;
2775  let Inst{14-12} = sh{4-2};
2776  let Inst{7-6}   = sh{1-0};
2777}
2778
2779// Alternate cases for PKHTB where identities eliminate some nodes.  Note that
2780// a shift amount of 0 is *not legal* here, it is PKHBT instead.
2781def : T2Pat<(or (and rGPR:$src1, 0xFFFF0000), (srl rGPR:$src2, imm16_31:$sh)),
2782            (t2PKHTB rGPR:$src1, rGPR:$src2, imm16_31:$sh)>,
2783            Requires<[HasT2ExtractPack, IsThumb2]>;
2784def : T2Pat<(or (and rGPR:$src1, 0xFFFF0000),
2785                (and (srl rGPR:$src2, imm1_15:$sh), 0xFFFF)),
2786            (t2PKHTB rGPR:$src1, rGPR:$src2, imm1_15:$sh)>,
2787            Requires<[HasT2ExtractPack, IsThumb2]>;
2788
2789//===----------------------------------------------------------------------===//
2790//  Comparison Instructions...
2791//
2792defm t2CMP  : T2I_cmp_irs<0b1101, "cmp",
2793                          IIC_iCMPi, IIC_iCMPr, IIC_iCMPsi,
2794                          BinOpFrag<(ARMcmp node:$LHS, node:$RHS)>, "t2CMP">;
2795
2796def : T2Pat<(ARMcmpZ  GPRnopc:$lhs, t2_so_imm:$imm),
2797            (t2CMPri  GPRnopc:$lhs, t2_so_imm:$imm)>;
2798def : T2Pat<(ARMcmpZ  GPRnopc:$lhs, rGPR:$rhs),
2799            (t2CMPrr  GPRnopc:$lhs, rGPR:$rhs)>;
2800def : T2Pat<(ARMcmpZ  GPRnopc:$lhs, t2_so_reg:$rhs),
2801            (t2CMPrs  GPRnopc:$lhs, t2_so_reg:$rhs)>;
2802
2803//FIXME: Disable CMN, as CCodes are backwards from compare expectations
2804//       Compare-to-zero still works out, just not the relationals
2805//defm t2CMN  : T2I_cmp_irs<0b1000, "cmn",
2806//                          BinOpFrag<(ARMcmp node:$LHS,(ineg node:$RHS))>>;
2807defm t2CMNz : T2I_cmp_irs<0b1000, "cmn",
2808                          IIC_iCMPi, IIC_iCMPr, IIC_iCMPsi,
2809                          BinOpFrag<(ARMcmpZ node:$LHS,(ineg node:$RHS))>,
2810                          "t2CMNz">;
2811
2812//def : T2Pat<(ARMcmp  GPR:$src, t2_so_imm_neg:$imm),
2813//            (t2CMNri GPR:$src, t2_so_imm_neg:$imm)>;
2814
2815def : T2Pat<(ARMcmpZ  GPRnopc:$src, t2_so_imm_neg:$imm),
2816            (t2CMNzri GPRnopc:$src, t2_so_imm_neg:$imm)>;
2817
2818defm t2TST  : T2I_cmp_irs<0b0000, "tst",
2819                          IIC_iTSTi, IIC_iTSTr, IIC_iTSTsi,
2820                         BinOpFrag<(ARMcmpZ (and_su node:$LHS, node:$RHS), 0)>,
2821                          "t2TST">;
2822defm t2TEQ  : T2I_cmp_irs<0b0100, "teq",
2823                          IIC_iTSTi, IIC_iTSTr, IIC_iTSTsi,
2824                         BinOpFrag<(ARMcmpZ (xor_su node:$LHS, node:$RHS), 0)>,
2825                          "t2TEQ">;
2826
2827// Conditional moves
2828// FIXME: should be able to write a pattern for ARMcmov, but can't use
2829// a two-value operand where a dag node expects two operands. :(
2830let neverHasSideEffects = 1 in {
2831def t2MOVCCr : t2PseudoInst<(outs rGPR:$Rd),
2832                            (ins rGPR:$false, rGPR:$Rm, pred:$p),
2833                            4, IIC_iCMOVr,
2834   [/*(set rGPR:$Rd, (ARMcmov rGPR:$false, rGPR:$Rm, imm:$cc, CCR:$ccr))*/]>,
2835                RegConstraint<"$false = $Rd">;
2836
2837let isMoveImm = 1 in
2838def t2MOVCCi : t2PseudoInst<(outs rGPR:$Rd),
2839                            (ins rGPR:$false, t2_so_imm:$imm, pred:$p),
2840                   4, IIC_iCMOVi,
2841[/*(set rGPR:$Rd,(ARMcmov rGPR:$false,t2_so_imm:$imm, imm:$cc, CCR:$ccr))*/]>,
2842                   RegConstraint<"$false = $Rd">;
2843
2844// FIXME: Pseudo-ize these. For now, just mark codegen only.
2845let isCodeGenOnly = 1 in {
2846let isMoveImm = 1 in
2847def t2MOVCCi16 : T2I<(outs rGPR:$Rd), (ins rGPR:$false, imm0_65535_expr:$imm),
2848                      IIC_iCMOVi,
2849                      "movw", "\t$Rd, $imm", []>,
2850                      RegConstraint<"$false = $Rd"> {
2851  let Inst{31-27} = 0b11110;
2852  let Inst{25} = 1;
2853  let Inst{24-21} = 0b0010;
2854  let Inst{20} = 0; // The S bit.
2855  let Inst{15} = 0;
2856
2857  bits<4> Rd;
2858  bits<16> imm;
2859
2860  let Inst{11-8}  = Rd;
2861  let Inst{19-16} = imm{15-12};
2862  let Inst{26}    = imm{11};
2863  let Inst{14-12} = imm{10-8};
2864  let Inst{7-0}   = imm{7-0};
2865}
2866
2867let isMoveImm = 1 in
2868def t2MOVCCi32imm : PseudoInst<(outs rGPR:$dst),
2869                               (ins rGPR:$false, i32imm:$src, pred:$p),
2870                    IIC_iCMOVix2, []>, RegConstraint<"$false = $dst">;
2871
2872let isMoveImm = 1 in
2873def t2MVNCCi : T2OneRegImm<(outs rGPR:$Rd), (ins rGPR:$false, t2_so_imm:$imm),
2874                   IIC_iCMOVi, "mvn", ".w\t$Rd, $imm",
2875[/*(set rGPR:$Rd,(ARMcmov rGPR:$false,t2_so_imm_not:$imm,
2876                   imm:$cc, CCR:$ccr))*/]>,
2877                   RegConstraint<"$false = $Rd"> {
2878  let Inst{31-27} = 0b11110;
2879  let Inst{25} = 0;
2880  let Inst{24-21} = 0b0011;
2881  let Inst{20} = 0; // The S bit.
2882  let Inst{19-16} = 0b1111; // Rn
2883  let Inst{15} = 0;
2884}
2885
2886class T2I_movcc_sh<bits<2> opcod, dag oops, dag iops, InstrItinClass itin,
2887                   string opc, string asm, list<dag> pattern>
2888  : T2TwoRegShiftImm<oops, iops, itin, opc, asm, pattern> {
2889  let Inst{31-27} = 0b11101;
2890  let Inst{26-25} = 0b01;
2891  let Inst{24-21} = 0b0010;
2892  let Inst{20} = 0; // The S bit.
2893  let Inst{19-16} = 0b1111; // Rn
2894  let Inst{5-4} = opcod; // Shift type.
2895}
2896def t2MOVCClsl : T2I_movcc_sh<0b00, (outs rGPR:$Rd),
2897                             (ins rGPR:$false, rGPR:$Rm, i32imm:$imm),
2898                             IIC_iCMOVsi, "lsl", ".w\t$Rd, $Rm, $imm", []>,
2899                 RegConstraint<"$false = $Rd">;
2900def t2MOVCClsr : T2I_movcc_sh<0b01, (outs rGPR:$Rd),
2901                             (ins rGPR:$false, rGPR:$Rm, i32imm:$imm),
2902                             IIC_iCMOVsi, "lsr", ".w\t$Rd, $Rm, $imm", []>,
2903                 RegConstraint<"$false = $Rd">;
2904def t2MOVCCasr : T2I_movcc_sh<0b10, (outs rGPR:$Rd),
2905                             (ins rGPR:$false, rGPR:$Rm, i32imm:$imm),
2906                             IIC_iCMOVsi, "asr", ".w\t$Rd, $Rm, $imm", []>,
2907                 RegConstraint<"$false = $Rd">;
2908def t2MOVCCror : T2I_movcc_sh<0b11, (outs rGPR:$Rd),
2909                             (ins rGPR:$false, rGPR:$Rm, i32imm:$imm),
2910                             IIC_iCMOVsi, "ror", ".w\t$Rd, $Rm, $imm", []>,
2911                 RegConstraint<"$false = $Rd">;
2912} // isCodeGenOnly = 1
2913} // neverHasSideEffects
2914
2915//===----------------------------------------------------------------------===//
2916// Atomic operations intrinsics
2917//
2918
2919// memory barriers protect the atomic sequences
2920let hasSideEffects = 1 in {
2921def t2DMB : AInoP<(outs), (ins memb_opt:$opt), ThumbFrm, NoItinerary,
2922                  "dmb", "\t$opt", [(ARMMemBarrier (i32 imm:$opt))]>,
2923                  Requires<[IsThumb, HasDB]> {
2924  bits<4> opt;
2925  let Inst{31-4} = 0xf3bf8f5;
2926  let Inst{3-0} = opt;
2927}
2928}
2929
2930def t2DSB : AInoP<(outs), (ins memb_opt:$opt), ThumbFrm, NoItinerary,
2931                  "dsb", "\t$opt", []>,
2932                  Requires<[IsThumb, HasDB]> {
2933  bits<4> opt;
2934  let Inst{31-4} = 0xf3bf8f4;
2935  let Inst{3-0} = opt;
2936}
2937
2938def t2ISB : AInoP<(outs), (ins memb_opt:$opt), ThumbFrm, NoItinerary,
2939                  "isb", "\t$opt",
2940                  []>, Requires<[IsThumb2, HasDB]> {
2941  bits<4> opt;
2942  let Inst{31-4} = 0xf3bf8f6;
2943  let Inst{3-0} = opt;
2944}
2945
2946class T2I_ldrex<bits<2> opcod, dag oops, dag iops, AddrMode am, int sz,
2947                InstrItinClass itin, string opc, string asm, string cstr,
2948                list<dag> pattern, bits<4> rt2 = 0b1111>
2949  : Thumb2I<oops, iops, am, sz, itin, opc, asm, cstr, pattern> {
2950  let Inst{31-27} = 0b11101;
2951  let Inst{26-20} = 0b0001101;
2952  let Inst{11-8} = rt2;
2953  let Inst{7-6} = 0b01;
2954  let Inst{5-4} = opcod;
2955  let Inst{3-0} = 0b1111;
2956
2957  bits<4> addr;
2958  bits<4> Rt;
2959  let Inst{19-16} = addr;
2960  let Inst{15-12} = Rt;
2961}
2962class T2I_strex<bits<2> opcod, dag oops, dag iops, AddrMode am, int sz,
2963                InstrItinClass itin, string opc, string asm, string cstr,
2964                list<dag> pattern, bits<4> rt2 = 0b1111>
2965  : Thumb2I<oops, iops, am, sz, itin, opc, asm, cstr, pattern> {
2966  let Inst{31-27} = 0b11101;
2967  let Inst{26-20} = 0b0001100;
2968  let Inst{11-8} = rt2;
2969  let Inst{7-6} = 0b01;
2970  let Inst{5-4} = opcod;
2971
2972  bits<4> Rd;
2973  bits<4> addr;
2974  bits<4> Rt;
2975  let Inst{3-0}  = Rd;
2976  let Inst{19-16} = addr;
2977  let Inst{15-12} = Rt;
2978}
2979
2980let mayLoad = 1 in {
2981def t2LDREXB : T2I_ldrex<0b00, (outs rGPR:$Rt), (ins addr_offset_none:$addr),
2982                         AddrModeNone, 4, NoItinerary,
2983                         "ldrexb", "\t$Rt, $addr", "", []>;
2984def t2LDREXH : T2I_ldrex<0b01, (outs rGPR:$Rt), (ins addr_offset_none:$addr),
2985                         AddrModeNone, 4, NoItinerary,
2986                         "ldrexh", "\t$Rt, $addr", "", []>;
2987def t2LDREX  : Thumb2I<(outs rGPR:$Rt), (ins t2addrmode_imm0_1020s4:$addr),
2988                       AddrModeNone, 4, NoItinerary,
2989                       "ldrex", "\t$Rt, $addr", "", []> {
2990  bits<4> Rt;
2991  bits<12> addr;
2992  let Inst{31-27} = 0b11101;
2993  let Inst{26-20} = 0b0000101;
2994  let Inst{19-16} = addr{11-8};
2995  let Inst{15-12} = Rt;
2996  let Inst{11-8} = 0b1111;
2997  let Inst{7-0} = addr{7-0};
2998}
2999let hasExtraDefRegAllocReq = 1 in
3000def t2LDREXD : T2I_ldrex<0b11, (outs rGPR:$Rt, rGPR:$Rt2),
3001                         (ins addr_offset_none:$addr),
3002                         AddrModeNone, 4, NoItinerary,
3003                         "ldrexd", "\t$Rt, $Rt2, $addr", "",
3004                         [], {?, ?, ?, ?}> {
3005  bits<4> Rt2;
3006  let Inst{11-8} = Rt2;
3007}
3008}
3009
3010let mayStore = 1, Constraints = "@earlyclobber $Rd" in {
3011def t2STREXB : T2I_strex<0b00, (outs rGPR:$Rd),
3012                         (ins rGPR:$Rt, addr_offset_none:$addr),
3013                         AddrModeNone, 4, NoItinerary,
3014                         "strexb", "\t$Rd, $Rt, $addr", "", []>;
3015def t2STREXH : T2I_strex<0b01, (outs rGPR:$Rd),
3016                         (ins rGPR:$Rt, addr_offset_none:$addr),
3017                         AddrModeNone, 4, NoItinerary,
3018                         "strexh", "\t$Rd, $Rt, $addr", "", []>;
3019def t2STREX  : Thumb2I<(outs rGPR:$Rd), (ins rGPR:$Rt,
3020                             t2addrmode_imm0_1020s4:$addr),
3021                  AddrModeNone, 4, NoItinerary,
3022                  "strex", "\t$Rd, $Rt, $addr", "",
3023                  []> {
3024  bits<4> Rd;
3025  bits<4> Rt;
3026  bits<12> addr;
3027  let Inst{31-27} = 0b11101;
3028  let Inst{26-20} = 0b0000100;
3029  let Inst{19-16} = addr{11-8};
3030  let Inst{15-12} = Rt;
3031  let Inst{11-8}  = Rd;
3032  let Inst{7-0} = addr{7-0};
3033}
3034}
3035
3036let hasExtraSrcRegAllocReq = 1, Constraints = "@earlyclobber $Rd" in
3037def t2STREXD : T2I_strex<0b11, (outs rGPR:$Rd),
3038                         (ins rGPR:$Rt, rGPR:$Rt2, addr_offset_none:$addr),
3039                         AddrModeNone, 4, NoItinerary,
3040                         "strexd", "\t$Rd, $Rt, $Rt2, $addr", "", [],
3041                         {?, ?, ?, ?}> {
3042  bits<4> Rt2;
3043  let Inst{11-8} = Rt2;
3044}
3045
3046def t2CLREX : T2I<(outs), (ins), NoItinerary, "clrex", "", []>,
3047            Requires<[IsThumb2, HasV7]>  {
3048  let Inst{31-16} = 0xf3bf;
3049  let Inst{15-14} = 0b10;
3050  let Inst{13} = 0;
3051  let Inst{12} = 0;
3052  let Inst{11-8} = 0b1111;
3053  let Inst{7-4} = 0b0010;
3054  let Inst{3-0} = 0b1111;
3055}
3056
3057//===----------------------------------------------------------------------===//
3058// SJLJ Exception handling intrinsics
3059//   eh_sjlj_setjmp() is an instruction sequence to store the return
3060//   address and save #0 in R0 for the non-longjmp case.
3061//   Since by its nature we may be coming from some other function to get
3062//   here, and we're using the stack frame for the containing function to
3063//   save/restore registers, we can't keep anything live in regs across
3064//   the eh_sjlj_setjmp(), else it will almost certainly have been tromped upon
3065//   when we get here from a longjmp(). We force everything out of registers
3066//   except for our own input by listing the relevant registers in Defs. By
3067//   doing so, we also cause the prologue/epilogue code to actively preserve
3068//   all of the callee-saved resgisters, which is exactly what we want.
3069//   $val is a scratch register for our use.
3070let Defs =
3071  [ R0,  R1,  R2,  R3,  R4,  R5,  R6,  R7,  R8,  R9,  R10, R11, R12, LR, CPSR,
3072    QQQQ0, QQQQ1, QQQQ2, QQQQ3 ],
3073  hasSideEffects = 1, isBarrier = 1, isCodeGenOnly = 1 in {
3074  def t2Int_eh_sjlj_setjmp : Thumb2XI<(outs), (ins tGPR:$src, tGPR:$val),
3075                               AddrModeNone, 0, NoItinerary, "", "",
3076                          [(set R0, (ARMeh_sjlj_setjmp tGPR:$src, tGPR:$val))]>,
3077                             Requires<[IsThumb2, HasVFP2]>;
3078}
3079
3080let Defs =
3081  [ R0,  R1,  R2,  R3,  R4,  R5,  R6,  R7,  R8,  R9,  R10, R11, R12, LR, CPSR ],
3082  hasSideEffects = 1, isBarrier = 1, isCodeGenOnly = 1 in {
3083  def t2Int_eh_sjlj_setjmp_nofp : Thumb2XI<(outs), (ins tGPR:$src, tGPR:$val),
3084                               AddrModeNone, 0, NoItinerary, "", "",
3085                          [(set R0, (ARMeh_sjlj_setjmp tGPR:$src, tGPR:$val))]>,
3086                                  Requires<[IsThumb2, NoVFP]>;
3087}
3088
3089
3090//===----------------------------------------------------------------------===//
3091// Control-Flow Instructions
3092//
3093
3094// FIXME: remove when we have a way to marking a MI with these properties.
3095// FIXME: Should pc be an implicit operand like PICADD, etc?
3096let isReturn = 1, isTerminator = 1, isBarrier = 1, mayLoad = 1,
3097    hasExtraDefRegAllocReq = 1, isCodeGenOnly = 1 in
3098def t2LDMIA_RET: t2PseudoExpand<(outs GPR:$wb), (ins GPR:$Rn, pred:$p,
3099                                                   reglist:$regs, variable_ops),
3100                              4, IIC_iLoad_mBr, [],
3101            (t2LDMIA_UPD GPR:$wb, GPR:$Rn, pred:$p, reglist:$regs)>,
3102                         RegConstraint<"$Rn = $wb">;
3103
3104let isBranch = 1, isTerminator = 1, isBarrier = 1 in {
3105let isPredicable = 1 in
3106def t2B   : T2I<(outs), (ins uncondbrtarget:$target), IIC_Br,
3107                 "b", ".w\t$target",
3108                 [(br bb:$target)]> {
3109  let Inst{31-27} = 0b11110;
3110  let Inst{15-14} = 0b10;
3111  let Inst{12} = 1;
3112
3113  bits<20> target;
3114  let Inst{26} = target{19};
3115  let Inst{11} = target{18};
3116  let Inst{13} = target{17};
3117  let Inst{21-16} = target{16-11};
3118  let Inst{10-0} = target{10-0};
3119}
3120
3121let isNotDuplicable = 1, isIndirectBranch = 1 in {
3122def t2BR_JT : t2PseudoInst<(outs),
3123          (ins GPR:$target, GPR:$index, i32imm:$jt, i32imm:$id),
3124           0, IIC_Br,
3125          [(ARMbr2jt GPR:$target, GPR:$index, tjumptable:$jt, imm:$id)]>;
3126
3127// FIXME: Add a non-pc based case that can be predicated.
3128def t2TBB_JT : t2PseudoInst<(outs),
3129        (ins GPR:$index, i32imm:$jt, i32imm:$id), 0, IIC_Br, []>;
3130
3131def t2TBH_JT : t2PseudoInst<(outs),
3132        (ins GPR:$index, i32imm:$jt, i32imm:$id), 0, IIC_Br, []>;
3133
3134def t2TBB : T2I<(outs), (ins addrmode_tbb:$addr), IIC_Br,
3135                    "tbb", "\t$addr", []> {
3136  bits<4> Rn;
3137  bits<4> Rm;
3138  let Inst{31-20} = 0b111010001101;
3139  let Inst{19-16} = Rn;
3140  let Inst{15-5} = 0b11110000000;
3141  let Inst{4} = 0; // B form
3142  let Inst{3-0} = Rm;
3143
3144  let DecoderMethod = "DecodeThumbTableBranch";
3145}
3146
3147def t2TBH : T2I<(outs), (ins addrmode_tbh:$addr), IIC_Br,
3148                   "tbh", "\t$addr", []> {
3149  bits<4> Rn;
3150  bits<4> Rm;
3151  let Inst{31-20} = 0b111010001101;
3152  let Inst{19-16} = Rn;
3153  let Inst{15-5} = 0b11110000000;
3154  let Inst{4} = 1; // H form
3155  let Inst{3-0} = Rm;
3156
3157  let DecoderMethod = "DecodeThumbTableBranch";
3158}
3159} // isNotDuplicable, isIndirectBranch
3160
3161} // isBranch, isTerminator, isBarrier
3162
3163// FIXME: should be able to write a pattern for ARMBrcond, but can't use
3164// a two-value operand where a dag node expects ", "two operands. :(
3165let isBranch = 1, isTerminator = 1 in
3166def t2Bcc : T2I<(outs), (ins brtarget:$target), IIC_Br,
3167                "b", ".w\t$target",
3168                [/*(ARMbrcond bb:$target, imm:$cc)*/]> {
3169  let Inst{31-27} = 0b11110;
3170  let Inst{15-14} = 0b10;
3171  let Inst{12} = 0;
3172
3173  bits<4> p;
3174  let Inst{25-22} = p;
3175
3176  bits<21> target;
3177  let Inst{26} = target{20};
3178  let Inst{11} = target{19};
3179  let Inst{13} = target{18};
3180  let Inst{21-16} = target{17-12};
3181  let Inst{10-0} = target{11-1};
3182
3183  let DecoderMethod = "DecodeThumb2BCCInstruction";
3184}
3185
3186// Tail calls. The Darwin version of thumb tail calls uses a t2 branch, so
3187// it goes here.
3188let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1 in {
3189  // Darwin version.
3190  let Defs = [R0, R1, R2, R3, R9, R12, QQQQ0, QQQQ2, QQQQ3, PC],
3191      Uses = [SP] in
3192  def tTAILJMPd: tPseudoExpand<(outs),
3193                   (ins uncondbrtarget:$dst, pred:$p, variable_ops),
3194                   4, IIC_Br, [],
3195                   (t2B uncondbrtarget:$dst, pred:$p)>,
3196                 Requires<[IsThumb2, IsDarwin]>;
3197}
3198
3199// IT block
3200let Defs = [ITSTATE] in
3201def t2IT : Thumb2XI<(outs), (ins it_pred:$cc, it_mask:$mask),
3202                    AddrModeNone, 2,  IIC_iALUx,
3203                    "it$mask\t$cc", "", []> {
3204  // 16-bit instruction.
3205  let Inst{31-16} = 0x0000;
3206  let Inst{15-8} = 0b10111111;
3207
3208  bits<4> cc;
3209  bits<4> mask;
3210  let Inst{7-4} = cc;
3211  let Inst{3-0} = mask;
3212
3213  let DecoderMethod = "DecodeIT";
3214}
3215
3216// Branch and Exchange Jazelle -- for disassembly only
3217// Rm = Inst{19-16}
3218def t2BXJ : T2I<(outs), (ins rGPR:$func), NoItinerary, "bxj", "\t$func", []> {
3219  bits<4> func;
3220  let Inst{31-27} = 0b11110;
3221  let Inst{26} = 0;
3222  let Inst{25-20} = 0b111100;
3223  let Inst{19-16} = func;
3224  let Inst{15-0} = 0b1000111100000000;
3225}
3226
3227// Compare and branch on zero / non-zero
3228let isBranch = 1, isTerminator = 1 in {
3229  def tCBZ  : T1I<(outs), (ins tGPR:$Rn, t_cbtarget:$target), IIC_Br,
3230                  "cbz\t$Rn, $target", []>,
3231              T1Misc<{0,0,?,1,?,?,?}>,
3232              Requires<[IsThumb2]> {
3233    // A8.6.27
3234    bits<6> target;
3235    bits<3> Rn;
3236    let Inst{9}   = target{5};
3237    let Inst{7-3} = target{4-0};
3238    let Inst{2-0} = Rn;
3239  }
3240
3241  def tCBNZ : T1I<(outs), (ins tGPR:$Rn, t_cbtarget:$target), IIC_Br,
3242                  "cbnz\t$Rn, $target", []>,
3243              T1Misc<{1,0,?,1,?,?,?}>,
3244              Requires<[IsThumb2]> {
3245    // A8.6.27
3246    bits<6> target;
3247    bits<3> Rn;
3248    let Inst{9}   = target{5};
3249    let Inst{7-3} = target{4-0};
3250    let Inst{2-0} = Rn;
3251  }
3252}
3253
3254
3255// Change Processor State is a system instruction.
3256// FIXME: Since the asm parser has currently no clean way to handle optional
3257// operands, create 3 versions of the same instruction. Once there's a clean
3258// framework to represent optional operands, change this behavior.
3259class t2CPS<dag iops, string asm_op> : T2XI<(outs), iops, NoItinerary,
3260            !strconcat("cps", asm_op), []> {
3261  bits<2> imod;
3262  bits<3> iflags;
3263  bits<5> mode;
3264  bit M;
3265
3266  let Inst{31-27} = 0b11110;
3267  let Inst{26}    = 0;
3268  let Inst{25-20} = 0b111010;
3269  let Inst{19-16} = 0b1111;
3270  let Inst{15-14} = 0b10;
3271  let Inst{12}    = 0;
3272  let Inst{10-9}  = imod;
3273  let Inst{8}     = M;
3274  let Inst{7-5}   = iflags;
3275  let Inst{4-0}   = mode;
3276  let DecoderMethod = "DecodeT2CPSInstruction";
3277}
3278
3279let M = 1 in
3280  def t2CPS3p : t2CPS<(ins imod_op:$imod, iflags_op:$iflags, i32imm:$mode),
3281                      "$imod.w\t$iflags, $mode">;
3282let mode = 0, M = 0 in
3283  def t2CPS2p : t2CPS<(ins imod_op:$imod, iflags_op:$iflags),
3284                      "$imod.w\t$iflags">;
3285let imod = 0, iflags = 0, M = 1 in
3286  def t2CPS1p : t2CPS<(ins imm0_31:$mode), "\t$mode">;
3287
3288// A6.3.4 Branches and miscellaneous control
3289// Table A6-14 Change Processor State, and hint instructions
3290class T2I_hint<bits<8> op7_0, string opc, string asm>
3291  : T2I<(outs), (ins), NoItinerary, opc, asm, []> {
3292  let Inst{31-20} = 0xf3a;
3293  let Inst{19-16} = 0b1111;
3294  let Inst{15-14} = 0b10;
3295  let Inst{12} = 0;
3296  let Inst{10-8} = 0b000;
3297  let Inst{7-0} = op7_0;
3298}
3299
3300def t2NOP   : T2I_hint<0b00000000, "nop",   ".w">;
3301def t2YIELD : T2I_hint<0b00000001, "yield", ".w">;
3302def t2WFE   : T2I_hint<0b00000010, "wfe",   ".w">;
3303def t2WFI   : T2I_hint<0b00000011, "wfi",   ".w">;
3304def t2SEV   : T2I_hint<0b00000100, "sev",   ".w">;
3305
3306def t2DBG : T2I<(outs), (ins imm0_15:$opt), NoItinerary, "dbg", "\t$opt", []> {
3307  bits<4> opt;
3308  let Inst{31-20} = 0b111100111010;
3309  let Inst{19-16} = 0b1111;
3310  let Inst{15-8} = 0b10000000;
3311  let Inst{7-4} = 0b1111;
3312  let Inst{3-0} = opt;
3313}
3314
3315// Secure Monitor Call is a system instruction.
3316// Option = Inst{19-16}
3317def t2SMC : T2I<(outs), (ins imm0_15:$opt), NoItinerary, "smc", "\t$opt", []> {
3318  let Inst{31-27} = 0b11110;
3319  let Inst{26-20} = 0b1111111;
3320  let Inst{15-12} = 0b1000;
3321
3322  bits<4> opt;
3323  let Inst{19-16} = opt;
3324}
3325
3326class T2SRS<bits<2> Op, bit W, dag oops, dag iops, InstrItinClass itin,
3327            string opc, string asm, list<dag> pattern>
3328  : T2I<oops, iops, itin, opc, asm, pattern> {
3329  bits<5> mode;
3330  let Inst{31-25} = 0b1110100;
3331  let Inst{24-23} = Op;
3332  let Inst{22} = 0;
3333  let Inst{21} = W;
3334  let Inst{20-16} = 0b01101;
3335  let Inst{15-5} = 0b11000000000;
3336  let Inst{4-0} = mode{4-0};
3337}
3338
3339// Store Return State is a system instruction.
3340def t2SRSDB_UPD : T2SRS<0b00, 1, (outs), (ins imm0_31:$mode), NoItinerary,
3341                        "srsdb", "\tsp!, $mode", []>;
3342def t2SRSDB  : T2SRS<0b00, 0, (outs), (ins imm0_31:$mode), NoItinerary,
3343                     "srsdb","\tsp, $mode", []>;
3344def t2SRSIA_UPD : T2SRS<0b11, 1, (outs), (ins imm0_31:$mode), NoItinerary,
3345                        "srsia","\tsp!, $mode", []>;
3346def t2SRSIA  : T2SRS<0b11, 0, (outs), (ins imm0_31:$mode), NoItinerary,
3347                     "srsia","\tsp, $mode", []>;
3348
3349// Return From Exception is a system instruction.
3350class T2RFE<bits<12> op31_20, dag oops, dag iops, InstrItinClass itin,
3351          string opc, string asm, list<dag> pattern>
3352  : T2I<oops, iops, itin, opc, asm, pattern> {
3353  let Inst{31-20} = op31_20{11-0};
3354
3355  bits<4> Rn;
3356  let Inst{19-16} = Rn;
3357  let Inst{15-0} = 0xc000;
3358}
3359
3360def t2RFEDBW : T2RFE<0b111010000011,
3361                   (outs), (ins GPR:$Rn), NoItinerary, "rfedb", "\t$Rn!",
3362                   [/* For disassembly only; pattern left blank */]>;
3363def t2RFEDB  : T2RFE<0b111010000001,
3364                   (outs), (ins GPR:$Rn), NoItinerary, "rfedb", "\t$Rn",
3365                   [/* For disassembly only; pattern left blank */]>;
3366def t2RFEIAW : T2RFE<0b111010011011,
3367                   (outs), (ins GPR:$Rn), NoItinerary, "rfeia", "\t$Rn!",
3368                   [/* For disassembly only; pattern left blank */]>;
3369def t2RFEIA  : T2RFE<0b111010011001,
3370                   (outs), (ins GPR:$Rn), NoItinerary, "rfeia", "\t$Rn",
3371                   [/* For disassembly only; pattern left blank */]>;
3372
3373//===----------------------------------------------------------------------===//
3374// Non-Instruction Patterns
3375//
3376
3377// 32-bit immediate using movw + movt.
3378// This is a single pseudo instruction to make it re-materializable.
3379// FIXME: Remove this when we can do generalized remat.
3380let isReMaterializable = 1, isMoveImm = 1 in
3381def t2MOVi32imm : PseudoInst<(outs rGPR:$dst), (ins i32imm:$src), IIC_iMOVix2,
3382                            [(set rGPR:$dst, (i32 imm:$src))]>,
3383                            Requires<[IsThumb, HasV6T2]>;
3384
3385// Pseudo instruction that combines movw + movt + add pc (if pic).
3386// It also makes it possible to rematerialize the instructions.
3387// FIXME: Remove this when we can do generalized remat and when machine licm
3388// can properly the instructions.
3389let isReMaterializable = 1 in {
3390def t2MOV_ga_pcrel : PseudoInst<(outs rGPR:$dst), (ins i32imm:$addr),
3391                                IIC_iMOVix2addpc,
3392                          [(set rGPR:$dst, (ARMWrapperPIC tglobaladdr:$addr))]>,
3393                          Requires<[IsThumb2, UseMovt]>;
3394
3395def t2MOV_ga_dyn : PseudoInst<(outs rGPR:$dst), (ins i32imm:$addr),
3396                              IIC_iMOVix2,
3397                          [(set rGPR:$dst, (ARMWrapperDYN tglobaladdr:$addr))]>,
3398                          Requires<[IsThumb2, UseMovt]>;
3399}
3400
3401// ConstantPool, GlobalAddress, and JumpTable
3402def : T2Pat<(ARMWrapper  tglobaladdr :$dst), (t2LEApcrel tglobaladdr :$dst)>,
3403           Requires<[IsThumb2, DontUseMovt]>;
3404def : T2Pat<(ARMWrapper  tconstpool  :$dst), (t2LEApcrel tconstpool  :$dst)>;
3405def : T2Pat<(ARMWrapper  tglobaladdr :$dst), (t2MOVi32imm tglobaladdr :$dst)>,
3406           Requires<[IsThumb2, UseMovt]>;
3407
3408def : T2Pat<(ARMWrapperJT tjumptable:$dst, imm:$id),
3409            (t2LEApcrelJT tjumptable:$dst, imm:$id)>;
3410
3411// Pseudo instruction that combines ldr from constpool and add pc. This should
3412// be expanded into two instructions late to allow if-conversion and
3413// scheduling.
3414let canFoldAsLoad = 1, isReMaterializable = 1 in
3415def t2LDRpci_pic : PseudoInst<(outs rGPR:$dst), (ins i32imm:$addr, pclabel:$cp),
3416                   IIC_iLoadiALU,
3417              [(set rGPR:$dst, (ARMpic_add (load (ARMWrapper tconstpool:$addr)),
3418                                           imm:$cp))]>,
3419               Requires<[IsThumb2]>;
3420//===----------------------------------------------------------------------===//
3421// Coprocessor load/store -- for disassembly only
3422//
3423class T2CI<dag oops, dag iops, string opc, string asm>
3424  : T2I<oops, iops, NoItinerary, opc, asm, []> {
3425  let Inst{27-25} = 0b110;
3426}
3427
3428multiclass T2LdStCop<bits<4> op31_28, bit load, string opc> {
3429  def _OFFSET : T2CI<(outs),
3430      (ins nohash_imm:$cop, nohash_imm:$CRd, addrmode2:$addr),
3431      opc, "\tp$cop, cr$CRd, $addr"> {
3432    let Inst{31-28} = op31_28;
3433    let Inst{24} = 1; // P = 1
3434    let Inst{21} = 0; // W = 0
3435    let Inst{22} = 0; // D = 0
3436    let Inst{20} = load;
3437    let DecoderMethod = "DecodeCopMemInstruction";
3438  }
3439
3440  def _PRE : T2CI<(outs),
3441      (ins nohash_imm:$cop, nohash_imm:$CRd, addrmode2:$addr),
3442      opc, "\tp$cop, cr$CRd, $addr!"> {
3443    let Inst{31-28} = op31_28;
3444    let Inst{24} = 1; // P = 1
3445    let Inst{21} = 1; // W = 1
3446    let Inst{22} = 0; // D = 0
3447    let Inst{20} = load;
3448    let DecoderMethod = "DecodeCopMemInstruction";
3449  }
3450
3451  def _POST : T2CI<(outs),
3452      (ins nohash_imm:$cop, nohash_imm:$CRd, addrmode2:$addr),
3453      opc, "\tp$cop, cr$CRd, $addr"> {
3454    let Inst{31-28} = op31_28;
3455    let Inst{24} = 0; // P = 0
3456    let Inst{21} = 1; // W = 1
3457    let Inst{22} = 0; // D = 0
3458    let Inst{20} = load;
3459    let DecoderMethod = "DecodeCopMemInstruction";
3460  }
3461
3462  def _OPTION : T2CI<(outs),
3463      (ins nohash_imm:$cop,nohash_imm:$CRd,GPR:$base, nohash_imm:$option),
3464      opc, "\tp$cop, cr$CRd, [$base], \\{$option\\}"> {
3465    let Inst{31-28} = op31_28;
3466    let Inst{24} = 0; // P = 0
3467    let Inst{23} = 1; // U = 1
3468    let Inst{21} = 0; // W = 0
3469    let Inst{22} = 0; // D = 0
3470    let Inst{20} = load;
3471    let DecoderMethod = "DecodeCopMemInstruction";
3472  }
3473
3474  def L_OFFSET : T2CI<(outs),
3475      (ins nohash_imm:$cop, nohash_imm:$CRd, addrmode2:$addr),
3476      !strconcat(opc, "l"), "\tp$cop, cr$CRd, $addr"> {
3477    let Inst{31-28} = op31_28;
3478    let Inst{24} = 1; // P = 1
3479    let Inst{21} = 0; // W = 0
3480    let Inst{22} = 1; // D = 1
3481    let Inst{20} = load;
3482    let DecoderMethod = "DecodeCopMemInstruction";
3483  }
3484
3485  def L_PRE : T2CI<(outs),
3486      (ins nohash_imm:$cop, nohash_imm:$CRd, addrmode2:$addr),
3487      !strconcat(opc, "l"), "\tp$cop, cr$CRd, $addr!"> {
3488    let Inst{31-28} = op31_28;
3489    let Inst{24} = 1; // P = 1
3490    let Inst{21} = 1; // W = 1
3491    let Inst{22} = 1; // D = 1
3492    let Inst{20} = load;
3493    let DecoderMethod = "DecodeCopMemInstruction";
3494  }
3495
3496  def L_POST : T2CI<(outs),
3497      (ins nohash_imm:$cop, nohash_imm:$CRd, addr_offset_none:$addr,
3498            postidx_imm8s4:$offset),
3499      !strconcat(opc, "l"), "\tp$cop, cr$CRd, $addr, $offset"> {
3500    let Inst{31-28} = op31_28;
3501    let Inst{24} = 0; // P = 0
3502    let Inst{21} = 1; // W = 1
3503    let Inst{22} = 1; // D = 1
3504    let Inst{20} = load;
3505    let DecoderMethod = "DecodeCopMemInstruction";
3506  }
3507
3508  def L_OPTION : T2CI<(outs),
3509      (ins nohash_imm:$cop, nohash_imm:$CRd,GPR:$base,nohash_imm:$option),
3510      !strconcat(opc, "l"), "\tp$cop, cr$CRd, [$base], \\{$option\\}"> {
3511    let Inst{31-28} = op31_28;
3512    let Inst{24} = 0; // P = 0
3513    let Inst{23} = 1; // U = 1
3514    let Inst{21} = 0; // W = 0
3515    let Inst{22} = 1; // D = 1
3516    let Inst{20} = load;
3517    let DecoderMethod = "DecodeCopMemInstruction";
3518  }
3519}
3520
3521defm t2LDC  : T2LdStCop<0b1111, 1, "ldc">;
3522defm t2STC  : T2LdStCop<0b1111, 0, "stc">;
3523
3524
3525//===----------------------------------------------------------------------===//
3526// Move between special register and ARM core register -- for disassembly only
3527//
3528// Move to ARM core register from Special Register
3529def t2MRS : T2I<(outs GPR:$Rd), (ins), NoItinerary, "mrs", "\t$Rd, apsr", []> {
3530  bits<4> Rd;
3531  let Inst{31-12} = 0b11110011111011111000;
3532  let Inst{11-8} = Rd;
3533  let Inst{7-0} = 0b0000;
3534}
3535
3536def : t2InstAlias<"mrs${p} $Rd, cpsr", (t2MRS GPR:$Rd, pred:$p)>;
3537
3538def t2MRSsys:T2I<(outs GPR:$Rd), (ins), NoItinerary, "mrs", "\t$Rd, spsr", []> {
3539  bits<4> Rd;
3540  let Inst{31-12} = 0b11110011111111111000;
3541  let Inst{11-8} = Rd;
3542  let Inst{7-0} = 0b0000;
3543}
3544
3545// Move from ARM core register to Special Register
3546//
3547// No need to have both system and application versions, the encodings are the
3548// same and the assembly parser has no way to distinguish between them. The mask
3549// operand contains the special register (R Bit) in bit 4 and bits 3-0 contains
3550// the mask with the fields to be accessed in the special register.
3551def t2MSR : T2I<(outs), (ins msr_mask:$mask, rGPR:$Rn),
3552                NoItinerary, "msr", "\t$mask, $Rn", []> {
3553  bits<5> mask;
3554  bits<4> Rn;
3555  let Inst{31-21} = 0b11110011100;
3556  let Inst{20}    = mask{4}; // R Bit
3557  let Inst{19-16} = Rn;
3558  let Inst{15-12} = 0b1000;
3559  let Inst{11-8}  = mask{3-0};
3560  let Inst{7-0}   = 0;
3561}
3562
3563//===----------------------------------------------------------------------===//
3564// Move between coprocessor and ARM core register
3565//
3566
3567class t2MovRCopro<bits<4> Op, string opc, bit direction, dag oops, dag iops,
3568                  list<dag> pattern>
3569  : T2Cop<Op, oops, iops,
3570          !strconcat(opc, "\t$cop, $opc1, $Rt, $CRn, $CRm, $opc2"),
3571          pattern> {
3572  let Inst{27-24} = 0b1110;
3573  let Inst{20} = direction;
3574  let Inst{4} = 1;
3575
3576  bits<4> Rt;
3577  bits<4> cop;
3578  bits<3> opc1;
3579  bits<3> opc2;
3580  bits<4> CRm;
3581  bits<4> CRn;
3582
3583  let Inst{15-12} = Rt;
3584  let Inst{11-8}  = cop;
3585  let Inst{23-21} = opc1;
3586  let Inst{7-5}   = opc2;
3587  let Inst{3-0}   = CRm;
3588  let Inst{19-16} = CRn;
3589}
3590
3591class t2MovRRCopro<bits<4> Op, string opc, bit direction,
3592                   list<dag> pattern = []>
3593  : T2Cop<Op, (outs),
3594          (ins p_imm:$cop, imm0_15:$opc1, GPR:$Rt, GPR:$Rt2, c_imm:$CRm),
3595          !strconcat(opc, "\t$cop, $opc1, $Rt, $Rt2, $CRm"), pattern> {
3596  let Inst{27-24} = 0b1100;
3597  let Inst{23-21} = 0b010;
3598  let Inst{20} = direction;
3599
3600  bits<4> Rt;
3601  bits<4> Rt2;
3602  bits<4> cop;
3603  bits<4> opc1;
3604  bits<4> CRm;
3605
3606  let Inst{15-12} = Rt;
3607  let Inst{19-16} = Rt2;
3608  let Inst{11-8}  = cop;
3609  let Inst{7-4}   = opc1;
3610  let Inst{3-0}   = CRm;
3611}
3612
3613/* from ARM core register to coprocessor */
3614def t2MCR : t2MovRCopro<0b1110, "mcr", 0,
3615           (outs),
3616           (ins p_imm:$cop, imm0_7:$opc1, GPR:$Rt, c_imm:$CRn,
3617                c_imm:$CRm, imm0_7:$opc2),
3618           [(int_arm_mcr imm:$cop, imm:$opc1, GPR:$Rt, imm:$CRn,
3619                         imm:$CRm, imm:$opc2)]>;
3620def t2MCR2 : t2MovRCopro<0b1111, "mcr2", 0,
3621             (outs), (ins p_imm:$cop, imm0_7:$opc1, GPR:$Rt, c_imm:$CRn,
3622                          c_imm:$CRm, imm0_7:$opc2),
3623             [(int_arm_mcr2 imm:$cop, imm:$opc1, GPR:$Rt, imm:$CRn,
3624                            imm:$CRm, imm:$opc2)]>;
3625
3626/* from coprocessor to ARM core register */
3627def t2MRC : t2MovRCopro<0b1110, "mrc", 1,
3628             (outs GPR:$Rt), (ins p_imm:$cop, imm0_7:$opc1, c_imm:$CRn,
3629                                  c_imm:$CRm, imm0_7:$opc2), []>;
3630
3631def t2MRC2 : t2MovRCopro<0b1111, "mrc2", 1,
3632             (outs GPR:$Rt), (ins p_imm:$cop, imm0_7:$opc1, c_imm:$CRn,
3633                                  c_imm:$CRm, imm0_7:$opc2), []>;
3634
3635def : T2v6Pat<(int_arm_mrc  imm:$cop, imm:$opc1, imm:$CRn, imm:$CRm, imm:$opc2),
3636              (t2MRC imm:$cop, imm:$opc1, imm:$CRn, imm:$CRm, imm:$opc2)>;
3637
3638def : T2v6Pat<(int_arm_mrc2 imm:$cop, imm:$opc1, imm:$CRn, imm:$CRm, imm:$opc2),
3639              (t2MRC2 imm:$cop, imm:$opc1, imm:$CRn, imm:$CRm, imm:$opc2)>;
3640
3641
3642/* from ARM core register to coprocessor */
3643def t2MCRR : t2MovRRCopro<0b1110, "mcrr", 0,
3644                        [(int_arm_mcrr imm:$cop, imm:$opc1, GPR:$Rt, GPR:$Rt2,
3645                                       imm:$CRm)]>;
3646def t2MCRR2 : t2MovRRCopro<0b1111, "mcrr2", 0,
3647                           [(int_arm_mcrr2 imm:$cop, imm:$opc1, GPR:$Rt,
3648                                           GPR:$Rt2, imm:$CRm)]>;
3649/* from coprocessor to ARM core register */
3650def t2MRRC : t2MovRRCopro<0b1110, "mrrc", 1>;
3651
3652def t2MRRC2 : t2MovRRCopro<0b1111, "mrrc2", 1>;
3653
3654//===----------------------------------------------------------------------===//
3655// Other Coprocessor Instructions.
3656//
3657
3658def tCDP : T2Cop<0b1110, (outs), (ins p_imm:$cop, imm0_15:$opc1,
3659                 c_imm:$CRd, c_imm:$CRn, c_imm:$CRm, imm0_7:$opc2),
3660                 "cdp\t$cop, $opc1, $CRd, $CRn, $CRm, $opc2",
3661                 [(int_arm_cdp imm:$cop, imm:$opc1, imm:$CRd, imm:$CRn,
3662                               imm:$CRm, imm:$opc2)]> {
3663  let Inst{27-24} = 0b1110;
3664
3665  bits<4> opc1;
3666  bits<4> CRn;
3667  bits<4> CRd;
3668  bits<4> cop;
3669  bits<3> opc2;
3670  bits<4> CRm;
3671
3672  let Inst{3-0}   = CRm;
3673  let Inst{4}     = 0;
3674  let Inst{7-5}   = opc2;
3675  let Inst{11-8}  = cop;
3676  let Inst{15-12} = CRd;
3677  let Inst{19-16} = CRn;
3678  let Inst{23-20} = opc1;
3679}
3680
3681def t2CDP2 : T2Cop<0b1111, (outs), (ins p_imm:$cop, imm0_15:$opc1,
3682                   c_imm:$CRd, c_imm:$CRn, c_imm:$CRm, imm0_7:$opc2),
3683                   "cdp2\t$cop, $opc1, $CRd, $CRn, $CRm, $opc2",
3684                   [(int_arm_cdp2 imm:$cop, imm:$opc1, imm:$CRd, imm:$CRn,
3685                                  imm:$CRm, imm:$opc2)]> {
3686  let Inst{27-24} = 0b1110;
3687
3688  bits<4> opc1;
3689  bits<4> CRn;
3690  bits<4> CRd;
3691  bits<4> cop;
3692  bits<3> opc2;
3693  bits<4> CRm;
3694
3695  let Inst{3-0}   = CRm;
3696  let Inst{4}     = 0;
3697  let Inst{7-5}   = opc2;
3698  let Inst{11-8}  = cop;
3699  let Inst{15-12} = CRd;
3700  let Inst{19-16} = CRn;
3701  let Inst{23-20} = opc1;
3702}
3703
3704
3705
3706//===----------------------------------------------------------------------===//
3707// Non-Instruction Patterns
3708//
3709
3710// SXT/UXT with no rotate
3711let AddedComplexity = 16 in {
3712def : T2Pat<(and rGPR:$Rm, 0x000000FF), (t2UXTB rGPR:$Rm, 0)>,
3713           Requires<[IsThumb2]>;
3714def : T2Pat<(and rGPR:$Rm, 0x0000FFFF), (t2UXTH rGPR:$Rm, 0)>,
3715           Requires<[IsThumb2]>;
3716def : T2Pat<(and rGPR:$Rm, 0x00FF00FF), (t2UXTB16 rGPR:$Rm, 0)>,
3717           Requires<[HasT2ExtractPack, IsThumb2]>;
3718def : T2Pat<(add rGPR:$Rn, (and rGPR:$Rm, 0x00FF)),
3719            (t2UXTAB rGPR:$Rn, rGPR:$Rm, 0)>,
3720           Requires<[HasT2ExtractPack, IsThumb2]>;
3721def : T2Pat<(add rGPR:$Rn, (and rGPR:$Rm, 0xFFFF)),
3722            (t2UXTAH rGPR:$Rn, rGPR:$Rm, 0)>,
3723           Requires<[HasT2ExtractPack, IsThumb2]>;
3724}
3725
3726def : T2Pat<(sext_inreg rGPR:$Src, i8),  (t2SXTB rGPR:$Src, 0)>,
3727           Requires<[IsThumb2]>;
3728def : T2Pat<(sext_inreg rGPR:$Src, i16), (t2SXTH rGPR:$Src, 0)>,
3729           Requires<[IsThumb2]>;
3730def : T2Pat<(add rGPR:$Rn, (sext_inreg rGPR:$Rm, i8)),
3731            (t2SXTAB rGPR:$Rn, rGPR:$Rm, 0)>,
3732           Requires<[HasT2ExtractPack, IsThumb2]>;
3733def : T2Pat<(add rGPR:$Rn, (sext_inreg rGPR:$Rm, i16)),
3734            (t2SXTAH rGPR:$Rn, rGPR:$Rm, 0)>,
3735           Requires<[HasT2ExtractPack, IsThumb2]>;
3736
3737// Atomic load/store patterns
3738def : T2Pat<(atomic_load_8   t2addrmode_imm12:$addr),
3739            (t2LDRBi12  t2addrmode_imm12:$addr)>;
3740def : T2Pat<(atomic_load_8   t2addrmode_negimm8:$addr),
3741            (t2LDRBi8   t2addrmode_negimm8:$addr)>;
3742def : T2Pat<(atomic_load_8   t2addrmode_so_reg:$addr),
3743            (t2LDRBs    t2addrmode_so_reg:$addr)>;
3744def : T2Pat<(atomic_load_16  t2addrmode_imm12:$addr),
3745            (t2LDRHi12  t2addrmode_imm12:$addr)>;
3746def : T2Pat<(atomic_load_16  t2addrmode_negimm8:$addr),
3747            (t2LDRHi8   t2addrmode_negimm8:$addr)>;
3748def : T2Pat<(atomic_load_16  t2addrmode_so_reg:$addr),
3749            (t2LDRHs    t2addrmode_so_reg:$addr)>;
3750def : T2Pat<(atomic_load_32  t2addrmode_imm12:$addr),
3751            (t2LDRi12   t2addrmode_imm12:$addr)>;
3752def : T2Pat<(atomic_load_32  t2addrmode_negimm8:$addr),
3753            (t2LDRi8    t2addrmode_negimm8:$addr)>;
3754def : T2Pat<(atomic_load_32  t2addrmode_so_reg:$addr),
3755            (t2LDRs     t2addrmode_so_reg:$addr)>;
3756def : T2Pat<(atomic_store_8  t2addrmode_imm12:$addr, GPR:$val),
3757            (t2STRBi12  GPR:$val, t2addrmode_imm12:$addr)>;
3758def : T2Pat<(atomic_store_8  t2addrmode_negimm8:$addr, GPR:$val),
3759            (t2STRBi8   GPR:$val, t2addrmode_negimm8:$addr)>;
3760def : T2Pat<(atomic_store_8  t2addrmode_so_reg:$addr, GPR:$val),
3761            (t2STRBs    GPR:$val, t2addrmode_so_reg:$addr)>;
3762def : T2Pat<(atomic_store_16 t2addrmode_imm12:$addr, GPR:$val),
3763            (t2STRHi12  GPR:$val, t2addrmode_imm12:$addr)>;
3764def : T2Pat<(atomic_store_16 t2addrmode_negimm8:$addr, GPR:$val),
3765            (t2STRHi8   GPR:$val, t2addrmode_negimm8:$addr)>;
3766def : T2Pat<(atomic_store_16 t2addrmode_so_reg:$addr, GPR:$val),
3767            (t2STRHs    GPR:$val, t2addrmode_so_reg:$addr)>;
3768def : T2Pat<(atomic_store_32 t2addrmode_imm12:$addr, GPR:$val),
3769            (t2STRi12   GPR:$val, t2addrmode_imm12:$addr)>;
3770def : T2Pat<(atomic_store_32 t2addrmode_negimm8:$addr, GPR:$val),
3771            (t2STRi8    GPR:$val, t2addrmode_negimm8:$addr)>;
3772def : T2Pat<(atomic_store_32 t2addrmode_so_reg:$addr, GPR:$val),
3773            (t2STRs     GPR:$val, t2addrmode_so_reg:$addr)>;
3774
3775
3776//===----------------------------------------------------------------------===//
3777// Assembler aliases
3778//
3779
3780// Aliases for ADC without the ".w" optional width specifier.
3781def : t2InstAlias<"adc${s}${p} $Rd, $Rn, $Rm",
3782                  (t2ADCrr rGPR:$Rd, rGPR:$Rn, rGPR:$Rm, pred:$p, cc_out:$s)>;
3783def : t2InstAlias<"adc${s}${p} $Rd, $Rn, $ShiftedRm",
3784                  (t2ADCrs rGPR:$Rd, rGPR:$Rn, t2_so_reg:$ShiftedRm,
3785                           pred:$p, cc_out:$s)>;
3786
3787// Aliases for SBC without the ".w" optional width specifier.
3788def : t2InstAlias<"sbc${s}${p} $Rd, $Rn, $Rm",
3789                  (t2SBCrr rGPR:$Rd, rGPR:$Rn, rGPR:$Rm, pred:$p, cc_out:$s)>;
3790def : t2InstAlias<"sbc${s}${p} $Rd, $Rn, $ShiftedRm",
3791                  (t2SBCrs rGPR:$Rd, rGPR:$Rn, t2_so_reg:$ShiftedRm,
3792                           pred:$p, cc_out:$s)>;
3793
3794// Aliases for ADD without the ".w" optional width specifier.
3795def : t2InstAlias<"add${s}${p} $Rd, $Rn, $imm",
3796           (t2ADDri rGPR:$Rd, GPRnopc:$Rn, t2_so_imm:$imm, pred:$p, cc_out:$s)>;
3797def : t2InstAlias<"add${p} $Rd, $Rn, $imm",
3798           (t2ADDri12 rGPR:$Rd, GPR:$Rn, imm0_4095:$imm, pred:$p)>;
3799def : t2InstAlias<"add${s}${p} $Rd, $Rn, $Rm",
3800                 (t2ADDrr rGPR:$Rd, GPRnopc:$Rn, rGPR:$Rm, pred:$p, cc_out:$s)>;
3801def : t2InstAlias<"add${s}${p} $Rd, $Rn, $ShiftedRm",
3802                  (t2ADDrs rGPR:$Rd, GPRnopc:$Rn, t2_so_reg:$ShiftedRm,
3803                           pred:$p, cc_out:$s)>;
3804
3805// Aliases for SUB without the ".w" optional width specifier.
3806def : t2InstAlias<"sub${s}${p} $Rd, $Rn, $imm",
3807           (t2SUBri rGPR:$Rd, GPRnopc:$Rn, t2_so_imm:$imm, pred:$p, cc_out:$s)>;
3808def : t2InstAlias<"sub${p} $Rd, $Rn, $imm",
3809           (t2SUBri12 rGPR:$Rd, GPR:$Rn, imm0_4095:$imm, pred:$p)>;
3810def : t2InstAlias<"sub${s}${p} $Rd, $Rn, $Rm",
3811                 (t2SUBrr rGPR:$Rd, GPRnopc:$Rn, rGPR:$Rm, pred:$p, cc_out:$s)>;
3812def : t2InstAlias<"sub${s}${p} $Rd, $Rn, $ShiftedRm",
3813                  (t2SUBrs rGPR:$Rd, GPRnopc:$Rn, t2_so_reg:$ShiftedRm,
3814                           pred:$p, cc_out:$s)>;
3815
3816// Alias for compares without the ".w" optional width specifier.
3817def : t2InstAlias<"cmn${p} $Rn, $Rm",
3818                  (t2CMNzrr GPRnopc:$Rn, rGPR:$Rm, pred:$p)>;
3819def : t2InstAlias<"teq${p} $Rn, $Rm",
3820                  (t2TEQrr GPRnopc:$Rn, rGPR:$Rm, pred:$p)>;
3821def : t2InstAlias<"tst${p} $Rn, $Rm",
3822                  (t2TSTrr GPRnopc:$Rn, rGPR:$Rm, pred:$p)>;
3823
3824// Memory barriers
3825def : InstAlias<"dmb", (t2DMB 0xf)>, Requires<[IsThumb2, HasDB]>;
3826def : InstAlias<"dsb", (t2DSB 0xf)>, Requires<[IsThumb2, HasDB]>;
3827def : InstAlias<"isb", (t2ISB 0xf)>, Requires<[IsThumb2, HasDB]>;
3828
3829// Alias for LDR, LDRB, LDRH, LDRSB, and LDRSH without the ".w" optional
3830// width specifier.
3831def : t2InstAlias<"ldr${p} $Rt, $addr",
3832                  (t2LDRi12 GPR:$Rt, t2addrmode_imm12:$addr, pred:$p)>;
3833def : t2InstAlias<"ldrb${p} $Rt, $addr",
3834                  (t2LDRBi12 rGPR:$Rt, t2addrmode_imm12:$addr, pred:$p)>;
3835def : t2InstAlias<"ldrh${p} $Rt, $addr",
3836                  (t2LDRHi12 rGPR:$Rt, t2addrmode_imm12:$addr, pred:$p)>;
3837def : t2InstAlias<"ldrsb${p} $Rt, $addr",
3838                  (t2LDRSBi12 rGPR:$Rt, t2addrmode_imm12:$addr, pred:$p)>;
3839def : t2InstAlias<"ldrsh${p} $Rt, $addr",
3840                  (t2LDRSHi12 rGPR:$Rt, t2addrmode_imm12:$addr, pred:$p)>;
3841
3842def : t2InstAlias<"ldr${p} $Rt, $addr",
3843                  (t2LDRs GPR:$Rt, t2addrmode_so_reg:$addr, pred:$p)>;
3844def : t2InstAlias<"ldrb${p} $Rt, $addr",
3845                  (t2LDRBs rGPR:$Rt, t2addrmode_so_reg:$addr, pred:$p)>;
3846def : t2InstAlias<"ldrh${p} $Rt, $addr",
3847                  (t2LDRHs rGPR:$Rt, t2addrmode_so_reg:$addr, pred:$p)>;
3848def : t2InstAlias<"ldrsb${p} $Rt, $addr",
3849                  (t2LDRSBs rGPR:$Rt, t2addrmode_so_reg:$addr, pred:$p)>;
3850def : t2InstAlias<"ldrsh${p} $Rt, $addr",
3851                  (t2LDRSHs rGPR:$Rt, t2addrmode_so_reg:$addr, pred:$p)>;
3852
3853// Alias for MVN without the ".w" optional width specifier.
3854def : t2InstAlias<"mvn${s}${p} $Rd, $Rm",
3855           (t2MVNr rGPR:$Rd, rGPR:$Rm, pred:$p, cc_out:$s)>;
3856def : t2InstAlias<"mvn${s}${p} $Rd, $ShiftedRm",
3857           (t2MVNs rGPR:$Rd, t2_so_reg:$ShiftedRm, pred:$p, cc_out:$s)>;
3858
3859// PKHBT/PKHTB with default shift amount. PKHTB is equivalent to PKHBT when the
3860// shift amount is zero (i.e., unspecified).
3861def : InstAlias<"pkhbt${p} $Rd, $Rn, $Rm",
3862                (t2PKHBT rGPR:$Rd, rGPR:$Rn, rGPR:$Rm, 0, pred:$p)>,
3863            Requires<[HasT2ExtractPack, IsThumb2]>;
3864def : InstAlias<"pkhtb${p} $Rd, $Rn, $Rm",
3865                (t2PKHBT rGPR:$Rd, rGPR:$Rn, rGPR:$Rm, 0, pred:$p)>,
3866            Requires<[HasT2ExtractPack, IsThumb2]>;
3867
3868// PUSH/POP aliases for STM/LDM
3869def : t2InstAlias<"push${p}.w $regs", (t2STMDB_UPD SP, pred:$p, reglist:$regs)>;
3870def : t2InstAlias<"push${p} $regs", (t2STMDB_UPD SP, pred:$p, reglist:$regs)>;
3871def : t2InstAlias<"pop${p}.w $regs", (t2LDMIA_UPD SP, pred:$p, reglist:$regs)>;
3872def : t2InstAlias<"pop${p} $regs", (t2LDMIA_UPD SP, pred:$p, reglist:$regs)>;
3873
3874// Alias for REV/REV16/REVSH without the ".w" optional width specifier.
3875def : t2InstAlias<"rev${p} $Rd, $Rm", (t2REV rGPR:$Rd, rGPR:$Rm, pred:$p)>;
3876def : t2InstAlias<"rev16${p} $Rd, $Rm", (t2REV16 rGPR:$Rd, rGPR:$Rm, pred:$p)>;
3877def : t2InstAlias<"revsh${p} $Rd, $Rm", (t2REVSH rGPR:$Rd, rGPR:$Rm, pred:$p)>;
3878
3879
3880// Alias for RSB without the ".w" optional width specifier, and with optional
3881// implied destination register.
3882def : t2InstAlias<"rsb${s}${p} $Rd, $Rn, $imm",
3883           (t2RSBri rGPR:$Rd, rGPR:$Rn, t2_so_imm:$imm, pred:$p, cc_out:$s)>;
3884def : t2InstAlias<"rsb${s}${p} $Rdn, $imm",
3885           (t2RSBri rGPR:$Rdn, rGPR:$Rdn, t2_so_imm:$imm, pred:$p, cc_out:$s)>;
3886def : t2InstAlias<"rsb${s}${p} $Rdn, $Rm",
3887           (t2RSBrr rGPR:$Rdn, rGPR:$Rdn, rGPR:$Rm, pred:$p, cc_out:$s)>;
3888def : t2InstAlias<"rsb${s}${p} $Rdn, $ShiftedRm",
3889           (t2RSBrs rGPR:$Rdn, rGPR:$Rdn, t2_so_reg:$ShiftedRm, pred:$p,
3890                    cc_out:$s)>;
3891
3892// SSAT/USAT optional shift operand.
3893def : t2InstAlias<"ssat${p} $Rd, $sat_imm, $Rn",
3894                  (t2SSAT rGPR:$Rd, imm1_32:$sat_imm, rGPR:$Rn, 0, pred:$p)>;
3895def : t2InstAlias<"usat${p} $Rd, $sat_imm, $Rn",
3896                  (t2USAT rGPR:$Rd, imm0_31:$sat_imm, rGPR:$Rn, 0, pred:$p)>;
3897
3898// STM w/o the .w suffix.
3899def : t2InstAlias<"stm${p} $Rn, $regs",
3900                  (t2STMIA GPR:$Rn, pred:$p, reglist:$regs)>;
3901
3902// Alias for STR, STRB, and STRH without the ".w" optional
3903// width specifier.
3904def : t2InstAlias<"str${p} $Rt, $addr",
3905                  (t2STRi12 GPR:$Rt, t2addrmode_imm12:$addr, pred:$p)>;
3906def : t2InstAlias<"strb${p} $Rt, $addr",
3907                  (t2STRBi12 rGPR:$Rt, t2addrmode_imm12:$addr, pred:$p)>;
3908def : t2InstAlias<"strh${p} $Rt, $addr",
3909                  (t2STRHi12 rGPR:$Rt, t2addrmode_imm12:$addr, pred:$p)>;
3910
3911def : t2InstAlias<"str${p} $Rt, $addr",
3912                  (t2STRs GPR:$Rt, t2addrmode_so_reg:$addr, pred:$p)>;
3913def : t2InstAlias<"strb${p} $Rt, $addr",
3914                  (t2STRBs rGPR:$Rt, t2addrmode_so_reg:$addr, pred:$p)>;
3915def : t2InstAlias<"strh${p} $Rt, $addr",
3916                  (t2STRHs rGPR:$Rt, t2addrmode_so_reg:$addr, pred:$p)>;
3917
3918// Extend instruction optional rotate operand.
3919def : t2InstAlias<"sxtab${p} $Rd, $Rn, $Rm",
3920                (t2SXTAB rGPR:$Rd, rGPR:$Rn, rGPR:$Rm, 0, pred:$p)>;
3921def : t2InstAlias<"sxtah${p} $Rd, $Rn, $Rm",
3922                (t2SXTAH rGPR:$Rd, rGPR:$Rn, rGPR:$Rm, 0, pred:$p)>;
3923def : t2InstAlias<"sxtab16${p} $Rd, $Rn, $Rm",
3924                (t2SXTAB16 rGPR:$Rd, rGPR:$Rn, rGPR:$Rm, 0, pred:$p)>;
3925def : t2InstAlias<"sxtb${p} $Rd, $Rm",
3926                (t2SXTB rGPR:$Rd, rGPR:$Rm, 0, pred:$p)>;
3927def : t2InstAlias<"sxtb16${p} $Rd, $Rm",
3928                (t2SXTB16 rGPR:$Rd, rGPR:$Rm, 0, pred:$p)>;
3929def : t2InstAlias<"sxth${p} $Rd, $Rm",
3930                (t2SXTH rGPR:$Rd, rGPR:$Rm, 0, pred:$p)>;
3931
3932def : t2InstAlias<"uxtab${p} $Rd, $Rn, $Rm",
3933                (t2UXTAB rGPR:$Rd, rGPR:$Rn, rGPR:$Rm, 0, pred:$p)>;
3934def : t2InstAlias<"uxtah${p} $Rd, $Rn, $Rm",
3935                (t2UXTAH rGPR:$Rd, rGPR:$Rn, rGPR:$Rm, 0, pred:$p)>;
3936def : t2InstAlias<"uxtab16${p} $Rd, $Rn, $Rm",
3937                (t2UXTAB16 rGPR:$Rd, rGPR:$Rn, rGPR:$Rm, 0, pred:$p)>;
3938def : t2InstAlias<"uxtb${p} $Rd, $Rm",
3939                (t2UXTB rGPR:$Rd, rGPR:$Rm, 0, pred:$p)>;
3940def : t2InstAlias<"uxtb16${p} $Rd, $Rm",
3941                (t2UXTB16 rGPR:$Rd, rGPR:$Rm, 0, pred:$p)>;
3942def : t2InstAlias<"uxth${p} $Rd, $Rm",
3943                (t2UXTH rGPR:$Rd, rGPR:$Rm, 0, pred:$p)>;
3944
3945// Extend instruction w/o the ".w" optional width specifier.
3946def : t2InstAlias<"uxtb${p} $Rd, $Rm$rot",
3947                  (t2UXTB rGPR:$Rd, rGPR:$Rm, rot_imm:$rot, pred:$p)>;
3948def : t2InstAlias<"uxtb16${p} $Rd, $Rm$rot",
3949                  (t2UXTB16 rGPR:$Rd, rGPR:$Rm, rot_imm:$rot, pred:$p)>;
3950def : t2InstAlias<"uxth${p} $Rd, $Rm$rot",
3951                  (t2UXTH rGPR:$Rd, rGPR:$Rm, rot_imm:$rot, pred:$p)>;
3952
3953def : t2InstAlias<"sxtb${p} $Rd, $Rm$rot",
3954                  (t2SXTB rGPR:$Rd, rGPR:$Rm, rot_imm:$rot, pred:$p)>;
3955def : t2InstAlias<"sxtb16${p} $Rd, $Rm$rot",
3956                  (t2SXTB16 rGPR:$Rd, rGPR:$Rm, rot_imm:$rot, pred:$p)>;
3957def : t2InstAlias<"sxth${p} $Rd, $Rm$rot",
3958                  (t2SXTH rGPR:$Rd, rGPR:$Rm, rot_imm:$rot, pred:$p)>;
3959