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