Deduplicate ARM call-related instructions.
[oota-llvm.git] / lib / Target / ARM / ARMInstrInfo.td
1 //===- ARMInstrInfo.td - Target Description for ARM Target -*- 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 ARM instructions in TableGen format.
11 //
12 //===----------------------------------------------------------------------===//
13
14 //===----------------------------------------------------------------------===//
15 // ARM specific DAG Nodes.
16 //
17
18 // Type profiles.
19 def SDT_ARMCallSeqStart : SDCallSeqStart<[ SDTCisVT<0, i32> ]>;
20 def SDT_ARMCallSeqEnd   : SDCallSeqEnd<[ SDTCisVT<0, i32>, SDTCisVT<1, i32> ]>;
21
22 def SDT_ARMSaveCallPC : SDTypeProfile<0, 1, []>;
23
24 def SDT_ARMcall    : SDTypeProfile<0, -1, [SDTCisPtrTy<0>]>;
25
26 def SDT_ARMCMov    : SDTypeProfile<1, 3,
27                                    [SDTCisSameAs<0, 1>, SDTCisSameAs<0, 2>,
28                                     SDTCisVT<3, i32>]>;
29
30 def SDT_ARMBrcond  : SDTypeProfile<0, 2,
31                                    [SDTCisVT<0, OtherVT>, SDTCisVT<1, i32>]>;
32
33 def SDT_ARMBrJT    : SDTypeProfile<0, 3,
34                                   [SDTCisPtrTy<0>, SDTCisVT<1, i32>,
35                                    SDTCisVT<2, i32>]>;
36
37 def SDT_ARMBr2JT   : SDTypeProfile<0, 4,
38                                   [SDTCisPtrTy<0>, SDTCisVT<1, i32>,
39                                    SDTCisVT<2, i32>, SDTCisVT<3, i32>]>;
40
41 def SDT_ARMBCC_i64 : SDTypeProfile<0, 6,
42                                   [SDTCisVT<0, i32>,
43                                    SDTCisVT<1, i32>, SDTCisVT<2, i32>,
44                                    SDTCisVT<3, i32>, SDTCisVT<4, i32>,
45                                    SDTCisVT<5, OtherVT>]>;
46
47 def SDT_ARMAnd     : SDTypeProfile<1, 2,
48                                    [SDTCisVT<0, i32>, SDTCisVT<1, i32>,
49                                     SDTCisVT<2, i32>]>;
50
51 def SDT_ARMCmp     : SDTypeProfile<0, 2, [SDTCisSameAs<0, 1>]>;
52
53 def SDT_ARMPICAdd  : SDTypeProfile<1, 2, [SDTCisSameAs<0, 1>,
54                                           SDTCisPtrTy<1>, SDTCisVT<2, i32>]>;
55
56 def SDT_ARMThreadPointer : SDTypeProfile<1, 0, [SDTCisPtrTy<0>]>;
57 def SDT_ARMEH_SJLJ_Setjmp : SDTypeProfile<1, 2, [SDTCisInt<0>, SDTCisPtrTy<1>,
58                                                  SDTCisInt<2>]>;
59 def SDT_ARMEH_SJLJ_Longjmp: SDTypeProfile<0, 2, [SDTCisPtrTy<0>, SDTCisInt<1>]>;
60
61 def SDT_ARMMEMBARRIER     : SDTypeProfile<0, 1, [SDTCisInt<0>]>;
62
63 def SDT_ARMPREFETCH : SDTypeProfile<0, 3, [SDTCisPtrTy<0>, SDTCisSameAs<1, 2>,
64                                            SDTCisInt<1>]>;
65
66 def SDT_ARMTCRET : SDTypeProfile<0, 1, [SDTCisPtrTy<0>]>;
67
68 def SDT_ARMBFI : SDTypeProfile<1, 3, [SDTCisVT<0, i32>, SDTCisVT<1, i32>,
69                                       SDTCisVT<2, i32>, SDTCisVT<3, i32>]>;
70
71 def SDTBinaryArithWithFlags : SDTypeProfile<2, 2,
72                                             [SDTCisSameAs<0, 2>,
73                                              SDTCisSameAs<0, 3>,
74                                              SDTCisInt<0>, SDTCisVT<1, i32>]>;
75
76 // SDTBinaryArithWithFlagsInOut - RES1, CPSR = op LHS, RHS, CPSR
77 def SDTBinaryArithWithFlagsInOut : SDTypeProfile<2, 3,
78                                             [SDTCisSameAs<0, 2>,
79                                              SDTCisSameAs<0, 3>,
80                                              SDTCisInt<0>,
81                                              SDTCisVT<1, i32>,
82                                              SDTCisVT<4, i32>]>;
83 // Node definitions.
84 def ARMWrapper       : SDNode<"ARMISD::Wrapper",     SDTIntUnaryOp>;
85 def ARMWrapperDYN    : SDNode<"ARMISD::WrapperDYN",  SDTIntUnaryOp>;
86 def ARMWrapperPIC    : SDNode<"ARMISD::WrapperPIC",  SDTIntUnaryOp>;
87 def ARMWrapperJT     : SDNode<"ARMISD::WrapperJT",   SDTIntBinOp>;
88
89 def ARMcallseq_start : SDNode<"ISD::CALLSEQ_START", SDT_ARMCallSeqStart,
90                               [SDNPHasChain, SDNPOutGlue]>;
91 def ARMcallseq_end   : SDNode<"ISD::CALLSEQ_END",   SDT_ARMCallSeqEnd,
92                               [SDNPHasChain, SDNPOptInGlue, SDNPOutGlue]>;
93
94 def ARMcall          : SDNode<"ARMISD::CALL", SDT_ARMcall,
95                               [SDNPHasChain, SDNPOptInGlue, SDNPOutGlue,
96                                SDNPVariadic]>;
97 def ARMcall_pred    : SDNode<"ARMISD::CALL_PRED", SDT_ARMcall,
98                               [SDNPHasChain, SDNPOptInGlue, SDNPOutGlue,
99                                SDNPVariadic]>;
100 def ARMcall_nolink   : SDNode<"ARMISD::CALL_NOLINK", SDT_ARMcall,
101                               [SDNPHasChain, SDNPOptInGlue, SDNPOutGlue,
102                                SDNPVariadic]>;
103
104 def ARMretflag       : SDNode<"ARMISD::RET_FLAG", SDTNone,
105                               [SDNPHasChain, SDNPOptInGlue]>;
106
107 def ARMcmov          : SDNode<"ARMISD::CMOV", SDT_ARMCMov,
108                               [SDNPInGlue]>;
109
110 def ARMbrcond        : SDNode<"ARMISD::BRCOND", SDT_ARMBrcond,
111                               [SDNPHasChain, SDNPInGlue, SDNPOutGlue]>;
112
113 def ARMbrjt          : SDNode<"ARMISD::BR_JT", SDT_ARMBrJT,
114                               [SDNPHasChain]>;
115 def ARMbr2jt         : SDNode<"ARMISD::BR2_JT", SDT_ARMBr2JT,
116                               [SDNPHasChain]>;
117
118 def ARMBcci64        : SDNode<"ARMISD::BCC_i64", SDT_ARMBCC_i64,
119                               [SDNPHasChain]>;
120
121 def ARMcmp           : SDNode<"ARMISD::CMP", SDT_ARMCmp,
122                               [SDNPOutGlue]>;
123
124 def ARMcmpZ          : SDNode<"ARMISD::CMPZ", SDT_ARMCmp,
125                               [SDNPOutGlue, SDNPCommutative]>;
126
127 def ARMpic_add       : SDNode<"ARMISD::PIC_ADD", SDT_ARMPICAdd>;
128
129 def ARMsrl_flag      : SDNode<"ARMISD::SRL_FLAG", SDTIntUnaryOp, [SDNPOutGlue]>;
130 def ARMsra_flag      : SDNode<"ARMISD::SRA_FLAG", SDTIntUnaryOp, [SDNPOutGlue]>;
131 def ARMrrx           : SDNode<"ARMISD::RRX"     , SDTIntUnaryOp, [SDNPInGlue ]>;
132
133 def ARMaddc          : SDNode<"ARMISD::ADDC",  SDTBinaryArithWithFlags,
134                               [SDNPCommutative]>;
135 def ARMsubc          : SDNode<"ARMISD::SUBC",  SDTBinaryArithWithFlags>;
136 def ARMadde          : SDNode<"ARMISD::ADDE",  SDTBinaryArithWithFlagsInOut>;
137 def ARMsube          : SDNode<"ARMISD::SUBE",  SDTBinaryArithWithFlagsInOut>;
138
139 def ARMthread_pointer: SDNode<"ARMISD::THREAD_POINTER", SDT_ARMThreadPointer>;
140 def ARMeh_sjlj_setjmp: SDNode<"ARMISD::EH_SJLJ_SETJMP",
141                                SDT_ARMEH_SJLJ_Setjmp, [SDNPHasChain]>;
142 def ARMeh_sjlj_longjmp: SDNode<"ARMISD::EH_SJLJ_LONGJMP",
143                                SDT_ARMEH_SJLJ_Longjmp, [SDNPHasChain]>;
144
145 def ARMMemBarrier     : SDNode<"ARMISD::MEMBARRIER", SDT_ARMMEMBARRIER,
146                                [SDNPHasChain]>;
147 def ARMMemBarrierMCR  : SDNode<"ARMISD::MEMBARRIER_MCR", SDT_ARMMEMBARRIER,
148                                [SDNPHasChain]>;
149 def ARMPreload        : SDNode<"ARMISD::PRELOAD", SDT_ARMPREFETCH,
150                                [SDNPHasChain, SDNPMayLoad, SDNPMayStore]>;
151
152 def ARMrbit          : SDNode<"ARMISD::RBIT", SDTIntUnaryOp>;
153
154 def ARMtcret         : SDNode<"ARMISD::TC_RETURN", SDT_ARMTCRET,
155                         [SDNPHasChain,  SDNPOptInGlue, SDNPVariadic]>;
156
157
158 def ARMbfi           : SDNode<"ARMISD::BFI", SDT_ARMBFI>;
159
160 //===----------------------------------------------------------------------===//
161 // ARM Instruction Predicate Definitions.
162 //
163 def HasV4T           : Predicate<"Subtarget->hasV4TOps()">,
164                                  AssemblerPredicate<"HasV4TOps">;
165 def NoV4T            : Predicate<"!Subtarget->hasV4TOps()">;
166 def HasV5T           : Predicate<"Subtarget->hasV5TOps()">;
167 def HasV5TE          : Predicate<"Subtarget->hasV5TEOps()">,
168                                  AssemblerPredicate<"HasV5TEOps">;
169 def HasV6            : Predicate<"Subtarget->hasV6Ops()">,
170                                  AssemblerPredicate<"HasV6Ops">;
171 def NoV6             : Predicate<"!Subtarget->hasV6Ops()">;
172 def HasV6T2          : Predicate<"Subtarget->hasV6T2Ops()">,
173                                  AssemblerPredicate<"HasV6T2Ops">;
174 def NoV6T2           : Predicate<"!Subtarget->hasV6T2Ops()">;
175 def HasV7            : Predicate<"Subtarget->hasV7Ops()">,
176                                  AssemblerPredicate<"HasV7Ops">;
177 def NoVFP            : Predicate<"!Subtarget->hasVFP2()">;
178 def HasVFP2          : Predicate<"Subtarget->hasVFP2()">,
179                                  AssemblerPredicate<"FeatureVFP2">;
180 def HasVFP3          : Predicate<"Subtarget->hasVFP3()">,
181                                  AssemblerPredicate<"FeatureVFP3">;
182 def HasVFP4          : Predicate<"Subtarget->hasVFP4()">,
183                                  AssemblerPredicate<"FeatureVFP4">;
184 def NoVFP4            : Predicate<"!Subtarget->hasVFP4()">;
185 def HasNEON          : Predicate<"Subtarget->hasNEON()">,
186                                  AssemblerPredicate<"FeatureNEON">;
187 def HasNEON2         : Predicate<"Subtarget->hasNEON2()">,
188                                  AssemblerPredicate<"FeatureNEON2">;
189 def NoNEON2          : Predicate<"!Subtarget->hasNEON2()">;
190 def HasFP16          : Predicate<"Subtarget->hasFP16()">,
191                                  AssemblerPredicate<"FeatureFP16">;
192 def HasDivide        : Predicate<"Subtarget->hasDivide()">,
193                                  AssemblerPredicate<"FeatureHWDiv">;
194 def HasT2ExtractPack : Predicate<"Subtarget->hasT2ExtractPack()">,
195                                  AssemblerPredicate<"FeatureT2XtPk">;
196 def HasThumb2DSP     : Predicate<"Subtarget->hasThumb2DSP()">,
197                                  AssemblerPredicate<"FeatureDSPThumb2">;
198 def HasDB            : Predicate<"Subtarget->hasDataBarrier()">,
199                                  AssemblerPredicate<"FeatureDB">;
200 def HasMP            : Predicate<"Subtarget->hasMPExtension()">,
201                                  AssemblerPredicate<"FeatureMP">;
202 def UseNEONForFP     : Predicate<"Subtarget->useNEONForSinglePrecisionFP()">;
203 def DontUseNEONForFP : Predicate<"!Subtarget->useNEONForSinglePrecisionFP()">;
204 def IsThumb          : Predicate<"Subtarget->isThumb()">,
205                                  AssemblerPredicate<"ModeThumb">;
206 def IsThumb1Only     : Predicate<"Subtarget->isThumb1Only()">;
207 def IsThumb2         : Predicate<"Subtarget->isThumb2()">,
208                                  AssemblerPredicate<"ModeThumb,FeatureThumb2">;
209 def IsMClass         : Predicate<"Subtarget->isMClass()">,
210                                  AssemblerPredicate<"FeatureMClass">;
211 def IsARClass        : Predicate<"!Subtarget->isMClass()">,
212                                  AssemblerPredicate<"!FeatureMClass">;
213 def IsARM            : Predicate<"!Subtarget->isThumb()">,
214                                  AssemblerPredicate<"!ModeThumb">;
215 def IsIOS            : Predicate<"Subtarget->isTargetIOS()">;
216 def IsNotIOS         : Predicate<"!Subtarget->isTargetIOS()">;
217 def IsNaCl           : Predicate<"Subtarget->isTargetNaCl()">;
218
219 // FIXME: Eventually this will be just "hasV6T2Ops".
220 def UseMovt          : Predicate<"Subtarget->useMovt()">;
221 def DontUseMovt      : Predicate<"!Subtarget->useMovt()">;
222 def UseFPVMLx        : Predicate<"Subtarget->useFPVMLx()">;
223
224 //===----------------------------------------------------------------------===//
225 // ARM Flag Definitions.
226
227 class RegConstraint<string C> {
228   string Constraints = C;
229 }
230
231 //===----------------------------------------------------------------------===//
232 //  ARM specific transformation functions and pattern fragments.
233 //
234
235 // so_imm_neg_XFORM - Return a so_imm value packed into the format described for
236 // so_imm_neg def below.
237 def so_imm_neg_XFORM : SDNodeXForm<imm, [{
238   return CurDAG->getTargetConstant(-(int)N->getZExtValue(), MVT::i32);
239 }]>;
240
241 // so_imm_not_XFORM - Return a so_imm value packed into the format described for
242 // so_imm_not def below.
243 def so_imm_not_XFORM : SDNodeXForm<imm, [{
244   return CurDAG->getTargetConstant(~(int)N->getZExtValue(), MVT::i32);
245 }]>;
246
247 /// imm16_31 predicate - True if the 32-bit immediate is in the range [16,31].
248 def imm16_31 : ImmLeaf<i32, [{
249   return (int32_t)Imm >= 16 && (int32_t)Imm < 32;
250 }]>;
251
252 def so_imm_neg_asmoperand : AsmOperandClass { let Name = "ARMSOImmNeg"; }
253 def so_imm_neg : Operand<i32>, PatLeaf<(imm), [{
254     int64_t Value = -(int)N->getZExtValue();
255     return Value && ARM_AM::getSOImmVal(Value) != -1;
256   }], so_imm_neg_XFORM> {
257   let ParserMatchClass = so_imm_neg_asmoperand;
258 }
259
260 // Note: this pattern doesn't require an encoder method and such, as it's
261 // only used on aliases (Pat<> and InstAlias<>). The actual encoding
262 // is handled by the destination instructions, which use so_imm.
263 def so_imm_not_asmoperand : AsmOperandClass { let Name = "ARMSOImmNot"; }
264 def so_imm_not : Operand<i32>, PatLeaf<(imm), [{
265     return ARM_AM::getSOImmVal(~(uint32_t)N->getZExtValue()) != -1;
266   }], so_imm_not_XFORM> {
267   let ParserMatchClass = so_imm_not_asmoperand;
268 }
269
270 // sext_16_node predicate - True if the SDNode is sign-extended 16 or more bits.
271 def sext_16_node : PatLeaf<(i32 GPR:$a), [{
272   return CurDAG->ComputeNumSignBits(SDValue(N,0)) >= 17;
273 }]>;
274
275 /// Split a 32-bit immediate into two 16 bit parts.
276 def hi16 : SDNodeXForm<imm, [{
277   return CurDAG->getTargetConstant((uint32_t)N->getZExtValue() >> 16, MVT::i32);
278 }]>;
279
280 def lo16AllZero : PatLeaf<(i32 imm), [{
281   // Returns true if all low 16-bits are 0.
282   return (((uint32_t)N->getZExtValue()) & 0xFFFFUL) == 0;
283 }], hi16>;
284
285 class BinOpWithFlagFrag<dag res> :
286       PatFrag<(ops node:$LHS, node:$RHS, node:$FLAG), res>;
287 class BinOpFrag<dag res> : PatFrag<(ops node:$LHS, node:$RHS), res>;
288 class UnOpFrag <dag res> : PatFrag<(ops node:$Src), res>;
289
290 // An 'and' node with a single use.
291 def and_su : PatFrag<(ops node:$lhs, node:$rhs), (and node:$lhs, node:$rhs), [{
292   return N->hasOneUse();
293 }]>;
294
295 // An 'xor' node with a single use.
296 def xor_su : PatFrag<(ops node:$lhs, node:$rhs), (xor node:$lhs, node:$rhs), [{
297   return N->hasOneUse();
298 }]>;
299
300 // An 'fmul' node with a single use.
301 def fmul_su : PatFrag<(ops node:$lhs, node:$rhs), (fmul node:$lhs, node:$rhs),[{
302   return N->hasOneUse();
303 }]>;
304
305 // An 'fadd' node which checks for single non-hazardous use.
306 def fadd_mlx : PatFrag<(ops node:$lhs, node:$rhs),(fadd node:$lhs, node:$rhs),[{
307   return hasNoVMLxHazardUse(N);
308 }]>;
309
310 // An 'fsub' node which checks for single non-hazardous use.
311 def fsub_mlx : PatFrag<(ops node:$lhs, node:$rhs),(fsub node:$lhs, node:$rhs),[{
312   return hasNoVMLxHazardUse(N);
313 }]>;
314
315 //===----------------------------------------------------------------------===//
316 // Operand Definitions.
317 //
318
319 // Immediate operands with a shared generic asm render method.
320 class ImmAsmOperand : AsmOperandClass { let RenderMethod = "addImmOperands"; }
321
322 // Branch target.
323 // FIXME: rename brtarget to t2_brtarget
324 def brtarget : Operand<OtherVT> {
325   let EncoderMethod = "getBranchTargetOpValue";
326   let OperandType = "OPERAND_PCREL";
327   let DecoderMethod = "DecodeT2BROperand";
328 }
329
330 // FIXME: get rid of this one?
331 def uncondbrtarget : Operand<OtherVT> {
332   let EncoderMethod = "getUnconditionalBranchTargetOpValue";
333   let OperandType = "OPERAND_PCREL";
334 }
335
336 // Branch target for ARM. Handles conditional/unconditional
337 def br_target : Operand<OtherVT> {
338   let EncoderMethod = "getARMBranchTargetOpValue";
339   let OperandType = "OPERAND_PCREL";
340 }
341
342 // Call target.
343 // FIXME: rename bltarget to t2_bl_target?
344 def bltarget : Operand<i32> {
345   // Encoded the same as branch targets.
346   let EncoderMethod = "getBranchTargetOpValue";
347   let OperandType = "OPERAND_PCREL";
348 }
349
350 // Call target for ARM. Handles conditional/unconditional
351 // FIXME: rename bl_target to t2_bltarget?
352 def bl_target : Operand<i32> {
353   let EncoderMethod = "getARMBLTargetOpValue";
354   let OperandType = "OPERAND_PCREL";
355 }
356
357 def blx_target : Operand<i32> {
358   let EncoderMethod = "getARMBLXTargetOpValue";
359   let OperandType = "OPERAND_PCREL";
360 }
361
362 // A list of registers separated by comma. Used by load/store multiple.
363 def RegListAsmOperand : AsmOperandClass { let Name = "RegList"; }
364 def reglist : Operand<i32> {
365   let EncoderMethod = "getRegisterListOpValue";
366   let ParserMatchClass = RegListAsmOperand;
367   let PrintMethod = "printRegisterList";
368   let DecoderMethod = "DecodeRegListOperand";
369 }
370
371 def DPRRegListAsmOperand : AsmOperandClass { let Name = "DPRRegList"; }
372 def dpr_reglist : Operand<i32> {
373   let EncoderMethod = "getRegisterListOpValue";
374   let ParserMatchClass = DPRRegListAsmOperand;
375   let PrintMethod = "printRegisterList";
376   let DecoderMethod = "DecodeDPRRegListOperand";
377 }
378
379 def SPRRegListAsmOperand : AsmOperandClass { let Name = "SPRRegList"; }
380 def spr_reglist : Operand<i32> {
381   let EncoderMethod = "getRegisterListOpValue";
382   let ParserMatchClass = SPRRegListAsmOperand;
383   let PrintMethod = "printRegisterList";
384   let DecoderMethod = "DecodeSPRRegListOperand";
385 }
386
387 // An operand for the CONSTPOOL_ENTRY pseudo-instruction.
388 def cpinst_operand : Operand<i32> {
389   let PrintMethod = "printCPInstOperand";
390 }
391
392 // Local PC labels.
393 def pclabel : Operand<i32> {
394   let PrintMethod = "printPCLabel";
395 }
396
397 // ADR instruction labels.
398 def adrlabel : Operand<i32> {
399   let EncoderMethod = "getAdrLabelOpValue";
400 }
401
402 def neon_vcvt_imm32 : Operand<i32> {
403   let EncoderMethod = "getNEONVcvtImm32OpValue";
404   let DecoderMethod = "DecodeVCVTImmOperand";
405 }
406
407 // rot_imm: An integer that encodes a rotate amount. Must be 8, 16, or 24.
408 def rot_imm_XFORM: SDNodeXForm<imm, [{
409   switch (N->getZExtValue()){
410   default: assert(0);
411   case 0:  return CurDAG->getTargetConstant(0, MVT::i32);
412   case 8:  return CurDAG->getTargetConstant(1, MVT::i32);
413   case 16: return CurDAG->getTargetConstant(2, MVT::i32);
414   case 24: return CurDAG->getTargetConstant(3, MVT::i32);
415   }
416 }]>;
417 def RotImmAsmOperand : AsmOperandClass {
418   let Name = "RotImm";
419   let ParserMethod = "parseRotImm";
420 }
421 def rot_imm : Operand<i32>, PatLeaf<(i32 imm), [{
422     int32_t v = N->getZExtValue();
423     return v == 8 || v == 16 || v == 24; }],
424     rot_imm_XFORM> {
425   let PrintMethod = "printRotImmOperand";
426   let ParserMatchClass = RotImmAsmOperand;
427 }
428
429 // shift_imm: An integer that encodes a shift amount and the type of shift
430 // (asr or lsl). The 6-bit immediate encodes as:
431 //    {5}     0 ==> lsl
432 //            1     asr
433 //    {4-0}   imm5 shift amount.
434 //            asr #32 encoded as imm5 == 0.
435 def ShifterImmAsmOperand : AsmOperandClass {
436   let Name = "ShifterImm";
437   let ParserMethod = "parseShifterImm";
438 }
439 def shift_imm : Operand<i32> {
440   let PrintMethod = "printShiftImmOperand";
441   let ParserMatchClass = ShifterImmAsmOperand;
442 }
443
444 // shifter_operand operands: so_reg_reg, so_reg_imm, and so_imm.
445 def ShiftedRegAsmOperand : AsmOperandClass { let Name = "RegShiftedReg"; }
446 def so_reg_reg : Operand<i32>,  // reg reg imm
447                  ComplexPattern<i32, 3, "SelectRegShifterOperand",
448                                 [shl, srl, sra, rotr]> {
449   let EncoderMethod = "getSORegRegOpValue";
450   let PrintMethod = "printSORegRegOperand";
451   let DecoderMethod = "DecodeSORegRegOperand";
452   let ParserMatchClass = ShiftedRegAsmOperand;
453   let MIOperandInfo = (ops GPRnopc, GPRnopc, i32imm);
454 }
455
456 def ShiftedImmAsmOperand : AsmOperandClass { let Name = "RegShiftedImm"; }
457 def so_reg_imm : Operand<i32>, // reg imm
458                  ComplexPattern<i32, 2, "SelectImmShifterOperand",
459                                 [shl, srl, sra, rotr]> {
460   let EncoderMethod = "getSORegImmOpValue";
461   let PrintMethod = "printSORegImmOperand";
462   let DecoderMethod = "DecodeSORegImmOperand";
463   let ParserMatchClass = ShiftedImmAsmOperand;
464   let MIOperandInfo = (ops GPR, i32imm);
465 }
466
467 // FIXME: Does this need to be distinct from so_reg?
468 def shift_so_reg_reg : Operand<i32>,    // reg reg imm
469                    ComplexPattern<i32, 3, "SelectShiftRegShifterOperand",
470                                   [shl,srl,sra,rotr]> {
471   let EncoderMethod = "getSORegRegOpValue";
472   let PrintMethod = "printSORegRegOperand";
473   let DecoderMethod = "DecodeSORegRegOperand";
474   let ParserMatchClass = ShiftedRegAsmOperand;
475   let MIOperandInfo = (ops GPR, GPR, i32imm);
476 }
477
478 // FIXME: Does this need to be distinct from so_reg?
479 def shift_so_reg_imm : Operand<i32>,    // reg reg imm
480                    ComplexPattern<i32, 2, "SelectShiftImmShifterOperand",
481                                   [shl,srl,sra,rotr]> {
482   let EncoderMethod = "getSORegImmOpValue";
483   let PrintMethod = "printSORegImmOperand";
484   let DecoderMethod = "DecodeSORegImmOperand";
485   let ParserMatchClass = ShiftedImmAsmOperand;
486   let MIOperandInfo = (ops GPR, i32imm);
487 }
488
489
490 // so_imm - Match a 32-bit shifter_operand immediate operand, which is an
491 // 8-bit immediate rotated by an arbitrary number of bits.
492 def SOImmAsmOperand: ImmAsmOperand { let Name = "ARMSOImm"; }
493 def so_imm : Operand<i32>, ImmLeaf<i32, [{
494     return ARM_AM::getSOImmVal(Imm) != -1;
495   }]> {
496   let EncoderMethod = "getSOImmOpValue";
497   let ParserMatchClass = SOImmAsmOperand;
498   let DecoderMethod = "DecodeSOImmOperand";
499 }
500
501 // Break so_imm's up into two pieces.  This handles immediates with up to 16
502 // bits set in them.  This uses so_imm2part to match and so_imm2part_[12] to
503 // get the first/second pieces.
504 def so_imm2part : PatLeaf<(imm), [{
505       return ARM_AM::isSOImmTwoPartVal((unsigned)N->getZExtValue());
506 }]>;
507
508 /// arm_i32imm - True for +V6T2, or true only if so_imm2part is true.
509 ///
510 def arm_i32imm : PatLeaf<(imm), [{
511   if (Subtarget->hasV6T2Ops())
512     return true;
513   return ARM_AM::isSOImmTwoPartVal((unsigned)N->getZExtValue());
514 }]>;
515
516 /// imm0_1 predicate - Immediate in the range [0,1].
517 def Imm0_1AsmOperand: ImmAsmOperand { let Name = "Imm0_1"; }
518 def imm0_1 : Operand<i32> { let ParserMatchClass = Imm0_1AsmOperand; }
519
520 /// imm0_3 predicate - Immediate in the range [0,3].
521 def Imm0_3AsmOperand: ImmAsmOperand { let Name = "Imm0_3"; }
522 def imm0_3 : Operand<i32> { let ParserMatchClass = Imm0_3AsmOperand; }
523
524 /// imm0_7 predicate - Immediate in the range [0,7].
525 def Imm0_7AsmOperand: ImmAsmOperand { let Name = "Imm0_7"; }
526 def imm0_7 : Operand<i32>, ImmLeaf<i32, [{
527   return Imm >= 0 && Imm < 8;
528 }]> {
529   let ParserMatchClass = Imm0_7AsmOperand;
530 }
531
532 /// imm8 predicate - Immediate is exactly 8.
533 def Imm8AsmOperand: ImmAsmOperand { let Name = "Imm8"; }
534 def imm8 : Operand<i32>, ImmLeaf<i32, [{ return Imm == 8; }]> {
535   let ParserMatchClass = Imm8AsmOperand;
536 }
537
538 /// imm16 predicate - Immediate is exactly 16.
539 def Imm16AsmOperand: ImmAsmOperand { let Name = "Imm16"; }
540 def imm16 : Operand<i32>, ImmLeaf<i32, [{ return Imm == 16; }]> {
541   let ParserMatchClass = Imm16AsmOperand;
542 }
543
544 /// imm32 predicate - Immediate is exactly 32.
545 def Imm32AsmOperand: ImmAsmOperand { let Name = "Imm32"; }
546 def imm32 : Operand<i32>, ImmLeaf<i32, [{ return Imm == 32; }]> {
547   let ParserMatchClass = Imm32AsmOperand;
548 }
549
550 /// imm1_7 predicate - Immediate in the range [1,7].
551 def Imm1_7AsmOperand: ImmAsmOperand { let Name = "Imm1_7"; }
552 def imm1_7 : Operand<i32>, ImmLeaf<i32, [{ return Imm > 0 && Imm < 8; }]> {
553   let ParserMatchClass = Imm1_7AsmOperand;
554 }
555
556 /// imm1_15 predicate - Immediate in the range [1,15].
557 def Imm1_15AsmOperand: ImmAsmOperand { let Name = "Imm1_15"; }
558 def imm1_15 : Operand<i32>, ImmLeaf<i32, [{ return Imm > 0 && Imm < 16; }]> {
559   let ParserMatchClass = Imm1_15AsmOperand;
560 }
561
562 /// imm1_31 predicate - Immediate in the range [1,31].
563 def Imm1_31AsmOperand: ImmAsmOperand { let Name = "Imm1_31"; }
564 def imm1_31 : Operand<i32>, ImmLeaf<i32, [{ return Imm > 0 && Imm < 32; }]> {
565   let ParserMatchClass = Imm1_31AsmOperand;
566 }
567
568 /// imm0_15 predicate - Immediate in the range [0,15].
569 def Imm0_15AsmOperand: ImmAsmOperand { let Name = "Imm0_15"; }
570 def imm0_15 : Operand<i32>, ImmLeaf<i32, [{
571   return Imm >= 0 && Imm < 16;
572 }]> {
573   let ParserMatchClass = Imm0_15AsmOperand;
574 }
575
576 /// imm0_31 predicate - True if the 32-bit immediate is in the range [0,31].
577 def Imm0_31AsmOperand: ImmAsmOperand { let Name = "Imm0_31"; }
578 def imm0_31 : Operand<i32>, ImmLeaf<i32, [{
579   return Imm >= 0 && Imm < 32;
580 }]> {
581   let ParserMatchClass = Imm0_31AsmOperand;
582 }
583
584 /// imm0_32 predicate - True if the 32-bit immediate is in the range [0,32].
585 def Imm0_32AsmOperand: ImmAsmOperand { let Name = "Imm0_32"; }
586 def imm0_32 : Operand<i32>, ImmLeaf<i32, [{
587   return Imm >= 0 && Imm < 32;
588 }]> {
589   let ParserMatchClass = Imm0_32AsmOperand;
590 }
591
592 /// imm0_63 predicate - True if the 32-bit immediate is in the range [0,63].
593 def Imm0_63AsmOperand: ImmAsmOperand { let Name = "Imm0_63"; }
594 def imm0_63 : Operand<i32>, ImmLeaf<i32, [{
595   return Imm >= 0 && Imm < 64;
596 }]> {
597   let ParserMatchClass = Imm0_63AsmOperand;
598 }
599
600 /// imm0_255 predicate - Immediate in the range [0,255].
601 def Imm0_255AsmOperand : ImmAsmOperand { let Name = "Imm0_255"; }
602 def imm0_255 : Operand<i32>, ImmLeaf<i32, [{ return Imm >= 0 && Imm < 256; }]> {
603   let ParserMatchClass = Imm0_255AsmOperand;
604 }
605
606 /// imm0_65535 - An immediate is in the range [0.65535].
607 def Imm0_65535AsmOperand: ImmAsmOperand { let Name = "Imm0_65535"; }
608 def imm0_65535 : Operand<i32>, ImmLeaf<i32, [{
609   return Imm >= 0 && Imm < 65536;
610 }]> {
611   let ParserMatchClass = Imm0_65535AsmOperand;
612 }
613
614 // imm0_65535_expr - For movt/movw - 16-bit immediate that can also reference
615 // a relocatable expression.
616 //
617 // FIXME: This really needs a Thumb version separate from the ARM version.
618 // While the range is the same, and can thus use the same match class,
619 // the encoding is different so it should have a different encoder method.
620 def Imm0_65535ExprAsmOperand: ImmAsmOperand { let Name = "Imm0_65535Expr"; }
621 def imm0_65535_expr : Operand<i32> {
622   let EncoderMethod = "getHiLo16ImmOpValue";
623   let ParserMatchClass = Imm0_65535ExprAsmOperand;
624 }
625
626 /// imm24b - True if the 32-bit immediate is encodable in 24 bits.
627 def Imm24bitAsmOperand: ImmAsmOperand { let Name = "Imm24bit"; }
628 def imm24b : Operand<i32>, ImmLeaf<i32, [{
629   return Imm >= 0 && Imm <= 0xffffff;
630 }]> {
631   let ParserMatchClass = Imm24bitAsmOperand;
632 }
633
634
635 /// bf_inv_mask_imm predicate - An AND mask to clear an arbitrary width bitfield
636 /// e.g., 0xf000ffff
637 def BitfieldAsmOperand : AsmOperandClass {
638   let Name = "Bitfield";
639   let ParserMethod = "parseBitfield";
640 }
641
642 def bf_inv_mask_imm : Operand<i32>,
643                       PatLeaf<(imm), [{
644   return ARM::isBitFieldInvertedMask(N->getZExtValue());
645 }] > {
646   let EncoderMethod = "getBitfieldInvertedMaskOpValue";
647   let PrintMethod = "printBitfieldInvMaskImmOperand";
648   let DecoderMethod = "DecodeBitfieldMaskOperand";
649   let ParserMatchClass = BitfieldAsmOperand;
650 }
651
652 def imm1_32_XFORM: SDNodeXForm<imm, [{
653   return CurDAG->getTargetConstant((int)N->getZExtValue() - 1, MVT::i32);
654 }]>;
655 def Imm1_32AsmOperand: AsmOperandClass { let Name = "Imm1_32"; }
656 def imm1_32 : Operand<i32>, PatLeaf<(imm), [{
657    uint64_t Imm = N->getZExtValue();
658    return Imm > 0 && Imm <= 32;
659  }],
660     imm1_32_XFORM> {
661   let PrintMethod = "printImmPlusOneOperand";
662   let ParserMatchClass = Imm1_32AsmOperand;
663 }
664
665 def imm1_16_XFORM: SDNodeXForm<imm, [{
666   return CurDAG->getTargetConstant((int)N->getZExtValue() - 1, MVT::i32);
667 }]>;
668 def Imm1_16AsmOperand: AsmOperandClass { let Name = "Imm1_16"; }
669 def imm1_16 : Operand<i32>, PatLeaf<(imm), [{ return Imm > 0 && Imm <= 16; }],
670     imm1_16_XFORM> {
671   let PrintMethod = "printImmPlusOneOperand";
672   let ParserMatchClass = Imm1_16AsmOperand;
673 }
674
675 // Define ARM specific addressing modes.
676 // addrmode_imm12 := reg +/- imm12
677 //
678 def MemImm12OffsetAsmOperand : AsmOperandClass { let Name = "MemImm12Offset"; }
679 def addrmode_imm12 : Operand<i32>,
680                      ComplexPattern<i32, 2, "SelectAddrModeImm12", []> {
681   // 12-bit immediate operand. Note that instructions using this encode
682   // #0 and #-0 differently. We flag #-0 as the magic value INT32_MIN. All other
683   // immediate values are as normal.
684
685   let EncoderMethod = "getAddrModeImm12OpValue";
686   let PrintMethod = "printAddrModeImm12Operand";
687   let DecoderMethod = "DecodeAddrModeImm12Operand";
688   let ParserMatchClass = MemImm12OffsetAsmOperand;
689   let MIOperandInfo = (ops GPR:$base, i32imm:$offsimm);
690 }
691 // ldst_so_reg := reg +/- reg shop imm
692 //
693 def MemRegOffsetAsmOperand : AsmOperandClass { let Name = "MemRegOffset"; }
694 def ldst_so_reg : Operand<i32>,
695                   ComplexPattern<i32, 3, "SelectLdStSOReg", []> {
696   let EncoderMethod = "getLdStSORegOpValue";
697   // FIXME: Simplify the printer
698   let PrintMethod = "printAddrMode2Operand";
699   let DecoderMethod = "DecodeSORegMemOperand";
700   let ParserMatchClass = MemRegOffsetAsmOperand;
701   let MIOperandInfo = (ops GPR:$base, GPRnopc:$offsreg, i32imm:$shift);
702 }
703
704 // postidx_imm8 := +/- [0,255]
705 //
706 // 9 bit value:
707 //  {8}       1 is imm8 is non-negative. 0 otherwise.
708 //  {7-0}     [0,255] imm8 value.
709 def PostIdxImm8AsmOperand : AsmOperandClass { let Name = "PostIdxImm8"; }
710 def postidx_imm8 : Operand<i32> {
711   let PrintMethod = "printPostIdxImm8Operand";
712   let ParserMatchClass = PostIdxImm8AsmOperand;
713   let MIOperandInfo = (ops i32imm);
714 }
715
716 // postidx_imm8s4 := +/- [0,1020]
717 //
718 // 9 bit value:
719 //  {8}       1 is imm8 is non-negative. 0 otherwise.
720 //  {7-0}     [0,255] imm8 value, scaled by 4.
721 def PostIdxImm8s4AsmOperand : AsmOperandClass { let Name = "PostIdxImm8s4"; }
722 def postidx_imm8s4 : Operand<i32> {
723   let PrintMethod = "printPostIdxImm8s4Operand";
724   let ParserMatchClass = PostIdxImm8s4AsmOperand;
725   let MIOperandInfo = (ops i32imm);
726 }
727
728
729 // postidx_reg := +/- reg
730 //
731 def PostIdxRegAsmOperand : AsmOperandClass {
732   let Name = "PostIdxReg";
733   let ParserMethod = "parsePostIdxReg";
734 }
735 def postidx_reg : Operand<i32> {
736   let EncoderMethod = "getPostIdxRegOpValue";
737   let DecoderMethod = "DecodePostIdxReg";
738   let PrintMethod = "printPostIdxRegOperand";
739   let ParserMatchClass = PostIdxRegAsmOperand;
740   let MIOperandInfo = (ops GPRnopc, i32imm);
741 }
742
743
744 // addrmode2 := reg +/- imm12
745 //           := reg +/- reg shop imm
746 //
747 // FIXME: addrmode2 should be refactored the rest of the way to always
748 // use explicit imm vs. reg versions above (addrmode_imm12 and ldst_so_reg).
749 def AddrMode2AsmOperand : AsmOperandClass { let Name = "AddrMode2"; }
750 def addrmode2 : Operand<i32>,
751                 ComplexPattern<i32, 3, "SelectAddrMode2", []> {
752   let EncoderMethod = "getAddrMode2OpValue";
753   let PrintMethod = "printAddrMode2Operand";
754   let ParserMatchClass = AddrMode2AsmOperand;
755   let MIOperandInfo = (ops GPR:$base, GPR:$offsreg, i32imm:$offsimm);
756 }
757
758 def PostIdxRegShiftedAsmOperand : AsmOperandClass {
759   let Name = "PostIdxRegShifted";
760   let ParserMethod = "parsePostIdxReg";
761 }
762 def am2offset_reg : Operand<i32>,
763                 ComplexPattern<i32, 2, "SelectAddrMode2OffsetReg",
764                 [], [SDNPWantRoot]> {
765   let EncoderMethod = "getAddrMode2OffsetOpValue";
766   let PrintMethod = "printAddrMode2OffsetOperand";
767   // When using this for assembly, it's always as a post-index offset.
768   let ParserMatchClass = PostIdxRegShiftedAsmOperand;
769   let MIOperandInfo = (ops GPRnopc, i32imm);
770 }
771
772 // FIXME: am2offset_imm should only need the immediate, not the GPR. Having
773 // the GPR is purely vestigal at this point.
774 def AM2OffsetImmAsmOperand : AsmOperandClass { let Name = "AM2OffsetImm"; }
775 def am2offset_imm : Operand<i32>,
776                 ComplexPattern<i32, 2, "SelectAddrMode2OffsetImm",
777                 [], [SDNPWantRoot]> {
778   let EncoderMethod = "getAddrMode2OffsetOpValue";
779   let PrintMethod = "printAddrMode2OffsetOperand";
780   let ParserMatchClass = AM2OffsetImmAsmOperand;
781   let MIOperandInfo = (ops GPRnopc, i32imm);
782 }
783
784
785 // addrmode3 := reg +/- reg
786 // addrmode3 := reg +/- imm8
787 //
788 // FIXME: split into imm vs. reg versions.
789 def AddrMode3AsmOperand : AsmOperandClass { let Name = "AddrMode3"; }
790 def addrmode3 : Operand<i32>,
791                 ComplexPattern<i32, 3, "SelectAddrMode3", []> {
792   let EncoderMethod = "getAddrMode3OpValue";
793   let PrintMethod = "printAddrMode3Operand";
794   let ParserMatchClass = AddrMode3AsmOperand;
795   let MIOperandInfo = (ops GPR:$base, GPR:$offsreg, i32imm:$offsimm);
796 }
797
798 // FIXME: split into imm vs. reg versions.
799 // FIXME: parser method to handle +/- register.
800 def AM3OffsetAsmOperand : AsmOperandClass {
801   let Name = "AM3Offset";
802   let ParserMethod = "parseAM3Offset";
803 }
804 def am3offset : Operand<i32>,
805                 ComplexPattern<i32, 2, "SelectAddrMode3Offset",
806                                [], [SDNPWantRoot]> {
807   let EncoderMethod = "getAddrMode3OffsetOpValue";
808   let PrintMethod = "printAddrMode3OffsetOperand";
809   let ParserMatchClass = AM3OffsetAsmOperand;
810   let MIOperandInfo = (ops GPR, i32imm);
811 }
812
813 // ldstm_mode := {ia, ib, da, db}
814 //
815 def ldstm_mode : OptionalDefOperand<OtherVT, (ops i32), (ops (i32 1))> {
816   let EncoderMethod = "getLdStmModeOpValue";
817   let PrintMethod = "printLdStmModeOperand";
818 }
819
820 // addrmode5 := reg +/- imm8*4
821 //
822 def AddrMode5AsmOperand : AsmOperandClass { let Name = "AddrMode5"; }
823 def addrmode5 : Operand<i32>,
824                 ComplexPattern<i32, 2, "SelectAddrMode5", []> {
825   let PrintMethod = "printAddrMode5Operand";
826   let EncoderMethod = "getAddrMode5OpValue";
827   let DecoderMethod = "DecodeAddrMode5Operand";
828   let ParserMatchClass = AddrMode5AsmOperand;
829   let MIOperandInfo = (ops GPR:$base, i32imm);
830 }
831
832 // addrmode6 := reg with optional alignment
833 //
834 def AddrMode6AsmOperand : AsmOperandClass { let Name = "AlignedMemory"; }
835 def addrmode6 : Operand<i32>,
836                 ComplexPattern<i32, 2, "SelectAddrMode6", [], [SDNPWantParent]>{
837   let PrintMethod = "printAddrMode6Operand";
838   let MIOperandInfo = (ops GPR:$addr, i32imm:$align);
839   let EncoderMethod = "getAddrMode6AddressOpValue";
840   let DecoderMethod = "DecodeAddrMode6Operand";
841   let ParserMatchClass = AddrMode6AsmOperand;
842 }
843
844 def am6offset : Operand<i32>,
845                 ComplexPattern<i32, 1, "SelectAddrMode6Offset",
846                                [], [SDNPWantRoot]> {
847   let PrintMethod = "printAddrMode6OffsetOperand";
848   let MIOperandInfo = (ops GPR);
849   let EncoderMethod = "getAddrMode6OffsetOpValue";
850   let DecoderMethod = "DecodeGPRRegisterClass";
851 }
852
853 // Special version of addrmode6 to handle alignment encoding for VST1/VLD1
854 // (single element from one lane) for size 32.
855 def addrmode6oneL32 : Operand<i32>,
856                 ComplexPattern<i32, 2, "SelectAddrMode6", [], [SDNPWantParent]>{
857   let PrintMethod = "printAddrMode6Operand";
858   let MIOperandInfo = (ops GPR:$addr, i32imm);
859   let EncoderMethod = "getAddrMode6OneLane32AddressOpValue";
860 }
861
862 // Special version of addrmode6 to handle alignment encoding for VLD-dup
863 // instructions, specifically VLD4-dup.
864 def addrmode6dup : Operand<i32>,
865                 ComplexPattern<i32, 2, "SelectAddrMode6", [], [SDNPWantParent]>{
866   let PrintMethod = "printAddrMode6Operand";
867   let MIOperandInfo = (ops GPR:$addr, i32imm);
868   let EncoderMethod = "getAddrMode6DupAddressOpValue";
869   // FIXME: This is close, but not quite right. The alignment specifier is
870   // different.
871   let ParserMatchClass = AddrMode6AsmOperand;
872 }
873
874 // addrmodepc := pc + reg
875 //
876 def addrmodepc : Operand<i32>,
877                  ComplexPattern<i32, 2, "SelectAddrModePC", []> {
878   let PrintMethod = "printAddrModePCOperand";
879   let MIOperandInfo = (ops GPR, i32imm);
880 }
881
882 // addr_offset_none := reg
883 //
884 def MemNoOffsetAsmOperand : AsmOperandClass { let Name = "MemNoOffset"; }
885 def addr_offset_none : Operand<i32>,
886                        ComplexPattern<i32, 1, "SelectAddrOffsetNone", []> {
887   let PrintMethod = "printAddrMode7Operand";
888   let DecoderMethod = "DecodeAddrMode7Operand";
889   let ParserMatchClass = MemNoOffsetAsmOperand;
890   let MIOperandInfo = (ops GPR:$base);
891 }
892
893 def nohash_imm : Operand<i32> {
894   let PrintMethod = "printNoHashImmediate";
895 }
896
897 def CoprocNumAsmOperand : AsmOperandClass {
898   let Name = "CoprocNum";
899   let ParserMethod = "parseCoprocNumOperand";
900 }
901 def p_imm : Operand<i32> {
902   let PrintMethod = "printPImmediate";
903   let ParserMatchClass = CoprocNumAsmOperand;
904   let DecoderMethod = "DecodeCoprocessor";
905 }
906
907 def CoprocRegAsmOperand : AsmOperandClass {
908   let Name = "CoprocReg";
909   let ParserMethod = "parseCoprocRegOperand";
910 }
911 def c_imm : Operand<i32> {
912   let PrintMethod = "printCImmediate";
913   let ParserMatchClass = CoprocRegAsmOperand;
914 }
915 def CoprocOptionAsmOperand : AsmOperandClass {
916   let Name = "CoprocOption";
917   let ParserMethod = "parseCoprocOptionOperand";
918 }
919 def coproc_option_imm : Operand<i32> {
920   let PrintMethod = "printCoprocOptionImm";
921   let ParserMatchClass = CoprocOptionAsmOperand;
922 }
923
924 //===----------------------------------------------------------------------===//
925
926 include "ARMInstrFormats.td"
927
928 //===----------------------------------------------------------------------===//
929 // Multiclass helpers...
930 //
931
932 /// AsI1_bin_irs - Defines a set of (op r, {so_imm|r|so_reg}) patterns for a
933 /// binop that produces a value.
934 multiclass AsI1_bin_irs<bits<4> opcod, string opc,
935                      InstrItinClass iii, InstrItinClass iir, InstrItinClass iis,
936                         PatFrag opnode, string baseOpc, bit Commutable = 0> {
937   // The register-immediate version is re-materializable. This is useful
938   // in particular for taking the address of a local.
939   let isReMaterializable = 1 in {
940   def ri : AsI1<opcod, (outs GPR:$Rd), (ins GPR:$Rn, so_imm:$imm), DPFrm,
941                iii, opc, "\t$Rd, $Rn, $imm",
942                [(set GPR:$Rd, (opnode GPR:$Rn, so_imm:$imm))]> {
943     bits<4> Rd;
944     bits<4> Rn;
945     bits<12> imm;
946     let Inst{25} = 1;
947     let Inst{19-16} = Rn;
948     let Inst{15-12} = Rd;
949     let Inst{11-0} = imm;
950   }
951   }
952   def rr : AsI1<opcod, (outs GPR:$Rd), (ins GPR:$Rn, GPR:$Rm), DPFrm,
953                iir, opc, "\t$Rd, $Rn, $Rm",
954                [(set GPR:$Rd, (opnode GPR:$Rn, GPR:$Rm))]> {
955     bits<4> Rd;
956     bits<4> Rn;
957     bits<4> Rm;
958     let Inst{25} = 0;
959     let isCommutable = Commutable;
960     let Inst{19-16} = Rn;
961     let Inst{15-12} = Rd;
962     let Inst{11-4} = 0b00000000;
963     let Inst{3-0} = Rm;
964   }
965
966   def rsi : AsI1<opcod, (outs GPR:$Rd),
967                (ins GPR:$Rn, so_reg_imm:$shift), DPSoRegImmFrm,
968                iis, opc, "\t$Rd, $Rn, $shift",
969                [(set GPR:$Rd, (opnode GPR:$Rn, so_reg_imm:$shift))]> {
970     bits<4> Rd;
971     bits<4> Rn;
972     bits<12> shift;
973     let Inst{25} = 0;
974     let Inst{19-16} = Rn;
975     let Inst{15-12} = Rd;
976     let Inst{11-5} = shift{11-5};
977     let Inst{4} = 0;
978     let Inst{3-0} = shift{3-0};
979   }
980
981   def rsr : AsI1<opcod, (outs GPR:$Rd),
982                (ins GPR:$Rn, so_reg_reg:$shift), DPSoRegRegFrm,
983                iis, opc, "\t$Rd, $Rn, $shift",
984                [(set GPR:$Rd, (opnode GPR:$Rn, so_reg_reg:$shift))]> {
985     bits<4> Rd;
986     bits<4> Rn;
987     bits<12> shift;
988     let Inst{25} = 0;
989     let Inst{19-16} = Rn;
990     let Inst{15-12} = Rd;
991     let Inst{11-8} = shift{11-8};
992     let Inst{7} = 0;
993     let Inst{6-5} = shift{6-5};
994     let Inst{4} = 1;
995     let Inst{3-0} = shift{3-0};
996   }
997
998   // Assembly aliases for optional destination operand when it's the same
999   // as the source operand.
1000   def : InstAlias<!strconcat(opc, "${s}${p} $Rdn, $imm"),
1001      (!cast<Instruction>(!strconcat(baseOpc, "ri")) GPR:$Rdn, GPR:$Rdn,
1002                                                     so_imm:$imm, pred:$p,
1003                                                     cc_out:$s)>,
1004      Requires<[IsARM]>;
1005   def : InstAlias<!strconcat(opc, "${s}${p} $Rdn, $Rm"),
1006      (!cast<Instruction>(!strconcat(baseOpc, "rr")) GPR:$Rdn, GPR:$Rdn,
1007                                                     GPR:$Rm, pred:$p,
1008                                                     cc_out:$s)>,
1009      Requires<[IsARM]>;
1010   def : InstAlias<!strconcat(opc, "${s}${p} $Rdn, $shift"),
1011      (!cast<Instruction>(!strconcat(baseOpc, "rsi")) GPR:$Rdn, GPR:$Rdn,
1012                                                     so_reg_imm:$shift, pred:$p,
1013                                                     cc_out:$s)>,
1014      Requires<[IsARM]>;
1015   def : InstAlias<!strconcat(opc, "${s}${p} $Rdn, $shift"),
1016      (!cast<Instruction>(!strconcat(baseOpc, "rsr")) GPR:$Rdn, GPR:$Rdn,
1017                                                     so_reg_reg:$shift, pred:$p,
1018                                                     cc_out:$s)>,
1019      Requires<[IsARM]>;
1020
1021 }
1022
1023 /// AsI1_rbin_irs - Same as AsI1_bin_irs except the order of operands are
1024 /// reversed.  The 'rr' form is only defined for the disassembler; for codegen
1025 /// it is equivalent to the AsI1_bin_irs counterpart.
1026 multiclass AsI1_rbin_irs<bits<4> opcod, string opc,
1027                      InstrItinClass iii, InstrItinClass iir, InstrItinClass iis,
1028                         PatFrag opnode, string baseOpc, bit Commutable = 0> {
1029   // The register-immediate version is re-materializable. This is useful
1030   // in particular for taking the address of a local.
1031   let isReMaterializable = 1 in {
1032   def ri : AsI1<opcod, (outs GPR:$Rd), (ins GPR:$Rn, so_imm:$imm), DPFrm,
1033                iii, opc, "\t$Rd, $Rn, $imm",
1034                [(set GPR:$Rd, (opnode so_imm:$imm, GPR:$Rn))]> {
1035     bits<4> Rd;
1036     bits<4> Rn;
1037     bits<12> imm;
1038     let Inst{25} = 1;
1039     let Inst{19-16} = Rn;
1040     let Inst{15-12} = Rd;
1041     let Inst{11-0} = imm;
1042   }
1043   }
1044   def rr : AsI1<opcod, (outs GPR:$Rd), (ins GPR:$Rn, GPR:$Rm), DPFrm,
1045                iir, opc, "\t$Rd, $Rn, $Rm",
1046                [/* pattern left blank */]> {
1047     bits<4> Rd;
1048     bits<4> Rn;
1049     bits<4> Rm;
1050     let Inst{11-4} = 0b00000000;
1051     let Inst{25} = 0;
1052     let Inst{3-0} = Rm;
1053     let Inst{15-12} = Rd;
1054     let Inst{19-16} = Rn;
1055   }
1056
1057   def rsi : AsI1<opcod, (outs GPR:$Rd),
1058                (ins GPR:$Rn, so_reg_imm:$shift), DPSoRegImmFrm,
1059                iis, opc, "\t$Rd, $Rn, $shift",
1060                [(set GPR:$Rd, (opnode so_reg_imm:$shift, GPR:$Rn))]> {
1061     bits<4> Rd;
1062     bits<4> Rn;
1063     bits<12> shift;
1064     let Inst{25} = 0;
1065     let Inst{19-16} = Rn;
1066     let Inst{15-12} = Rd;
1067     let Inst{11-5} = shift{11-5};
1068     let Inst{4} = 0;
1069     let Inst{3-0} = shift{3-0};
1070   }
1071
1072   def rsr : AsI1<opcod, (outs GPR:$Rd),
1073                (ins GPR:$Rn, so_reg_reg:$shift), DPSoRegRegFrm,
1074                iis, opc, "\t$Rd, $Rn, $shift",
1075                [(set GPR:$Rd, (opnode so_reg_reg:$shift, GPR:$Rn))]> {
1076     bits<4> Rd;
1077     bits<4> Rn;
1078     bits<12> shift;
1079     let Inst{25} = 0;
1080     let Inst{19-16} = Rn;
1081     let Inst{15-12} = Rd;
1082     let Inst{11-8} = shift{11-8};
1083     let Inst{7} = 0;
1084     let Inst{6-5} = shift{6-5};
1085     let Inst{4} = 1;
1086     let Inst{3-0} = shift{3-0};
1087   }
1088
1089   // Assembly aliases for optional destination operand when it's the same
1090   // as the source operand.
1091   def : InstAlias<!strconcat(opc, "${s}${p} $Rdn, $imm"),
1092      (!cast<Instruction>(!strconcat(baseOpc, "ri")) GPR:$Rdn, GPR:$Rdn,
1093                                                     so_imm:$imm, pred:$p,
1094                                                     cc_out:$s)>,
1095      Requires<[IsARM]>;
1096   def : InstAlias<!strconcat(opc, "${s}${p} $Rdn, $Rm"),
1097      (!cast<Instruction>(!strconcat(baseOpc, "rr")) GPR:$Rdn, GPR:$Rdn,
1098                                                     GPR:$Rm, pred:$p,
1099                                                     cc_out:$s)>,
1100      Requires<[IsARM]>;
1101   def : InstAlias<!strconcat(opc, "${s}${p} $Rdn, $shift"),
1102      (!cast<Instruction>(!strconcat(baseOpc, "rsi")) GPR:$Rdn, GPR:$Rdn,
1103                                                     so_reg_imm:$shift, pred:$p,
1104                                                     cc_out:$s)>,
1105      Requires<[IsARM]>;
1106   def : InstAlias<!strconcat(opc, "${s}${p} $Rdn, $shift"),
1107      (!cast<Instruction>(!strconcat(baseOpc, "rsr")) GPR:$Rdn, GPR:$Rdn,
1108                                                     so_reg_reg:$shift, pred:$p,
1109                                                     cc_out:$s)>,
1110      Requires<[IsARM]>;
1111
1112 }
1113
1114 /// AsI1_bin_s_irs - Same as AsI1_bin_irs except it sets the 's' bit by default.
1115 ///
1116 /// These opcodes will be converted to the real non-S opcodes by
1117 /// AdjustInstrPostInstrSelection after giving them an optional CPSR operand.
1118 let hasPostISelHook = 1, Defs = [CPSR] in {
1119 multiclass AsI1_bin_s_irs<InstrItinClass iii, InstrItinClass iir,
1120                           InstrItinClass iis, PatFrag opnode,
1121                           bit Commutable = 0> {
1122   def ri : ARMPseudoInst<(outs GPR:$Rd), (ins GPR:$Rn, so_imm:$imm, pred:$p),
1123                          4, iii,
1124                          [(set GPR:$Rd, CPSR, (opnode GPR:$Rn, so_imm:$imm))]>;
1125
1126   def rr : ARMPseudoInst<(outs GPR:$Rd), (ins GPR:$Rn, GPR:$Rm, pred:$p),
1127                          4, iir,
1128                          [(set GPR:$Rd, CPSR, (opnode GPR:$Rn, GPR:$Rm))]> {
1129     let isCommutable = Commutable;
1130   }
1131   def rsi : ARMPseudoInst<(outs GPR:$Rd),
1132                           (ins GPR:$Rn, so_reg_imm:$shift, pred:$p),
1133                           4, iis,
1134                           [(set GPR:$Rd, CPSR, (opnode GPR:$Rn,
1135                                                 so_reg_imm:$shift))]>;
1136
1137   def rsr : ARMPseudoInst<(outs GPR:$Rd),
1138                           (ins GPR:$Rn, so_reg_reg:$shift, pred:$p),
1139                           4, iis,
1140                           [(set GPR:$Rd, CPSR, (opnode GPR:$Rn,
1141                                                 so_reg_reg:$shift))]>;
1142 }
1143 }
1144
1145 /// AsI1_rbin_s_is - Same as AsI1_bin_s_irs, except selection DAG
1146 /// operands are reversed.
1147 let hasPostISelHook = 1, Defs = [CPSR] in {
1148 multiclass AsI1_rbin_s_is<InstrItinClass iii, InstrItinClass iir,
1149                           InstrItinClass iis, PatFrag opnode,
1150                           bit Commutable = 0> {
1151   def ri : ARMPseudoInst<(outs GPR:$Rd), (ins GPR:$Rn, so_imm:$imm, pred:$p),
1152                          4, iii,
1153                          [(set GPR:$Rd, CPSR, (opnode so_imm:$imm, GPR:$Rn))]>;
1154
1155   def rsi : ARMPseudoInst<(outs GPR:$Rd),
1156                           (ins GPR:$Rn, so_reg_imm:$shift, pred:$p),
1157                           4, iis,
1158                           [(set GPR:$Rd, CPSR, (opnode so_reg_imm:$shift,
1159                                              GPR:$Rn))]>;
1160
1161   def rsr : ARMPseudoInst<(outs GPR:$Rd),
1162                           (ins GPR:$Rn, so_reg_reg:$shift, pred:$p),
1163                           4, iis,
1164                           [(set GPR:$Rd, CPSR, (opnode so_reg_reg:$shift,
1165                                              GPR:$Rn))]>;
1166 }
1167 }
1168
1169 /// AI1_cmp_irs - Defines a set of (op r, {so_imm|r|so_reg}) cmp / test
1170 /// patterns. Similar to AsI1_bin_irs except the instruction does not produce
1171 /// a explicit result, only implicitly set CPSR.
1172 let isCompare = 1, Defs = [CPSR] in {
1173 multiclass AI1_cmp_irs<bits<4> opcod, string opc,
1174                      InstrItinClass iii, InstrItinClass iir, InstrItinClass iis,
1175                        PatFrag opnode, bit Commutable = 0> {
1176   def ri : AI1<opcod, (outs), (ins GPR:$Rn, so_imm:$imm), DPFrm, iii,
1177                opc, "\t$Rn, $imm",
1178                [(opnode GPR:$Rn, so_imm:$imm)]> {
1179     bits<4> Rn;
1180     bits<12> imm;
1181     let Inst{25} = 1;
1182     let Inst{20} = 1;
1183     let Inst{19-16} = Rn;
1184     let Inst{15-12} = 0b0000;
1185     let Inst{11-0} = imm;
1186   }
1187   def rr : AI1<opcod, (outs), (ins GPR:$Rn, GPR:$Rm), DPFrm, iir,
1188                opc, "\t$Rn, $Rm",
1189                [(opnode GPR:$Rn, GPR:$Rm)]> {
1190     bits<4> Rn;
1191     bits<4> Rm;
1192     let isCommutable = Commutable;
1193     let Inst{25} = 0;
1194     let Inst{20} = 1;
1195     let Inst{19-16} = Rn;
1196     let Inst{15-12} = 0b0000;
1197     let Inst{11-4} = 0b00000000;
1198     let Inst{3-0} = Rm;
1199   }
1200   def rsi : AI1<opcod, (outs),
1201                (ins GPR:$Rn, so_reg_imm:$shift), DPSoRegImmFrm, iis,
1202                opc, "\t$Rn, $shift",
1203                [(opnode GPR:$Rn, so_reg_imm:$shift)]> {
1204     bits<4> Rn;
1205     bits<12> shift;
1206     let Inst{25} = 0;
1207     let Inst{20} = 1;
1208     let Inst{19-16} = Rn;
1209     let Inst{15-12} = 0b0000;
1210     let Inst{11-5} = shift{11-5};
1211     let Inst{4} = 0;
1212     let Inst{3-0} = shift{3-0};
1213   }
1214   def rsr : AI1<opcod, (outs),
1215                (ins GPR:$Rn, so_reg_reg:$shift), DPSoRegRegFrm, iis,
1216                opc, "\t$Rn, $shift",
1217                [(opnode GPR:$Rn, so_reg_reg:$shift)]> {
1218     bits<4> Rn;
1219     bits<12> shift;
1220     let Inst{25} = 0;
1221     let Inst{20} = 1;
1222     let Inst{19-16} = Rn;
1223     let Inst{15-12} = 0b0000;
1224     let Inst{11-8} = shift{11-8};
1225     let Inst{7} = 0;
1226     let Inst{6-5} = shift{6-5};
1227     let Inst{4} = 1;
1228     let Inst{3-0} = shift{3-0};
1229   }
1230
1231 }
1232 }
1233
1234 /// AI_ext_rrot - A unary operation with two forms: one whose operand is a
1235 /// register and one whose operand is a register rotated by 8/16/24.
1236 /// FIXME: Remove the 'r' variant. Its rot_imm is zero.
1237 class AI_ext_rrot<bits<8> opcod, string opc, PatFrag opnode>
1238   : AExtI<opcod, (outs GPRnopc:$Rd), (ins GPRnopc:$Rm, rot_imm:$rot),
1239           IIC_iEXTr, opc, "\t$Rd, $Rm$rot",
1240           [(set GPRnopc:$Rd, (opnode (rotr GPRnopc:$Rm, rot_imm:$rot)))]>,
1241        Requires<[IsARM, HasV6]> {
1242   bits<4> Rd;
1243   bits<4> Rm;
1244   bits<2> rot;
1245   let Inst{19-16} = 0b1111;
1246   let Inst{15-12} = Rd;
1247   let Inst{11-10} = rot;
1248   let Inst{3-0}   = Rm;
1249 }
1250
1251 class AI_ext_rrot_np<bits<8> opcod, string opc>
1252   : AExtI<opcod, (outs GPRnopc:$Rd), (ins GPRnopc:$Rm, rot_imm:$rot),
1253           IIC_iEXTr, opc, "\t$Rd, $Rm$rot", []>,
1254        Requires<[IsARM, HasV6]> {
1255   bits<2> rot;
1256   let Inst{19-16} = 0b1111;
1257   let Inst{11-10} = rot;
1258 }
1259
1260 /// AI_exta_rrot - A binary operation with two forms: one whose operand is a
1261 /// register and one whose operand is a register rotated by 8/16/24.
1262 class AI_exta_rrot<bits<8> opcod, string opc, PatFrag opnode>
1263   : AExtI<opcod, (outs GPRnopc:$Rd), (ins GPR:$Rn, GPRnopc:$Rm, rot_imm:$rot),
1264           IIC_iEXTAr, opc, "\t$Rd, $Rn, $Rm$rot",
1265           [(set GPRnopc:$Rd, (opnode GPR:$Rn,
1266                                      (rotr GPRnopc:$Rm, rot_imm:$rot)))]>,
1267         Requires<[IsARM, HasV6]> {
1268   bits<4> Rd;
1269   bits<4> Rm;
1270   bits<4> Rn;
1271   bits<2> rot;
1272   let Inst{19-16} = Rn;
1273   let Inst{15-12} = Rd;
1274   let Inst{11-10} = rot;
1275   let Inst{9-4}   = 0b000111;
1276   let Inst{3-0}   = Rm;
1277 }
1278
1279 class AI_exta_rrot_np<bits<8> opcod, string opc>
1280   : AExtI<opcod, (outs GPRnopc:$Rd), (ins GPR:$Rn, GPRnopc:$Rm, rot_imm:$rot),
1281           IIC_iEXTAr, opc, "\t$Rd, $Rn, $Rm$rot", []>,
1282        Requires<[IsARM, HasV6]> {
1283   bits<4> Rn;
1284   bits<2> rot;
1285   let Inst{19-16} = Rn;
1286   let Inst{11-10} = rot;
1287 }
1288
1289 /// AI1_adde_sube_irs - Define instructions and patterns for adde and sube.
1290 multiclass AI1_adde_sube_irs<bits<4> opcod, string opc, PatFrag opnode,
1291                              string baseOpc, bit Commutable = 0> {
1292   let hasPostISelHook = 1, Defs = [CPSR], Uses = [CPSR] in {
1293   def ri : AsI1<opcod, (outs GPR:$Rd), (ins GPR:$Rn, so_imm:$imm),
1294                 DPFrm, IIC_iALUi, opc, "\t$Rd, $Rn, $imm",
1295                [(set GPR:$Rd, CPSR, (opnode GPR:$Rn, so_imm:$imm, CPSR))]>,
1296                Requires<[IsARM]> {
1297     bits<4> Rd;
1298     bits<4> Rn;
1299     bits<12> imm;
1300     let Inst{25} = 1;
1301     let Inst{15-12} = Rd;
1302     let Inst{19-16} = Rn;
1303     let Inst{11-0} = imm;
1304   }
1305   def rr : AsI1<opcod, (outs GPR:$Rd), (ins GPR:$Rn, GPR:$Rm),
1306                 DPFrm, IIC_iALUr, opc, "\t$Rd, $Rn, $Rm",
1307                [(set GPR:$Rd, CPSR, (opnode GPR:$Rn, GPR:$Rm, CPSR))]>,
1308                Requires<[IsARM]> {
1309     bits<4> Rd;
1310     bits<4> Rn;
1311     bits<4> Rm;
1312     let Inst{11-4} = 0b00000000;
1313     let Inst{25} = 0;
1314     let isCommutable = Commutable;
1315     let Inst{3-0} = Rm;
1316     let Inst{15-12} = Rd;
1317     let Inst{19-16} = Rn;
1318   }
1319   def rsi : AsI1<opcod, (outs GPR:$Rd),
1320                 (ins GPR:$Rn, so_reg_imm:$shift),
1321                 DPSoRegImmFrm, IIC_iALUsr, opc, "\t$Rd, $Rn, $shift",
1322               [(set GPR:$Rd, CPSR, (opnode GPR:$Rn, so_reg_imm:$shift, CPSR))]>,
1323                Requires<[IsARM]> {
1324     bits<4> Rd;
1325     bits<4> Rn;
1326     bits<12> shift;
1327     let Inst{25} = 0;
1328     let Inst{19-16} = Rn;
1329     let Inst{15-12} = Rd;
1330     let Inst{11-5} = shift{11-5};
1331     let Inst{4} = 0;
1332     let Inst{3-0} = shift{3-0};
1333   }
1334   def rsr : AsI1<opcod, (outs GPRnopc:$Rd),
1335                 (ins GPRnopc:$Rn, so_reg_reg:$shift),
1336                 DPSoRegRegFrm, IIC_iALUsr, opc, "\t$Rd, $Rn, $shift",
1337               [(set GPRnopc:$Rd, CPSR, (opnode GPRnopc:$Rn, so_reg_reg:$shift, CPSR))]>,
1338                Requires<[IsARM]> {
1339     bits<4> Rd;
1340     bits<4> Rn;
1341     bits<12> shift;
1342     let Inst{25} = 0;
1343     let Inst{19-16} = Rn;
1344     let Inst{15-12} = Rd;
1345     let Inst{11-8} = shift{11-8};
1346     let Inst{7} = 0;
1347     let Inst{6-5} = shift{6-5};
1348     let Inst{4} = 1;
1349     let Inst{3-0} = shift{3-0};
1350   }
1351   }
1352
1353   // Assembly aliases for optional destination operand when it's the same
1354   // as the source operand.
1355   def : InstAlias<!strconcat(opc, "${s}${p} $Rdn, $imm"),
1356      (!cast<Instruction>(!strconcat(baseOpc, "ri")) GPR:$Rdn, GPR:$Rdn,
1357                                                     so_imm:$imm, pred:$p,
1358                                                     cc_out:$s)>,
1359      Requires<[IsARM]>;
1360   def : InstAlias<!strconcat(opc, "${s}${p} $Rdn, $Rm"),
1361      (!cast<Instruction>(!strconcat(baseOpc, "rr")) GPR:$Rdn, GPR:$Rdn,
1362                                                     GPR:$Rm, pred:$p,
1363                                                     cc_out:$s)>,
1364      Requires<[IsARM]>;
1365   def : InstAlias<!strconcat(opc, "${s}${p} $Rdn, $shift"),
1366      (!cast<Instruction>(!strconcat(baseOpc, "rsi")) GPR:$Rdn, GPR:$Rdn,
1367                                                     so_reg_imm:$shift, pred:$p,
1368                                                     cc_out:$s)>,
1369      Requires<[IsARM]>;
1370   def : InstAlias<!strconcat(opc, "${s}${p} $Rdn, $shift"),
1371      (!cast<Instruction>(!strconcat(baseOpc, "rsr")) GPRnopc:$Rdn, GPRnopc:$Rdn,
1372                                                     so_reg_reg:$shift, pred:$p,
1373                                                     cc_out:$s)>,
1374      Requires<[IsARM]>;
1375 }
1376
1377 /// AI1_rsc_irs - Define instructions and patterns for rsc
1378 multiclass AI1_rsc_irs<bits<4> opcod, string opc, PatFrag opnode,
1379                        string baseOpc> {
1380   let hasPostISelHook = 1, Defs = [CPSR], Uses = [CPSR] in {
1381   def ri : AsI1<opcod, (outs GPR:$Rd), (ins GPR:$Rn, so_imm:$imm),
1382                 DPFrm, IIC_iALUi, opc, "\t$Rd, $Rn, $imm",
1383                [(set GPR:$Rd, CPSR, (opnode so_imm:$imm, GPR:$Rn, CPSR))]>,
1384                Requires<[IsARM]> {
1385     bits<4> Rd;
1386     bits<4> Rn;
1387     bits<12> imm;
1388     let Inst{25} = 1;
1389     let Inst{15-12} = Rd;
1390     let Inst{19-16} = Rn;
1391     let Inst{11-0} = imm;
1392   }
1393   def rr : AsI1<opcod, (outs GPR:$Rd), (ins GPR:$Rn, GPR:$Rm),
1394                 DPFrm, IIC_iALUr, opc, "\t$Rd, $Rn, $Rm",
1395                [/* pattern left blank */]> {
1396     bits<4> Rd;
1397     bits<4> Rn;
1398     bits<4> Rm;
1399     let Inst{11-4} = 0b00000000;
1400     let Inst{25} = 0;
1401     let Inst{3-0} = Rm;
1402     let Inst{15-12} = Rd;
1403     let Inst{19-16} = Rn;
1404   }
1405   def rsi : AsI1<opcod, (outs GPR:$Rd), (ins GPR:$Rn, so_reg_imm:$shift),
1406                 DPSoRegImmFrm, IIC_iALUsr, opc, "\t$Rd, $Rn, $shift",
1407               [(set GPR:$Rd, CPSR, (opnode so_reg_imm:$shift, GPR:$Rn, CPSR))]>,
1408                Requires<[IsARM]> {
1409     bits<4> Rd;
1410     bits<4> Rn;
1411     bits<12> shift;
1412     let Inst{25} = 0;
1413     let Inst{19-16} = Rn;
1414     let Inst{15-12} = Rd;
1415     let Inst{11-5} = shift{11-5};
1416     let Inst{4} = 0;
1417     let Inst{3-0} = shift{3-0};
1418   }
1419   def rsr : AsI1<opcod, (outs GPR:$Rd), (ins GPR:$Rn, so_reg_reg:$shift),
1420                 DPSoRegRegFrm, IIC_iALUsr, opc, "\t$Rd, $Rn, $shift",
1421               [(set GPR:$Rd, CPSR, (opnode so_reg_reg:$shift, GPR:$Rn, CPSR))]>,
1422                Requires<[IsARM]> {
1423     bits<4> Rd;
1424     bits<4> Rn;
1425     bits<12> shift;
1426     let Inst{25} = 0;
1427     let Inst{19-16} = Rn;
1428     let Inst{15-12} = Rd;
1429     let Inst{11-8} = shift{11-8};
1430     let Inst{7} = 0;
1431     let Inst{6-5} = shift{6-5};
1432     let Inst{4} = 1;
1433     let Inst{3-0} = shift{3-0};
1434   }
1435   }
1436
1437   // Assembly aliases for optional destination operand when it's the same
1438   // as the source operand.
1439   def : InstAlias<!strconcat(opc, "${s}${p} $Rdn, $imm"),
1440      (!cast<Instruction>(!strconcat(baseOpc, "ri")) GPR:$Rdn, GPR:$Rdn,
1441                                                     so_imm:$imm, pred:$p,
1442                                                     cc_out:$s)>,
1443      Requires<[IsARM]>;
1444   def : InstAlias<!strconcat(opc, "${s}${p} $Rdn, $Rm"),
1445      (!cast<Instruction>(!strconcat(baseOpc, "rr")) GPR:$Rdn, GPR:$Rdn,
1446                                                     GPR:$Rm, pred:$p,
1447                                                     cc_out:$s)>,
1448      Requires<[IsARM]>;
1449   def : InstAlias<!strconcat(opc, "${s}${p} $Rdn, $shift"),
1450      (!cast<Instruction>(!strconcat(baseOpc, "rsi")) GPR:$Rdn, GPR:$Rdn,
1451                                                     so_reg_imm:$shift, pred:$p,
1452                                                     cc_out:$s)>,
1453      Requires<[IsARM]>;
1454   def : InstAlias<!strconcat(opc, "${s}${p} $Rdn, $shift"),
1455      (!cast<Instruction>(!strconcat(baseOpc, "rsr")) GPR:$Rdn, GPR:$Rdn,
1456                                                     so_reg_reg:$shift, pred:$p,
1457                                                     cc_out:$s)>,
1458      Requires<[IsARM]>;
1459 }
1460
1461 let canFoldAsLoad = 1, isReMaterializable = 1 in {
1462 multiclass AI_ldr1<bit isByte, string opc, InstrItinClass iii,
1463            InstrItinClass iir, PatFrag opnode> {
1464   // Note: We use the complex addrmode_imm12 rather than just an input
1465   // GPR and a constrained immediate so that we can use this to match
1466   // frame index references and avoid matching constant pool references.
1467   def i12: AI2ldst<0b010, 1, isByte, (outs GPR:$Rt), (ins addrmode_imm12:$addr),
1468                    AddrMode_i12, LdFrm, iii, opc, "\t$Rt, $addr",
1469                   [(set GPR:$Rt, (opnode addrmode_imm12:$addr))]> {
1470     bits<4>  Rt;
1471     bits<17> addr;
1472     let Inst{23}    = addr{12};     // U (add = ('U' == 1))
1473     let Inst{19-16} = addr{16-13};  // Rn
1474     let Inst{15-12} = Rt;
1475     let Inst{11-0}  = addr{11-0};   // imm12
1476   }
1477   def rs : AI2ldst<0b011, 1, isByte, (outs GPR:$Rt), (ins ldst_so_reg:$shift),
1478                   AddrModeNone, LdFrm, iir, opc, "\t$Rt, $shift",
1479                  [(set GPR:$Rt, (opnode ldst_so_reg:$shift))]> {
1480     bits<4>  Rt;
1481     bits<17> shift;
1482     let shift{4}    = 0;            // Inst{4} = 0
1483     let Inst{23}    = shift{12};    // U (add = ('U' == 1))
1484     let Inst{19-16} = shift{16-13}; // Rn
1485     let Inst{15-12} = Rt;
1486     let Inst{11-0}  = shift{11-0};
1487   }
1488 }
1489 }
1490
1491 let canFoldAsLoad = 1, isReMaterializable = 1 in {
1492 multiclass AI_ldr1nopc<bit isByte, string opc, InstrItinClass iii,
1493            InstrItinClass iir, PatFrag opnode> {
1494   // Note: We use the complex addrmode_imm12 rather than just an input
1495   // GPR and a constrained immediate so that we can use this to match
1496   // frame index references and avoid matching constant pool references.
1497   def i12: AI2ldst<0b010, 1, isByte, (outs GPRnopc:$Rt), (ins addrmode_imm12:$addr),
1498                    AddrMode_i12, LdFrm, iii, opc, "\t$Rt, $addr",
1499                   [(set GPRnopc:$Rt, (opnode addrmode_imm12:$addr))]> {
1500     bits<4>  Rt;
1501     bits<17> addr;
1502     let Inst{23}    = addr{12};     // U (add = ('U' == 1))
1503     let Inst{19-16} = addr{16-13};  // Rn
1504     let Inst{15-12} = Rt;
1505     let Inst{11-0}  = addr{11-0};   // imm12
1506   }
1507   def rs : AI2ldst<0b011, 1, isByte, (outs GPRnopc:$Rt), (ins ldst_so_reg:$shift),
1508                   AddrModeNone, LdFrm, iir, opc, "\t$Rt, $shift",
1509                  [(set GPRnopc:$Rt, (opnode ldst_so_reg:$shift))]> {
1510     bits<4>  Rt;
1511     bits<17> shift;
1512     let shift{4}    = 0;            // Inst{4} = 0
1513     let Inst{23}    = shift{12};    // U (add = ('U' == 1))
1514     let Inst{19-16} = shift{16-13}; // Rn
1515     let Inst{15-12} = Rt;
1516     let Inst{11-0}  = shift{11-0};
1517   }
1518 }
1519 }
1520
1521
1522 multiclass AI_str1<bit isByte, string opc, InstrItinClass iii,
1523            InstrItinClass iir, PatFrag opnode> {
1524   // Note: We use the complex addrmode_imm12 rather than just an input
1525   // GPR and a constrained immediate so that we can use this to match
1526   // frame index references and avoid matching constant pool references.
1527   def i12 : AI2ldst<0b010, 0, isByte, (outs),
1528                    (ins GPR:$Rt, addrmode_imm12:$addr),
1529                    AddrMode_i12, StFrm, iii, opc, "\t$Rt, $addr",
1530                   [(opnode GPR:$Rt, addrmode_imm12:$addr)]> {
1531     bits<4> Rt;
1532     bits<17> addr;
1533     let Inst{23}    = addr{12};     // U (add = ('U' == 1))
1534     let Inst{19-16} = addr{16-13};  // Rn
1535     let Inst{15-12} = Rt;
1536     let Inst{11-0}  = addr{11-0};   // imm12
1537   }
1538   def rs : AI2ldst<0b011, 0, isByte, (outs), (ins GPR:$Rt, ldst_so_reg:$shift),
1539                   AddrModeNone, StFrm, iir, opc, "\t$Rt, $shift",
1540                  [(opnode GPR:$Rt, ldst_so_reg:$shift)]> {
1541     bits<4> Rt;
1542     bits<17> shift;
1543     let shift{4}    = 0;            // Inst{4} = 0
1544     let Inst{23}    = shift{12};    // U (add = ('U' == 1))
1545     let Inst{19-16} = shift{16-13}; // Rn
1546     let Inst{15-12} = Rt;
1547     let Inst{11-0}  = shift{11-0};
1548   }
1549 }
1550
1551 multiclass AI_str1nopc<bit isByte, string opc, InstrItinClass iii,
1552            InstrItinClass iir, PatFrag opnode> {
1553   // Note: We use the complex addrmode_imm12 rather than just an input
1554   // GPR and a constrained immediate so that we can use this to match
1555   // frame index references and avoid matching constant pool references.
1556   def i12 : AI2ldst<0b010, 0, isByte, (outs),
1557                    (ins GPRnopc:$Rt, addrmode_imm12:$addr),
1558                    AddrMode_i12, StFrm, iii, opc, "\t$Rt, $addr",
1559                   [(opnode GPRnopc:$Rt, addrmode_imm12:$addr)]> {
1560     bits<4> Rt;
1561     bits<17> addr;
1562     let Inst{23}    = addr{12};     // U (add = ('U' == 1))
1563     let Inst{19-16} = addr{16-13};  // Rn
1564     let Inst{15-12} = Rt;
1565     let Inst{11-0}  = addr{11-0};   // imm12
1566   }
1567   def rs : AI2ldst<0b011, 0, isByte, (outs), (ins GPRnopc:$Rt, ldst_so_reg:$shift),
1568                   AddrModeNone, StFrm, iir, opc, "\t$Rt, $shift",
1569                  [(opnode GPRnopc:$Rt, ldst_so_reg:$shift)]> {
1570     bits<4> Rt;
1571     bits<17> shift;
1572     let shift{4}    = 0;            // Inst{4} = 0
1573     let Inst{23}    = shift{12};    // U (add = ('U' == 1))
1574     let Inst{19-16} = shift{16-13}; // Rn
1575     let Inst{15-12} = Rt;
1576     let Inst{11-0}  = shift{11-0};
1577   }
1578 }
1579
1580
1581 //===----------------------------------------------------------------------===//
1582 // Instructions
1583 //===----------------------------------------------------------------------===//
1584
1585 //===----------------------------------------------------------------------===//
1586 //  Miscellaneous Instructions.
1587 //
1588
1589 /// CONSTPOOL_ENTRY - This instruction represents a floating constant pool in
1590 /// the function.  The first operand is the ID# for this instruction, the second
1591 /// is the index into the MachineConstantPool that this is, the third is the
1592 /// size in bytes of this constant pool entry.
1593 let neverHasSideEffects = 1, isNotDuplicable = 1 in
1594 def CONSTPOOL_ENTRY :
1595 PseudoInst<(outs), (ins cpinst_operand:$instid, cpinst_operand:$cpidx,
1596                     i32imm:$size), NoItinerary, []>;
1597
1598 // FIXME: Marking these as hasSideEffects is necessary to prevent machine DCE
1599 // from removing one half of the matched pairs. That breaks PEI, which assumes
1600 // these will always be in pairs, and asserts if it finds otherwise. Better way?
1601 let Defs = [SP], Uses = [SP], hasSideEffects = 1 in {
1602 def ADJCALLSTACKUP :
1603 PseudoInst<(outs), (ins i32imm:$amt1, i32imm:$amt2, pred:$p), NoItinerary,
1604            [(ARMcallseq_end timm:$amt1, timm:$amt2)]>;
1605
1606 def ADJCALLSTACKDOWN :
1607 PseudoInst<(outs), (ins i32imm:$amt, pred:$p), NoItinerary,
1608            [(ARMcallseq_start timm:$amt)]>;
1609 }
1610
1611 // Atomic pseudo-insts which will be lowered to ldrexd/strexd loops.
1612 // (These pseudos use a hand-written selection code).
1613 let usesCustomInserter = 1, Defs = [CPSR], mayLoad = 1, mayStore = 1 in {
1614 def ATOMOR6432   : PseudoInst<(outs GPR:$dst1, GPR:$dst2),
1615                               (ins GPR:$addr, GPR:$src1, GPR:$src2),
1616                               NoItinerary, []>;
1617 def ATOMXOR6432  : PseudoInst<(outs GPR:$dst1, GPR:$dst2),
1618                               (ins GPR:$addr, GPR:$src1, GPR:$src2),
1619                               NoItinerary, []>;
1620 def ATOMADD6432  : PseudoInst<(outs GPR:$dst1, GPR:$dst2),
1621                               (ins GPR:$addr, GPR:$src1, GPR:$src2),
1622                               NoItinerary, []>;
1623 def ATOMSUB6432  : PseudoInst<(outs GPR:$dst1, GPR:$dst2),
1624                               (ins GPR:$addr, GPR:$src1, GPR:$src2),
1625                               NoItinerary, []>;
1626 def ATOMNAND6432 : PseudoInst<(outs GPR:$dst1, GPR:$dst2),
1627                               (ins GPR:$addr, GPR:$src1, GPR:$src2),
1628                               NoItinerary, []>;
1629 def ATOMAND6432  : PseudoInst<(outs GPR:$dst1, GPR:$dst2),
1630                               (ins GPR:$addr, GPR:$src1, GPR:$src2),
1631                               NoItinerary, []>;
1632 def ATOMSWAP6432 : PseudoInst<(outs GPR:$dst1, GPR:$dst2),
1633                               (ins GPR:$addr, GPR:$src1, GPR:$src2),
1634                               NoItinerary, []>;
1635 def ATOMCMPXCHG6432 : PseudoInst<(outs GPR:$dst1, GPR:$dst2),
1636                                  (ins GPR:$addr, GPR:$cmp1, GPR:$cmp2,
1637                                       GPR:$set1, GPR:$set2),
1638                                  NoItinerary, []>;
1639 }
1640
1641 def NOP : AI<(outs), (ins), MiscFrm, NoItinerary, "nop", "", []>,
1642           Requires<[IsARM, HasV6T2]> {
1643   let Inst{27-16} = 0b001100100000;
1644   let Inst{15-8} = 0b11110000;
1645   let Inst{7-0} = 0b00000000;
1646 }
1647
1648 def YIELD : AI<(outs), (ins), MiscFrm, NoItinerary, "yield", "", []>,
1649           Requires<[IsARM, HasV6T2]> {
1650   let Inst{27-16} = 0b001100100000;
1651   let Inst{15-8} = 0b11110000;
1652   let Inst{7-0} = 0b00000001;
1653 }
1654
1655 def WFE : AI<(outs), (ins), MiscFrm, NoItinerary, "wfe", "", []>,
1656           Requires<[IsARM, HasV6T2]> {
1657   let Inst{27-16} = 0b001100100000;
1658   let Inst{15-8} = 0b11110000;
1659   let Inst{7-0} = 0b00000010;
1660 }
1661
1662 def WFI : AI<(outs), (ins), MiscFrm, NoItinerary, "wfi", "", []>,
1663           Requires<[IsARM, HasV6T2]> {
1664   let Inst{27-16} = 0b001100100000;
1665   let Inst{15-8} = 0b11110000;
1666   let Inst{7-0} = 0b00000011;
1667 }
1668
1669 def SEL : AI<(outs GPR:$Rd), (ins GPR:$Rn, GPR:$Rm), DPFrm, NoItinerary, "sel",
1670              "\t$Rd, $Rn, $Rm", []>, Requires<[IsARM, HasV6]> {
1671   bits<4> Rd;
1672   bits<4> Rn;
1673   bits<4> Rm;
1674   let Inst{3-0} = Rm;
1675   let Inst{15-12} = Rd;
1676   let Inst{19-16} = Rn;
1677   let Inst{27-20} = 0b01101000;
1678   let Inst{7-4} = 0b1011;
1679   let Inst{11-8} = 0b1111;
1680 }
1681
1682 def SEV : AI<(outs), (ins), MiscFrm, NoItinerary, "sev", "",
1683              []>, Requires<[IsARM, HasV6T2]> {
1684   let Inst{27-16} = 0b001100100000;
1685   let Inst{15-8} = 0b11110000;
1686   let Inst{7-0} = 0b00000100;
1687 }
1688
1689 // The i32imm operand $val can be used by a debugger to store more information
1690 // about the breakpoint.
1691 def BKPT : AI<(outs), (ins imm0_65535:$val), MiscFrm, NoItinerary,
1692               "bkpt", "\t$val", []>, Requires<[IsARM]> {
1693   bits<16> val;
1694   let Inst{3-0} = val{3-0};
1695   let Inst{19-8} = val{15-4};
1696   let Inst{27-20} = 0b00010010;
1697   let Inst{7-4} = 0b0111;
1698 }
1699
1700 // Change Processor State
1701 // FIXME: We should use InstAlias to handle the optional operands.
1702 class CPS<dag iops, string asm_ops>
1703   : AXI<(outs), iops, MiscFrm, NoItinerary, !strconcat("cps", asm_ops),
1704         []>, Requires<[IsARM]> {
1705   bits<2> imod;
1706   bits<3> iflags;
1707   bits<5> mode;
1708   bit M;
1709
1710   let Inst{31-28} = 0b1111;
1711   let Inst{27-20} = 0b00010000;
1712   let Inst{19-18} = imod;
1713   let Inst{17}    = M; // Enabled if mode is set;
1714   let Inst{16-9}  = 0b00000000;
1715   let Inst{8-6}   = iflags;
1716   let Inst{5}     = 0;
1717   let Inst{4-0}   = mode;
1718 }
1719
1720 let DecoderMethod = "DecodeCPSInstruction" in {
1721 let M = 1 in
1722   def CPS3p : CPS<(ins imod_op:$imod, iflags_op:$iflags, imm0_31:$mode),
1723                   "$imod\t$iflags, $mode">;
1724 let mode = 0, M = 0 in
1725   def CPS2p : CPS<(ins imod_op:$imod, iflags_op:$iflags), "$imod\t$iflags">;
1726
1727 let imod = 0, iflags = 0, M = 1 in
1728   def CPS1p : CPS<(ins imm0_31:$mode), "\t$mode">;
1729 }
1730
1731 // Preload signals the memory system of possible future data/instruction access.
1732 multiclass APreLoad<bits<1> read, bits<1> data, string opc> {
1733
1734   def i12 : AXI<(outs), (ins addrmode_imm12:$addr), MiscFrm, IIC_Preload,
1735                 !strconcat(opc, "\t$addr"),
1736                 [(ARMPreload addrmode_imm12:$addr, (i32 read), (i32 data))]> {
1737     bits<4> Rt;
1738     bits<17> addr;
1739     let Inst{31-26} = 0b111101;
1740     let Inst{25} = 0; // 0 for immediate form
1741     let Inst{24} = data;
1742     let Inst{23} = addr{12};        // U (add = ('U' == 1))
1743     let Inst{22} = read;
1744     let Inst{21-20} = 0b01;
1745     let Inst{19-16} = addr{16-13};  // Rn
1746     let Inst{15-12} = 0b1111;
1747     let Inst{11-0}  = addr{11-0};   // imm12
1748   }
1749
1750   def rs : AXI<(outs), (ins ldst_so_reg:$shift), MiscFrm, IIC_Preload,
1751                !strconcat(opc, "\t$shift"),
1752                [(ARMPreload ldst_so_reg:$shift, (i32 read), (i32 data))]> {
1753     bits<17> shift;
1754     let Inst{31-26} = 0b111101;
1755     let Inst{25} = 1; // 1 for register form
1756     let Inst{24} = data;
1757     let Inst{23} = shift{12};    // U (add = ('U' == 1))
1758     let Inst{22} = read;
1759     let Inst{21-20} = 0b01;
1760     let Inst{19-16} = shift{16-13}; // Rn
1761     let Inst{15-12} = 0b1111;
1762     let Inst{11-0}  = shift{11-0};
1763     let Inst{4} = 0;
1764   }
1765 }
1766
1767 defm PLD  : APreLoad<1, 1, "pld">,  Requires<[IsARM]>;
1768 defm PLDW : APreLoad<0, 1, "pldw">, Requires<[IsARM,HasV7,HasMP]>;
1769 defm PLI  : APreLoad<1, 0, "pli">,  Requires<[IsARM,HasV7]>;
1770
1771 def SETEND : AXI<(outs), (ins setend_op:$end), MiscFrm, NoItinerary,
1772                  "setend\t$end", []>, Requires<[IsARM]> {
1773   bits<1> end;
1774   let Inst{31-10} = 0b1111000100000001000000;
1775   let Inst{9} = end;
1776   let Inst{8-0} = 0;
1777 }
1778
1779 def DBG : AI<(outs), (ins imm0_15:$opt), MiscFrm, NoItinerary, "dbg", "\t$opt",
1780              []>, Requires<[IsARM, HasV7]> {
1781   bits<4> opt;
1782   let Inst{27-4} = 0b001100100000111100001111;
1783   let Inst{3-0} = opt;
1784 }
1785
1786 // A5.4 Permanently UNDEFINED instructions.
1787 let isBarrier = 1, isTerminator = 1 in
1788 def TRAP : AXI<(outs), (ins), MiscFrm, NoItinerary,
1789                "trap", [(trap)]>,
1790            Requires<[IsARM]> {
1791   let Inst = 0xe7ffdefe;
1792 }
1793
1794 // Address computation and loads and stores in PIC mode.
1795 let isNotDuplicable = 1 in {
1796 def PICADD  : ARMPseudoInst<(outs GPR:$dst), (ins GPR:$a, pclabel:$cp, pred:$p),
1797                             4, IIC_iALUr,
1798                             [(set GPR:$dst, (ARMpic_add GPR:$a, imm:$cp))]>;
1799
1800 let AddedComplexity = 10 in {
1801 def PICLDR  : ARMPseudoInst<(outs GPR:$dst), (ins addrmodepc:$addr, pred:$p),
1802                             4, IIC_iLoad_r,
1803                             [(set GPR:$dst, (load addrmodepc:$addr))]>;
1804
1805 def PICLDRH : ARMPseudoInst<(outs GPR:$Rt), (ins addrmodepc:$addr, pred:$p),
1806                             4, IIC_iLoad_bh_r,
1807                             [(set GPR:$Rt, (zextloadi16 addrmodepc:$addr))]>;
1808
1809 def PICLDRB : ARMPseudoInst<(outs GPR:$Rt), (ins addrmodepc:$addr, pred:$p),
1810                             4, IIC_iLoad_bh_r,
1811                             [(set GPR:$Rt, (zextloadi8 addrmodepc:$addr))]>;
1812
1813 def PICLDRSH : ARMPseudoInst<(outs GPR:$Rt), (ins addrmodepc:$addr, pred:$p),
1814                             4, IIC_iLoad_bh_r,
1815                             [(set GPR:$Rt, (sextloadi16 addrmodepc:$addr))]>;
1816
1817 def PICLDRSB : ARMPseudoInst<(outs GPR:$Rt), (ins addrmodepc:$addr, pred:$p),
1818                             4, IIC_iLoad_bh_r,
1819                             [(set GPR:$Rt, (sextloadi8 addrmodepc:$addr))]>;
1820 }
1821 let AddedComplexity = 10 in {
1822 def PICSTR  : ARMPseudoInst<(outs), (ins GPR:$src, addrmodepc:$addr, pred:$p),
1823       4, IIC_iStore_r, [(store GPR:$src, addrmodepc:$addr)]>;
1824
1825 def PICSTRH : ARMPseudoInst<(outs), (ins GPR:$src, addrmodepc:$addr, pred:$p),
1826       4, IIC_iStore_bh_r, [(truncstorei16 GPR:$src,
1827                                                    addrmodepc:$addr)]>;
1828
1829 def PICSTRB : ARMPseudoInst<(outs), (ins GPR:$src, addrmodepc:$addr, pred:$p),
1830       4, IIC_iStore_bh_r, [(truncstorei8 GPR:$src, addrmodepc:$addr)]>;
1831 }
1832 } // isNotDuplicable = 1
1833
1834
1835 // LEApcrel - Load a pc-relative address into a register without offending the
1836 // assembler.
1837 let neverHasSideEffects = 1, isReMaterializable = 1 in
1838 // The 'adr' mnemonic encodes differently if the label is before or after
1839 // the instruction. The {24-21} opcode bits are set by the fixup, as we don't
1840 // know until then which form of the instruction will be used.
1841 def ADR : AI1<{0,?,?,0}, (outs GPR:$Rd), (ins adrlabel:$label),
1842                  MiscFrm, IIC_iALUi, "adr", "\t$Rd, $label", []> {
1843   bits<4> Rd;
1844   bits<14> label;
1845   let Inst{27-25} = 0b001;
1846   let Inst{24} = 0;
1847   let Inst{23-22} = label{13-12};
1848   let Inst{21} = 0;
1849   let Inst{20} = 0;
1850   let Inst{19-16} = 0b1111;
1851   let Inst{15-12} = Rd;
1852   let Inst{11-0} = label{11-0};
1853 }
1854 def LEApcrel : ARMPseudoInst<(outs GPR:$Rd), (ins i32imm:$label, pred:$p),
1855                     4, IIC_iALUi, []>;
1856
1857 def LEApcrelJT : ARMPseudoInst<(outs GPR:$Rd),
1858                       (ins i32imm:$label, nohash_imm:$id, pred:$p),
1859                       4, IIC_iALUi, []>;
1860
1861 //===----------------------------------------------------------------------===//
1862 //  Control Flow Instructions.
1863 //
1864
1865 let isReturn = 1, isTerminator = 1, isBarrier = 1 in {
1866   // ARMV4T and above
1867   def BX_RET : AI<(outs), (ins), BrMiscFrm, IIC_Br,
1868                   "bx", "\tlr", [(ARMretflag)]>,
1869                Requires<[IsARM, HasV4T]> {
1870     let Inst{27-0}  = 0b0001001011111111111100011110;
1871   }
1872
1873   // ARMV4 only
1874   def MOVPCLR : AI<(outs), (ins), BrMiscFrm, IIC_Br,
1875                   "mov", "\tpc, lr", [(ARMretflag)]>,
1876                Requires<[IsARM, NoV4T]> {
1877     let Inst{27-0} = 0b0001101000001111000000001110;
1878   }
1879 }
1880
1881 // Indirect branches
1882 let isBranch = 1, isTerminator = 1, isBarrier = 1, isIndirectBranch = 1 in {
1883   // ARMV4T and above
1884   def BX : AXI<(outs), (ins GPR:$dst), BrMiscFrm, IIC_Br, "bx\t$dst",
1885                   [(brind GPR:$dst)]>,
1886               Requires<[IsARM, HasV4T]> {
1887     bits<4> dst;
1888     let Inst{31-4} = 0b1110000100101111111111110001;
1889     let Inst{3-0}  = dst;
1890   }
1891
1892   def BX_pred : AI<(outs), (ins GPR:$dst), BrMiscFrm, IIC_Br,
1893                   "bx", "\t$dst", [/* pattern left blank */]>,
1894               Requires<[IsARM, HasV4T]> {
1895     bits<4> dst;
1896     let Inst{27-4} = 0b000100101111111111110001;
1897     let Inst{3-0}  = dst;
1898   }
1899 }
1900
1901 // SP is marked as a use to prevent stack-pointer assignments that appear
1902 // immediately before calls from potentially appearing dead.
1903 let isCall = 1,
1904   // FIXME:  Do we really need a non-predicated version? If so, it should
1905   // at least be a pseudo instruction expanding to the predicated version
1906   // at MC lowering time.
1907   Defs = [LR], Uses = [SP] in {
1908   def BL  : ABXI<0b1011, (outs), (ins bl_target:$func, variable_ops),
1909                 IIC_Br, "bl\t$func",
1910                 [(ARMcall tglobaladdr:$func)]>,
1911             Requires<[IsARM]> {
1912     let Inst{31-28} = 0b1110;
1913     bits<24> func;
1914     let Inst{23-0} = func;
1915     let DecoderMethod = "DecodeBranchImmInstruction";
1916   }
1917
1918   def BL_pred : ABI<0b1011, (outs), (ins bl_target:$func, variable_ops),
1919                    IIC_Br, "bl", "\t$func",
1920                    [(ARMcall_pred tglobaladdr:$func)]>,
1921                 Requires<[IsARM]> {
1922     bits<24> func;
1923     let Inst{23-0} = func;
1924     let DecoderMethod = "DecodeBranchImmInstruction";
1925   }
1926
1927   // ARMv5T and above
1928   def BLX : AXI<(outs), (ins GPR:$func, variable_ops), BrMiscFrm,
1929                 IIC_Br, "blx\t$func",
1930                 [(ARMcall GPR:$func)]>,
1931             Requires<[IsARM, HasV5T]> {
1932     bits<4> func;
1933     let Inst{31-4} = 0b1110000100101111111111110011;
1934     let Inst{3-0}  = func;
1935   }
1936
1937   def BLX_pred : AI<(outs), (ins GPR:$func, variable_ops), BrMiscFrm,
1938                     IIC_Br, "blx", "\t$func",
1939                     [(ARMcall_pred GPR:$func)]>,
1940                  Requires<[IsARM, HasV5T]> {
1941     bits<4> func;
1942     let Inst{27-4} = 0b000100101111111111110011;
1943     let Inst{3-0}  = func;
1944   }
1945
1946   // ARMv4T
1947   // Note: Restrict $func to the tGPR regclass to prevent it being in LR.
1948   def BX_CALL : ARMPseudoInst<(outs), (ins tGPR:$func, variable_ops),
1949                    8, IIC_Br, [(ARMcall_nolink tGPR:$func)]>,
1950                    Requires<[IsARM, HasV4T]>;
1951
1952   // ARMv4
1953   def BMOVPCRX_CALL : ARMPseudoInst<(outs), (ins tGPR:$func, variable_ops),
1954                    8, IIC_Br, [(ARMcall_nolink tGPR:$func)]>,
1955                    Requires<[IsARM, NoV4T]>;
1956
1957   // mov lr, pc; b if callee is marked noreturn to avoid confusing the
1958   // return stack predictor.
1959   def BMOVPCB_CALL : ARMPseudoInst<(outs),
1960                                    (ins bl_target:$func, variable_ops),
1961                                8, IIC_Br, [(ARMcall_nolink tglobaladdr:$func)]>,
1962                       Requires<[IsARM]>;
1963 }
1964
1965 let isBranch = 1, isTerminator = 1 in {
1966   // FIXME: should be able to write a pattern for ARMBrcond, but can't use
1967   // a two-value operand where a dag node expects two operands. :(
1968   def Bcc : ABI<0b1010, (outs), (ins br_target:$target),
1969                IIC_Br, "b", "\t$target",
1970                [/*(ARMbrcond bb:$target, imm:$cc, CCR:$ccr)*/]> {
1971     bits<24> target;
1972     let Inst{23-0} = target;
1973     let DecoderMethod = "DecodeBranchImmInstruction";
1974   }
1975
1976   let isBarrier = 1 in {
1977     // B is "predicable" since it's just a Bcc with an 'always' condition.
1978     let isPredicable = 1 in
1979     // FIXME: We shouldn't need this pseudo at all. Just using Bcc directly
1980     // should be sufficient.
1981     // FIXME: Is B really a Barrier? That doesn't seem right.
1982     def B : ARMPseudoExpand<(outs), (ins br_target:$target), 4, IIC_Br,
1983                 [(br bb:$target)], (Bcc br_target:$target, (ops 14, zero_reg))>;
1984
1985     let isNotDuplicable = 1, isIndirectBranch = 1 in {
1986     def BR_JTr : ARMPseudoInst<(outs),
1987                       (ins GPR:$target, i32imm:$jt, i32imm:$id),
1988                       0, IIC_Br,
1989                       [(ARMbrjt GPR:$target, tjumptable:$jt, imm:$id)]>;
1990     // FIXME: This shouldn't use the generic "addrmode2," but rather be split
1991     // into i12 and rs suffixed versions.
1992     def BR_JTm : ARMPseudoInst<(outs),
1993                      (ins addrmode2:$target, i32imm:$jt, i32imm:$id),
1994                      0, IIC_Br,
1995                      [(ARMbrjt (i32 (load addrmode2:$target)), tjumptable:$jt,
1996                        imm:$id)]>;
1997     def BR_JTadd : ARMPseudoInst<(outs),
1998                    (ins GPR:$target, GPR:$idx, i32imm:$jt, i32imm:$id),
1999                    0, IIC_Br,
2000                    [(ARMbrjt (add GPR:$target, GPR:$idx), tjumptable:$jt,
2001                      imm:$id)]>;
2002     } // isNotDuplicable = 1, isIndirectBranch = 1
2003   } // isBarrier = 1
2004
2005 }
2006
2007 // BLX (immediate)
2008 def BLXi : AXI<(outs), (ins blx_target:$target), BrMiscFrm, NoItinerary,
2009                "blx\t$target", []>,
2010            Requires<[IsARM, HasV5T]> {
2011   let Inst{31-25} = 0b1111101;
2012   bits<25> target;
2013   let Inst{23-0} = target{24-1};
2014   let Inst{24} = target{0};
2015 }
2016
2017 // Branch and Exchange Jazelle
2018 def BXJ : ABI<0b0001, (outs), (ins GPR:$func), NoItinerary, "bxj", "\t$func",
2019               [/* pattern left blank */]> {
2020   bits<4> func;
2021   let Inst{23-20} = 0b0010;
2022   let Inst{19-8} = 0xfff;
2023   let Inst{7-4} = 0b0010;
2024   let Inst{3-0} = func;
2025 }
2026
2027 // Tail calls.
2028
2029 let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1 in {
2030   // IOS versions.
2031   let Uses = [SP] in {
2032     def TCRETURNdi : PseudoInst<(outs), (ins i32imm:$dst, variable_ops),
2033                        IIC_Br, []>, Requires<[IsIOS]>;
2034
2035     def TCRETURNri : PseudoInst<(outs), (ins tcGPR:$dst, variable_ops),
2036                        IIC_Br, []>, Requires<[IsIOS]>;
2037
2038     def TAILJMPd : ARMPseudoExpand<(outs), (ins br_target:$dst, variable_ops),
2039                    4, IIC_Br, [],
2040                    (Bcc br_target:$dst, (ops 14, zero_reg))>,
2041                    Requires<[IsARM, IsIOS]>;
2042
2043     def TAILJMPr : ARMPseudoExpand<(outs), (ins tcGPR:$dst, variable_ops),
2044                    4, IIC_Br, [],
2045                    (BX GPR:$dst)>,
2046                    Requires<[IsARM, IsIOS]>;
2047
2048   }
2049
2050   // Non-IOS versions (the difference is R9).
2051   let Uses = [SP] in {
2052     def TCRETURNdiND : PseudoInst<(outs), (ins i32imm:$dst, variable_ops),
2053                        IIC_Br, []>, Requires<[IsNotIOS]>;
2054
2055     def TCRETURNriND : PseudoInst<(outs), (ins tcGPR:$dst, variable_ops),
2056                        IIC_Br, []>, Requires<[IsNotIOS]>;
2057
2058     def TAILJMPdND : ARMPseudoExpand<(outs), (ins brtarget:$dst, variable_ops),
2059                    4, IIC_Br, [],
2060                    (Bcc br_target:$dst, (ops 14, zero_reg))>,
2061                    Requires<[IsARM, IsNotIOS]>;
2062
2063     def TAILJMPrND : ARMPseudoExpand<(outs), (ins tcGPR:$dst, variable_ops),
2064                      4, IIC_Br, [],
2065                      (BX GPR:$dst)>,
2066                      Requires<[IsARM, IsNotIOS]>;
2067   }
2068 }
2069
2070 // Secure Monitor Call is a system instruction.
2071 def SMC : ABI<0b0001, (outs), (ins imm0_15:$opt), NoItinerary, "smc", "\t$opt",
2072               []> {
2073   bits<4> opt;
2074   let Inst{23-4} = 0b01100000000000000111;
2075   let Inst{3-0} = opt;
2076 }
2077
2078 // Supervisor Call (Software Interrupt)
2079 let isCall = 1, Uses = [SP] in {
2080 def SVC : ABI<0b1111, (outs), (ins imm24b:$svc), IIC_Br, "svc", "\t$svc", []> {
2081   bits<24> svc;
2082   let Inst{23-0} = svc;
2083 }
2084 }
2085
2086 // Store Return State
2087 class SRSI<bit wb, string asm>
2088   : XI<(outs), (ins imm0_31:$mode), AddrModeNone, 4, IndexModeNone, BrFrm,
2089        NoItinerary, asm, "", []> {
2090   bits<5> mode;
2091   let Inst{31-28} = 0b1111;
2092   let Inst{27-25} = 0b100;
2093   let Inst{22} = 1;
2094   let Inst{21} = wb;
2095   let Inst{20} = 0;
2096   let Inst{19-16} = 0b1101;  // SP
2097   let Inst{15-5} = 0b00000101000;
2098   let Inst{4-0} = mode;
2099 }
2100
2101 def SRSDA : SRSI<0, "srsda\tsp, $mode"> {
2102   let Inst{24-23} = 0;
2103 }
2104 def SRSDA_UPD : SRSI<1, "srsda\tsp!, $mode"> {
2105   let Inst{24-23} = 0;
2106 }
2107 def SRSDB : SRSI<0, "srsdb\tsp, $mode"> {
2108   let Inst{24-23} = 0b10;
2109 }
2110 def SRSDB_UPD : SRSI<1, "srsdb\tsp!, $mode"> {
2111   let Inst{24-23} = 0b10;
2112 }
2113 def SRSIA : SRSI<0, "srsia\tsp, $mode"> {
2114   let Inst{24-23} = 0b01;
2115 }
2116 def SRSIA_UPD : SRSI<1, "srsia\tsp!, $mode"> {
2117   let Inst{24-23} = 0b01;
2118 }
2119 def SRSIB : SRSI<0, "srsib\tsp, $mode"> {
2120   let Inst{24-23} = 0b11;
2121 }
2122 def SRSIB_UPD : SRSI<1, "srsib\tsp!, $mode"> {
2123   let Inst{24-23} = 0b11;
2124 }
2125
2126 // Return From Exception
2127 class RFEI<bit wb, string asm>
2128   : XI<(outs), (ins GPR:$Rn), AddrModeNone, 4, IndexModeNone, BrFrm,
2129        NoItinerary, asm, "", []> {
2130   bits<4> Rn;
2131   let Inst{31-28} = 0b1111;
2132   let Inst{27-25} = 0b100;
2133   let Inst{22} = 0;
2134   let Inst{21} = wb;
2135   let Inst{20} = 1;
2136   let Inst{19-16} = Rn;
2137   let Inst{15-0} = 0xa00;
2138 }
2139
2140 def RFEDA : RFEI<0, "rfeda\t$Rn"> {
2141   let Inst{24-23} = 0;
2142 }
2143 def RFEDA_UPD : RFEI<1, "rfeda\t$Rn!"> {
2144   let Inst{24-23} = 0;
2145 }
2146 def RFEDB : RFEI<0, "rfedb\t$Rn"> {
2147   let Inst{24-23} = 0b10;
2148 }
2149 def RFEDB_UPD : RFEI<1, "rfedb\t$Rn!"> {
2150   let Inst{24-23} = 0b10;
2151 }
2152 def RFEIA : RFEI<0, "rfeia\t$Rn"> {
2153   let Inst{24-23} = 0b01;
2154 }
2155 def RFEIA_UPD : RFEI<1, "rfeia\t$Rn!"> {
2156   let Inst{24-23} = 0b01;
2157 }
2158 def RFEIB : RFEI<0, "rfeib\t$Rn"> {
2159   let Inst{24-23} = 0b11;
2160 }
2161 def RFEIB_UPD : RFEI<1, "rfeib\t$Rn!"> {
2162   let Inst{24-23} = 0b11;
2163 }
2164
2165 //===----------------------------------------------------------------------===//
2166 //  Load / Store Instructions.
2167 //
2168
2169 // Load
2170
2171
2172 defm LDR  : AI_ldr1<0, "ldr", IIC_iLoad_r, IIC_iLoad_si,
2173                     UnOpFrag<(load node:$Src)>>;
2174 defm LDRB : AI_ldr1nopc<1, "ldrb", IIC_iLoad_bh_r, IIC_iLoad_bh_si,
2175                     UnOpFrag<(zextloadi8 node:$Src)>>;
2176 defm STR  : AI_str1<0, "str", IIC_iStore_r, IIC_iStore_si,
2177                    BinOpFrag<(store node:$LHS, node:$RHS)>>;
2178 defm STRB : AI_str1nopc<1, "strb", IIC_iStore_bh_r, IIC_iStore_bh_si,
2179                    BinOpFrag<(truncstorei8 node:$LHS, node:$RHS)>>;
2180
2181 // Special LDR for loads from non-pc-relative constpools.
2182 let canFoldAsLoad = 1, mayLoad = 1, neverHasSideEffects = 1,
2183     isReMaterializable = 1, isCodeGenOnly = 1 in
2184 def LDRcp : AI2ldst<0b010, 1, 0, (outs GPR:$Rt), (ins addrmode_imm12:$addr),
2185                  AddrMode_i12, LdFrm, IIC_iLoad_r, "ldr", "\t$Rt, $addr",
2186                  []> {
2187   bits<4> Rt;
2188   bits<17> addr;
2189   let Inst{23}    = addr{12};     // U (add = ('U' == 1))
2190   let Inst{19-16} = 0b1111;
2191   let Inst{15-12} = Rt;
2192   let Inst{11-0}  = addr{11-0};   // imm12
2193 }
2194
2195 // Loads with zero extension
2196 def LDRH  : AI3ld<0b1011, 1, (outs GPR:$Rt), (ins addrmode3:$addr), LdMiscFrm,
2197                   IIC_iLoad_bh_r, "ldrh", "\t$Rt, $addr",
2198                   [(set GPR:$Rt, (zextloadi16 addrmode3:$addr))]>;
2199
2200 // Loads with sign extension
2201 def LDRSH : AI3ld<0b1111, 1, (outs GPR:$Rt), (ins addrmode3:$addr), LdMiscFrm,
2202                    IIC_iLoad_bh_r, "ldrsh", "\t$Rt, $addr",
2203                    [(set GPR:$Rt, (sextloadi16 addrmode3:$addr))]>;
2204
2205 def LDRSB : AI3ld<0b1101, 1, (outs GPR:$Rt), (ins addrmode3:$addr), LdMiscFrm,
2206                    IIC_iLoad_bh_r, "ldrsb", "\t$Rt, $addr",
2207                    [(set GPR:$Rt, (sextloadi8 addrmode3:$addr))]>;
2208
2209 let mayLoad = 1, neverHasSideEffects = 1, hasExtraDefRegAllocReq = 1 in {
2210 // Load doubleword
2211 def LDRD : AI3ld<0b1101, 0, (outs GPR:$Rd, GPR:$dst2),
2212                  (ins addrmode3:$addr), LdMiscFrm,
2213                  IIC_iLoad_d_r, "ldrd", "\t$Rd, $dst2, $addr",
2214                  []>, Requires<[IsARM, HasV5TE]>;
2215 }
2216
2217 // Indexed loads
2218 multiclass AI2_ldridx<bit isByte, string opc,
2219                       InstrItinClass iii, InstrItinClass iir> {
2220   def _PRE_IMM  : AI2ldstidx<1, isByte, 1, (outs GPR:$Rt, GPR:$Rn_wb),
2221                       (ins addrmode_imm12:$addr), IndexModePre, LdFrm, iii,
2222                       opc, "\t$Rt, $addr!", "$addr.base = $Rn_wb", []> {
2223     bits<17> addr;
2224     let Inst{25} = 0;
2225     let Inst{23} = addr{12};
2226     let Inst{19-16} = addr{16-13};
2227     let Inst{11-0} = addr{11-0};
2228     let DecoderMethod = "DecodeLDRPreImm";
2229     let AsmMatchConverter = "cvtLdWriteBackRegAddrModeImm12";
2230   }
2231
2232   def _PRE_REG  : AI2ldstidx<1, isByte, 1, (outs GPR:$Rt, GPR:$Rn_wb),
2233                       (ins ldst_so_reg:$addr), IndexModePre, LdFrm, iir,
2234                       opc, "\t$Rt, $addr!", "$addr.base = $Rn_wb", []> {
2235     bits<17> addr;
2236     let Inst{25} = 1;
2237     let Inst{23} = addr{12};
2238     let Inst{19-16} = addr{16-13};
2239     let Inst{11-0} = addr{11-0};
2240     let Inst{4} = 0;
2241     let DecoderMethod = "DecodeLDRPreReg";
2242     let AsmMatchConverter = "cvtLdWriteBackRegAddrMode2";
2243   }
2244
2245   def _POST_REG : AI2ldstidx<1, isByte, 0, (outs GPR:$Rt, GPR:$Rn_wb),
2246                        (ins addr_offset_none:$addr, am2offset_reg:$offset),
2247                        IndexModePost, LdFrm, iir,
2248                        opc, "\t$Rt, $addr, $offset",
2249                        "$addr.base = $Rn_wb", []> {
2250      // {12}     isAdd
2251      // {11-0}   imm12/Rm
2252      bits<14> offset;
2253      bits<4> addr;
2254      let Inst{25} = 1;
2255      let Inst{23} = offset{12};
2256      let Inst{19-16} = addr;
2257      let Inst{11-0} = offset{11-0};
2258
2259     let DecoderMethod = "DecodeAddrMode2IdxInstruction";
2260    }
2261
2262    def _POST_IMM : AI2ldstidx<1, isByte, 0, (outs GPR:$Rt, GPR:$Rn_wb),
2263                        (ins addr_offset_none:$addr, am2offset_imm:$offset),
2264                       IndexModePost, LdFrm, iii,
2265                       opc, "\t$Rt, $addr, $offset",
2266                       "$addr.base = $Rn_wb", []> {
2267     // {12}     isAdd
2268     // {11-0}   imm12/Rm
2269     bits<14> offset;
2270     bits<4> addr;
2271     let Inst{25} = 0;
2272     let Inst{23} = offset{12};
2273     let Inst{19-16} = addr;
2274     let Inst{11-0} = offset{11-0};
2275
2276     let DecoderMethod = "DecodeAddrMode2IdxInstruction";
2277   }
2278
2279 }
2280
2281 let mayLoad = 1, neverHasSideEffects = 1 in {
2282 // FIXME: for LDR_PRE_REG etc. the itineray should be either IIC_iLoad_ru or
2283 // IIC_iLoad_siu depending on whether it the offset register is shifted.
2284 defm LDR  : AI2_ldridx<0, "ldr", IIC_iLoad_iu, IIC_iLoad_ru>;
2285 defm LDRB : AI2_ldridx<1, "ldrb", IIC_iLoad_bh_iu, IIC_iLoad_bh_ru>;
2286 }
2287
2288 multiclass AI3_ldridx<bits<4> op, string opc, InstrItinClass itin> {
2289   def _PRE  : AI3ldstidx<op, 1, 1, (outs GPR:$Rt, GPR:$Rn_wb),
2290                         (ins addrmode3:$addr), IndexModePre,
2291                         LdMiscFrm, itin,
2292                         opc, "\t$Rt, $addr!", "$addr.base = $Rn_wb", []> {
2293     bits<14> addr;
2294     let Inst{23}    = addr{8};      // U bit
2295     let Inst{22}    = addr{13};     // 1 == imm8, 0 == Rm
2296     let Inst{19-16} = addr{12-9};   // Rn
2297     let Inst{11-8}  = addr{7-4};    // imm7_4/zero
2298     let Inst{3-0}   = addr{3-0};    // imm3_0/Rm
2299     let AsmMatchConverter = "cvtLdWriteBackRegAddrMode3";
2300     let DecoderMethod = "DecodeAddrMode3Instruction";
2301   }
2302   def _POST : AI3ldstidx<op, 1, 0, (outs GPR:$Rt, GPR:$Rn_wb),
2303                         (ins addr_offset_none:$addr, am3offset:$offset),
2304                         IndexModePost, LdMiscFrm, itin,
2305                         opc, "\t$Rt, $addr, $offset", "$addr.base = $Rn_wb",
2306                         []> {
2307     bits<10> offset;
2308     bits<4> addr;
2309     let Inst{23}    = offset{8};      // U bit
2310     let Inst{22}    = offset{9};      // 1 == imm8, 0 == Rm
2311     let Inst{19-16} = addr;
2312     let Inst{11-8}  = offset{7-4};    // imm7_4/zero
2313     let Inst{3-0}   = offset{3-0};    // imm3_0/Rm
2314     let DecoderMethod = "DecodeAddrMode3Instruction";
2315   }
2316 }
2317
2318 let mayLoad = 1, neverHasSideEffects = 1 in {
2319 defm LDRH  : AI3_ldridx<0b1011, "ldrh", IIC_iLoad_bh_ru>;
2320 defm LDRSH : AI3_ldridx<0b1111, "ldrsh", IIC_iLoad_bh_ru>;
2321 defm LDRSB : AI3_ldridx<0b1101, "ldrsb", IIC_iLoad_bh_ru>;
2322 let hasExtraDefRegAllocReq = 1 in {
2323 def LDRD_PRE : AI3ldstidx<0b1101, 0, 1, (outs GPR:$Rt, GPR:$Rt2, GPR:$Rn_wb),
2324                           (ins addrmode3:$addr), IndexModePre,
2325                           LdMiscFrm, IIC_iLoad_d_ru,
2326                           "ldrd", "\t$Rt, $Rt2, $addr!",
2327                           "$addr.base = $Rn_wb", []> {
2328   bits<14> addr;
2329   let Inst{23}    = addr{8};      // U bit
2330   let Inst{22}    = addr{13};     // 1 == imm8, 0 == Rm
2331   let Inst{19-16} = addr{12-9};   // Rn
2332   let Inst{11-8}  = addr{7-4};    // imm7_4/zero
2333   let Inst{3-0}   = addr{3-0};    // imm3_0/Rm
2334   let DecoderMethod = "DecodeAddrMode3Instruction";
2335   let AsmMatchConverter = "cvtLdrdPre";
2336 }
2337 def LDRD_POST: AI3ldstidx<0b1101, 0, 0, (outs GPR:$Rt, GPR:$Rt2, GPR:$Rn_wb),
2338                           (ins addr_offset_none:$addr, am3offset:$offset),
2339                           IndexModePost, LdMiscFrm, IIC_iLoad_d_ru,
2340                           "ldrd", "\t$Rt, $Rt2, $addr, $offset",
2341                           "$addr.base = $Rn_wb", []> {
2342   bits<10> offset;
2343   bits<4> addr;
2344   let Inst{23}    = offset{8};      // U bit
2345   let Inst{22}    = offset{9};      // 1 == imm8, 0 == Rm
2346   let Inst{19-16} = addr;
2347   let Inst{11-8}  = offset{7-4};    // imm7_4/zero
2348   let Inst{3-0}   = offset{3-0};    // imm3_0/Rm
2349   let DecoderMethod = "DecodeAddrMode3Instruction";
2350 }
2351 } // hasExtraDefRegAllocReq = 1
2352 } // mayLoad = 1, neverHasSideEffects = 1
2353
2354 // LDRT, LDRBT, LDRSBT, LDRHT, LDRSHT.
2355 let mayLoad = 1, neverHasSideEffects = 1 in {
2356 def LDRT_POST_REG : AI2ldstidx<1, 0, 0, (outs GPR:$Rt, GPR:$Rn_wb),
2357                     (ins addr_offset_none:$addr, am2offset_reg:$offset),
2358                     IndexModePost, LdFrm, IIC_iLoad_ru,
2359                     "ldrt", "\t$Rt, $addr, $offset",
2360                     "$addr.base = $Rn_wb", []> {
2361   // {12}     isAdd
2362   // {11-0}   imm12/Rm
2363   bits<14> offset;
2364   bits<4> addr;
2365   let Inst{25} = 1;
2366   let Inst{23} = offset{12};
2367   let Inst{21} = 1; // overwrite
2368   let Inst{19-16} = addr;
2369   let Inst{11-5} = offset{11-5};
2370   let Inst{4} = 0;
2371   let Inst{3-0} = offset{3-0};
2372   let DecoderMethod = "DecodeAddrMode2IdxInstruction";
2373 }
2374
2375 def LDRT_POST_IMM : AI2ldstidx<1, 0, 0, (outs GPR:$Rt, GPR:$Rn_wb),
2376                     (ins addr_offset_none:$addr, am2offset_imm:$offset),
2377                    IndexModePost, LdFrm, IIC_iLoad_ru,
2378                    "ldrt", "\t$Rt, $addr, $offset",
2379                    "$addr.base = $Rn_wb", []> {
2380   // {12}     isAdd
2381   // {11-0}   imm12/Rm
2382   bits<14> offset;
2383   bits<4> addr;
2384   let Inst{25} = 0;
2385   let Inst{23} = offset{12};
2386   let Inst{21} = 1; // overwrite
2387   let Inst{19-16} = addr;
2388   let Inst{11-0} = offset{11-0};
2389   let DecoderMethod = "DecodeAddrMode2IdxInstruction";
2390 }
2391
2392 def LDRBT_POST_REG : AI2ldstidx<1, 1, 0, (outs GPR:$Rt, GPR:$Rn_wb),
2393                      (ins addr_offset_none:$addr, am2offset_reg:$offset),
2394                      IndexModePost, LdFrm, IIC_iLoad_bh_ru,
2395                      "ldrbt", "\t$Rt, $addr, $offset",
2396                      "$addr.base = $Rn_wb", []> {
2397   // {12}     isAdd
2398   // {11-0}   imm12/Rm
2399   bits<14> offset;
2400   bits<4> addr;
2401   let Inst{25} = 1;
2402   let Inst{23} = offset{12};
2403   let Inst{21} = 1; // overwrite
2404   let Inst{19-16} = addr;
2405   let Inst{11-5} = offset{11-5};
2406   let Inst{4} = 0;
2407   let Inst{3-0} = offset{3-0};
2408   let DecoderMethod = "DecodeAddrMode2IdxInstruction";
2409 }
2410
2411 def LDRBT_POST_IMM : AI2ldstidx<1, 1, 0, (outs GPR:$Rt, GPR:$Rn_wb),
2412                      (ins addr_offset_none:$addr, am2offset_imm:$offset),
2413                     IndexModePost, LdFrm, IIC_iLoad_bh_ru,
2414                     "ldrbt", "\t$Rt, $addr, $offset",
2415                     "$addr.base = $Rn_wb", []> {
2416   // {12}     isAdd
2417   // {11-0}   imm12/Rm
2418   bits<14> offset;
2419   bits<4> addr;
2420   let Inst{25} = 0;
2421   let Inst{23} = offset{12};
2422   let Inst{21} = 1; // overwrite
2423   let Inst{19-16} = addr;
2424   let Inst{11-0} = offset{11-0};
2425   let DecoderMethod = "DecodeAddrMode2IdxInstruction";
2426 }
2427
2428 multiclass AI3ldrT<bits<4> op, string opc> {
2429   def i : AI3ldstidxT<op, 1, (outs GPR:$Rt, GPR:$base_wb),
2430                       (ins addr_offset_none:$addr, postidx_imm8:$offset),
2431                       IndexModePost, LdMiscFrm, IIC_iLoad_bh_ru, opc,
2432                       "\t$Rt, $addr, $offset", "$addr.base = $base_wb", []> {
2433     bits<9> offset;
2434     let Inst{23} = offset{8};
2435     let Inst{22} = 1;
2436     let Inst{11-8} = offset{7-4};
2437     let Inst{3-0} = offset{3-0};
2438     let AsmMatchConverter = "cvtLdExtTWriteBackImm";
2439   }
2440   def r : AI3ldstidxT<op, 1, (outs GPRnopc:$Rt, GPRnopc:$base_wb),
2441                       (ins addr_offset_none:$addr, postidx_reg:$Rm),
2442                       IndexModePost, LdMiscFrm, IIC_iLoad_bh_ru, opc,
2443                       "\t$Rt, $addr, $Rm", "$addr.base = $base_wb", []> {
2444     bits<5> Rm;
2445     let Inst{23} = Rm{4};
2446     let Inst{22} = 0;
2447     let Inst{11-8} = 0;
2448     let Unpredictable{11-8} = 0b1111;
2449     let Inst{3-0} = Rm{3-0};
2450     let AsmMatchConverter = "cvtLdExtTWriteBackReg";
2451     let DecoderMethod = "DecodeLDR";
2452   }
2453 }
2454
2455 defm LDRSBT : AI3ldrT<0b1101, "ldrsbt">;
2456 defm LDRHT  : AI3ldrT<0b1011, "ldrht">;
2457 defm LDRSHT : AI3ldrT<0b1111, "ldrsht">;
2458 }
2459
2460 // Store
2461
2462 // Stores with truncate
2463 def STRH : AI3str<0b1011, (outs), (ins GPR:$Rt, addrmode3:$addr), StMiscFrm,
2464                IIC_iStore_bh_r, "strh", "\t$Rt, $addr",
2465                [(truncstorei16 GPR:$Rt, addrmode3:$addr)]>;
2466
2467 // Store doubleword
2468 let mayStore = 1, neverHasSideEffects = 1, hasExtraSrcRegAllocReq = 1 in
2469 def STRD : AI3str<0b1111, (outs), (ins GPR:$Rt, GPR:$src2, addrmode3:$addr),
2470                StMiscFrm, IIC_iStore_d_r,
2471                "strd", "\t$Rt, $src2, $addr", []>,
2472            Requires<[IsARM, HasV5TE]> {
2473   let Inst{21} = 0;
2474 }
2475
2476 // Indexed stores
2477 multiclass AI2_stridx<bit isByte, string opc,
2478                       InstrItinClass iii, InstrItinClass iir> {
2479   def _PRE_IMM : AI2ldstidx<0, isByte, 1, (outs GPR:$Rn_wb),
2480                             (ins GPR:$Rt, addrmode_imm12:$addr), IndexModePre,
2481                             StFrm, iii,
2482                             opc, "\t$Rt, $addr!", "$addr.base = $Rn_wb", []> {
2483     bits<17> addr;
2484     let Inst{25} = 0;
2485     let Inst{23}    = addr{12};     // U (add = ('U' == 1))
2486     let Inst{19-16} = addr{16-13};  // Rn
2487     let Inst{11-0}  = addr{11-0};   // imm12
2488     let AsmMatchConverter = "cvtStWriteBackRegAddrModeImm12";
2489     let DecoderMethod = "DecodeSTRPreImm";
2490   }
2491
2492   def _PRE_REG  : AI2ldstidx<0, isByte, 1, (outs GPR:$Rn_wb),
2493                       (ins GPR:$Rt, ldst_so_reg:$addr),
2494                       IndexModePre, StFrm, iir,
2495                       opc, "\t$Rt, $addr!", "$addr.base = $Rn_wb", []> {
2496     bits<17> addr;
2497     let Inst{25} = 1;
2498     let Inst{23}    = addr{12};    // U (add = ('U' == 1))
2499     let Inst{19-16} = addr{16-13}; // Rn
2500     let Inst{11-0}  = addr{11-0};
2501     let Inst{4}     = 0;           // Inst{4} = 0
2502     let AsmMatchConverter = "cvtStWriteBackRegAddrMode2";
2503     let DecoderMethod = "DecodeSTRPreReg";
2504   }
2505   def _POST_REG : AI2ldstidx<0, isByte, 0, (outs GPR:$Rn_wb),
2506                 (ins GPR:$Rt, addr_offset_none:$addr, am2offset_reg:$offset),
2507                 IndexModePost, StFrm, iir,
2508                 opc, "\t$Rt, $addr, $offset",
2509                 "$addr.base = $Rn_wb", []> {
2510      // {12}     isAdd
2511      // {11-0}   imm12/Rm
2512      bits<14> offset;
2513      bits<4> addr;
2514      let Inst{25} = 1;
2515      let Inst{23} = offset{12};
2516      let Inst{19-16} = addr;
2517      let Inst{11-0} = offset{11-0};
2518
2519     let DecoderMethod = "DecodeAddrMode2IdxInstruction";
2520    }
2521
2522    def _POST_IMM : AI2ldstidx<0, isByte, 0, (outs GPR:$Rn_wb),
2523                 (ins GPR:$Rt, addr_offset_none:$addr, am2offset_imm:$offset),
2524                 IndexModePost, StFrm, iii,
2525                 opc, "\t$Rt, $addr, $offset",
2526                 "$addr.base = $Rn_wb", []> {
2527     // {12}     isAdd
2528     // {11-0}   imm12/Rm
2529     bits<14> offset;
2530     bits<4> addr;
2531     let Inst{25} = 0;
2532     let Inst{23} = offset{12};
2533     let Inst{19-16} = addr;
2534     let Inst{11-0} = offset{11-0};
2535
2536     let DecoderMethod = "DecodeAddrMode2IdxInstruction";
2537   }
2538 }
2539
2540 let mayStore = 1, neverHasSideEffects = 1 in {
2541 // FIXME: for STR_PRE_REG etc. the itineray should be either IIC_iStore_ru or
2542 // IIC_iStore_siu depending on whether it the offset register is shifted.
2543 defm STR  : AI2_stridx<0, "str", IIC_iStore_iu, IIC_iStore_ru>;
2544 defm STRB : AI2_stridx<1, "strb", IIC_iStore_bh_iu, IIC_iStore_bh_ru>;
2545 }
2546
2547 def : ARMPat<(post_store GPR:$Rt, addr_offset_none:$addr,
2548                          am2offset_reg:$offset),
2549              (STR_POST_REG GPR:$Rt, addr_offset_none:$addr,
2550                            am2offset_reg:$offset)>;
2551 def : ARMPat<(post_store GPR:$Rt, addr_offset_none:$addr,
2552                          am2offset_imm:$offset),
2553              (STR_POST_IMM GPR:$Rt, addr_offset_none:$addr,
2554                            am2offset_imm:$offset)>;
2555 def : ARMPat<(post_truncsti8 GPR:$Rt, addr_offset_none:$addr,
2556                              am2offset_reg:$offset),
2557              (STRB_POST_REG GPR:$Rt, addr_offset_none:$addr,
2558                             am2offset_reg:$offset)>;
2559 def : ARMPat<(post_truncsti8 GPR:$Rt, addr_offset_none:$addr,
2560                              am2offset_imm:$offset),
2561              (STRB_POST_IMM GPR:$Rt, addr_offset_none:$addr,
2562                             am2offset_imm:$offset)>;
2563
2564 // Pseudo-instructions for pattern matching the pre-indexed stores. We can't
2565 // put the patterns on the instruction definitions directly as ISel wants
2566 // the address base and offset to be separate operands, not a single
2567 // complex operand like we represent the instructions themselves. The
2568 // pseudos map between the two.
2569 let usesCustomInserter = 1,
2570     Constraints = "$Rn = $Rn_wb,@earlyclobber $Rn_wb" in {
2571 def STRi_preidx: ARMPseudoInst<(outs GPR:$Rn_wb),
2572                (ins GPR:$Rt, GPR:$Rn, am2offset_imm:$offset, pred:$p),
2573                4, IIC_iStore_ru,
2574             [(set GPR:$Rn_wb,
2575                   (pre_store GPR:$Rt, GPR:$Rn, am2offset_imm:$offset))]>;
2576 def STRr_preidx: ARMPseudoInst<(outs GPR:$Rn_wb),
2577                (ins GPR:$Rt, GPR:$Rn, am2offset_reg:$offset, pred:$p),
2578                4, IIC_iStore_ru,
2579             [(set GPR:$Rn_wb,
2580                   (pre_store GPR:$Rt, GPR:$Rn, am2offset_reg:$offset))]>;
2581 def STRBi_preidx: ARMPseudoInst<(outs GPR:$Rn_wb),
2582                (ins GPR:$Rt, GPR:$Rn, am2offset_imm:$offset, pred:$p),
2583                4, IIC_iStore_ru,
2584             [(set GPR:$Rn_wb,
2585                   (pre_truncsti8 GPR:$Rt, GPR:$Rn, am2offset_imm:$offset))]>;
2586 def STRBr_preidx: ARMPseudoInst<(outs GPR:$Rn_wb),
2587                (ins GPR:$Rt, GPR:$Rn, am2offset_reg:$offset, pred:$p),
2588                4, IIC_iStore_ru,
2589             [(set GPR:$Rn_wb,
2590                   (pre_truncsti8 GPR:$Rt, GPR:$Rn, am2offset_reg:$offset))]>;
2591 def STRH_preidx: ARMPseudoInst<(outs GPR:$Rn_wb),
2592                (ins GPR:$Rt, GPR:$Rn, am3offset:$offset, pred:$p),
2593                4, IIC_iStore_ru,
2594             [(set GPR:$Rn_wb,
2595                   (pre_truncsti16 GPR:$Rt, GPR:$Rn, am3offset:$offset))]>;
2596 }
2597
2598
2599
2600 def STRH_PRE  : AI3ldstidx<0b1011, 0, 1, (outs GPR:$Rn_wb),
2601                            (ins GPR:$Rt, addrmode3:$addr), IndexModePre,
2602                            StMiscFrm, IIC_iStore_bh_ru,
2603                            "strh", "\t$Rt, $addr!", "$addr.base = $Rn_wb", []> {
2604   bits<14> addr;
2605   let Inst{23}    = addr{8};      // U bit
2606   let Inst{22}    = addr{13};     // 1 == imm8, 0 == Rm
2607   let Inst{19-16} = addr{12-9};   // Rn
2608   let Inst{11-8}  = addr{7-4};    // imm7_4/zero
2609   let Inst{3-0}   = addr{3-0};    // imm3_0/Rm
2610   let AsmMatchConverter = "cvtStWriteBackRegAddrMode3";
2611   let DecoderMethod = "DecodeAddrMode3Instruction";
2612 }
2613
2614 def STRH_POST : AI3ldstidx<0b1011, 0, 0, (outs GPR:$Rn_wb),
2615                        (ins GPR:$Rt, addr_offset_none:$addr, am3offset:$offset),
2616                        IndexModePost, StMiscFrm, IIC_iStore_bh_ru,
2617                        "strh", "\t$Rt, $addr, $offset", "$addr.base = $Rn_wb",
2618                    [(set GPR:$Rn_wb, (post_truncsti16 GPR:$Rt,
2619                                                       addr_offset_none:$addr,
2620                                                       am3offset:$offset))]> {
2621   bits<10> offset;
2622   bits<4> addr;
2623   let Inst{23}    = offset{8};      // U bit
2624   let Inst{22}    = offset{9};      // 1 == imm8, 0 == Rm
2625   let Inst{19-16} = addr;
2626   let Inst{11-8}  = offset{7-4};    // imm7_4/zero
2627   let Inst{3-0}   = offset{3-0};    // imm3_0/Rm
2628   let DecoderMethod = "DecodeAddrMode3Instruction";
2629 }
2630
2631 let mayStore = 1, neverHasSideEffects = 1, hasExtraSrcRegAllocReq = 1 in {
2632 def STRD_PRE : AI3ldstidx<0b1111, 0, 1, (outs GPR:$Rn_wb),
2633                           (ins GPR:$Rt, GPR:$Rt2, addrmode3:$addr),
2634                           IndexModePre, StMiscFrm, IIC_iStore_d_ru,
2635                           "strd", "\t$Rt, $Rt2, $addr!",
2636                           "$addr.base = $Rn_wb", []> {
2637   bits<14> addr;
2638   let Inst{23}    = addr{8};      // U bit
2639   let Inst{22}    = addr{13};     // 1 == imm8, 0 == Rm
2640   let Inst{19-16} = addr{12-9};   // Rn
2641   let Inst{11-8}  = addr{7-4};    // imm7_4/zero
2642   let Inst{3-0}   = addr{3-0};    // imm3_0/Rm
2643   let DecoderMethod = "DecodeAddrMode3Instruction";
2644   let AsmMatchConverter = "cvtStrdPre";
2645 }
2646
2647 def STRD_POST: AI3ldstidx<0b1111, 0, 0, (outs GPR:$Rn_wb),
2648                           (ins GPR:$Rt, GPR:$Rt2, addr_offset_none:$addr,
2649                                am3offset:$offset),
2650                           IndexModePost, StMiscFrm, IIC_iStore_d_ru,
2651                           "strd", "\t$Rt, $Rt2, $addr, $offset",
2652                           "$addr.base = $Rn_wb", []> {
2653   bits<10> offset;
2654   bits<4> addr;
2655   let Inst{23}    = offset{8};      // U bit
2656   let Inst{22}    = offset{9};      // 1 == imm8, 0 == Rm
2657   let Inst{19-16} = addr;
2658   let Inst{11-8}  = offset{7-4};    // imm7_4/zero
2659   let Inst{3-0}   = offset{3-0};    // imm3_0/Rm
2660   let DecoderMethod = "DecodeAddrMode3Instruction";
2661 }
2662 } // mayStore = 1, neverHasSideEffects = 1, hasExtraSrcRegAllocReq = 1
2663
2664 // STRT, STRBT, and STRHT
2665
2666 def STRBT_POST_REG : AI2ldstidx<0, 1, 0, (outs GPR:$Rn_wb),
2667                    (ins GPR:$Rt, addr_offset_none:$addr, am2offset_reg:$offset),
2668                    IndexModePost, StFrm, IIC_iStore_bh_ru,
2669                    "strbt", "\t$Rt, $addr, $offset",
2670                    "$addr.base = $Rn_wb", []> {
2671   // {12}     isAdd
2672   // {11-0}   imm12/Rm
2673   bits<14> offset;
2674   bits<4> addr;
2675   let Inst{25} = 1;
2676   let Inst{23} = offset{12};
2677   let Inst{21} = 1; // overwrite
2678   let Inst{19-16} = addr;
2679   let Inst{11-5} = offset{11-5};
2680   let Inst{4} = 0;
2681   let Inst{3-0} = offset{3-0};
2682   let DecoderMethod = "DecodeAddrMode2IdxInstruction";
2683 }
2684
2685 def STRBT_POST_IMM : AI2ldstidx<0, 1, 0, (outs GPR:$Rn_wb),
2686                    (ins GPR:$Rt, addr_offset_none:$addr, am2offset_imm:$offset),
2687                    IndexModePost, StFrm, IIC_iStore_bh_ru,
2688                    "strbt", "\t$Rt, $addr, $offset",
2689                    "$addr.base = $Rn_wb", []> {
2690   // {12}     isAdd
2691   // {11-0}   imm12/Rm
2692   bits<14> offset;
2693   bits<4> addr;
2694   let Inst{25} = 0;
2695   let Inst{23} = offset{12};
2696   let Inst{21} = 1; // overwrite
2697   let Inst{19-16} = addr;
2698   let Inst{11-0} = offset{11-0};
2699   let DecoderMethod = "DecodeAddrMode2IdxInstruction";
2700 }
2701
2702 let mayStore = 1, neverHasSideEffects = 1 in {
2703 def STRT_POST_REG : AI2ldstidx<0, 0, 0, (outs GPR:$Rn_wb),
2704                    (ins GPR:$Rt, addr_offset_none:$addr, am2offset_reg:$offset),
2705                    IndexModePost, StFrm, IIC_iStore_ru,
2706                    "strt", "\t$Rt, $addr, $offset",
2707                    "$addr.base = $Rn_wb", []> {
2708   // {12}     isAdd
2709   // {11-0}   imm12/Rm
2710   bits<14> offset;
2711   bits<4> addr;
2712   let Inst{25} = 1;
2713   let Inst{23} = offset{12};
2714   let Inst{21} = 1; // overwrite
2715   let Inst{19-16} = addr;
2716   let Inst{11-5} = offset{11-5};
2717   let Inst{4} = 0;
2718   let Inst{3-0} = offset{3-0};
2719   let DecoderMethod = "DecodeAddrMode2IdxInstruction";
2720 }
2721
2722 def STRT_POST_IMM : AI2ldstidx<0, 0, 0, (outs GPR:$Rn_wb),
2723                    (ins GPR:$Rt, addr_offset_none:$addr, am2offset_imm:$offset),
2724                    IndexModePost, StFrm, IIC_iStore_ru,
2725                    "strt", "\t$Rt, $addr, $offset",
2726                    "$addr.base = $Rn_wb", []> {
2727   // {12}     isAdd
2728   // {11-0}   imm12/Rm
2729   bits<14> offset;
2730   bits<4> addr;
2731   let Inst{25} = 0;
2732   let Inst{23} = offset{12};
2733   let Inst{21} = 1; // overwrite
2734   let Inst{19-16} = addr;
2735   let Inst{11-0} = offset{11-0};
2736   let DecoderMethod = "DecodeAddrMode2IdxInstruction";
2737 }
2738 }
2739
2740
2741 multiclass AI3strT<bits<4> op, string opc> {
2742   def i : AI3ldstidxT<op, 0, (outs GPR:$base_wb),
2743                     (ins GPR:$Rt, addr_offset_none:$addr, postidx_imm8:$offset),
2744                     IndexModePost, StMiscFrm, IIC_iStore_bh_ru, opc,
2745                     "\t$Rt, $addr, $offset", "$addr.base = $base_wb", []> {
2746     bits<9> offset;
2747     let Inst{23} = offset{8};
2748     let Inst{22} = 1;
2749     let Inst{11-8} = offset{7-4};
2750     let Inst{3-0} = offset{3-0};
2751     let AsmMatchConverter = "cvtStExtTWriteBackImm";
2752   }
2753   def r : AI3ldstidxT<op, 0, (outs GPR:$base_wb),
2754                       (ins GPR:$Rt, addr_offset_none:$addr, postidx_reg:$Rm),
2755                       IndexModePost, StMiscFrm, IIC_iStore_bh_ru, opc,
2756                       "\t$Rt, $addr, $Rm", "$addr.base = $base_wb", []> {
2757     bits<5> Rm;
2758     let Inst{23} = Rm{4};
2759     let Inst{22} = 0;
2760     let Inst{11-8} = 0;
2761     let Inst{3-0} = Rm{3-0};
2762     let AsmMatchConverter = "cvtStExtTWriteBackReg";
2763   }
2764 }
2765
2766
2767 defm STRHT : AI3strT<0b1011, "strht">;
2768
2769
2770 //===----------------------------------------------------------------------===//
2771 //  Load / store multiple Instructions.
2772 //
2773
2774 multiclass arm_ldst_mult<string asm, string sfx, bit L_bit, bit P_bit, Format f,
2775                          InstrItinClass itin, InstrItinClass itin_upd> {
2776   // IA is the default, so no need for an explicit suffix on the
2777   // mnemonic here. Without it is the cannonical spelling.
2778   def IA :
2779     AXI4<(outs), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops),
2780          IndexModeNone, f, itin,
2781          !strconcat(asm, "${p}\t$Rn, $regs", sfx), "", []> {
2782     let Inst{24-23} = 0b01;       // Increment After
2783     let Inst{22}    = P_bit;
2784     let Inst{21}    = 0;          // No writeback
2785     let Inst{20}    = L_bit;
2786   }
2787   def IA_UPD :
2788     AXI4<(outs GPR:$wb), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops),
2789          IndexModeUpd, f, itin_upd,
2790          !strconcat(asm, "${p}\t$Rn!, $regs", sfx), "$Rn = $wb", []> {
2791     let Inst{24-23} = 0b01;       // Increment After
2792     let Inst{22}    = P_bit;
2793     let Inst{21}    = 1;          // Writeback
2794     let Inst{20}    = L_bit;
2795
2796     let DecoderMethod = "DecodeMemMultipleWritebackInstruction";
2797   }
2798   def DA :
2799     AXI4<(outs), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops),
2800          IndexModeNone, f, itin,
2801          !strconcat(asm, "da${p}\t$Rn, $regs", sfx), "", []> {
2802     let Inst{24-23} = 0b00;       // Decrement After
2803     let Inst{22}    = P_bit;
2804     let Inst{21}    = 0;          // No writeback
2805     let Inst{20}    = L_bit;
2806   }
2807   def DA_UPD :
2808     AXI4<(outs GPR:$wb), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops),
2809          IndexModeUpd, f, itin_upd,
2810          !strconcat(asm, "da${p}\t$Rn!, $regs", sfx), "$Rn = $wb", []> {
2811     let Inst{24-23} = 0b00;       // Decrement After
2812     let Inst{22}    = P_bit;
2813     let Inst{21}    = 1;          // Writeback
2814     let Inst{20}    = L_bit;
2815
2816     let DecoderMethod = "DecodeMemMultipleWritebackInstruction";
2817   }
2818   def DB :
2819     AXI4<(outs), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops),
2820          IndexModeNone, f, itin,
2821          !strconcat(asm, "db${p}\t$Rn, $regs", sfx), "", []> {
2822     let Inst{24-23} = 0b10;       // Decrement Before
2823     let Inst{22}    = P_bit;
2824     let Inst{21}    = 0;          // No writeback
2825     let Inst{20}    = L_bit;
2826   }
2827   def DB_UPD :
2828     AXI4<(outs GPR:$wb), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops),
2829          IndexModeUpd, f, itin_upd,
2830          !strconcat(asm, "db${p}\t$Rn!, $regs", sfx), "$Rn = $wb", []> {
2831     let Inst{24-23} = 0b10;       // Decrement Before
2832     let Inst{22}    = P_bit;
2833     let Inst{21}    = 1;          // Writeback
2834     let Inst{20}    = L_bit;
2835
2836     let DecoderMethod = "DecodeMemMultipleWritebackInstruction";
2837   }
2838   def IB :
2839     AXI4<(outs), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops),
2840          IndexModeNone, f, itin,
2841          !strconcat(asm, "ib${p}\t$Rn, $regs", sfx), "", []> {
2842     let Inst{24-23} = 0b11;       // Increment Before
2843     let Inst{22}    = P_bit;
2844     let Inst{21}    = 0;          // No writeback
2845     let Inst{20}    = L_bit;
2846   }
2847   def IB_UPD :
2848     AXI4<(outs GPR:$wb), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops),
2849          IndexModeUpd, f, itin_upd,
2850          !strconcat(asm, "ib${p}\t$Rn!, $regs", sfx), "$Rn = $wb", []> {
2851     let Inst{24-23} = 0b11;       // Increment Before
2852     let Inst{22}    = P_bit;
2853     let Inst{21}    = 1;          // Writeback
2854     let Inst{20}    = L_bit;
2855
2856     let DecoderMethod = "DecodeMemMultipleWritebackInstruction";
2857   }
2858 }
2859
2860 let neverHasSideEffects = 1 in {
2861
2862 let mayLoad = 1, hasExtraDefRegAllocReq = 1 in
2863 defm LDM : arm_ldst_mult<"ldm", "", 1, 0, LdStMulFrm, IIC_iLoad_m,
2864                          IIC_iLoad_mu>;
2865
2866 let mayStore = 1, hasExtraSrcRegAllocReq = 1 in
2867 defm STM : arm_ldst_mult<"stm", "", 0, 0, LdStMulFrm, IIC_iStore_m,
2868                          IIC_iStore_mu>;
2869
2870 } // neverHasSideEffects
2871
2872 // FIXME: remove when we have a way to marking a MI with these properties.
2873 // FIXME: Should pc be an implicit operand like PICADD, etc?
2874 let isReturn = 1, isTerminator = 1, isBarrier = 1, mayLoad = 1,
2875     hasExtraDefRegAllocReq = 1, isCodeGenOnly = 1 in
2876 def LDMIA_RET : ARMPseudoExpand<(outs GPR:$wb), (ins GPR:$Rn, pred:$p,
2877                                                  reglist:$regs, variable_ops),
2878                      4, IIC_iLoad_mBr, [],
2879                      (LDMIA_UPD GPR:$wb, GPR:$Rn, pred:$p, reglist:$regs)>,
2880       RegConstraint<"$Rn = $wb">;
2881
2882 let mayLoad = 1, hasExtraDefRegAllocReq = 1 in
2883 defm sysLDM : arm_ldst_mult<"ldm", " ^", 1, 1, LdStMulFrm, IIC_iLoad_m,
2884                                IIC_iLoad_mu>;
2885
2886 let mayStore = 1, hasExtraSrcRegAllocReq = 1 in
2887 defm sysSTM : arm_ldst_mult<"stm", " ^", 0, 1, LdStMulFrm, IIC_iStore_m,
2888                                IIC_iStore_mu>;
2889
2890
2891
2892 //===----------------------------------------------------------------------===//
2893 //  Move Instructions.
2894 //
2895
2896 let neverHasSideEffects = 1 in
2897 def MOVr : AsI1<0b1101, (outs GPR:$Rd), (ins GPR:$Rm), DPFrm, IIC_iMOVr,
2898                 "mov", "\t$Rd, $Rm", []>, UnaryDP {
2899   bits<4> Rd;
2900   bits<4> Rm;
2901
2902   let Inst{19-16} = 0b0000;
2903   let Inst{11-4} = 0b00000000;
2904   let Inst{25} = 0;
2905   let Inst{3-0} = Rm;
2906   let Inst{15-12} = Rd;
2907 }
2908
2909 def : ARMInstAlias<"movs${p} $Rd, $Rm",
2910                    (MOVr GPR:$Rd, GPR:$Rm, pred:$p, CPSR)>;
2911
2912 // A version for the smaller set of tail call registers.
2913 let neverHasSideEffects = 1 in
2914 def MOVr_TC : AsI1<0b1101, (outs tcGPR:$Rd), (ins tcGPR:$Rm), DPFrm,
2915                 IIC_iMOVr, "mov", "\t$Rd, $Rm", []>, UnaryDP {
2916   bits<4> Rd;
2917   bits<4> Rm;
2918
2919   let Inst{11-4} = 0b00000000;
2920   let Inst{25} = 0;
2921   let Inst{3-0} = Rm;
2922   let Inst{15-12} = Rd;
2923 }
2924
2925 def MOVsr : AsI1<0b1101, (outs GPRnopc:$Rd), (ins shift_so_reg_reg:$src),
2926                 DPSoRegRegFrm, IIC_iMOVsr,
2927                 "mov", "\t$Rd, $src",
2928                 [(set GPRnopc:$Rd, shift_so_reg_reg:$src)]>, UnaryDP {
2929   bits<4> Rd;
2930   bits<12> src;
2931   let Inst{15-12} = Rd;
2932   let Inst{19-16} = 0b0000;
2933   let Inst{11-8} = src{11-8};
2934   let Inst{7} = 0;
2935   let Inst{6-5} = src{6-5};
2936   let Inst{4} = 1;
2937   let Inst{3-0} = src{3-0};
2938   let Inst{25} = 0;
2939 }
2940
2941 def MOVsi : AsI1<0b1101, (outs GPR:$Rd), (ins shift_so_reg_imm:$src),
2942                 DPSoRegImmFrm, IIC_iMOVsr,
2943                 "mov", "\t$Rd, $src", [(set GPR:$Rd, shift_so_reg_imm:$src)]>,
2944                 UnaryDP {
2945   bits<4> Rd;
2946   bits<12> src;
2947   let Inst{15-12} = Rd;
2948   let Inst{19-16} = 0b0000;
2949   let Inst{11-5} = src{11-5};
2950   let Inst{4} = 0;
2951   let Inst{3-0} = src{3-0};
2952   let Inst{25} = 0;
2953 }
2954
2955 let isReMaterializable = 1, isAsCheapAsAMove = 1, isMoveImm = 1 in
2956 def MOVi : AsI1<0b1101, (outs GPR:$Rd), (ins so_imm:$imm), DPFrm, IIC_iMOVi,
2957                 "mov", "\t$Rd, $imm", [(set GPR:$Rd, so_imm:$imm)]>, UnaryDP {
2958   bits<4> Rd;
2959   bits<12> imm;
2960   let Inst{25} = 1;
2961   let Inst{15-12} = Rd;
2962   let Inst{19-16} = 0b0000;
2963   let Inst{11-0} = imm;
2964 }
2965
2966 let isReMaterializable = 1, isAsCheapAsAMove = 1, isMoveImm = 1 in
2967 def MOVi16 : AI1<0b1000, (outs GPR:$Rd), (ins imm0_65535_expr:$imm),
2968                  DPFrm, IIC_iMOVi,
2969                  "movw", "\t$Rd, $imm",
2970                  [(set GPR:$Rd, imm0_65535:$imm)]>,
2971                  Requires<[IsARM, HasV6T2]>, UnaryDP {
2972   bits<4> Rd;
2973   bits<16> imm;
2974   let Inst{15-12} = Rd;
2975   let Inst{11-0}  = imm{11-0};
2976   let Inst{19-16} = imm{15-12};
2977   let Inst{20} = 0;
2978   let Inst{25} = 1;
2979   let DecoderMethod = "DecodeArmMOVTWInstruction";
2980 }
2981
2982 def : InstAlias<"mov${p} $Rd, $imm",
2983                 (MOVi16 GPR:$Rd, imm0_65535_expr:$imm, pred:$p)>,
2984         Requires<[IsARM]>;
2985
2986 def MOVi16_ga_pcrel : PseudoInst<(outs GPR:$Rd),
2987                                 (ins i32imm:$addr, pclabel:$id), IIC_iMOVi, []>;
2988
2989 let Constraints = "$src = $Rd" in {
2990 def MOVTi16 : AI1<0b1010, (outs GPRnopc:$Rd),
2991                   (ins GPR:$src, imm0_65535_expr:$imm),
2992                   DPFrm, IIC_iMOVi,
2993                   "movt", "\t$Rd, $imm",
2994                   [(set GPRnopc:$Rd,
2995                         (or (and GPR:$src, 0xffff),
2996                             lo16AllZero:$imm))]>, UnaryDP,
2997                   Requires<[IsARM, HasV6T2]> {
2998   bits<4> Rd;
2999   bits<16> imm;
3000   let Inst{15-12} = Rd;
3001   let Inst{11-0}  = imm{11-0};
3002   let Inst{19-16} = imm{15-12};
3003   let Inst{20} = 0;
3004   let Inst{25} = 1;
3005   let DecoderMethod = "DecodeArmMOVTWInstruction";
3006 }
3007
3008 def MOVTi16_ga_pcrel : PseudoInst<(outs GPR:$Rd),
3009                       (ins GPR:$src, i32imm:$addr, pclabel:$id), IIC_iMOVi, []>;
3010
3011 } // Constraints
3012
3013 def : ARMPat<(or GPR:$src, 0xffff0000), (MOVTi16 GPR:$src, 0xffff)>,
3014       Requires<[IsARM, HasV6T2]>;
3015
3016 let Uses = [CPSR] in
3017 def RRX: PseudoInst<(outs GPR:$Rd), (ins GPR:$Rm), IIC_iMOVsi,
3018                     [(set GPR:$Rd, (ARMrrx GPR:$Rm))]>, UnaryDP,
3019                     Requires<[IsARM]>;
3020
3021 // These aren't really mov instructions, but we have to define them this way
3022 // due to flag operands.
3023
3024 let Defs = [CPSR] in {
3025 def MOVsrl_flag : PseudoInst<(outs GPR:$dst), (ins GPR:$src), IIC_iMOVsi,
3026                       [(set GPR:$dst, (ARMsrl_flag GPR:$src))]>, UnaryDP,
3027                       Requires<[IsARM]>;
3028 def MOVsra_flag : PseudoInst<(outs GPR:$dst), (ins GPR:$src), IIC_iMOVsi,
3029                       [(set GPR:$dst, (ARMsra_flag GPR:$src))]>, UnaryDP,
3030                       Requires<[IsARM]>;
3031 }
3032
3033 //===----------------------------------------------------------------------===//
3034 //  Extend Instructions.
3035 //
3036
3037 // Sign extenders
3038
3039 def SXTB  : AI_ext_rrot<0b01101010,
3040                          "sxtb", UnOpFrag<(sext_inreg node:$Src, i8)>>;
3041 def SXTH  : AI_ext_rrot<0b01101011,
3042                          "sxth", UnOpFrag<(sext_inreg node:$Src, i16)>>;
3043
3044 def SXTAB : AI_exta_rrot<0b01101010,
3045                "sxtab", BinOpFrag<(add node:$LHS, (sext_inreg node:$RHS, i8))>>;
3046 def SXTAH : AI_exta_rrot<0b01101011,
3047                "sxtah", BinOpFrag<(add node:$LHS, (sext_inreg node:$RHS,i16))>>;
3048
3049 def SXTB16  : AI_ext_rrot_np<0b01101000, "sxtb16">;
3050
3051 def SXTAB16 : AI_exta_rrot_np<0b01101000, "sxtab16">;
3052
3053 // Zero extenders
3054
3055 let AddedComplexity = 16 in {
3056 def UXTB   : AI_ext_rrot<0b01101110,
3057                           "uxtb"  , UnOpFrag<(and node:$Src, 0x000000FF)>>;
3058 def UXTH   : AI_ext_rrot<0b01101111,
3059                           "uxth"  , UnOpFrag<(and node:$Src, 0x0000FFFF)>>;
3060 def UXTB16 : AI_ext_rrot<0b01101100,
3061                           "uxtb16", UnOpFrag<(and node:$Src, 0x00FF00FF)>>;
3062
3063 // FIXME: This pattern incorrectly assumes the shl operator is a rotate.
3064 //        The transformation should probably be done as a combiner action
3065 //        instead so we can include a check for masking back in the upper
3066 //        eight bits of the source into the lower eight bits of the result.
3067 //def : ARMV6Pat<(and (shl GPR:$Src, (i32 8)), 0xFF00FF),
3068 //               (UXTB16r_rot GPR:$Src, 3)>;
3069 def : ARMV6Pat<(and (srl GPR:$Src, (i32 8)), 0xFF00FF),
3070                (UXTB16 GPR:$Src, 1)>;
3071
3072 def UXTAB : AI_exta_rrot<0b01101110, "uxtab",
3073                         BinOpFrag<(add node:$LHS, (and node:$RHS, 0x00FF))>>;
3074 def UXTAH : AI_exta_rrot<0b01101111, "uxtah",
3075                         BinOpFrag<(add node:$LHS, (and node:$RHS, 0xFFFF))>>;
3076 }
3077
3078 // This isn't safe in general, the add is two 16-bit units, not a 32-bit add.
3079 def UXTAB16 : AI_exta_rrot_np<0b01101100, "uxtab16">;
3080
3081
3082 def SBFX  : I<(outs GPRnopc:$Rd),
3083               (ins GPRnopc:$Rn, imm0_31:$lsb, imm1_32:$width),
3084                AddrMode1, 4, IndexModeNone, DPFrm, IIC_iUNAsi,
3085                "sbfx", "\t$Rd, $Rn, $lsb, $width", "", []>,
3086                Requires<[IsARM, HasV6T2]> {
3087   bits<4> Rd;
3088   bits<4> Rn;
3089   bits<5> lsb;
3090   bits<5> width;
3091   let Inst{27-21} = 0b0111101;
3092   let Inst{6-4}   = 0b101;
3093   let Inst{20-16} = width;
3094   let Inst{15-12} = Rd;
3095   let Inst{11-7}  = lsb;
3096   let Inst{3-0}   = Rn;
3097 }
3098
3099 def UBFX  : I<(outs GPR:$Rd),
3100               (ins GPR:$Rn, imm0_31:$lsb, imm1_32:$width),
3101                AddrMode1, 4, IndexModeNone, DPFrm, IIC_iUNAsi,
3102                "ubfx", "\t$Rd, $Rn, $lsb, $width", "", []>,
3103                Requires<[IsARM, HasV6T2]> {
3104   bits<4> Rd;
3105   bits<4> Rn;
3106   bits<5> lsb;
3107   bits<5> width;
3108   let Inst{27-21} = 0b0111111;
3109   let Inst{6-4}   = 0b101;
3110   let Inst{20-16} = width;
3111   let Inst{15-12} = Rd;
3112   let Inst{11-7}  = lsb;
3113   let Inst{3-0}   = Rn;
3114 }
3115
3116 //===----------------------------------------------------------------------===//
3117 //  Arithmetic Instructions.
3118 //
3119
3120 defm ADD  : AsI1_bin_irs<0b0100, "add",
3121                          IIC_iALUi, IIC_iALUr, IIC_iALUsr,
3122                          BinOpFrag<(add  node:$LHS, node:$RHS)>, "ADD", 1>;
3123 defm SUB  : AsI1_bin_irs<0b0010, "sub",
3124                          IIC_iALUi, IIC_iALUr, IIC_iALUsr,
3125                          BinOpFrag<(sub  node:$LHS, node:$RHS)>, "SUB">;
3126
3127 // ADD and SUB with 's' bit set.
3128 //
3129 // Currently, ADDS/SUBS are pseudo opcodes that exist only in the
3130 // selection DAG. They are "lowered" to real ADD/SUB opcodes by
3131 // AdjustInstrPostInstrSelection where we determine whether or not to
3132 // set the "s" bit based on CPSR liveness.
3133 //
3134 // FIXME: Eliminate ADDS/SUBS pseudo opcodes after adding tablegen
3135 // support for an optional CPSR definition that corresponds to the DAG
3136 // node's second value. We can then eliminate the implicit def of CPSR.
3137 defm ADDS : AsI1_bin_s_irs<IIC_iALUi, IIC_iALUr, IIC_iALUsr,
3138                            BinOpFrag<(ARMaddc node:$LHS, node:$RHS)>, 1>;
3139 defm SUBS : AsI1_bin_s_irs<IIC_iALUi, IIC_iALUr, IIC_iALUsr,
3140                            BinOpFrag<(ARMsubc node:$LHS, node:$RHS)>>;
3141
3142 defm ADC : AI1_adde_sube_irs<0b0101, "adc",
3143                   BinOpWithFlagFrag<(ARMadde node:$LHS, node:$RHS, node:$FLAG)>,
3144                           "ADC", 1>;
3145 defm SBC : AI1_adde_sube_irs<0b0110, "sbc",
3146                   BinOpWithFlagFrag<(ARMsube node:$LHS, node:$RHS, node:$FLAG)>,
3147                           "SBC">;
3148
3149 defm RSB  : AsI1_rbin_irs <0b0011, "rsb",
3150                          IIC_iALUi, IIC_iALUr, IIC_iALUsr,
3151                          BinOpFrag<(sub node:$LHS, node:$RHS)>, "RSB">;
3152
3153 // FIXME: Eliminate them if we can write def : Pat patterns which defines
3154 // CPSR and the implicit def of CPSR is not needed.
3155 defm RSBS : AsI1_rbin_s_is<IIC_iALUi, IIC_iALUr, IIC_iALUsr,
3156                            BinOpFrag<(ARMsubc node:$LHS, node:$RHS)>>;
3157
3158 defm RSC : AI1_rsc_irs<0b0111, "rsc",
3159                   BinOpWithFlagFrag<(ARMsube node:$LHS, node:$RHS, node:$FLAG)>,
3160                        "RSC">;
3161
3162 // (sub X, imm) gets canonicalized to (add X, -imm).  Match this form.
3163 // The assume-no-carry-in form uses the negation of the input since add/sub
3164 // assume opposite meanings of the carry flag (i.e., carry == !borrow).
3165 // See the definition of AddWithCarry() in the ARM ARM A2.2.1 for the gory
3166 // details.
3167 def : ARMPat<(add     GPR:$src, so_imm_neg:$imm),
3168              (SUBri   GPR:$src, so_imm_neg:$imm)>;
3169 def : ARMPat<(ARMaddc GPR:$src, so_imm_neg:$imm),
3170              (SUBSri  GPR:$src, so_imm_neg:$imm)>;
3171
3172 // The with-carry-in form matches bitwise not instead of the negation.
3173 // Effectively, the inverse interpretation of the carry flag already accounts
3174 // for part of the negation.
3175 def : ARMPat<(ARMadde GPR:$src, so_imm_not:$imm, CPSR),
3176              (SBCri   GPR:$src, so_imm_not:$imm)>;
3177
3178 // Note: These are implemented in C++ code, because they have to generate
3179 // ADD/SUBrs instructions, which use a complex pattern that a xform function
3180 // cannot produce.
3181 // (mul X, 2^n+1) -> (add (X << n), X)
3182 // (mul X, 2^n-1) -> (rsb X, (X << n))
3183
3184 // ARM Arithmetic Instruction
3185 // GPR:$dst = GPR:$a op GPR:$b
3186 class AAI<bits<8> op27_20, bits<8> op11_4, string opc,
3187           list<dag> pattern = [],
3188           dag iops = (ins GPRnopc:$Rn, GPRnopc:$Rm),
3189           string asm = "\t$Rd, $Rn, $Rm">
3190   : AI<(outs GPRnopc:$Rd), iops, DPFrm, IIC_iALUr, opc, asm, pattern> {
3191   bits<4> Rn;
3192   bits<4> Rd;
3193   bits<4> Rm;
3194   let Inst{27-20} = op27_20;
3195   let Inst{11-4} = op11_4;
3196   let Inst{19-16} = Rn;
3197   let Inst{15-12} = Rd;
3198   let Inst{3-0}   = Rm;
3199   
3200   let Unpredictable{11-8} = 0b1111;
3201 }
3202
3203 // Saturating add/subtract
3204
3205 def QADD    : AAI<0b00010000, 0b00000101, "qadd",
3206                   [(set GPRnopc:$Rd, (int_arm_qadd GPRnopc:$Rm, GPRnopc:$Rn))],
3207                   (ins GPRnopc:$Rm, GPRnopc:$Rn), "\t$Rd, $Rm, $Rn">;
3208 def QSUB    : AAI<0b00010010, 0b00000101, "qsub",
3209                   [(set GPRnopc:$Rd, (int_arm_qsub GPRnopc:$Rm, GPRnopc:$Rn))],
3210                   (ins GPRnopc:$Rm, GPRnopc:$Rn), "\t$Rd, $Rm, $Rn">;
3211 def QDADD   : AAI<0b00010100, 0b00000101, "qdadd", [],
3212                   (ins GPRnopc:$Rm, GPRnopc:$Rn),
3213                   "\t$Rd, $Rm, $Rn">;
3214 def QDSUB   : AAI<0b00010110, 0b00000101, "qdsub", [],
3215                   (ins GPRnopc:$Rm, GPRnopc:$Rn),
3216                   "\t$Rd, $Rm, $Rn">;
3217
3218 def QADD16  : AAI<0b01100010, 0b11110001, "qadd16">;
3219 def QADD8   : AAI<0b01100010, 0b11111001, "qadd8">;
3220 def QASX    : AAI<0b01100010, 0b11110011, "qasx">;
3221 def QSAX    : AAI<0b01100010, 0b11110101, "qsax">;
3222 def QSUB16  : AAI<0b01100010, 0b11110111, "qsub16">;
3223 def QSUB8   : AAI<0b01100010, 0b11111111, "qsub8">;
3224 def UQADD16 : AAI<0b01100110, 0b11110001, "uqadd16">;
3225 def UQADD8  : AAI<0b01100110, 0b11111001, "uqadd8">;
3226 def UQASX   : AAI<0b01100110, 0b11110011, "uqasx">;
3227 def UQSAX   : AAI<0b01100110, 0b11110101, "uqsax">;
3228 def UQSUB16 : AAI<0b01100110, 0b11110111, "uqsub16">;
3229 def UQSUB8  : AAI<0b01100110, 0b11111111, "uqsub8">;
3230
3231 // Signed/Unsigned add/subtract
3232
3233 def SASX   : AAI<0b01100001, 0b11110011, "sasx">;
3234 def SADD16 : AAI<0b01100001, 0b11110001, "sadd16">;
3235 def SADD8  : AAI<0b01100001, 0b11111001, "sadd8">;
3236 def SSAX   : AAI<0b01100001, 0b11110101, "ssax">;
3237 def SSUB16 : AAI<0b01100001, 0b11110111, "ssub16">;
3238 def SSUB8  : AAI<0b01100001, 0b11111111, "ssub8">;
3239 def UASX   : AAI<0b01100101, 0b11110011, "uasx">;
3240 def UADD16 : AAI<0b01100101, 0b11110001, "uadd16">;
3241 def UADD8  : AAI<0b01100101, 0b11111001, "uadd8">;
3242 def USAX   : AAI<0b01100101, 0b11110101, "usax">;
3243 def USUB16 : AAI<0b01100101, 0b11110111, "usub16">;
3244 def USUB8  : AAI<0b01100101, 0b11111111, "usub8">;
3245
3246 // Signed/Unsigned halving add/subtract
3247
3248 def SHASX   : AAI<0b01100011, 0b11110011, "shasx">;
3249 def SHADD16 : AAI<0b01100011, 0b11110001, "shadd16">;
3250 def SHADD8  : AAI<0b01100011, 0b11111001, "shadd8">;
3251 def SHSAX   : AAI<0b01100011, 0b11110101, "shsax">;
3252 def SHSUB16 : AAI<0b01100011, 0b11110111, "shsub16">;
3253 def SHSUB8  : AAI<0b01100011, 0b11111111, "shsub8">;
3254 def UHASX   : AAI<0b01100111, 0b11110011, "uhasx">;
3255 def UHADD16 : AAI<0b01100111, 0b11110001, "uhadd16">;
3256 def UHADD8  : AAI<0b01100111, 0b11111001, "uhadd8">;
3257 def UHSAX   : AAI<0b01100111, 0b11110101, "uhsax">;
3258 def UHSUB16 : AAI<0b01100111, 0b11110111, "uhsub16">;
3259 def UHSUB8  : AAI<0b01100111, 0b11111111, "uhsub8">;
3260
3261 // Unsigned Sum of Absolute Differences [and Accumulate].
3262
3263 def USAD8  : AI<(outs GPR:$Rd), (ins GPR:$Rn, GPR:$Rm),
3264                 MulFrm /* for convenience */, NoItinerary, "usad8",
3265                 "\t$Rd, $Rn, $Rm", []>,
3266              Requires<[IsARM, HasV6]> {
3267   bits<4> Rd;
3268   bits<4> Rn;
3269   bits<4> Rm;
3270   let Inst{27-20} = 0b01111000;
3271   let Inst{15-12} = 0b1111;
3272   let Inst{7-4} = 0b0001;
3273   let Inst{19-16} = Rd;
3274   let Inst{11-8} = Rm;
3275   let Inst{3-0} = Rn;
3276 }
3277 def USADA8 : AI<(outs GPR:$Rd), (ins GPR:$Rn, GPR:$Rm, GPR:$Ra),
3278                 MulFrm /* for convenience */, NoItinerary, "usada8",
3279                 "\t$Rd, $Rn, $Rm, $Ra", []>,
3280              Requires<[IsARM, HasV6]> {
3281   bits<4> Rd;
3282   bits<4> Rn;
3283   bits<4> Rm;
3284   bits<4> Ra;
3285   let Inst{27-20} = 0b01111000;
3286   let Inst{7-4} = 0b0001;
3287   let Inst{19-16} = Rd;
3288   let Inst{15-12} = Ra;
3289   let Inst{11-8} = Rm;
3290   let Inst{3-0} = Rn;
3291 }
3292
3293 // Signed/Unsigned saturate
3294
3295 def SSAT : AI<(outs GPRnopc:$Rd),
3296               (ins imm1_32:$sat_imm, GPRnopc:$Rn, shift_imm:$sh),
3297               SatFrm, NoItinerary, "ssat", "\t$Rd, $sat_imm, $Rn$sh", []> {
3298   bits<4> Rd;
3299   bits<5> sat_imm;
3300   bits<4> Rn;
3301   bits<8> sh;
3302   let Inst{27-21} = 0b0110101;
3303   let Inst{5-4} = 0b01;
3304   let Inst{20-16} = sat_imm;
3305   let Inst{15-12} = Rd;
3306   let Inst{11-7} = sh{4-0};
3307   let Inst{6} = sh{5};
3308   let Inst{3-0} = Rn;
3309 }
3310
3311 def SSAT16 : AI<(outs GPRnopc:$Rd),
3312                 (ins imm1_16:$sat_imm, GPRnopc:$Rn), SatFrm,
3313                 NoItinerary, "ssat16", "\t$Rd, $sat_imm, $Rn", []> {
3314   bits<4> Rd;
3315   bits<4> sat_imm;
3316   bits<4> Rn;
3317   let Inst{27-20} = 0b01101010;
3318   let Inst{11-4} = 0b11110011;
3319   let Inst{15-12} = Rd;
3320   let Inst{19-16} = sat_imm;
3321   let Inst{3-0} = Rn;
3322 }
3323
3324 def USAT : AI<(outs GPRnopc:$Rd),
3325               (ins imm0_31:$sat_imm, GPRnopc:$Rn, shift_imm:$sh),
3326               SatFrm, NoItinerary, "usat", "\t$Rd, $sat_imm, $Rn$sh", []> {
3327   bits<4> Rd;
3328   bits<5> sat_imm;
3329   bits<4> Rn;
3330   bits<8> sh;
3331   let Inst{27-21} = 0b0110111;
3332   let Inst{5-4} = 0b01;
3333   let Inst{15-12} = Rd;
3334   let Inst{11-7} = sh{4-0};
3335   let Inst{6} = sh{5};
3336   let Inst{20-16} = sat_imm;
3337   let Inst{3-0} = Rn;
3338 }
3339
3340 def USAT16 : AI<(outs GPRnopc:$Rd),
3341                 (ins imm0_15:$sat_imm, GPRnopc:$Rn), SatFrm,
3342                 NoItinerary, "usat16", "\t$Rd, $sat_imm, $Rn", []> {
3343   bits<4> Rd;
3344   bits<4> sat_imm;
3345   bits<4> Rn;
3346   let Inst{27-20} = 0b01101110;
3347   let Inst{11-4} = 0b11110011;
3348   let Inst{15-12} = Rd;
3349   let Inst{19-16} = sat_imm;
3350   let Inst{3-0} = Rn;
3351 }
3352
3353 def : ARMV6Pat<(int_arm_ssat GPRnopc:$a, imm:$pos),
3354                (SSAT imm:$pos, GPRnopc:$a, 0)>;
3355 def : ARMV6Pat<(int_arm_usat GPRnopc:$a, imm:$pos),
3356                (USAT imm:$pos, GPRnopc:$a, 0)>;
3357
3358 //===----------------------------------------------------------------------===//
3359 //  Bitwise Instructions.
3360 //
3361
3362 defm AND   : AsI1_bin_irs<0b0000, "and",
3363                           IIC_iBITi, IIC_iBITr, IIC_iBITsr,
3364                           BinOpFrag<(and node:$LHS, node:$RHS)>, "AND", 1>;
3365 defm ORR   : AsI1_bin_irs<0b1100, "orr",
3366                           IIC_iBITi, IIC_iBITr, IIC_iBITsr,
3367                           BinOpFrag<(or  node:$LHS, node:$RHS)>, "ORR", 1>;
3368 defm EOR   : AsI1_bin_irs<0b0001, "eor",
3369                           IIC_iBITi, IIC_iBITr, IIC_iBITsr,
3370                           BinOpFrag<(xor node:$LHS, node:$RHS)>, "EOR", 1>;
3371 defm BIC   : AsI1_bin_irs<0b1110, "bic",
3372                           IIC_iBITi, IIC_iBITr, IIC_iBITsr,
3373                           BinOpFrag<(and node:$LHS, (not node:$RHS))>, "BIC">;
3374
3375 // FIXME: bf_inv_mask_imm should be two operands, the lsb and the msb, just
3376 // like in the actual instruction encoding. The complexity of mapping the mask
3377 // to the lsb/msb pair should be handled by ISel, not encapsulated in the
3378 // instruction description.
3379 def BFC    : I<(outs GPR:$Rd), (ins GPR:$src, bf_inv_mask_imm:$imm),
3380                AddrMode1, 4, IndexModeNone, DPFrm, IIC_iUNAsi,
3381                "bfc", "\t$Rd, $imm", "$src = $Rd",
3382                [(set GPR:$Rd, (and GPR:$src, bf_inv_mask_imm:$imm))]>,
3383                Requires<[IsARM, HasV6T2]> {
3384   bits<4> Rd;
3385   bits<10> imm;
3386   let Inst{27-21} = 0b0111110;
3387   let Inst{6-0}   = 0b0011111;
3388   let Inst{15-12} = Rd;
3389   let Inst{11-7}  = imm{4-0}; // lsb
3390   let Inst{20-16} = imm{9-5}; // msb
3391 }
3392
3393 // A8.6.18  BFI - Bitfield insert (Encoding A1)
3394 def BFI:I<(outs GPRnopc:$Rd), (ins GPRnopc:$src, GPR:$Rn, bf_inv_mask_imm:$imm),
3395           AddrMode1, 4, IndexModeNone, DPFrm, IIC_iUNAsi,
3396           "bfi", "\t$Rd, $Rn, $imm", "$src = $Rd",
3397           [(set GPRnopc:$Rd, (ARMbfi GPRnopc:$src, GPR:$Rn,
3398                            bf_inv_mask_imm:$imm))]>,
3399           Requires<[IsARM, HasV6T2]> {
3400   bits<4> Rd;
3401   bits<4> Rn;
3402   bits<10> imm;
3403   let Inst{27-21} = 0b0111110;
3404   let Inst{6-4}   = 0b001; // Rn: Inst{3-0} != 15
3405   let Inst{15-12} = Rd;
3406   let Inst{11-7}  = imm{4-0}; // lsb
3407   let Inst{20-16} = imm{9-5}; // width
3408   let Inst{3-0}   = Rn;
3409 }
3410
3411 def  MVNr  : AsI1<0b1111, (outs GPR:$Rd), (ins GPR:$Rm), DPFrm, IIC_iMVNr,
3412                   "mvn", "\t$Rd, $Rm",
3413                   [(set GPR:$Rd, (not GPR:$Rm))]>, UnaryDP {
3414   bits<4> Rd;
3415   bits<4> Rm;
3416   let Inst{25} = 0;
3417   let Inst{19-16} = 0b0000;
3418   let Inst{11-4} = 0b00000000;
3419   let Inst{15-12} = Rd;
3420   let Inst{3-0} = Rm;
3421 }
3422 def  MVNsi  : AsI1<0b1111, (outs GPR:$Rd), (ins so_reg_imm:$shift),
3423                   DPSoRegImmFrm, IIC_iMVNsr, "mvn", "\t$Rd, $shift",
3424                   [(set GPR:$Rd, (not so_reg_imm:$shift))]>, UnaryDP {
3425   bits<4> Rd;
3426   bits<12> shift;
3427   let Inst{25} = 0;
3428   let Inst{19-16} = 0b0000;
3429   let Inst{15-12} = Rd;
3430   let Inst{11-5} = shift{11-5};
3431   let Inst{4} = 0;
3432   let Inst{3-0} = shift{3-0};
3433 }
3434 def  MVNsr  : AsI1<0b1111, (outs GPR:$Rd), (ins so_reg_reg:$shift),
3435                   DPSoRegRegFrm, IIC_iMVNsr, "mvn", "\t$Rd, $shift",
3436                   [(set GPR:$Rd, (not so_reg_reg:$shift))]>, UnaryDP {
3437   bits<4> Rd;
3438   bits<12> shift;
3439   let Inst{25} = 0;
3440   let Inst{19-16} = 0b0000;
3441   let Inst{15-12} = Rd;
3442   let Inst{11-8} = shift{11-8};
3443   let Inst{7} = 0;
3444   let Inst{6-5} = shift{6-5};
3445   let Inst{4} = 1;
3446   let Inst{3-0} = shift{3-0};
3447 }
3448 let isReMaterializable = 1, isAsCheapAsAMove = 1, isMoveImm = 1 in
3449 def  MVNi  : AsI1<0b1111, (outs GPR:$Rd), (ins so_imm:$imm), DPFrm,
3450                   IIC_iMVNi, "mvn", "\t$Rd, $imm",
3451                   [(set GPR:$Rd, so_imm_not:$imm)]>,UnaryDP {
3452   bits<4> Rd;
3453   bits<12> imm;
3454   let Inst{25} = 1;
3455   let Inst{19-16} = 0b0000;
3456   let Inst{15-12} = Rd;
3457   let Inst{11-0} = imm;
3458 }
3459
3460 def : ARMPat<(and   GPR:$src, so_imm_not:$imm),
3461              (BICri GPR:$src, so_imm_not:$imm)>;
3462
3463 //===----------------------------------------------------------------------===//
3464 //  Multiply Instructions.
3465 //
3466 class AsMul1I32<bits<7> opcod, dag oops, dag iops, InstrItinClass itin,
3467              string opc, string asm, list<dag> pattern>
3468   : AsMul1I<opcod, oops, iops, itin, opc, asm, pattern> {
3469   bits<4> Rd;
3470   bits<4> Rm;
3471   bits<4> Rn;
3472   let Inst{19-16} = Rd;
3473   let Inst{11-8}  = Rm;
3474   let Inst{3-0}   = Rn;
3475 }
3476 class AsMul1I64<bits<7> opcod, dag oops, dag iops, InstrItinClass itin,
3477              string opc, string asm, list<dag> pattern>
3478   : AsMul1I<opcod, oops, iops, itin, opc, asm, pattern> {
3479   bits<4> RdLo;
3480   bits<4> RdHi;
3481   bits<4> Rm;
3482   bits<4> Rn;
3483   let Inst{19-16} = RdHi;
3484   let Inst{15-12} = RdLo;
3485   let Inst{11-8}  = Rm;
3486   let Inst{3-0}   = Rn;
3487 }
3488
3489 // FIXME: The v5 pseudos are only necessary for the additional Constraint
3490 //        property. Remove them when it's possible to add those properties
3491 //        on an individual MachineInstr, not just an instuction description.
3492 let isCommutable = 1 in {
3493 def MUL  : AsMul1I32<0b0000000, (outs GPRnopc:$Rd), (ins GPRnopc:$Rn, GPRnopc:$Rm),
3494                    IIC_iMUL32, "mul", "\t$Rd, $Rn, $Rm",
3495                    [(set GPRnopc:$Rd, (mul GPRnopc:$Rn, GPRnopc:$Rm))]>,
3496                    Requires<[IsARM, HasV6]> {
3497   let Inst{15-12} = 0b0000;
3498   let Unpredictable{15-12} = 0b1111;
3499 }
3500
3501 let Constraints = "@earlyclobber $Rd" in
3502 def MULv5: ARMPseudoExpand<(outs GPRnopc:$Rd), (ins GPRnopc:$Rn, GPRnopc:$Rm,
3503                                             pred:$p, cc_out:$s),
3504                           4, IIC_iMUL32,
3505                          [(set GPRnopc:$Rd, (mul GPRnopc:$Rn, GPRnopc:$Rm))],
3506                          (MUL GPRnopc:$Rd, GPRnopc:$Rn, GPRnopc:$Rm, pred:$p, cc_out:$s)>,
3507                         Requires<[IsARM, NoV6]>;
3508 }
3509
3510 def MLA  : AsMul1I32<0b0000001, (outs GPR:$Rd), (ins GPR:$Rn, GPR:$Rm, GPR:$Ra),
3511                     IIC_iMAC32, "mla", "\t$Rd, $Rn, $Rm, $Ra",
3512                    [(set GPR:$Rd, (add (mul GPR:$Rn, GPR:$Rm), GPR:$Ra))]>,
3513                    Requires<[IsARM, HasV6]> {
3514   bits<4> Ra;
3515   let Inst{15-12} = Ra;
3516 }
3517
3518 let Constraints = "@earlyclobber $Rd" in
3519 def MLAv5: ARMPseudoExpand<(outs GPR:$Rd),
3520                           (ins GPR:$Rn, GPR:$Rm, GPR:$Ra, pred:$p, cc_out:$s),
3521                           4, IIC_iMAC32,
3522                         [(set GPR:$Rd, (add (mul GPR:$Rn, GPR:$Rm), GPR:$Ra))],
3523                   (MLA GPR:$Rd, GPR:$Rn, GPR:$Rm, GPR:$Ra, pred:$p, cc_out:$s)>,
3524                         Requires<[IsARM, NoV6]>;
3525
3526 def MLS  : AMul1I<0b0000011, (outs GPR:$Rd), (ins GPR:$Rn, GPR:$Rm, GPR:$Ra),
3527                    IIC_iMAC32, "mls", "\t$Rd, $Rn, $Rm, $Ra",
3528                    [(set GPR:$Rd, (sub GPR:$Ra, (mul GPR:$Rn, GPR:$Rm)))]>,
3529                    Requires<[IsARM, HasV6T2]> {
3530   bits<4> Rd;
3531   bits<4> Rm;
3532   bits<4> Rn;
3533   bits<4> Ra;
3534   let Inst{19-16} = Rd;
3535   let Inst{15-12} = Ra;
3536   let Inst{11-8}  = Rm;
3537   let Inst{3-0}   = Rn;
3538 }
3539
3540 // Extra precision multiplies with low / high results
3541 let neverHasSideEffects = 1 in {
3542 let isCommutable = 1 in {
3543 def SMULL : AsMul1I64<0b0000110, (outs GPR:$RdLo, GPR:$RdHi),
3544                                  (ins GPR:$Rn, GPR:$Rm), IIC_iMUL64,
3545                     "smull", "\t$RdLo, $RdHi, $Rn, $Rm", []>,
3546                     Requires<[IsARM, HasV6]>;
3547
3548 def UMULL : AsMul1I64<0b0000100, (outs GPR:$RdLo, GPR:$RdHi),
3549                                  (ins GPR:$Rn, GPR:$Rm), IIC_iMUL64,
3550                     "umull", "\t$RdLo, $RdHi, $Rn, $Rm", []>,
3551                     Requires<[IsARM, HasV6]>;
3552
3553 let Constraints = "@earlyclobber $RdLo,@earlyclobber $RdHi" in {
3554 def SMULLv5 : ARMPseudoExpand<(outs GPR:$RdLo, GPR:$RdHi),
3555                             (ins GPR:$Rn, GPR:$Rm, pred:$p, cc_out:$s),
3556                             4, IIC_iMUL64, [],
3557           (SMULL GPR:$RdLo, GPR:$RdHi, GPR:$Rn, GPR:$Rm, pred:$p, cc_out:$s)>,
3558                            Requires<[IsARM, NoV6]>;
3559
3560 def UMULLv5 : ARMPseudoExpand<(outs GPR:$RdLo, GPR:$RdHi),
3561                             (ins GPR:$Rn, GPR:$Rm, pred:$p, cc_out:$s),
3562                             4, IIC_iMUL64, [],
3563           (UMULL GPR:$RdLo, GPR:$RdHi, GPR:$Rn, GPR:$Rm, pred:$p, cc_out:$s)>,
3564                            Requires<[IsARM, NoV6]>;
3565 }
3566 }
3567
3568 // Multiply + accumulate
3569 def SMLAL : AsMul1I64<0b0000111, (outs GPR:$RdLo, GPR:$RdHi),
3570                                (ins GPR:$Rn, GPR:$Rm), IIC_iMAC64,
3571                     "smlal", "\t$RdLo, $RdHi, $Rn, $Rm", []>,
3572                     Requires<[IsARM, HasV6]>;
3573 def UMLAL : AsMul1I64<0b0000101, (outs GPR:$RdLo, GPR:$RdHi),
3574                                (ins GPR:$Rn, GPR:$Rm), IIC_iMAC64,
3575                     "umlal", "\t$RdLo, $RdHi, $Rn, $Rm", []>,
3576                     Requires<[IsARM, HasV6]>;
3577
3578 def UMAAL : AMul1I <0b0000010, (outs GPR:$RdLo, GPR:$RdHi),
3579                                (ins GPR:$Rn, GPR:$Rm), IIC_iMAC64,
3580                     "umaal", "\t$RdLo, $RdHi, $Rn, $Rm", []>,
3581                     Requires<[IsARM, HasV6]> {
3582   bits<4> RdLo;
3583   bits<4> RdHi;
3584   bits<4> Rm;
3585   bits<4> Rn;
3586   let Inst{19-16} = RdHi;
3587   let Inst{15-12} = RdLo;
3588   let Inst{11-8}  = Rm;
3589   let Inst{3-0}   = Rn;
3590 }
3591
3592 let Constraints = "@earlyclobber $RdLo,@earlyclobber $RdHi" in {
3593 def SMLALv5 : ARMPseudoExpand<(outs GPR:$RdLo, GPR:$RdHi),
3594                               (ins GPR:$Rn, GPR:$Rm, pred:$p, cc_out:$s),
3595                               4, IIC_iMAC64, [],
3596           (SMLAL GPR:$RdLo, GPR:$RdHi, GPR:$Rn, GPR:$Rm, pred:$p, cc_out:$s)>,
3597                            Requires<[IsARM, NoV6]>;
3598 def UMLALv5 : ARMPseudoExpand<(outs GPR:$RdLo, GPR:$RdHi),
3599                               (ins GPR:$Rn, GPR:$Rm, pred:$p, cc_out:$s),
3600                               4, IIC_iMAC64, [],
3601           (UMLAL GPR:$RdLo, GPR:$RdHi, GPR:$Rn, GPR:$Rm, pred:$p, cc_out:$s)>,
3602                            Requires<[IsARM, NoV6]>;
3603 def UMAALv5 : ARMPseudoExpand<(outs GPR:$RdLo, GPR:$RdHi),
3604                               (ins GPR:$Rn, GPR:$Rm, pred:$p),
3605                               4, IIC_iMAC64, [],
3606           (UMAAL GPR:$RdLo, GPR:$RdHi, GPR:$Rn, GPR:$Rm, pred:$p)>,
3607                            Requires<[IsARM, NoV6]>;
3608 }
3609
3610 } // neverHasSideEffects
3611
3612 // Most significant word multiply
3613 def SMMUL : AMul2I <0b0111010, 0b0001, (outs GPR:$Rd), (ins GPR:$Rn, GPR:$Rm),
3614                IIC_iMUL32, "smmul", "\t$Rd, $Rn, $Rm",
3615                [(set GPR:$Rd, (mulhs GPR:$Rn, GPR:$Rm))]>,
3616             Requires<[IsARM, HasV6]> {
3617   let Inst{15-12} = 0b1111;
3618 }
3619
3620 def SMMULR : AMul2I <0b0111010, 0b0011, (outs GPR:$Rd), (ins GPR:$Rn, GPR:$Rm),
3621                IIC_iMUL32, "smmulr", "\t$Rd, $Rn, $Rm", []>,
3622             Requires<[IsARM, HasV6]> {
3623   let Inst{15-12} = 0b1111;
3624 }
3625
3626 def SMMLA : AMul2Ia <0b0111010, 0b0001, (outs GPR:$Rd),
3627                (ins GPR:$Rn, GPR:$Rm, GPR:$Ra),
3628                IIC_iMAC32, "smmla", "\t$Rd, $Rn, $Rm, $Ra",
3629                [(set GPR:$Rd, (add (mulhs GPR:$Rn, GPR:$Rm), GPR:$Ra))]>,
3630             Requires<[IsARM, HasV6]>;
3631
3632 def SMMLAR : AMul2Ia <0b0111010, 0b0011, (outs GPR:$Rd),
3633                (ins GPR:$Rn, GPR:$Rm, GPR:$Ra),
3634                IIC_iMAC32, "smmlar", "\t$Rd, $Rn, $Rm, $Ra", []>,
3635             Requires<[IsARM, HasV6]>;
3636
3637 def SMMLS : AMul2Ia <0b0111010, 0b1101, (outs GPR:$Rd),
3638                (ins GPR:$Rn, GPR:$Rm, GPR:$Ra),
3639                IIC_iMAC32, "smmls", "\t$Rd, $Rn, $Rm, $Ra",
3640                [(set GPR:$Rd, (sub GPR:$Ra, (mulhs GPR:$Rn, GPR:$Rm)))]>,
3641             Requires<[IsARM, HasV6]>;
3642
3643 def SMMLSR : AMul2Ia <0b0111010, 0b1111, (outs GPR:$Rd),
3644                (ins GPR:$Rn, GPR:$Rm, GPR:$Ra),
3645                IIC_iMAC32, "smmlsr", "\t$Rd, $Rn, $Rm, $Ra", []>,
3646             Requires<[IsARM, HasV6]>;
3647
3648 multiclass AI_smul<string opc, PatFrag opnode> {
3649   def BB : AMulxyI<0b0001011, 0b00, (outs GPR:$Rd), (ins GPR:$Rn, GPR:$Rm),
3650               IIC_iMUL16, !strconcat(opc, "bb"), "\t$Rd, $Rn, $Rm",
3651               [(set GPR:$Rd, (opnode (sext_inreg GPR:$Rn, i16),
3652                                       (sext_inreg GPR:$Rm, i16)))]>,
3653            Requires<[IsARM, HasV5TE]>;
3654
3655   def BT : AMulxyI<0b0001011, 0b10, (outs GPR:$Rd), (ins GPR:$Rn, GPR:$Rm),
3656               IIC_iMUL16, !strconcat(opc, "bt"), "\t$Rd, $Rn, $Rm",
3657               [(set GPR:$Rd, (opnode (sext_inreg GPR:$Rn, i16),
3658                                       (sra GPR:$Rm, (i32 16))))]>,
3659            Requires<[IsARM, HasV5TE]>;
3660
3661   def TB : AMulxyI<0b0001011, 0b01, (outs GPR:$Rd), (ins GPR:$Rn, GPR:$Rm),
3662               IIC_iMUL16, !strconcat(opc, "tb"), "\t$Rd, $Rn, $Rm",
3663               [(set GPR:$Rd, (opnode (sra GPR:$Rn, (i32 16)),
3664                                       (sext_inreg GPR:$Rm, i16)))]>,
3665            Requires<[IsARM, HasV5TE]>;
3666
3667   def TT : AMulxyI<0b0001011, 0b11, (outs GPR:$Rd), (ins GPR:$Rn, GPR:$Rm),
3668               IIC_iMUL16, !strconcat(opc, "tt"), "\t$Rd, $Rn, $Rm",
3669               [(set GPR:$Rd, (opnode (sra GPR:$Rn, (i32 16)),
3670                                       (sra GPR:$Rm, (i32 16))))]>,
3671             Requires<[IsARM, HasV5TE]>;
3672
3673   def WB : AMulxyI<0b0001001, 0b01, (outs GPR:$Rd), (ins GPR:$Rn, GPR:$Rm),
3674               IIC_iMUL16, !strconcat(opc, "wb"), "\t$Rd, $Rn, $Rm",
3675               [(set GPR:$Rd, (sra (opnode GPR:$Rn,
3676                                     (sext_inreg GPR:$Rm, i16)), (i32 16)))]>,
3677            Requires<[IsARM, HasV5TE]>;
3678
3679   def WT : AMulxyI<0b0001001, 0b11, (outs GPR:$Rd), (ins GPR:$Rn, GPR:$Rm),
3680               IIC_iMUL16, !strconcat(opc, "wt"), "\t$Rd, $Rn, $Rm",
3681               [(set GPR:$Rd, (sra (opnode GPR:$Rn,
3682                                     (sra GPR:$Rm, (i32 16))), (i32 16)))]>,
3683             Requires<[IsARM, HasV5TE]>;
3684 }
3685
3686
3687 multiclass AI_smla<string opc, PatFrag opnode> {
3688   let DecoderMethod = "DecodeSMLAInstruction" in {
3689   def BB : AMulxyIa<0b0001000, 0b00, (outs GPRnopc:$Rd),
3690               (ins GPRnopc:$Rn, GPRnopc:$Rm, GPR:$Ra),
3691               IIC_iMAC16, !strconcat(opc, "bb"), "\t$Rd, $Rn, $Rm, $Ra",
3692               [(set GPRnopc:$Rd, (add GPR:$Ra,
3693                                (opnode (sext_inreg GPRnopc:$Rn, i16),
3694                                        (sext_inreg GPRnopc:$Rm, i16))))]>,
3695            Requires<[IsARM, HasV5TE]>;
3696
3697   def BT : AMulxyIa<0b0001000, 0b10, (outs GPRnopc:$Rd),
3698               (ins GPRnopc:$Rn, GPRnopc:$Rm, GPR:$Ra),
3699               IIC_iMAC16, !strconcat(opc, "bt"), "\t$Rd, $Rn, $Rm, $Ra",
3700               [(set GPRnopc:$Rd,
3701                     (add GPR:$Ra, (opnode (sext_inreg GPRnopc:$Rn, i16),
3702                                           (sra GPRnopc:$Rm, (i32 16)))))]>,
3703            Requires<[IsARM, HasV5TE]>;
3704
3705   def TB : AMulxyIa<0b0001000, 0b01, (outs GPRnopc:$Rd),
3706               (ins GPRnopc:$Rn, GPRnopc:$Rm, GPR:$Ra),
3707               IIC_iMAC16, !strconcat(opc, "tb"), "\t$Rd, $Rn, $Rm, $Ra",
3708               [(set GPRnopc:$Rd,
3709                     (add GPR:$Ra, (opnode (sra GPRnopc:$Rn, (i32 16)),
3710                                           (sext_inreg GPRnopc:$Rm, i16))))]>,
3711            Requires<[IsARM, HasV5TE]>;
3712
3713   def TT : AMulxyIa<0b0001000, 0b11, (outs GPRnopc:$Rd),
3714               (ins GPRnopc:$Rn, GPRnopc:$Rm, GPR:$Ra),
3715               IIC_iMAC16, !strconcat(opc, "tt"), "\t$Rd, $Rn, $Rm, $Ra",
3716              [(set GPRnopc:$Rd,
3717                    (add GPR:$Ra, (opnode (sra GPRnopc:$Rn, (i32 16)),
3718                                          (sra GPRnopc:$Rm, (i32 16)))))]>,
3719             Requires<[IsARM, HasV5TE]>;
3720
3721   def WB : AMulxyIa<0b0001001, 0b00, (outs GPRnopc:$Rd),
3722               (ins GPRnopc:$Rn, GPRnopc:$Rm, GPR:$Ra),
3723               IIC_iMAC16, !strconcat(opc, "wb"), "\t$Rd, $Rn, $Rm, $Ra",
3724               [(set GPRnopc:$Rd,
3725                     (add GPR:$Ra, (sra (opnode GPRnopc:$Rn,
3726                                   (sext_inreg GPRnopc:$Rm, i16)), (i32 16))))]>,
3727            Requires<[IsARM, HasV5TE]>;
3728
3729   def WT : AMulxyIa<0b0001001, 0b10, (outs GPRnopc:$Rd),
3730               (ins GPRnopc:$Rn, GPRnopc:$Rm, GPR:$Ra),
3731               IIC_iMAC16, !strconcat(opc, "wt"), "\t$Rd, $Rn, $Rm, $Ra",
3732               [(set GPRnopc:$Rd,
3733                  (add GPR:$Ra, (sra (opnode GPRnopc:$Rn,
3734                                     (sra GPRnopc:$Rm, (i32 16))), (i32 16))))]>,
3735             Requires<[IsARM, HasV5TE]>;
3736   }
3737 }
3738
3739 defm SMUL : AI_smul<"smul", BinOpFrag<(mul node:$LHS, node:$RHS)>>;
3740 defm SMLA : AI_smla<"smla", BinOpFrag<(mul node:$LHS, node:$RHS)>>;
3741
3742 // Halfword multiply accumulate long: SMLAL<x><y>.
3743 def SMLALBB : AMulxyI64<0b0001010, 0b00, (outs GPRnopc:$RdLo, GPRnopc:$RdHi),
3744                       (ins GPRnopc:$Rn, GPRnopc:$Rm),
3745                       IIC_iMAC64, "smlalbb", "\t$RdLo, $RdHi, $Rn, $Rm", []>,
3746               Requires<[IsARM, HasV5TE]>;
3747
3748 def SMLALBT : AMulxyI64<0b0001010, 0b10, (outs GPRnopc:$RdLo, GPRnopc:$RdHi),
3749                       (ins GPRnopc:$Rn, GPRnopc:$Rm),
3750                       IIC_iMAC64, "smlalbt", "\t$RdLo, $RdHi, $Rn, $Rm", []>,
3751               Requires<[IsARM, HasV5TE]>;
3752
3753 def SMLALTB : AMulxyI64<0b0001010, 0b01, (outs GPRnopc:$RdLo, GPRnopc:$RdHi),
3754                       (ins GPRnopc:$Rn, GPRnopc:$Rm),
3755                       IIC_iMAC64, "smlaltb", "\t$RdLo, $RdHi, $Rn, $Rm", []>,
3756               Requires<[IsARM, HasV5TE]>;
3757
3758 def SMLALTT : AMulxyI64<0b0001010, 0b11, (outs GPRnopc:$RdLo, GPRnopc:$RdHi),
3759                       (ins GPRnopc:$Rn, GPRnopc:$Rm),
3760                       IIC_iMAC64, "smlaltt", "\t$RdLo, $RdHi, $Rn, $Rm", []>,
3761               Requires<[IsARM, HasV5TE]>;
3762
3763 // Helper class for AI_smld.
3764 class AMulDualIbase<bit long, bit sub, bit swap, dag oops, dag iops,
3765                     InstrItinClass itin, string opc, string asm>
3766   : AI<oops, iops, MulFrm, itin, opc, asm, []>, Requires<[IsARM, HasV6]> {
3767   bits<4> Rn;
3768   bits<4> Rm;
3769   let Inst{27-23} = 0b01110;
3770   let Inst{22}    = long;
3771   let Inst{21-20} = 0b00;
3772   let Inst{11-8}  = Rm;
3773   let Inst{7}     = 0;
3774   let Inst{6}     = sub;
3775   let Inst{5}     = swap;
3776   let Inst{4}     = 1;
3777   let Inst{3-0}   = Rn;
3778 }
3779 class AMulDualI<bit long, bit sub, bit swap, dag oops, dag iops,
3780                 InstrItinClass itin, string opc, string asm>
3781   : AMulDualIbase<long, sub, swap, oops, iops, itin, opc, asm> {
3782   bits<4> Rd;
3783   let Inst{15-12} = 0b1111;
3784   let Inst{19-16} = Rd;
3785 }
3786 class AMulDualIa<bit long, bit sub, bit swap, dag oops, dag iops,
3787                 InstrItinClass itin, string opc, string asm>
3788   : AMulDualIbase<long, sub, swap, oops, iops, itin, opc, asm> {
3789   bits<4> Ra;
3790   bits<4> Rd;
3791   let Inst{19-16} = Rd;
3792   let Inst{15-12} = Ra;
3793 }
3794 class AMulDualI64<bit long, bit sub, bit swap, dag oops, dag iops,
3795                   InstrItinClass itin, string opc, string asm>
3796   : AMulDualIbase<long, sub, swap, oops, iops, itin, opc, asm> {
3797   bits<4> RdLo;
3798   bits<4> RdHi;
3799   let Inst{19-16} = RdHi;
3800   let Inst{15-12} = RdLo;
3801 }
3802
3803 multiclass AI_smld<bit sub, string opc> {
3804
3805   def D : AMulDualIa<0, sub, 0, (outs GPRnopc:$Rd),
3806                   (ins GPRnopc:$Rn, GPRnopc:$Rm, GPR:$Ra),
3807                   NoItinerary, !strconcat(opc, "d"), "\t$Rd, $Rn, $Rm, $Ra">;
3808
3809   def DX: AMulDualIa<0, sub, 1, (outs GPRnopc:$Rd),
3810                   (ins GPRnopc:$Rn, GPRnopc:$Rm, GPR:$Ra),
3811                   NoItinerary, !strconcat(opc, "dx"), "\t$Rd, $Rn, $Rm, $Ra">;
3812
3813   def LD: AMulDualI64<1, sub, 0, (outs GPRnopc:$RdLo, GPRnopc:$RdHi),
3814                   (ins GPRnopc:$Rn, GPRnopc:$Rm), NoItinerary,
3815                   !strconcat(opc, "ld"), "\t$RdLo, $RdHi, $Rn, $Rm">;
3816
3817   def LDX : AMulDualI64<1, sub, 1, (outs GPRnopc:$RdLo, GPRnopc:$RdHi),
3818                   (ins GPRnopc:$Rn, GPRnopc:$Rm), NoItinerary,
3819                   !strconcat(opc, "ldx"),"\t$RdLo, $RdHi, $Rn, $Rm">;
3820
3821 }
3822
3823 defm SMLA : AI_smld<0, "smla">;
3824 defm SMLS : AI_smld<1, "smls">;
3825
3826 multiclass AI_sdml<bit sub, string opc> {
3827
3828   def D:AMulDualI<0, sub, 0, (outs GPRnopc:$Rd), (ins GPRnopc:$Rn, GPRnopc:$Rm),
3829                   NoItinerary, !strconcat(opc, "d"), "\t$Rd, $Rn, $Rm">;
3830   def DX:AMulDualI<0, sub, 1, (outs GPRnopc:$Rd),(ins GPRnopc:$Rn, GPRnopc:$Rm),
3831                   NoItinerary, !strconcat(opc, "dx"), "\t$Rd, $Rn, $Rm">;
3832 }
3833
3834 defm SMUA : AI_sdml<0, "smua">;
3835 defm SMUS : AI_sdml<1, "smus">;
3836
3837 //===----------------------------------------------------------------------===//
3838 //  Misc. Arithmetic Instructions.
3839 //
3840
3841 def CLZ  : AMiscA1I<0b000010110, 0b0001, (outs GPR:$Rd), (ins GPR:$Rm),
3842               IIC_iUNAr, "clz", "\t$Rd, $Rm",
3843               [(set GPR:$Rd, (ctlz GPR:$Rm))]>, Requires<[IsARM, HasV5T]>;
3844
3845 def RBIT : AMiscA1I<0b01101111, 0b0011, (outs GPR:$Rd), (ins GPR:$Rm),
3846               IIC_iUNAr, "rbit", "\t$Rd, $Rm",
3847               [(set GPR:$Rd, (ARMrbit GPR:$Rm))]>,
3848            Requires<[IsARM, HasV6T2]>;
3849
3850 def REV  : AMiscA1I<0b01101011, 0b0011, (outs GPR:$Rd), (ins GPR:$Rm),
3851               IIC_iUNAr, "rev", "\t$Rd, $Rm",
3852               [(set GPR:$Rd, (bswap GPR:$Rm))]>, Requires<[IsARM, HasV6]>;
3853
3854 let AddedComplexity = 5 in
3855 def REV16 : AMiscA1I<0b01101011, 0b1011, (outs GPR:$Rd), (ins GPR:$Rm),
3856                IIC_iUNAr, "rev16", "\t$Rd, $Rm",
3857                [(set GPR:$Rd, (rotr (bswap GPR:$Rm), (i32 16)))]>,
3858                Requires<[IsARM, HasV6]>;
3859
3860 let AddedComplexity = 5 in
3861 def REVSH : AMiscA1I<0b01101111, 0b1011, (outs GPR:$Rd), (ins GPR:$Rm),
3862                IIC_iUNAr, "revsh", "\t$Rd, $Rm",
3863                [(set GPR:$Rd, (sra (bswap GPR:$Rm), (i32 16)))]>,
3864                Requires<[IsARM, HasV6]>;
3865
3866 def : ARMV6Pat<(or (sra (shl GPR:$Rm, (i32 24)), (i32 16)),
3867                    (and (srl GPR:$Rm, (i32 8)), 0xFF)),
3868                (REVSH GPR:$Rm)>;
3869
3870 def PKHBT : APKHI<0b01101000, 0, (outs GPRnopc:$Rd),
3871                               (ins GPRnopc:$Rn, GPRnopc:$Rm, pkh_lsl_amt:$sh),
3872                IIC_iALUsi, "pkhbt", "\t$Rd, $Rn, $Rm$sh",
3873                [(set GPRnopc:$Rd, (or (and GPRnopc:$Rn, 0xFFFF),
3874                                       (and (shl GPRnopc:$Rm, pkh_lsl_amt:$sh),
3875                                            0xFFFF0000)))]>,
3876                Requires<[IsARM, HasV6]>;
3877
3878 // Alternate cases for PKHBT where identities eliminate some nodes.
3879 def : ARMV6Pat<(or (and GPRnopc:$Rn, 0xFFFF), (and GPRnopc:$Rm, 0xFFFF0000)),
3880                (PKHBT GPRnopc:$Rn, GPRnopc:$Rm, 0)>;
3881 def : ARMV6Pat<(or (and GPRnopc:$Rn, 0xFFFF), (shl GPRnopc:$Rm, imm16_31:$sh)),
3882                (PKHBT GPRnopc:$Rn, GPRnopc:$Rm, imm16_31:$sh)>;
3883
3884 // Note: Shifts of 1-15 bits will be transformed to srl instead of sra and
3885 // will match the pattern below.
3886 def PKHTB : APKHI<0b01101000, 1, (outs GPRnopc:$Rd),
3887                               (ins GPRnopc:$Rn, GPRnopc:$Rm, pkh_asr_amt:$sh),
3888                IIC_iBITsi, "pkhtb", "\t$Rd, $Rn, $Rm$sh",
3889                [(set GPRnopc:$Rd, (or (and GPRnopc:$Rn, 0xFFFF0000),
3890                                       (and (sra GPRnopc:$Rm, pkh_asr_amt:$sh),
3891                                            0xFFFF)))]>,
3892                Requires<[IsARM, HasV6]>;
3893
3894 // Alternate cases for PKHTB where identities eliminate some nodes.  Note that
3895 // a shift amount of 0 is *not legal* here, it is PKHBT instead.
3896 def : ARMV6Pat<(or (and GPRnopc:$src1, 0xFFFF0000),
3897                    (srl GPRnopc:$src2, imm16_31:$sh)),
3898                (PKHTB GPRnopc:$src1, GPRnopc:$src2, imm16_31:$sh)>;
3899 def : ARMV6Pat<(or (and GPRnopc:$src1, 0xFFFF0000),
3900                    (and (srl GPRnopc:$src2, imm1_15:$sh), 0xFFFF)),
3901                (PKHTB GPRnopc:$src1, GPRnopc:$src2, imm1_15:$sh)>;
3902
3903 //===----------------------------------------------------------------------===//
3904 //  Comparison Instructions...
3905 //
3906
3907 defm CMP  : AI1_cmp_irs<0b1010, "cmp",
3908                         IIC_iCMPi, IIC_iCMPr, IIC_iCMPsr,
3909                         BinOpFrag<(ARMcmp node:$LHS, node:$RHS)>>;
3910
3911 // ARMcmpZ can re-use the above instruction definitions.
3912 def : ARMPat<(ARMcmpZ GPR:$src, so_imm:$imm),
3913              (CMPri   GPR:$src, so_imm:$imm)>;
3914 def : ARMPat<(ARMcmpZ GPR:$src, GPR:$rhs),
3915              (CMPrr   GPR:$src, GPR:$rhs)>;
3916 def : ARMPat<(ARMcmpZ GPR:$src, so_reg_imm:$rhs),
3917              (CMPrsi   GPR:$src, so_reg_imm:$rhs)>;
3918 def : ARMPat<(ARMcmpZ GPR:$src, so_reg_reg:$rhs),
3919              (CMPrsr   GPR:$src, so_reg_reg:$rhs)>;
3920
3921 // FIXME: We have to be careful when using the CMN instruction and comparison
3922 // with 0. One would expect these two pieces of code should give identical
3923 // results:
3924 //
3925 //   rsbs r1, r1, 0
3926 //   cmp  r0, r1
3927 //   mov  r0, #0
3928 //   it   ls
3929 //   mov  r0, #1
3930 //
3931 // and:
3932 //
3933 //   cmn  r0, r1
3934 //   mov  r0, #0
3935 //   it   ls
3936 //   mov  r0, #1
3937 //
3938 // However, the CMN gives the *opposite* result when r1 is 0. This is because
3939 // the carry flag is set in the CMP case but not in the CMN case. In short, the
3940 // CMP instruction doesn't perform a truncate of the (logical) NOT of 0 plus the
3941 // value of r0 and the carry bit (because the "carry bit" parameter to
3942 // AddWithCarry is defined as 1 in this case, the carry flag will always be set
3943 // when r0 >= 0). The CMN instruction doesn't perform a NOT of 0 so there is
3944 // never a "carry" when this AddWithCarry is performed (because the "carry bit"
3945 // parameter to AddWithCarry is defined as 0).
3946 //
3947 // When x is 0 and unsigned:
3948 //
3949 //    x = 0
3950 //   ~x = 0xFFFF FFFF
3951 //   ~x + 1 = 0x1 0000 0000
3952 //   (-x = 0) != (0x1 0000 0000 = ~x + 1)
3953 //
3954 // Therefore, we should disable CMN when comparing against zero, until we can
3955 // limit when the CMN instruction is used (when we know that the RHS is not 0 or
3956 // when it's a comparison which doesn't look at the 'carry' flag).
3957 //
3958 // (See the ARM docs for the "AddWithCarry" pseudo-code.)
3959 //
3960 // This is related to <rdar://problem/7569620>.
3961 //
3962 //defm CMN  : AI1_cmp_irs<0b1011, "cmn",
3963 //                        BinOpFrag<(ARMcmp node:$LHS,(ineg node:$RHS))>>;
3964
3965 // Note that TST/TEQ don't set all the same flags that CMP does!
3966 defm TST  : AI1_cmp_irs<0b1000, "tst",
3967                         IIC_iTSTi, IIC_iTSTr, IIC_iTSTsr,
3968                       BinOpFrag<(ARMcmpZ (and_su node:$LHS, node:$RHS), 0)>, 1>;
3969 defm TEQ  : AI1_cmp_irs<0b1001, "teq",
3970                         IIC_iTSTi, IIC_iTSTr, IIC_iTSTsr,
3971                       BinOpFrag<(ARMcmpZ (xor_su node:$LHS, node:$RHS), 0)>, 1>;
3972
3973 defm CMNz  : AI1_cmp_irs<0b1011, "cmn",
3974                          IIC_iCMPi, IIC_iCMPr, IIC_iCMPsr,
3975                          BinOpFrag<(ARMcmpZ node:$LHS,(ineg node:$RHS))>>;
3976
3977 //def : ARMPat<(ARMcmp GPR:$src, so_imm_neg:$imm),
3978 //             (CMNri  GPR:$src, so_imm_neg:$imm)>;
3979
3980 def : ARMPat<(ARMcmpZ GPR:$src, so_imm_neg:$imm),
3981              (CMNzri  GPR:$src, so_imm_neg:$imm)>;
3982
3983 // Pseudo i64 compares for some floating point compares.
3984 let usesCustomInserter = 1, isBranch = 1, isTerminator = 1,
3985     Defs = [CPSR] in {
3986 def BCCi64 : PseudoInst<(outs),
3987     (ins i32imm:$cc, GPR:$lhs1, GPR:$lhs2, GPR:$rhs1, GPR:$rhs2, brtarget:$dst),
3988      IIC_Br,
3989     [(ARMBcci64 imm:$cc, GPR:$lhs1, GPR:$lhs2, GPR:$rhs1, GPR:$rhs2, bb:$dst)]>;
3990
3991 def BCCZi64 : PseudoInst<(outs),
3992      (ins i32imm:$cc, GPR:$lhs1, GPR:$lhs2, brtarget:$dst), IIC_Br,
3993     [(ARMBcci64 imm:$cc, GPR:$lhs1, GPR:$lhs2, 0, 0, bb:$dst)]>;
3994 } // usesCustomInserter
3995
3996
3997 // Conditional moves
3998 // FIXME: should be able to write a pattern for ARMcmov, but can't use
3999 // a two-value operand where a dag node expects two operands. :(
4000 let neverHasSideEffects = 1 in {
4001
4002 let isCommutable = 1 in
4003 def MOVCCr : ARMPseudoInst<(outs GPR:$Rd), (ins GPR:$false, GPR:$Rm, pred:$p),
4004                            4, IIC_iCMOVr,
4005   [/*(set GPR:$Rd, (ARMcmov GPR:$false, GPR:$Rm, imm:$cc, CCR:$ccr))*/]>,
4006       RegConstraint<"$false = $Rd">;
4007
4008 def MOVCCsi : ARMPseudoInst<(outs GPR:$Rd),
4009                            (ins GPR:$false, so_reg_imm:$shift, pred:$p),
4010                            4, IIC_iCMOVsr,
4011   [/*(set GPR:$Rd, (ARMcmov GPR:$false, so_reg_imm:$shift,
4012                             imm:$cc, CCR:$ccr))*/]>,
4013       RegConstraint<"$false = $Rd">;
4014 def MOVCCsr : ARMPseudoInst<(outs GPR:$Rd),
4015                            (ins GPR:$false, so_reg_reg:$shift, pred:$p),
4016                            4, IIC_iCMOVsr,
4017   [/*(set GPR:$Rd, (ARMcmov GPR:$false, so_reg_reg:$shift,
4018                             imm:$cc, CCR:$ccr))*/]>,
4019       RegConstraint<"$false = $Rd">;
4020
4021
4022 let isMoveImm = 1 in
4023 def MOVCCi16 : ARMPseudoInst<(outs GPR:$Rd),
4024                              (ins GPR:$false, imm0_65535_expr:$imm, pred:$p),
4025                              4, IIC_iMOVi,
4026                              []>,
4027       RegConstraint<"$false = $Rd">, Requires<[IsARM, HasV6T2]>;
4028
4029 let isMoveImm = 1 in
4030 def MOVCCi : ARMPseudoInst<(outs GPR:$Rd),
4031                            (ins GPR:$false, so_imm:$imm, pred:$p),
4032                            4, IIC_iCMOVi,
4033    [/*(set GPR:$Rd, (ARMcmov GPR:$false, so_imm:$imm, imm:$cc, CCR:$ccr))*/]>,
4034       RegConstraint<"$false = $Rd">;
4035
4036 // Two instruction predicate mov immediate.
4037 let isMoveImm = 1 in
4038 def MOVCCi32imm : ARMPseudoInst<(outs GPR:$Rd),
4039                                 (ins GPR:$false, i32imm:$src, pred:$p),
4040                   8, IIC_iCMOVix2, []>, RegConstraint<"$false = $Rd">;
4041
4042 let isMoveImm = 1 in
4043 def MVNCCi : ARMPseudoInst<(outs GPR:$Rd),
4044                            (ins GPR:$false, so_imm:$imm, pred:$p),
4045                            4, IIC_iCMOVi,
4046  [/*(set GPR:$Rd, (ARMcmov GPR:$false, so_imm_not:$imm, imm:$cc, CCR:$ccr))*/]>,
4047                 RegConstraint<"$false = $Rd">;
4048
4049 // Conditional instructions
4050 multiclass AsI1_bincc_irs<Instruction iri, Instruction irr, Instruction irsi,
4051                           Instruction irsr,
4052                           InstrItinClass iii, InstrItinClass iir,
4053                           InstrItinClass iis> {
4054   def ri  : ARMPseudoExpand<(outs GPR:$Rd),
4055                             (ins GPR:$Rn, so_imm:$imm, pred:$p, cc_out:$s),
4056                             4, iii, [],
4057                        (iri GPR:$Rd, GPR:$Rn, so_imm:$imm, pred:$p, cc_out:$s)>,
4058                             RegConstraint<"$Rn = $Rd">;
4059   def rr  : ARMPseudoExpand<(outs GPR:$Rd),
4060                             (ins GPR:$Rn, GPR:$Rm, pred:$p, cc_out:$s),
4061                             4, iir, [],
4062                            (irr GPR:$Rd, GPR:$Rn, GPR:$Rm, pred:$p, cc_out:$s)>,
4063                             RegConstraint<"$Rn = $Rd">;
4064   def rsi : ARMPseudoExpand<(outs GPR:$Rd),
4065                            (ins GPR:$Rn, so_reg_imm:$shift, pred:$p, cc_out:$s),
4066                             4, iis, [],
4067                 (irsi GPR:$Rd, GPR:$Rn, so_reg_imm:$shift, pred:$p, cc_out:$s)>,
4068                             RegConstraint<"$Rn = $Rd">;
4069   def rsr : ARMPseudoExpand<(outs GPRnopc:$Rd),
4070                        (ins GPRnopc:$Rn, so_reg_reg:$shift, pred:$p, cc_out:$s),
4071                             4, iis, [],
4072                 (irsr GPR:$Rd, GPR:$Rn, so_reg_reg:$shift, pred:$p, cc_out:$s)>,
4073                             RegConstraint<"$Rn = $Rd">;
4074 }
4075
4076 defm ANDCC : AsI1_bincc_irs<ANDri, ANDrr, ANDrsi, ANDrsr,
4077                             IIC_iBITi, IIC_iBITr, IIC_iBITsr>;
4078 defm ORRCC : AsI1_bincc_irs<ORRri, ORRrr, ORRrsi, ORRrsr,
4079                             IIC_iBITi, IIC_iBITr, IIC_iBITsr>;
4080 defm EORCC : AsI1_bincc_irs<EORri, EORrr, EORrsi, EORrsr,
4081                             IIC_iBITi, IIC_iBITr, IIC_iBITsr>;
4082
4083 } // neverHasSideEffects
4084
4085
4086 //===----------------------------------------------------------------------===//
4087 // Atomic operations intrinsics
4088 //
4089
4090 def MemBarrierOptOperand : AsmOperandClass {
4091   let Name = "MemBarrierOpt";
4092   let ParserMethod = "parseMemBarrierOptOperand";
4093 }
4094 def memb_opt : Operand<i32> {
4095   let PrintMethod = "printMemBOption";
4096   let ParserMatchClass = MemBarrierOptOperand;
4097   let DecoderMethod = "DecodeMemBarrierOption";
4098 }
4099
4100 // memory barriers protect the atomic sequences
4101 let hasSideEffects = 1 in {
4102 def DMB : AInoP<(outs), (ins memb_opt:$opt), MiscFrm, NoItinerary,
4103                 "dmb", "\t$opt", [(ARMMemBarrier (i32 imm:$opt))]>,
4104                 Requires<[IsARM, HasDB]> {
4105   bits<4> opt;
4106   let Inst{31-4} = 0xf57ff05;
4107   let Inst{3-0} = opt;
4108 }
4109 }
4110
4111 def DSB : AInoP<(outs), (ins memb_opt:$opt), MiscFrm, NoItinerary,
4112                 "dsb", "\t$opt", []>,
4113                 Requires<[IsARM, HasDB]> {
4114   bits<4> opt;
4115   let Inst{31-4} = 0xf57ff04;
4116   let Inst{3-0} = opt;
4117 }
4118
4119 // ISB has only full system option
4120 def ISB : AInoP<(outs), (ins memb_opt:$opt), MiscFrm, NoItinerary,
4121                 "isb", "\t$opt", []>,
4122                 Requires<[IsARM, HasDB]> {
4123   bits<4> opt;
4124   let Inst{31-4} = 0xf57ff06;
4125   let Inst{3-0} = opt;
4126 }
4127
4128 // Pseudo isntruction that combines movs + predicated rsbmi
4129 // to implement integer ABS
4130 let usesCustomInserter = 1, Defs = [CPSR] in {
4131 def ABS : ARMPseudoInst<
4132   (outs GPR:$dst), (ins GPR:$src),
4133   8, NoItinerary, []>;
4134 }
4135
4136 let usesCustomInserter = 1 in {
4137   let Defs = [CPSR] in {
4138     def ATOMIC_LOAD_ADD_I8 : PseudoInst<
4139       (outs GPR:$dst), (ins GPR:$ptr, GPR:$incr), NoItinerary,
4140       [(set GPR:$dst, (atomic_load_add_8 GPR:$ptr, GPR:$incr))]>;
4141     def ATOMIC_LOAD_SUB_I8 : PseudoInst<
4142       (outs GPR:$dst), (ins GPR:$ptr, GPR:$incr), NoItinerary,
4143       [(set GPR:$dst, (atomic_load_sub_8 GPR:$ptr, GPR:$incr))]>;
4144     def ATOMIC_LOAD_AND_I8 : PseudoInst<
4145       (outs GPR:$dst), (ins GPR:$ptr, GPR:$incr), NoItinerary,
4146       [(set GPR:$dst, (atomic_load_and_8 GPR:$ptr, GPR:$incr))]>;
4147     def ATOMIC_LOAD_OR_I8 : PseudoInst<
4148       (outs GPR:$dst), (ins GPR:$ptr, GPR:$incr), NoItinerary,
4149       [(set GPR:$dst, (atomic_load_or_8 GPR:$ptr, GPR:$incr))]>;
4150     def ATOMIC_LOAD_XOR_I8 : PseudoInst<
4151       (outs GPR:$dst), (ins GPR:$ptr, GPR:$incr), NoItinerary,
4152       [(set GPR:$dst, (atomic_load_xor_8 GPR:$ptr, GPR:$incr))]>;
4153     def ATOMIC_LOAD_NAND_I8 : PseudoInst<
4154       (outs GPR:$dst), (ins GPR:$ptr, GPR:$incr), NoItinerary,
4155       [(set GPR:$dst, (atomic_load_nand_8 GPR:$ptr, GPR:$incr))]>;
4156     def ATOMIC_LOAD_MIN_I8 : PseudoInst<
4157       (outs GPR:$dst), (ins GPR:$ptr, GPR:$val), NoItinerary,
4158       [(set GPR:$dst, (atomic_load_min_8 GPR:$ptr, GPR:$val))]>;
4159     def ATOMIC_LOAD_MAX_I8 : PseudoInst<
4160       (outs GPR:$dst), (ins GPR:$ptr, GPR:$val), NoItinerary,
4161       [(set GPR:$dst, (atomic_load_max_8 GPR:$ptr, GPR:$val))]>;
4162     def ATOMIC_LOAD_UMIN_I8 : PseudoInst<
4163       (outs GPR:$dst), (ins GPR:$ptr, GPR:$val), NoItinerary,
4164       [(set GPR:$dst, (atomic_load_umin_8 GPR:$ptr, GPR:$val))]>;
4165     def ATOMIC_LOAD_UMAX_I8 : PseudoInst<
4166       (outs GPR:$dst), (ins GPR:$ptr, GPR:$val), NoItinerary,
4167       [(set GPR:$dst, (atomic_load_umax_8 GPR:$ptr, GPR:$val))]>;
4168     def ATOMIC_LOAD_ADD_I16 : PseudoInst<
4169       (outs GPR:$dst), (ins GPR:$ptr, GPR:$incr), NoItinerary,
4170       [(set GPR:$dst, (atomic_load_add_16 GPR:$ptr, GPR:$incr))]>;
4171     def ATOMIC_LOAD_SUB_I16 : PseudoInst<
4172       (outs GPR:$dst), (ins GPR:$ptr, GPR:$incr), NoItinerary,
4173       [(set GPR:$dst, (atomic_load_sub_16 GPR:$ptr, GPR:$incr))]>;
4174     def ATOMIC_LOAD_AND_I16 : PseudoInst<
4175       (outs GPR:$dst), (ins GPR:$ptr, GPR:$incr), NoItinerary,
4176       [(set GPR:$dst, (atomic_load_and_16 GPR:$ptr, GPR:$incr))]>;
4177     def ATOMIC_LOAD_OR_I16 : PseudoInst<
4178       (outs GPR:$dst), (ins GPR:$ptr, GPR:$incr), NoItinerary,
4179       [(set GPR:$dst, (atomic_load_or_16 GPR:$ptr, GPR:$incr))]>;
4180     def ATOMIC_LOAD_XOR_I16 : PseudoInst<
4181       (outs GPR:$dst), (ins GPR:$ptr, GPR:$incr), NoItinerary,
4182       [(set GPR:$dst, (atomic_load_xor_16 GPR:$ptr, GPR:$incr))]>;
4183     def ATOMIC_LOAD_NAND_I16 : PseudoInst<
4184       (outs GPR:$dst), (ins GPR:$ptr, GPR:$incr), NoItinerary,
4185       [(set GPR:$dst, (atomic_load_nand_16 GPR:$ptr, GPR:$incr))]>;
4186     def ATOMIC_LOAD_MIN_I16 : PseudoInst<
4187       (outs GPR:$dst), (ins GPR:$ptr, GPR:$val), NoItinerary,
4188       [(set GPR:$dst, (atomic_load_min_16 GPR:$ptr, GPR:$val))]>;
4189     def ATOMIC_LOAD_MAX_I16 : PseudoInst<
4190       (outs GPR:$dst), (ins GPR:$ptr, GPR:$val), NoItinerary,
4191       [(set GPR:$dst, (atomic_load_max_16 GPR:$ptr, GPR:$val))]>;
4192     def ATOMIC_LOAD_UMIN_I16 : PseudoInst<
4193       (outs GPR:$dst), (ins GPR:$ptr, GPR:$val), NoItinerary,
4194       [(set GPR:$dst, (atomic_load_umin_16 GPR:$ptr, GPR:$val))]>;
4195     def ATOMIC_LOAD_UMAX_I16 : PseudoInst<
4196       (outs GPR:$dst), (ins GPR:$ptr, GPR:$val), NoItinerary,
4197       [(set GPR:$dst, (atomic_load_umax_16 GPR:$ptr, GPR:$val))]>;
4198     def ATOMIC_LOAD_ADD_I32 : PseudoInst<
4199       (outs GPR:$dst), (ins GPR:$ptr, GPR:$incr), NoItinerary,
4200       [(set GPR:$dst, (atomic_load_add_32 GPR:$ptr, GPR:$incr))]>;
4201     def ATOMIC_LOAD_SUB_I32 : PseudoInst<
4202       (outs GPR:$dst), (ins GPR:$ptr, GPR:$incr), NoItinerary,
4203       [(set GPR:$dst, (atomic_load_sub_32 GPR:$ptr, GPR:$incr))]>;
4204     def ATOMIC_LOAD_AND_I32 : PseudoInst<
4205       (outs GPR:$dst), (ins GPR:$ptr, GPR:$incr), NoItinerary,
4206       [(set GPR:$dst, (atomic_load_and_32 GPR:$ptr, GPR:$incr))]>;
4207     def ATOMIC_LOAD_OR_I32 : PseudoInst<
4208       (outs GPR:$dst), (ins GPR:$ptr, GPR:$incr), NoItinerary,
4209       [(set GPR:$dst, (atomic_load_or_32 GPR:$ptr, GPR:$incr))]>;
4210     def ATOMIC_LOAD_XOR_I32 : PseudoInst<
4211       (outs GPR:$dst), (ins GPR:$ptr, GPR:$incr), NoItinerary,
4212       [(set GPR:$dst, (atomic_load_xor_32 GPR:$ptr, GPR:$incr))]>;
4213     def ATOMIC_LOAD_NAND_I32 : PseudoInst<
4214       (outs GPR:$dst), (ins GPR:$ptr, GPR:$incr), NoItinerary,
4215       [(set GPR:$dst, (atomic_load_nand_32 GPR:$ptr, GPR:$incr))]>;
4216     def ATOMIC_LOAD_MIN_I32 : PseudoInst<
4217       (outs GPR:$dst), (ins GPR:$ptr, GPR:$val), NoItinerary,
4218       [(set GPR:$dst, (atomic_load_min_32 GPR:$ptr, GPR:$val))]>;
4219     def ATOMIC_LOAD_MAX_I32 : PseudoInst<
4220       (outs GPR:$dst), (ins GPR:$ptr, GPR:$val), NoItinerary,
4221       [(set GPR:$dst, (atomic_load_max_32 GPR:$ptr, GPR:$val))]>;
4222     def ATOMIC_LOAD_UMIN_I32 : PseudoInst<
4223       (outs GPR:$dst), (ins GPR:$ptr, GPR:$val), NoItinerary,
4224       [(set GPR:$dst, (atomic_load_umin_32 GPR:$ptr, GPR:$val))]>;
4225     def ATOMIC_LOAD_UMAX_I32 : PseudoInst<
4226       (outs GPR:$dst), (ins GPR:$ptr, GPR:$val), NoItinerary,
4227       [(set GPR:$dst, (atomic_load_umax_32 GPR:$ptr, GPR:$val))]>;
4228
4229     def ATOMIC_SWAP_I8 : PseudoInst<
4230       (outs GPR:$dst), (ins GPR:$ptr, GPR:$new), NoItinerary,
4231       [(set GPR:$dst, (atomic_swap_8 GPR:$ptr, GPR:$new))]>;
4232     def ATOMIC_SWAP_I16 : PseudoInst<
4233       (outs GPR:$dst), (ins GPR:$ptr, GPR:$new), NoItinerary,
4234       [(set GPR:$dst, (atomic_swap_16 GPR:$ptr, GPR:$new))]>;
4235     def ATOMIC_SWAP_I32 : PseudoInst<
4236       (outs GPR:$dst), (ins GPR:$ptr, GPR:$new), NoItinerary,
4237       [(set GPR:$dst, (atomic_swap_32 GPR:$ptr, GPR:$new))]>;
4238
4239     def ATOMIC_CMP_SWAP_I8 : PseudoInst<
4240       (outs GPR:$dst), (ins GPR:$ptr, GPR:$old, GPR:$new), NoItinerary,
4241       [(set GPR:$dst, (atomic_cmp_swap_8 GPR:$ptr, GPR:$old, GPR:$new))]>;
4242     def ATOMIC_CMP_SWAP_I16 : PseudoInst<
4243       (outs GPR:$dst), (ins GPR:$ptr, GPR:$old, GPR:$new), NoItinerary,
4244       [(set GPR:$dst, (atomic_cmp_swap_16 GPR:$ptr, GPR:$old, GPR:$new))]>;
4245     def ATOMIC_CMP_SWAP_I32 : PseudoInst<
4246       (outs GPR:$dst), (ins GPR:$ptr, GPR:$old, GPR:$new), NoItinerary,
4247       [(set GPR:$dst, (atomic_cmp_swap_32 GPR:$ptr, GPR:$old, GPR:$new))]>;
4248 }
4249 }
4250
4251 let mayLoad = 1 in {
4252 def LDREXB : AIldrex<0b10, (outs GPR:$Rt), (ins addr_offset_none:$addr),
4253                      NoItinerary,
4254                     "ldrexb", "\t$Rt, $addr", []>;
4255 def LDREXH : AIldrex<0b11, (outs GPR:$Rt), (ins addr_offset_none:$addr),
4256                      NoItinerary, "ldrexh", "\t$Rt, $addr", []>;
4257 def LDREX  : AIldrex<0b00, (outs GPR:$Rt), (ins addr_offset_none:$addr),
4258                      NoItinerary, "ldrex", "\t$Rt, $addr", []>;
4259 let hasExtraDefRegAllocReq = 1 in
4260 def LDREXD: AIldrex<0b01, (outs GPR:$Rt, GPR:$Rt2),(ins addr_offset_none:$addr),
4261                       NoItinerary, "ldrexd", "\t$Rt, $Rt2, $addr", []> {
4262   let DecoderMethod = "DecodeDoubleRegLoad";
4263 }
4264 }
4265
4266 let mayStore = 1, Constraints = "@earlyclobber $Rd" in {
4267 def STREXB: AIstrex<0b10, (outs GPR:$Rd), (ins GPR:$Rt, addr_offset_none:$addr),
4268                     NoItinerary, "strexb", "\t$Rd, $Rt, $addr", []>;
4269 def STREXH: AIstrex<0b11, (outs GPR:$Rd), (ins GPR:$Rt, addr_offset_none:$addr),
4270                     NoItinerary, "strexh", "\t$Rd, $Rt, $addr", []>;
4271 def STREX : AIstrex<0b00, (outs GPR:$Rd), (ins GPR:$Rt, addr_offset_none:$addr),
4272                     NoItinerary, "strex", "\t$Rd, $Rt, $addr", []>;
4273 let hasExtraSrcRegAllocReq = 1 in
4274 def STREXD : AIstrex<0b01, (outs GPR:$Rd),
4275                     (ins GPR:$Rt, GPR:$Rt2, addr_offset_none:$addr),
4276                     NoItinerary, "strexd", "\t$Rd, $Rt, $Rt2, $addr", []> {
4277   let DecoderMethod = "DecodeDoubleRegStore";
4278 }
4279 }
4280
4281
4282 def CLREX : AXI<(outs), (ins), MiscFrm, NoItinerary, "clrex", []>,
4283             Requires<[IsARM, HasV7]>  {
4284   let Inst{31-0} = 0b11110101011111111111000000011111;
4285 }
4286
4287 // SWP/SWPB are deprecated in V6/V7.
4288 let mayLoad = 1, mayStore = 1 in {
4289 def SWP : AIswp<0, (outs GPR:$Rt), (ins GPR:$Rt2, addr_offset_none:$addr),
4290                 "swp", []>;
4291 def SWPB: AIswp<1, (outs GPR:$Rt), (ins GPR:$Rt2, addr_offset_none:$addr),
4292                 "swpb", []>;
4293 }
4294
4295 //===----------------------------------------------------------------------===//
4296 // Coprocessor Instructions.
4297 //
4298
4299 def CDP : ABI<0b1110, (outs), (ins p_imm:$cop, imm0_15:$opc1,
4300             c_imm:$CRd, c_imm:$CRn, c_imm:$CRm, imm0_7:$opc2),
4301             NoItinerary, "cdp", "\t$cop, $opc1, $CRd, $CRn, $CRm, $opc2",
4302             [(int_arm_cdp imm:$cop, imm:$opc1, imm:$CRd, imm:$CRn,
4303                           imm:$CRm, imm:$opc2)]> {
4304   bits<4> opc1;
4305   bits<4> CRn;
4306   bits<4> CRd;
4307   bits<4> cop;
4308   bits<3> opc2;
4309   bits<4> CRm;
4310
4311   let Inst{3-0}   = CRm;
4312   let Inst{4}     = 0;
4313   let Inst{7-5}   = opc2;
4314   let Inst{11-8}  = cop;
4315   let Inst{15-12} = CRd;
4316   let Inst{19-16} = CRn;
4317   let Inst{23-20} = opc1;
4318 }
4319
4320 def CDP2 : ABXI<0b1110, (outs), (ins p_imm:$cop, imm0_15:$opc1,
4321                c_imm:$CRd, c_imm:$CRn, c_imm:$CRm, imm0_7:$opc2),
4322                NoItinerary, "cdp2\t$cop, $opc1, $CRd, $CRn, $CRm, $opc2",
4323                [(int_arm_cdp2 imm:$cop, imm:$opc1, imm:$CRd, imm:$CRn,
4324                               imm:$CRm, imm:$opc2)]> {
4325   let Inst{31-28} = 0b1111;
4326   bits<4> opc1;
4327   bits<4> CRn;
4328   bits<4> CRd;
4329   bits<4> cop;
4330   bits<3> opc2;
4331   bits<4> CRm;
4332
4333   let Inst{3-0}   = CRm;
4334   let Inst{4}     = 0;
4335   let Inst{7-5}   = opc2;
4336   let Inst{11-8}  = cop;
4337   let Inst{15-12} = CRd;
4338   let Inst{19-16} = CRn;
4339   let Inst{23-20} = opc1;
4340 }
4341
4342 class ACI<dag oops, dag iops, string opc, string asm,
4343           IndexMode im = IndexModeNone>
4344   : I<oops, iops, AddrModeNone, 4, im, BrFrm, NoItinerary,
4345       opc, asm, "", []> {
4346   let Inst{27-25} = 0b110;
4347 }
4348 class ACInoP<dag oops, dag iops, string opc, string asm,
4349           IndexMode im = IndexModeNone>
4350   : InoP<oops, iops, AddrModeNone, 4, im, BrFrm, NoItinerary,
4351          opc, asm, "", []> {
4352   let Inst{31-28} = 0b1111;
4353   let Inst{27-25} = 0b110;
4354 }
4355 multiclass LdStCop<bit load, bit Dbit, string asm> {
4356   def _OFFSET : ACI<(outs), (ins p_imm:$cop, c_imm:$CRd, addrmode5:$addr),
4357                     asm, "\t$cop, $CRd, $addr"> {
4358     bits<13> addr;
4359     bits<4> cop;
4360     bits<4> CRd;
4361     let Inst{24} = 1; // P = 1
4362     let Inst{23} = addr{8};
4363     let Inst{22} = Dbit;
4364     let Inst{21} = 0; // W = 0
4365     let Inst{20} = load;
4366     let Inst{19-16} = addr{12-9};
4367     let Inst{15-12} = CRd;
4368     let Inst{11-8} = cop;
4369     let Inst{7-0} = addr{7-0};
4370     let DecoderMethod = "DecodeCopMemInstruction";
4371   }
4372   def _PRE : ACI<(outs), (ins p_imm:$cop, c_imm:$CRd, addrmode5:$addr),
4373                  asm, "\t$cop, $CRd, $addr!", IndexModePre> {
4374     bits<13> addr;
4375     bits<4> cop;
4376     bits<4> CRd;
4377     let Inst{24} = 1; // P = 1
4378     let Inst{23} = addr{8};
4379     let Inst{22} = Dbit;
4380     let Inst{21} = 1; // W = 1
4381     let Inst{20} = load;
4382     let Inst{19-16} = addr{12-9};
4383     let Inst{15-12} = CRd;
4384     let Inst{11-8} = cop;
4385     let Inst{7-0} = addr{7-0};
4386     let DecoderMethod = "DecodeCopMemInstruction";
4387   }
4388   def _POST: ACI<(outs), (ins p_imm:$cop, c_imm:$CRd, addr_offset_none:$addr,
4389                               postidx_imm8s4:$offset),
4390                  asm, "\t$cop, $CRd, $addr, $offset", IndexModePost> {
4391     bits<9> offset;
4392     bits<4> addr;
4393     bits<4> cop;
4394     bits<4> CRd;
4395     let Inst{24} = 0; // P = 0
4396     let Inst{23} = offset{8};
4397     let Inst{22} = Dbit;
4398     let Inst{21} = 1; // W = 1
4399     let Inst{20} = load;
4400     let Inst{19-16} = addr;
4401     let Inst{15-12} = CRd;
4402     let Inst{11-8} = cop;
4403     let Inst{7-0} = offset{7-0};
4404     let DecoderMethod = "DecodeCopMemInstruction";
4405   }
4406   def _OPTION : ACI<(outs),
4407                     (ins p_imm:$cop, c_imm:$CRd, addr_offset_none:$addr,
4408                          coproc_option_imm:$option),
4409       asm, "\t$cop, $CRd, $addr, $option"> {
4410     bits<8> option;
4411     bits<4> addr;
4412     bits<4> cop;
4413     bits<4> CRd;
4414     let Inst{24} = 0; // P = 0
4415     let Inst{23} = 1; // U = 1
4416     let Inst{22} = Dbit;
4417     let Inst{21} = 0; // W = 0
4418     let Inst{20} = load;
4419     let Inst{19-16} = addr;
4420     let Inst{15-12} = CRd;
4421     let Inst{11-8} = cop;
4422     let Inst{7-0} = option;
4423     let DecoderMethod = "DecodeCopMemInstruction";
4424   }
4425 }
4426 multiclass LdSt2Cop<bit load, bit Dbit, string asm> {
4427   def _OFFSET : ACInoP<(outs), (ins p_imm:$cop, c_imm:$CRd, addrmode5:$addr),
4428                        asm, "\t$cop, $CRd, $addr"> {
4429     bits<13> addr;
4430     bits<4> cop;
4431     bits<4> CRd;
4432     let Inst{24} = 1; // P = 1
4433     let Inst{23} = addr{8};
4434     let Inst{22} = Dbit;
4435     let Inst{21} = 0; // W = 0
4436     let Inst{20} = load;
4437     let Inst{19-16} = addr{12-9};
4438     let Inst{15-12} = CRd;
4439     let Inst{11-8} = cop;
4440     let Inst{7-0} = addr{7-0};
4441     let DecoderMethod = "DecodeCopMemInstruction";
4442   }
4443   def _PRE : ACInoP<(outs), (ins p_imm:$cop, c_imm:$CRd, addrmode5:$addr),
4444                     asm, "\t$cop, $CRd, $addr!", IndexModePre> {
4445     bits<13> addr;
4446     bits<4> cop;
4447     bits<4> CRd;
4448     let Inst{24} = 1; // P = 1
4449     let Inst{23} = addr{8};
4450     let Inst{22} = Dbit;
4451     let Inst{21} = 1; // W = 1
4452     let Inst{20} = load;
4453     let Inst{19-16} = addr{12-9};
4454     let Inst{15-12} = CRd;
4455     let Inst{11-8} = cop;
4456     let Inst{7-0} = addr{7-0};
4457     let DecoderMethod = "DecodeCopMemInstruction";
4458   }
4459   def _POST: ACInoP<(outs), (ins p_imm:$cop, c_imm:$CRd, addr_offset_none:$addr,
4460                                  postidx_imm8s4:$offset),
4461                  asm, "\t$cop, $CRd, $addr, $offset", IndexModePost> {
4462     bits<9> offset;
4463     bits<4> addr;
4464     bits<4> cop;
4465     bits<4> CRd;
4466     let Inst{24} = 0; // P = 0
4467     let Inst{23} = offset{8};
4468     let Inst{22} = Dbit;
4469     let Inst{21} = 1; // W = 1
4470     let Inst{20} = load;
4471     let Inst{19-16} = addr;
4472     let Inst{15-12} = CRd;
4473     let Inst{11-8} = cop;
4474     let Inst{7-0} = offset{7-0};
4475     let DecoderMethod = "DecodeCopMemInstruction";
4476   }
4477   def _OPTION : ACInoP<(outs),
4478                        (ins p_imm:$cop, c_imm:$CRd, addr_offset_none:$addr,
4479                             coproc_option_imm:$option),
4480       asm, "\t$cop, $CRd, $addr, $option"> {
4481     bits<8> option;
4482     bits<4> addr;
4483     bits<4> cop;
4484     bits<4> CRd;
4485     let Inst{24} = 0; // P = 0
4486     let Inst{23} = 1; // U = 1
4487     let Inst{22} = Dbit;
4488     let Inst{21} = 0; // W = 0
4489     let Inst{20} = load;
4490     let Inst{19-16} = addr;
4491     let Inst{15-12} = CRd;
4492     let Inst{11-8} = cop;
4493     let Inst{7-0} = option;
4494     let DecoderMethod = "DecodeCopMemInstruction";
4495   }
4496 }
4497
4498 defm LDC   : LdStCop <1, 0, "ldc">;
4499 defm LDCL  : LdStCop <1, 1, "ldcl">;
4500 defm STC   : LdStCop <0, 0, "stc">;
4501 defm STCL  : LdStCop <0, 1, "stcl">;
4502 defm LDC2  : LdSt2Cop<1, 0, "ldc2">;
4503 defm LDC2L : LdSt2Cop<1, 1, "ldc2l">;
4504 defm STC2  : LdSt2Cop<0, 0, "stc2">;
4505 defm STC2L : LdSt2Cop<0, 1, "stc2l">;
4506
4507 //===----------------------------------------------------------------------===//
4508 // Move between coprocessor and ARM core register.
4509 //
4510
4511 class MovRCopro<string opc, bit direction, dag oops, dag iops,
4512                 list<dag> pattern>
4513   : ABI<0b1110, oops, iops, NoItinerary, opc,
4514         "\t$cop, $opc1, $Rt, $CRn, $CRm, $opc2", pattern> {
4515   let Inst{20} = direction;
4516   let Inst{4} = 1;
4517
4518   bits<4> Rt;
4519   bits<4> cop;
4520   bits<3> opc1;
4521   bits<3> opc2;
4522   bits<4> CRm;
4523   bits<4> CRn;
4524
4525   let Inst{15-12} = Rt;
4526   let Inst{11-8}  = cop;
4527   let Inst{23-21} = opc1;
4528   let Inst{7-5}   = opc2;
4529   let Inst{3-0}   = CRm;
4530   let Inst{19-16} = CRn;
4531 }
4532
4533 def MCR : MovRCopro<"mcr", 0 /* from ARM core register to coprocessor */,
4534                     (outs),
4535                     (ins p_imm:$cop, imm0_7:$opc1, GPR:$Rt, c_imm:$CRn,
4536                          c_imm:$CRm, imm0_7:$opc2),
4537                     [(int_arm_mcr imm:$cop, imm:$opc1, GPR:$Rt, imm:$CRn,
4538                                   imm:$CRm, imm:$opc2)]>;
4539 def : ARMInstAlias<"mcr${p} $cop, $opc1, $Rt, $CRn, $CRm",
4540                    (MCR p_imm:$cop, imm0_7:$opc1, GPR:$Rt, c_imm:$CRn,
4541                         c_imm:$CRm, 0, pred:$p)>;
4542 def MRC : MovRCopro<"mrc", 1 /* from coprocessor to ARM core register */,
4543                     (outs GPR:$Rt),
4544                     (ins p_imm:$cop, imm0_7:$opc1, c_imm:$CRn, c_imm:$CRm,
4545                          imm0_7:$opc2), []>;
4546 def : ARMInstAlias<"mrc${p} $cop, $opc1, $Rt, $CRn, $CRm",
4547                    (MRC GPR:$Rt, p_imm:$cop, imm0_7:$opc1, c_imm:$CRn,
4548                         c_imm:$CRm, 0, pred:$p)>;
4549
4550 def : ARMPat<(int_arm_mrc imm:$cop, imm:$opc1, imm:$CRn, imm:$CRm, imm:$opc2),
4551              (MRC imm:$cop, imm:$opc1, imm:$CRn, imm:$CRm, imm:$opc2)>;
4552
4553 class MovRCopro2<string opc, bit direction, dag oops, dag iops,
4554                  list<dag> pattern>
4555   : ABXI<0b1110, oops, iops, NoItinerary,
4556          !strconcat(opc, "\t$cop, $opc1, $Rt, $CRn, $CRm, $opc2"), pattern> {
4557   let Inst{31-28} = 0b1111;
4558   let Inst{20} = direction;
4559   let Inst{4} = 1;
4560
4561   bits<4> Rt;
4562   bits<4> cop;
4563   bits<3> opc1;
4564   bits<3> opc2;
4565   bits<4> CRm;
4566   bits<4> CRn;
4567
4568   let Inst{15-12} = Rt;
4569   let Inst{11-8}  = cop;
4570   let Inst{23-21} = opc1;
4571   let Inst{7-5}   = opc2;
4572   let Inst{3-0}   = CRm;
4573   let Inst{19-16} = CRn;
4574 }
4575
4576 def MCR2 : MovRCopro2<"mcr2", 0 /* from ARM core register to coprocessor */,
4577                       (outs),
4578                       (ins p_imm:$cop, imm0_7:$opc1, GPR:$Rt, c_imm:$CRn,
4579                            c_imm:$CRm, imm0_7:$opc2),
4580                       [(int_arm_mcr2 imm:$cop, imm:$opc1, GPR:$Rt, imm:$CRn,
4581                                      imm:$CRm, imm:$opc2)]>;
4582 def : ARMInstAlias<"mcr2$ $cop, $opc1, $Rt, $CRn, $CRm",
4583                    (MCR2 p_imm:$cop, imm0_7:$opc1, GPR:$Rt, c_imm:$CRn,
4584                          c_imm:$CRm, 0)>;
4585 def MRC2 : MovRCopro2<"mrc2", 1 /* from coprocessor to ARM core register */,
4586                       (outs GPR:$Rt),
4587                       (ins p_imm:$cop, imm0_7:$opc1, c_imm:$CRn, c_imm:$CRm,
4588                            imm0_7:$opc2), []>;
4589 def : ARMInstAlias<"mrc2$ $cop, $opc1, $Rt, $CRn, $CRm",
4590                    (MRC2 GPR:$Rt, p_imm:$cop, imm0_7:$opc1, c_imm:$CRn,
4591                          c_imm:$CRm, 0)>;
4592
4593 def : ARMV5TPat<(int_arm_mrc2 imm:$cop, imm:$opc1, imm:$CRn,
4594                               imm:$CRm, imm:$opc2),
4595                 (MRC2 imm:$cop, imm:$opc1, imm:$CRn, imm:$CRm, imm:$opc2)>;
4596
4597 class MovRRCopro<string opc, bit direction, list<dag> pattern = []>
4598   : ABI<0b1100, (outs), (ins p_imm:$cop, imm0_15:$opc1,
4599         GPR:$Rt, GPR:$Rt2, c_imm:$CRm),
4600         NoItinerary, opc, "\t$cop, $opc1, $Rt, $Rt2, $CRm", pattern> {
4601   let Inst{23-21} = 0b010;
4602   let Inst{20} = direction;
4603
4604   bits<4> Rt;
4605   bits<4> Rt2;
4606   bits<4> cop;
4607   bits<4> opc1;
4608   bits<4> CRm;
4609
4610   let Inst{15-12} = Rt;
4611   let Inst{19-16} = Rt2;
4612   let Inst{11-8}  = cop;
4613   let Inst{7-4}   = opc1;
4614   let Inst{3-0}   = CRm;
4615 }
4616
4617 def MCRR : MovRRCopro<"mcrr", 0 /* from ARM core register to coprocessor */,
4618                       [(int_arm_mcrr imm:$cop, imm:$opc1, GPR:$Rt, GPR:$Rt2,
4619                                      imm:$CRm)]>;
4620 def MRRC : MovRRCopro<"mrrc", 1 /* from coprocessor to ARM core register */>;
4621
4622 class MovRRCopro2<string opc, bit direction, list<dag> pattern = []>
4623   : ABXI<0b1100, (outs), (ins p_imm:$cop, imm0_15:$opc1,
4624          GPR:$Rt, GPR:$Rt2, c_imm:$CRm), NoItinerary,
4625          !strconcat(opc, "\t$cop, $opc1, $Rt, $Rt2, $CRm"), pattern> {
4626   let Inst{31-28} = 0b1111;
4627   let Inst{23-21} = 0b010;
4628   let Inst{20} = direction;
4629
4630   bits<4> Rt;
4631   bits<4> Rt2;
4632   bits<4> cop;
4633   bits<4> opc1;
4634   bits<4> CRm;
4635
4636   let Inst{15-12} = Rt;
4637   let Inst{19-16} = Rt2;
4638   let Inst{11-8}  = cop;
4639   let Inst{7-4}   = opc1;
4640   let Inst{3-0}   = CRm;
4641 }
4642
4643 def MCRR2 : MovRRCopro2<"mcrr2", 0 /* from ARM core register to coprocessor */,
4644                         [(int_arm_mcrr2 imm:$cop, imm:$opc1, GPR:$Rt, GPR:$Rt2,
4645                                         imm:$CRm)]>;
4646 def MRRC2 : MovRRCopro2<"mrrc2", 1 /* from coprocessor to ARM core register */>;
4647
4648 //===----------------------------------------------------------------------===//
4649 // Move between special register and ARM core register
4650 //
4651
4652 // Move to ARM core register from Special Register
4653 def MRS : ABI<0b0001, (outs GPR:$Rd), (ins), NoItinerary,
4654               "mrs", "\t$Rd, apsr", []> {
4655   bits<4> Rd;
4656   let Inst{23-16} = 0b00001111;
4657   let Inst{15-12} = Rd;
4658   let Inst{7-4} = 0b0000;
4659 }
4660
4661 def : InstAlias<"mrs${p} $Rd, cpsr", (MRS GPR:$Rd, pred:$p)>, Requires<[IsARM]>;
4662
4663 def MRSsys : ABI<0b0001, (outs GPR:$Rd), (ins), NoItinerary,
4664                  "mrs", "\t$Rd, spsr", []> {
4665   bits<4> Rd;
4666   let Inst{23-16} = 0b01001111;
4667   let Inst{15-12} = Rd;
4668   let Inst{7-4} = 0b0000;
4669 }
4670
4671 // Move from ARM core register to Special Register
4672 //
4673 // No need to have both system and application versions, the encodings are the
4674 // same and the assembly parser has no way to distinguish between them. The mask
4675 // operand contains the special register (R Bit) in bit 4 and bits 3-0 contains
4676 // the mask with the fields to be accessed in the special register.
4677 def MSR : ABI<0b0001, (outs), (ins msr_mask:$mask, GPR:$Rn), NoItinerary,
4678               "msr", "\t$mask, $Rn", []> {
4679   bits<5> mask;
4680   bits<4> Rn;
4681
4682   let Inst{23} = 0;
4683   let Inst{22} = mask{4}; // R bit
4684   let Inst{21-20} = 0b10;
4685   let Inst{19-16} = mask{3-0};
4686   let Inst{15-12} = 0b1111;
4687   let Inst{11-4} = 0b00000000;
4688   let Inst{3-0} = Rn;
4689 }
4690
4691 def MSRi : ABI<0b0011, (outs), (ins msr_mask:$mask,  so_imm:$a), NoItinerary,
4692                "msr", "\t$mask, $a", []> {
4693   bits<5> mask;
4694   bits<12> a;
4695
4696   let Inst{23} = 0;
4697   let Inst{22} = mask{4}; // R bit
4698   let Inst{21-20} = 0b10;
4699   let Inst{19-16} = mask{3-0};
4700   let Inst{15-12} = 0b1111;
4701   let Inst{11-0} = a;
4702 }
4703
4704 //===----------------------------------------------------------------------===//
4705 // TLS Instructions
4706 //
4707
4708 // __aeabi_read_tp preserves the registers r1-r3.
4709 // This is a pseudo inst so that we can get the encoding right,
4710 // complete with fixup for the aeabi_read_tp function.
4711 let isCall = 1,
4712   Defs = [R0, R12, LR, CPSR], Uses = [SP] in {
4713   def TPsoft : PseudoInst<(outs), (ins), IIC_Br,
4714                [(set R0, ARMthread_pointer)]>;
4715 }
4716
4717 //===----------------------------------------------------------------------===//
4718 // SJLJ Exception handling intrinsics
4719 //   eh_sjlj_setjmp() is an instruction sequence to store the return
4720 //   address and save #0 in R0 for the non-longjmp case.
4721 //   Since by its nature we may be coming from some other function to get
4722 //   here, and we're using the stack frame for the containing function to
4723 //   save/restore registers, we can't keep anything live in regs across
4724 //   the eh_sjlj_setjmp(), else it will almost certainly have been tromped upon
4725 //   when we get here from a longjmp(). We force everything out of registers
4726 //   except for our own input by listing the relevant registers in Defs. By
4727 //   doing so, we also cause the prologue/epilogue code to actively preserve
4728 //   all of the callee-saved resgisters, which is exactly what we want.
4729 //   A constant value is passed in $val, and we use the location as a scratch.
4730 //
4731 // These are pseudo-instructions and are lowered to individual MC-insts, so
4732 // no encoding information is necessary.
4733 let Defs =
4734   [ R0,  R1,  R2,  R3,  R4,  R5,  R6,  R7,  R8,  R9,  R10, R11, R12, LR, CPSR,
4735     Q0, Q1, Q2, Q3, Q4, Q5, Q6, Q7, Q8, Q9, Q10, Q11, Q12, Q13, Q14, Q15 ],
4736   hasSideEffects = 1, isBarrier = 1, usesCustomInserter = 1 in {
4737   def Int_eh_sjlj_setjmp : PseudoInst<(outs), (ins GPR:$src, GPR:$val),
4738                                NoItinerary,
4739                          [(set R0, (ARMeh_sjlj_setjmp GPR:$src, GPR:$val))]>,
4740                            Requires<[IsARM, HasVFP2]>;
4741 }
4742
4743 let Defs =
4744   [ R0,  R1,  R2,  R3,  R4,  R5,  R6,  R7,  R8,  R9,  R10, R11, R12, LR, CPSR ],
4745   hasSideEffects = 1, isBarrier = 1, usesCustomInserter = 1 in {
4746   def Int_eh_sjlj_setjmp_nofp : PseudoInst<(outs), (ins GPR:$src, GPR:$val),
4747                                    NoItinerary,
4748                          [(set R0, (ARMeh_sjlj_setjmp GPR:$src, GPR:$val))]>,
4749                                 Requires<[IsARM, NoVFP]>;
4750 }
4751
4752 // FIXME: Non-IOS version(s)
4753 let isBarrier = 1, hasSideEffects = 1, isTerminator = 1,
4754     Defs = [ R7, LR, SP ] in {
4755 def Int_eh_sjlj_longjmp : PseudoInst<(outs), (ins GPR:$src, GPR:$scratch),
4756                              NoItinerary,
4757                          [(ARMeh_sjlj_longjmp GPR:$src, GPR:$scratch)]>,
4758                                 Requires<[IsARM, IsIOS]>;
4759 }
4760
4761 // eh.sjlj.dispatchsetup pseudo-instructions.
4762 // These pseudos are used for both ARM and Thumb2. Any differences are
4763 // handled when the pseudo is expanded (which happens before any passes
4764 // that need the instruction size).
4765 let Defs =
4766   [ R0,  R1,  R2,  R3,  R4,  R5,  R6,  R7,  R8,  R9,  R10, R11, R12, LR, CPSR,
4767     Q0, Q1, Q2, Q3, Q4, Q5, Q6, Q7, Q8, Q9, Q10, Q11, Q12, Q13, Q14, Q15 ],
4768   isBarrier = 1 in
4769 def Int_eh_sjlj_dispatchsetup : PseudoInst<(outs), (ins), NoItinerary, []>;
4770
4771 let Defs =
4772   [ R0,  R1,  R2,  R3,  R4,  R5,  R6,  R7,  R8,  R9,  R10, R11, R12, LR, CPSR ],
4773   isBarrier = 1 in
4774 def Int_eh_sjlj_dispatchsetup_nofp : PseudoInst<(outs), (ins), NoItinerary, []>;
4775
4776
4777 //===----------------------------------------------------------------------===//
4778 // Non-Instruction Patterns
4779 //
4780
4781 // ARMv4 indirect branch using (MOVr PC, dst)
4782 let isBranch = 1, isTerminator = 1, isBarrier = 1, isIndirectBranch = 1 in
4783   def MOVPCRX : ARMPseudoExpand<(outs), (ins GPR:$dst),
4784                     4, IIC_Br, [(brind GPR:$dst)],
4785                     (MOVr PC, GPR:$dst, (ops 14, zero_reg), zero_reg)>,
4786                   Requires<[IsARM, NoV4T]>;
4787
4788 // Large immediate handling.
4789
4790 // 32-bit immediate using two piece so_imms or movw + movt.
4791 // This is a single pseudo instruction, the benefit is that it can be remat'd
4792 // as a single unit instead of having to handle reg inputs.
4793 // FIXME: Remove this when we can do generalized remat.
4794 let isReMaterializable = 1, isMoveImm = 1 in
4795 def MOVi32imm : PseudoInst<(outs GPR:$dst), (ins i32imm:$src), IIC_iMOVix2,
4796                            [(set GPR:$dst, (arm_i32imm:$src))]>,
4797                            Requires<[IsARM]>;
4798
4799 // Pseudo instruction that combines movw + movt + add pc (if PIC).
4800 // It also makes it possible to rematerialize the instructions.
4801 // FIXME: Remove this when we can do generalized remat and when machine licm
4802 // can properly the instructions.
4803 let isReMaterializable = 1 in {
4804 def MOV_ga_pcrel : PseudoInst<(outs GPR:$dst), (ins i32imm:$addr),
4805                               IIC_iMOVix2addpc,
4806                         [(set GPR:$dst, (ARMWrapperPIC tglobaladdr:$addr))]>,
4807                         Requires<[IsARM, UseMovt]>;
4808
4809 def MOV_ga_dyn : PseudoInst<(outs GPR:$dst), (ins i32imm:$addr),
4810                              IIC_iMOVix2,
4811                         [(set GPR:$dst, (ARMWrapperDYN tglobaladdr:$addr))]>,
4812                         Requires<[IsARM, UseMovt]>;
4813
4814 let AddedComplexity = 10 in
4815 def MOV_ga_pcrel_ldr : PseudoInst<(outs GPR:$dst), (ins i32imm:$addr),
4816                                 IIC_iMOVix2ld,
4817                     [(set GPR:$dst, (load (ARMWrapperPIC tglobaladdr:$addr)))]>,
4818                     Requires<[IsARM, UseMovt]>;
4819 } // isReMaterializable
4820
4821 // ConstantPool, GlobalAddress, and JumpTable
4822 def : ARMPat<(ARMWrapper  tglobaladdr :$dst), (LEApcrel tglobaladdr :$dst)>,
4823             Requires<[IsARM, DontUseMovt]>;
4824 def : ARMPat<(ARMWrapper  tconstpool  :$dst), (LEApcrel tconstpool  :$dst)>;
4825 def : ARMPat<(ARMWrapper  tglobaladdr :$dst), (MOVi32imm tglobaladdr :$dst)>,
4826             Requires<[IsARM, UseMovt]>;
4827 def : ARMPat<(ARMWrapperJT tjumptable:$dst, imm:$id),
4828              (LEApcrelJT tjumptable:$dst, imm:$id)>;
4829
4830 // TODO: add,sub,and, 3-instr forms?
4831
4832 // Tail calls
4833 def : ARMPat<(ARMtcret tcGPR:$dst),
4834           (TCRETURNri tcGPR:$dst)>, Requires<[IsIOS]>;
4835
4836 def : ARMPat<(ARMtcret (i32 tglobaladdr:$dst)),
4837           (TCRETURNdi texternalsym:$dst)>, Requires<[IsIOS]>;
4838
4839 def : ARMPat<(ARMtcret (i32 texternalsym:$dst)),
4840           (TCRETURNdi texternalsym:$dst)>, Requires<[IsIOS]>;
4841
4842 def : ARMPat<(ARMtcret tcGPR:$dst),
4843           (TCRETURNriND tcGPR:$dst)>, Requires<[IsNotIOS]>;
4844
4845 def : ARMPat<(ARMtcret (i32 tglobaladdr:$dst)),
4846           (TCRETURNdiND texternalsym:$dst)>, Requires<[IsNotIOS]>;
4847
4848 def : ARMPat<(ARMtcret (i32 texternalsym:$dst)),
4849           (TCRETURNdiND texternalsym:$dst)>, Requires<[IsNotIOS]>;
4850
4851 // Direct calls
4852 def : ARMPat<(ARMcall texternalsym:$func), (BL texternalsym:$func)>,
4853       Requires<[IsARM]>;
4854 def : ARMPat<(ARMcall_nolink texternalsym:$func),
4855              (BMOVPCB_CALL texternalsym:$func)>, Requires<[IsARM]>;
4856
4857 // zextload i1 -> zextload i8
4858 def : ARMPat<(zextloadi1 addrmode_imm12:$addr), (LDRBi12 addrmode_imm12:$addr)>;
4859 def : ARMPat<(zextloadi1 ldst_so_reg:$addr),    (LDRBrs ldst_so_reg:$addr)>;
4860
4861 // extload -> zextload
4862 def : ARMPat<(extloadi1 addrmode_imm12:$addr),  (LDRBi12 addrmode_imm12:$addr)>;
4863 def : ARMPat<(extloadi1 ldst_so_reg:$addr),     (LDRBrs ldst_so_reg:$addr)>;
4864 def : ARMPat<(extloadi8 addrmode_imm12:$addr),  (LDRBi12 addrmode_imm12:$addr)>;
4865 def : ARMPat<(extloadi8 ldst_so_reg:$addr),     (LDRBrs ldst_so_reg:$addr)>;
4866
4867 def : ARMPat<(extloadi16 addrmode3:$addr),  (LDRH addrmode3:$addr)>;
4868
4869 def : ARMPat<(extloadi8  addrmodepc:$addr), (PICLDRB addrmodepc:$addr)>;
4870 def : ARMPat<(extloadi16 addrmodepc:$addr), (PICLDRH addrmodepc:$addr)>;
4871
4872 // smul* and smla*
4873 def : ARMV5TEPat<(mul (sra (shl GPR:$a, (i32 16)), (i32 16)),
4874                       (sra (shl GPR:$b, (i32 16)), (i32 16))),
4875                  (SMULBB GPR:$a, GPR:$b)>;
4876 def : ARMV5TEPat<(mul sext_16_node:$a, sext_16_node:$b),
4877                  (SMULBB GPR:$a, GPR:$b)>;
4878 def : ARMV5TEPat<(mul (sra (shl GPR:$a, (i32 16)), (i32 16)),
4879                       (sra GPR:$b, (i32 16))),
4880                  (SMULBT GPR:$a, GPR:$b)>;
4881 def : ARMV5TEPat<(mul sext_16_node:$a, (sra GPR:$b, (i32 16))),
4882                  (SMULBT GPR:$a, GPR:$b)>;
4883 def : ARMV5TEPat<(mul (sra GPR:$a, (i32 16)),
4884                       (sra (shl GPR:$b, (i32 16)), (i32 16))),
4885                  (SMULTB GPR:$a, GPR:$b)>;
4886 def : ARMV5TEPat<(mul (sra GPR:$a, (i32 16)), sext_16_node:$b),
4887                 (SMULTB GPR:$a, GPR:$b)>;
4888 def : ARMV5TEPat<(sra (mul GPR:$a, (sra (shl GPR:$b, (i32 16)), (i32 16))),
4889                       (i32 16)),
4890                  (SMULWB GPR:$a, GPR:$b)>;
4891 def : ARMV5TEPat<(sra (mul GPR:$a, sext_16_node:$b), (i32 16)),
4892                  (SMULWB GPR:$a, GPR:$b)>;
4893
4894 def : ARMV5TEPat<(add GPR:$acc,
4895                       (mul (sra (shl GPR:$a, (i32 16)), (i32 16)),
4896                            (sra (shl GPR:$b, (i32 16)), (i32 16)))),
4897                  (SMLABB GPR:$a, GPR:$b, GPR:$acc)>;
4898 def : ARMV5TEPat<(add GPR:$acc,
4899                       (mul sext_16_node:$a, sext_16_node:$b)),
4900                  (SMLABB GPR:$a, GPR:$b, GPR:$acc)>;
4901 def : ARMV5TEPat<(add GPR:$acc,
4902                       (mul (sra (shl GPR:$a, (i32 16)), (i32 16)),
4903                            (sra GPR:$b, (i32 16)))),
4904                  (SMLABT GPR:$a, GPR:$b, GPR:$acc)>;
4905 def : ARMV5TEPat<(add GPR:$acc,
4906                       (mul sext_16_node:$a, (sra GPR:$b, (i32 16)))),
4907                  (SMLABT GPR:$a, GPR:$b, GPR:$acc)>;
4908 def : ARMV5TEPat<(add GPR:$acc,
4909                       (mul (sra GPR:$a, (i32 16)),
4910                            (sra (shl GPR:$b, (i32 16)), (i32 16)))),
4911                  (SMLATB GPR:$a, GPR:$b, GPR:$acc)>;
4912 def : ARMV5TEPat<(add GPR:$acc,
4913                       (mul (sra GPR:$a, (i32 16)), sext_16_node:$b)),
4914                  (SMLATB GPR:$a, GPR:$b, GPR:$acc)>;
4915 def : ARMV5TEPat<(add GPR:$acc,
4916                       (sra (mul GPR:$a, (sra (shl GPR:$b, (i32 16)), (i32 16))),
4917                            (i32 16))),
4918                  (SMLAWB GPR:$a, GPR:$b, GPR:$acc)>;
4919 def : ARMV5TEPat<(add GPR:$acc,
4920                       (sra (mul GPR:$a, sext_16_node:$b), (i32 16))),
4921                  (SMLAWB GPR:$a, GPR:$b, GPR:$acc)>;
4922
4923
4924 // Pre-v7 uses MCR for synchronization barriers.
4925 def : ARMPat<(ARMMemBarrierMCR GPR:$zero), (MCR 15, 0, GPR:$zero, 7, 10, 5)>,
4926          Requires<[IsARM, HasV6]>;
4927
4928 // SXT/UXT with no rotate
4929 let AddedComplexity = 16 in {
4930 def : ARMV6Pat<(and GPR:$Src, 0x000000FF), (UXTB GPR:$Src, 0)>;
4931 def : ARMV6Pat<(and GPR:$Src, 0x0000FFFF), (UXTH GPR:$Src, 0)>;
4932 def : ARMV6Pat<(and GPR:$Src, 0x00FF00FF), (UXTB16 GPR:$Src, 0)>;
4933 def : ARMV6Pat<(add GPR:$Rn, (and GPR:$Rm, 0x00FF)),
4934                (UXTAB GPR:$Rn, GPR:$Rm, 0)>;
4935 def : ARMV6Pat<(add GPR:$Rn, (and GPR:$Rm, 0xFFFF)),
4936                (UXTAH GPR:$Rn, GPR:$Rm, 0)>;
4937 }
4938
4939 def : ARMV6Pat<(sext_inreg GPR:$Src, i8),  (SXTB GPR:$Src, 0)>;
4940 def : ARMV6Pat<(sext_inreg GPR:$Src, i16), (SXTH GPR:$Src, 0)>;
4941
4942 def : ARMV6Pat<(add GPR:$Rn, (sext_inreg GPRnopc:$Rm, i8)),
4943                (SXTAB GPR:$Rn, GPRnopc:$Rm, 0)>;
4944 def : ARMV6Pat<(add GPR:$Rn, (sext_inreg GPRnopc:$Rm, i16)),
4945                (SXTAH GPR:$Rn, GPRnopc:$Rm, 0)>;
4946
4947 // Atomic load/store patterns
4948 def : ARMPat<(atomic_load_8 ldst_so_reg:$src),
4949              (LDRBrs ldst_so_reg:$src)>;
4950 def : ARMPat<(atomic_load_8 addrmode_imm12:$src),
4951              (LDRBi12 addrmode_imm12:$src)>;
4952 def : ARMPat<(atomic_load_16 addrmode3:$src),
4953              (LDRH addrmode3:$src)>;
4954 def : ARMPat<(atomic_load_32 ldst_so_reg:$src),
4955              (LDRrs ldst_so_reg:$src)>;
4956 def : ARMPat<(atomic_load_32 addrmode_imm12:$src),
4957              (LDRi12 addrmode_imm12:$src)>;
4958 def : ARMPat<(atomic_store_8 ldst_so_reg:$ptr, GPR:$val),
4959              (STRBrs GPR:$val, ldst_so_reg:$ptr)>;
4960 def : ARMPat<(atomic_store_8 addrmode_imm12:$ptr, GPR:$val),
4961              (STRBi12 GPR:$val, addrmode_imm12:$ptr)>;
4962 def : ARMPat<(atomic_store_16 addrmode3:$ptr, GPR:$val),
4963              (STRH GPR:$val, addrmode3:$ptr)>;
4964 def : ARMPat<(atomic_store_32 ldst_so_reg:$ptr, GPR:$val),
4965              (STRrs GPR:$val, ldst_so_reg:$ptr)>;
4966 def : ARMPat<(atomic_store_32 addrmode_imm12:$ptr, GPR:$val),
4967              (STRi12 GPR:$val, addrmode_imm12:$ptr)>;
4968
4969
4970 //===----------------------------------------------------------------------===//
4971 // Thumb Support
4972 //
4973
4974 include "ARMInstrThumb.td"
4975
4976 //===----------------------------------------------------------------------===//
4977 // Thumb2 Support
4978 //
4979
4980 include "ARMInstrThumb2.td"
4981
4982 //===----------------------------------------------------------------------===//
4983 // Floating Point Support
4984 //
4985
4986 include "ARMInstrVFP.td"
4987
4988 //===----------------------------------------------------------------------===//
4989 // Advanced SIMD (NEON) Support
4990 //
4991
4992 include "ARMInstrNEON.td"
4993
4994 //===----------------------------------------------------------------------===//
4995 // Assembler aliases
4996 //
4997
4998 // Memory barriers
4999 def : InstAlias<"dmb", (DMB 0xf)>, Requires<[IsARM, HasDB]>;
5000 def : InstAlias<"dsb", (DSB 0xf)>, Requires<[IsARM, HasDB]>;
5001 def : InstAlias<"isb", (ISB 0xf)>, Requires<[IsARM, HasDB]>;
5002
5003 // System instructions
5004 def : MnemonicAlias<"swi", "svc">;
5005
5006 // Load / Store Multiple
5007 def : MnemonicAlias<"ldmfd", "ldm">;
5008 def : MnemonicAlias<"ldmia", "ldm">;
5009 def : MnemonicAlias<"ldmea", "ldmdb">;
5010 def : MnemonicAlias<"stmfd", "stmdb">;
5011 def : MnemonicAlias<"stmia", "stm">;
5012 def : MnemonicAlias<"stmea", "stm">;
5013
5014 // PKHBT/PKHTB with default shift amount. PKHTB is equivalent to PKHBT when the
5015 // shift amount is zero (i.e., unspecified).
5016 def : InstAlias<"pkhbt${p} $Rd, $Rn, $Rm",
5017                 (PKHBT GPRnopc:$Rd, GPRnopc:$Rn, GPRnopc:$Rm, 0, pred:$p)>,
5018         Requires<[IsARM, HasV6]>;
5019 def : InstAlias<"pkhtb${p} $Rd, $Rn, $Rm",
5020                 (PKHBT GPRnopc:$Rd, GPRnopc:$Rn, GPRnopc:$Rm, 0, pred:$p)>,
5021         Requires<[IsARM, HasV6]>;
5022
5023 // PUSH/POP aliases for STM/LDM
5024 def : ARMInstAlias<"push${p} $regs", (STMDB_UPD SP, pred:$p, reglist:$regs)>;
5025 def : ARMInstAlias<"pop${p} $regs", (LDMIA_UPD SP, pred:$p, reglist:$regs)>;
5026
5027 // SSAT/USAT optional shift operand.
5028 def : ARMInstAlias<"ssat${p} $Rd, $sat_imm, $Rn",
5029                 (SSAT GPRnopc:$Rd, imm1_32:$sat_imm, GPRnopc:$Rn, 0, pred:$p)>;
5030 def : ARMInstAlias<"usat${p} $Rd, $sat_imm, $Rn",
5031                 (USAT GPRnopc:$Rd, imm0_31:$sat_imm, GPRnopc:$Rn, 0, pred:$p)>;
5032
5033
5034 // Extend instruction optional rotate operand.
5035 def : ARMInstAlias<"sxtab${p} $Rd, $Rn, $Rm",
5036                 (SXTAB GPRnopc:$Rd, GPR:$Rn, GPRnopc:$Rm, 0, pred:$p)>;
5037 def : ARMInstAlias<"sxtah${p} $Rd, $Rn, $Rm",
5038                 (SXTAH GPRnopc:$Rd, GPR:$Rn, GPRnopc:$Rm, 0, pred:$p)>;
5039 def : ARMInstAlias<"sxtab16${p} $Rd, $Rn, $Rm",
5040                 (SXTAB16 GPRnopc:$Rd, GPR:$Rn, GPRnopc:$Rm, 0, pred:$p)>;
5041 def : ARMInstAlias<"sxtb${p} $Rd, $Rm",
5042                 (SXTB GPRnopc:$Rd, GPRnopc:$Rm, 0, pred:$p)>;
5043 def : ARMInstAlias<"sxtb16${p} $Rd, $Rm",
5044                 (SXTB16 GPRnopc:$Rd, GPRnopc:$Rm, 0, pred:$p)>;
5045 def : ARMInstAlias<"sxth${p} $Rd, $Rm",
5046                 (SXTH GPRnopc:$Rd, GPRnopc:$Rm, 0, pred:$p)>;
5047
5048 def : ARMInstAlias<"uxtab${p} $Rd, $Rn, $Rm",
5049                 (UXTAB GPRnopc:$Rd, GPR:$Rn, GPRnopc:$Rm, 0, pred:$p)>;
5050 def : ARMInstAlias<"uxtah${p} $Rd, $Rn, $Rm",
5051                 (UXTAH GPRnopc:$Rd, GPR:$Rn, GPRnopc:$Rm, 0, pred:$p)>;
5052 def : ARMInstAlias<"uxtab16${p} $Rd, $Rn, $Rm",
5053                 (UXTAB16 GPRnopc:$Rd, GPR:$Rn, GPRnopc:$Rm, 0, pred:$p)>;
5054 def : ARMInstAlias<"uxtb${p} $Rd, $Rm",
5055                 (UXTB GPRnopc:$Rd, GPRnopc:$Rm, 0, pred:$p)>;
5056 def : ARMInstAlias<"uxtb16${p} $Rd, $Rm",
5057                 (UXTB16 GPRnopc:$Rd, GPRnopc:$Rm, 0, pred:$p)>;
5058 def : ARMInstAlias<"uxth${p} $Rd, $Rm",
5059                 (UXTH GPRnopc:$Rd, GPRnopc:$Rm, 0, pred:$p)>;
5060
5061
5062 // RFE aliases
5063 def : MnemonicAlias<"rfefa", "rfeda">;
5064 def : MnemonicAlias<"rfeea", "rfedb">;
5065 def : MnemonicAlias<"rfefd", "rfeia">;
5066 def : MnemonicAlias<"rfeed", "rfeib">;
5067 def : MnemonicAlias<"rfe", "rfeia">;
5068
5069 // SRS aliases
5070 def : MnemonicAlias<"srsfa", "srsda">;
5071 def : MnemonicAlias<"srsea", "srsdb">;
5072 def : MnemonicAlias<"srsfd", "srsia">;
5073 def : MnemonicAlias<"srsed", "srsib">;
5074 def : MnemonicAlias<"srs", "srsia">;
5075
5076 // QSAX == QSUBADDX
5077 def : MnemonicAlias<"qsubaddx", "qsax">;
5078 // SASX == SADDSUBX
5079 def : MnemonicAlias<"saddsubx", "sasx">;
5080 // SHASX == SHADDSUBX
5081 def : MnemonicAlias<"shaddsubx", "shasx">;
5082 // SHSAX == SHSUBADDX
5083 def : MnemonicAlias<"shsubaddx", "shsax">;
5084 // SSAX == SSUBADDX
5085 def : MnemonicAlias<"ssubaddx", "ssax">;
5086 // UASX == UADDSUBX
5087 def : MnemonicAlias<"uaddsubx", "uasx">;
5088 // UHASX == UHADDSUBX
5089 def : MnemonicAlias<"uhaddsubx", "uhasx">;
5090 // UHSAX == UHSUBADDX
5091 def : MnemonicAlias<"uhsubaddx", "uhsax">;
5092 // UQASX == UQADDSUBX
5093 def : MnemonicAlias<"uqaddsubx", "uqasx">;
5094 // UQSAX == UQSUBADDX
5095 def : MnemonicAlias<"uqsubaddx", "uqsax">;
5096 // USAX == USUBADDX
5097 def : MnemonicAlias<"usubaddx", "usax">;
5098
5099 // "mov Rd, so_imm_not" can be handled via "mvn" in assembly, just like
5100 // for isel.
5101 def : ARMInstAlias<"mov${s}${p} $Rd, $imm",
5102                    (MVNi rGPR:$Rd, so_imm_not:$imm, pred:$p, cc_out:$s)>;
5103 def : ARMInstAlias<"mvn${s}${p} $Rd, $imm",
5104                    (MOVi rGPR:$Rd, so_imm_not:$imm, pred:$p, cc_out:$s)>;
5105 // Same for AND <--> BIC
5106 def : ARMInstAlias<"bic${s}${p} $Rd, $Rn, $imm",
5107                    (ANDri rGPR:$Rd, rGPR:$Rn, so_imm_not:$imm,
5108                           pred:$p, cc_out:$s)>;
5109 def : ARMInstAlias<"bic${s}${p} $Rdn, $imm",
5110                    (ANDri rGPR:$Rdn, rGPR:$Rdn, so_imm_not:$imm,
5111                           pred:$p, cc_out:$s)>;
5112 def : ARMInstAlias<"and${s}${p} $Rd, $Rn, $imm",
5113                    (BICri rGPR:$Rd, rGPR:$Rn, so_imm_not:$imm,
5114                           pred:$p, cc_out:$s)>;
5115 def : ARMInstAlias<"and${s}${p} $Rdn, $imm",
5116                    (BICri rGPR:$Rdn, rGPR:$Rdn, so_imm_not:$imm,
5117                           pred:$p, cc_out:$s)>;
5118
5119 // Likewise, "add Rd, so_imm_neg" -> sub
5120 def : ARMInstAlias<"add${s}${p} $Rd, $Rn, $imm",
5121                  (SUBri GPR:$Rd, GPR:$Rn, so_imm_neg:$imm, pred:$p, cc_out:$s)>;
5122 def : ARMInstAlias<"add${s}${p} $Rd, $imm",
5123                  (SUBri GPR:$Rd, GPR:$Rd, so_imm_neg:$imm, pred:$p, cc_out:$s)>;
5124 // Same for CMP <--> CMN via so_imm_neg
5125 def : ARMInstAlias<"cmp${p} $Rd, $imm",
5126                    (CMNzri rGPR:$Rd, so_imm_neg:$imm, pred:$p)>;
5127 def : ARMInstAlias<"cmn${p} $Rd, $imm",
5128                    (CMPri rGPR:$Rd, so_imm_neg:$imm, pred:$p)>;
5129
5130 // The shifter forms of the MOV instruction are aliased to the ASR, LSL,
5131 // LSR, ROR, and RRX instructions.
5132 // FIXME: We need C++ parser hooks to map the alias to the MOV
5133 //        encoding. It seems we should be able to do that sort of thing
5134 //        in tblgen, but it could get ugly.
5135 def ASRi : ARMAsmPseudo<"asr${s}${p} $Rd, $Rm, $imm",
5136                         (ins GPR:$Rd, GPR:$Rm, imm0_32:$imm, pred:$p,
5137                              cc_out:$s)>;
5138 def LSRi : ARMAsmPseudo<"lsr${s}${p} $Rd, $Rm, $imm",
5139                         (ins GPR:$Rd, GPR:$Rm, imm0_32:$imm, pred:$p,
5140                              cc_out:$s)>;
5141 def LSLi : ARMAsmPseudo<"lsl${s}${p} $Rd, $Rm, $imm",
5142                         (ins GPR:$Rd, GPR:$Rm, imm0_31:$imm, pred:$p,
5143                              cc_out:$s)>;
5144 def RORi : ARMAsmPseudo<"ror${s}${p} $Rd, $Rm, $imm",
5145                         (ins GPR:$Rd, GPR:$Rm, imm0_31:$imm, pred:$p,
5146                              cc_out:$s)>;
5147 def RRXi : ARMAsmPseudo<"rrx${s}${p} $Rd, $Rm",
5148                         (ins GPRnopc:$Rd, GPRnopc:$Rm, pred:$p, cc_out:$s)>;
5149 def ASRr : ARMAsmPseudo<"asr${s}${p} $Rd, $Rn, $Rm",
5150                         (ins GPRnopc:$Rd, GPRnopc:$Rn, GPRnopc:$Rm, pred:$p,
5151                              cc_out:$s)>;
5152 def LSRr : ARMAsmPseudo<"lsr${s}${p} $Rd, $Rn, $Rm",
5153                         (ins GPRnopc:$Rd, GPRnopc:$Rn, GPRnopc:$Rm, pred:$p,
5154                              cc_out:$s)>;
5155 def LSLr : ARMAsmPseudo<"lsl${s}${p} $Rd, $Rn, $Rm",
5156                         (ins GPRnopc:$Rd, GPRnopc:$Rn, GPRnopc:$Rm, pred:$p,
5157                              cc_out:$s)>;
5158 def RORr : ARMAsmPseudo<"ror${s}${p} $Rd, $Rn, $Rm",
5159                         (ins GPRnopc:$Rd, GPRnopc:$Rn, GPRnopc:$Rm, pred:$p,
5160                              cc_out:$s)>;
5161 // shifter instructions also support a two-operand form.
5162 def : ARMInstAlias<"asr${s}${p} $Rm, $imm",
5163                    (ASRi GPR:$Rm, GPR:$Rm, imm0_32:$imm, pred:$p, cc_out:$s)>;
5164 def : ARMInstAlias<"lsr${s}${p} $Rm, $imm",
5165                    (LSRi GPR:$Rm, GPR:$Rm, imm0_32:$imm, pred:$p, cc_out:$s)>;
5166 def : ARMInstAlias<"lsl${s}${p} $Rm, $imm",
5167                    (LSLi GPR:$Rm, GPR:$Rm, imm0_31:$imm, pred:$p, cc_out:$s)>;
5168 def : ARMInstAlias<"ror${s}${p} $Rm, $imm",
5169                    (RORi GPR:$Rm, GPR:$Rm, imm0_31:$imm, pred:$p, cc_out:$s)>;
5170 def : ARMInstAlias<"asr${s}${p} $Rn, $Rm",
5171                    (ASRr GPRnopc:$Rn, GPRnopc:$Rn, GPRnopc:$Rm, pred:$p,
5172                          cc_out:$s)>;
5173 def : ARMInstAlias<"lsr${s}${p} $Rn, $Rm",
5174                    (LSRr GPRnopc:$Rn, GPRnopc:$Rn, GPRnopc:$Rm, pred:$p,
5175                          cc_out:$s)>;
5176 def : ARMInstAlias<"lsl${s}${p} $Rn, $Rm",
5177                    (LSLr GPRnopc:$Rn, GPRnopc:$Rn, GPRnopc:$Rm, pred:$p,
5178                          cc_out:$s)>;
5179 def : ARMInstAlias<"ror${s}${p} $Rn, $Rm",
5180                    (RORr GPRnopc:$Rn, GPRnopc:$Rn, GPRnopc:$Rm, pred:$p,
5181                          cc_out:$s)>;
5182
5183
5184 // 'mul' instruction can be specified with only two operands.
5185 def : ARMInstAlias<"mul${s}${p} $Rn, $Rm",
5186                    (MUL rGPR:$Rn, rGPR:$Rm, rGPR:$Rn, pred:$p, cc_out:$s)>;
5187
5188 // "neg" is and alias for "rsb rd, rn, #0"
5189 def : ARMInstAlias<"neg${s}${p} $Rd, $Rm",
5190                    (RSBri GPR:$Rd, GPR:$Rm, 0, pred:$p, cc_out:$s)>;
5191
5192 // Pre-v6, 'mov r0, r0' was used as a NOP encoding.
5193 def : InstAlias<"nop${p}", (MOVr R0, R0, pred:$p, zero_reg)>,
5194          Requires<[IsARM, NoV6]>;
5195
5196 // UMULL/SMULL are available on all arches, but the instruction definitions
5197 // need difference constraints pre-v6. Use these aliases for the assembly
5198 // parsing on pre-v6.
5199 def : InstAlias<"smull${s}${p} $RdLo, $RdHi, $Rn, $Rm",
5200             (SMULL GPR:$RdLo, GPR:$RdHi, GPR:$Rn, GPR:$Rm, pred:$p, cc_out:$s)>,
5201          Requires<[IsARM, NoV6]>;
5202 def : InstAlias<"umull${s}${p} $RdLo, $RdHi, $Rn, $Rm",
5203             (UMULL GPR:$RdLo, GPR:$RdHi, GPR:$Rn, GPR:$Rm, pred:$p, cc_out:$s)>,
5204          Requires<[IsARM, NoV6]>;
5205
5206 // 'it' blocks in ARM mode just validate the predicates. The IT itself
5207 // is discarded.
5208 def ITasm : ARMAsmPseudo<"it$mask $cc", (ins it_pred:$cc, it_mask:$mask)>;