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