Refact ARM Thumb1 tMOVr instruction family.
[oota-llvm.git] / lib / Target / ARM / ARMInstrThumb.td
1 //===- ARMInstrThumb.td - Thumb support for ARM ------------*- tablegen -*-===//
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 Thumb instruction set.
11 //
12 //===----------------------------------------------------------------------===//
13
14 //===----------------------------------------------------------------------===//
15 // Thumb specific DAG Nodes.
16 //
17
18 def ARMtcall : SDNode<"ARMISD::tCALL", SDT_ARMcall,
19                       [SDNPHasChain, SDNPOptInGlue, SDNPOutGlue,
20                        SDNPVariadic]>;
21
22 def imm_neg_XFORM : SDNodeXForm<imm, [{
23   return CurDAG->getTargetConstant(-(int)N->getZExtValue(), MVT::i32);
24 }]>;
25 def imm_comp_XFORM : SDNodeXForm<imm, [{
26   return CurDAG->getTargetConstant(~((uint32_t)N->getZExtValue()), MVT::i32);
27 }]>;
28
29 /// imm0_7 predicate - True if the 32-bit immediate is in the range [0,7].
30 def imm0_7 : ImmLeaf<i32, [{
31   return Imm >= 0 && Imm < 8;
32 }]>;
33 def imm0_7_neg : PatLeaf<(i32 imm), [{
34   return (uint32_t)-N->getZExtValue() < 8;
35 }], imm_neg_XFORM>;
36
37 def imm0_255_asmoperand : AsmOperandClass { let Name = "Imm0_255"; }
38 def imm0_255 : Operand<i32>, ImmLeaf<i32, [{ return Imm >= 0 && Imm < 256; }]> {
39   let ParserMatchClass = imm0_255_asmoperand;
40 }
41 def imm0_255_comp : PatLeaf<(i32 imm), [{
42   return ~((uint32_t)N->getZExtValue()) < 256;
43 }]>;
44
45 def imm8_255 : ImmLeaf<i32, [{
46   return Imm >= 8 && Imm < 256;
47 }]>;
48 def imm8_255_neg : PatLeaf<(i32 imm), [{
49   unsigned Val = -N->getZExtValue();
50   return Val >= 8 && Val < 256;
51 }], imm_neg_XFORM>;
52
53 // Break imm's up into two pieces: an immediate + a left shift. This uses
54 // thumb_immshifted to match and thumb_immshifted_val and thumb_immshifted_shamt
55 // to get the val/shift pieces.
56 def thumb_immshifted : PatLeaf<(imm), [{
57   return ARM_AM::isThumbImmShiftedVal((unsigned)N->getZExtValue());
58 }]>;
59
60 def thumb_immshifted_val : SDNodeXForm<imm, [{
61   unsigned V = ARM_AM::getThumbImmNonShiftedVal((unsigned)N->getZExtValue());
62   return CurDAG->getTargetConstant(V, MVT::i32);
63 }]>;
64
65 def thumb_immshifted_shamt : SDNodeXForm<imm, [{
66   unsigned V = ARM_AM::getThumbImmValShift((unsigned)N->getZExtValue());
67   return CurDAG->getTargetConstant(V, MVT::i32);
68 }]>;
69
70 // ADR instruction labels.
71 def t_adrlabel : Operand<i32> {
72   let EncoderMethod = "getThumbAdrLabelOpValue";
73 }
74
75 // Scaled 4 immediate.
76 def t_imm_s4 : Operand<i32> {
77   let PrintMethod = "printThumbS4ImmOperand";
78 }
79
80 // Define Thumb specific addressing modes.
81
82 def t_brtarget : Operand<OtherVT> {
83   let EncoderMethod = "getThumbBRTargetOpValue";
84 }
85
86 def t_bcctarget : Operand<i32> {
87   let EncoderMethod = "getThumbBCCTargetOpValue";
88 }
89
90 def t_cbtarget : Operand<i32> {
91   let EncoderMethod = "getThumbCBTargetOpValue";
92 }
93
94 def t_bltarget : Operand<i32> {
95   let EncoderMethod = "getThumbBLTargetOpValue";
96 }
97
98 def t_blxtarget : Operand<i32> {
99   let EncoderMethod = "getThumbBLXTargetOpValue";
100 }
101
102 def MemModeRegThumbAsmOperand : AsmOperandClass {
103   let Name = "MemModeRegThumb";
104   let SuperClasses = [];
105 }
106
107 def MemModeImmThumbAsmOperand : AsmOperandClass {
108   let Name = "MemModeImmThumb";
109   let SuperClasses = [];
110 }
111
112 // t_addrmode_rr := reg + reg
113 //
114 def t_addrmode_rr : Operand<i32>,
115                     ComplexPattern<i32, 2, "SelectThumbAddrModeRR", []> {
116   let EncoderMethod = "getThumbAddrModeRegRegOpValue";
117   let PrintMethod = "printThumbAddrModeRROperand";
118   let MIOperandInfo = (ops tGPR:$base, tGPR:$offsreg);
119 }
120
121 // t_addrmode_rrs := reg + reg
122 //
123 def t_addrmode_rrs1 : Operand<i32>,
124                       ComplexPattern<i32, 2, "SelectThumbAddrModeRI5S1", []> {
125   let EncoderMethod = "getThumbAddrModeRegRegOpValue";
126   let PrintMethod = "printThumbAddrModeRROperand";
127   let MIOperandInfo = (ops tGPR:$base, tGPR:$offsreg);
128   let ParserMatchClass = MemModeRegThumbAsmOperand;
129 }
130 def t_addrmode_rrs2 : Operand<i32>,
131                       ComplexPattern<i32, 2, "SelectThumbAddrModeRI5S2", []> {
132   let EncoderMethod = "getThumbAddrModeRegRegOpValue";
133   let PrintMethod = "printThumbAddrModeRROperand";
134   let MIOperandInfo = (ops tGPR:$base, tGPR:$offsreg);
135   let ParserMatchClass = MemModeRegThumbAsmOperand;
136 }
137 def t_addrmode_rrs4 : Operand<i32>,
138                       ComplexPattern<i32, 2, "SelectThumbAddrModeRI5S4", []> {
139   let EncoderMethod = "getThumbAddrModeRegRegOpValue";
140   let PrintMethod = "printThumbAddrModeRROperand";
141   let MIOperandInfo = (ops tGPR:$base, tGPR:$offsreg);
142   let ParserMatchClass = MemModeRegThumbAsmOperand;
143 }
144
145 // t_addrmode_is4 := reg + imm5 * 4
146 //
147 def t_addrmode_is4 : Operand<i32>,
148                      ComplexPattern<i32, 2, "SelectThumbAddrModeImm5S4", []> {
149   let EncoderMethod = "getAddrModeISOpValue";
150   let PrintMethod = "printThumbAddrModeImm5S4Operand";
151   let MIOperandInfo = (ops tGPR:$base, i32imm:$offsimm);
152   let ParserMatchClass = MemModeImmThumbAsmOperand;
153 }
154
155 // t_addrmode_is2 := reg + imm5 * 2
156 //
157 def t_addrmode_is2 : Operand<i32>,
158                      ComplexPattern<i32, 2, "SelectThumbAddrModeImm5S2", []> {
159   let EncoderMethod = "getAddrModeISOpValue";
160   let PrintMethod = "printThumbAddrModeImm5S2Operand";
161   let MIOperandInfo = (ops tGPR:$base, i32imm:$offsimm);
162   let ParserMatchClass = MemModeImmThumbAsmOperand;
163 }
164
165 // t_addrmode_is1 := reg + imm5
166 //
167 def t_addrmode_is1 : Operand<i32>,
168                      ComplexPattern<i32, 2, "SelectThumbAddrModeImm5S1", []> {
169   let EncoderMethod = "getAddrModeISOpValue";
170   let PrintMethod = "printThumbAddrModeImm5S1Operand";
171   let MIOperandInfo = (ops tGPR:$base, i32imm:$offsimm);
172   let ParserMatchClass = MemModeImmThumbAsmOperand;
173 }
174
175 // t_addrmode_sp := sp + imm8 * 4
176 //
177 def t_addrmode_sp : Operand<i32>,
178                     ComplexPattern<i32, 2, "SelectThumbAddrModeSP", []> {
179   let EncoderMethod = "getAddrModeThumbSPOpValue";
180   let PrintMethod = "printThumbAddrModeSPOperand";
181   let MIOperandInfo = (ops GPR:$base, i32imm:$offsimm);
182   let ParserMatchClass = MemModeImmThumbAsmOperand;
183 }
184
185 // t_addrmode_pc := <label> => pc + imm8 * 4
186 //
187 def t_addrmode_pc : Operand<i32> {
188   let EncoderMethod = "getAddrModePCOpValue";
189   let ParserMatchClass = MemModeImmThumbAsmOperand;
190 }
191
192 //===----------------------------------------------------------------------===//
193 //  Miscellaneous Instructions.
194 //
195
196 // FIXME: Marking these as hasSideEffects is necessary to prevent machine DCE
197 // from removing one half of the matched pairs. That breaks PEI, which assumes
198 // these will always be in pairs, and asserts if it finds otherwise. Better way?
199 let Defs = [SP], Uses = [SP], hasSideEffects = 1 in {
200 def tADJCALLSTACKUP :
201   PseudoInst<(outs), (ins i32imm:$amt1, i32imm:$amt2), NoItinerary,
202              [(ARMcallseq_end imm:$amt1, imm:$amt2)]>,
203             Requires<[IsThumb, IsThumb1Only]>;
204
205 def tADJCALLSTACKDOWN :
206   PseudoInst<(outs), (ins i32imm:$amt), NoItinerary,
207              [(ARMcallseq_start imm:$amt)]>,
208             Requires<[IsThumb, IsThumb1Only]>;
209 }
210
211 // T1Disassembly - A simple class to make encoding some disassembly patterns
212 // easier and less verbose.
213 class T1Disassembly<bits<2> op1, bits<8> op2>
214   : T1Encoding<0b101111> {
215   let Inst{9-8} = op1;
216   let Inst{7-0} = op2;
217 }
218
219 def tNOP : T1pI<(outs), (ins), NoItinerary, "nop", "",
220                 [/* For disassembly only; pattern left blank */]>,
221            T1Disassembly<0b11, 0x00>; // A8.6.110
222
223 def tYIELD : T1pI<(outs), (ins), NoItinerary, "yield", "",
224                   [/* For disassembly only; pattern left blank */]>,
225            T1Disassembly<0b11, 0x10>; // A8.6.410
226
227 def tWFE : T1pI<(outs), (ins), NoItinerary, "wfe", "",
228                 [/* For disassembly only; pattern left blank */]>,
229            T1Disassembly<0b11, 0x20>; // A8.6.408
230
231 def tWFI : T1pI<(outs), (ins), NoItinerary, "wfi", "",
232                 [/* For disassembly only; pattern left blank */]>,
233            T1Disassembly<0b11, 0x30>; // A8.6.409
234
235 def tSEV : T1pI<(outs), (ins), NoItinerary, "sev", "",
236                 [/* For disassembly only; pattern left blank */]>,
237            T1Disassembly<0b11, 0x40>; // A8.6.157
238
239 // The i32imm operand $val can be used by a debugger to store more information
240 // about the breakpoint.
241 def tBKPT : T1I<(outs), (ins i32imm:$val), NoItinerary, "bkpt\t$val",
242                 [/* For disassembly only; pattern left blank */]>,
243            T1Disassembly<0b10, {?,?,?,?,?,?,?,?}> {
244   // A8.6.22
245   bits<8> val;
246   let Inst{7-0} = val;
247 }
248
249 def tSETENDBE : T1I<(outs), (ins), NoItinerary, "setend\tbe",
250                     [/* For disassembly only; pattern left blank */]>,
251                 T1Encoding<0b101101> {
252   // A8.6.156
253   let Inst{9-5} = 0b10010;
254   let Inst{4}   = 1;
255   let Inst{3}   = 1;            // Big-Endian
256   let Inst{2-0} = 0b000;
257 }
258
259 def tSETENDLE : T1I<(outs), (ins), NoItinerary, "setend\tle",
260                     [/* For disassembly only; pattern left blank */]>,
261                 T1Encoding<0b101101> {
262   // A8.6.156
263   let Inst{9-5} = 0b10010;
264   let Inst{4}   = 1;
265   let Inst{3}   = 0;            // Little-Endian
266   let Inst{2-0} = 0b000;
267 }
268
269 // Change Processor State is a system instruction -- for disassembly only.
270 def tCPS : T1I<(outs), (ins imod_op:$imod, iflags_op:$iflags),
271                 NoItinerary, "cps$imod $iflags",
272                 [/* For disassembly only; pattern left blank */]>,
273            T1Misc<0b0110011> {
274   // A8.6.38 & B6.1.1
275   bit imod;
276   bits<3> iflags;
277
278   let Inst{4}   = imod;
279   let Inst{3}   = 0;
280   let Inst{2-0} = iflags;
281 }
282
283 // For both thumb1 and thumb2.
284 let isNotDuplicable = 1, isCodeGenOnly = 1 in
285 def tPICADD : TIt<(outs GPR:$dst), (ins GPR:$lhs, pclabel:$cp), IIC_iALUr, "",
286                   [(set GPR:$dst, (ARMpic_add GPR:$lhs, imm:$cp))]>,
287               T1Special<{0,0,?,?}> {
288   // A8.6.6
289   bits<3> dst;
290   let Inst{6-3} = 0b1111; // Rm = pc
291   let Inst{2-0} = dst;
292 }
293
294 // PC relative add (ADR).
295 def tADDrPCi : T1I<(outs tGPR:$dst), (ins t_imm_s4:$rhs), IIC_iALUi,
296                    "add\t$dst, pc, $rhs", []>,
297                T1Encoding<{1,0,1,0,0,?}> {
298   // A6.2 & A8.6.10
299   bits<3> dst;
300   bits<8> rhs;
301   let Inst{10-8} = dst;
302   let Inst{7-0}  = rhs;
303 }
304
305 // ADD <Rd>, sp, #<imm8>
306 // This is rematerializable, which is particularly useful for taking the
307 // address of locals.
308 let isReMaterializable = 1 in
309 def tADDrSPi : T1I<(outs tGPR:$dst), (ins GPR:$sp, t_imm_s4:$rhs), IIC_iALUi,
310                    "add\t$dst, $sp, $rhs", []>,
311                T1Encoding<{1,0,1,0,1,?}> {
312   // A6.2 & A8.6.8
313   bits<3> dst;
314   bits<8> rhs;
315   let Inst{10-8} = dst;
316   let Inst{7-0}  = rhs;
317 }
318
319 // ADD sp, sp, #<imm7>
320 def tADDspi : TIt<(outs GPR:$dst), (ins GPR:$lhs, t_imm_s4:$rhs), IIC_iALUi,
321                   "add\t$dst, $rhs", []>,
322               T1Misc<{0,0,0,0,0,?,?}> {
323   // A6.2.5 & A8.6.8
324   bits<7> rhs;
325   let Inst{6-0} = rhs;
326 }
327
328 // SUB sp, sp, #<imm7>
329 // FIXME: The encoding and the ASM string don't match up.
330 def tSUBspi : TIt<(outs GPR:$dst), (ins GPR:$lhs, t_imm_s4:$rhs), IIC_iALUi,
331                   "sub\t$dst, $rhs", []>,
332               T1Misc<{0,0,0,0,1,?,?}> {
333   // A6.2.5 & A8.6.214
334   bits<7> rhs;
335   let Inst{6-0} = rhs;
336 }
337
338 // ADD <Rm>, sp
339 def tADDrSP : TIt<(outs GPR:$dst), (ins GPR:$lhs, GPR:$rhs), IIC_iALUr,
340                   "add\t$dst, $rhs", []>,
341               T1Special<{0,0,?,?}> {
342   // A8.6.9 Encoding T1
343   bits<4> dst;
344   let Inst{7}   = dst{3};
345   let Inst{6-3} = 0b1101;
346   let Inst{2-0} = dst{2-0};
347 }
348
349 // ADD sp, <Rm>
350 def tADDspr : TIt<(outs GPR:$dst), (ins GPR:$lhs, GPR:$rhs), IIC_iALUr,
351                   "add\t$dst, $rhs", []>,
352               T1Special<{0,0,?,?}> {
353   // A8.6.9 Encoding T2
354   bits<4> dst;
355   let Inst{7} = 1;
356   let Inst{6-3} = dst;
357   let Inst{2-0} = 0b101;
358 }
359
360 //===----------------------------------------------------------------------===//
361 //  Control Flow Instructions.
362 //
363
364 let isReturn = 1, isTerminator = 1, isBarrier = 1 in {
365   def tBX_RET : TI<(outs), (ins), IIC_Br, "bx\tlr",
366                    [(ARMretflag)]>,
367                 T1Special<{1,1,0,?}> {
368     // A6.2.3 & A8.6.25
369     let Inst{6-3} = 0b1110; // Rm = lr
370     let Inst{2-0} = 0b000;
371   }
372
373   // Alternative return instruction used by vararg functions.
374   def tBX_RET_vararg : TI<(outs), (ins tGPR:$Rm),
375                           IIC_Br, "bx\t$Rm",
376                           []>,
377                        T1Special<{1,1,0,?}> {
378     // A6.2.3 & A8.6.25
379     bits<4> Rm;
380     let Inst{6-3} = Rm;
381     let Inst{2-0} = 0b000;
382   }
383 }
384
385 // Indirect branches
386 let isBranch = 1, isTerminator = 1, isBarrier = 1, isIndirectBranch = 1 in {
387   def tBX : TI<(outs), (ins GPR:$Rm, pred:$p), IIC_Br, "bx${p}\t$Rm", []>,
388             T1Special<{1,1,0,?}> {
389     // A6.2.3 & A8.6.25
390     bits<4> Rm;
391     let Inst{6-3} = Rm;
392     let Inst{2-0} = 0b000;
393   }
394
395   def tBRIND : TI<(outs), (ins GPR:$Rm),
396                   IIC_Br,
397                   "mov\tpc, $Rm",
398                   [(brind GPR:$Rm)]>,
399                T1Special<{1,0,?,?}> {
400     // A8.6.97
401     bits<4> Rm;
402     let Inst{7}   = 1;          // <Rd> = Inst{7:2-0} = pc
403     let Inst{6-3} = Rm;
404     let Inst{2-0} = 0b111;
405   }
406 }
407
408 // FIXME: remove when we have a way to marking a MI with these properties.
409 let isReturn = 1, isTerminator = 1, isBarrier = 1, mayLoad = 1,
410     hasExtraDefRegAllocReq = 1 in
411 def tPOP_RET : tPseudoInst<(outs), (ins pred:$p, reglist:$regs, variable_ops),
412                            Size2Bytes, IIC_iPop_Br, []>;
413
414 // All calls clobber the non-callee saved registers. SP is marked as a use to
415 // prevent stack-pointer assignments that appear immediately before calls from
416 // potentially appearing dead.
417 let isCall = 1,
418   // On non-Darwin platforms R9 is callee-saved.
419   Defs = [R0,  R1,  R2,  R3,  R12, LR, QQQQ0, QQQQ2, QQQQ3, CPSR, FPSCR],
420   Uses = [SP] in {
421   // Also used for Thumb2
422   def tBL  : TIx2<0b11110, 0b11, 1,
423                   (outs), (ins t_bltarget:$func, variable_ops), IIC_Br,
424                   "bl\t$func",
425                   [(ARMtcall tglobaladdr:$func)]>,
426              Requires<[IsThumb, IsNotDarwin]> {
427     bits<21> func;
428     let Inst{25-16} = func{20-11};
429     let Inst{13} = 1;
430     let Inst{11} = 1;
431     let Inst{10-0} = func{10-0};
432   }
433
434   // ARMv5T and above, also used for Thumb2
435   def tBLXi : TIx2<0b11110, 0b11, 0,
436                    (outs), (ins t_blxtarget:$func, variable_ops), IIC_Br,
437                    "blx\t$func",
438                    [(ARMcall tglobaladdr:$func)]>,
439               Requires<[IsThumb, HasV5T, IsNotDarwin]> {
440     bits<21> func;
441     let Inst{25-16} = func{20-11};
442     let Inst{13} = 1;
443     let Inst{11} = 1;
444     let Inst{10-1} = func{10-1};
445     let Inst{0} = 0; // func{0} is assumed zero
446   }
447
448   // Also used for Thumb2
449   def tBLXr : TI<(outs), (ins GPR:$func, variable_ops), IIC_Br,
450                   "blx\t$func",
451                   [(ARMtcall GPR:$func)]>,
452               Requires<[IsThumb, HasV5T, IsNotDarwin]>,
453               T1Special<{1,1,1,?}> { // A6.2.3 & A8.6.24;
454     bits<4> func;
455     let Inst{6-3} = func;
456     let Inst{2-0} = 0b000;
457   }
458
459   // ARMv4T
460   def tBX_CALL : tPseudoInst<(outs), (ins tGPR:$func, variable_ops),
461                   Size4Bytes, IIC_Br,
462                   [(ARMcall_nolink tGPR:$func)]>,
463             Requires<[IsThumb, IsThumb1Only, IsNotDarwin]>;
464 }
465
466 let isCall = 1,
467   // On Darwin R9 is call-clobbered.
468   // R7 is marked as a use to prevent frame-pointer assignments from being
469   // moved above / below calls.
470   Defs = [R0,  R1,  R2,  R3,  R9,  R12, LR, QQQQ0, QQQQ2, QQQQ3, CPSR, FPSCR],
471   Uses = [R7, SP] in {
472   // Also used for Thumb2
473   def tBLr9 : TIx2<0b11110, 0b11, 1,
474                    (outs), (ins pred:$p, t_bltarget:$func, variable_ops),
475                    IIC_Br, "bl${p}\t$func",
476                    [(ARMtcall tglobaladdr:$func)]>,
477               Requires<[IsThumb, IsDarwin]> {
478     bits<21> func;
479     let Inst{25-16} = func{20-11};
480     let Inst{13} = 1;
481     let Inst{11} = 1;
482     let Inst{10-0} = func{10-0};
483   }
484
485   // ARMv5T and above, also used for Thumb2
486   def tBLXi_r9 : TIx2<0b11110, 0b11, 0,
487                       (outs), (ins pred:$p, t_blxtarget:$func, variable_ops),
488                       IIC_Br, "blx${p}\t$func",
489                       [(ARMcall tglobaladdr:$func)]>,
490                  Requires<[IsThumb, HasV5T, IsDarwin]> {
491     bits<21> func;
492     let Inst{25-16} = func{20-11};
493     let Inst{13} = 1;
494     let Inst{11} = 1;
495     let Inst{10-1} = func{10-1};
496     let Inst{0} = 0; // func{0} is assumed zero
497   }
498
499   // Also used for Thumb2
500   def tBLXr_r9 : TI<(outs), (ins pred:$p, GPR:$func, variable_ops), IIC_Br,
501                     "blx${p}\t$func",
502                     [(ARMtcall GPR:$func)]>,
503                  Requires<[IsThumb, HasV5T, IsDarwin]>,
504                  T1Special<{1,1,1,?}> {
505     // A6.2.3 & A8.6.24
506     bits<4> func;
507     let Inst{6-3} = func;
508     let Inst{2-0} = 0b000;
509   }
510
511   // ARMv4T
512   def tBXr9_CALL : tPseudoInst<(outs), (ins tGPR:$func, variable_ops),
513                    Size4Bytes, IIC_Br,
514                    [(ARMcall_nolink tGPR:$func)]>,
515               Requires<[IsThumb, IsThumb1Only, IsDarwin]>;
516 }
517
518 let isBranch = 1, isTerminator = 1, isBarrier = 1 in {
519   let isPredicable = 1 in
520   def tB   : T1I<(outs), (ins t_brtarget:$target), IIC_Br,
521                  "b\t$target", [(br bb:$target)]>,
522              T1Encoding<{1,1,1,0,0,?}> {
523     bits<11> target;
524     let Inst{10-0} = target;
525   }
526
527   // Far jump
528   // Just a pseudo for a tBL instruction. Needed to let regalloc know about
529   // the clobber of LR.
530   let Defs = [LR] in
531   def tBfar : tPseudoInst<(outs), (ins t_bltarget:$target),
532                           Size4Bytes, IIC_Br, []>;
533
534   def tBR_JTr : tPseudoInst<(outs),
535                       (ins tGPR:$target, i32imm:$jt, i32imm:$id),
536                       SizeSpecial, IIC_Br,
537                       [(ARMbrjt tGPR:$target, tjumptable:$jt, imm:$id)]> {
538     list<Predicate> Predicates = [IsThumb, IsThumb1Only];
539   }
540 }
541
542 // FIXME: should be able to write a pattern for ARMBrcond, but can't use
543 // a two-value operand where a dag node expects two operands. :(
544 let isBranch = 1, isTerminator = 1 in
545   def tBcc : T1I<(outs), (ins t_bcctarget:$target, pred:$p), IIC_Br,
546                  "b${p}\t$target",
547                  [/*(ARMbrcond bb:$target, imm:$cc)*/]>,
548              T1BranchCond<{1,1,0,1}> {
549   bits<4> p;
550   bits<8> target;
551   let Inst{11-8} = p;
552   let Inst{7-0} = target;
553 }
554
555 // Compare and branch on zero / non-zero
556 let isBranch = 1, isTerminator = 1 in {
557   def tCBZ  : T1I<(outs), (ins tGPR:$Rn, t_cbtarget:$target), IIC_Br,
558                   "cbz\t$Rn, $target", []>,
559               T1Misc<{0,0,?,1,?,?,?}> {
560     // A8.6.27
561     bits<6> target;
562     bits<3> Rn;
563     let Inst{9}   = target{5};
564     let Inst{7-3} = target{4-0};
565     let Inst{2-0} = Rn;
566   }
567
568   def tCBNZ : T1I<(outs), (ins tGPR:$cmp, t_cbtarget:$target), IIC_Br,
569                   "cbnz\t$cmp, $target", []>,
570               T1Misc<{1,0,?,1,?,?,?}> {
571     // A8.6.27
572     bits<6> target;
573     bits<3> Rn;
574     let Inst{9}   = target{5};
575     let Inst{7-3} = target{4-0};
576     let Inst{2-0} = Rn;
577   }
578 }
579
580 // A8.6.218 Supervisor Call (Software Interrupt) -- for disassembly only
581 // A8.6.16 B: Encoding T1
582 // If Inst{11-8} == 0b1111 then SEE SVC
583 let isCall = 1, Uses = [SP] in
584 def tSVC : T1pI<(outs), (ins i32imm:$imm), IIC_Br,
585                 "svc", "\t$imm", []>, Encoding16 {
586   bits<8> imm;
587   let Inst{15-12} = 0b1101;
588   let Inst{11-8}  = 0b1111;
589   let Inst{7-0}   = imm;
590 }
591
592 // The assembler uses 0xDEFE for a trap instruction.
593 let isBarrier = 1, isTerminator = 1 in
594 def tTRAP : TI<(outs), (ins), IIC_Br,
595                "trap", [(trap)]>, Encoding16 {
596   let Inst = 0xdefe;
597 }
598
599 //===----------------------------------------------------------------------===//
600 //  Load Store Instructions.
601 //
602
603 // Loads: reg/reg and reg/imm5
604 let canFoldAsLoad = 1, isReMaterializable = 1 in
605 multiclass thumb_ld_rr_ri_enc<bits<3> reg_opc, bits<4> imm_opc,
606                               Operand AddrMode_r, Operand AddrMode_i,
607                               AddrMode am, InstrItinClass itin_r,
608                               InstrItinClass itin_i, string asm,
609                               PatFrag opnode> {
610   def r : // reg/reg
611     T1pILdStEncode<reg_opc,
612                    (outs tGPR:$Rt), (ins AddrMode_r:$addr),
613                    am, itin_r, asm, "\t$Rt, $addr",
614                    [(set tGPR:$Rt, (opnode AddrMode_r:$addr))]>;
615   def i : // reg/imm5
616     T1pILdStEncodeImm<imm_opc, 1 /* Load */,
617                       (outs tGPR:$Rt), (ins AddrMode_i:$addr),
618                       am, itin_i, asm, "\t$Rt, $addr",
619                       [(set tGPR:$Rt, (opnode AddrMode_i:$addr))]>;
620 }
621 // Stores: reg/reg and reg/imm5
622 multiclass thumb_st_rr_ri_enc<bits<3> reg_opc, bits<4> imm_opc,
623                               Operand AddrMode_r, Operand AddrMode_i,
624                               AddrMode am, InstrItinClass itin_r,
625                               InstrItinClass itin_i, string asm,
626                               PatFrag opnode> {
627   def r : // reg/reg
628     T1pILdStEncode<reg_opc,
629                    (outs), (ins tGPR:$Rt, AddrMode_r:$addr),
630                    am, itin_r, asm, "\t$Rt, $addr",
631                    [(opnode tGPR:$Rt, AddrMode_r:$addr)]>;
632   def i : // reg/imm5
633     T1pILdStEncodeImm<imm_opc, 0 /* Store */,
634                       (outs), (ins tGPR:$Rt, AddrMode_i:$addr),
635                       am, itin_i, asm, "\t$Rt, $addr",
636                       [(opnode tGPR:$Rt, AddrMode_i:$addr)]>;
637 }
638
639 // A8.6.57 & A8.6.60
640 defm tLDR  : thumb_ld_rr_ri_enc<0b100, 0b0110, t_addrmode_rrs4,
641                                 t_addrmode_is4, AddrModeT1_4,
642                                 IIC_iLoad_r, IIC_iLoad_i, "ldr",
643                                 UnOpFrag<(load node:$Src)>>;
644
645 // A8.6.64 & A8.6.61
646 defm tLDRB : thumb_ld_rr_ri_enc<0b110, 0b0111, t_addrmode_rrs1,
647                                 t_addrmode_is1, AddrModeT1_1,
648                                 IIC_iLoad_bh_r, IIC_iLoad_bh_i, "ldrb",
649                                 UnOpFrag<(zextloadi8 node:$Src)>>;
650
651 // A8.6.76 & A8.6.73
652 defm tLDRH : thumb_ld_rr_ri_enc<0b101, 0b1000, t_addrmode_rrs2,
653                                 t_addrmode_is2, AddrModeT1_2,
654                                 IIC_iLoad_bh_r, IIC_iLoad_bh_i, "ldrh",
655                                 UnOpFrag<(zextloadi16 node:$Src)>>;
656
657 let AddedComplexity = 10 in
658 def tLDRSB :                    // A8.6.80
659   T1pILdStEncode<0b011, (outs tGPR:$dst), (ins t_addrmode_rr:$addr),
660                  AddrModeT1_1, IIC_iLoad_bh_r,
661                  "ldrsb", "\t$dst, $addr",
662                  [(set tGPR:$dst, (sextloadi8 t_addrmode_rr:$addr))]>;
663
664 let AddedComplexity = 10 in
665 def tLDRSH :                    // A8.6.84
666   T1pILdStEncode<0b111, (outs tGPR:$dst), (ins t_addrmode_rr:$addr),
667                  AddrModeT1_2, IIC_iLoad_bh_r,
668                  "ldrsh", "\t$dst, $addr",
669                  [(set tGPR:$dst, (sextloadi16 t_addrmode_rr:$addr))]>;
670
671 let canFoldAsLoad = 1 in
672 def tLDRspi : T1pIs<(outs tGPR:$Rt), (ins t_addrmode_sp:$addr), IIC_iLoad_i,
673                     "ldr", "\t$Rt, $addr",
674                     [(set tGPR:$Rt, (load t_addrmode_sp:$addr))]>,
675               T1LdStSP<{1,?,?}> {
676   bits<3> Rt;
677   bits<8> addr;
678   let Inst{10-8} = Rt;
679   let Inst{7-0} = addr;
680 }
681
682 // Load tconstpool
683 // FIXME: Use ldr.n to work around a Darwin assembler bug.
684 let canFoldAsLoad = 1, isReMaterializable = 1 in
685 def tLDRpci : T1pIs<(outs tGPR:$Rt), (ins t_addrmode_pc:$addr), IIC_iLoad_i,
686                   "ldr", ".n\t$Rt, $addr",
687                   [(set tGPR:$Rt, (load (ARMWrapper tconstpool:$addr)))]>,
688               T1Encoding<{0,1,0,0,1,?}> {
689   // A6.2 & A8.6.59
690   bits<3> Rt;
691   bits<8> addr;
692   let Inst{10-8} = Rt;
693   let Inst{7-0}  = addr;
694 }
695
696 // FIXME: Remove this entry when the above ldr.n workaround is fixed.
697 // For disassembly use only.
698 def tLDRpciDIS : T1pIs<(outs tGPR:$Rt), (ins t_addrmode_pc:$addr), IIC_iLoad_i,
699                        "ldr", "\t$Rt, $addr",
700                        [/* disassembly only */]>,
701                  T1Encoding<{0,1,0,0,1,?}> {
702   // A6.2 & A8.6.59
703   bits<3> Rt;
704   bits<8> addr;
705   let Inst{10-8} = Rt;
706   let Inst{7-0}  = addr;
707 }
708
709 // A8.6.194 & A8.6.192
710 defm tSTR  : thumb_st_rr_ri_enc<0b000, 0b0110, t_addrmode_rrs4,
711                                 t_addrmode_is4, AddrModeT1_4,
712                                 IIC_iStore_r, IIC_iStore_i, "str",
713                                 BinOpFrag<(store node:$LHS, node:$RHS)>>;
714
715 // A8.6.197 & A8.6.195
716 defm tSTRB : thumb_st_rr_ri_enc<0b010, 0b0111, t_addrmode_rrs1,
717                                 t_addrmode_is1, AddrModeT1_1,
718                                 IIC_iStore_bh_r, IIC_iStore_bh_i, "strb",
719                                 BinOpFrag<(truncstorei8 node:$LHS, node:$RHS)>>;
720
721 // A8.6.207 & A8.6.205
722 defm tSTRH : thumb_st_rr_ri_enc<0b001, 0b1000, t_addrmode_rrs2,
723                                t_addrmode_is2, AddrModeT1_2,
724                                IIC_iStore_bh_r, IIC_iStore_bh_i, "strh",
725                                BinOpFrag<(truncstorei16 node:$LHS, node:$RHS)>>;
726
727
728 def tSTRspi : T1pIs<(outs), (ins tGPR:$Rt, t_addrmode_sp:$addr), IIC_iStore_i,
729                     "str", "\t$Rt, $addr",
730                     [(store tGPR:$Rt, t_addrmode_sp:$addr)]>,
731               T1LdStSP<{0,?,?}> {
732   bits<3> Rt;
733   bits<8> addr;
734   let Inst{10-8} = Rt;
735   let Inst{7-0} = addr;
736 }
737
738 //===----------------------------------------------------------------------===//
739 //  Load / store multiple Instructions.
740 //
741
742 multiclass thumb_ldst_mult<string asm, InstrItinClass itin,
743                            InstrItinClass itin_upd, bits<6> T1Enc,
744                            bit L_bit> {
745   def IA :
746     T1I<(outs), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops),
747         itin, !strconcat(asm, "ia${p}\t$Rn, $regs"), []>,
748        T1Encoding<T1Enc> {
749     bits<3> Rn;
750     bits<8> regs;
751     let Inst{10-8} = Rn;
752     let Inst{7-0}  = regs;
753   }
754   def IA_UPD :
755     T1It<(outs GPR:$wb), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops),
756          itin_upd, !strconcat(asm, "ia${p}\t$Rn!, $regs"), "$Rn = $wb", []>,
757         T1Encoding<T1Enc> {
758     bits<3> Rn;
759     bits<8> regs;
760     let Inst{10-8} = Rn;
761     let Inst{7-0}  = regs;
762   }
763 }
764
765 // These require base address to be written back or one of the loaded regs.
766 let neverHasSideEffects = 1 in {
767
768 let mayLoad = 1, hasExtraDefRegAllocReq = 1 in
769 defm tLDM : thumb_ldst_mult<"ldm", IIC_iLoad_m, IIC_iLoad_mu,
770                             {1,1,0,0,1,?}, 1>;
771
772 let mayStore = 1, hasExtraSrcRegAllocReq = 1 in
773 defm tSTM : thumb_ldst_mult<"stm", IIC_iStore_m, IIC_iStore_mu,
774                             {1,1,0,0,0,?}, 0>;
775
776 } // neverHasSideEffects
777
778 let mayLoad = 1, Uses = [SP], Defs = [SP], hasExtraDefRegAllocReq = 1 in
779 def tPOP : T1I<(outs), (ins pred:$p, reglist:$regs, variable_ops),
780                IIC_iPop,
781                "pop${p}\t$regs", []>,
782            T1Misc<{1,1,0,?,?,?,?}> {
783   bits<16> regs;
784   let Inst{8}   = regs{15};
785   let Inst{7-0} = regs{7-0};
786 }
787
788 let mayStore = 1, Uses = [SP], Defs = [SP], hasExtraSrcRegAllocReq = 1 in
789 def tPUSH : T1I<(outs), (ins pred:$p, reglist:$regs, variable_ops),
790                 IIC_iStore_m,
791                 "push${p}\t$regs", []>,
792             T1Misc<{0,1,0,?,?,?,?}> {
793   bits<16> regs;
794   let Inst{8}   = regs{14};
795   let Inst{7-0} = regs{7-0};
796 }
797
798 //===----------------------------------------------------------------------===//
799 //  Arithmetic Instructions.
800 //
801
802 // Helper classes for encoding T1pI patterns:
803 class T1pIDPEncode<bits<4> opA, dag oops, dag iops, InstrItinClass itin,
804                    string opc, string asm, list<dag> pattern>
805     : T1pI<oops, iops, itin, opc, asm, pattern>,
806       T1DataProcessing<opA> {
807   bits<3> Rm;
808   bits<3> Rn;
809   let Inst{5-3} = Rm;
810   let Inst{2-0} = Rn;
811 }
812 class T1pIMiscEncode<bits<7> opA, dag oops, dag iops, InstrItinClass itin,
813                      string opc, string asm, list<dag> pattern>
814     : T1pI<oops, iops, itin, opc, asm, pattern>,
815       T1Misc<opA> {
816   bits<3> Rm;
817   bits<3> Rd;
818   let Inst{5-3} = Rm;
819   let Inst{2-0} = Rd;
820 }
821
822 // Helper classes for encoding T1sI patterns:
823 class T1sIDPEncode<bits<4> opA, dag oops, dag iops, InstrItinClass itin,
824                    string opc, string asm, list<dag> pattern>
825     : T1sI<oops, iops, itin, opc, asm, pattern>,
826       T1DataProcessing<opA> {
827   bits<3> Rd;
828   bits<3> Rn;
829   let Inst{5-3} = Rn;
830   let Inst{2-0} = Rd;
831 }
832 class T1sIGenEncode<bits<5> opA, dag oops, dag iops, InstrItinClass itin,
833                     string opc, string asm, list<dag> pattern>
834     : T1sI<oops, iops, itin, opc, asm, pattern>,
835       T1General<opA> {
836   bits<3> Rm;
837   bits<3> Rn;
838   bits<3> Rd;
839   let Inst{8-6} = Rm;
840   let Inst{5-3} = Rn;
841   let Inst{2-0} = Rd;
842 }
843 class T1sIGenEncodeImm<bits<5> opA, dag oops, dag iops, InstrItinClass itin,
844                        string opc, string asm, list<dag> pattern>
845     : T1sI<oops, iops, itin, opc, asm, pattern>,
846       T1General<opA> {
847   bits<3> Rd;
848   bits<3> Rm;
849   let Inst{5-3} = Rm;
850   let Inst{2-0} = Rd;
851 }
852
853 // Helper classes for encoding T1sIt patterns:
854 class T1sItDPEncode<bits<4> opA, dag oops, dag iops, InstrItinClass itin,
855                     string opc, string asm, list<dag> pattern>
856     : T1sIt<oops, iops, itin, opc, asm, pattern>,
857       T1DataProcessing<opA> {
858   bits<3> Rdn;
859   bits<3> Rm;
860   let Inst{5-3} = Rm;
861   let Inst{2-0} = Rdn;
862 }
863 class T1sItGenEncodeImm<bits<5> opA, dag oops, dag iops, InstrItinClass itin,
864                         string opc, string asm, list<dag> pattern>
865     : T1sIt<oops, iops, itin, opc, asm, pattern>,
866       T1General<opA> {
867   bits<3> Rdn;
868   bits<8> imm8;
869   let Inst{10-8} = Rdn;
870   let Inst{7-0}  = imm8;
871 }
872
873 // Add with carry register
874 let isCommutable = 1, Uses = [CPSR] in
875 def tADC :                      // A8.6.2
876   T1sItDPEncode<0b0101, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm), IIC_iALUr,
877                 "adc", "\t$Rdn, $Rm",
878                 [(set tGPR:$Rdn, (adde tGPR:$Rn, tGPR:$Rm))]>;
879
880 // Add immediate
881 def tADDi3 :                    // A8.6.4 T1
882   T1sIGenEncodeImm<0b01110, (outs tGPR:$Rd), (ins tGPR:$Rm, i32imm:$imm3),
883                    IIC_iALUi,
884                    "add", "\t$Rd, $Rm, $imm3",
885                    [(set tGPR:$Rd, (add tGPR:$Rm, imm0_7:$imm3))]> {
886   bits<3> imm3;
887   let Inst{8-6} = imm3;
888 }
889
890 def tADDi8 :                    // A8.6.4 T2
891   T1sItGenEncodeImm<{1,1,0,?,?}, (outs tGPR:$Rdn), (ins tGPR:$Rn, i32imm:$imm8),
892                     IIC_iALUi,
893                     "add", "\t$Rdn, $imm8",
894                     [(set tGPR:$Rdn, (add tGPR:$Rn, imm8_255:$imm8))]>;
895
896 // Add register
897 let isCommutable = 1 in
898 def tADDrr :                    // A8.6.6 T1
899   T1sIGenEncode<0b01100, (outs tGPR:$Rd), (ins tGPR:$Rn, tGPR:$Rm),
900                 IIC_iALUr,
901                 "add", "\t$Rd, $Rn, $Rm",
902                 [(set tGPR:$Rd, (add tGPR:$Rn, tGPR:$Rm))]>;
903
904 let neverHasSideEffects = 1 in
905 def tADDhirr : T1pIt<(outs GPR:$Rdn), (ins GPR:$Rn, GPR:$Rm), IIC_iALUr,
906                      "add", "\t$Rdn, $Rm", []>,
907                T1Special<{0,0,?,?}> {
908   // A8.6.6 T2
909   bits<4> Rdn;
910   bits<4> Rm;
911   let Inst{7}   = Rdn{3};
912   let Inst{6-3} = Rm;
913   let Inst{2-0} = Rdn{2-0};
914 }
915
916 // AND register
917 let isCommutable = 1 in
918 def tAND :                      // A8.6.12
919   T1sItDPEncode<0b0000, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
920                 IIC_iBITr,
921                 "and", "\t$Rdn, $Rm",
922                 [(set tGPR:$Rdn, (and tGPR:$Rn, tGPR:$Rm))]>;
923
924 // ASR immediate
925 def tASRri :                    // A8.6.14
926   T1sIGenEncodeImm<{0,1,0,?,?}, (outs tGPR:$Rd), (ins tGPR:$Rm, i32imm:$imm5),
927                    IIC_iMOVsi,
928                    "asr", "\t$Rd, $Rm, $imm5",
929                    [(set tGPR:$Rd, (sra tGPR:$Rm, (i32 imm:$imm5)))]> {
930   bits<5> imm5;
931   let Inst{10-6} = imm5;
932 }
933
934 // ASR register
935 def tASRrr :                    // A8.6.15
936   T1sItDPEncode<0b0100, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
937                 IIC_iMOVsr,
938                 "asr", "\t$Rdn, $Rm",
939                 [(set tGPR:$Rdn, (sra tGPR:$Rn, tGPR:$Rm))]>;
940
941 // BIC register
942 def tBIC :                      // A8.6.20
943   T1sItDPEncode<0b1110, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
944                 IIC_iBITr,
945                 "bic", "\t$Rdn, $Rm",
946                 [(set tGPR:$Rdn, (and tGPR:$Rn, (not tGPR:$Rm)))]>;
947
948 // CMN register
949 let isCompare = 1, Defs = [CPSR] in {
950 //FIXME: Disable CMN, as CCodes are backwards from compare expectations
951 //       Compare-to-zero still works out, just not the relationals
952 //def tCMN :                     // A8.6.33
953 //  T1pIDPEncode<0b1011, (outs), (ins tGPR:$lhs, tGPR:$rhs),
954 //               IIC_iCMPr,
955 //               "cmn", "\t$lhs, $rhs",
956 //               [(ARMcmp tGPR:$lhs, (ineg tGPR:$rhs))]>;
957
958 def tCMNz :                     // A8.6.33
959   T1pIDPEncode<0b1011, (outs), (ins tGPR:$Rn, tGPR:$Rm),
960                IIC_iCMPr,
961                "cmn", "\t$Rn, $Rm",
962                [(ARMcmpZ tGPR:$Rn, (ineg tGPR:$Rm))]>;
963
964 } // isCompare = 1, Defs = [CPSR]
965
966 // CMP immediate
967 let isCompare = 1, Defs = [CPSR] in {
968 def tCMPi8 : T1pI<(outs), (ins tGPR:$Rn, i32imm:$imm8), IIC_iCMPi,
969                   "cmp", "\t$Rn, $imm8",
970                   [(ARMcmp tGPR:$Rn, imm0_255:$imm8)]>,
971              T1General<{1,0,1,?,?}> {
972   // A8.6.35
973   bits<3> Rn;
974   bits<8> imm8;
975   let Inst{10-8} = Rn;
976   let Inst{7-0}  = imm8;
977 }
978
979 // CMP register
980 def tCMPr :                     // A8.6.36 T1
981   T1pIDPEncode<0b1010, (outs), (ins tGPR:$Rn, tGPR:$Rm),
982                IIC_iCMPr,
983                "cmp", "\t$Rn, $Rm",
984                [(ARMcmp tGPR:$Rn, tGPR:$Rm)]>;
985
986 def tCMPhir : T1pI<(outs), (ins GPR:$Rn, GPR:$Rm), IIC_iCMPr,
987                    "cmp", "\t$Rn, $Rm", []>,
988               T1Special<{0,1,?,?}> {
989   // A8.6.36 T2
990   bits<4> Rm;
991   bits<4> Rn;
992   let Inst{7}   = Rn{3};
993   let Inst{6-3} = Rm;
994   let Inst{2-0} = Rn{2-0};
995 }
996 } // isCompare = 1, Defs = [CPSR]
997
998
999 // XOR register
1000 let isCommutable = 1 in
1001 def tEOR :                      // A8.6.45
1002   T1sItDPEncode<0b0001, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
1003                 IIC_iBITr,
1004                 "eor", "\t$Rdn, $Rm",
1005                 [(set tGPR:$Rdn, (xor tGPR:$Rn, tGPR:$Rm))]>;
1006
1007 // LSL immediate
1008 def tLSLri :                    // A8.6.88
1009   T1sIGenEncodeImm<{0,0,0,?,?}, (outs tGPR:$Rd), (ins tGPR:$Rm, i32imm:$imm5),
1010                    IIC_iMOVsi,
1011                    "lsl", "\t$Rd, $Rm, $imm5",
1012                    [(set tGPR:$Rd, (shl tGPR:$Rm, (i32 imm:$imm5)))]> {
1013   bits<5> imm5;
1014   let Inst{10-6} = imm5;
1015 }
1016
1017 // LSL register
1018 def tLSLrr :                    // A8.6.89
1019   T1sItDPEncode<0b0010, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
1020                 IIC_iMOVsr,
1021                 "lsl", "\t$Rdn, $Rm",
1022                 [(set tGPR:$Rdn, (shl tGPR:$Rn, tGPR:$Rm))]>;
1023
1024 // LSR immediate
1025 def tLSRri :                    // A8.6.90
1026   T1sIGenEncodeImm<{0,0,1,?,?}, (outs tGPR:$Rd), (ins tGPR:$Rm, i32imm:$imm5),
1027                    IIC_iMOVsi,
1028                    "lsr", "\t$Rd, $Rm, $imm5",
1029                    [(set tGPR:$Rd, (srl tGPR:$Rm, (i32 imm:$imm5)))]> {
1030   bits<5> imm5;
1031   let Inst{10-6} = imm5;
1032 }
1033
1034 // LSR register
1035 def tLSRrr :                    // A8.6.91
1036   T1sItDPEncode<0b0011, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
1037                 IIC_iMOVsr,
1038                 "lsr", "\t$Rdn, $Rm",
1039                 [(set tGPR:$Rdn, (srl tGPR:$Rn, tGPR:$Rm))]>;
1040
1041 // Move register
1042 let isMoveImm = 1 in
1043 def tMOVi8 : T1sI<(outs tGPR:$Rd), (ins imm0_255:$imm8), IIC_iMOVi,
1044                   "mov", "\t$Rd, $imm8",
1045                   [(set tGPR:$Rd, imm0_255:$imm8)]>,
1046              T1General<{1,0,0,?,?}> {
1047   // A8.6.96
1048   bits<3> Rd;
1049   bits<8> imm8;
1050   let Inst{10-8} = Rd;
1051   let Inst{7-0}  = imm8;
1052 }
1053
1054 // TODO: A7-73: MOV(2) - mov setting flag.
1055
1056 let neverHasSideEffects = 1 in {
1057 def tMOVr : Thumb1pI<(outs GPR:$Rd), (ins GPR:$Rm), AddrModeNone,
1058                       Size2Bytes, IIC_iMOVr,
1059                       "mov", "\t$Rd, $Rm", "", []>,
1060                   T1Special<{1,0,?,?}> {
1061   // A8.6.97
1062   bits<4> Rd;
1063   bits<4> Rm;
1064   let Inst{7}   = Rd{3};
1065   let Inst{6-3} = Rm;
1066   let Inst{2-0} = Rd{2-0};
1067 }
1068 let Defs = [CPSR] in
1069 def tMOVSr      : T1I<(outs tGPR:$Rd), (ins tGPR:$Rm), IIC_iMOVr,
1070                       "movs\t$Rd, $Rm", []>, Encoding16 {
1071   // A8.6.97
1072   bits<3> Rd;
1073   bits<3> Rm;
1074   let Inst{15-6} = 0b0000000000;
1075   let Inst{5-3}  = Rm;
1076   let Inst{2-0}  = Rd;
1077 }
1078 } // neverHasSideEffects
1079
1080 // Multiply register
1081 let isCommutable = 1 in
1082 def tMUL :                      // A8.6.105 T1
1083   T1sItDPEncode<0b1101, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
1084                 IIC_iMUL32,
1085                 "mul", "\t$Rdn, $Rm, $Rdn",
1086                 [(set tGPR:$Rdn, (mul tGPR:$Rn, tGPR:$Rm))]>;
1087
1088 // Move inverse register
1089 def tMVN :                      // A8.6.107
1090   T1sIDPEncode<0b1111, (outs tGPR:$Rd), (ins tGPR:$Rn), IIC_iMVNr,
1091                "mvn", "\t$Rd, $Rn",
1092                [(set tGPR:$Rd, (not tGPR:$Rn))]>;
1093
1094 // Bitwise or register
1095 let isCommutable = 1 in
1096 def tORR :                      // A8.6.114
1097   T1sItDPEncode<0b1100, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
1098                 IIC_iBITr,
1099                 "orr", "\t$Rdn, $Rm",
1100                 [(set tGPR:$Rdn, (or tGPR:$Rn, tGPR:$Rm))]>;
1101
1102 // Swaps
1103 def tREV :                      // A8.6.134
1104   T1pIMiscEncode<{1,0,1,0,0,0,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1105                  IIC_iUNAr,
1106                  "rev", "\t$Rd, $Rm",
1107                  [(set tGPR:$Rd, (bswap tGPR:$Rm))]>,
1108                  Requires<[IsThumb, IsThumb1Only, HasV6]>;
1109
1110 def tREV16 :                    // A8.6.135
1111   T1pIMiscEncode<{1,0,1,0,0,1,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1112                  IIC_iUNAr,
1113                  "rev16", "\t$Rd, $Rm",
1114              [(set tGPR:$Rd, (rotr (bswap tGPR:$Rm), (i32 16)))]>,
1115                 Requires<[IsThumb, IsThumb1Only, HasV6]>;
1116
1117 def tREVSH :                    // A8.6.136
1118   T1pIMiscEncode<{1,0,1,0,1,1,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1119                  IIC_iUNAr,
1120                  "revsh", "\t$Rd, $Rm",
1121                  [(set tGPR:$Rd, (sra (bswap tGPR:$Rm), (i32 16)))]>,
1122                  Requires<[IsThumb, IsThumb1Only, HasV6]>;
1123
1124 // Rotate right register
1125 def tROR :                      // A8.6.139
1126   T1sItDPEncode<0b0111, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
1127                 IIC_iMOVsr,
1128                 "ror", "\t$Rdn, $Rm",
1129                 [(set tGPR:$Rdn, (rotr tGPR:$Rn, tGPR:$Rm))]>;
1130
1131 // Negate register
1132 def tRSB :                      // A8.6.141
1133   T1sIDPEncode<0b1001, (outs tGPR:$Rd), (ins tGPR:$Rn),
1134                IIC_iALUi,
1135                "rsb", "\t$Rd, $Rn, #0",
1136                [(set tGPR:$Rd, (ineg tGPR:$Rn))]>;
1137
1138 // Subtract with carry register
1139 let Uses = [CPSR] in
1140 def tSBC :                      // A8.6.151
1141   T1sItDPEncode<0b0110, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
1142                 IIC_iALUr,
1143                 "sbc", "\t$Rdn, $Rm",
1144                 [(set tGPR:$Rdn, (sube tGPR:$Rn, tGPR:$Rm))]>;
1145
1146 // Subtract immediate
1147 def tSUBi3 :                    // A8.6.210 T1
1148   T1sIGenEncodeImm<0b01111, (outs tGPR:$Rd), (ins tGPR:$Rm, i32imm:$imm3),
1149                    IIC_iALUi,
1150                    "sub", "\t$Rd, $Rm, $imm3",
1151                    [(set tGPR:$Rd, (add tGPR:$Rm, imm0_7_neg:$imm3))]> {
1152   bits<3> imm3;
1153   let Inst{8-6} = imm3;
1154 }
1155
1156 def tSUBi8 :                    // A8.6.210 T2
1157   T1sItGenEncodeImm<{1,1,1,?,?}, (outs tGPR:$Rdn), (ins tGPR:$Rn, i32imm:$imm8),
1158                     IIC_iALUi,
1159                     "sub", "\t$Rdn, $imm8",
1160                     [(set tGPR:$Rdn, (add tGPR:$Rn, imm8_255_neg:$imm8))]>;
1161
1162 // Subtract register
1163 def tSUBrr :                    // A8.6.212
1164   T1sIGenEncode<0b01101, (outs tGPR:$Rd), (ins tGPR:$Rn, tGPR:$Rm),
1165                 IIC_iALUr,
1166                 "sub", "\t$Rd, $Rn, $Rm",
1167                 [(set tGPR:$Rd, (sub tGPR:$Rn, tGPR:$Rm))]>;
1168
1169 // TODO: A7-96: STMIA - store multiple.
1170
1171 // Sign-extend byte
1172 def tSXTB :                     // A8.6.222
1173   T1pIMiscEncode<{0,0,1,0,0,1,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1174                  IIC_iUNAr,
1175                  "sxtb", "\t$Rd, $Rm",
1176                  [(set tGPR:$Rd, (sext_inreg tGPR:$Rm, i8))]>,
1177                  Requires<[IsThumb, IsThumb1Only, HasV6]>;
1178
1179 // Sign-extend short
1180 def tSXTH :                     // A8.6.224
1181   T1pIMiscEncode<{0,0,1,0,0,0,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1182                  IIC_iUNAr,
1183                  "sxth", "\t$Rd, $Rm",
1184                  [(set tGPR:$Rd, (sext_inreg tGPR:$Rm, i16))]>,
1185                  Requires<[IsThumb, IsThumb1Only, HasV6]>;
1186
1187 // Test
1188 let isCompare = 1, isCommutable = 1, Defs = [CPSR] in
1189 def tTST :                      // A8.6.230
1190   T1pIDPEncode<0b1000, (outs), (ins tGPR:$Rn, tGPR:$Rm), IIC_iTSTr,
1191                "tst", "\t$Rn, $Rm",
1192                [(ARMcmpZ (and_su tGPR:$Rn, tGPR:$Rm), 0)]>;
1193
1194 // Zero-extend byte
1195 def tUXTB :                     // A8.6.262
1196   T1pIMiscEncode<{0,0,1,0,1,1,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1197                  IIC_iUNAr,
1198                  "uxtb", "\t$Rd, $Rm",
1199                  [(set tGPR:$Rd, (and tGPR:$Rm, 0xFF))]>,
1200                  Requires<[IsThumb, IsThumb1Only, HasV6]>;
1201
1202 // Zero-extend short
1203 def tUXTH :                     // A8.6.264
1204   T1pIMiscEncode<{0,0,1,0,1,0,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1205                  IIC_iUNAr,
1206                  "uxth", "\t$Rd, $Rm",
1207                  [(set tGPR:$Rd, (and tGPR:$Rm, 0xFFFF))]>,
1208                  Requires<[IsThumb, IsThumb1Only, HasV6]>;
1209
1210 // Conditional move tMOVCCr - Used to implement the Thumb SELECT_CC operation.
1211 // Expanded after instruction selection into a branch sequence.
1212 let usesCustomInserter = 1 in  // Expanded after instruction selection.
1213   def tMOVCCr_pseudo :
1214   PseudoInst<(outs tGPR:$dst), (ins tGPR:$false, tGPR:$true, pred:$cc),
1215               NoItinerary,
1216              [/*(set tGPR:$dst, (ARMcmov tGPR:$false, tGPR:$true, imm:$cc))*/]>;
1217
1218
1219 // 16-bit movcc in IT blocks for Thumb2.
1220 let neverHasSideEffects = 1 in {
1221 def tMOVCCr : T1pIt<(outs GPR:$Rdn), (ins GPR:$Rn, GPR:$Rm), IIC_iCMOVr,
1222                     "mov", "\t$Rdn, $Rm", []>,
1223               T1Special<{1,0,?,?}> {
1224   bits<4> Rdn;
1225   bits<4> Rm;
1226   let Inst{7}   = Rdn{3};
1227   let Inst{6-3} = Rm;
1228   let Inst{2-0} = Rdn{2-0};
1229 }
1230
1231 let isMoveImm = 1 in
1232 def tMOVCCi : T1pIt<(outs tGPR:$Rdn), (ins tGPR:$Rn, i32imm:$Rm), IIC_iCMOVi,
1233                     "mov", "\t$Rdn, $Rm", []>,
1234               T1General<{1,0,0,?,?}> {
1235   bits<3> Rdn;
1236   bits<8> Rm;
1237   let Inst{10-8} = Rdn;
1238   let Inst{7-0}  = Rm;
1239 }
1240
1241 } // neverHasSideEffects
1242
1243 // tLEApcrel - Load a pc-relative address into a register without offending the
1244 // assembler.
1245
1246 def tADR : T1I<(outs tGPR:$Rd), (ins t_adrlabel:$addr, pred:$p),
1247                IIC_iALUi, "adr{$p}\t$Rd, #$addr", []>,
1248                T1Encoding<{1,0,1,0,0,?}> {
1249   bits<3> Rd;
1250   bits<8> addr;
1251   let Inst{10-8} = Rd;
1252   let Inst{7-0} = addr;
1253 }
1254
1255 let neverHasSideEffects = 1, isReMaterializable = 1 in
1256 def tLEApcrel   : tPseudoInst<(outs tGPR:$Rd), (ins i32imm:$label, pred:$p),
1257                               Size2Bytes, IIC_iALUi, []>;
1258
1259 def tLEApcrelJT : tPseudoInst<(outs tGPR:$Rd),
1260                               (ins i32imm:$label, nohash_imm:$id, pred:$p),
1261                               Size2Bytes, IIC_iALUi, []>;
1262
1263 //===----------------------------------------------------------------------===//
1264 // Move between coprocessor and ARM core register -- for disassembly only
1265 //
1266
1267 class tMovRCopro<string opc, bit direction, dag oops, dag iops,
1268                  list<dag> pattern>
1269   : T1Cop<oops, iops, !strconcat(opc, "\t$cop, $opc1, $Rt, $CRn, $CRm, $opc2"),
1270           pattern> {
1271   let Inst{27-24} = 0b1110;
1272   let Inst{20} = direction;
1273   let Inst{4} = 1;
1274
1275   bits<4> Rt;
1276   bits<4> cop;
1277   bits<3> opc1;
1278   bits<3> opc2;
1279   bits<4> CRm;
1280   bits<4> CRn;
1281
1282   let Inst{15-12} = Rt;
1283   let Inst{11-8}  = cop;
1284   let Inst{23-21} = opc1;
1285   let Inst{7-5}   = opc2;
1286   let Inst{3-0}   = CRm;
1287   let Inst{19-16} = CRn;
1288 }
1289
1290 def tMCR : tMovRCopro<"mcr", 0 /* from ARM core register to coprocessor */,
1291            (outs),
1292            (ins p_imm:$cop, i32imm:$opc1, GPR:$Rt, c_imm:$CRn,
1293                 c_imm:$CRm, i32imm:$opc2),
1294            [(int_arm_mcr imm:$cop, imm:$opc1, GPR:$Rt, imm:$CRn,
1295                          imm:$CRm, imm:$opc2)]>;
1296 def tMRC : tMovRCopro<"mrc", 1 /* from coprocessor to ARM core register */,
1297            (outs GPR:$Rt),
1298            (ins p_imm:$cop, i32imm:$opc1, c_imm:$CRn, c_imm:$CRm, i32imm:$opc2),
1299            []>;
1300
1301 def : Pat<(int_arm_mrc imm:$cop, imm:$opc1, imm:$CRn, imm:$CRm, imm:$opc2),
1302           (tMRC imm:$cop, imm:$opc1, imm:$CRn, imm:$CRm, imm:$opc2)>,
1303           Requires<[IsThumb, HasV6T2]>;
1304
1305 class tMovRRCopro<string opc, bit direction,
1306                   list<dag> pattern = [/* For disassembly only */]>
1307   : T1Cop<(outs), (ins p_imm:$cop, i32imm:$opc1, GPR:$Rt, GPR:$Rt2, c_imm:$CRm),
1308           !strconcat(opc, "\t$cop, $opc1, $Rt, $Rt2, $CRm"), pattern> {
1309   let Inst{27-24} = 0b1100;
1310   let Inst{23-21} = 0b010;
1311   let Inst{20} = direction;
1312
1313   bits<4> Rt;
1314   bits<4> Rt2;
1315   bits<4> cop;
1316   bits<4> opc1;
1317   bits<4> CRm;
1318
1319   let Inst{15-12} = Rt;
1320   let Inst{19-16} = Rt2;
1321   let Inst{11-8}  = cop;
1322   let Inst{7-4}   = opc1;
1323   let Inst{3-0}   = CRm;
1324 }
1325
1326 def tMCRR : tMovRRCopro<"mcrr", 0 /* from ARM core register to coprocessor */,
1327                         [(int_arm_mcrr imm:$cop, imm:$opc1, GPR:$Rt, GPR:$Rt2,
1328                                        imm:$CRm)]>;
1329 def tMRRC : tMovRRCopro<"mrrc", 1 /* from coprocessor to ARM core register */>;
1330
1331 //===----------------------------------------------------------------------===//
1332 // Other Coprocessor Instructions.  For disassembly only.
1333 //
1334 def tCDP : T1Cop<(outs), (ins p_imm:$cop, i32imm:$opc1,
1335                  c_imm:$CRd, c_imm:$CRn, c_imm:$CRm, i32imm:$opc2),
1336                  "cdp\t$cop, $opc1, $CRd, $CRn, $CRm, $opc2",
1337                  [(int_arm_cdp imm:$cop, imm:$opc1, imm:$CRd, imm:$CRn,
1338                                imm:$CRm, imm:$opc2)]> {
1339   let Inst{27-24} = 0b1110;
1340
1341   bits<4> opc1;
1342   bits<4> CRn;
1343   bits<4> CRd;
1344   bits<4> cop;
1345   bits<3> opc2;
1346   bits<4> CRm;
1347
1348   let Inst{3-0}   = CRm;
1349   let Inst{4}     = 0;
1350   let Inst{7-5}   = opc2;
1351   let Inst{11-8}  = cop;
1352   let Inst{15-12} = CRd;
1353   let Inst{19-16} = CRn;
1354   let Inst{23-20} = opc1;
1355 }
1356
1357 //===----------------------------------------------------------------------===//
1358 // TLS Instructions
1359 //
1360
1361 // __aeabi_read_tp preserves the registers r1-r3.
1362 // This is a pseudo inst so that we can get the encoding right,
1363 // complete with fixup for the aeabi_read_tp function.
1364 let isCall = 1, Defs = [R0, R12, LR, CPSR], Uses = [SP] in
1365 def tTPsoft : tPseudoInst<(outs), (ins), Size4Bytes, IIC_Br,
1366                           [(set R0, ARMthread_pointer)]>;
1367
1368 //===----------------------------------------------------------------------===//
1369 // SJLJ Exception handling intrinsics
1370 //
1371
1372 // eh_sjlj_setjmp() is an instruction sequence to store the return address and
1373 // save #0 in R0 for the non-longjmp case.  Since by its nature we may be coming
1374 // from some other function to get here, and we're using the stack frame for the
1375 // containing function to save/restore registers, we can't keep anything live in
1376 // regs across the eh_sjlj_setjmp(), else it will almost certainly have been
1377 // tromped upon when we get here from a longjmp(). We force everything out of
1378 // registers except for our own input by listing the relevant registers in
1379 // Defs. By doing so, we also cause the prologue/epilogue code to actively
1380 // preserve all of the callee-saved resgisters, which is exactly what we want.
1381 // $val is a scratch register for our use.
1382 let Defs = [ R0,  R1,  R2,  R3,  R4,  R5,  R6,  R7, R12, CPSR ],
1383     hasSideEffects = 1, isBarrier = 1, isCodeGenOnly = 1 in
1384 def tInt_eh_sjlj_setjmp : ThumbXI<(outs),(ins tGPR:$src, tGPR:$val),
1385                                   AddrModeNone, SizeSpecial, NoItinerary, "","",
1386                           [(set R0, (ARMeh_sjlj_setjmp tGPR:$src, tGPR:$val))]>;
1387
1388 // FIXME: Non-Darwin version(s)
1389 let isBarrier = 1, hasSideEffects = 1, isTerminator = 1, isCodeGenOnly = 1,
1390     Defs = [ R7, LR, SP ] in
1391 def tInt_eh_sjlj_longjmp : XI<(outs), (ins GPR:$src, GPR:$scratch),
1392                               AddrModeNone, SizeSpecial, IndexModeNone,
1393                               Pseudo, NoItinerary, "", "",
1394                               [(ARMeh_sjlj_longjmp GPR:$src, GPR:$scratch)]>,
1395                              Requires<[IsThumb, IsDarwin]>;
1396
1397 //===----------------------------------------------------------------------===//
1398 // Non-Instruction Patterns
1399 //
1400
1401 // Comparisons
1402 def : T1Pat<(ARMcmpZ tGPR:$Rn, imm0_255:$imm8),
1403             (tCMPi8  tGPR:$Rn, imm0_255:$imm8)>;
1404 def : T1Pat<(ARMcmpZ tGPR:$Rn, tGPR:$Rm),
1405             (tCMPr   tGPR:$Rn, tGPR:$Rm)>;
1406
1407 // Add with carry
1408 def : T1Pat<(addc   tGPR:$lhs, imm0_7:$rhs),
1409             (tADDi3 tGPR:$lhs, imm0_7:$rhs)>;
1410 def : T1Pat<(addc   tGPR:$lhs, imm8_255:$rhs),
1411             (tADDi8 tGPR:$lhs, imm8_255:$rhs)>;
1412 def : T1Pat<(addc   tGPR:$lhs, tGPR:$rhs),
1413             (tADDrr tGPR:$lhs, tGPR:$rhs)>;
1414
1415 // Subtract with carry
1416 def : T1Pat<(addc   tGPR:$lhs, imm0_7_neg:$rhs),
1417             (tSUBi3 tGPR:$lhs, imm0_7_neg:$rhs)>;
1418 def : T1Pat<(addc   tGPR:$lhs, imm8_255_neg:$rhs),
1419             (tSUBi8 tGPR:$lhs, imm8_255_neg:$rhs)>;
1420 def : T1Pat<(subc   tGPR:$lhs, tGPR:$rhs),
1421             (tSUBrr tGPR:$lhs, tGPR:$rhs)>;
1422
1423 // ConstantPool, GlobalAddress
1424 def : T1Pat<(ARMWrapper  tglobaladdr :$dst), (tLEApcrel tglobaladdr :$dst)>;
1425 def : T1Pat<(ARMWrapper  tconstpool  :$dst), (tLEApcrel tconstpool  :$dst)>;
1426
1427 // JumpTable
1428 def : T1Pat<(ARMWrapperJT tjumptable:$dst, imm:$id),
1429             (tLEApcrelJT tjumptable:$dst, imm:$id)>;
1430
1431 // Direct calls
1432 def : T1Pat<(ARMtcall texternalsym:$func), (tBL texternalsym:$func)>,
1433       Requires<[IsThumb, IsNotDarwin]>;
1434 def : T1Pat<(ARMtcall texternalsym:$func), (tBLr9 texternalsym:$func)>,
1435       Requires<[IsThumb, IsDarwin]>;
1436
1437 def : Tv5Pat<(ARMcall texternalsym:$func), (tBLXi texternalsym:$func)>,
1438       Requires<[IsThumb, HasV5T, IsNotDarwin]>;
1439 def : Tv5Pat<(ARMcall texternalsym:$func), (tBLXi_r9 texternalsym:$func)>,
1440       Requires<[IsThumb, HasV5T, IsDarwin]>;
1441
1442 // Indirect calls to ARM routines
1443 def : Tv5Pat<(ARMcall GPR:$dst), (tBLXr GPR:$dst)>,
1444       Requires<[IsThumb, HasV5T, IsNotDarwin]>;
1445 def : Tv5Pat<(ARMcall GPR:$dst), (tBLXr_r9 GPR:$dst)>,
1446       Requires<[IsThumb, HasV5T, IsDarwin]>;
1447
1448 // zextload i1 -> zextload i8
1449 def : T1Pat<(zextloadi1 t_addrmode_rrs1:$addr),
1450             (tLDRBr t_addrmode_rrs1:$addr)>;
1451 def : T1Pat<(zextloadi1 t_addrmode_is1:$addr),
1452             (tLDRBi t_addrmode_is1:$addr)>;
1453
1454 // extload -> zextload
1455 def : T1Pat<(extloadi1  t_addrmode_rrs1:$addr), (tLDRBr t_addrmode_rrs1:$addr)>;
1456 def : T1Pat<(extloadi1  t_addrmode_is1:$addr),  (tLDRBi t_addrmode_is1:$addr)>;
1457 def : T1Pat<(extloadi8  t_addrmode_rrs1:$addr), (tLDRBr t_addrmode_rrs1:$addr)>;
1458 def : T1Pat<(extloadi8  t_addrmode_is1:$addr),  (tLDRBi t_addrmode_is1:$addr)>;
1459 def : T1Pat<(extloadi16 t_addrmode_rrs2:$addr), (tLDRHr t_addrmode_rrs2:$addr)>;
1460 def : T1Pat<(extloadi16 t_addrmode_is2:$addr),  (tLDRHi t_addrmode_is2:$addr)>;
1461
1462 // If it's impossible to use [r,r] address mode for sextload, select to
1463 // ldr{b|h} + sxt{b|h} instead.
1464 def : T1Pat<(sextloadi8 t_addrmode_is1:$addr),
1465             (tSXTB (tLDRBi t_addrmode_is1:$addr))>,
1466       Requires<[IsThumb, IsThumb1Only, HasV6]>;
1467 def : T1Pat<(sextloadi8 t_addrmode_rrs1:$addr),
1468             (tSXTB (tLDRBr t_addrmode_rrs1:$addr))>,
1469       Requires<[IsThumb, IsThumb1Only, HasV6]>;
1470 def : T1Pat<(sextloadi16 t_addrmode_is2:$addr),
1471             (tSXTH (tLDRHi t_addrmode_is2:$addr))>,
1472       Requires<[IsThumb, IsThumb1Only, HasV6]>;
1473 def : T1Pat<(sextloadi16 t_addrmode_rrs2:$addr),
1474             (tSXTH (tLDRHr t_addrmode_rrs2:$addr))>,
1475       Requires<[IsThumb, IsThumb1Only, HasV6]>;
1476
1477 def : T1Pat<(sextloadi8 t_addrmode_rrs1:$addr),
1478             (tASRri (tLSLri (tLDRBr t_addrmode_rrs1:$addr), 24), 24)>;
1479 def : T1Pat<(sextloadi8 t_addrmode_is1:$addr),
1480             (tASRri (tLSLri (tLDRBi t_addrmode_is1:$addr), 24), 24)>;
1481 def : T1Pat<(sextloadi16 t_addrmode_rrs2:$addr),
1482             (tASRri (tLSLri (tLDRHr t_addrmode_rrs2:$addr), 16), 16)>;
1483 def : T1Pat<(sextloadi16 t_addrmode_is2:$addr),
1484             (tASRri (tLSLri (tLDRHi t_addrmode_is2:$addr), 16), 16)>;
1485
1486 // Large immediate handling.
1487
1488 // Two piece imms.
1489 def : T1Pat<(i32 thumb_immshifted:$src),
1490             (tLSLri (tMOVi8 (thumb_immshifted_val imm:$src)),
1491                     (thumb_immshifted_shamt imm:$src))>;
1492
1493 def : T1Pat<(i32 imm0_255_comp:$src),
1494             (tMVN (tMOVi8 (imm_comp_XFORM imm:$src)))>;
1495
1496 // Pseudo instruction that combines ldr from constpool and add pc. This should
1497 // be expanded into two instructions late to allow if-conversion and
1498 // scheduling.
1499 let isReMaterializable = 1 in
1500 def tLDRpci_pic : PseudoInst<(outs GPR:$dst), (ins i32imm:$addr, pclabel:$cp),
1501                              NoItinerary,
1502                [(set GPR:$dst, (ARMpic_add (load (ARMWrapper tconstpool:$addr)),
1503                                            imm:$cp))]>,
1504                Requires<[IsThumb, IsThumb1Only]>;