Add PredicateOperand to all ARM instructions that have the condition field.
[oota-llvm.git] / lib / Target / ARM / ARMInstrThumb.td
1 //===- ARMInstrThumb.td - Thumb support for ARM ---------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file was developed by Chris Lattner and is distributed under the
6 // University of Illinois Open Source 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, SDNPOptInFlag, SDNPOutFlag]>;
20
21 // TI - Thumb instruction.
22
23 // ThumbPat - Same as Pat<>, but requires that the compiler be in Thumb mode.
24 class ThumbPat<dag pattern, dag result> : Pat<pattern, result> {
25   list<Predicate> Predicates = [IsThumb];
26 }
27
28 class ThumbV5Pat<dag pattern, dag result> : Pat<pattern, result> {
29   list<Predicate> Predicates = [IsThumb, HasV5T];
30 }
31
32 class ThumbI<dag ops, AddrMode am, SizeFlagVal sz,
33              string asm, string cstr, list<dag> pattern>
34   // FIXME: Set all opcodes to 0 for now.
35   : InstARM<0, am, sz, IndexModeNone, cstr> {
36   let OperandList = ops;
37   let AsmString   = asm;
38   let Pattern = pattern;
39   list<Predicate> Predicates = [IsThumb];
40 }
41
42 class TI<dag ops, string asm, list<dag> pattern>
43   : ThumbI<ops, AddrModeNone, Size2Bytes, asm, "", pattern>;
44 class TI1<dag ops, string asm, list<dag> pattern>
45   : ThumbI<ops, AddrModeT1, Size2Bytes, asm, "", pattern>;
46 class TI2<dag ops, string asm, list<dag> pattern>
47   : ThumbI<ops, AddrModeT2, Size2Bytes, asm, "", pattern>;
48 class TI4<dag ops, string asm, list<dag> pattern>
49   : ThumbI<ops, AddrModeT4, Size2Bytes, asm, "", pattern>;
50 class TIs<dag ops, string asm, list<dag> pattern>
51   : ThumbI<ops, AddrModeTs, Size2Bytes, asm, "", pattern>;
52
53 // Two-address instructions
54 class TIt<dag ops, string asm, list<dag> pattern>
55   : ThumbI<ops, AddrModeNone, Size2Bytes, asm, "$lhs = $dst", pattern>;
56
57 // BL, BLX(1) are translated by assembler into two instructions
58 class TIx2<dag ops, string asm, list<dag> pattern>
59   : ThumbI<ops, AddrModeNone, Size4Bytes, asm, "", pattern>;
60
61 // BR_JT instructions
62 class TJTI<dag ops, string asm, list<dag> pattern>
63   : ThumbI<ops, AddrModeNone, SizeSpecial, asm, "", pattern>;
64
65 def imm_neg_XFORM : SDNodeXForm<imm, [{
66   return CurDAG->getTargetConstant(-(int)N->getValue(), MVT::i32);
67 }]>;
68 def imm_comp_XFORM : SDNodeXForm<imm, [{
69   return CurDAG->getTargetConstant(~((uint32_t)N->getValue()), MVT::i32);
70 }]>;
71
72
73 /// imm0_7 predicate - True if the 32-bit immediate is in the range [0,7].
74 def imm0_7 : PatLeaf<(i32 imm), [{
75   return (uint32_t)N->getValue() < 8;
76 }]>;
77 def imm0_7_neg : PatLeaf<(i32 imm), [{
78   return (uint32_t)-N->getValue() < 8;
79 }], imm_neg_XFORM>;
80
81 def imm0_255 : PatLeaf<(i32 imm), [{
82   return (uint32_t)N->getValue() < 256;
83 }]>;
84 def imm0_255_comp : PatLeaf<(i32 imm), [{
85   return ~((uint32_t)N->getValue()) < 256;
86 }]>;
87
88 def imm8_255 : PatLeaf<(i32 imm), [{
89   return (uint32_t)N->getValue() >= 8 && (uint32_t)N->getValue() < 256;
90 }]>;
91 def imm8_255_neg : PatLeaf<(i32 imm), [{
92   unsigned Val = -N->getValue();
93   return Val >= 8 && Val < 256;
94 }], imm_neg_XFORM>;
95
96 // Break imm's up into two pieces: an immediate + a left shift.
97 // This uses thumb_immshifted to match and thumb_immshifted_val and
98 // thumb_immshifted_shamt to get the val/shift pieces.
99 def thumb_immshifted : PatLeaf<(imm), [{
100   return ARM_AM::isThumbImmShiftedVal((unsigned)N->getValue());
101 }]>;
102
103 def thumb_immshifted_val : SDNodeXForm<imm, [{
104   unsigned V = ARM_AM::getThumbImmNonShiftedVal((unsigned)N->getValue());
105   return CurDAG->getTargetConstant(V, MVT::i32);
106 }]>;
107
108 def thumb_immshifted_shamt : SDNodeXForm<imm, [{
109   unsigned V = ARM_AM::getThumbImmValShift((unsigned)N->getValue());
110   return CurDAG->getTargetConstant(V, MVT::i32);
111 }]>;
112
113 // Define Thumb specific addressing modes.
114
115 // t_addrmode_rr := reg + reg
116 //
117 def t_addrmode_rr : Operand<i32>,
118                     ComplexPattern<i32, 2, "SelectThumbAddrModeRR", []> {
119   let PrintMethod = "printThumbAddrModeRROperand";
120   let MIOperandInfo = (ops GPR:$base, GPR:$offsreg);
121 }
122
123 // t_addrmode_s4 := reg + reg
124 //                  reg + imm5 * 4
125 //
126 def t_addrmode_s4 : Operand<i32>,
127                     ComplexPattern<i32, 3, "SelectThumbAddrModeS4", []> {
128   let PrintMethod = "printThumbAddrModeS4Operand";
129   let MIOperandInfo = (ops GPR:$base, i32imm:$offsimm, GPR:$offsreg);
130 }
131
132 // t_addrmode_s2 := reg + reg
133 //                  reg + imm5 * 2
134 //
135 def t_addrmode_s2 : Operand<i32>,
136                     ComplexPattern<i32, 3, "SelectThumbAddrModeS2", []> {
137   let PrintMethod = "printThumbAddrModeS2Operand";
138   let MIOperandInfo = (ops GPR:$base, i32imm:$offsimm, GPR:$offsreg);
139 }
140
141 // t_addrmode_s1 := reg + reg
142 //                  reg + imm5
143 //
144 def t_addrmode_s1 : Operand<i32>,
145                     ComplexPattern<i32, 3, "SelectThumbAddrModeS1", []> {
146   let PrintMethod = "printThumbAddrModeS1Operand";
147   let MIOperandInfo = (ops GPR:$base, i32imm:$offsimm, GPR:$offsreg);
148 }
149
150 // t_addrmode_sp := sp + imm8 * 4
151 //
152 def t_addrmode_sp : Operand<i32>,
153                     ComplexPattern<i32, 2, "SelectThumbAddrModeSP", []> {
154   let PrintMethod = "printThumbAddrModeSPOperand";
155   let MIOperandInfo = (ops GPR:$base, i32imm:$offsimm);
156 }
157
158 //===----------------------------------------------------------------------===//
159 //  Miscellaneous Instructions.
160 //
161
162 def tADJCALLSTACKUP :
163 PseudoInst<(ops i32imm:$amt),
164            "@ tADJCALLSTACKUP $amt",
165            [(ARMcallseq_end imm:$amt)]>, Imp<[SP],[SP]>, Requires<[IsThumb]>;
166
167 def tADJCALLSTACKDOWN : 
168 PseudoInst<(ops i32imm:$amt),
169            "@ tADJCALLSTACKDOWN $amt",
170            [(ARMcallseq_start imm:$amt)]>, Imp<[SP],[SP]>, Requires<[IsThumb]>;
171
172 def tPICADD : TIt<(ops GPR:$dst, GPR:$lhs, pclabel:$cp),
173                   "$cp:\n\tadd $dst, pc",
174                   [(set GPR:$dst, (ARMpic_add GPR:$lhs, imm:$cp))]>;
175
176 //===----------------------------------------------------------------------===//
177 //  Control Flow Instructions.
178 //
179
180 let isReturn = 1, isTerminator = 1 in {
181   def tBX_RET : TI<(ops), "bx lr", [(ARMretflag)]>;
182   // Alternative return instruction used by vararg functions.
183   def tBX_RET_vararg : TI<(ops GPR:$dst), "bx $dst", []>;
184 }
185
186 // FIXME: remove when we have a way to marking a MI with these properties.
187 let isLoad = 1, isReturn = 1, isTerminator = 1 in
188 def tPOP_RET : TI<(ops reglist:$dst1, variable_ops),
189                    "pop $dst1", []>;
190
191 let isCall = 1, noResults = 1, 
192   Defs = [R0, R1, R2, R3, LR,
193           D0, D1, D2, D3, D4, D5, D6, D7] in {
194   def tBL  : TIx2<(ops i32imm:$func, variable_ops),
195                    "bl ${func:call}",
196                    [(ARMtcall tglobaladdr:$func)]>;
197   // ARMv5T and above
198   def tBLXi : TIx2<(ops i32imm:$func, variable_ops),
199                     "blx ${func:call}",
200                     [(ARMcall tglobaladdr:$func)]>, Requires<[HasV5T]>;
201   def tBLXr : TI<(ops GPR:$dst, variable_ops),
202                   "blx $dst",
203                   [(ARMtcall GPR:$dst)]>, Requires<[HasV5T]>;
204   // ARMv4T
205   def tBX : TIx2<(ops GPR:$dst, variable_ops),
206                   "cpy lr, pc\n\tbx $dst",
207                   [(ARMcall_nolink GPR:$dst)]>;
208 }
209
210 let isBranch = 1, isTerminator = 1, isBarrier = 1 in {
211   def tB   : TI<(ops brtarget:$dst), "b $dst", [(br bb:$dst)]>;
212
213   // Far jump
214   def tBfar  : TIx2<(ops brtarget:$dst), "bl $dst\t@ far jump", []>;
215
216   def tBR_JTr : TJTI<(ops GPR:$dst, jtblock_operand:$jt, i32imm:$id),
217                      "cpy pc, $dst \n\t.align\t2\n$jt",
218                      [(ARMbrjt GPR:$dst, tjumptable:$jt, imm:$id)]>;
219 }
220
221 let isBranch = 1, isTerminator = 1, noResults = 1, isBarrier = 1 in
222   def tBcc : TI<(ops brtarget:$dst, ccop:$cc), "b$cc $dst",
223                  [(ARMbrcond bb:$dst, imm:$cc)]>;
224
225 //===----------------------------------------------------------------------===//
226 //  Load Store Instructions.
227 //
228
229 let isLoad = 1 in {
230 def tLDR : TI4<(ops GPR:$dst, t_addrmode_s4:$addr),
231                "ldr $dst, $addr",
232                [(set GPR:$dst, (load t_addrmode_s4:$addr))]>;
233
234 def tLDRB : TI1<(ops GPR:$dst, t_addrmode_s1:$addr),
235                 "ldrb $dst, $addr",
236                 [(set GPR:$dst, (zextloadi8 t_addrmode_s1:$addr))]>;
237
238 def tLDRH : TI2<(ops GPR:$dst, t_addrmode_s2:$addr),
239                 "ldrh $dst, $addr",
240                 [(set GPR:$dst, (zextloadi16 t_addrmode_s2:$addr))]>;
241
242 def tLDRSB : TI1<(ops GPR:$dst, t_addrmode_rr:$addr),
243                  "ldrsb $dst, $addr",
244                  [(set GPR:$dst, (sextloadi8 t_addrmode_rr:$addr))]>;
245
246 def tLDRSH : TI2<(ops GPR:$dst, t_addrmode_rr:$addr),
247                  "ldrsh $dst, $addr",
248                  [(set GPR:$dst, (sextloadi16 t_addrmode_rr:$addr))]>;
249
250 def tLDRspi : TIs<(ops GPR:$dst, t_addrmode_sp:$addr),
251                   "ldr $dst, $addr",
252                   [(set GPR:$dst, (load t_addrmode_sp:$addr))]>;
253
254 // Special instruction for restore. It cannot clobber condition register
255 // when it's expanded by eliminateCallFramePseudoInstr().
256 def tRestore : TIs<(ops GPR:$dst, t_addrmode_sp:$addr),
257                     "ldr $dst, $addr", []>;
258
259 // Load tconstpool
260 def tLDRpci : TIs<(ops GPR:$dst, i32imm:$addr),
261                   "ldr $dst, $addr",
262                   [(set GPR:$dst, (load (ARMWrapper tconstpool:$addr)))]>;
263
264 // Special LDR for loads from non-pc-relative constpools.
265 let isReMaterializable = 1 in
266 def tLDRcp  : TIs<(ops GPR:$dst, i32imm:$addr),
267                   "ldr $dst, $addr", []>;
268 } // isLoad
269
270 let isStore = 1 in {
271 def tSTR : TI4<(ops GPR:$src, t_addrmode_s4:$addr),
272                "str $src, $addr",
273                [(store GPR:$src, t_addrmode_s4:$addr)]>;
274
275 def tSTRB : TI1<(ops GPR:$src, t_addrmode_s1:$addr),
276                  "strb $src, $addr",
277                  [(truncstorei8 GPR:$src, t_addrmode_s1:$addr)]>;
278
279 def tSTRH : TI2<(ops GPR:$src, t_addrmode_s2:$addr),
280                  "strh $src, $addr",
281                  [(truncstorei16 GPR:$src, t_addrmode_s2:$addr)]>;
282
283 def tSTRspi : TIs<(ops GPR:$src, t_addrmode_sp:$addr),
284                    "str $src, $addr",
285                    [(store GPR:$src, t_addrmode_sp:$addr)]>;
286
287 // Special instruction for spill. It cannot clobber condition register
288 // when it's expanded by eliminateCallFramePseudoInstr().
289 def tSpill : TIs<(ops GPR:$src, t_addrmode_sp:$addr),
290                   "str $src, $addr", []>;
291 }
292
293 //===----------------------------------------------------------------------===//
294 //  Load / store multiple Instructions.
295 //
296
297 // TODO: A7-44: LDMIA - load multiple
298
299 let isLoad = 1 in
300 def tPOP : TI<(ops reglist:$dst1, variable_ops),
301                "pop $dst1", []>;
302
303 let isStore = 1 in
304 def tPUSH : TI<(ops reglist:$src1, variable_ops),
305                 "push $src1", []>;
306
307 //===----------------------------------------------------------------------===//
308 //  Arithmetic Instructions.
309 //
310
311 // Add with carry
312 def tADC : TIt<(ops GPR:$dst, GPR:$lhs, GPR:$rhs),
313                "adc $dst, $rhs",
314                [(set GPR:$dst, (adde GPR:$lhs, GPR:$rhs))]>;
315
316 def tADDS : TI<(ops GPR:$dst, GPR:$lhs, GPR:$rhs),
317                "add $dst, $lhs, $rhs",
318                [(set GPR:$dst, (addc GPR:$lhs, GPR:$rhs))]>;
319
320
321 def tADDi3 : TI<(ops GPR:$dst, GPR:$lhs, i32imm:$rhs),
322                 "add $dst, $lhs, $rhs",
323                 [(set GPR:$dst, (add GPR:$lhs, imm0_7:$rhs))]>;
324
325 def tADDi8 : TIt<(ops GPR:$dst, GPR:$lhs, i32imm:$rhs),
326                  "add $dst, $rhs",
327                  [(set GPR:$dst, (add GPR:$lhs, imm8_255:$rhs))]>;
328
329 def tADDrr : TI<(ops GPR:$dst, GPR:$lhs, GPR:$rhs),
330                 "add $dst, $lhs, $rhs",
331                 [(set GPR:$dst, (add GPR:$lhs, GPR:$rhs))]>;
332
333 def tADDhirr : TIt<(ops GPR:$dst, GPR:$lhs, GPR:$rhs),
334                    "add $dst, $rhs", []>;
335
336 def tADDrPCi : TI<(ops GPR:$dst, i32imm:$rhs),
337                   "add $dst, pc, $rhs * 4", []>;
338 def tADDrSPi : TI<(ops GPR:$dst, GPR:$sp, i32imm:$rhs),
339                   "add $dst, $sp, $rhs * 4", []>;
340 def tADDspi : TIt<(ops GPR:$dst, GPR:$lhs, i32imm:$rhs),
341                   "add $dst, $rhs * 4", []>;
342
343 def tAND : TIt<(ops GPR:$dst, GPR:$lhs, GPR:$rhs),
344                 "and $dst, $rhs",
345                 [(set GPR:$dst, (and GPR:$lhs, GPR:$rhs))]>;
346
347 def tASRri : TI<(ops GPR:$dst, GPR:$lhs, i32imm:$rhs),
348                 "asr $dst, $lhs, $rhs",
349                 [(set GPR:$dst, (sra GPR:$lhs, imm:$rhs))]>;
350
351 def tASRrr : TIt<(ops GPR:$dst, GPR:$lhs, GPR:$rhs),
352                  "asr $dst, $rhs",
353                  [(set GPR:$dst, (sra GPR:$lhs, GPR:$rhs))]>;
354
355 def tBIC : TIt<(ops GPR:$dst, GPR:$lhs, GPR:$rhs),
356                "bic $dst, $rhs",
357                [(set GPR:$dst, (and GPR:$lhs, (not GPR:$rhs)))]>;
358
359
360 def tCMN : TI<(ops GPR:$lhs, GPR:$rhs),
361               "cmn $lhs, $rhs",
362               [(ARMcmp GPR:$lhs, (ineg GPR:$rhs))]>;
363
364 def tCMPi8 : TI<(ops GPR:$lhs, i32imm:$rhs),
365                "cmp $lhs, $rhs",
366                [(ARMcmp GPR:$lhs, imm0_255:$rhs)]>;
367
368 def tCMPr : TI<(ops GPR:$lhs, GPR:$rhs),
369                "cmp $lhs, $rhs",
370                [(ARMcmp GPR:$lhs, GPR:$rhs)]>;
371
372 def tTST  : TI<(ops GPR:$lhs, GPR:$rhs),
373                "tst $lhs, $rhs",
374                [(ARMcmpNZ (and GPR:$lhs, GPR:$rhs), 0)]>;
375
376 def tCMNNZ : TI<(ops GPR:$lhs, GPR:$rhs),
377                 "cmn $lhs, $rhs",
378                 [(ARMcmpNZ GPR:$lhs, (ineg GPR:$rhs))]>;
379
380 def tCMPNZi8 : TI<(ops GPR:$lhs, i32imm:$rhs),
381                  "cmp $lhs, $rhs",
382                  [(ARMcmpNZ GPR:$lhs, imm0_255:$rhs)]>;
383
384 def tCMPNZr : TI<(ops GPR:$lhs, GPR:$rhs),
385                  "cmp $lhs, $rhs",
386                  [(ARMcmpNZ GPR:$lhs, GPR:$rhs)]>;
387
388 // TODO: A7-37: CMP(3) - cmp hi regs
389
390 def tEOR : TIt<(ops GPR:$dst, GPR:$lhs, GPR:$rhs),
391                "eor $dst, $rhs",
392                [(set GPR:$dst, (xor GPR:$lhs, GPR:$rhs))]>;
393
394 def tLSLri : TI<(ops GPR:$dst, GPR:$lhs, i32imm:$rhs),
395                 "lsl $dst, $lhs, $rhs",
396                 [(set GPR:$dst, (shl GPR:$lhs, imm:$rhs))]>;
397
398 def tLSLrr : TIt<(ops GPR:$dst, GPR:$lhs, GPR:$rhs),
399                  "lsl $dst, $rhs",
400                  [(set GPR:$dst, (shl GPR:$lhs, GPR:$rhs))]>;
401
402 def tLSRri : TI<(ops GPR:$dst, GPR:$lhs, i32imm:$rhs),
403                 "lsr $dst, $lhs, $rhs",
404                 [(set GPR:$dst, (srl GPR:$lhs, imm:$rhs))]>;
405
406 def tLSRrr : TIt<(ops GPR:$dst, GPR:$lhs, GPR:$rhs),
407                  "lsr $dst, $rhs",
408                  [(set GPR:$dst, (srl GPR:$lhs, GPR:$rhs))]>;
409
410 // FIXME: This is not rematerializable because mov changes the condition code.
411 def tMOVi8 : TI<(ops GPR:$dst, i32imm:$src),
412                  "mov $dst, $src",
413                  [(set GPR:$dst, imm0_255:$src)]>;
414
415 // TODO: A7-73: MOV(2) - mov setting flag.
416
417
418 // Note: MOV(2) of two low regs updates the flags, so we emit this as 'cpy',
419 // which is MOV(3).  This also supports high registers.
420 def tMOVr  : TI<(ops GPR:$dst, GPR:$src),
421                  "cpy $dst, $src", []>;
422
423 def tMUL : TIt<(ops GPR:$dst, GPR:$lhs, GPR:$rhs),
424                "mul $dst, $rhs",
425                [(set GPR:$dst, (mul GPR:$lhs, GPR:$rhs))]>;
426
427 def tMVN : TI<(ops GPR:$dst, GPR:$src),
428               "mvn $dst, $src",
429               [(set GPR:$dst, (not GPR:$src))]>;
430
431 def tNEG : TI<(ops GPR:$dst, GPR:$src),
432               "neg $dst, $src",
433               [(set GPR:$dst, (ineg GPR:$src))]>;
434
435 def tORR : TIt<(ops GPR:$dst, GPR:$lhs, GPR:$rhs),
436                "orr $dst, $rhs",
437                [(set GPR:$dst, (or GPR:$lhs, GPR:$rhs))]>;
438
439
440 def tREV : TI<(ops GPR:$dst, GPR:$src),
441               "rev $dst, $src",
442               [(set GPR:$dst, (bswap GPR:$src))]>, 
443               Requires<[IsThumb, HasV6]>;
444
445 def tREV16 : TI<(ops GPR:$dst, GPR:$src),
446                 "rev16 $dst, $src",
447                 [(set GPR:$dst,
448                     (or (and (srl GPR:$src, 8), 0xFF),
449                         (or (and (shl GPR:$src, 8), 0xFF00),
450                             (or (and (srl GPR:$src, 8), 0xFF0000),
451                                 (and (shl GPR:$src, 8), 0xFF000000)))))]>,
452                 Requires<[IsThumb, HasV6]>;
453
454 def tREVSH : TI<(ops GPR:$dst, GPR:$src),
455                 "revsh $dst, $src",
456                 [(set GPR:$dst,
457                    (sext_inreg
458                      (or (srl (and GPR:$src, 0xFFFF), 8),
459                          (shl GPR:$src, 8)), i16))]>,
460                 Requires<[IsThumb, HasV6]>;
461
462 def tROR : TIt<(ops GPR:$dst, GPR:$lhs, GPR:$rhs),
463                 "ror $dst, $rhs",
464                 [(set GPR:$dst, (rotr GPR:$lhs, GPR:$rhs))]>;
465
466
467 // Subtract with carry
468 def tSBC : TIt<(ops GPR:$dst, GPR:$lhs, GPR:$rhs),
469                 "sbc $dst, $rhs",
470                 [(set GPR:$dst, (sube GPR:$lhs, GPR:$rhs))]>;
471
472 def tSUBS : TI<(ops GPR:$dst, GPR:$lhs, GPR:$rhs),
473                 "sub $dst, $lhs, $rhs",
474                [(set GPR:$dst, (subc GPR:$lhs, GPR:$rhs))]>;
475
476
477 // TODO: A7-96: STMIA - store multiple.
478
479 def tSUBi3 : TI<(ops GPR:$dst, GPR:$lhs, i32imm:$rhs),
480                 "sub $dst, $lhs, $rhs",
481                 [(set GPR:$dst, (add GPR:$lhs, imm0_7_neg:$rhs))]>;
482                 
483 def tSUBi8 : TIt<(ops GPR:$dst, GPR:$lhs, i32imm:$rhs),
484                   "sub $dst, $rhs",
485                   [(set GPR:$dst, (add GPR:$lhs, imm8_255_neg:$rhs))]>;
486                 
487 def tSUBrr : TI<(ops GPR:$dst, GPR:$lhs, GPR:$rhs),
488                 "sub $dst, $lhs, $rhs",
489                 [(set GPR:$dst, (sub GPR:$lhs, GPR:$rhs))]>;
490
491 def tSUBspi : TIt<(ops GPR:$dst, GPR:$lhs, i32imm:$rhs),
492                   "sub $dst, $rhs * 4", []>;
493
494 def tSXTB  : TI<(ops GPR:$dst, GPR:$src),
495                 "sxtb $dst, $src",
496                 [(set GPR:$dst, (sext_inreg GPR:$src, i8))]>,
497                 Requires<[IsThumb, HasV6]>;
498 def tSXTH  : TI<(ops GPR:$dst, GPR:$src),
499                 "sxth $dst, $src",
500                 [(set GPR:$dst, (sext_inreg GPR:$src, i16))]>,
501                 Requires<[IsThumb, HasV6]>;
502
503
504 def tUXTB  : TI<(ops GPR:$dst, GPR:$src),
505                 "uxtb $dst, $src",
506                 [(set GPR:$dst, (and GPR:$src, 0xFF))]>,
507                 Requires<[IsThumb, HasV6]>;
508 def tUXTH  : TI<(ops GPR:$dst, GPR:$src),
509                 "uxth $dst, $src",
510                 [(set GPR:$dst, (and GPR:$src, 0xFFFF))]>, 
511                 Requires<[IsThumb, HasV6]>;
512
513
514 // Conditional move tMOVCCr - Used to implement the Thumb SELECT_CC DAG operation.
515 // Expanded by the scheduler into a branch sequence.
516 let usesCustomDAGSchedInserter = 1 in  // Expanded by the scheduler.
517   def tMOVCCr :
518   PseudoInst<(ops GPR:$dst, GPR:$false, GPR:$true, ccop:$cc),
519               "@ tMOVCCr $cc",
520               [(set GPR:$dst, (ARMcmov GPR:$false, GPR:$true, imm:$cc))]>;
521
522 // tLEApcrel - Load a pc-relative address into a register without offending the
523 // assembler.
524 def tLEApcrel : TIx2<(ops GPR:$dst, i32imm:$label),
525                     !strconcat(!strconcat(".set PCRELV${:uid}, ($label-(",
526                                           "${:private}PCRELL${:uid}+4))\n"),
527                                !strconcat("\tmov $dst, #PCRELV${:uid}\n",
528                                   "${:private}PCRELL${:uid}:\n\tadd $dst, pc")),
529                     []>;
530
531 def tLEApcrelJT : TIx2<(ops GPR:$dst, i32imm:$label, i32imm:$id),
532           !strconcat(!strconcat(".set PCRELV${:uid}, (${label}_${id:no_hash}-(",
533                                          "${:private}PCRELL${:uid}+4))\n"),
534                      !strconcat("\tmov $dst, #PCRELV${:uid}\n",
535                                 "${:private}PCRELL${:uid}:\n\tadd $dst, pc")),
536                     []>;
537
538 //===----------------------------------------------------------------------===//
539 // TLS Instructions
540 //
541
542 // __aeabi_read_tp preserves the registers r1-r3.
543 let isCall = 1,
544   Defs = [R0, LR] in {
545   def tTPsoft  : TIx2<(ops),
546                "bl __aeabi_read_tp",
547                [(set R0, ARMthread_pointer)]>;
548 }
549
550 //===----------------------------------------------------------------------===//
551 // Non-Instruction Patterns
552 //
553
554 // ConstantPool, GlobalAddress
555 def : ThumbPat<(ARMWrapper  tglobaladdr :$dst), (tLEApcrel tglobaladdr :$dst)>;
556 def : ThumbPat<(ARMWrapper  tconstpool  :$dst), (tLEApcrel tconstpool  :$dst)>;
557
558 // JumpTable
559 def : ThumbPat<(ARMWrapperJT tjumptable:$dst, imm:$id),
560                (tLEApcrelJT tjumptable:$dst, imm:$id)>;
561
562 // Direct calls
563 def : ThumbPat<(ARMtcall texternalsym:$func), (tBL texternalsym:$func)>;
564 def : ThumbV5Pat<(ARMcall texternalsym:$func), (tBLXi texternalsym:$func)>;
565
566 // Indirect calls to ARM routines
567 def : ThumbV5Pat<(ARMcall GPR:$dst), (tBLXr GPR:$dst)>;
568
569 // zextload i1 -> zextload i8
570 def : ThumbPat<(zextloadi1 t_addrmode_s1:$addr),
571                (tLDRB t_addrmode_s1:$addr)>;
572                   
573 // extload -> zextload
574 def : ThumbPat<(extloadi1  t_addrmode_s1:$addr),  (tLDRB t_addrmode_s1:$addr)>;
575 def : ThumbPat<(extloadi8  t_addrmode_s1:$addr),  (tLDRB t_addrmode_s1:$addr)>;
576 def : ThumbPat<(extloadi16 t_addrmode_s2:$addr),  (tLDRH t_addrmode_s2:$addr)>;
577
578 // truncstore i1 -> truncstore i8
579 def : ThumbPat<(truncstorei1 GPR:$src, t_addrmode_s1:$dst), 
580                (tSTRB GPR:$src, t_addrmode_s1:$dst)>;
581
582 // Large immediate handling.
583
584 // Two piece imms.
585 def : ThumbPat<(i32 thumb_immshifted:$src),
586                (tLSLri (tMOVi8 (thumb_immshifted_val imm:$src)),
587                        (thumb_immshifted_shamt imm:$src))>;
588
589 def : ThumbPat<(i32 imm0_255_comp:$src),
590                (tMVN (tMOVi8 (imm_comp_XFORM imm:$src)))>;