Add some missing patterns now that tLDRB and tLDRH are split into reg and
[oota-llvm.git] / lib / Target / ARM / ARMInstrThumb.td
1 //===- ARMInstrThumb.td - Thumb support for ARM ------------*- tablegen -*-===//
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                        SDNPVariadic]>;
21
22 def imm_neg_XFORM : SDNodeXForm<imm, [{
23   return CurDAG->getTargetConstant(-(int)N->getZExtValue(), MVT::i32);
24 }]>;
25 def imm_comp_XFORM : SDNodeXForm<imm, [{
26   return CurDAG->getTargetConstant(~((uint32_t)N->getZExtValue()), MVT::i32);
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. This uses
53 // thumb_immshifted to match and thumb_immshifted_val and thumb_immshifted_shamt
54 // 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 // ADR instruction labels.
70 def t_adrlabel : Operand<i32> {
71   let EncoderMethod = "getThumbAdrLabelOpValue";
72 }
73
74 // Scaled 4 immediate.
75 def t_imm_s4 : Operand<i32> {
76   let PrintMethod = "printThumbS4ImmOperand";
77 }
78
79 // Define Thumb specific addressing modes.
80
81 def t_brtarget : Operand<OtherVT> {
82   let EncoderMethod = "getThumbBRTargetOpValue";
83 }
84
85 def t_bcctarget : Operand<i32> {
86   let EncoderMethod = "getThumbBCCTargetOpValue";
87 }
88
89 def t_cbtarget : Operand<i32> {
90   let EncoderMethod = "getThumbCBTargetOpValue";
91 }
92
93 def t_bltarget : Operand<i32> {
94   let EncoderMethod = "getThumbBLTargetOpValue";
95 }
96
97 def t_blxtarget : Operand<i32> {
98   let EncoderMethod = "getThumbBLXTargetOpValue";
99 }
100
101 def MemModeRegThumbAsmOperand : AsmOperandClass {
102   let Name = "MemModeRegThumb";
103   let SuperClasses = [];
104 }
105
106 def MemModeImmThumbAsmOperand : AsmOperandClass {
107   let Name = "MemModeImmThumb";
108   let SuperClasses = [];
109 }
110
111 // t_addrmode_rr := reg + reg
112 //
113 def t_addrmode_rr : Operand<i32>,
114                     ComplexPattern<i32, 2, "SelectThumbAddrModeRR", []> {
115   let EncoderMethod = "getThumbAddrModeRegRegOpValue";
116   let PrintMethod = "printThumbAddrModeRROperand";
117   let MIOperandInfo = (ops tGPR:$base, tGPR:$offsreg);
118 }
119
120 // t_addrmode_rrs := reg + reg
121 //
122 def t_addrmode_rrs1 : Operand<i32>,
123                       ComplexPattern<i32, 2, "SelectThumbAddrModeRI5S1", []> {
124   let EncoderMethod = "getThumbAddrModeRegRegOpValue";
125   let PrintMethod = "printThumbAddrModeRROperand";
126   let MIOperandInfo = (ops tGPR:$base, tGPR:$offsreg);
127   let ParserMatchClass = MemModeRegThumbAsmOperand;
128 }
129 def t_addrmode_rrs2 : Operand<i32>,
130                       ComplexPattern<i32, 2, "SelectThumbAddrModeRI5S2", []> {
131   let EncoderMethod = "getThumbAddrModeRegRegOpValue";
132   let PrintMethod = "printThumbAddrModeRROperand";
133   let MIOperandInfo = (ops tGPR:$base, tGPR:$offsreg);
134   let ParserMatchClass = MemModeRegThumbAsmOperand;
135 }
136 def t_addrmode_rrs4 : Operand<i32>,
137                       ComplexPattern<i32, 2, "SelectThumbAddrModeRI5S4", []> {
138   let EncoderMethod = "getThumbAddrModeRegRegOpValue";
139   let PrintMethod = "printThumbAddrModeRROperand";
140   let MIOperandInfo = (ops tGPR:$base, tGPR:$offsreg);
141   let ParserMatchClass = MemModeRegThumbAsmOperand;
142 }
143
144 // t_addrmode_is4 := reg + imm5 * 4
145 //
146 def t_addrmode_is4 : Operand<i32>,
147                      ComplexPattern<i32, 2, "SelectThumbAddrModeImm5S4", []> {
148   let EncoderMethod = "getAddrModeISOpValue";
149   let PrintMethod = "printThumbAddrModeImm5S4Operand";
150   let MIOperandInfo = (ops tGPR:$base, i32imm:$offsimm);
151   let ParserMatchClass = MemModeImmThumbAsmOperand;
152 }
153
154 // t_addrmode_is2 := reg + imm5 * 2
155 //
156 def t_addrmode_is2 : Operand<i32>,
157                      ComplexPattern<i32, 2, "SelectThumbAddrModeImm5S2", []> {
158   let EncoderMethod = "getAddrModeISOpValue";
159   let PrintMethod = "printThumbAddrModeImm5S2Operand";
160   let MIOperandInfo = (ops tGPR:$base, i32imm:$offsimm);
161   let ParserMatchClass = MemModeImmThumbAsmOperand;
162 }
163
164 // t_addrmode_is1 := reg + imm5
165 //
166 def t_addrmode_is1 : Operand<i32>,
167                      ComplexPattern<i32, 2, "SelectThumbAddrModeImm5S1", []> {
168   let EncoderMethod = "getAddrModeISOpValue";
169   let PrintMethod = "printThumbAddrModeImm5S1Operand";
170   let MIOperandInfo = (ops tGPR:$base, i32imm:$offsimm);
171   let ParserMatchClass = MemModeImmThumbAsmOperand;
172 }
173
174 // t_addrmode_sp := sp + imm8 * 4
175 //
176 def t_addrmode_sp : Operand<i32>,
177                     ComplexPattern<i32, 2, "SelectThumbAddrModeSP", []> {
178   let EncoderMethod = "getAddrModeThumbSPOpValue";
179   let PrintMethod = "printThumbAddrModeSPOperand";
180   let MIOperandInfo = (ops GPR:$base, i32imm:$offsimm);
181   let ParserMatchClass = MemModeImmThumbAsmOperand;
182 }
183
184 // t_addrmode_pc := <label> => pc + imm8 * 4
185 //
186 def t_addrmode_pc : Operand<i32> {
187   let EncoderMethod = "getAddrModePCOpValue";
188   let ParserMatchClass = MemModeImmThumbAsmOperand;
189 }
190
191 //===----------------------------------------------------------------------===//
192 //  Miscellaneous Instructions.
193 //
194
195 // FIXME: Marking these as hasSideEffects is necessary to prevent machine DCE
196 // from removing one half of the matched pairs. That breaks PEI, which assumes
197 // these will always be in pairs, and asserts if it finds otherwise. Better way?
198 let Defs = [SP], Uses = [SP], hasSideEffects = 1 in {
199 def tADJCALLSTACKUP :
200   PseudoInst<(outs), (ins i32imm:$amt1, i32imm:$amt2), NoItinerary,
201              [(ARMcallseq_end imm:$amt1, imm:$amt2)]>,
202             Requires<[IsThumb, IsThumb1Only]>;
203
204 def tADJCALLSTACKDOWN :
205   PseudoInst<(outs), (ins i32imm:$amt), NoItinerary,
206              [(ARMcallseq_start imm:$amt)]>,
207             Requires<[IsThumb, IsThumb1Only]>;
208 }
209
210 // T1Disassembly - A simple class to make encoding some disassembly patterns
211 // easier and less verbose.
212 class T1Disassembly<bits<2> op1, bits<8> op2>
213   : T1Encoding<0b101111> {
214   let Inst{9-8} = op1;
215   let Inst{7-0} = op2;
216 }
217
218 def tNOP : T1pI<(outs), (ins), NoItinerary, "nop", "",
219                 [/* For disassembly only; pattern left blank */]>,
220            T1Disassembly<0b11, 0x00>; // A8.6.110
221
222 def tYIELD : T1pI<(outs), (ins), NoItinerary, "yield", "",
223                   [/* For disassembly only; pattern left blank */]>,
224            T1Disassembly<0b11, 0x10>; // A8.6.410
225
226 def tWFE : T1pI<(outs), (ins), NoItinerary, "wfe", "",
227                 [/* For disassembly only; pattern left blank */]>,
228            T1Disassembly<0b11, 0x20>; // A8.6.408
229
230 def tWFI : T1pI<(outs), (ins), NoItinerary, "wfi", "",
231                 [/* For disassembly only; pattern left blank */]>,
232            T1Disassembly<0b11, 0x30>; // A8.6.409
233
234 def tSEV : T1pI<(outs), (ins), NoItinerary, "sev", "",
235                 [/* For disassembly only; pattern left blank */]>,
236            T1Disassembly<0b11, 0x40>; // A8.6.157
237
238 // The i32imm operand $val can be used by a debugger to store more information
239 // about the breakpoint.
240 def tBKPT : T1I<(outs), (ins i32imm:$val), NoItinerary, "bkpt\t$val",
241                 [/* For disassembly only; pattern left blank */]>,
242            T1Disassembly<0b10, {?,?,?,?,?,?,?,?}> {
243   // A8.6.22
244   bits<8> val;
245   let Inst{7-0} = val;
246 }
247
248 def tSETENDBE : T1I<(outs), (ins), NoItinerary, "setend\tbe",
249                     [/* For disassembly only; pattern left blank */]>,
250                 T1Encoding<0b101101> {
251   // A8.6.156
252   let Inst{9-5} = 0b10010;
253   let Inst{4}   = 1;
254   let Inst{3}   = 1;            // Big-Endian
255   let Inst{2-0} = 0b000;
256 }
257
258 def tSETENDLE : T1I<(outs), (ins), NoItinerary, "setend\tle",
259                     [/* For disassembly only; pattern left blank */]>,
260                 T1Encoding<0b101101> {
261   // A8.6.156
262   let Inst{9-5} = 0b10010;
263   let Inst{4}   = 1;
264   let Inst{3}   = 0;            // Little-Endian
265   let Inst{2-0} = 0b000;
266 }
267
268 // Change Processor State is a system instruction -- for disassembly only.
269 // The singleton $opt operand contains the following information:
270 // 
271 //   opt{4-0} = mode ==> don't care
272 //   opt{5} = changemode ==> 0 (false for 16-bit Thumb instr)
273 //   opt{8-6} = AIF from Inst{2-0}
274 //   opt{10-9} = 1:imod from Inst{4} with 0b10 as enable and 0b11 as disable
275 //
276 // The opt{4-0} and opt{5} sub-fields are to accommodate 32-bit Thumb and ARM
277 // CPS which has more options.
278 def tCPS : T1I<(outs), (ins cps_opt:$opt), NoItinerary, "cps$opt",
279               [/* For disassembly only; pattern left blank */]>,
280            T1Misc<0b0110011> {
281   // A8.6.38 & B6.1.1
282   let Inst{3} = 0;
283   // FIXME: Finish encoding.
284 }
285
286 // For both thumb1 and thumb2.
287 let isNotDuplicable = 1, isCodeGenOnly = 1 in
288 def tPICADD : TIt<(outs GPR:$dst), (ins GPR:$lhs, pclabel:$cp), IIC_iALUr, "",
289                   [(set GPR:$dst, (ARMpic_add GPR:$lhs, imm:$cp))]>,
290               T1Special<{0,0,?,?}> {
291   // A8.6.6
292   bits<3> dst;
293   let Inst{6-3} = 0b1111; // Rm = pc
294   let Inst{2-0} = dst;
295 }
296
297 // PC relative add (ADR).
298 def tADDrPCi : T1I<(outs tGPR:$dst), (ins t_imm_s4:$rhs), IIC_iALUi,
299                    "add\t$dst, pc, $rhs", []>,
300                T1Encoding<{1,0,1,0,0,?}> {
301   // A6.2 & A8.6.10
302   bits<3> dst;
303   bits<8> rhs;
304   let Inst{10-8} = dst;
305   let Inst{7-0}  = rhs;
306 }
307
308 // ADD <Rd>, sp, #<imm8>
309 // This is rematerializable, which is particularly useful for taking the
310 // address of locals.
311 let isReMaterializable = 1 in
312 def tADDrSPi : T1I<(outs tGPR:$dst), (ins GPR:$sp, t_imm_s4:$rhs), IIC_iALUi,
313                    "add\t$dst, $sp, $rhs", []>,
314                T1Encoding<{1,0,1,0,1,?}> {
315   // A6.2 & A8.6.8
316   bits<3> dst;
317   bits<8> rhs;
318   let Inst{10-8} = dst;
319   let Inst{7-0}  = rhs;
320 }
321
322 // ADD sp, sp, #<imm7>
323 def tADDspi : TIt<(outs GPR:$dst), (ins GPR:$lhs, t_imm_s4:$rhs), IIC_iALUi,
324                   "add\t$dst, $rhs", []>,
325               T1Misc<{0,0,0,0,0,?,?}> {
326   // A6.2.5 & A8.6.8
327   bits<7> rhs;
328   let Inst{6-0} = rhs;
329 }
330
331 // SUB sp, sp, #<imm7>
332 // FIXME: The encoding and the ASM string don't match up.
333 def tSUBspi : TIt<(outs GPR:$dst), (ins GPR:$lhs, t_imm_s4:$rhs), IIC_iALUi,
334                   "sub\t$dst, $rhs", []>,
335               T1Misc<{0,0,0,0,1,?,?}> {
336   // A6.2.5 & A8.6.214
337   bits<7> rhs;
338   let Inst{6-0} = rhs;
339 }
340
341 // ADD <Rm>, sp
342 def tADDrSP : TIt<(outs GPR:$dst), (ins GPR:$lhs, GPR:$rhs), IIC_iALUr,
343                   "add\t$dst, $rhs", []>,
344               T1Special<{0,0,?,?}> {
345   // A8.6.9 Encoding T1
346   bits<4> dst;
347   let Inst{7}   = dst{3};
348   let Inst{6-3} = 0b1101;
349   let Inst{2-0} = dst{2-0};
350 }
351
352 // ADD sp, <Rm>
353 def tADDspr : TIt<(outs GPR:$dst), (ins GPR:$lhs, GPR:$rhs), IIC_iALUr,
354                   "add\t$dst, $rhs", []>,
355               T1Special<{0,0,?,?}> {
356   // A8.6.9 Encoding T2
357   bits<4> dst;
358   let Inst{7} = 1;
359   let Inst{6-3} = dst;
360   let Inst{2-0} = 0b101;
361 }
362
363 //===----------------------------------------------------------------------===//
364 //  Control Flow Instructions.
365 //
366
367 let isReturn = 1, isTerminator = 1, isBarrier = 1 in {
368   def tBX_RET : TI<(outs), (ins), IIC_Br, "bx\tlr",
369                    [(ARMretflag)]>,
370                 T1Special<{1,1,0,?}> {
371     // A6.2.3 & A8.6.25
372     let Inst{6-3} = 0b1110; // Rm = lr
373     let Inst{2-0} = 0b000;
374   }
375
376   // Alternative return instruction used by vararg functions.
377   def tBX_RET_vararg : TI<(outs), (ins tGPR:$Rm),
378                           IIC_Br, "bx\t$Rm",
379                           []>,
380                        T1Special<{1,1,0,?}> {
381     // A6.2.3 & A8.6.25
382     bits<4> Rm;
383     let Inst{6-3} = Rm;
384     let Inst{2-0} = 0b000;
385   }
386 }
387
388 // Indirect branches
389 let isBranch = 1, isTerminator = 1, isBarrier = 1, isIndirectBranch = 1 in {
390   def tBRIND : TI<(outs), (ins GPR:$Rm),
391                   IIC_Br,
392                   "mov\tpc, $Rm",
393                   [(brind GPR:$Rm)]>,
394                T1Special<{1,0,?,?}> {
395     // A8.6.97
396     bits<4> Rm;
397     let Inst{7}   = 1;          // <Rd> = Inst{7:2-0} = pc
398     let Inst{6-3} = Rm;
399     let Inst{2-0} = 0b111;
400   }
401 }
402
403 // FIXME: remove when we have a way to marking a MI with these properties.
404 let isReturn = 1, isTerminator = 1, isBarrier = 1, mayLoad = 1,
405     hasExtraDefRegAllocReq = 1 in
406 def tPOP_RET : T1I<(outs), (ins pred:$p, reglist:$regs, variable_ops),
407                    IIC_iPop_Br,
408                    "pop${p}\t$regs", []>,
409                T1Misc<{1,1,0,?,?,?,?}> {
410   // A8.6.121
411   bits<16> regs;
412   let Inst{8}   = regs{15};     // registers = P:'0000000':register_list
413   let Inst{7-0} = regs{7-0};
414 }
415
416 // All calls clobber the non-callee saved registers. SP is marked as a use to
417 // prevent stack-pointer assignments that appear immediately before calls from
418 // potentially appearing dead.
419 let isCall = 1,
420   // On non-Darwin platforms R9 is callee-saved.
421   Defs = [R0,  R1,  R2,  R3,  R12, LR,
422           D0,  D1,  D2,  D3,  D4,  D5,  D6,  D7,
423           D16, D17, D18, D19, D20, D21, D22, D23,
424           D24, D25, D26, D27, D28, D29, D30, D31, CPSR, FPSCR],
425   Uses = [SP] in {
426   // Also used for Thumb2
427   def tBL  : TIx2<0b11110, 0b11, 1,
428                   (outs), (ins t_bltarget:$func, variable_ops), IIC_Br,
429                   "bl\t$func",
430                   [(ARMtcall tglobaladdr:$func)]>,
431              Requires<[IsThumb, IsNotDarwin]> {
432     bits<21> func;
433     let Inst{25-16} = func{20-11};
434     let Inst{13} = 1;
435     let Inst{11} = 1;
436     let Inst{10-0} = func{10-0};
437   }
438
439   // ARMv5T and above, also used for Thumb2
440   def tBLXi : TIx2<0b11110, 0b11, 0,
441                    (outs), (ins t_blxtarget:$func, variable_ops), IIC_Br,
442                    "blx\t$func",
443                    [(ARMcall tglobaladdr:$func)]>,
444               Requires<[IsThumb, HasV5T, IsNotDarwin]> {
445     bits<21> func;
446     let Inst{25-16} = func{20-11};
447     let Inst{13} = 1;
448     let Inst{11} = 1;
449     let Inst{10-1} = func{10-1};
450     let Inst{0} = 0; // func{0} is assumed zero
451   }
452
453   // Also used for Thumb2
454   def tBLXr : TI<(outs), (ins GPR:$func, variable_ops), IIC_Br,
455                   "blx\t$func",
456                   [(ARMtcall GPR:$func)]>,
457               Requires<[IsThumb, HasV5T, IsNotDarwin]>,
458               T1Special<{1,1,1,?}>; // A6.2.3 & A8.6.24;
459
460   // ARMv4T
461   // FIXME: Should be a pseudo.
462   let isCodeGenOnly = 1 in
463   def tBX : TIx2<{?,?,?,?,?}, {?,?}, ?,
464                   (outs), (ins tGPR:$func, variable_ops), IIC_Br,
465                   "mov\tlr, pc\n\tbx\t$func",
466                   [(ARMcall_nolink tGPR:$func)]>,
467             Requires<[IsThumb, IsThumb1Only, IsNotDarwin]>;
468 }
469
470 let isCall = 1,
471   // On Darwin R9 is call-clobbered.
472   // R7 is marked as a use to prevent frame-pointer assignments from being
473   // moved above / below calls.
474   Defs = [R0,  R1,  R2,  R3,  R9,  R12, LR,
475           D0,  D1,  D2,  D3,  D4,  D5,  D6,  D7,
476           D16, D17, D18, D19, D20, D21, D22, D23,
477           D24, D25, D26, D27, D28, D29, D30, D31, CPSR, FPSCR],
478   Uses = [R7, SP] in {
479   // Also used for Thumb2
480   def tBLr9 : TIx2<0b11110, 0b11, 1,
481                    (outs), (ins pred:$p, t_bltarget:$func, variable_ops),
482                    IIC_Br, "bl${p}\t$func",
483                    [(ARMtcall tglobaladdr:$func)]>,
484               Requires<[IsThumb, IsDarwin]> {
485     bits<21> func;
486     let Inst{25-16} = func{20-11};
487     let Inst{13} = 1;
488     let Inst{11} = 1;
489     let Inst{10-0} = func{10-0};
490   }
491
492   // ARMv5T and above, also used for Thumb2
493   def tBLXi_r9 : TIx2<0b11110, 0b11, 0,
494                       (outs), (ins pred:$p, t_blxtarget:$func, variable_ops),
495                       IIC_Br, "blx${p}\t$func",
496                       [(ARMcall tglobaladdr:$func)]>,
497                  Requires<[IsThumb, HasV5T, IsDarwin]> {
498     bits<21> func;
499     let Inst{25-16} = func{20-11};
500     let Inst{13} = 1;
501     let Inst{11} = 1;
502     let Inst{10-1} = func{10-1};
503     let Inst{0} = 0; // func{0} is assumed zero
504   }
505
506   // Also used for Thumb2
507   def tBLXr_r9 : TI<(outs), (ins pred:$p, GPR:$func, variable_ops), IIC_Br,
508                     "blx${p}\t$func",
509                     [(ARMtcall GPR:$func)]>,
510                  Requires<[IsThumb, HasV5T, IsDarwin]>,
511                  T1Special<{1,1,1,?}> {
512     // A6.2.3 & A8.6.24
513     bits<4> func;
514     let Inst{6-3} = func;
515     let Inst{2-0} = 0b000;
516   }
517
518   // ARMv4T
519   let isCodeGenOnly = 1 in
520   // FIXME: Should be a pseudo.
521   def tBXr9 : TIx2<{?,?,?,?,?}, {?,?}, ?,
522                    (outs), (ins tGPR:$func, variable_ops), IIC_Br,
523                    "mov\tlr, pc\n\tbx\t$func",
524                    [(ARMcall_nolink tGPR:$func)]>,
525               Requires<[IsThumb, IsThumb1Only, IsDarwin]>;
526 }
527
528 let isBranch = 1, isTerminator = 1, isBarrier = 1 in {
529   let isPredicable = 1 in
530   def tB   : T1I<(outs), (ins t_brtarget:$target), IIC_Br,
531                  "b\t$target", [(br bb:$target)]>,
532              T1Encoding<{1,1,1,0,0,?}> {
533     bits<11> target;
534     let Inst{10-0} = target;
535   }
536
537   // Far jump
538   // FIXME: Encoding. This should probably be a pseudo for tBL
539   let Defs = [LR] in
540   def tBfar : TIx2<0b11110, 0b11, 1, (outs), (ins brtarget:$target), IIC_Br,
541                     "bl\t$target",[]>;
542
543   def tBR_JTr : tPseudoInst<(outs),
544                       (ins tGPR:$target, i32imm:$jt, i32imm:$id),
545                       Size2Bytes, IIC_Br,
546                       [(ARMbrjt tGPR:$target, tjumptable:$jt, imm:$id)]> {
547     list<Predicate> Predicates = [IsThumb, IsThumb1Only];
548   }
549 }
550
551 // FIXME: should be able to write a pattern for ARMBrcond, but can't use
552 // a two-value operand where a dag node expects two operands. :(
553 let isBranch = 1, isTerminator = 1 in
554   def tBcc : T1I<(outs), (ins t_bcctarget:$target, pred:$p), IIC_Br,
555                  "b${p}\t$target",
556                  [/*(ARMbrcond bb:$target, imm:$cc)*/]>,
557              T1Encoding<{1,1,0,1,?,?}> {
558   bits<4> p;
559   bits<8> target;
560   let Inst{11-8} = p;
561   let Inst{7-0} = target;
562 }
563
564 // Compare and branch on zero / non-zero
565 let isBranch = 1, isTerminator = 1 in {
566   def tCBZ  : T1I<(outs), (ins tGPR:$Rn, t_cbtarget:$target), IIC_Br,
567                   "cbz\t$Rn, $target", []>,
568               T1Misc<{0,0,?,1,?,?,?}> {
569     // A8.6.27
570     bits<6> target;
571     bits<3> Rn;
572     let Inst{9}   = target{5};
573     let Inst{7-3} = target{4-0};
574     let Inst{2-0} = Rn;
575   }
576
577   def tCBNZ : T1I<(outs), (ins tGPR:$cmp, t_cbtarget:$target), IIC_Br,
578                   "cbnz\t$cmp, $target", []>,
579               T1Misc<{1,0,?,1,?,?,?}> {
580     // A8.6.27
581     bits<6> target;
582     bits<3> Rn;
583     let Inst{9}   = target{5};
584     let Inst{7-3} = target{4-0};
585     let Inst{2-0} = Rn;
586   }
587 }
588
589 // A8.6.218 Supervisor Call (Software Interrupt) -- for disassembly only
590 // A8.6.16 B: Encoding T1
591 // If Inst{11-8} == 0b1111 then SEE SVC
592 let isCall = 1, Uses = [SP] in
593 def tSVC : T1pI<(outs), (ins i32imm:$imm), IIC_Br,
594                 "svc", "\t$imm", []>, Encoding16 {
595   bits<8> imm;
596   let Inst{15-12} = 0b1101;
597   let Inst{11-8}  = 0b1111;
598   let Inst{7-0}   = imm;
599 }
600
601 // The assembler uses 0xDEFE for a trap instruction.
602 let isBarrier = 1, isTerminator = 1 in
603 def tTRAP : TI<(outs), (ins), IIC_Br, 
604                "trap", [(trap)]>, Encoding16 {
605   let Inst = 0xdefe;
606 }
607
608 //===----------------------------------------------------------------------===//
609 //  Load Store Instructions.
610 //
611
612 // Loads: reg/reg and reg/imm5
613 let canFoldAsLoad = 1, isReMaterializable = 1 in
614 multiclass thumb_ld_rr_ri_enc<bits<3> reg_opc, bits<4> imm_opc,
615                               Operand AddrMode_r, Operand AddrMode_i,
616                               AddrMode am, InstrItinClass itin_r,
617                               InstrItinClass itin_i, string asm,
618                               PatFrag opnode> {
619   def r : // reg/reg
620     T1pILdStEncode<reg_opc,
621                    (outs tGPR:$Rt), (ins AddrMode_r:$addr),
622                    am, itin_r, asm, "\t$Rt, $addr",
623                    [(set tGPR:$Rt, (opnode AddrMode_r:$addr))]>;
624   def i : // reg/imm5
625     T1pILdStEncodeImm<imm_opc, 1 /* Load */,
626                       (outs tGPR:$Rt), (ins AddrMode_i:$addr),
627                       am, itin_i, asm, "\t$Rt, $addr",
628                       [(set tGPR:$Rt, (opnode AddrMode_i:$addr))]>;
629 }
630 // Stores: reg/reg and reg/imm5
631 multiclass thumb_st_rr_ri_enc<bits<3> reg_opc, bits<4> imm_opc,
632                               Operand AddrMode_r, Operand AddrMode_i,
633                               AddrMode am, InstrItinClass itin_r,
634                               InstrItinClass itin_i, string asm,
635                               PatFrag opnode> {
636   def r : // reg/reg
637     T1pILdStEncode<reg_opc,
638                    (outs), (ins tGPR:$Rt, AddrMode_r:$addr),
639                    am, itin_r, asm, "\t$Rt, $addr",
640                    [(opnode tGPR:$Rt, AddrMode_r:$addr)]>;
641   def i : // reg/imm5
642     T1pILdStEncodeImm<imm_opc, 0 /* Store */,
643                       (outs), (ins tGPR:$Rt, AddrMode_i:$addr),
644                       am, itin_i, asm, "\t$Rt, $addr",
645                       [(opnode tGPR:$Rt, AddrMode_i:$addr)]>;
646 }
647
648 // A8.6.57 & A8.6.60
649 defm tLDR  : thumb_ld_rr_ri_enc<0b100, 0b0110, t_addrmode_rrs4,
650                                 t_addrmode_is4, AddrModeT1_4,
651                                 IIC_iLoad_r, IIC_iLoad_i, "ldr",
652                                 UnOpFrag<(load node:$Src)>>;
653
654 // A8.6.64 & A8.6.61
655 defm tLDRB : thumb_ld_rr_ri_enc<0b110, 0b0111, t_addrmode_rrs1,
656                                 t_addrmode_is1, AddrModeT1_1,
657                                 IIC_iLoad_bh_r, IIC_iLoad_bh_i, "ldrb",
658                                 UnOpFrag<(zextloadi8 node:$Src)>>;
659
660 // A8.6.76 & A8.6.73
661 defm tLDRH : thumb_ld_rr_ri_enc<0b101, 0b1000, t_addrmode_rrs2,
662                                 t_addrmode_is2, AddrModeT1_2,
663                                 IIC_iLoad_bh_r, IIC_iLoad_bh_i, "ldrh",
664                                 UnOpFrag<(zextloadi16 node:$Src)>>;
665
666 let AddedComplexity = 10 in
667 def tLDRSB :                    // A8.6.80
668   T1pILdStEncode<0b011, (outs tGPR:$dst), (ins t_addrmode_rr:$addr),
669                  AddrModeT1_1, IIC_iLoad_bh_r,
670                  "ldrsb", "\t$dst, $addr",
671                  [(set tGPR:$dst, (sextloadi8 t_addrmode_rr:$addr))]>;
672
673 let AddedComplexity = 10 in
674 def tLDRSH :                    // A8.6.84
675   T1pILdStEncode<0b111, (outs tGPR:$dst), (ins t_addrmode_rr:$addr),
676                  AddrModeT1_2, IIC_iLoad_bh_r,
677                  "ldrsh", "\t$dst, $addr",
678                  [(set tGPR:$dst, (sextloadi16 t_addrmode_rr:$addr))]>;
679
680 let canFoldAsLoad = 1 in
681 def tLDRspi : T1pIs<(outs tGPR:$Rt), (ins t_addrmode_sp:$addr), IIC_iLoad_i,
682                   "ldr", "\t$Rt, $addr",
683                   [(set tGPR:$Rt, (load t_addrmode_sp:$addr))]>,
684               T1LdStSP<{1,?,?}> {
685   bits<3> Rt;
686   bits<8> addr;
687   let Inst{10-8} = Rt;
688   let Inst{7-0} = addr;
689 }
690
691 // Special instruction for restore. It cannot clobber condition register
692 // when it's expanded by eliminateCallFramePseudoInstr().
693 let canFoldAsLoad = 1, mayLoad = 1, neverHasSideEffects = 1 in
694 // FIXME: Pseudo for tLDRspi
695 def tRestore : T1pIs<(outs tGPR:$dst), (ins t_addrmode_sp:$addr), IIC_iLoad_i,
696                     "ldr", "\t$dst, $addr", []>,
697                T1LdStSP<{1,?,?}>;
698
699 // Load tconstpool
700 // FIXME: Use ldr.n to work around a Darwin assembler bug.
701 let canFoldAsLoad = 1, isReMaterializable = 1 in
702 def tLDRpci : T1pIs<(outs tGPR:$Rt), (ins t_addrmode_pc:$addr), IIC_iLoad_i,
703                   "ldr", ".n\t$Rt, $addr",
704                   [(set tGPR:$Rt, (load (ARMWrapper tconstpool:$addr)))]>,
705               T1Encoding<{0,1,0,0,1,?}> {
706   // A6.2 & A8.6.59
707   bits<3> Rt;
708   bits<8> addr;
709   let Inst{10-8} = Rt;
710   let Inst{7-0}  = addr;
711 }
712
713 // Special LDR for loads from non-pc-relative constpools.
714 let canFoldAsLoad = 1, mayLoad = 1, neverHasSideEffects = 1,
715     isReMaterializable = 1 in
716 def tLDRcp  : T1pIs<(outs tGPR:$Rt), (ins i32imm:$addr), IIC_iLoad_i,
717                   "ldr", "\t$Rt, $addr", []>,
718               T1LdStSP<{1,?,?}> {
719   // A6.2 & A8.6.57 T2
720   bits<3> Rt;
721   bits<8> addr;
722   let Inst{10-8} = Rt;
723   let Inst{7-0}  = addr;
724 }
725
726 // A8.6.194 & A8.6.192
727 defm tSTR  : thumb_st_rr_ri_enc<0b000, 0b0110, t_addrmode_rrs4,
728                                 t_addrmode_is4, AddrModeT1_4,
729                                 IIC_iStore_r, IIC_iStore_i, "str",
730                                 BinOpFrag<(store node:$LHS, node:$RHS)>>;
731
732 // A8.6.197 & A8.6.195
733 defm tSTRB : thumb_st_rr_ri_enc<0b010, 0b0111, t_addrmode_rrs1,
734                                 t_addrmode_is1, AddrModeT1_1,
735                                 IIC_iStore_bh_r, IIC_iStore_bh_i, "strb",
736                                 BinOpFrag<(truncstorei8 node:$LHS, node:$RHS)>>;
737
738 // A8.6.207 & A8.6.205
739 defm tSTRH : thumb_st_rr_ri_enc<0b001, 0b1000, t_addrmode_rrs2,
740                                 t_addrmode_is2, AddrModeT1_2,
741                                 IIC_iStore_bh_r, IIC_iStore_bh_i, "strh",
742                                 BinOpFrag<(truncstorei16 node:$LHS, node:$RHS)>>;
743
744
745 def tSTRspi : T1pIs<(outs), (ins tGPR:$Rt, t_addrmode_sp:$addr), IIC_iStore_i,
746                     "str", "\t$Rt, $addr",
747                     [(store tGPR:$Rt, t_addrmode_sp:$addr)]>,
748               T1LdStSP<{0,?,?}> {
749   bits<3> Rt;
750   bits<8> addr;
751   let Inst{10-8} = Rt;
752   let Inst{7-0} = addr;
753 }
754
755 let mayStore = 1, neverHasSideEffects = 1 in
756 // Special instruction for spill. It cannot clobber condition register when it's
757 // expanded by eliminateCallFramePseudoInstr().
758 // FIXME: Pseudo for tSTRspi
759 def tSpill : T1pIs<(outs), (ins tGPR:$src, t_addrmode_sp:$addr), IIC_iStore_i,
760                   "str", "\t$src, $addr", []>,
761              T1LdStSP<{0,?,?}>;
762
763 //===----------------------------------------------------------------------===//
764 //  Load / store multiple Instructions.
765 //
766
767 multiclass thumb_ldst_mult<string asm, InstrItinClass itin,
768                            InstrItinClass itin_upd, bits<6> T1Enc,
769                            bit L_bit> {
770   def IA :
771     T1I<(outs), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops),
772         itin, !strconcat(asm, "ia${p}\t$Rn, $regs"), []>,
773        T1Encoding<T1Enc> {
774     bits<3> Rn;
775     bits<8> regs;
776     let Inst{10-8} = Rn;
777     let Inst{7-0}  = regs;
778   }
779   def IA_UPD :
780     T1It<(outs GPR:$wb), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops),
781          itin_upd, !strconcat(asm, "ia${p}\t$Rn!, $regs"), "$Rn = $wb", []>,
782         T1Encoding<T1Enc> {
783     bits<3> Rn;
784     bits<8> regs;
785     let Inst{10-8} = Rn;
786     let Inst{7-0}  = regs;
787   }
788 }
789
790 // These require base address to be written back or one of the loaded regs.
791 let neverHasSideEffects = 1 in {
792
793 let mayLoad = 1, hasExtraDefRegAllocReq = 1 in
794 defm tLDM : thumb_ldst_mult<"ldm", IIC_iLoad_m, IIC_iLoad_mu,
795                             {1,1,0,0,1,?}, 1>;
796
797 let mayStore = 1, hasExtraSrcRegAllocReq = 1 in
798 defm tSTM : thumb_ldst_mult<"stm", IIC_iStore_m, IIC_iStore_mu,
799                             {1,1,0,0,0,?}, 0>;
800  
801 } // neverHasSideEffects
802
803 let mayLoad = 1, Uses = [SP], Defs = [SP], hasExtraDefRegAllocReq = 1 in
804 def tPOP : T1I<(outs), (ins pred:$p, reglist:$regs, variable_ops),
805                IIC_iPop,
806                "pop${p}\t$regs", []>,
807            T1Misc<{1,1,0,?,?,?,?}> {
808   bits<16> regs;
809   let Inst{8}   = regs{15};
810   let Inst{7-0} = regs{7-0};
811 }
812
813 let mayStore = 1, Uses = [SP], Defs = [SP], hasExtraSrcRegAllocReq = 1 in
814 def tPUSH : T1I<(outs), (ins pred:$p, reglist:$regs, variable_ops),
815                 IIC_iStore_m,
816                 "push${p}\t$regs", []>,
817             T1Misc<{0,1,0,?,?,?,?}> {
818   bits<16> regs;
819   let Inst{8}   = regs{14};
820   let Inst{7-0} = regs{7-0};
821 }
822
823 //===----------------------------------------------------------------------===//
824 //  Arithmetic Instructions.
825 //
826
827 // Helper classes for encoding T1pI patterns:
828 class T1pIDPEncode<bits<4> opA, dag oops, dag iops, InstrItinClass itin,
829                    string opc, string asm, list<dag> pattern>
830     : T1pI<oops, iops, itin, opc, asm, pattern>,
831       T1DataProcessing<opA> {
832   bits<3> Rm;
833   bits<3> Rn;
834   let Inst{5-3} = Rm;
835   let Inst{2-0} = Rn;
836 }
837 class T1pIMiscEncode<bits<7> opA, dag oops, dag iops, InstrItinClass itin,
838                      string opc, string asm, list<dag> pattern>
839     : T1pI<oops, iops, itin, opc, asm, pattern>,
840       T1Misc<opA> {
841   bits<3> Rm;
842   bits<3> Rd;
843   let Inst{5-3} = Rm;
844   let Inst{2-0} = Rd;
845 }
846
847 // Helper classes for encoding T1sI patterns:
848 class T1sIDPEncode<bits<4> opA, dag oops, dag iops, InstrItinClass itin,
849                    string opc, string asm, list<dag> pattern>
850     : T1sI<oops, iops, itin, opc, asm, pattern>,
851       T1DataProcessing<opA> {
852   bits<3> Rd;
853   bits<3> Rn;
854   let Inst{5-3} = Rn;
855   let Inst{2-0} = Rd;
856 }
857 class T1sIGenEncode<bits<5> opA, dag oops, dag iops, InstrItinClass itin,
858                     string opc, string asm, list<dag> pattern>
859     : T1sI<oops, iops, itin, opc, asm, pattern>,
860       T1General<opA> {
861   bits<3> Rm;
862   bits<3> Rn;
863   bits<3> Rd;
864   let Inst{8-6} = Rm;
865   let Inst{5-3} = Rn;
866   let Inst{2-0} = Rd;
867 }
868 class T1sIGenEncodeImm<bits<5> opA, dag oops, dag iops, InstrItinClass itin,
869                        string opc, string asm, list<dag> pattern>
870     : T1sI<oops, iops, itin, opc, asm, pattern>,
871       T1General<opA> {
872   bits<3> Rd;
873   bits<3> Rm;
874   let Inst{5-3} = Rm;
875   let Inst{2-0} = Rd;
876 }
877
878 // Helper classes for encoding T1sIt patterns:
879 class T1sItDPEncode<bits<4> opA, dag oops, dag iops, InstrItinClass itin,
880                     string opc, string asm, list<dag> pattern>
881     : T1sIt<oops, iops, itin, opc, asm, pattern>,
882       T1DataProcessing<opA> {
883   bits<3> Rdn;
884   bits<3> Rm;
885   let Inst{5-3} = Rm;
886   let Inst{2-0} = Rdn;
887 }
888 class T1sItGenEncodeImm<bits<5> opA, dag oops, dag iops, InstrItinClass itin,
889                         string opc, string asm, list<dag> pattern>
890     : T1sIt<oops, iops, itin, opc, asm, pattern>,
891       T1General<opA> {
892   bits<3> Rdn;
893   bits<8> imm8;
894   let Inst{10-8} = Rdn;
895   let Inst{7-0}  = imm8;
896 }
897
898 // Add with carry register
899 let isCommutable = 1, Uses = [CPSR] in
900 def tADC :                      // A8.6.2
901   T1sItDPEncode<0b0101, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm), IIC_iALUr,
902                 "adc", "\t$Rdn, $Rm",
903                 [(set tGPR:$Rdn, (adde tGPR:$Rn, tGPR:$Rm))]>;
904
905 // Add immediate
906 def tADDi3 :                    // A8.6.4 T1
907   T1sIGenEncodeImm<0b01110, (outs tGPR:$Rd), (ins tGPR:$Rm, i32imm:$imm3), IIC_iALUi,
908                    "add", "\t$Rd, $Rm, $imm3",
909                    [(set tGPR:$Rd, (add tGPR:$Rm, imm0_7:$imm3))]> {
910   bits<3> imm3;
911   let Inst{8-6} = imm3;
912 }
913
914 def tADDi8 :                    // A8.6.4 T2
915   T1sItGenEncodeImm<{1,1,0,?,?}, (outs tGPR:$Rdn), (ins tGPR:$Rn, i32imm:$imm8),
916                     IIC_iALUi,
917                     "add", "\t$Rdn, $imm8",
918                     [(set tGPR:$Rdn, (add tGPR:$Rn, imm8_255:$imm8))]>;
919
920 // Add register
921 let isCommutable = 1 in
922 def tADDrr :                    // A8.6.6 T1
923   T1sIGenEncode<0b01100, (outs tGPR:$Rd), (ins tGPR:$Rn, tGPR:$Rm),
924                 IIC_iALUr,
925                 "add", "\t$Rd, $Rn, $Rm",
926                 [(set tGPR:$Rd, (add tGPR:$Rn, tGPR:$Rm))]>;
927
928 let neverHasSideEffects = 1 in
929 def tADDhirr : T1pIt<(outs GPR:$Rdn), (ins GPR:$Rn, GPR:$Rm), IIC_iALUr,
930                      "add", "\t$Rdn, $Rm", []>,
931                T1Special<{0,0,?,?}> {
932   // A8.6.6 T2
933   bits<4> Rdn;
934   bits<4> Rm;
935   let Inst{7}   = Rdn{3};
936   let Inst{6-3} = Rm;
937   let Inst{2-0} = Rdn{2-0};
938 }
939
940 // AND register
941 let isCommutable = 1 in
942 def tAND :                      // A8.6.12
943   T1sItDPEncode<0b0000, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
944                 IIC_iBITr,
945                 "and", "\t$Rdn, $Rm",
946                 [(set tGPR:$Rdn, (and tGPR:$Rn, tGPR:$Rm))]>;
947
948 // ASR immediate
949 def tASRri :                    // A8.6.14
950   T1sIGenEncodeImm<{0,1,0,?,?}, (outs tGPR:$Rd), (ins tGPR:$Rm, i32imm:$imm5),
951                    IIC_iMOVsi,
952                    "asr", "\t$Rd, $Rm, $imm5",
953                    [(set tGPR:$Rd, (sra tGPR:$Rm, (i32 imm:$imm5)))]> {
954   bits<5> imm5;
955   let Inst{10-6} = imm5;
956 }
957
958 // ASR register
959 def tASRrr :                    // A8.6.15
960   T1sItDPEncode<0b0100, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
961                 IIC_iMOVsr,
962                 "asr", "\t$Rdn, $Rm",
963                 [(set tGPR:$Rdn, (sra tGPR:$Rn, tGPR:$Rm))]>;
964
965 // BIC register
966 def tBIC :                      // A8.6.20
967   T1sItDPEncode<0b1110, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
968                 IIC_iBITr,
969                 "bic", "\t$Rdn, $Rm",
970                 [(set tGPR:$Rdn, (and tGPR:$Rn, (not tGPR:$Rm)))]>;
971
972 // CMN register
973 let isCompare = 1, Defs = [CPSR] in {
974 //FIXME: Disable CMN, as CCodes are backwards from compare expectations
975 //       Compare-to-zero still works out, just not the relationals
976 //def tCMN :                     // A8.6.33
977 //  T1pIDPEncode<0b1011, (outs), (ins tGPR:$lhs, tGPR:$rhs),
978 //               IIC_iCMPr,
979 //               "cmn", "\t$lhs, $rhs",
980 //               [(ARMcmp tGPR:$lhs, (ineg tGPR:$rhs))]>;
981
982 def tCMNz :                     // A8.6.33
983   T1pIDPEncode<0b1011, (outs), (ins tGPR:$Rn, tGPR:$Rm),
984                IIC_iCMPr,
985                "cmn", "\t$Rn, $Rm",
986                [(ARMcmpZ tGPR:$Rn, (ineg tGPR:$Rm))]>;
987
988 } // isCompare = 1, Defs = [CPSR]
989
990 // CMP immediate
991 let isCompare = 1, Defs = [CPSR] in {
992 def tCMPi8 : T1pI<(outs), (ins tGPR:$Rn, i32imm:$imm8), IIC_iCMPi,
993                   "cmp", "\t$Rn, $imm8",
994                   [(ARMcmp tGPR:$Rn, imm0_255:$imm8)]>,
995              T1General<{1,0,1,?,?}> {
996   // A8.6.35
997   bits<3> Rn;
998   bits<8> imm8;
999   let Inst{10-8} = Rn;
1000   let Inst{7-0}  = imm8;
1001 }
1002
1003 // CMP register
1004 def tCMPr :                     // A8.6.36 T1
1005   T1pIDPEncode<0b1010, (outs), (ins tGPR:$Rn, tGPR:$Rm),
1006                IIC_iCMPr,
1007                "cmp", "\t$Rn, $Rm",
1008                [(ARMcmp tGPR:$Rn, tGPR:$Rm)]>;
1009
1010 def tCMPhir : T1pI<(outs), (ins GPR:$Rn, GPR:$Rm), IIC_iCMPr,
1011                    "cmp", "\t$Rn, $Rm", []>,
1012               T1Special<{0,1,?,?}> {
1013   // A8.6.36 T2
1014   bits<4> Rm;
1015   bits<4> Rn;
1016   let Inst{7}   = Rn{3};
1017   let Inst{6-3} = Rm;
1018   let Inst{2-0} = Rn{2-0};
1019 }
1020 } // isCompare = 1, Defs = [CPSR]
1021
1022
1023 // XOR register
1024 let isCommutable = 1 in
1025 def tEOR :                      // A8.6.45
1026   T1sItDPEncode<0b0001, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
1027                 IIC_iBITr,
1028                 "eor", "\t$Rdn, $Rm",
1029                 [(set tGPR:$Rdn, (xor tGPR:$Rn, tGPR:$Rm))]>;
1030
1031 // LSL immediate
1032 def tLSLri :                    // A8.6.88
1033   T1sIGenEncodeImm<{0,0,0,?,?}, (outs tGPR:$Rd), (ins tGPR:$Rm, i32imm:$imm5),
1034                    IIC_iMOVsi,
1035                    "lsl", "\t$Rd, $Rm, $imm5",
1036                    [(set tGPR:$Rd, (shl tGPR:$Rm, (i32 imm:$imm5)))]> {
1037   bits<5> imm5;
1038   let Inst{10-6} = imm5;
1039 }
1040
1041 // LSL register
1042 def tLSLrr :                    // A8.6.89
1043   T1sItDPEncode<0b0010, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
1044                 IIC_iMOVsr,
1045                 "lsl", "\t$Rdn, $Rm",
1046                 [(set tGPR:$Rdn, (shl tGPR:$Rn, tGPR:$Rm))]>;
1047
1048 // LSR immediate
1049 def tLSRri :                    // A8.6.90
1050   T1sIGenEncodeImm<{0,0,1,?,?}, (outs tGPR:$Rd), (ins tGPR:$Rm, i32imm:$imm5),
1051                    IIC_iMOVsi,
1052                    "lsr", "\t$Rd, $Rm, $imm5",
1053                    [(set tGPR:$Rd, (srl tGPR:$Rm, (i32 imm:$imm5)))]> {
1054   bits<5> imm5;
1055   let Inst{10-6} = imm5;
1056 }
1057
1058 // LSR register
1059 def tLSRrr :                    // A8.6.91
1060   T1sItDPEncode<0b0011, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
1061                 IIC_iMOVsr,
1062                 "lsr", "\t$Rdn, $Rm",
1063                 [(set tGPR:$Rdn, (srl tGPR:$Rn, tGPR:$Rm))]>;
1064
1065 // Move register
1066 let isMoveImm = 1 in
1067 def tMOVi8 : T1sI<(outs tGPR:$Rd), (ins i32imm:$imm8), IIC_iMOVi,
1068                   "mov", "\t$Rd, $imm8",
1069                   [(set tGPR:$Rd, imm0_255:$imm8)]>,
1070              T1General<{1,0,0,?,?}> {
1071   // A8.6.96
1072   bits<3> Rd;
1073   bits<8> imm8;
1074   let Inst{10-8} = Rd;
1075   let Inst{7-0}  = imm8;
1076 }
1077
1078 // TODO: A7-73: MOV(2) - mov setting flag.
1079
1080 let neverHasSideEffects = 1 in {
1081 // FIXME: Make this predicable.
1082 def tMOVr       : T1I<(outs tGPR:$Rd), (ins tGPR:$Rm), IIC_iMOVr,
1083                       "mov\t$Rd, $Rm", []>,
1084                   T1Special<0b1000> {
1085   // A8.6.97
1086   bits<4> Rd;
1087   bits<4> Rm;
1088   // Bits {7-6} are encoded by the T1Special value.
1089   let Inst{5-3} = Rm{2-0};
1090   let Inst{2-0} = Rd{2-0};
1091 }
1092 let Defs = [CPSR] in
1093 def tMOVSr      : T1I<(outs tGPR:$Rd), (ins tGPR:$Rm), IIC_iMOVr,
1094                       "movs\t$Rd, $Rm", []>, Encoding16 {
1095   // A8.6.97
1096   bits<3> Rd;
1097   bits<3> Rm;
1098   let Inst{15-6} = 0b0000000000;
1099   let Inst{5-3}  = Rm;
1100   let Inst{2-0}  = Rd;
1101 }
1102
1103 // FIXME: Make these predicable.
1104 def tMOVgpr2tgpr : T1I<(outs tGPR:$Rd), (ins GPR:$Rm), IIC_iMOVr,
1105                        "mov\t$Rd, $Rm", []>,
1106                    T1Special<{1,0,0,?}> {
1107   // A8.6.97
1108   bits<4> Rd;
1109   bits<4> Rm;
1110   // Bit {7} is encoded by the T1Special value.
1111   let Inst{6-3} = Rm;
1112   let Inst{2-0} = Rd{2-0};
1113 }
1114 def tMOVtgpr2gpr : T1I<(outs GPR:$Rd), (ins tGPR:$Rm), IIC_iMOVr,
1115                        "mov\t$Rd, $Rm", []>,
1116                    T1Special<{1,0,?,0}> {
1117   // A8.6.97
1118   bits<4> Rd;
1119   bits<4> Rm;
1120   // Bit {6} is encoded by the T1Special value.
1121   let Inst{7}   = Rd{3};
1122   let Inst{5-3} = Rm{2-0};
1123   let Inst{2-0} = Rd{2-0};
1124 }
1125 def tMOVgpr2gpr  : T1I<(outs GPR:$Rd), (ins GPR:$Rm), IIC_iMOVr,
1126                        "mov\t$Rd, $Rm", []>,
1127                    T1Special<{1,0,?,?}> {
1128   // A8.6.97
1129   bits<4> Rd;
1130   bits<4> Rm;
1131   let Inst{7}   = Rd{3};
1132   let Inst{6-3} = Rm;
1133   let Inst{2-0} = Rd{2-0};
1134 }
1135 } // neverHasSideEffects
1136
1137 // Multiply register
1138 let isCommutable = 1 in
1139 def tMUL :                      // A8.6.105 T1
1140   T1sItDPEncode<0b1101, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
1141                 IIC_iMUL32,
1142                 "mul", "\t$Rdn, $Rm, $Rdn",
1143                 [(set tGPR:$Rdn, (mul tGPR:$Rn, tGPR:$Rm))]>;
1144
1145 // Move inverse register
1146 def tMVN :                      // A8.6.107
1147   T1sIDPEncode<0b1111, (outs tGPR:$Rd), (ins tGPR:$Rn), IIC_iMVNr,
1148                "mvn", "\t$Rd, $Rn",
1149                [(set tGPR:$Rd, (not tGPR:$Rn))]>;
1150
1151 // Bitwise or register
1152 let isCommutable = 1 in
1153 def tORR :                      // A8.6.114
1154   T1sItDPEncode<0b1100, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
1155                 IIC_iBITr,
1156                 "orr", "\t$Rdn, $Rm",
1157                 [(set tGPR:$Rdn, (or tGPR:$Rn, tGPR:$Rm))]>;
1158
1159 // Swaps
1160 def tREV :                      // A8.6.134
1161   T1pIMiscEncode<{1,0,1,0,0,0,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1162                  IIC_iUNAr,
1163                  "rev", "\t$Rd, $Rm",
1164                  [(set tGPR:$Rd, (bswap tGPR:$Rm))]>,
1165                  Requires<[IsThumb, IsThumb1Only, HasV6]>;
1166
1167 def tREV16 :                    // A8.6.135
1168   T1pIMiscEncode<{1,0,1,0,0,1,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1169                  IIC_iUNAr,
1170                  "rev16", "\t$Rd, $Rm",
1171              [(set tGPR:$Rd,
1172                    (or (and (srl tGPR:$Rm, (i32 8)), 0xFF),
1173                        (or (and (shl tGPR:$Rm, (i32 8)), 0xFF00),
1174                            (or (and (srl tGPR:$Rm, (i32 8)), 0xFF0000),
1175                                (and (shl tGPR:$Rm, (i32 8)), 0xFF000000)))))]>,
1176                 Requires<[IsThumb, IsThumb1Only, HasV6]>;
1177
1178 def tREVSH :                    // A8.6.136
1179   T1pIMiscEncode<{1,0,1,0,1,1,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1180                  IIC_iUNAr,
1181                  "revsh", "\t$Rd, $Rm",
1182                  [(set tGPR:$Rd,
1183                        (sext_inreg
1184                          (or (srl (and tGPR:$Rm, 0xFF00), (i32 8)),
1185                              (shl tGPR:$Rm, (i32 8))), i16))]>,
1186                  Requires<[IsThumb, IsThumb1Only, HasV6]>;
1187
1188 // Rotate right register
1189 def tROR :                      // A8.6.139
1190   T1sItDPEncode<0b0111, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
1191                 IIC_iMOVsr,
1192                 "ror", "\t$Rdn, $Rm",
1193                 [(set tGPR:$Rdn, (rotr tGPR:$Rn, tGPR:$Rm))]>;
1194
1195 // Negate register
1196 def tRSB :                      // A8.6.141
1197   T1sIDPEncode<0b1001, (outs tGPR:$Rd), (ins tGPR:$Rn),
1198                IIC_iALUi,
1199                "rsb", "\t$Rd, $Rn, #0",
1200                [(set tGPR:$Rd, (ineg tGPR:$Rn))]>;
1201
1202 // Subtract with carry register
1203 let Uses = [CPSR] in
1204 def tSBC :                      // A8.6.151
1205   T1sItDPEncode<0b0110, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
1206                 IIC_iALUr,
1207                 "sbc", "\t$Rdn, $Rm",
1208                 [(set tGPR:$Rdn, (sube tGPR:$Rn, tGPR:$Rm))]>;
1209
1210 // Subtract immediate
1211 def tSUBi3 :                    // A8.6.210 T1
1212   T1sIGenEncodeImm<0b01111, (outs tGPR:$Rd), (ins tGPR:$Rm, i32imm:$imm3),
1213                    IIC_iALUi,
1214                    "sub", "\t$Rd, $Rm, $imm3",
1215                    [(set tGPR:$Rd, (add tGPR:$Rm, imm0_7_neg:$imm3))]> {
1216   bits<3> imm3;
1217   let Inst{8-6} = imm3;
1218 }
1219
1220 def tSUBi8 :                    // A8.6.210 T2
1221   T1sItGenEncodeImm<{1,1,1,?,?}, (outs tGPR:$Rdn), (ins tGPR:$Rn, i32imm:$imm8),
1222                     IIC_iALUi,
1223                     "sub", "\t$Rdn, $imm8",
1224                     [(set tGPR:$Rdn, (add tGPR:$Rn, imm8_255_neg:$imm8))]>;
1225
1226 // Subtract register
1227 def tSUBrr :                    // A8.6.212
1228   T1sIGenEncode<0b01101, (outs tGPR:$Rd), (ins tGPR:$Rn, tGPR:$Rm),
1229                 IIC_iALUr,
1230                 "sub", "\t$Rd, $Rn, $Rm",
1231                 [(set tGPR:$Rd, (sub tGPR:$Rn, tGPR:$Rm))]>;
1232
1233 // TODO: A7-96: STMIA - store multiple.
1234
1235 // Sign-extend byte
1236 def tSXTB :                     // A8.6.222
1237   T1pIMiscEncode<{0,0,1,0,0,1,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1238                  IIC_iUNAr,
1239                  "sxtb", "\t$Rd, $Rm",
1240                  [(set tGPR:$Rd, (sext_inreg tGPR:$Rm, i8))]>,
1241                  Requires<[IsThumb, IsThumb1Only, HasV6]>;
1242
1243 // Sign-extend short
1244 def tSXTH :                     // A8.6.224
1245   T1pIMiscEncode<{0,0,1,0,0,0,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1246                  IIC_iUNAr,
1247                  "sxth", "\t$Rd, $Rm",
1248                  [(set tGPR:$Rd, (sext_inreg tGPR:$Rm, i16))]>,
1249                  Requires<[IsThumb, IsThumb1Only, HasV6]>;
1250
1251 // Test
1252 let isCompare = 1, isCommutable = 1, Defs = [CPSR] in
1253 def tTST :                      // A8.6.230
1254   T1pIDPEncode<0b1000, (outs), (ins tGPR:$Rn, tGPR:$Rm), IIC_iTSTr,
1255                "tst", "\t$Rn, $Rm",
1256                [(ARMcmpZ (and_su tGPR:$Rn, tGPR:$Rm), 0)]>;
1257
1258 // Zero-extend byte
1259 def tUXTB :                     // A8.6.262
1260   T1pIMiscEncode<{0,0,1,0,1,1,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1261                  IIC_iUNAr,
1262                  "uxtb", "\t$Rd, $Rm",
1263                  [(set tGPR:$Rd, (and tGPR:$Rm, 0xFF))]>,
1264                  Requires<[IsThumb, IsThumb1Only, HasV6]>;
1265
1266 // Zero-extend short
1267 def tUXTH :                     // A8.6.264
1268   T1pIMiscEncode<{0,0,1,0,1,0,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1269                  IIC_iUNAr,
1270                  "uxth", "\t$Rd, $Rm",
1271                  [(set tGPR:$Rd, (and tGPR:$Rm, 0xFFFF))]>,
1272                  Requires<[IsThumb, IsThumb1Only, HasV6]>;
1273
1274 // Conditional move tMOVCCr - Used to implement the Thumb SELECT_CC operation.
1275 // Expanded after instruction selection into a branch sequence.
1276 let usesCustomInserter = 1 in  // Expanded after instruction selection.
1277   def tMOVCCr_pseudo :
1278   PseudoInst<(outs tGPR:$dst), (ins tGPR:$false, tGPR:$true, pred:$cc),
1279               NoItinerary,
1280              [/*(set tGPR:$dst, (ARMcmov tGPR:$false, tGPR:$true, imm:$cc))*/]>;
1281
1282
1283 // 16-bit movcc in IT blocks for Thumb2.
1284 let neverHasSideEffects = 1 in {
1285 def tMOVCCr : T1pIt<(outs GPR:$Rdn), (ins GPR:$Rn, GPR:$Rm), IIC_iCMOVr,
1286                     "mov", "\t$Rdn, $Rm", []>,
1287               T1Special<{1,0,?,?}> {
1288   bits<4> Rdn;
1289   bits<4> Rm;
1290   let Inst{7}   = Rdn{3};
1291   let Inst{6-3} = Rm;
1292   let Inst{2-0} = Rdn{2-0};
1293 }
1294
1295 let isMoveImm = 1 in
1296 def tMOVCCi : T1pIt<(outs tGPR:$Rdn), (ins tGPR:$Rn, i32imm:$Rm), IIC_iCMOVi,
1297                     "mov", "\t$Rdn, $Rm", []>,
1298               T1General<{1,0,0,?,?}> {
1299   bits<3> Rdn;
1300   bits<8> Rm;
1301   let Inst{10-8} = Rdn;
1302   let Inst{7-0}  = Rm;
1303 }
1304
1305 } // neverHasSideEffects
1306
1307 // tLEApcrel - Load a pc-relative address into a register without offending the
1308 // assembler.
1309
1310 def tADR : T1I<(outs tGPR:$Rd), (ins t_adrlabel:$addr, pred:$p),
1311                IIC_iALUi, "adr{$p}\t$Rd, #$addr", []>,
1312                T1Encoding<{1,0,1,0,0,?}> {
1313   bits<3> Rd;
1314   bits<8> addr;
1315   let Inst{10-8} = Rd;
1316   let Inst{7-0} = addr;
1317 }
1318
1319 let neverHasSideEffects = 1, isReMaterializable = 1 in
1320 def tLEApcrel   : tPseudoInst<(outs tGPR:$Rd), (ins i32imm:$label, pred:$p),
1321                               Size2Bytes, IIC_iALUi, []>;
1322
1323 def tLEApcrelJT : tPseudoInst<(outs tGPR:$Rd),
1324                               (ins i32imm:$label, nohash_imm:$id, pred:$p),
1325                               Size2Bytes, IIC_iALUi, []>;
1326
1327 //===----------------------------------------------------------------------===//
1328 // TLS Instructions
1329 //
1330
1331 // __aeabi_read_tp preserves the registers r1-r3.
1332 let isCall = 1, Defs = [R0, LR], Uses = [SP] in
1333 def tTPsoft : TIx2<0b11110, 0b11, 1, (outs), (ins), IIC_Br,
1334                    "bl\t__aeabi_read_tp",
1335                    [(set R0, ARMthread_pointer)]> {
1336   // Encoding is 0xf7fffffe.
1337   let Inst = 0xf7fffffe;
1338 }
1339
1340 //===----------------------------------------------------------------------===//
1341 // SJLJ Exception handling intrinsics
1342 // 
1343
1344 // eh_sjlj_setjmp() is an instruction sequence to store the return address and
1345 // save #0 in R0 for the non-longjmp case.  Since by its nature we may be coming
1346 // from some other function to get here, and we're using the stack frame for the
1347 // containing function to save/restore registers, we can't keep anything live in
1348 // regs across the eh_sjlj_setjmp(), else it will almost certainly have been
1349 // tromped upon when we get here from a longjmp(). We force everthing out of
1350 // registers except for our own input by listing the relevant registers in
1351 // Defs. By doing so, we also cause the prologue/epilogue code to actively
1352 // preserve all of the callee-saved resgisters, which is exactly what we want.
1353 // $val is a scratch register for our use.
1354 let Defs = [ R0,  R1,  R2,  R3,  R4,  R5,  R6,  R7, R12 ],
1355     hasSideEffects = 1, isBarrier = 1, isCodeGenOnly = 1 in
1356 def tInt_eh_sjlj_setjmp : ThumbXI<(outs),(ins tGPR:$src, tGPR:$val),
1357                                   AddrModeNone, SizeSpecial, NoItinerary, "","",
1358                           [(set R0, (ARMeh_sjlj_setjmp tGPR:$src, tGPR:$val))]>;
1359
1360 // FIXME: Non-Darwin version(s)
1361 let isBarrier = 1, hasSideEffects = 1, isTerminator = 1, isCodeGenOnly = 1,
1362     Defs = [ R7, LR, SP ] in
1363 def tInt_eh_sjlj_longjmp : XI<(outs), (ins GPR:$src, GPR:$scratch),
1364                               AddrModeNone, SizeSpecial, IndexModeNone,
1365                               Pseudo, NoItinerary, "", "",
1366                               [(ARMeh_sjlj_longjmp GPR:$src, GPR:$scratch)]>,
1367                              Requires<[IsThumb, IsDarwin]>;
1368
1369 //===----------------------------------------------------------------------===//
1370 // Non-Instruction Patterns
1371 //
1372
1373 // Comparisons
1374 def : T1Pat<(ARMcmpZ tGPR:$Rn, imm0_255:$imm8),
1375             (tCMPi8  tGPR:$Rn, imm0_255:$imm8)>;
1376 def : T1Pat<(ARMcmpZ tGPR:$Rn, tGPR:$Rm),
1377             (tCMPr   tGPR:$Rn, tGPR:$Rm)>;
1378
1379 // Add with carry
1380 def : T1Pat<(addc   tGPR:$lhs, imm0_7:$rhs),
1381             (tADDi3 tGPR:$lhs, imm0_7:$rhs)>;
1382 def : T1Pat<(addc   tGPR:$lhs, imm8_255:$rhs),
1383             (tADDi8 tGPR:$lhs, imm8_255:$rhs)>;
1384 def : T1Pat<(addc   tGPR:$lhs, tGPR:$rhs),
1385             (tADDrr tGPR:$lhs, tGPR:$rhs)>;
1386
1387 // Subtract with carry
1388 def : T1Pat<(addc   tGPR:$lhs, imm0_7_neg:$rhs),
1389             (tSUBi3 tGPR:$lhs, imm0_7_neg:$rhs)>;
1390 def : T1Pat<(addc   tGPR:$lhs, imm8_255_neg:$rhs),
1391             (tSUBi8 tGPR:$lhs, imm8_255_neg:$rhs)>;
1392 def : T1Pat<(subc   tGPR:$lhs, tGPR:$rhs),
1393             (tSUBrr tGPR:$lhs, tGPR:$rhs)>;
1394
1395 // ConstantPool, GlobalAddress
1396 def : T1Pat<(ARMWrapper  tglobaladdr :$dst), (tLEApcrel tglobaladdr :$dst)>;
1397 def : T1Pat<(ARMWrapper  tconstpool  :$dst), (tLEApcrel tconstpool  :$dst)>;
1398
1399 // JumpTable
1400 def : T1Pat<(ARMWrapperJT tjumptable:$dst, imm:$id),
1401             (tLEApcrelJT tjumptable:$dst, imm:$id)>;
1402
1403 // Direct calls
1404 def : T1Pat<(ARMtcall texternalsym:$func), (tBL texternalsym:$func)>,
1405       Requires<[IsThumb, IsNotDarwin]>;
1406 def : T1Pat<(ARMtcall texternalsym:$func), (tBLr9 texternalsym:$func)>,
1407       Requires<[IsThumb, IsDarwin]>;
1408
1409 def : Tv5Pat<(ARMcall texternalsym:$func), (tBLXi texternalsym:$func)>,
1410       Requires<[IsThumb, HasV5T, IsNotDarwin]>;
1411 def : Tv5Pat<(ARMcall texternalsym:$func), (tBLXi_r9 texternalsym:$func)>,
1412       Requires<[IsThumb, HasV5T, IsDarwin]>;
1413
1414 // Indirect calls to ARM routines
1415 def : Tv5Pat<(ARMcall GPR:$dst), (tBLXr GPR:$dst)>,
1416       Requires<[IsThumb, HasV5T, IsNotDarwin]>;
1417 def : Tv5Pat<(ARMcall GPR:$dst), (tBLXr_r9 GPR:$dst)>,
1418       Requires<[IsThumb, HasV5T, IsDarwin]>;
1419
1420 // zextload i1 -> zextload i8
1421 def : T1Pat<(zextloadi1 t_addrmode_rrs1:$addr),
1422             (tLDRBr t_addrmode_rrs1:$addr)>;
1423 def : T1Pat<(zextloadi1 t_addrmode_is1:$addr),
1424             (tLDRBi t_addrmode_is1:$addr)>;
1425
1426 // extload -> zextload
1427 def : T1Pat<(extloadi1  t_addrmode_rrs1:$addr), (tLDRBr t_addrmode_rrs1:$addr)>;
1428 def : T1Pat<(extloadi1  t_addrmode_is1:$addr),  (tLDRBi t_addrmode_is1:$addr)>;
1429 def : T1Pat<(extloadi8  t_addrmode_rrs1:$addr), (tLDRBr t_addrmode_rrs1:$addr)>;
1430 def : T1Pat<(extloadi8  t_addrmode_is1:$addr),  (tLDRBi t_addrmode_is1:$addr)>;
1431 def : T1Pat<(extloadi16 t_addrmode_rrs2:$addr), (tLDRHr t_addrmode_rrs2:$addr)>;
1432 def : T1Pat<(extloadi16 t_addrmode_is2:$addr),  (tLDRHi t_addrmode_is2:$addr)>;
1433
1434 // If it's impossible to use [r,r] address mode for sextload, select to
1435 // ldr{b|h} + sxt{b|h} instead.
1436 def : T1Pat<(sextloadi8 t_addrmode_is1:$addr),
1437             (tSXTB (tLDRBi t_addrmode_is1:$addr))>,
1438       Requires<[IsThumb, IsThumb1Only, HasV6]>;
1439 def : T1Pat<(sextloadi8 t_addrmode_rrs1:$addr),
1440             (tSXTB (tLDRBr t_addrmode_rrs1:$addr))>,
1441       Requires<[IsThumb, IsThumb1Only, HasV6]>;
1442 def : T1Pat<(sextloadi16 t_addrmode_is2:$addr),
1443             (tSXTH (tLDRHi t_addrmode_is2:$addr))>,
1444       Requires<[IsThumb, IsThumb1Only, HasV6]>;
1445 def : T1Pat<(sextloadi16 t_addrmode_rrs2:$addr),
1446             (tSXTH (tLDRHr t_addrmode_rrs2:$addr))>,
1447       Requires<[IsThumb, IsThumb1Only, HasV6]>;
1448
1449 def : T1Pat<(sextloadi8 t_addrmode_rrs1:$addr),
1450             (tASRri (tLSLri (tLDRBr t_addrmode_rrs1:$addr), 24), 24)>;
1451 def : T1Pat<(sextloadi8 t_addrmode_is1:$addr),
1452             (tASRri (tLSLri (tLDRBi t_addrmode_is1:$addr), 24), 24)>;
1453 def : T1Pat<(sextloadi16 t_addrmode_rrs2:$addr),
1454             (tASRri (tLSLri (tLDRHr t_addrmode_rrs2:$addr), 16), 16)>;
1455 def : T1Pat<(sextloadi16 t_addrmode_is2:$addr),
1456             (tASRri (tLSLri (tLDRHi t_addrmode_is2:$addr), 16), 16)>;
1457
1458 // Large immediate handling.
1459
1460 // Two piece imms.
1461 def : T1Pat<(i32 thumb_immshifted:$src),
1462             (tLSLri (tMOVi8 (thumb_immshifted_val imm:$src)),
1463                     (thumb_immshifted_shamt imm:$src))>;
1464
1465 def : T1Pat<(i32 imm0_255_comp:$src),
1466             (tMVN (tMOVi8 (imm_comp_XFORM imm:$src)))>;
1467
1468 // Pseudo instruction that combines ldr from constpool and add pc. This should
1469 // be expanded into two instructions late to allow if-conversion and
1470 // scheduling.
1471 let isReMaterializable = 1 in
1472 def tLDRpci_pic : PseudoInst<(outs GPR:$dst), (ins i32imm:$addr, pclabel:$cp),
1473                              NoItinerary,
1474                [(set GPR:$dst, (ARMpic_add (load (ARMWrapper tconstpool:$addr)),
1475                                            imm:$cp))]>,
1476                Requires<[IsThumb, IsThumb1Only]>;