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