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