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