Added tSVC and tTRAP for disassembly only.
[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 // Scaled 4 immediate.
70 def t_imm_s4 : Operand<i32> {
71   let PrintMethod = "printThumbS4ImmOperand";
72 }
73
74 // Define Thumb specific addressing modes.
75
76 // t_addrmode_rr := reg + reg
77 //
78 def t_addrmode_rr : Operand<i32>,
79                     ComplexPattern<i32, 2, "SelectThumbAddrModeRR", []> {
80   let PrintMethod = "printThumbAddrModeRROperand";
81   let MIOperandInfo = (ops tGPR:$base, tGPR:$offsreg);
82 }
83
84 // t_addrmode_s4 := reg + reg
85 //                  reg + imm5 * 4
86 //
87 def t_addrmode_s4 : Operand<i32>,
88                     ComplexPattern<i32, 3, "SelectThumbAddrModeS4", []> {
89   let PrintMethod = "printThumbAddrModeS4Operand";
90   let MIOperandInfo = (ops tGPR:$base, i32imm:$offsimm, tGPR:$offsreg);
91 }
92
93 // t_addrmode_s2 := reg + reg
94 //                  reg + imm5 * 2
95 //
96 def t_addrmode_s2 : Operand<i32>,
97                     ComplexPattern<i32, 3, "SelectThumbAddrModeS2", []> {
98   let PrintMethod = "printThumbAddrModeS2Operand";
99   let MIOperandInfo = (ops tGPR:$base, i32imm:$offsimm, tGPR:$offsreg);
100 }
101
102 // t_addrmode_s1 := reg + reg
103 //                  reg + imm5
104 //
105 def t_addrmode_s1 : Operand<i32>,
106                     ComplexPattern<i32, 3, "SelectThumbAddrModeS1", []> {
107   let PrintMethod = "printThumbAddrModeS1Operand";
108   let MIOperandInfo = (ops tGPR:$base, i32imm:$offsimm, tGPR:$offsreg);
109 }
110
111 // t_addrmode_sp := sp + imm8 * 4
112 //
113 def t_addrmode_sp : Operand<i32>,
114                     ComplexPattern<i32, 2, "SelectThumbAddrModeSP", []> {
115   let PrintMethod = "printThumbAddrModeSPOperand";
116   let MIOperandInfo = (ops GPR:$base, i32imm:$offsimm);
117 }
118
119 //===----------------------------------------------------------------------===//
120 //  Miscellaneous Instructions.
121 //
122
123 // FIXME: Marking these as hasSideEffects is necessary to prevent machine DCE
124 // from removing one half of the matched pairs. That breaks PEI, which assumes
125 // these will always be in pairs, and asserts if it finds otherwise. Better way?
126 let Defs = [SP], Uses = [SP], hasSideEffects = 1 in {
127 def tADJCALLSTACKUP :
128 PseudoInst<(outs), (ins i32imm:$amt1, i32imm:$amt2), NoItinerary,
129            "@ tADJCALLSTACKUP $amt1",
130            [(ARMcallseq_end imm:$amt1, imm:$amt2)]>, Requires<[IsThumb1Only]>;
131
132 def tADJCALLSTACKDOWN :
133 PseudoInst<(outs), (ins i32imm:$amt), NoItinerary,
134            "@ tADJCALLSTACKDOWN $amt",
135            [(ARMcallseq_start imm:$amt)]>, Requires<[IsThumb1Only]>;
136 }
137
138 // The i32imm operand $val can be used by a debugger to store more information
139 // about the breakpoint.
140 def tBKPT : T1I<(outs), (ins i32imm:$val), NoItinerary, "bkpt\t$val",
141                 [/* For disassembly only; pattern left blank */]>,
142             T1Encoding<0b101111> {
143   let Inst{9-8} = 0b10;
144 }
145
146 // For both thumb1 and thumb2.
147 let isNotDuplicable = 1 in
148 def tPICADD : TIt<(outs GPR:$dst), (ins GPR:$lhs, pclabel:$cp), IIC_iALUr,
149                  "\n$cp:\n\tadd\t$dst, pc",
150                  [(set GPR:$dst, (ARMpic_add GPR:$lhs, imm:$cp))]>,
151               T1Special<{0,0,?,?}> {
152   let Inst{6-3} = 0b1111; // A8.6.6 Rm = pc
153 }
154
155 // PC relative add.
156 def tADDrPCi : T1I<(outs tGPR:$dst), (ins t_imm_s4:$rhs), IIC_iALUi,
157                   "add\t$dst, pc, $rhs", []>,
158                T1Encoding<{1,0,1,0,0,?}>; // A6.2 & A8.6.10
159
160 // ADD rd, sp, #imm8
161 def tADDrSPi : T1I<(outs tGPR:$dst), (ins GPR:$sp, t_imm_s4:$rhs), IIC_iALUi,
162                   "add\t$dst, $sp, $rhs", []>,
163                T1Encoding<{1,0,1,0,1,?}>; // A6.2 & A8.6.8
164
165 // ADD sp, sp, #imm7
166 def tADDspi : TIt<(outs GPR:$dst), (ins GPR:$lhs, t_imm_s4:$rhs), IIC_iALUi,
167                   "add\t$dst, $rhs", []>,
168               T1Misc<{0,0,0,0,0,?,?}>; // A6.2.5 & A8.6.8
169
170 // SUB sp, sp, #imm7
171 def tSUBspi : TIt<(outs GPR:$dst), (ins GPR:$lhs, t_imm_s4:$rhs), IIC_iALUi,
172                   "sub\t$dst, $rhs", []>,
173               T1Misc<{0,0,0,0,1,?,?}>; // A6.2.5 & A8.6.215
174
175 // ADD rm, sp
176 def tADDrSP : TIt<(outs GPR:$dst), (ins GPR:$lhs, GPR:$rhs), IIC_iALUr,
177                   "add\t$dst, $rhs", []>,
178               T1Special<{0,0,?,?}> {
179   let Inst{6-3} = 0b1101; // A8.6.9 Encoding T1
180 }
181
182 // ADD sp, rm
183 def tADDspr : TIt<(outs GPR:$dst), (ins GPR:$lhs, GPR:$rhs), IIC_iALUr,
184                   "add\t$dst, $rhs", []>,
185               T1Special<{0,0,?,?}> {
186   // A8.6.9 Encoding T2
187   let Inst{7} = 1;
188   let Inst{2-0} = 0b101;
189 }
190
191 // Pseudo instruction that will expand into a tSUBspi + a copy.
192 let usesCustomInserter = 1 in { // Expanded after instruction selection.
193 def tSUBspi_ : PseudoInst<(outs GPR:$dst), (ins GPR:$lhs, t_imm_s4:$rhs),
194                NoItinerary, "@ sub\t$dst, $rhs", []>;
195
196 def tADDspr_ : PseudoInst<(outs GPR:$dst), (ins GPR:$lhs, GPR:$rhs),
197                NoItinerary, "@ add\t$dst, $rhs", []>;
198
199 let Defs = [CPSR] in
200 def tANDsp : PseudoInst<(outs tGPR:$dst), (ins tGPR:$lhs, tGPR:$rhs),
201              NoItinerary, "@ and\t$dst, $rhs", []>;
202 } // usesCustomInserter
203
204 //===----------------------------------------------------------------------===//
205 //  Control Flow Instructions.
206 //
207
208 let isReturn = 1, isTerminator = 1, isBarrier = 1 in {
209   def tBX_RET : TI<(outs), (ins), IIC_Br, "bx\tlr", [(ARMretflag)]>,
210                 T1Special<{1,1,0,?}> { // A6.2.3 & A8.6.25
211     let Inst{6-3} = 0b1110; // Rm = lr
212   }
213   // Alternative return instruction used by vararg functions.
214   def tBX_RET_vararg : TI<(outs), (ins tGPR:$target), IIC_Br, "bx\t$target",[]>,
215                        T1Special<{1,1,0,?}>; // A6.2.3 & A8.6.25
216 }
217
218 // Indirect branches
219 let isBranch = 1, isTerminator = 1, isBarrier = 1, isIndirectBranch = 1 in {
220   def tBRIND : TI<(outs), (ins GPR:$dst), IIC_Br, "mov\tpc, $dst",
221                   [(brind GPR:$dst)]>,
222                T1Special<{1,0,1,?}> {
223     // <Rd> = Inst{7:2-0} = pc
224     let Inst{2-0} = 0b111;
225   }
226 }
227
228 // FIXME: remove when we have a way to marking a MI with these properties.
229 let isReturn = 1, isTerminator = 1, isBarrier = 1, mayLoad = 1,
230     hasExtraDefRegAllocReq = 1 in
231 def tPOP_RET : T1I<(outs), (ins pred:$p, reglist:$wb, variable_ops), IIC_Br,
232                    "pop${p}\t$wb", []>,
233                T1Misc<{1,1,0,?,?,?,?}>;
234
235 let isCall = 1,
236   Defs = [R0,  R1,  R2,  R3,  R12, LR,
237           D0,  D1,  D2,  D3,  D4,  D5,  D6,  D7,
238           D16, D17, D18, D19, D20, D21, D22, D23,
239           D24, D25, D26, D27, D28, D29, D30, D31, CPSR, FPSCR] in {
240   // Also used for Thumb2
241   def tBL  : TIx2<0b11110, 0b11, 1,
242                   (outs), (ins i32imm:$func, variable_ops), IIC_Br,
243                   "bl\t${func:call}",
244                   [(ARMtcall tglobaladdr:$func)]>,
245              Requires<[IsThumb, IsNotDarwin]>;
246
247   // ARMv5T and above, also used for Thumb2
248   def tBLXi : TIx2<0b11110, 0b11, 0,
249                    (outs), (ins i32imm:$func, variable_ops), IIC_Br,
250                    "blx\t${func:call}",
251                    [(ARMcall tglobaladdr:$func)]>,
252               Requires<[IsThumb, HasV5T, IsNotDarwin]>;
253
254   // Also used for Thumb2
255   def tBLXr : TI<(outs), (ins GPR:$func, variable_ops), IIC_Br,
256                   "blx\t$func",
257                   [(ARMtcall GPR:$func)]>,
258               Requires<[IsThumb, HasV5T, IsNotDarwin]>,
259               T1Special<{1,1,1,?}>; // A6.2.3 & A8.6.24;
260
261   // ARMv4T
262   def tBX : TIx2<{?,?,?,?,?}, {?,?}, ?,
263                   (outs), (ins tGPR:$func, variable_ops), IIC_Br,
264                   "mov\tlr, pc\n\tbx\t$func",
265                   [(ARMcall_nolink tGPR:$func)]>,
266             Requires<[IsThumb1Only, IsNotDarwin]>;
267 }
268
269 // On Darwin R9 is call-clobbered.
270 let isCall = 1,
271   Defs = [R0,  R1,  R2,  R3,  R9,  R12, LR,
272           D0,  D1,  D2,  D3,  D4,  D5,  D6,  D7,
273           D16, D17, D18, D19, D20, D21, D22, D23,
274           D24, D25, D26, D27, D28, D29, D30, D31, CPSR, FPSCR] in {
275   // Also used for Thumb2
276   def tBLr9 : TIx2<0b11110, 0b11, 1,
277                    (outs), (ins i32imm:$func, variable_ops), IIC_Br,
278                    "bl\t${func:call}",
279                    [(ARMtcall tglobaladdr:$func)]>,
280               Requires<[IsThumb, IsDarwin]>;
281
282   // ARMv5T and above, also used for Thumb2
283   def tBLXi_r9 : TIx2<0b11110, 0b11, 0,
284                       (outs), (ins i32imm:$func, variable_ops), IIC_Br,
285                       "blx\t${func:call}",
286                       [(ARMcall tglobaladdr:$func)]>,
287                  Requires<[IsThumb, HasV5T, IsDarwin]>;
288
289   // Also used for Thumb2
290   def tBLXr_r9 : TI<(outs), (ins GPR:$func, variable_ops), IIC_Br,
291                     "blx\t$func",
292                     [(ARMtcall GPR:$func)]>,
293                  Requires<[IsThumb, HasV5T, IsDarwin]>,
294                  T1Special<{1,1,1,?}>; // A6.2.3 & A8.6.24
295
296   // ARMv4T
297   def tBXr9 : TIx2<{?,?,?,?,?}, {?,?}, ?,
298                    (outs), (ins tGPR:$func, variable_ops), IIC_Br,
299                    "mov\tlr, pc\n\tbx\t$func",
300                    [(ARMcall_nolink tGPR:$func)]>,
301               Requires<[IsThumb1Only, IsDarwin]>;
302 }
303
304 let isBranch = 1, isTerminator = 1 in {
305   let isBarrier = 1 in {
306     let isPredicable = 1 in
307     def tB   : T1I<(outs), (ins brtarget:$target), IIC_Br,
308                    "b\t$target", [(br bb:$target)]>,
309                T1Encoding<{1,1,1,0,0,?}>;
310
311   // Far jump
312   let Defs = [LR] in
313   def tBfar : TIx2<0b11110, 0b11, 1, (outs), (ins brtarget:$target), IIC_Br,
314                     "bl\t$target\t@ far jump",[]>;
315
316   def tBR_JTr : T1JTI<(outs),
317                       (ins tGPR:$target, jtblock_operand:$jt, i32imm:$id),
318                       IIC_Br, "mov\tpc, $target\n\t.align\t2\n$jt",
319                       [(ARMbrjt tGPR:$target, tjumptable:$jt, imm:$id)]>,
320                 Encoding16 {
321     let Inst{15-7} = 0b010001101;
322     let Inst{2-0} = 0b111;
323   }
324   }
325 }
326
327 // FIXME: should be able to write a pattern for ARMBrcond, but can't use
328 // a two-value operand where a dag node expects two operands. :(
329 let isBranch = 1, isTerminator = 1 in
330   def tBcc : T1I<(outs), (ins brtarget:$target, pred:$cc), IIC_Br,
331                  "b$cc\t$target",
332                  [/*(ARMbrcond bb:$target, imm:$cc)*/]>,
333              T1Encoding<{1,1,0,1,?,?}>;
334
335 // Compare and branch on zero / non-zero
336 let isBranch = 1, isTerminator = 1 in {
337   def tCBZ  : T1I<(outs), (ins tGPR:$cmp, brtarget:$target), IIC_Br,
338                   "cbz\t$cmp, $target", []>,
339               T1Misc<{0,0,?,1,?,?,?}>;
340
341   def tCBNZ : T1I<(outs), (ins tGPR:$cmp, brtarget:$target), IIC_Br,
342                   "cbnz\t$cmp, $target", []>,
343               T1Misc<{1,0,?,1,?,?,?}>;
344 }
345
346 // A8.6.218 Supervisor Call (Software Interrupt) -- for disassembly only
347 // A8.6.16 B: Encoding T1
348 // If Inst{11-8} == 0b1111 then SEE SVC
349 let isCall = 1 in {
350 def tSVC : T1I<(outs), (ins i32imm:$svc, pred:$cc), IIC_Br, "svc$cc\t$svc", []>,
351            Encoding16 {
352   let Inst{15-12} = 0b1101;
353   let Inst{11-8} = 0b1111;
354 }
355 }
356
357 // A8.6.16 B: Encoding T1 -- for disassembly only
358 // If Inst{11-8} == 0b1110 then UNDEFINED
359 def tTRAP : T1I<(outs), (ins), IIC_Br, "trap", []>, Encoding16 {
360   let Inst{15-12} = 0b1101;
361   let Inst{11-8} = 0b1110;
362 }
363
364 //===----------------------------------------------------------------------===//
365 //  Load Store Instructions.
366 //
367
368 let canFoldAsLoad = 1, isReMaterializable = 1, mayHaveSideEffects = 1 in
369 def tLDR : T1pI4<(outs tGPR:$dst), (ins t_addrmode_s4:$addr), IIC_iLoadr,
370                "ldr", "\t$dst, $addr",
371                [(set tGPR:$dst, (load t_addrmode_s4:$addr))]>,
372            T1LdSt<0b100>;
373 def tLDRi: T1pI4<(outs tGPR:$dst), (ins t_addrmode_s4:$addr), IIC_iLoadr,
374                "ldr", "\t$dst, $addr",
375                []>,
376            T1LdSt4Imm<{1,?,?}>;
377
378 def tLDRB : T1pI1<(outs tGPR:$dst), (ins t_addrmode_s1:$addr), IIC_iLoadr,
379                 "ldrb", "\t$dst, $addr",
380                 [(set tGPR:$dst, (zextloadi8 t_addrmode_s1:$addr))]>,
381             T1LdSt<0b110>;
382 def tLDRBi: T1pI1<(outs tGPR:$dst), (ins t_addrmode_s1:$addr), IIC_iLoadr,
383                 "ldrb", "\t$dst, $addr",
384                 []>,
385             T1LdSt1Imm<{1,?,?}>;
386
387 def tLDRH : T1pI2<(outs tGPR:$dst), (ins t_addrmode_s2:$addr), IIC_iLoadr,
388                 "ldrh", "\t$dst, $addr",
389                 [(set tGPR:$dst, (zextloadi16 t_addrmode_s2:$addr))]>,
390             T1LdSt<0b101>;
391 def tLDRHi: T1pI2<(outs tGPR:$dst), (ins t_addrmode_s2:$addr), IIC_iLoadr,
392                 "ldrh", "\t$dst, $addr",
393                 []>,
394             T1LdSt2Imm<{1,?,?}>;
395
396 let AddedComplexity = 10 in
397 def tLDRSB : T1pI1<(outs tGPR:$dst), (ins t_addrmode_rr:$addr), IIC_iLoadr,
398                  "ldrsb", "\t$dst, $addr",
399                  [(set tGPR:$dst, (sextloadi8 t_addrmode_rr:$addr))]>,
400              T1LdSt<0b011>;
401
402 let AddedComplexity = 10 in
403 def tLDRSH : T1pI2<(outs tGPR:$dst), (ins t_addrmode_rr:$addr), IIC_iLoadr,
404                  "ldrsh", "\t$dst, $addr",
405                  [(set tGPR:$dst, (sextloadi16 t_addrmode_rr:$addr))]>,
406              T1LdSt<0b111>;
407
408 let canFoldAsLoad = 1 in
409 def tLDRspi : T1pIs<(outs tGPR:$dst), (ins t_addrmode_sp:$addr), IIC_iLoadi,
410                   "ldr", "\t$dst, $addr",
411                   [(set tGPR:$dst, (load t_addrmode_sp:$addr))]>,
412               T1LdStSP<{1,?,?}>;
413
414 // Special instruction for restore. It cannot clobber condition register
415 // when it's expanded by eliminateCallFramePseudoInstr().
416 let canFoldAsLoad = 1, mayLoad = 1 in
417 def tRestore : T1pIs<(outs tGPR:$dst), (ins t_addrmode_sp:$addr), IIC_iLoadi,
418                     "ldr", "\t$dst, $addr", []>,
419                T1LdStSP<{1,?,?}>;
420
421 // Load tconstpool
422 // FIXME: Use ldr.n to work around a Darwin assembler bug.
423 let canFoldAsLoad = 1, isReMaterializable = 1, mayHaveSideEffects = 1  in
424 def tLDRpci : T1pIs<(outs tGPR:$dst), (ins i32imm:$addr), IIC_iLoadi,
425                   "ldr", ".n\t$dst, $addr",
426                   [(set tGPR:$dst, (load (ARMWrapper tconstpool:$addr)))]>,
427               T1Encoding<{0,1,0,0,1,?}>; // A6.2 & A8.6.59
428
429 // Special LDR for loads from non-pc-relative constpools.
430 let canFoldAsLoad = 1, mayLoad = 1, isReMaterializable = 1,
431     mayHaveSideEffects = 1  in
432 def tLDRcp  : T1pIs<(outs tGPR:$dst), (ins i32imm:$addr), IIC_iLoadi,
433                   "ldr", "\t$dst, $addr", []>,
434               T1LdStSP<{1,?,?}>;
435
436 def tSTR : T1pI4<(outs), (ins tGPR:$src, t_addrmode_s4:$addr), IIC_iStorer,
437                "str", "\t$src, $addr",
438                [(store tGPR:$src, t_addrmode_s4:$addr)]>,
439            T1LdSt<0b000>;
440 def tSTRi: T1pI4<(outs), (ins tGPR:$src, t_addrmode_s4:$addr), IIC_iStorer,
441                "str", "\t$src, $addr",
442                []>,
443            T1LdSt4Imm<{0,?,?}>;
444
445 def tSTRB : T1pI1<(outs), (ins tGPR:$src, t_addrmode_s1:$addr), IIC_iStorer,
446                  "strb", "\t$src, $addr",
447                  [(truncstorei8 tGPR:$src, t_addrmode_s1:$addr)]>,
448             T1LdSt<0b010>;
449 def tSTRBi: T1pI1<(outs), (ins tGPR:$src, t_addrmode_s1:$addr), IIC_iStorer,
450                  "strb", "\t$src, $addr",
451                  []>,
452             T1LdSt1Imm<{0,?,?}>;
453
454 def tSTRH : T1pI2<(outs), (ins tGPR:$src, t_addrmode_s2:$addr), IIC_iStorer,
455                  "strh", "\t$src, $addr",
456                  [(truncstorei16 tGPR:$src, t_addrmode_s2:$addr)]>,
457             T1LdSt<0b001>;
458 def tSTRHi: T1pI2<(outs), (ins tGPR:$src, t_addrmode_s2:$addr), IIC_iStorer,
459                  "strh", "\t$src, $addr",
460                  []>,
461             T1LdSt2Imm<{0,?,?}>;
462
463 def tSTRspi : T1pIs<(outs), (ins tGPR:$src, t_addrmode_sp:$addr), IIC_iStorei,
464                    "str", "\t$src, $addr",
465                    [(store tGPR:$src, t_addrmode_sp:$addr)]>,
466               T1LdStSP<{0,?,?}>;
467
468 let mayStore = 1 in {
469 // Special instruction for spill. It cannot clobber condition register
470 // when it's expanded by eliminateCallFramePseudoInstr().
471 def tSpill : T1pIs<(outs), (ins tGPR:$src, t_addrmode_sp:$addr), IIC_iStorei,
472                   "str", "\t$src, $addr", []>,
473              T1LdStSP<{0,?,?}>;
474 }
475
476 //===----------------------------------------------------------------------===//
477 //  Load / store multiple Instructions.
478 //
479
480 // These requires base address to be written back or one of the loaded regs.
481 let mayLoad = 1, hasExtraDefRegAllocReq = 1 in
482 def tLDM : T1I<(outs),
483                (ins addrmode4:$addr, pred:$p, reglist:$wb, variable_ops),
484                IIC_iLoadm,
485                "ldm${addr:submode}${p}\t$addr, $wb", []>,
486            T1Encoding<{1,1,0,0,1,?}>; // A6.2 & A8.6.53
487
488 let mayStore = 1, hasExtraSrcRegAllocReq = 1 in
489 def tSTM : T1I<(outs),
490                (ins addrmode4:$addr, pred:$p, reglist:$wb, variable_ops),
491                IIC_iStorem,
492                "stm${addr:submode}${p}\t$addr, $wb", []>,
493            T1Encoding<{1,1,0,0,0,?}>; // A6.2 & A8.6.189
494
495 let mayLoad = 1, Uses = [SP], Defs = [SP], hasExtraDefRegAllocReq = 1 in
496 def tPOP : T1I<(outs), (ins pred:$p, reglist:$wb, variable_ops), IIC_Br,
497                "pop${p}\t$wb", []>,
498            T1Misc<{1,1,0,?,?,?,?}>;
499
500 let mayStore = 1, Uses = [SP], Defs = [SP], hasExtraSrcRegAllocReq = 1 in
501 def tPUSH : T1I<(outs), (ins pred:$p, reglist:$wb, variable_ops), IIC_Br,
502                 "push${p}\t$wb", []>,
503             T1Misc<{0,1,0,?,?,?,?}>;
504
505 //===----------------------------------------------------------------------===//
506 //  Arithmetic Instructions.
507 //
508
509 // Add with carry register
510 let isCommutable = 1, Uses = [CPSR] in
511 def tADC : T1sIt<(outs tGPR:$dst), (ins tGPR:$lhs, tGPR:$rhs), IIC_iALUr,
512                  "adc", "\t$dst, $rhs",
513                  [(set tGPR:$dst, (adde tGPR:$lhs, tGPR:$rhs))]>,
514            T1DataProcessing<0b0101>;
515
516 // Add immediate
517 def tADDi3 : T1sI<(outs tGPR:$dst), (ins tGPR:$lhs, i32imm:$rhs), IIC_iALUi,
518                    "add", "\t$dst, $lhs, $rhs",
519                    [(set tGPR:$dst, (add tGPR:$lhs, imm0_7:$rhs))]>,
520              T1General<0b01110>;
521
522 def tADDi8 : T1sIt<(outs tGPR:$dst), (ins tGPR:$lhs, i32imm:$rhs), IIC_iALUi,
523                    "add", "\t$dst, $rhs",
524                    [(set tGPR:$dst, (add tGPR:$lhs, imm8_255:$rhs))]>,
525              T1General<{1,1,0,?,?}>;
526
527 // Add register
528 let isCommutable = 1 in
529 def tADDrr : T1sI<(outs tGPR:$dst), (ins tGPR:$lhs, tGPR:$rhs), IIC_iALUr,
530                    "add", "\t$dst, $lhs, $rhs",
531                    [(set tGPR:$dst, (add tGPR:$lhs, tGPR:$rhs))]>,
532              T1General<0b01100>;
533
534 let neverHasSideEffects = 1 in
535 def tADDhirr : T1pIt<(outs GPR:$dst), (ins GPR:$lhs, GPR:$rhs), IIC_iALUr,
536                      "add", "\t$dst, $rhs", []>,
537                T1Special<{0,0,?,?}>;
538
539 // And register
540 let isCommutable = 1 in
541 def tAND : T1sIt<(outs tGPR:$dst), (ins tGPR:$lhs, tGPR:$rhs), IIC_iALUr,
542                  "and", "\t$dst, $rhs",
543                  [(set tGPR:$dst, (and tGPR:$lhs, tGPR:$rhs))]>,
544            T1DataProcessing<0b0000>;
545
546 // ASR immediate
547 def tASRri : T1sI<(outs tGPR:$dst), (ins tGPR:$lhs, i32imm:$rhs), IIC_iMOVsi,
548                   "asr", "\t$dst, $lhs, $rhs",
549                   [(set tGPR:$dst, (sra tGPR:$lhs, (i32 imm:$rhs)))]>,
550              T1General<{0,1,0,?,?}>;
551
552 // ASR register
553 def tASRrr : T1sIt<(outs tGPR:$dst), (ins tGPR:$lhs, tGPR:$rhs), IIC_iMOVsr,
554                    "asr", "\t$dst, $rhs",
555                    [(set tGPR:$dst, (sra tGPR:$lhs, tGPR:$rhs))]>,
556              T1DataProcessing<0b0100>;
557
558 // BIC register
559 def tBIC : T1sIt<(outs tGPR:$dst), (ins tGPR:$lhs, tGPR:$rhs), IIC_iALUr,
560                  "bic", "\t$dst, $rhs",
561                  [(set tGPR:$dst, (and tGPR:$lhs, (not tGPR:$rhs)))]>,
562            T1DataProcessing<0b1110>;
563
564 // CMN register
565 let Defs = [CPSR] in {
566 //FIXME: Disable CMN, as CCodes are backwards from compare expectations
567 //       Compare-to-zero still works out, just not the relationals
568 //def tCMN : T1pI<(outs), (ins tGPR:$lhs, tGPR:$rhs), IIC_iCMPr,
569 //                "cmn", "\t$lhs, $rhs",
570 //                [(ARMcmp tGPR:$lhs, (ineg tGPR:$rhs))]>,
571 //           T1DataProcessing<0b1011>;
572 def tCMNz : T1pI<(outs), (ins tGPR:$lhs, tGPR:$rhs), IIC_iCMPr,
573                  "cmn", "\t$lhs, $rhs",
574                  [(ARMcmpZ tGPR:$lhs, (ineg tGPR:$rhs))]>,
575             T1DataProcessing<0b1011>;
576 }
577
578 // CMP immediate
579 let Defs = [CPSR] in {
580 def tCMPi8 : T1pI<(outs), (ins tGPR:$lhs, i32imm:$rhs), IIC_iCMPi,
581                   "cmp", "\t$lhs, $rhs",
582                   [(ARMcmp tGPR:$lhs, imm0_255:$rhs)]>,
583              T1General<{1,0,1,?,?}>;
584 def tCMPzi8 : T1pI<(outs), (ins tGPR:$lhs, i32imm:$rhs), IIC_iCMPi,
585                   "cmp", "\t$lhs, $rhs",
586                   [(ARMcmpZ tGPR:$lhs, imm0_255:$rhs)]>,
587               T1General<{1,0,1,?,?}>;
588 }
589
590 // CMP register
591 let Defs = [CPSR] in {
592 def tCMPr : T1pI<(outs), (ins tGPR:$lhs, tGPR:$rhs), IIC_iCMPr,
593                  "cmp", "\t$lhs, $rhs",
594                  [(ARMcmp tGPR:$lhs, tGPR:$rhs)]>,
595             T1DataProcessing<0b1010>;
596 def tCMPzr : T1pI<(outs), (ins tGPR:$lhs, tGPR:$rhs), IIC_iCMPr,
597                   "cmp", "\t$lhs, $rhs",
598                   [(ARMcmpZ tGPR:$lhs, tGPR:$rhs)]>,
599              T1DataProcessing<0b1010>;
600
601 def tCMPhir : T1pI<(outs), (ins GPR:$lhs, GPR:$rhs), IIC_iCMPr,
602                    "cmp", "\t$lhs, $rhs", []>,
603               T1Special<{0,1,?,?}>;
604 def tCMPzhir : T1pI<(outs), (ins GPR:$lhs, GPR:$rhs), IIC_iCMPr,
605                     "cmp", "\t$lhs, $rhs", []>,
606                T1Special<{0,1,?,?}>;
607 }
608
609
610 // XOR register
611 let isCommutable = 1 in
612 def tEOR : T1sIt<(outs tGPR:$dst), (ins tGPR:$lhs, tGPR:$rhs), IIC_iALUr,
613                  "eor", "\t$dst, $rhs",
614                  [(set tGPR:$dst, (xor tGPR:$lhs, tGPR:$rhs))]>,
615            T1DataProcessing<0b0001>;
616
617 // LSL immediate
618 def tLSLri : T1sI<(outs tGPR:$dst), (ins tGPR:$lhs, i32imm:$rhs), IIC_iMOVsi,
619                   "lsl", "\t$dst, $lhs, $rhs",
620                   [(set tGPR:$dst, (shl tGPR:$lhs, (i32 imm:$rhs)))]>,
621              T1General<{0,0,0,?,?}>;
622
623 // LSL register
624 def tLSLrr : T1sIt<(outs tGPR:$dst), (ins tGPR:$lhs, tGPR:$rhs), IIC_iMOVsr,
625                    "lsl", "\t$dst, $rhs",
626                    [(set tGPR:$dst, (shl tGPR:$lhs, tGPR:$rhs))]>,
627              T1DataProcessing<0b0010>;
628
629 // LSR immediate
630 def tLSRri : T1sI<(outs tGPR:$dst), (ins tGPR:$lhs, i32imm:$rhs), IIC_iMOVsi,
631                   "lsr", "\t$dst, $lhs, $rhs",
632                   [(set tGPR:$dst, (srl tGPR:$lhs, (i32 imm:$rhs)))]>,
633              T1General<{0,0,1,?,?}>;
634
635 // LSR register
636 def tLSRrr : T1sIt<(outs tGPR:$dst), (ins tGPR:$lhs, tGPR:$rhs), IIC_iMOVsr,
637                    "lsr", "\t$dst, $rhs",
638                    [(set tGPR:$dst, (srl tGPR:$lhs, tGPR:$rhs))]>,
639              T1DataProcessing<0b0011>;
640
641 // move register
642 def tMOVi8 : T1sI<(outs tGPR:$dst), (ins i32imm:$src), IIC_iMOVi,
643                   "mov", "\t$dst, $src",
644                   [(set tGPR:$dst, imm0_255:$src)]>,
645              T1General<{1,0,0,?,?}>;
646
647 // TODO: A7-73: MOV(2) - mov setting flag.
648
649
650 let neverHasSideEffects = 1 in {
651 // FIXME: Make this predicable.
652 def tMOVr       : T1I<(outs tGPR:$dst), (ins tGPR:$src), IIC_iMOVr,
653                       "mov\t$dst, $src", []>,
654                   T1Special<0b1000>;
655 let Defs = [CPSR] in
656 def tMOVSr      : T1I<(outs tGPR:$dst), (ins tGPR:$src), IIC_iMOVr,
657                        "movs\t$dst, $src", []>, Encoding16 {
658   let Inst{15-6} = 0b0000000000;
659 }
660
661 // FIXME: Make these predicable.
662 def tMOVgpr2tgpr : T1I<(outs tGPR:$dst), (ins GPR:$src), IIC_iMOVr,
663                        "mov\t$dst, $src", []>,
664                    T1Special<{1,0,0,?}>;
665 def tMOVtgpr2gpr : T1I<(outs GPR:$dst), (ins tGPR:$src), IIC_iMOVr,
666                        "mov\t$dst, $src", []>,
667                    T1Special<{1,0,?,0}>;
668 def tMOVgpr2gpr  : T1I<(outs GPR:$dst), (ins GPR:$src), IIC_iMOVr,
669                        "mov\t$dst, $src", []>,
670                    T1Special<{1,0,?,?}>;
671 } // neverHasSideEffects
672
673 // multiply register
674 let isCommutable = 1 in
675 def tMUL : T1sIt<(outs tGPR:$dst), (ins tGPR:$lhs, tGPR:$rhs), IIC_iMUL32,
676                  "mul", "\t$dst, $rhs",
677                  [(set tGPR:$dst, (mul tGPR:$lhs, tGPR:$rhs))]>,
678            T1DataProcessing<0b1101>;
679
680 // move inverse register
681 def tMVN : T1sI<(outs tGPR:$dst), (ins tGPR:$src), IIC_iMOVr,
682                 "mvn", "\t$dst, $src",
683                 [(set tGPR:$dst, (not tGPR:$src))]>,
684            T1DataProcessing<0b1111>;
685
686 // bitwise or register
687 let isCommutable = 1 in
688 def tORR : T1sIt<(outs tGPR:$dst), (ins tGPR:$lhs, tGPR:$rhs),  IIC_iALUr,
689                  "orr", "\t$dst, $rhs",
690                  [(set tGPR:$dst, (or tGPR:$lhs, tGPR:$rhs))]>,
691            T1DataProcessing<0b1100>;
692
693 // swaps
694 def tREV : T1pI<(outs tGPR:$dst), (ins tGPR:$src), IIC_iUNAr,
695                 "rev", "\t$dst, $src",
696                 [(set tGPR:$dst, (bswap tGPR:$src))]>,
697                 Requires<[IsThumb1Only, HasV6]>,
698            T1Misc<{1,0,1,0,0,0,?}>;
699
700 def tREV16 : T1pI<(outs tGPR:$dst), (ins tGPR:$src), IIC_iUNAr,
701                   "rev16", "\t$dst, $src",
702              [(set tGPR:$dst,
703                    (or (and (srl tGPR:$src, (i32 8)), 0xFF),
704                        (or (and (shl tGPR:$src, (i32 8)), 0xFF00),
705                            (or (and (srl tGPR:$src, (i32 8)), 0xFF0000),
706                                (and (shl tGPR:$src, (i32 8)), 0xFF000000)))))]>,
707                 Requires<[IsThumb1Only, HasV6]>,
708              T1Misc<{1,0,1,0,0,1,?}>;
709
710 def tREVSH : T1pI<(outs tGPR:$dst), (ins tGPR:$src), IIC_iUNAr,
711                   "revsh", "\t$dst, $src",
712                   [(set tGPR:$dst,
713                         (sext_inreg
714                           (or (srl (and tGPR:$src, 0xFF00), (i32 8)),
715                               (shl tGPR:$src, (i32 8))), i16))]>,
716                   Requires<[IsThumb1Only, HasV6]>,
717              T1Misc<{1,0,1,0,1,1,?}>;
718
719 // rotate right register
720 def tROR : T1sIt<(outs tGPR:$dst), (ins tGPR:$lhs, tGPR:$rhs), IIC_iMOVsr,
721                  "ror", "\t$dst, $rhs",
722                  [(set tGPR:$dst, (rotr tGPR:$lhs, tGPR:$rhs))]>,
723            T1DataProcessing<0b0111>;
724
725 // negate register
726 def tRSB : T1sI<(outs tGPR:$dst), (ins tGPR:$src), IIC_iALUi,
727                 "rsb", "\t$dst, $src, #0",
728                 [(set tGPR:$dst, (ineg tGPR:$src))]>,
729            T1DataProcessing<0b1001>;
730
731 // Subtract with carry register
732 let Uses = [CPSR] in
733 def tSBC : T1sIt<(outs tGPR:$dst), (ins tGPR:$lhs, tGPR:$rhs), IIC_iALUr,
734                  "sbc", "\t$dst, $rhs",
735                  [(set tGPR:$dst, (sube tGPR:$lhs, tGPR:$rhs))]>,
736            T1DataProcessing<0b0110>;
737
738 // Subtract immediate
739 def tSUBi3 : T1sI<(outs tGPR:$dst), (ins tGPR:$lhs, i32imm:$rhs), IIC_iALUi,
740                   "sub", "\t$dst, $lhs, $rhs",
741                   [(set tGPR:$dst, (add tGPR:$lhs, imm0_7_neg:$rhs))]>,
742              T1General<0b01111>;
743
744 def tSUBi8 : T1sIt<(outs tGPR:$dst), (ins tGPR:$lhs, i32imm:$rhs), IIC_iALUi,
745                    "sub", "\t$dst, $rhs",
746                    [(set tGPR:$dst, (add tGPR:$lhs, imm8_255_neg:$rhs))]>,
747              T1General<{1,1,1,?,?}>;
748
749 // subtract register
750 def tSUBrr : T1sI<(outs tGPR:$dst), (ins tGPR:$lhs, tGPR:$rhs), IIC_iALUr,
751                   "sub", "\t$dst, $lhs, $rhs",
752                   [(set tGPR:$dst, (sub tGPR:$lhs, tGPR:$rhs))]>,
753              T1General<0b01101>;
754
755 // TODO: A7-96: STMIA - store multiple.
756
757 // sign-extend byte
758 def tSXTB  : T1pI<(outs tGPR:$dst), (ins tGPR:$src), IIC_iUNAr,
759                   "sxtb", "\t$dst, $src",
760                   [(set tGPR:$dst, (sext_inreg tGPR:$src, i8))]>,
761                   Requires<[IsThumb1Only, HasV6]>,
762              T1Misc<{0,0,1,0,0,1,?}>;
763
764 // sign-extend short
765 def tSXTH  : T1pI<(outs tGPR:$dst), (ins tGPR:$src), IIC_iUNAr,
766                   "sxth", "\t$dst, $src",
767                   [(set tGPR:$dst, (sext_inreg tGPR:$src, i16))]>,
768                   Requires<[IsThumb1Only, HasV6]>,
769              T1Misc<{0,0,1,0,0,0,?}>;
770
771 // test
772 let isCommutable = 1, Defs = [CPSR] in
773 def tTST  : T1pI<(outs), (ins tGPR:$lhs, tGPR:$rhs), IIC_iCMPr,
774                  "tst", "\t$lhs, $rhs",
775                  [(ARMcmpZ (and tGPR:$lhs, tGPR:$rhs), 0)]>,
776             T1DataProcessing<0b1000>;
777
778 // zero-extend byte
779 def tUXTB  : T1pI<(outs tGPR:$dst), (ins tGPR:$src), IIC_iUNAr,
780                   "uxtb", "\t$dst, $src",
781                   [(set tGPR:$dst, (and tGPR:$src, 0xFF))]>,
782                   Requires<[IsThumb1Only, HasV6]>,
783              T1Misc<{0,0,1,0,1,1,?}>;
784
785 // zero-extend short
786 def tUXTH  : T1pI<(outs tGPR:$dst), (ins tGPR:$src), IIC_iUNAr,
787                   "uxth", "\t$dst, $src",
788                   [(set tGPR:$dst, (and tGPR:$src, 0xFFFF))]>,
789                   Requires<[IsThumb1Only, HasV6]>,
790              T1Misc<{0,0,1,0,1,0,?}>;
791
792
793 // Conditional move tMOVCCr - Used to implement the Thumb SELECT_CC operation.
794 // Expanded after instruction selection into a branch sequence.
795 let usesCustomInserter = 1 in  // Expanded after instruction selection.
796   def tMOVCCr_pseudo :
797   PseudoInst<(outs tGPR:$dst), (ins tGPR:$false, tGPR:$true, pred:$cc),
798               NoItinerary, "@ tMOVCCr $cc",
799              [/*(set tGPR:$dst, (ARMcmov tGPR:$false, tGPR:$true, imm:$cc))*/]>;
800
801
802 // 16-bit movcc in IT blocks for Thumb2.
803 def tMOVCCr : T1pIt<(outs GPR:$dst), (ins GPR:$lhs, GPR:$rhs), IIC_iCMOVr,
804                     "mov", "\t$dst, $rhs", []>,
805               T1Special<{1,0,?,?}>;
806
807 def tMOVCCi : T1pIt<(outs tGPR:$dst), (ins tGPR:$lhs, i32imm:$rhs), IIC_iCMOVi,
808                     "mov", "\t$dst, $rhs", []>,
809               T1General<{1,0,0,?,?}>;
810
811 // tLEApcrel - Load a pc-relative address into a register without offending the
812 // assembler.
813 def tLEApcrel : T1I<(outs tGPR:$dst), (ins i32imm:$label, pred:$p), IIC_iALUi,
814                     "adr$p\t$dst, #$label", []>,
815                 T1Encoding<{1,0,1,0,0,?}>; // A6.2 & A8.6.10
816
817 def tLEApcrelJT : T1I<(outs tGPR:$dst),
818                       (ins i32imm:$label, nohash_imm:$id, pred:$p),
819                       IIC_iALUi, "adr$p\t$dst, #${label}_${id}", []>,
820                   T1Encoding<{1,0,1,0,0,?}>; // A6.2 & A8.6.10
821
822 //===----------------------------------------------------------------------===//
823 // TLS Instructions
824 //
825
826 // __aeabi_read_tp preserves the registers r1-r3.
827 let isCall = 1,
828   Defs = [R0, LR] in {
829   def tTPsoft : TIx2<0b11110, 0b11, 1, (outs), (ins), IIC_Br,
830                      "bl\t__aeabi_read_tp",
831                      [(set R0, ARMthread_pointer)]>;
832 }
833
834 // SJLJ Exception handling intrinsics
835 //   eh_sjlj_setjmp() is an instruction sequence to store the return
836 //   address and save #0 in R0 for the non-longjmp case.
837 //   Since by its nature we may be coming from some other function to get
838 //   here, and we're using the stack frame for the containing function to
839 //   save/restore registers, we can't keep anything live in regs across
840 //   the eh_sjlj_setjmp(), else it will almost certainly have been tromped upon
841 //   when we get here from a longjmp(). We force everthing out of registers
842 //   except for our own input by listing the relevant registers in Defs. By
843 //   doing so, we also cause the prologue/epilogue code to actively preserve
844 //   all of the callee-saved resgisters, which is exactly what we want.
845 //   The current SP is passed in $val, and we reuse the reg as a scratch.
846 let Defs =
847   [ R0,  R1,  R2,  R3,  R4,  R5,  R6,  R7, R12 ] in {
848   def tInt_eh_sjlj_setjmp : ThumbXI<(outs),(ins tGPR:$src, tGPR:$val),
849                               AddrModeNone, SizeSpecial, NoItinerary,
850                               "str\t$val, [$src, #8]\t@ begin eh.setjmp\n"
851                               "\tmov\t$val, pc\n"
852                               "\tadds\t$val, #9\n"
853                               "\tstr\t$val, [$src, #4]\n"
854                               "\tmovs\tr0, #0\n"
855                               "\tb\t1f\n"
856                               "\tmovs\tr0, #1\t@ end eh.setjmp\n"
857                               "1:", "",
858                    [(set R0, (ARMeh_sjlj_setjmp tGPR:$src, tGPR:$val))]>;
859 }
860 //===----------------------------------------------------------------------===//
861 // Non-Instruction Patterns
862 //
863
864 // Add with carry
865 def : T1Pat<(addc   tGPR:$lhs, imm0_7:$rhs),
866             (tADDi3 tGPR:$lhs, imm0_7:$rhs)>;
867 def : T1Pat<(addc   tGPR:$lhs, imm8_255:$rhs),
868             (tADDi8 tGPR:$lhs, imm8_255:$rhs)>;
869 def : T1Pat<(addc   tGPR:$lhs, tGPR:$rhs),
870             (tADDrr tGPR:$lhs, tGPR:$rhs)>;
871
872 // Subtract with carry
873 def : T1Pat<(addc   tGPR:$lhs, imm0_7_neg:$rhs),
874             (tSUBi3 tGPR:$lhs, imm0_7_neg:$rhs)>;
875 def : T1Pat<(addc   tGPR:$lhs, imm8_255_neg:$rhs),
876             (tSUBi8 tGPR:$lhs, imm8_255_neg:$rhs)>;
877 def : T1Pat<(subc   tGPR:$lhs, tGPR:$rhs),
878             (tSUBrr tGPR:$lhs, tGPR:$rhs)>;
879
880 // ConstantPool, GlobalAddress
881 def : T1Pat<(ARMWrapper  tglobaladdr :$dst), (tLEApcrel tglobaladdr :$dst)>;
882 def : T1Pat<(ARMWrapper  tconstpool  :$dst), (tLEApcrel tconstpool  :$dst)>;
883
884 // JumpTable
885 def : T1Pat<(ARMWrapperJT tjumptable:$dst, imm:$id),
886             (tLEApcrelJT tjumptable:$dst, imm:$id)>;
887
888 // Direct calls
889 def : T1Pat<(ARMtcall texternalsym:$func), (tBL texternalsym:$func)>,
890       Requires<[IsThumb, IsNotDarwin]>;
891 def : T1Pat<(ARMtcall texternalsym:$func), (tBLr9 texternalsym:$func)>,
892       Requires<[IsThumb, IsDarwin]>;
893
894 def : Tv5Pat<(ARMcall texternalsym:$func), (tBLXi texternalsym:$func)>,
895       Requires<[IsThumb, HasV5T, IsNotDarwin]>;
896 def : Tv5Pat<(ARMcall texternalsym:$func), (tBLXi_r9 texternalsym:$func)>,
897       Requires<[IsThumb, HasV5T, IsDarwin]>;
898
899 // Indirect calls to ARM routines
900 def : Tv5Pat<(ARMcall GPR:$dst), (tBLXr GPR:$dst)>,
901       Requires<[IsThumb, HasV5T, IsNotDarwin]>;
902 def : Tv5Pat<(ARMcall GPR:$dst), (tBLXr_r9 GPR:$dst)>,
903       Requires<[IsThumb, HasV5T, IsDarwin]>;
904
905 // zextload i1 -> zextload i8
906 def : T1Pat<(zextloadi1 t_addrmode_s1:$addr),
907             (tLDRB t_addrmode_s1:$addr)>;
908
909 // extload -> zextload
910 def : T1Pat<(extloadi1  t_addrmode_s1:$addr),  (tLDRB t_addrmode_s1:$addr)>;
911 def : T1Pat<(extloadi8  t_addrmode_s1:$addr),  (tLDRB t_addrmode_s1:$addr)>;
912 def : T1Pat<(extloadi16 t_addrmode_s2:$addr),  (tLDRH t_addrmode_s2:$addr)>;
913
914 // If it's impossible to use [r,r] address mode for sextload, select to
915 // ldr{b|h} + sxt{b|h} instead.
916 def : T1Pat<(sextloadi8 t_addrmode_s1:$addr),
917             (tSXTB (tLDRB t_addrmode_s1:$addr))>,
918       Requires<[IsThumb1Only, HasV6]>;
919 def : T1Pat<(sextloadi16 t_addrmode_s2:$addr),
920             (tSXTH (tLDRH t_addrmode_s2:$addr))>,
921       Requires<[IsThumb1Only, HasV6]>;
922
923 def : T1Pat<(sextloadi8 t_addrmode_s1:$addr),
924             (tASRri (tLSLri (tLDRB t_addrmode_s1:$addr), 24), 24)>;
925 def : T1Pat<(sextloadi16 t_addrmode_s1:$addr),
926             (tASRri (tLSLri (tLDRH t_addrmode_s1:$addr), 16), 16)>;
927
928 // Large immediate handling.
929
930 // Two piece imms.
931 def : T1Pat<(i32 thumb_immshifted:$src),
932             (tLSLri (tMOVi8 (thumb_immshifted_val imm:$src)),
933                     (thumb_immshifted_shamt imm:$src))>;
934
935 def : T1Pat<(i32 imm0_255_comp:$src),
936             (tMVN (tMOVi8 (imm_comp_XFORM imm:$src)))>;
937
938 // Pseudo instruction that combines ldr from constpool and add pc. This should
939 // be expanded into two instructions late to allow if-conversion and
940 // scheduling.
941 let isReMaterializable = 1 in
942 def tLDRpci_pic : PseudoInst<(outs GPR:$dst), (ins i32imm:$addr, pclabel:$cp),
943                    NoItinerary, "@ ldr.n\t$dst, $addr\n$cp:\n\tadd\t$dst, pc",
944                [(set GPR:$dst, (ARMpic_add (load (ARMWrapper tconstpool:$addr)),
945                                            imm:$cp))]>,
946                Requires<[IsThumb1Only]>;