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