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