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