1//===-- PPCInstrInfo.td - The PowerPC Instruction Set ------*- 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 subset of the 32-bit PowerPC instruction set, as used
11// by the PowerPC instruction selector.
12//
13//===----------------------------------------------------------------------===//
14
15include "PPCInstrFormats.td"
16
17//===----------------------------------------------------------------------===//
18// PowerPC specific type constraints.
19//
20def SDT_PPCstfiwx : SDTypeProfile<0, 2, [ // stfiwx
21  SDTCisVT<0, f64>, SDTCisPtrTy<1>
22]>;
23def SDT_PPClfiwx : SDTypeProfile<1, 1, [ // lfiw[az]x
24  SDTCisVT<0, f64>, SDTCisPtrTy<1>
25]>;
26
27def SDT_PPCCallSeqStart : SDCallSeqStart<[ SDTCisVT<0, i32> ]>;
28def SDT_PPCCallSeqEnd   : SDCallSeqEnd<[ SDTCisVT<0, i32>,
29                                         SDTCisVT<1, i32> ]>;
30def SDT_PPCvperm   : SDTypeProfile<1, 3, [
31  SDTCisVT<3, v16i8>, SDTCisSameAs<0, 1>, SDTCisSameAs<0, 2>
32]>;
33
34def SDT_PPCvcmp : SDTypeProfile<1, 3, [
35  SDTCisSameAs<0, 1>, SDTCisSameAs<1, 2>, SDTCisVT<3, i32>
36]>;
37
38def SDT_PPCcondbr : SDTypeProfile<0, 3, [
39  SDTCisVT<0, i32>, SDTCisVT<2, OtherVT>
40]>;
41
42def SDT_PPClbrx : SDTypeProfile<1, 2, [
43  SDTCisInt<0>, SDTCisPtrTy<1>, SDTCisVT<2, OtherVT>
44]>;
45def SDT_PPCstbrx : SDTypeProfile<0, 3, [
46  SDTCisInt<0>, SDTCisPtrTy<1>, SDTCisVT<2, OtherVT>
47]>;
48
49def SDT_PPCTC_ret : SDTypeProfile<0, 2, [
50  SDTCisPtrTy<0>, SDTCisVT<1, i32>
51]>;
52
53def tocentry32 : Operand<iPTR> {
54  let MIOperandInfo = (ops i32imm:$imm);
55}
56
57def SDT_PPCqvfperm   : SDTypeProfile<1, 3, [
58  SDTCisVec<0>, SDTCisSameAs<0, 1>, SDTCisSameAs<0, 2>, SDTCisVec<3>
59]>;
60def SDT_PPCqvgpci   : SDTypeProfile<1, 1, [
61  SDTCisVec<0>, SDTCisInt<1>
62]>;
63def SDT_PPCqvaligni   : SDTypeProfile<1, 3, [
64  SDTCisVec<0>, SDTCisSameAs<0, 1>, SDTCisSameAs<0, 2>, SDTCisInt<3>
65]>;
66def SDT_PPCqvesplati   : SDTypeProfile<1, 2, [
67  SDTCisVec<0>, SDTCisSameAs<0, 1>, SDTCisInt<2>
68]>;
69
70def SDT_PPCqbflt : SDTypeProfile<1, 1, [
71  SDTCisVec<0>, SDTCisVec<1>
72]>;
73
74def SDT_PPCqvlfsb : SDTypeProfile<1, 1, [
75  SDTCisVec<0>, SDTCisPtrTy<1>
76]>;
77
78//===----------------------------------------------------------------------===//
79// PowerPC specific DAG Nodes.
80//
81
82def PPCfre    : SDNode<"PPCISD::FRE",     SDTFPUnaryOp, []>;
83def PPCfrsqrte: SDNode<"PPCISD::FRSQRTE", SDTFPUnaryOp, []>;
84
85def PPCfcfid  : SDNode<"PPCISD::FCFID",   SDTFPUnaryOp, []>;
86def PPCfcfidu : SDNode<"PPCISD::FCFIDU",  SDTFPUnaryOp, []>;
87def PPCfcfids : SDNode<"PPCISD::FCFIDS",  SDTFPRoundOp, []>;
88def PPCfcfidus: SDNode<"PPCISD::FCFIDUS", SDTFPRoundOp, []>;
89def PPCfctidz : SDNode<"PPCISD::FCTIDZ", SDTFPUnaryOp, []>;
90def PPCfctiwz : SDNode<"PPCISD::FCTIWZ", SDTFPUnaryOp, []>;
91def PPCfctiduz: SDNode<"PPCISD::FCTIDUZ",SDTFPUnaryOp, []>;
92def PPCfctiwuz: SDNode<"PPCISD::FCTIWUZ",SDTFPUnaryOp, []>;
93def PPCstfiwx : SDNode<"PPCISD::STFIWX", SDT_PPCstfiwx,
94                       [SDNPHasChain, SDNPMayStore]>;
95def PPClfiwax : SDNode<"PPCISD::LFIWAX", SDT_PPClfiwx,
96                       [SDNPHasChain, SDNPMayLoad]>;
97def PPClfiwzx : SDNode<"PPCISD::LFIWZX", SDT_PPClfiwx,
98                       [SDNPHasChain, SDNPMayLoad]>;
99
100// Extract FPSCR (not modeled at the DAG level).
101def PPCmffs   : SDNode<"PPCISD::MFFS",
102                       SDTypeProfile<1, 0, [SDTCisVT<0, f64>]>, []>;
103
104// Perform FADD in round-to-zero mode.
105def PPCfaddrtz: SDNode<"PPCISD::FADDRTZ", SDTFPBinOp, []>;
106
107
108def PPCfsel   : SDNode<"PPCISD::FSEL",
109   // Type constraint for fsel.
110   SDTypeProfile<1, 3, [SDTCisSameAs<0, 2>, SDTCisSameAs<0, 3>,
111                        SDTCisFP<0>, SDTCisVT<1, f64>]>, []>;
112
113def PPChi       : SDNode<"PPCISD::Hi", SDTIntBinOp, []>;
114def PPClo       : SDNode<"PPCISD::Lo", SDTIntBinOp, []>;
115def PPCtoc_entry: SDNode<"PPCISD::TOC_ENTRY", SDTIntBinOp,
116                         [SDNPMayLoad, SDNPMemOperand]>;
117def PPCvmaddfp  : SDNode<"PPCISD::VMADDFP", SDTFPTernaryOp, []>;
118def PPCvnmsubfp : SDNode<"PPCISD::VNMSUBFP", SDTFPTernaryOp, []>;
119
120def PPCppc32GOT : SDNode<"PPCISD::PPC32_GOT", SDTIntLeaf, []>;
121
122def PPCaddisGotTprelHA : SDNode<"PPCISD::ADDIS_GOT_TPREL_HA", SDTIntBinOp>;
123def PPCldGotTprelL : SDNode<"PPCISD::LD_GOT_TPREL_L", SDTIntBinOp,
124                            [SDNPMayLoad]>;
125def PPCaddTls     : SDNode<"PPCISD::ADD_TLS", SDTIntBinOp, []>;
126def PPCaddisTlsgdHA : SDNode<"PPCISD::ADDIS_TLSGD_HA", SDTIntBinOp>;
127def PPCaddiTlsgdL   : SDNode<"PPCISD::ADDI_TLSGD_L", SDTIntBinOp>;
128def PPCgetTlsAddr   : SDNode<"PPCISD::GET_TLS_ADDR", SDTIntBinOp>;
129def PPCaddiTlsgdLAddr : SDNode<"PPCISD::ADDI_TLSGD_L_ADDR",
130                               SDTypeProfile<1, 3, [
131                                 SDTCisSameAs<0, 1>, SDTCisSameAs<0, 2>,
132                                 SDTCisSameAs<0, 3>, SDTCisInt<0> ]>>;
133def PPCaddisTlsldHA : SDNode<"PPCISD::ADDIS_TLSLD_HA", SDTIntBinOp>;
134def PPCaddiTlsldL   : SDNode<"PPCISD::ADDI_TLSLD_L", SDTIntBinOp>;
135def PPCgetTlsldAddr : SDNode<"PPCISD::GET_TLSLD_ADDR", SDTIntBinOp>;
136def PPCaddiTlsldLAddr : SDNode<"PPCISD::ADDI_TLSLD_L_ADDR",
137                               SDTypeProfile<1, 3, [
138                                 SDTCisSameAs<0, 1>, SDTCisSameAs<0, 2>,
139                                 SDTCisSameAs<0, 3>, SDTCisInt<0> ]>>;
140def PPCaddisDtprelHA : SDNode<"PPCISD::ADDIS_DTPREL_HA", SDTIntBinOp>;
141def PPCaddiDtprelL   : SDNode<"PPCISD::ADDI_DTPREL_L", SDTIntBinOp>;
142
143def PPCvperm    : SDNode<"PPCISD::VPERM", SDT_PPCvperm, []>;
144
145def PPCqvfperm   : SDNode<"PPCISD::QVFPERM", SDT_PPCqvfperm, []>;
146def PPCqvgpci    : SDNode<"PPCISD::QVGPCI", SDT_PPCqvgpci, []>;
147def PPCqvaligni  : SDNode<"PPCISD::QVALIGNI", SDT_PPCqvaligni, []>;
148def PPCqvesplati : SDNode<"PPCISD::QVESPLATI", SDT_PPCqvesplati, []>;
149
150def PPCqbflt     : SDNode<"PPCISD::QBFLT", SDT_PPCqbflt, []>;
151
152def PPCqvlfsb    : SDNode<"PPCISD::QVLFSb", SDT_PPCqvlfsb,
153                          [SDNPHasChain, SDNPMayLoad]>;
154
155def PPCcmpb     : SDNode<"PPCISD::CMPB", SDTIntBinOp, []>;
156
157// These nodes represent the 32-bit PPC shifts that operate on 6-bit shift
158// amounts.  These nodes are generated by the multi-precision shift code.
159def PPCsrl        : SDNode<"PPCISD::SRL"       , SDTIntShiftOp>;
160def PPCsra        : SDNode<"PPCISD::SRA"       , SDTIntShiftOp>;
161def PPCshl        : SDNode<"PPCISD::SHL"       , SDTIntShiftOp>;
162
163// These are target-independent nodes, but have target-specific formats.
164def callseq_start : SDNode<"ISD::CALLSEQ_START", SDT_PPCCallSeqStart,
165                           [SDNPHasChain, SDNPOutGlue]>;
166def callseq_end   : SDNode<"ISD::CALLSEQ_END",   SDT_PPCCallSeqEnd,
167                           [SDNPHasChain, SDNPOptInGlue, SDNPOutGlue]>;
168
169def SDT_PPCCall   : SDTypeProfile<0, -1, [SDTCisInt<0>]>;
170def PPCcall  : SDNode<"PPCISD::CALL", SDT_PPCCall,
171                      [SDNPHasChain, SDNPOptInGlue, SDNPOutGlue,
172                       SDNPVariadic]>;
173def PPCcall_nop  : SDNode<"PPCISD::CALL_NOP", SDT_PPCCall,
174                          [SDNPHasChain, SDNPOptInGlue, SDNPOutGlue,
175                           SDNPVariadic]>;
176def PPCmtctr      : SDNode<"PPCISD::MTCTR", SDT_PPCCall,
177                           [SDNPHasChain, SDNPOptInGlue, SDNPOutGlue]>;
178def PPCbctrl : SDNode<"PPCISD::BCTRL", SDTNone,
179                      [SDNPHasChain, SDNPOptInGlue, SDNPOutGlue,
180                       SDNPVariadic]>;
181def PPCbctrl_load_toc : SDNode<"PPCISD::BCTRL_LOAD_TOC",
182                               SDTypeProfile<0, 1, []>,
183                               [SDNPHasChain, SDNPOptInGlue, SDNPOutGlue,
184                                SDNPVariadic]>;
185
186def retflag       : SDNode<"PPCISD::RET_FLAG", SDTNone,
187                           [SDNPHasChain, SDNPOptInGlue, SDNPVariadic]>;
188
189def PPCtc_return : SDNode<"PPCISD::TC_RETURN", SDT_PPCTC_ret,
190                        [SDNPHasChain,  SDNPOptInGlue, SDNPVariadic]>;
191
192def PPCeh_sjlj_setjmp  : SDNode<"PPCISD::EH_SJLJ_SETJMP",
193                                SDTypeProfile<1, 1, [SDTCisInt<0>,
194                                                     SDTCisPtrTy<1>]>,
195                                [SDNPHasChain, SDNPSideEffect]>;
196def PPCeh_sjlj_longjmp : SDNode<"PPCISD::EH_SJLJ_LONGJMP",
197                                SDTypeProfile<0, 1, [SDTCisPtrTy<0>]>,
198                                [SDNPHasChain, SDNPSideEffect]>;
199
200def SDT_PPCsc     : SDTypeProfile<0, 1, [SDTCisInt<0>]>;
201def PPCsc         : SDNode<"PPCISD::SC", SDT_PPCsc,
202                           [SDNPHasChain, SDNPSideEffect]>;
203
204def PPCclrbhrb    : SDNode<"PPCISD::CLRBHRB", SDTNone,
205                           [SDNPHasChain, SDNPSideEffect]>;
206def PPCmfbhrbe    : SDNode<"PPCISD::MFBHRBE", SDTIntBinOp, [SDNPHasChain]>;
207def PPCrfebb      : SDNode<"PPCISD::RFEBB", SDT_PPCsc,
208                           [SDNPHasChain, SDNPSideEffect]>;
209
210def PPCvcmp       : SDNode<"PPCISD::VCMP" , SDT_PPCvcmp, []>;
211def PPCvcmp_o     : SDNode<"PPCISD::VCMPo", SDT_PPCvcmp, [SDNPOutGlue]>;
212
213def PPCcondbranch : SDNode<"PPCISD::COND_BRANCH", SDT_PPCcondbr,
214                           [SDNPHasChain, SDNPOptInGlue]>;
215
216def PPClbrx       : SDNode<"PPCISD::LBRX", SDT_PPClbrx,
217                           [SDNPHasChain, SDNPMayLoad]>;
218def PPCstbrx      : SDNode<"PPCISD::STBRX", SDT_PPCstbrx,
219                           [SDNPHasChain, SDNPMayStore]>;
220
221// Instructions to set/unset CR bit 6 for SVR4 vararg calls
222def PPCcr6set   : SDNode<"PPCISD::CR6SET", SDTNone,
223                         [SDNPHasChain, SDNPOptInGlue, SDNPOutGlue]>;
224def PPCcr6unset : SDNode<"PPCISD::CR6UNSET", SDTNone,
225                         [SDNPHasChain, SDNPOptInGlue, SDNPOutGlue]>;
226
227// Instructions to support dynamic alloca.
228def SDTDynOp  : SDTypeProfile<1, 2, []>;
229def SDTDynAreaOp  : SDTypeProfile<1, 1, []>;
230def PPCdynalloc   : SDNode<"PPCISD::DYNALLOC", SDTDynOp, [SDNPHasChain]>;
231def PPCdynareaoffset   : SDNode<"PPCISD::DYNAREAOFFSET", SDTDynAreaOp, [SDNPHasChain]>;
232
233//===----------------------------------------------------------------------===//
234// PowerPC specific transformation functions and pattern fragments.
235//
236
237def SHL32 : SDNodeXForm<imm, [{
238  // Transformation function: 31 - imm
239  return getI32Imm(31 - N->getZExtValue(), SDLoc(N));
240}]>;
241
242def SRL32 : SDNodeXForm<imm, [{
243  // Transformation function: 32 - imm
244  return N->getZExtValue() ? getI32Imm(32 - N->getZExtValue(), SDLoc(N))
245                           : getI32Imm(0, SDLoc(N));
246}]>;
247
248def LO16 : SDNodeXForm<imm, [{
249  // Transformation function: get the low 16 bits.
250  return getI32Imm((unsigned short)N->getZExtValue(), SDLoc(N));
251}]>;
252
253def HI16 : SDNodeXForm<imm, [{
254  // Transformation function: shift the immediate value down into the low bits.
255  return getI32Imm((unsigned)N->getZExtValue() >> 16, SDLoc(N));
256}]>;
257
258def HA16 : SDNodeXForm<imm, [{
259  // Transformation function: shift the immediate value down into the low bits.
260  signed int Val = N->getZExtValue();
261  return getI32Imm((Val - (signed short)Val) >> 16, SDLoc(N));
262}]>;
263def MB : SDNodeXForm<imm, [{
264  // Transformation function: get the start bit of a mask
265  unsigned mb = 0, me;
266  (void)isRunOfOnes((unsigned)N->getZExtValue(), mb, me);
267  return getI32Imm(mb, SDLoc(N));
268}]>;
269
270def ME : SDNodeXForm<imm, [{
271  // Transformation function: get the end bit of a mask
272  unsigned mb, me = 0;
273  (void)isRunOfOnes((unsigned)N->getZExtValue(), mb, me);
274  return getI32Imm(me, SDLoc(N));
275}]>;
276def maskimm32 : PatLeaf<(imm), [{
277  // maskImm predicate - True if immediate is a run of ones.
278  unsigned mb, me;
279  if (N->getValueType(0) == MVT::i32)
280    return isRunOfOnes((unsigned)N->getZExtValue(), mb, me);
281  else
282    return false;
283}]>;
284
285def imm32SExt16  : Operand<i32>, ImmLeaf<i32, [{
286  // imm32SExt16 predicate - True if the i32 immediate fits in a 16-bit
287  // sign extended field.  Used by instructions like 'addi'.
288  return (int32_t)Imm == (short)Imm;
289}]>;
290def imm64SExt16  : Operand<i64>, ImmLeaf<i64, [{
291  // imm64SExt16 predicate - True if the i64 immediate fits in a 16-bit
292  // sign extended field.  Used by instructions like 'addi'.
293  return (int64_t)Imm == (short)Imm;
294}]>;
295def immZExt16  : PatLeaf<(imm), [{
296  // immZExt16 predicate - True if the immediate fits in a 16-bit zero extended
297  // field.  Used by instructions like 'ori'.
298  return (uint64_t)N->getZExtValue() == (unsigned short)N->getZExtValue();
299}], LO16>;
300
301// imm16Shifted* - These match immediates where the low 16-bits are zero.  There
302// are two forms: imm16ShiftedSExt and imm16ShiftedZExt.  These two forms are
303// identical in 32-bit mode, but in 64-bit mode, they return true if the
304// immediate fits into a sign/zero extended 32-bit immediate (with the low bits
305// clear).
306def imm16ShiftedZExt : PatLeaf<(imm), [{
307  // imm16ShiftedZExt predicate - True if only bits in the top 16-bits of the
308  // immediate are set.  Used by instructions like 'xoris'.
309  return (N->getZExtValue() & ~uint64_t(0xFFFF0000)) == 0;
310}], HI16>;
311
312def imm16ShiftedSExt : PatLeaf<(imm), [{
313  // imm16ShiftedSExt predicate - True if only bits in the top 16-bits of the
314  // immediate are set.  Used by instructions like 'addis'.  Identical to
315  // imm16ShiftedZExt in 32-bit mode.
316  if (N->getZExtValue() & 0xFFFF) return false;
317  if (N->getValueType(0) == MVT::i32)
318    return true;
319  // For 64-bit, make sure it is sext right.
320  return N->getZExtValue() == (uint64_t)(int)N->getZExtValue();
321}], HI16>;
322
323def imm64ZExt32  : Operand<i64>, ImmLeaf<i64, [{
324  // imm64ZExt32 predicate - True if the i64 immediate fits in a 32-bit
325  // zero extended field.
326  return isUInt<32>(Imm);
327}]>;
328
329// Some r+i load/store instructions (such as LD, STD, LDU, etc.) that require
330// restricted memrix (4-aligned) constants are alignment sensitive. If these
331// offsets are hidden behind TOC entries than the values of the lower-order
332// bits cannot be checked directly. As a result, we need to also incorporate
333// an alignment check into the relevant patterns.
334
335def aligned4load : PatFrag<(ops node:$ptr), (load node:$ptr), [{
336  return cast<LoadSDNode>(N)->getAlignment() >= 4;
337}]>;
338def aligned4store : PatFrag<(ops node:$val, node:$ptr),
339                            (store node:$val, node:$ptr), [{
340  return cast<StoreSDNode>(N)->getAlignment() >= 4;
341}]>;
342def aligned4sextloadi32 : PatFrag<(ops node:$ptr), (sextloadi32 node:$ptr), [{
343  return cast<LoadSDNode>(N)->getAlignment() >= 4;
344}]>;
345def aligned4pre_store : PatFrag<
346                          (ops node:$val, node:$base, node:$offset),
347                          (pre_store node:$val, node:$base, node:$offset), [{
348  return cast<StoreSDNode>(N)->getAlignment() >= 4;
349}]>;
350
351def unaligned4load : PatFrag<(ops node:$ptr), (load node:$ptr), [{
352  return cast<LoadSDNode>(N)->getAlignment() < 4;
353}]>;
354def unaligned4store : PatFrag<(ops node:$val, node:$ptr),
355                              (store node:$val, node:$ptr), [{
356  return cast<StoreSDNode>(N)->getAlignment() < 4;
357}]>;
358def unaligned4sextloadi32 : PatFrag<(ops node:$ptr), (sextloadi32 node:$ptr), [{
359  return cast<LoadSDNode>(N)->getAlignment() < 4;
360}]>;
361
362//===----------------------------------------------------------------------===//
363// PowerPC Flag Definitions.
364
365class isPPC64 { bit PPC64 = 1; }
366class isDOT   { bit RC = 1; }
367
368class RegConstraint<string C> {
369  string Constraints = C;
370}
371class NoEncode<string E> {
372  string DisableEncoding = E;
373}
374
375
376//===----------------------------------------------------------------------===//
377// PowerPC Operand Definitions.
378
379// In the default PowerPC assembler syntax, registers are specified simply
380// by number, so they cannot be distinguished from immediate values (without
381// looking at the opcode).  This means that the default operand matching logic
382// for the asm parser does not work, and we need to specify custom matchers.
383// Since those can only be specified with RegisterOperand classes and not
384// directly on the RegisterClass, all instructions patterns used by the asm
385// parser need to use a RegisterOperand (instead of a RegisterClass) for
386// all their register operands.
387// For this purpose, we define one RegisterOperand for each RegisterClass,
388// using the same name as the class, just in lower case.
389
390def PPCRegGPRCAsmOperand : AsmOperandClass {
391  let Name = "RegGPRC"; let PredicateMethod = "isRegNumber";
392}
393def gprc : RegisterOperand<GPRC> {
394  let ParserMatchClass = PPCRegGPRCAsmOperand;
395}
396def PPCRegG8RCAsmOperand : AsmOperandClass {
397  let Name = "RegG8RC"; let PredicateMethod = "isRegNumber";
398}
399def g8rc : RegisterOperand<G8RC> {
400  let ParserMatchClass = PPCRegG8RCAsmOperand;
401}
402def PPCRegGPRCNoR0AsmOperand : AsmOperandClass {
403  let Name = "RegGPRCNoR0"; let PredicateMethod = "isRegNumber";
404}
405def gprc_nor0 : RegisterOperand<GPRC_NOR0> {
406  let ParserMatchClass = PPCRegGPRCNoR0AsmOperand;
407}
408def PPCRegG8RCNoX0AsmOperand : AsmOperandClass {
409  let Name = "RegG8RCNoX0"; let PredicateMethod = "isRegNumber";
410}
411def g8rc_nox0 : RegisterOperand<G8RC_NOX0> {
412  let ParserMatchClass = PPCRegG8RCNoX0AsmOperand;
413}
414def PPCRegF8RCAsmOperand : AsmOperandClass {
415  let Name = "RegF8RC"; let PredicateMethod = "isRegNumber";
416}
417def f8rc : RegisterOperand<F8RC> {
418  let ParserMatchClass = PPCRegF8RCAsmOperand;
419}
420def PPCRegF4RCAsmOperand : AsmOperandClass {
421  let Name = "RegF4RC"; let PredicateMethod = "isRegNumber";
422}
423def f4rc : RegisterOperand<F4RC> {
424  let ParserMatchClass = PPCRegF4RCAsmOperand;
425}
426def PPCRegVRRCAsmOperand : AsmOperandClass {
427  let Name = "RegVRRC"; let PredicateMethod = "isRegNumber";
428}
429def vrrc : RegisterOperand<VRRC> {
430  let ParserMatchClass = PPCRegVRRCAsmOperand;
431}
432def PPCRegCRBITRCAsmOperand : AsmOperandClass {
433  let Name = "RegCRBITRC"; let PredicateMethod = "isCRBitNumber";
434}
435def crbitrc : RegisterOperand<CRBITRC> {
436  let ParserMatchClass = PPCRegCRBITRCAsmOperand;
437}
438def PPCRegCRRCAsmOperand : AsmOperandClass {
439  let Name = "RegCRRC"; let PredicateMethod = "isCCRegNumber";
440}
441def crrc : RegisterOperand<CRRC> {
442  let ParserMatchClass = PPCRegCRRCAsmOperand;
443}
444def crrc0 : RegisterOperand<CRRC0> {
445  let ParserMatchClass = PPCRegCRRCAsmOperand;
446}
447
448def PPCU1ImmAsmOperand : AsmOperandClass {
449  let Name = "U1Imm"; let PredicateMethod = "isU1Imm";
450  let RenderMethod = "addImmOperands";
451}
452def u1imm   : Operand<i32> {
453  let PrintMethod = "printU1ImmOperand";
454  let ParserMatchClass = PPCU1ImmAsmOperand;
455}
456
457def PPCU2ImmAsmOperand : AsmOperandClass {
458  let Name = "U2Imm"; let PredicateMethod = "isU2Imm";
459  let RenderMethod = "addImmOperands";
460}
461def u2imm   : Operand<i32> {
462  let PrintMethod = "printU2ImmOperand";
463  let ParserMatchClass = PPCU2ImmAsmOperand;
464}
465
466def PPCU3ImmAsmOperand : AsmOperandClass {
467  let Name = "U3Imm"; let PredicateMethod = "isU3Imm";
468  let RenderMethod = "addImmOperands";
469}
470def u3imm   : Operand<i32> {
471  let PrintMethod = "printU3ImmOperand";
472  let ParserMatchClass = PPCU3ImmAsmOperand;
473}
474
475def PPCU4ImmAsmOperand : AsmOperandClass {
476  let Name = "U4Imm"; let PredicateMethod = "isU4Imm";
477  let RenderMethod = "addImmOperands";
478}
479def u4imm   : Operand<i32> {
480  let PrintMethod = "printU4ImmOperand";
481  let ParserMatchClass = PPCU4ImmAsmOperand;
482}
483def PPCS5ImmAsmOperand : AsmOperandClass {
484  let Name = "S5Imm"; let PredicateMethod = "isS5Imm";
485  let RenderMethod = "addImmOperands";
486}
487def s5imm   : Operand<i32> {
488  let PrintMethod = "printS5ImmOperand";
489  let ParserMatchClass = PPCS5ImmAsmOperand;
490  let DecoderMethod = "decodeSImmOperand<5>";
491}
492def PPCU5ImmAsmOperand : AsmOperandClass {
493  let Name = "U5Imm"; let PredicateMethod = "isU5Imm";
494  let RenderMethod = "addImmOperands";
495}
496def u5imm   : Operand<i32> {
497  let PrintMethod = "printU5ImmOperand";
498  let ParserMatchClass = PPCU5ImmAsmOperand;
499  let DecoderMethod = "decodeUImmOperand<5>";
500}
501def PPCU6ImmAsmOperand : AsmOperandClass {
502  let Name = "U6Imm"; let PredicateMethod = "isU6Imm";
503  let RenderMethod = "addImmOperands";
504}
505def u6imm   : Operand<i32> {
506  let PrintMethod = "printU6ImmOperand";
507  let ParserMatchClass = PPCU6ImmAsmOperand;
508  let DecoderMethod = "decodeUImmOperand<6>";
509}
510def PPCU7ImmAsmOperand : AsmOperandClass {
511  let Name = "U7Imm"; let PredicateMethod = "isU7Imm";
512  let RenderMethod = "addImmOperands";
513}
514def u7imm   : Operand<i32> {
515  let PrintMethod = "printU7ImmOperand";
516  let ParserMatchClass = PPCU7ImmAsmOperand;
517  let DecoderMethod = "decodeUImmOperand<7>";
518}
519def PPCU8ImmAsmOperand : AsmOperandClass {
520  let Name = "U8Imm"; let PredicateMethod = "isU8Imm";
521  let RenderMethod = "addImmOperands";
522}
523def u8imm   : Operand<i32> {
524  let PrintMethod = "printU8ImmOperand";
525  let ParserMatchClass = PPCU8ImmAsmOperand;
526  let DecoderMethod = "decodeUImmOperand<8>";
527}
528def PPCU10ImmAsmOperand : AsmOperandClass {
529  let Name = "U10Imm"; let PredicateMethod = "isU10Imm";
530  let RenderMethod = "addImmOperands";
531}
532def u10imm  : Operand<i32> {
533  let PrintMethod = "printU10ImmOperand";
534  let ParserMatchClass = PPCU10ImmAsmOperand;
535  let DecoderMethod = "decodeUImmOperand<10>";
536}
537def PPCU12ImmAsmOperand : AsmOperandClass {
538  let Name = "U12Imm"; let PredicateMethod = "isU12Imm";
539  let RenderMethod = "addImmOperands";
540}
541def u12imm  : Operand<i32> {
542  let PrintMethod = "printU12ImmOperand";
543  let ParserMatchClass = PPCU12ImmAsmOperand;
544  let DecoderMethod = "decodeUImmOperand<12>";
545}
546def PPCS16ImmAsmOperand : AsmOperandClass {
547  let Name = "S16Imm"; let PredicateMethod = "isS16Imm";
548  let RenderMethod = "addS16ImmOperands";
549}
550def s16imm  : Operand<i32> {
551  let PrintMethod = "printS16ImmOperand";
552  let EncoderMethod = "getImm16Encoding";
553  let ParserMatchClass = PPCS16ImmAsmOperand;
554  let DecoderMethod = "decodeSImmOperand<16>";
555}
556def PPCU16ImmAsmOperand : AsmOperandClass {
557  let Name = "U16Imm"; let PredicateMethod = "isU16Imm";
558  let RenderMethod = "addU16ImmOperands";
559}
560def u16imm  : Operand<i32> {
561  let PrintMethod = "printU16ImmOperand";
562  let EncoderMethod = "getImm16Encoding";
563  let ParserMatchClass = PPCU16ImmAsmOperand;
564  let DecoderMethod = "decodeUImmOperand<16>";
565}
566def PPCS17ImmAsmOperand : AsmOperandClass {
567  let Name = "S17Imm"; let PredicateMethod = "isS17Imm";
568  let RenderMethod = "addS16ImmOperands";
569}
570def s17imm  : Operand<i32> {
571  // This operand type is used for addis/lis to allow the assembler parser
572  // to accept immediates in the range -65536..65535 for compatibility with
573  // the GNU assembler.  The operand is treated as 16-bit otherwise.
574  let PrintMethod = "printS16ImmOperand";
575  let EncoderMethod = "getImm16Encoding";
576  let ParserMatchClass = PPCS17ImmAsmOperand;
577  let DecoderMethod = "decodeSImmOperand<16>";
578}
579def PPCDirectBrAsmOperand : AsmOperandClass {
580  let Name = "DirectBr"; let PredicateMethod = "isDirectBr";
581  let RenderMethod = "addBranchTargetOperands";
582}
583def directbrtarget : Operand<OtherVT> {
584  let PrintMethod = "printBranchOperand";
585  let EncoderMethod = "getDirectBrEncoding";
586  let ParserMatchClass = PPCDirectBrAsmOperand;
587}
588def absdirectbrtarget : Operand<OtherVT> {
589  let PrintMethod = "printAbsBranchOperand";
590  let EncoderMethod = "getAbsDirectBrEncoding";
591  let ParserMatchClass = PPCDirectBrAsmOperand;
592}
593def PPCCondBrAsmOperand : AsmOperandClass {
594  let Name = "CondBr"; let PredicateMethod = "isCondBr";
595  let RenderMethod = "addBranchTargetOperands";
596}
597def condbrtarget : Operand<OtherVT> {
598  let PrintMethod = "printBranchOperand";
599  let EncoderMethod = "getCondBrEncoding";
600  let ParserMatchClass = PPCCondBrAsmOperand;
601}
602def abscondbrtarget : Operand<OtherVT> {
603  let PrintMethod = "printAbsBranchOperand";
604  let EncoderMethod = "getAbsCondBrEncoding";
605  let ParserMatchClass = PPCCondBrAsmOperand;
606}
607def calltarget : Operand<iPTR> {
608  let PrintMethod = "printBranchOperand";
609  let EncoderMethod = "getDirectBrEncoding";
610  let ParserMatchClass = PPCDirectBrAsmOperand;
611}
612def abscalltarget : Operand<iPTR> {
613  let PrintMethod = "printAbsBranchOperand";
614  let EncoderMethod = "getAbsDirectBrEncoding";
615  let ParserMatchClass = PPCDirectBrAsmOperand;
616}
617def PPCCRBitMaskOperand : AsmOperandClass {
618 let Name = "CRBitMask"; let PredicateMethod = "isCRBitMask";
619}
620def crbitm: Operand<i8> {
621  let PrintMethod = "printcrbitm";
622  let EncoderMethod = "get_crbitm_encoding";
623  let DecoderMethod = "decodeCRBitMOperand";
624  let ParserMatchClass = PPCCRBitMaskOperand;
625}
626// Address operands
627// A version of ptr_rc which excludes R0 (or X0 in 64-bit mode).
628def PPCRegGxRCNoR0Operand : AsmOperandClass {
629  let Name = "RegGxRCNoR0"; let PredicateMethod = "isRegNumber";
630}
631def ptr_rc_nor0 : Operand<iPTR>, PointerLikeRegClass<1> {
632  let ParserMatchClass = PPCRegGxRCNoR0Operand;
633}
634// A version of ptr_rc usable with the asm parser.
635def PPCRegGxRCOperand : AsmOperandClass {
636  let Name = "RegGxRC"; let PredicateMethod = "isRegNumber";
637}
638def ptr_rc_idx : Operand<iPTR>, PointerLikeRegClass<0> {
639  let ParserMatchClass = PPCRegGxRCOperand;
640}
641
642def PPCDispRIOperand : AsmOperandClass {
643 let Name = "DispRI"; let PredicateMethod = "isS16Imm";
644 let RenderMethod = "addS16ImmOperands";
645}
646def dispRI : Operand<iPTR> {
647  let ParserMatchClass = PPCDispRIOperand;
648}
649def PPCDispRIXOperand : AsmOperandClass {
650 let Name = "DispRIX"; let PredicateMethod = "isS16ImmX4";
651 let RenderMethod = "addImmOperands";
652}
653def dispRIX : Operand<iPTR> {
654  let ParserMatchClass = PPCDispRIXOperand;
655}
656def PPCDispRIX16Operand : AsmOperandClass {
657 let Name = "DispRIX16"; let PredicateMethod = "isS16ImmX16";
658 let RenderMethod = "addImmOperands";
659}
660def dispRIX16 : Operand<iPTR> {
661  let ParserMatchClass = PPCDispRIX16Operand;
662}
663def PPCDispSPE8Operand : AsmOperandClass {
664 let Name = "DispSPE8"; let PredicateMethod = "isU8ImmX8";
665 let RenderMethod = "addImmOperands";
666}
667def dispSPE8 : Operand<iPTR> {
668  let ParserMatchClass = PPCDispSPE8Operand;
669}
670def PPCDispSPE4Operand : AsmOperandClass {
671 let Name = "DispSPE4"; let PredicateMethod = "isU7ImmX4";
672 let RenderMethod = "addImmOperands";
673}
674def dispSPE4 : Operand<iPTR> {
675  let ParserMatchClass = PPCDispSPE4Operand;
676}
677def PPCDispSPE2Operand : AsmOperandClass {
678 let Name = "DispSPE2"; let PredicateMethod = "isU6ImmX2";
679 let RenderMethod = "addImmOperands";
680}
681def dispSPE2 : Operand<iPTR> {
682  let ParserMatchClass = PPCDispSPE2Operand;
683}
684
685def memri : Operand<iPTR> {
686  let PrintMethod = "printMemRegImm";
687  let MIOperandInfo = (ops dispRI:$imm, ptr_rc_nor0:$reg);
688  let EncoderMethod = "getMemRIEncoding";
689  let DecoderMethod = "decodeMemRIOperands";
690}
691def memrr : Operand<iPTR> {
692  let PrintMethod = "printMemRegReg";
693  let MIOperandInfo = (ops ptr_rc_nor0:$ptrreg, ptr_rc_idx:$offreg);
694}
695def memrix : Operand<iPTR> {   // memri where the imm is 4-aligned.
696  let PrintMethod = "printMemRegImm";
697  let MIOperandInfo = (ops dispRIX:$imm, ptr_rc_nor0:$reg);
698  let EncoderMethod = "getMemRIXEncoding";
699  let DecoderMethod = "decodeMemRIXOperands";
700}
701def memrix16 : Operand<iPTR> { // memri, imm is 16-aligned, 12-bit, Inst{16:27}
702  let PrintMethod = "printMemRegImm";
703  let MIOperandInfo = (ops dispRIX16:$imm, ptr_rc_nor0:$reg);
704  let EncoderMethod = "getMemRIX16Encoding";
705  let DecoderMethod = "decodeMemRIX16Operands";
706}
707def spe8dis : Operand<iPTR> {   // SPE displacement where the imm is 8-aligned.
708  let PrintMethod = "printMemRegImm";
709  let MIOperandInfo = (ops dispSPE8:$imm, ptr_rc_nor0:$reg);
710  let EncoderMethod = "getSPE8DisEncoding";
711}
712def spe4dis : Operand<iPTR> {   // SPE displacement where the imm is 4-aligned.
713  let PrintMethod = "printMemRegImm";
714  let MIOperandInfo = (ops dispSPE4:$imm, ptr_rc_nor0:$reg);
715  let EncoderMethod = "getSPE4DisEncoding";
716}
717def spe2dis : Operand<iPTR> {   // SPE displacement where the imm is 2-aligned.
718  let PrintMethod = "printMemRegImm";
719  let MIOperandInfo = (ops dispSPE2:$imm, ptr_rc_nor0:$reg);
720  let EncoderMethod = "getSPE2DisEncoding";
721}
722
723// A single-register address. This is used with the SjLj
724// pseudo-instructions.
725def memr : Operand<iPTR> {
726  let MIOperandInfo = (ops ptr_rc:$ptrreg);
727}
728def PPCTLSRegOperand : AsmOperandClass {
729  let Name = "TLSReg"; let PredicateMethod = "isTLSReg";
730  let RenderMethod = "addTLSRegOperands";
731}
732def tlsreg32 : Operand<i32> {
733  let EncoderMethod = "getTLSRegEncoding";
734  let ParserMatchClass = PPCTLSRegOperand;
735}
736def tlsgd32 : Operand<i32> {}
737def tlscall32 : Operand<i32> {
738  let PrintMethod = "printTLSCall";
739  let MIOperandInfo = (ops calltarget:$func, tlsgd32:$sym);
740  let EncoderMethod = "getTLSCallEncoding";
741}
742
743// PowerPC Predicate operand.
744def pred : Operand<OtherVT> {
745  let PrintMethod = "printPredicateOperand";
746  let MIOperandInfo = (ops i32imm:$bibo, crrc:$reg);
747}
748
749// Define PowerPC specific addressing mode.
750def iaddr  : ComplexPattern<iPTR, 2, "SelectAddrImm",    [], []>;
751def xaddr  : ComplexPattern<iPTR, 2, "SelectAddrIdx",    [], []>;
752def xoaddr : ComplexPattern<iPTR, 2, "SelectAddrIdxOnly",[], []>;
753def ixaddr : ComplexPattern<iPTR, 2, "SelectAddrImmX4",  [], []>; // "std"
754
755// The address in a single register. This is used with the SjLj
756// pseudo-instructions.
757def addr   : ComplexPattern<iPTR, 1, "SelectAddr",[], []>;
758
759/// This is just the offset part of iaddr, used for preinc.
760def iaddroff : ComplexPattern<iPTR, 1, "SelectAddrImmOffs", [], []>;
761
762//===----------------------------------------------------------------------===//
763// PowerPC Instruction Predicate Definitions.
764def In32BitMode  : Predicate<"!PPCSubTarget->isPPC64()">;
765def In64BitMode  : Predicate<"PPCSubTarget->isPPC64()">;
766def IsBookE  : Predicate<"PPCSubTarget->isBookE()">;
767def IsNotBookE  : Predicate<"!PPCSubTarget->isBookE()">;
768def HasOnlyMSYNC : Predicate<"PPCSubTarget->hasOnlyMSYNC()">;
769def HasSYNC   : Predicate<"!PPCSubTarget->hasOnlyMSYNC()">;
770def IsPPC4xx  : Predicate<"PPCSubTarget->isPPC4xx()">;
771def IsPPC6xx  : Predicate<"PPCSubTarget->isPPC6xx()">;
772def IsE500  : Predicate<"PPCSubTarget->isE500()">;
773def HasSPE  : Predicate<"PPCSubTarget->HasSPE()">;
774def HasICBT : Predicate<"PPCSubTarget->hasICBT()">;
775def HasPartwordAtomics : Predicate<"PPCSubTarget->hasPartwordAtomics()">;
776def NoNaNsFPMath : Predicate<"TM.Options.NoNaNsFPMath">;
777def NaNsFPMath   : Predicate<"!TM.Options.NoNaNsFPMath">;
778def HasBPERMD : Predicate<"PPCSubTarget->hasBPERMD()">;
779def HasExtDiv : Predicate<"PPCSubTarget->hasExtDiv()">;
780
781//===----------------------------------------------------------------------===//
782// PowerPC Multiclass Definitions.
783
784multiclass XForm_6r<bits<6> opcode, bits<10> xo, dag OOL, dag IOL,
785                    string asmbase, string asmstr, InstrItinClass itin,
786                    list<dag> pattern> {
787  let BaseName = asmbase in {
788    def NAME : XForm_6<opcode, xo, OOL, IOL,
789                       !strconcat(asmbase, !strconcat(" ", asmstr)), itin,
790                       pattern>, RecFormRel;
791    let Defs = [CR0] in
792    def o    : XForm_6<opcode, xo, OOL, IOL,
793                       !strconcat(asmbase, !strconcat(". ", asmstr)), itin,
794                       []>, isDOT, RecFormRel;
795  }
796}
797
798multiclass XForm_6rc<bits<6> opcode, bits<10> xo, dag OOL, dag IOL,
799                     string asmbase, string asmstr, InstrItinClass itin,
800                     list<dag> pattern> {
801  let BaseName = asmbase in {
802    let Defs = [CARRY] in
803    def NAME : XForm_6<opcode, xo, OOL, IOL,
804                       !strconcat(asmbase, !strconcat(" ", asmstr)), itin,
805                       pattern>, RecFormRel;
806    let Defs = [CARRY, CR0] in
807    def o    : XForm_6<opcode, xo, OOL, IOL,
808                       !strconcat(asmbase, !strconcat(". ", asmstr)), itin,
809                       []>, isDOT, RecFormRel;
810  }
811}
812
813multiclass XForm_10rc<bits<6> opcode, bits<10> xo, dag OOL, dag IOL,
814                      string asmbase, string asmstr, InstrItinClass itin,
815                      list<dag> pattern> {
816  let BaseName = asmbase in {
817    let Defs = [CARRY] in
818    def NAME : XForm_10<opcode, xo, OOL, IOL,
819                       !strconcat(asmbase, !strconcat(" ", asmstr)), itin,
820                       pattern>, RecFormRel;
821    let Defs = [CARRY, CR0] in
822    def o    : XForm_10<opcode, xo, OOL, IOL,
823                       !strconcat(asmbase, !strconcat(". ", asmstr)), itin,
824                       []>, isDOT, RecFormRel;
825  }
826}
827
828multiclass XForm_11r<bits<6> opcode, bits<10> xo, dag OOL, dag IOL,
829                    string asmbase, string asmstr, InstrItinClass itin,
830                    list<dag> pattern> {
831  let BaseName = asmbase in {
832    def NAME : XForm_11<opcode, xo, OOL, IOL,
833                       !strconcat(asmbase, !strconcat(" ", asmstr)), itin,
834                       pattern>, RecFormRel;
835    let Defs = [CR0] in
836    def o    : XForm_11<opcode, xo, OOL, IOL,
837                       !strconcat(asmbase, !strconcat(". ", asmstr)), itin,
838                       []>, isDOT, RecFormRel;
839  }
840}
841
842multiclass XOForm_1r<bits<6> opcode, bits<9> xo, bit oe, dag OOL, dag IOL,
843                    string asmbase, string asmstr, InstrItinClass itin,
844                    list<dag> pattern> {
845  let BaseName = asmbase in {
846    def NAME : XOForm_1<opcode, xo, oe, OOL, IOL,
847                       !strconcat(asmbase, !strconcat(" ", asmstr)), itin,
848                       pattern>, RecFormRel;
849    let Defs = [CR0] in
850    def o    : XOForm_1<opcode, xo, oe, OOL, IOL,
851                       !strconcat(asmbase, !strconcat(". ", asmstr)), itin,
852                       []>, isDOT, RecFormRel;
853  }
854}
855
856// Multiclass for instructions for which the non record form is not cracked
857// and the record form is cracked (i.e. divw, mullw, etc.)
858multiclass XOForm_1rcr<bits<6> opcode, bits<9> xo, bit oe, dag OOL, dag IOL,
859                      string asmbase, string asmstr, InstrItinClass itin,
860                      list<dag> pattern> {
861  let BaseName = asmbase in {
862    def NAME : XOForm_1<opcode, xo, oe, OOL, IOL,
863                       !strconcat(asmbase, !strconcat(" ", asmstr)), itin,
864                       pattern>, RecFormRel;
865    let Defs = [CR0] in
866    def o    : XOForm_1<opcode, xo, oe, OOL, IOL,
867                       !strconcat(asmbase, !strconcat(". ", asmstr)), itin,
868                       []>, isDOT, RecFormRel, PPC970_DGroup_First,
869                       PPC970_DGroup_Cracked;
870  }
871}
872
873multiclass XOForm_1rc<bits<6> opcode, bits<9> xo, bit oe, dag OOL, dag IOL,
874                      string asmbase, string asmstr, InstrItinClass itin,
875                      list<dag> pattern> {
876  let BaseName = asmbase in {
877    let Defs = [CARRY] in
878    def NAME : XOForm_1<opcode, xo, oe, OOL, IOL,
879                       !strconcat(asmbase, !strconcat(" ", asmstr)), itin,
880                       pattern>, RecFormRel;
881    let Defs = [CARRY, CR0] in
882    def o    : XOForm_1<opcode, xo, oe, OOL, IOL,
883                       !strconcat(asmbase, !strconcat(". ", asmstr)), itin,
884                       []>, isDOT, RecFormRel;
885  }
886}
887
888multiclass XOForm_3r<bits<6> opcode, bits<9> xo, bit oe, dag OOL, dag IOL,
889                    string asmbase, string asmstr, InstrItinClass itin,
890                    list<dag> pattern> {
891  let BaseName = asmbase in {
892    def NAME : XOForm_3<opcode, xo, oe, OOL, IOL,
893                       !strconcat(asmbase, !strconcat(" ", asmstr)), itin,
894                       pattern>, RecFormRel;
895    let Defs = [CR0] in
896    def o    : XOForm_3<opcode, xo, oe, OOL, IOL,
897                       !strconcat(asmbase, !strconcat(". ", asmstr)), itin,
898                       []>, isDOT, RecFormRel;
899  }
900}
901
902multiclass XOForm_3rc<bits<6> opcode, bits<9> xo, bit oe, dag OOL, dag IOL,
903                      string asmbase, string asmstr, InstrItinClass itin,
904                      list<dag> pattern> {
905  let BaseName = asmbase in {
906    let Defs = [CARRY] in
907    def NAME : XOForm_3<opcode, xo, oe, OOL, IOL,
908                       !strconcat(asmbase, !strconcat(" ", asmstr)), itin,
909                       pattern>, RecFormRel;
910    let Defs = [CARRY, CR0] in
911    def o    : XOForm_3<opcode, xo, oe, OOL, IOL,
912                       !strconcat(asmbase, !strconcat(". ", asmstr)), itin,
913                       []>, isDOT, RecFormRel;
914  }
915}
916
917multiclass MForm_2r<bits<6> opcode, dag OOL, dag IOL,
918                    string asmbase, string asmstr, InstrItinClass itin,
919                    list<dag> pattern> {
920  let BaseName = asmbase in {
921    def NAME : MForm_2<opcode, OOL, IOL,
922                       !strconcat(asmbase, !strconcat(" ", asmstr)), itin,
923                       pattern>, RecFormRel;
924    let Defs = [CR0] in
925    def o    : MForm_2<opcode, OOL, IOL,
926                       !strconcat(asmbase, !strconcat(". ", asmstr)), itin,
927                       []>, isDOT, RecFormRel;
928  }
929}
930
931multiclass MDForm_1r<bits<6> opcode, bits<3> xo, dag OOL, dag IOL,
932                    string asmbase, string asmstr, InstrItinClass itin,
933                    list<dag> pattern> {
934  let BaseName = asmbase in {
935    def NAME : MDForm_1<opcode, xo, OOL, IOL,
936                       !strconcat(asmbase, !strconcat(" ", asmstr)), itin,
937                       pattern>, RecFormRel;
938    let Defs = [CR0] in
939    def o    : MDForm_1<opcode, xo, OOL, IOL,
940                       !strconcat(asmbase, !strconcat(". ", asmstr)), itin,
941                       []>, isDOT, RecFormRel;
942  }
943}
944
945multiclass MDSForm_1r<bits<6> opcode, bits<4> xo, dag OOL, dag IOL,
946                     string asmbase, string asmstr, InstrItinClass itin,
947                     list<dag> pattern> {
948  let BaseName = asmbase in {
949    def NAME : MDSForm_1<opcode, xo, OOL, IOL,
950                        !strconcat(asmbase, !strconcat(" ", asmstr)), itin,
951                        pattern>, RecFormRel;
952    let Defs = [CR0] in
953    def o    : MDSForm_1<opcode, xo, OOL, IOL,
954                        !strconcat(asmbase, !strconcat(". ", asmstr)), itin,
955                        []>, isDOT, RecFormRel;
956  }
957}
958
959multiclass XSForm_1rc<bits<6> opcode, bits<9> xo, dag OOL, dag IOL,
960                      string asmbase, string asmstr, InstrItinClass itin,
961                      list<dag> pattern> {
962  let BaseName = asmbase in {
963    let Defs = [CARRY] in
964    def NAME : XSForm_1<opcode, xo, OOL, IOL,
965                       !strconcat(asmbase, !strconcat(" ", asmstr)), itin,
966                       pattern>, RecFormRel;
967    let Defs = [CARRY, CR0] in
968    def o    : XSForm_1<opcode, xo, OOL, IOL,
969                       !strconcat(asmbase, !strconcat(". ", asmstr)), itin,
970                       []>, isDOT, RecFormRel;
971  }
972}
973
974multiclass XForm_26r<bits<6> opcode, bits<10> xo, dag OOL, dag IOL,
975                    string asmbase, string asmstr, InstrItinClass itin,
976                    list<dag> pattern> {
977  let BaseName = asmbase in {
978    def NAME : XForm_26<opcode, xo, OOL, IOL,
979                       !strconcat(asmbase, !strconcat(" ", asmstr)), itin,
980                       pattern>, RecFormRel;
981    let Defs = [CR1] in
982    def o    : XForm_26<opcode, xo, OOL, IOL,
983                       !strconcat(asmbase, !strconcat(". ", asmstr)), itin,
984                       []>, isDOT, RecFormRel;
985  }
986}
987
988multiclass XForm_28r<bits<6> opcode, bits<10> xo, dag OOL, dag IOL,
989                    string asmbase, string asmstr, InstrItinClass itin,
990                    list<dag> pattern> {
991  let BaseName = asmbase in {
992    def NAME : XForm_28<opcode, xo, OOL, IOL,
993                       !strconcat(asmbase, !strconcat(" ", asmstr)), itin,
994                       pattern>, RecFormRel;
995    let Defs = [CR1] in
996    def o    : XForm_28<opcode, xo, OOL, IOL,
997                       !strconcat(asmbase, !strconcat(". ", asmstr)), itin,
998                       []>, isDOT, RecFormRel;
999  }
1000}
1001
1002multiclass AForm_1r<bits<6> opcode, bits<5> xo, dag OOL, dag IOL,
1003                    string asmbase, string asmstr, InstrItinClass itin,
1004                    list<dag> pattern> {
1005  let BaseName = asmbase in {
1006    def NAME : AForm_1<opcode, xo, OOL, IOL,
1007                       !strconcat(asmbase, !strconcat(" ", asmstr)), itin,
1008                       pattern>, RecFormRel;
1009    let Defs = [CR1] in
1010    def o    : AForm_1<opcode, xo, OOL, IOL,
1011                       !strconcat(asmbase, !strconcat(". ", asmstr)), itin,
1012                       []>, isDOT, RecFormRel;
1013  }
1014}
1015
1016multiclass AForm_2r<bits<6> opcode, bits<5> xo, dag OOL, dag IOL,
1017                    string asmbase, string asmstr, InstrItinClass itin,
1018                    list<dag> pattern> {
1019  let BaseName = asmbase in {
1020    def NAME : AForm_2<opcode, xo, OOL, IOL,
1021                       !strconcat(asmbase, !strconcat(" ", asmstr)), itin,
1022                       pattern>, RecFormRel;
1023    let Defs = [CR1] in
1024    def o    : AForm_2<opcode, xo, OOL, IOL,
1025                       !strconcat(asmbase, !strconcat(". ", asmstr)), itin,
1026                       []>, isDOT, RecFormRel;
1027  }
1028}
1029
1030multiclass AForm_3r<bits<6> opcode, bits<5> xo, dag OOL, dag IOL,
1031                    string asmbase, string asmstr, InstrItinClass itin,
1032                    list<dag> pattern> {
1033  let BaseName = asmbase in {
1034    def NAME : AForm_3<opcode, xo, OOL, IOL,
1035                       !strconcat(asmbase, !strconcat(" ", asmstr)), itin,
1036                       pattern>, RecFormRel;
1037    let Defs = [CR1] in
1038    def o    : AForm_3<opcode, xo, OOL, IOL,
1039                       !strconcat(asmbase, !strconcat(". ", asmstr)), itin,
1040                       []>, isDOT, RecFormRel;
1041  }
1042}
1043
1044//===----------------------------------------------------------------------===//
1045// PowerPC Instruction Definitions.
1046
1047// Pseudo-instructions:
1048
1049let hasCtrlDep = 1 in {
1050let Defs = [R1], Uses = [R1] in {
1051def ADJCALLSTACKDOWN : Pseudo<(outs), (ins u16imm:$amt), "#ADJCALLSTACKDOWN $amt",
1052                              [(callseq_start timm:$amt)]>;
1053def ADJCALLSTACKUP   : Pseudo<(outs), (ins u16imm:$amt1, u16imm:$amt2), "#ADJCALLSTACKUP $amt1 $amt2",
1054                              [(callseq_end timm:$amt1, timm:$amt2)]>;
1055}
1056
1057def UPDATE_VRSAVE    : Pseudo<(outs gprc:$rD), (ins gprc:$rS),
1058                              "UPDATE_VRSAVE $rD, $rS", []>;
1059}
1060
1061let Defs = [R1], Uses = [R1] in
1062def DYNALLOC : Pseudo<(outs gprc:$result), (ins gprc:$negsize, memri:$fpsi), "#DYNALLOC",
1063                       [(set i32:$result,
1064                             (PPCdynalloc i32:$negsize, iaddr:$fpsi))]>;
1065def DYNAREAOFFSET : Pseudo<(outs i32imm:$result), (ins memri:$fpsi), "#DYNAREAOFFSET",
1066                       [(set i32:$result, (PPCdynareaoffset iaddr:$fpsi))]>;
1067
1068// SELECT_CC_* - Used to implement the SELECT_CC DAG operation.  Expanded after
1069// instruction selection into a branch sequence.
1070let usesCustomInserter = 1,    // Expanded after instruction selection.
1071    PPC970_Single = 1 in {
1072  // Note that SELECT_CC_I4 and SELECT_CC_I8 use the no-r0 register classes
1073  // because either operand might become the first operand in an isel, and
1074  // that operand cannot be r0.
1075  def SELECT_CC_I4 : Pseudo<(outs gprc:$dst), (ins crrc:$cond,
1076                              gprc_nor0:$T, gprc_nor0:$F,
1077                              i32imm:$BROPC), "#SELECT_CC_I4",
1078                              []>;
1079  def SELECT_CC_I8 : Pseudo<(outs g8rc:$dst), (ins crrc:$cond,
1080                              g8rc_nox0:$T, g8rc_nox0:$F,
1081                              i32imm:$BROPC), "#SELECT_CC_I8",
1082                              []>;
1083  def SELECT_CC_F4  : Pseudo<(outs f4rc:$dst), (ins crrc:$cond, f4rc:$T, f4rc:$F,
1084                              i32imm:$BROPC), "#SELECT_CC_F4",
1085                              []>;
1086  def SELECT_CC_F8  : Pseudo<(outs f8rc:$dst), (ins crrc:$cond, f8rc:$T, f8rc:$F,
1087                              i32imm:$BROPC), "#SELECT_CC_F8",
1088                              []>;
1089  def SELECT_CC_VRRC: Pseudo<(outs vrrc:$dst), (ins crrc:$cond, vrrc:$T, vrrc:$F,
1090                              i32imm:$BROPC), "#SELECT_CC_VRRC",
1091                              []>;
1092
1093  // SELECT_* pseudo instructions, like SELECT_CC_* but taking condition
1094  // register bit directly.
1095  def SELECT_I4 : Pseudo<(outs gprc:$dst), (ins crbitrc:$cond,
1096                          gprc_nor0:$T, gprc_nor0:$F), "#SELECT_I4",
1097                          [(set i32:$dst, (select i1:$cond, i32:$T, i32:$F))]>;
1098  def SELECT_I8 : Pseudo<(outs g8rc:$dst), (ins crbitrc:$cond,
1099                          g8rc_nox0:$T, g8rc_nox0:$F), "#SELECT_I8",
1100                          [(set i64:$dst, (select i1:$cond, i64:$T, i64:$F))]>;
1101  def SELECT_F4  : Pseudo<(outs f4rc:$dst), (ins crbitrc:$cond,
1102                          f4rc:$T, f4rc:$F), "#SELECT_F4",
1103                          [(set f32:$dst, (select i1:$cond, f32:$T, f32:$F))]>;
1104  def SELECT_F8  : Pseudo<(outs f8rc:$dst), (ins crbitrc:$cond,
1105                          f8rc:$T, f8rc:$F), "#SELECT_F8",
1106                          [(set f64:$dst, (select i1:$cond, f64:$T, f64:$F))]>;
1107  def SELECT_VRRC: Pseudo<(outs vrrc:$dst), (ins crbitrc:$cond,
1108                          vrrc:$T, vrrc:$F), "#SELECT_VRRC",
1109                          [(set v4i32:$dst,
1110                                (select i1:$cond, v4i32:$T, v4i32:$F))]>;
1111}
1112
1113// SPILL_CR - Indicate that we're dumping the CR register, so we'll need to
1114// scavenge a register for it.
1115let mayStore = 1 in {
1116def SPILL_CR : Pseudo<(outs), (ins crrc:$cond, memri:$F),
1117                     "#SPILL_CR", []>;
1118def SPILL_CRBIT : Pseudo<(outs), (ins crbitrc:$cond, memri:$F),
1119                         "#SPILL_CRBIT", []>;
1120}
1121
1122// RESTORE_CR - Indicate that we're restoring the CR register (previously
1123// spilled), so we'll need to scavenge a register for it.
1124let mayLoad = 1 in {
1125def RESTORE_CR : Pseudo<(outs crrc:$cond), (ins memri:$F),
1126                     "#RESTORE_CR", []>;
1127def RESTORE_CRBIT : Pseudo<(outs crbitrc:$cond), (ins memri:$F),
1128                           "#RESTORE_CRBIT", []>;
1129}
1130
1131let isTerminator = 1, isBarrier = 1, PPC970_Unit = 7 in {
1132  let isReturn = 1, Uses = [LR, RM] in
1133    def BLR : XLForm_2_ext<19, 16, 20, 0, 0, (outs), (ins), "blr", IIC_BrB,
1134                           [(retflag)]>, Requires<[In32BitMode]>;
1135  let isBranch = 1, isIndirectBranch = 1, Uses = [CTR] in {
1136    def BCTR : XLForm_2_ext<19, 528, 20, 0, 0, (outs), (ins), "bctr", IIC_BrB,
1137                            []>;
1138
1139    let isCodeGenOnly = 1 in {
1140      def BCCCTR : XLForm_2_br<19, 528, 0, (outs), (ins pred:$cond),
1141                               "b${cond:cc}ctr${cond:pm} ${cond:reg}", IIC_BrB,
1142                               []>;
1143
1144      def BCCTR :  XLForm_2_br2<19, 528, 12, 0, (outs), (ins crbitrc:$bi),
1145                                "bcctr 12, $bi, 0", IIC_BrB, []>;
1146      def BCCTRn : XLForm_2_br2<19, 528, 4, 0, (outs), (ins crbitrc:$bi),
1147                                "bcctr 4, $bi, 0", IIC_BrB, []>;
1148    }
1149  }
1150}
1151
1152let Defs = [LR] in
1153  def MovePCtoLR : Pseudo<(outs), (ins), "#MovePCtoLR", []>,
1154                   PPC970_Unit_BRU;
1155let Defs = [LR] in
1156  def MoveGOTtoLR : Pseudo<(outs), (ins), "#MoveGOTtoLR", []>,
1157                    PPC970_Unit_BRU;
1158
1159let isBranch = 1, isTerminator = 1, hasCtrlDep = 1, PPC970_Unit = 7 in {
1160  let isBarrier = 1 in {
1161  def B   : IForm<18, 0, 0, (outs), (ins directbrtarget:$dst),
1162                  "b $dst", IIC_BrB,
1163                  [(br bb:$dst)]>;
1164  def BA  : IForm<18, 1, 0, (outs), (ins absdirectbrtarget:$dst),
1165                  "ba $dst", IIC_BrB, []>;
1166  }
1167
1168  // BCC represents an arbitrary conditional branch on a predicate.
1169  // FIXME: should be able to write a pattern for PPCcondbranch, but can't use
1170  // a two-value operand where a dag node expects two operands. :(
1171  let isCodeGenOnly = 1 in {
1172    def BCC : BForm<16, 0, 0, (outs), (ins pred:$cond, condbrtarget:$dst),
1173                    "b${cond:cc}${cond:pm} ${cond:reg}, $dst"
1174                    /*[(PPCcondbranch crrc:$crS, imm:$opc, bb:$dst)]*/>;
1175    def BCCA : BForm<16, 1, 0, (outs), (ins pred:$cond, abscondbrtarget:$dst),
1176                     "b${cond:cc}a${cond:pm} ${cond:reg}, $dst">;
1177
1178    let isReturn = 1, Uses = [LR, RM] in
1179    def BCCLR : XLForm_2_br<19, 16, 0, (outs), (ins pred:$cond),
1180                           "b${cond:cc}lr${cond:pm} ${cond:reg}", IIC_BrB, []>;
1181  }
1182
1183  let isCodeGenOnly = 1 in {
1184    let Pattern = [(brcond i1:$bi, bb:$dst)] in
1185    def BC  : BForm_4<16, 12, 0, 0, (outs), (ins crbitrc:$bi, condbrtarget:$dst),
1186             "bc 12, $bi, $dst">;
1187
1188    let Pattern = [(brcond (not i1:$bi), bb:$dst)] in
1189    def BCn : BForm_4<16, 4, 0, 0, (outs), (ins crbitrc:$bi, condbrtarget:$dst),
1190             "bc 4, $bi, $dst">;
1191
1192    let isReturn = 1, Uses = [LR, RM] in
1193    def BCLR  : XLForm_2_br2<19, 16, 12, 0, (outs), (ins crbitrc:$bi),
1194                             "bclr 12, $bi, 0", IIC_BrB, []>;
1195    def BCLRn : XLForm_2_br2<19, 16, 4, 0, (outs), (ins crbitrc:$bi),
1196                             "bclr 4, $bi, 0", IIC_BrB, []>;
1197  }
1198
1199  let isReturn = 1, Defs = [CTR], Uses = [CTR, LR, RM] in {
1200   def BDZLR  : XLForm_2_ext<19, 16, 18, 0, 0, (outs), (ins),
1201                             "bdzlr", IIC_BrB, []>;
1202   def BDNZLR : XLForm_2_ext<19, 16, 16, 0, 0, (outs), (ins),
1203                             "bdnzlr", IIC_BrB, []>;
1204   def BDZLRp : XLForm_2_ext<19, 16, 27, 0, 0, (outs), (ins),
1205                             "bdzlr+", IIC_BrB, []>;
1206   def BDNZLRp: XLForm_2_ext<19, 16, 25, 0, 0, (outs), (ins),
1207                             "bdnzlr+", IIC_BrB, []>;
1208   def BDZLRm : XLForm_2_ext<19, 16, 26, 0, 0, (outs), (ins),
1209                             "bdzlr-", IIC_BrB, []>;
1210   def BDNZLRm: XLForm_2_ext<19, 16, 24, 0, 0, (outs), (ins),
1211                             "bdnzlr-", IIC_BrB, []>;
1212  }
1213
1214  let Defs = [CTR], Uses = [CTR] in {
1215    def BDZ  : BForm_1<16, 18, 0, 0, (outs), (ins condbrtarget:$dst),
1216                       "bdz $dst">;
1217    def BDNZ : BForm_1<16, 16, 0, 0, (outs), (ins condbrtarget:$dst),
1218                       "bdnz $dst">;
1219    def BDZA  : BForm_1<16, 18, 1, 0, (outs), (ins abscondbrtarget:$dst),
1220                        "bdza $dst">;
1221    def BDNZA : BForm_1<16, 16, 1, 0, (outs), (ins abscondbrtarget:$dst),
1222                        "bdnza $dst">;
1223    def BDZp : BForm_1<16, 27, 0, 0, (outs), (ins condbrtarget:$dst),
1224                       "bdz+ $dst">;
1225    def BDNZp: BForm_1<16, 25, 0, 0, (outs), (ins condbrtarget:$dst),
1226                       "bdnz+ $dst">;
1227    def BDZAp : BForm_1<16, 27, 1, 0, (outs), (ins abscondbrtarget:$dst),
1228                        "bdza+ $dst">;
1229    def BDNZAp: BForm_1<16, 25, 1, 0, (outs), (ins abscondbrtarget:$dst),
1230                        "bdnza+ $dst">;
1231    def BDZm : BForm_1<16, 26, 0, 0, (outs), (ins condbrtarget:$dst),
1232                       "bdz- $dst">;
1233    def BDNZm: BForm_1<16, 24, 0, 0, (outs), (ins condbrtarget:$dst),
1234                       "bdnz- $dst">;
1235    def BDZAm : BForm_1<16, 26, 1, 0, (outs), (ins abscondbrtarget:$dst),
1236                        "bdza- $dst">;
1237    def BDNZAm: BForm_1<16, 24, 1, 0, (outs), (ins abscondbrtarget:$dst),
1238                        "bdnza- $dst">;
1239  }
1240}
1241
1242// The unconditional BCL used by the SjLj setjmp code.
1243let isCall = 1, hasCtrlDep = 1, isCodeGenOnly = 1, PPC970_Unit = 7 in {
1244  let Defs = [LR], Uses = [RM] in {
1245    def BCLalways  : BForm_2<16, 20, 31, 0, 1, (outs), (ins condbrtarget:$dst),
1246                            "bcl 20, 31, $dst">;
1247  }
1248}
1249
1250let isCall = 1, PPC970_Unit = 7, Defs = [LR] in {
1251  // Convenient aliases for call instructions
1252  let Uses = [RM] in {
1253    def BL  : IForm<18, 0, 1, (outs), (ins calltarget:$func),
1254                    "bl $func", IIC_BrB, []>;  // See Pat patterns below.
1255    def BLA : IForm<18, 1, 1, (outs), (ins abscalltarget:$func),
1256                    "bla $func", IIC_BrB, [(PPCcall (i32 imm:$func))]>;
1257
1258    let isCodeGenOnly = 1 in {
1259      def BL_TLS  : IForm<18, 0, 1, (outs), (ins tlscall32:$func),
1260                          "bl $func", IIC_BrB, []>;
1261      def BCCL : BForm<16, 0, 1, (outs), (ins pred:$cond, condbrtarget:$dst),
1262                       "b${cond:cc}l${cond:pm} ${cond:reg}, $dst">;
1263      def BCCLA : BForm<16, 1, 1, (outs), (ins pred:$cond, abscondbrtarget:$dst),
1264                        "b${cond:cc}la${cond:pm} ${cond:reg}, $dst">;
1265
1266      def BCL  : BForm_4<16, 12, 0, 1, (outs),
1267                         (ins crbitrc:$bi, condbrtarget:$dst),
1268                         "bcl 12, $bi, $dst">;
1269      def BCLn : BForm_4<16, 4, 0, 1, (outs),
1270                         (ins crbitrc:$bi, condbrtarget:$dst),
1271                         "bcl 4, $bi, $dst">;
1272    }
1273  }
1274  let Uses = [CTR, RM] in {
1275    def BCTRL : XLForm_2_ext<19, 528, 20, 0, 1, (outs), (ins),
1276                             "bctrl", IIC_BrB, [(PPCbctrl)]>,
1277                Requires<[In32BitMode]>;
1278
1279    let isCodeGenOnly = 1 in {
1280      def BCCCTRL : XLForm_2_br<19, 528, 1, (outs), (ins pred:$cond),
1281                                "b${cond:cc}ctrl${cond:pm} ${cond:reg}", IIC_BrB,
1282                                []>;
1283
1284      def BCCTRL  : XLForm_2_br2<19, 528, 12, 1, (outs), (ins crbitrc:$bi),
1285                                 "bcctrl 12, $bi, 0", IIC_BrB, []>;
1286      def BCCTRLn : XLForm_2_br2<19, 528, 4, 1, (outs), (ins crbitrc:$bi),
1287                                 "bcctrl 4, $bi, 0", IIC_BrB, []>;
1288    }
1289  }
1290  let Uses = [LR, RM] in {
1291    def BLRL : XLForm_2_ext<19, 16, 20, 0, 1, (outs), (ins),
1292                            "blrl", IIC_BrB, []>;
1293
1294    let isCodeGenOnly = 1 in {
1295      def BCCLRL : XLForm_2_br<19, 16, 1, (outs), (ins pred:$cond),
1296                              "b${cond:cc}lrl${cond:pm} ${cond:reg}", IIC_BrB,
1297                              []>;
1298
1299      def BCLRL  : XLForm_2_br2<19, 16, 12, 1, (outs), (ins crbitrc:$bi),
1300                                "bclrl 12, $bi, 0", IIC_BrB, []>;
1301      def BCLRLn : XLForm_2_br2<19, 16, 4, 1, (outs), (ins crbitrc:$bi),
1302                                "bclrl 4, $bi, 0", IIC_BrB, []>;
1303    }
1304  }
1305  let Defs = [CTR], Uses = [CTR, RM] in {
1306    def BDZL  : BForm_1<16, 18, 0, 1, (outs), (ins condbrtarget:$dst),
1307                        "bdzl $dst">;
1308    def BDNZL : BForm_1<16, 16, 0, 1, (outs), (ins condbrtarget:$dst),
1309                        "bdnzl $dst">;
1310    def BDZLA  : BForm_1<16, 18, 1, 1, (outs), (ins abscondbrtarget:$dst),
1311                         "bdzla $dst">;
1312    def BDNZLA : BForm_1<16, 16, 1, 1, (outs), (ins abscondbrtarget:$dst),
1313                         "bdnzla $dst">;
1314    def BDZLp : BForm_1<16, 27, 0, 1, (outs), (ins condbrtarget:$dst),
1315                        "bdzl+ $dst">;
1316    def BDNZLp: BForm_1<16, 25, 0, 1, (outs), (ins condbrtarget:$dst),
1317                        "bdnzl+ $dst">;
1318    def BDZLAp : BForm_1<16, 27, 1, 1, (outs), (ins abscondbrtarget:$dst),
1319                         "bdzla+ $dst">;
1320    def BDNZLAp: BForm_1<16, 25, 1, 1, (outs), (ins abscondbrtarget:$dst),
1321                         "bdnzla+ $dst">;
1322    def BDZLm : BForm_1<16, 26, 0, 1, (outs), (ins condbrtarget:$dst),
1323                        "bdzl- $dst">;
1324    def BDNZLm: BForm_1<16, 24, 0, 1, (outs), (ins condbrtarget:$dst),
1325                        "bdnzl- $dst">;
1326    def BDZLAm : BForm_1<16, 26, 1, 1, (outs), (ins abscondbrtarget:$dst),
1327                         "bdzla- $dst">;
1328    def BDNZLAm: BForm_1<16, 24, 1, 1, (outs), (ins abscondbrtarget:$dst),
1329                         "bdnzla- $dst">;
1330  }
1331  let Defs = [CTR], Uses = [CTR, LR, RM] in {
1332    def BDZLRL  : XLForm_2_ext<19, 16, 18, 0, 1, (outs), (ins),
1333                               "bdzlrl", IIC_BrB, []>;
1334    def BDNZLRL : XLForm_2_ext<19, 16, 16, 0, 1, (outs), (ins),
1335                               "bdnzlrl", IIC_BrB, []>;
1336    def BDZLRLp : XLForm_2_ext<19, 16, 27, 0, 1, (outs), (ins),
1337                               "bdzlrl+", IIC_BrB, []>;
1338    def BDNZLRLp: XLForm_2_ext<19, 16, 25, 0, 1, (outs), (ins),
1339                               "bdnzlrl+", IIC_BrB, []>;
1340    def BDZLRLm : XLForm_2_ext<19, 16, 26, 0, 1, (outs), (ins),
1341                               "bdzlrl-", IIC_BrB, []>;
1342    def BDNZLRLm: XLForm_2_ext<19, 16, 24, 0, 1, (outs), (ins),
1343                               "bdnzlrl-", IIC_BrB, []>;
1344  }
1345}
1346
1347let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1, Uses = [RM] in
1348def TCRETURNdi :Pseudo< (outs),
1349                        (ins calltarget:$dst, i32imm:$offset),
1350                 "#TC_RETURNd $dst $offset",
1351                 []>;
1352
1353
1354let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1, Uses = [RM] in
1355def TCRETURNai :Pseudo<(outs), (ins abscalltarget:$func, i32imm:$offset),
1356                 "#TC_RETURNa $func $offset",
1357                 [(PPCtc_return (i32 imm:$func), imm:$offset)]>;
1358
1359let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1, Uses = [RM] in
1360def TCRETURNri : Pseudo<(outs), (ins CTRRC:$dst, i32imm:$offset),
1361                 "#TC_RETURNr $dst $offset",
1362                 []>;
1363
1364
1365let isCodeGenOnly = 1 in {
1366
1367let isTerminator = 1, isBarrier = 1, PPC970_Unit = 7, isBranch = 1,
1368    isIndirectBranch = 1, isCall = 1, isReturn = 1, Uses = [CTR, RM]  in
1369def TAILBCTR : XLForm_2_ext<19, 528, 20, 0, 0, (outs), (ins), "bctr", IIC_BrB,
1370                            []>, Requires<[In32BitMode]>;
1371
1372let isBranch = 1, isTerminator = 1, hasCtrlDep = 1, PPC970_Unit = 7,
1373    isBarrier = 1, isCall = 1, isReturn = 1, Uses = [RM] in
1374def TAILB   : IForm<18, 0, 0, (outs), (ins calltarget:$dst),
1375                  "b $dst", IIC_BrB,
1376                  []>;
1377
1378let isBranch = 1, isTerminator = 1, hasCtrlDep = 1, PPC970_Unit = 7,
1379    isBarrier = 1, isCall = 1, isReturn = 1, Uses = [RM] in
1380def TAILBA   : IForm<18, 0, 0, (outs), (ins abscalltarget:$dst),
1381                  "ba $dst", IIC_BrB,
1382                  []>;
1383
1384}
1385
1386let hasSideEffects = 1, isBarrier = 1, usesCustomInserter = 1 in {
1387  let Defs = [CTR] in
1388  def EH_SjLj_SetJmp32  : Pseudo<(outs gprc:$dst), (ins memr:$buf),
1389                            "#EH_SJLJ_SETJMP32",
1390                            [(set i32:$dst, (PPCeh_sjlj_setjmp addr:$buf))]>,
1391                          Requires<[In32BitMode]>;
1392  let isTerminator = 1 in
1393  def EH_SjLj_LongJmp32 : Pseudo<(outs), (ins memr:$buf),
1394                            "#EH_SJLJ_LONGJMP32",
1395                            [(PPCeh_sjlj_longjmp addr:$buf)]>,
1396                          Requires<[In32BitMode]>;
1397}
1398
1399let isBranch = 1, isTerminator = 1 in {
1400  def EH_SjLj_Setup : Pseudo<(outs), (ins directbrtarget:$dst),
1401                        "#EH_SjLj_Setup\t$dst", []>;
1402}
1403
1404// System call.
1405let PPC970_Unit = 7 in {
1406  def SC     : SCForm<17, 1, (outs), (ins i32imm:$lev),
1407                      "sc $lev", IIC_BrB, [(PPCsc (i32 imm:$lev))]>;
1408}
1409
1410// Branch history rolling buffer.
1411def CLRBHRB : XForm_0<31, 430, (outs), (ins), "clrbhrb", IIC_BrB,
1412                      [(PPCclrbhrb)]>,
1413                      PPC970_DGroup_Single;
1414// The $dmy argument used for MFBHRBE is not needed; however, including
1415// it avoids automatic generation of PPCFastISel::fastEmit_i(), which
1416// interferes with necessary special handling (see PPCFastISel.cpp).
1417def MFBHRBE : XFXForm_3p<31, 302, (outs gprc:$rD),
1418                         (ins u10imm:$imm, u10imm:$dmy),
1419                         "mfbhrbe $rD, $imm", IIC_BrB,
1420                         [(set i32:$rD,
1421                               (PPCmfbhrbe imm:$imm, imm:$dmy))]>,
1422                         PPC970_DGroup_First;
1423
1424def RFEBB : XLForm_S<19, 146, (outs), (ins u1imm:$imm), "rfebb $imm",
1425                     IIC_BrB, [(PPCrfebb (i32 imm:$imm))]>,
1426                     PPC970_DGroup_Single;
1427
1428// DCB* instructions.
1429def DCBA   : DCB_Form<758, 0, (outs), (ins memrr:$dst), "dcba $dst",
1430                      IIC_LdStDCBF, [(int_ppc_dcba xoaddr:$dst)]>,
1431                      PPC970_DGroup_Single;
1432def DCBF   : DCB_Form<86, 0, (outs), (ins memrr:$dst), "dcbf $dst",
1433                      IIC_LdStDCBF, [(int_ppc_dcbf xoaddr:$dst)]>,
1434                      PPC970_DGroup_Single;
1435def DCBI   : DCB_Form<470, 0, (outs), (ins memrr:$dst), "dcbi $dst",
1436                      IIC_LdStDCBF, [(int_ppc_dcbi xoaddr:$dst)]>,
1437                      PPC970_DGroup_Single;
1438def DCBST  : DCB_Form<54, 0, (outs), (ins memrr:$dst), "dcbst $dst",
1439                      IIC_LdStDCBF, [(int_ppc_dcbst xoaddr:$dst)]>,
1440                      PPC970_DGroup_Single;
1441def DCBZ   : DCB_Form<1014, 0, (outs), (ins memrr:$dst), "dcbz $dst",
1442                      IIC_LdStDCBF, [(int_ppc_dcbz xoaddr:$dst)]>,
1443                      PPC970_DGroup_Single;
1444def DCBZL  : DCB_Form<1014, 1, (outs), (ins memrr:$dst), "dcbzl $dst",
1445                      IIC_LdStDCBF, [(int_ppc_dcbzl xoaddr:$dst)]>,
1446                      PPC970_DGroup_Single;
1447
1448let hasSideEffects = 0, mayLoad = 1, mayStore = 1 in {
1449def DCBT   : DCB_Form_hint<278, (outs), (ins u5imm:$TH, memrr:$dst),
1450                      "dcbt $dst, $TH", IIC_LdStDCBF, []>,
1451                      PPC970_DGroup_Single;
1452def DCBTST : DCB_Form_hint<246, (outs), (ins u5imm:$TH, memrr:$dst),
1453                      "dcbtst $dst, $TH", IIC_LdStDCBF, []>,
1454                      PPC970_DGroup_Single;
1455} // hasSideEffects = 0
1456
1457def ICBT  : XForm_icbt<31, 22, (outs), (ins u4imm:$CT, memrr:$src),
1458                       "icbt $CT, $src", IIC_LdStLoad>, Requires<[HasICBT]>;
1459
1460def : Pat<(int_ppc_dcbt xoaddr:$dst),
1461          (DCBT 0, xoaddr:$dst)>;
1462def : Pat<(int_ppc_dcbtst xoaddr:$dst),
1463          (DCBTST 0, xoaddr:$dst)>;
1464
1465def : Pat<(prefetch xoaddr:$dst, (i32 0), imm, (i32 1)),
1466          (DCBT 0, xoaddr:$dst)>;   // data prefetch for loads
1467def : Pat<(prefetch xoaddr:$dst, (i32 1), imm, (i32 1)),
1468          (DCBTST 0, xoaddr:$dst)>; // data prefetch for stores
1469def : Pat<(prefetch xoaddr:$dst, (i32 0), imm, (i32 0)),
1470          (ICBT 0, xoaddr:$dst)>, Requires<[HasICBT]>; // inst prefetch (for read)
1471
1472// Atomic operations
1473let usesCustomInserter = 1 in {
1474  let Defs = [CR0] in {
1475    def ATOMIC_LOAD_ADD_I8 : Pseudo<
1476      (outs gprc:$dst), (ins memrr:$ptr, gprc:$incr), "#ATOMIC_LOAD_ADD_I8",
1477      [(set i32:$dst, (atomic_load_add_8 xoaddr:$ptr, i32:$incr))]>;
1478    def ATOMIC_LOAD_SUB_I8 : Pseudo<
1479      (outs gprc:$dst), (ins memrr:$ptr, gprc:$incr), "#ATOMIC_LOAD_SUB_I8",
1480      [(set i32:$dst, (atomic_load_sub_8 xoaddr:$ptr, i32:$incr))]>;
1481    def ATOMIC_LOAD_AND_I8 : Pseudo<
1482      (outs gprc:$dst), (ins memrr:$ptr, gprc:$incr), "#ATOMIC_LOAD_AND_I8",
1483      [(set i32:$dst, (atomic_load_and_8 xoaddr:$ptr, i32:$incr))]>;
1484    def ATOMIC_LOAD_OR_I8 : Pseudo<
1485      (outs gprc:$dst), (ins memrr:$ptr, gprc:$incr), "#ATOMIC_LOAD_OR_I8",
1486      [(set i32:$dst, (atomic_load_or_8 xoaddr:$ptr, i32:$incr))]>;
1487    def ATOMIC_LOAD_XOR_I8 : Pseudo<
1488      (outs gprc:$dst), (ins memrr:$ptr, gprc:$incr), "ATOMIC_LOAD_XOR_I8",
1489      [(set i32:$dst, (atomic_load_xor_8 xoaddr:$ptr, i32:$incr))]>;
1490    def ATOMIC_LOAD_NAND_I8 : Pseudo<
1491      (outs gprc:$dst), (ins memrr:$ptr, gprc:$incr), "#ATOMIC_LOAD_NAND_I8",
1492      [(set i32:$dst, (atomic_load_nand_8 xoaddr:$ptr, i32:$incr))]>;
1493    def ATOMIC_LOAD_ADD_I16 : Pseudo<
1494      (outs gprc:$dst), (ins memrr:$ptr, gprc:$incr), "#ATOMIC_LOAD_ADD_I16",
1495      [(set i32:$dst, (atomic_load_add_16 xoaddr:$ptr, i32:$incr))]>;
1496    def ATOMIC_LOAD_SUB_I16 : Pseudo<
1497      (outs gprc:$dst), (ins memrr:$ptr, gprc:$incr), "#ATOMIC_LOAD_SUB_I16",
1498      [(set i32:$dst, (atomic_load_sub_16 xoaddr:$ptr, i32:$incr))]>;
1499    def ATOMIC_LOAD_AND_I16 : Pseudo<
1500      (outs gprc:$dst), (ins memrr:$ptr, gprc:$incr), "#ATOMIC_LOAD_AND_I16",
1501      [(set i32:$dst, (atomic_load_and_16 xoaddr:$ptr, i32:$incr))]>;
1502    def ATOMIC_LOAD_OR_I16 : Pseudo<
1503      (outs gprc:$dst), (ins memrr:$ptr, gprc:$incr), "#ATOMIC_LOAD_OR_I16",
1504      [(set i32:$dst, (atomic_load_or_16 xoaddr:$ptr, i32:$incr))]>;
1505    def ATOMIC_LOAD_XOR_I16 : Pseudo<
1506      (outs gprc:$dst), (ins memrr:$ptr, gprc:$incr), "#ATOMIC_LOAD_XOR_I16",
1507      [(set i32:$dst, (atomic_load_xor_16 xoaddr:$ptr, i32:$incr))]>;
1508    def ATOMIC_LOAD_NAND_I16 : Pseudo<
1509      (outs gprc:$dst), (ins memrr:$ptr, gprc:$incr), "#ATOMIC_LOAD_NAND_I16",
1510      [(set i32:$dst, (atomic_load_nand_16 xoaddr:$ptr, i32:$incr))]>;
1511    def ATOMIC_LOAD_ADD_I32 : Pseudo<
1512      (outs gprc:$dst), (ins memrr:$ptr, gprc:$incr), "#ATOMIC_LOAD_ADD_I32",
1513      [(set i32:$dst, (atomic_load_add_32 xoaddr:$ptr, i32:$incr))]>;
1514    def ATOMIC_LOAD_SUB_I32 : Pseudo<
1515      (outs gprc:$dst), (ins memrr:$ptr, gprc:$incr), "#ATOMIC_LOAD_SUB_I32",
1516      [(set i32:$dst, (atomic_load_sub_32 xoaddr:$ptr, i32:$incr))]>;
1517    def ATOMIC_LOAD_AND_I32 : Pseudo<
1518      (outs gprc:$dst), (ins memrr:$ptr, gprc:$incr), "#ATOMIC_LOAD_AND_I32",
1519      [(set i32:$dst, (atomic_load_and_32 xoaddr:$ptr, i32:$incr))]>;
1520    def ATOMIC_LOAD_OR_I32 : Pseudo<
1521      (outs gprc:$dst), (ins memrr:$ptr, gprc:$incr), "#ATOMIC_LOAD_OR_I32",
1522      [(set i32:$dst, (atomic_load_or_32 xoaddr:$ptr, i32:$incr))]>;
1523    def ATOMIC_LOAD_XOR_I32 : Pseudo<
1524      (outs gprc:$dst), (ins memrr:$ptr, gprc:$incr), "#ATOMIC_LOAD_XOR_I32",
1525      [(set i32:$dst, (atomic_load_xor_32 xoaddr:$ptr, i32:$incr))]>;
1526    def ATOMIC_LOAD_NAND_I32 : Pseudo<
1527      (outs gprc:$dst), (ins memrr:$ptr, gprc:$incr), "#ATOMIC_LOAD_NAND_I32",
1528      [(set i32:$dst, (atomic_load_nand_32 xoaddr:$ptr, i32:$incr))]>;
1529
1530    def ATOMIC_CMP_SWAP_I8 : Pseudo<
1531      (outs gprc:$dst), (ins memrr:$ptr, gprc:$old, gprc:$new), "#ATOMIC_CMP_SWAP_I8",
1532      [(set i32:$dst, (atomic_cmp_swap_8 xoaddr:$ptr, i32:$old, i32:$new))]>;
1533    def ATOMIC_CMP_SWAP_I16 : Pseudo<
1534      (outs gprc:$dst), (ins memrr:$ptr, gprc:$old, gprc:$new), "#ATOMIC_CMP_SWAP_I16 $dst $ptr $old $new",
1535      [(set i32:$dst, (atomic_cmp_swap_16 xoaddr:$ptr, i32:$old, i32:$new))]>;
1536    def ATOMIC_CMP_SWAP_I32 : Pseudo<
1537      (outs gprc:$dst), (ins memrr:$ptr, gprc:$old, gprc:$new), "#ATOMIC_CMP_SWAP_I32 $dst $ptr $old $new",
1538      [(set i32:$dst, (atomic_cmp_swap_32 xoaddr:$ptr, i32:$old, i32:$new))]>;
1539
1540    def ATOMIC_SWAP_I8 : Pseudo<
1541      (outs gprc:$dst), (ins memrr:$ptr, gprc:$new), "#ATOMIC_SWAP_i8",
1542      [(set i32:$dst, (atomic_swap_8 xoaddr:$ptr, i32:$new))]>;
1543    def ATOMIC_SWAP_I16 : Pseudo<
1544      (outs gprc:$dst), (ins memrr:$ptr, gprc:$new), "#ATOMIC_SWAP_I16",
1545      [(set i32:$dst, (atomic_swap_16 xoaddr:$ptr, i32:$new))]>;
1546    def ATOMIC_SWAP_I32 : Pseudo<
1547      (outs gprc:$dst), (ins memrr:$ptr, gprc:$new), "#ATOMIC_SWAP_I32",
1548      [(set i32:$dst, (atomic_swap_32 xoaddr:$ptr, i32:$new))]>;
1549  }
1550}
1551
1552// Instructions to support atomic operations
1553let mayLoad = 1, hasSideEffects = 0 in {
1554def LBARX : XForm_1<31,  52, (outs gprc:$rD), (ins memrr:$src),
1555                    "lbarx $rD, $src", IIC_LdStLWARX, []>,
1556                    Requires<[HasPartwordAtomics]>;
1557
1558def LHARX : XForm_1<31,  116, (outs gprc:$rD), (ins memrr:$src),
1559                    "lharx $rD, $src", IIC_LdStLWARX, []>,
1560                    Requires<[HasPartwordAtomics]>;
1561
1562def LWARX : XForm_1<31,  20, (outs gprc:$rD), (ins memrr:$src),
1563                    "lwarx $rD, $src", IIC_LdStLWARX, []>;
1564
1565// Instructions to support lock versions of atomics
1566// (EH=1 - see Power ISA 2.07 Book II 4.4.2)
1567def LBARXL : XForm_1<31,  52, (outs gprc:$rD), (ins memrr:$src),
1568                     "lbarx $rD, $src, 1", IIC_LdStLWARX, []>, isDOT,
1569                     Requires<[HasPartwordAtomics]>;
1570
1571def LHARXL : XForm_1<31,  116, (outs gprc:$rD), (ins memrr:$src),
1572                     "lharx $rD, $src, 1", IIC_LdStLWARX, []>, isDOT,
1573                     Requires<[HasPartwordAtomics]>;
1574
1575def LWARXL : XForm_1<31,  20, (outs gprc:$rD), (ins memrr:$src),
1576                     "lwarx $rD, $src, 1", IIC_LdStLWARX, []>, isDOT;
1577}
1578
1579let Defs = [CR0], mayStore = 1, hasSideEffects = 0 in {
1580def STBCX : XForm_1<31, 694, (outs), (ins gprc:$rS, memrr:$dst),
1581                    "stbcx. $rS, $dst", IIC_LdStSTWCX, []>,
1582                    isDOT, Requires<[HasPartwordAtomics]>;
1583
1584def STHCX : XForm_1<31, 726, (outs), (ins gprc:$rS, memrr:$dst),
1585                    "sthcx. $rS, $dst", IIC_LdStSTWCX, []>,
1586                    isDOT, Requires<[HasPartwordAtomics]>;
1587
1588def STWCX : XForm_1<31, 150, (outs), (ins gprc:$rS, memrr:$dst),
1589                    "stwcx. $rS, $dst", IIC_LdStSTWCX, []>, isDOT;
1590}
1591
1592let isTerminator = 1, isBarrier = 1, hasCtrlDep = 1 in
1593def TRAP  : XForm_24<31, 4, (outs), (ins), "trap", IIC_LdStLoad, [(trap)]>;
1594
1595def TWI : DForm_base<3, (outs), (ins u5imm:$to, gprc:$rA, s16imm:$imm),
1596                     "twi $to, $rA, $imm", IIC_IntTrapW, []>;
1597def TW : XForm_1<31, 4, (outs), (ins u5imm:$to, gprc:$rA, gprc:$rB),
1598                 "tw $to, $rA, $rB", IIC_IntTrapW, []>;
1599def TDI : DForm_base<2, (outs), (ins u5imm:$to, g8rc:$rA, s16imm:$imm),
1600                     "tdi $to, $rA, $imm", IIC_IntTrapD, []>;
1601def TD : XForm_1<31, 68, (outs), (ins u5imm:$to, g8rc:$rA, g8rc:$rB),
1602                 "td $to, $rA, $rB", IIC_IntTrapD, []>;
1603
1604//===----------------------------------------------------------------------===//
1605// PPC32 Load Instructions.
1606//
1607
1608// Unindexed (r+i) Loads.
1609let PPC970_Unit = 2 in {
1610def LBZ : DForm_1<34, (outs gprc:$rD), (ins memri:$src),
1611                  "lbz $rD, $src", IIC_LdStLoad,
1612                  [(set i32:$rD, (zextloadi8 iaddr:$src))]>;
1613def LHA : DForm_1<42, (outs gprc:$rD), (ins memri:$src),
1614                  "lha $rD, $src", IIC_LdStLHA,
1615                  [(set i32:$rD, (sextloadi16 iaddr:$src))]>,
1616                  PPC970_DGroup_Cracked;
1617def LHZ : DForm_1<40, (outs gprc:$rD), (ins memri:$src),
1618                  "lhz $rD, $src", IIC_LdStLoad,
1619                  [(set i32:$rD, (zextloadi16 iaddr:$src))]>;
1620def LWZ : DForm_1<32, (outs gprc:$rD), (ins memri:$src),
1621                  "lwz $rD, $src", IIC_LdStLoad,
1622                  [(set i32:$rD, (load iaddr:$src))]>;
1623
1624def LFS : DForm_1<48, (outs f4rc:$rD), (ins memri:$src),
1625                  "lfs $rD, $src", IIC_LdStLFD,
1626                  [(set f32:$rD, (load iaddr:$src))]>;
1627def LFD : DForm_1<50, (outs f8rc:$rD), (ins memri:$src),
1628                  "lfd $rD, $src", IIC_LdStLFD,
1629                  [(set f64:$rD, (load iaddr:$src))]>;
1630
1631
1632// Unindexed (r+i) Loads with Update (preinc).
1633let mayLoad = 1, hasSideEffects = 0 in {
1634def LBZU : DForm_1<35, (outs gprc:$rD, ptr_rc_nor0:$ea_result), (ins memri:$addr),
1635                   "lbzu $rD, $addr", IIC_LdStLoadUpd,
1636                   []>, RegConstraint<"$addr.reg = $ea_result">,
1637                   NoEncode<"$ea_result">;
1638
1639def LHAU : DForm_1<43, (outs gprc:$rD, ptr_rc_nor0:$ea_result), (ins memri:$addr),
1640                   "lhau $rD, $addr", IIC_LdStLHAU,
1641                   []>, RegConstraint<"$addr.reg = $ea_result">,
1642                   NoEncode<"$ea_result">;
1643
1644def LHZU : DForm_1<41, (outs gprc:$rD, ptr_rc_nor0:$ea_result), (ins memri:$addr),
1645                   "lhzu $rD, $addr", IIC_LdStLoadUpd,
1646                   []>, RegConstraint<"$addr.reg = $ea_result">,
1647                   NoEncode<"$ea_result">;
1648
1649def LWZU : DForm_1<33, (outs gprc:$rD, ptr_rc_nor0:$ea_result), (ins memri:$addr),
1650                   "lwzu $rD, $addr", IIC_LdStLoadUpd,
1651                   []>, RegConstraint<"$addr.reg = $ea_result">,
1652                   NoEncode<"$ea_result">;
1653
1654def LFSU : DForm_1<49, (outs f4rc:$rD, ptr_rc_nor0:$ea_result), (ins memri:$addr),
1655                  "lfsu $rD, $addr", IIC_LdStLFDU,
1656                  []>, RegConstraint<"$addr.reg = $ea_result">,
1657                   NoEncode<"$ea_result">;
1658
1659def LFDU : DForm_1<51, (outs f8rc:$rD, ptr_rc_nor0:$ea_result), (ins memri:$addr),
1660                  "lfdu $rD, $addr", IIC_LdStLFDU,
1661                  []>, RegConstraint<"$addr.reg = $ea_result">,
1662                   NoEncode<"$ea_result">;
1663
1664
1665// Indexed (r+r) Loads with Update (preinc).
1666def LBZUX : XForm_1<31, 119, (outs gprc:$rD, ptr_rc_nor0:$ea_result),
1667                   (ins memrr:$addr),
1668                   "lbzux $rD, $addr", IIC_LdStLoadUpdX,
1669                   []>, RegConstraint<"$addr.ptrreg = $ea_result">,
1670                   NoEncode<"$ea_result">;
1671
1672def LHAUX : XForm_1<31, 375, (outs gprc:$rD, ptr_rc_nor0:$ea_result),
1673                   (ins memrr:$addr),
1674                   "lhaux $rD, $addr", IIC_LdStLHAUX,
1675                   []>, RegConstraint<"$addr.ptrreg = $ea_result">,
1676                   NoEncode<"$ea_result">;
1677
1678def LHZUX : XForm_1<31, 311, (outs gprc:$rD, ptr_rc_nor0:$ea_result),
1679                   (ins memrr:$addr),
1680                   "lhzux $rD, $addr", IIC_LdStLoadUpdX,
1681                   []>, RegConstraint<"$addr.ptrreg = $ea_result">,
1682                   NoEncode<"$ea_result">;
1683
1684def LWZUX : XForm_1<31, 55, (outs gprc:$rD, ptr_rc_nor0:$ea_result),
1685                   (ins memrr:$addr),
1686                   "lwzux $rD, $addr", IIC_LdStLoadUpdX,
1687                   []>, RegConstraint<"$addr.ptrreg = $ea_result">,
1688                   NoEncode<"$ea_result">;
1689
1690def LFSUX : XForm_1<31, 567, (outs f4rc:$rD, ptr_rc_nor0:$ea_result),
1691                   (ins memrr:$addr),
1692                   "lfsux $rD, $addr", IIC_LdStLFDUX,
1693                   []>, RegConstraint<"$addr.ptrreg = $ea_result">,
1694                   NoEncode<"$ea_result">;
1695
1696def LFDUX : XForm_1<31, 631, (outs f8rc:$rD, ptr_rc_nor0:$ea_result),
1697                   (ins memrr:$addr),
1698                   "lfdux $rD, $addr", IIC_LdStLFDUX,
1699                   []>, RegConstraint<"$addr.ptrreg = $ea_result">,
1700                   NoEncode<"$ea_result">;
1701}
1702}
1703
1704// Indexed (r+r) Loads.
1705//
1706let PPC970_Unit = 2 in {
1707def LBZX : XForm_1<31,  87, (outs gprc:$rD), (ins memrr:$src),
1708                   "lbzx $rD, $src", IIC_LdStLoad,
1709                   [(set i32:$rD, (zextloadi8 xaddr:$src))]>;
1710def LHAX : XForm_1<31, 343, (outs gprc:$rD), (ins memrr:$src),
1711                   "lhax $rD, $src", IIC_LdStLHA,
1712                   [(set i32:$rD, (sextloadi16 xaddr:$src))]>,
1713                   PPC970_DGroup_Cracked;
1714def LHZX : XForm_1<31, 279, (outs gprc:$rD), (ins memrr:$src),
1715                   "lhzx $rD, $src", IIC_LdStLoad,
1716                   [(set i32:$rD, (zextloadi16 xaddr:$src))]>;
1717def LWZX : XForm_1<31,  23, (outs gprc:$rD), (ins memrr:$src),
1718                   "lwzx $rD, $src", IIC_LdStLoad,
1719                   [(set i32:$rD, (load xaddr:$src))]>;
1720
1721
1722def LHBRX : XForm_1<31, 790, (outs gprc:$rD), (ins memrr:$src),
1723                   "lhbrx $rD, $src", IIC_LdStLoad,
1724                   [(set i32:$rD, (PPClbrx xoaddr:$src, i16))]>;
1725def LWBRX : XForm_1<31,  534, (outs gprc:$rD), (ins memrr:$src),
1726                   "lwbrx $rD, $src", IIC_LdStLoad,
1727                   [(set i32:$rD, (PPClbrx xoaddr:$src, i32))]>;
1728
1729def LFSX   : XForm_25<31, 535, (outs f4rc:$frD), (ins memrr:$src),
1730                      "lfsx $frD, $src", IIC_LdStLFD,
1731                      [(set f32:$frD, (load xaddr:$src))]>;
1732def LFDX   : XForm_25<31, 599, (outs f8rc:$frD), (ins memrr:$src),
1733                      "lfdx $frD, $src", IIC_LdStLFD,
1734                      [(set f64:$frD, (load xaddr:$src))]>;
1735
1736def LFIWAX : XForm_25<31, 855, (outs f8rc:$frD), (ins memrr:$src),
1737                      "lfiwax $frD, $src", IIC_LdStLFD,
1738                      [(set f64:$frD, (PPClfiwax xoaddr:$src))]>;
1739def LFIWZX : XForm_25<31, 887, (outs f8rc:$frD), (ins memrr:$src),
1740                      "lfiwzx $frD, $src", IIC_LdStLFD,
1741                      [(set f64:$frD, (PPClfiwzx xoaddr:$src))]>;
1742}
1743
1744// Load Multiple
1745def LMW : DForm_1<46, (outs gprc:$rD), (ins memri:$src),
1746                  "lmw $rD, $src", IIC_LdStLMW, []>;
1747
1748//===----------------------------------------------------------------------===//
1749// PPC32 Store Instructions.
1750//
1751
1752// Unindexed (r+i) Stores.
1753let PPC970_Unit = 2 in {
1754def STB  : DForm_1<38, (outs), (ins gprc:$rS, memri:$src),
1755                   "stb $rS, $src", IIC_LdStStore,
1756                   [(truncstorei8 i32:$rS, iaddr:$src)]>;
1757def STH  : DForm_1<44, (outs), (ins gprc:$rS, memri:$src),
1758                   "sth $rS, $src", IIC_LdStStore,
1759                   [(truncstorei16 i32:$rS, iaddr:$src)]>;
1760def STW  : DForm_1<36, (outs), (ins gprc:$rS, memri:$src),
1761                   "stw $rS, $src", IIC_LdStStore,
1762                   [(store i32:$rS, iaddr:$src)]>;
1763def STFS : DForm_1<52, (outs), (ins f4rc:$rS, memri:$dst),
1764                   "stfs $rS, $dst", IIC_LdStSTFD,
1765                   [(store f32:$rS, iaddr:$dst)]>;
1766def STFD : DForm_1<54, (outs), (ins f8rc:$rS, memri:$dst),
1767                   "stfd $rS, $dst", IIC_LdStSTFD,
1768                   [(store f64:$rS, iaddr:$dst)]>;
1769}
1770
1771// Unindexed (r+i) Stores with Update (preinc).
1772let PPC970_Unit = 2, mayStore = 1 in {
1773def STBU  : DForm_1<39, (outs ptr_rc_nor0:$ea_res), (ins gprc:$rS, memri:$dst),
1774                    "stbu $rS, $dst", IIC_LdStStoreUpd, []>,
1775                    RegConstraint<"$dst.reg = $ea_res">, NoEncode<"$ea_res">;
1776def STHU  : DForm_1<45, (outs ptr_rc_nor0:$ea_res), (ins gprc:$rS, memri:$dst),
1777                    "sthu $rS, $dst", IIC_LdStStoreUpd, []>,
1778                    RegConstraint<"$dst.reg = $ea_res">, NoEncode<"$ea_res">;
1779def STWU  : DForm_1<37, (outs ptr_rc_nor0:$ea_res), (ins gprc:$rS, memri:$dst),
1780                    "stwu $rS, $dst", IIC_LdStStoreUpd, []>,
1781                    RegConstraint<"$dst.reg = $ea_res">, NoEncode<"$ea_res">;
1782def STFSU : DForm_1<53, (outs ptr_rc_nor0:$ea_res), (ins f4rc:$rS, memri:$dst),
1783                    "stfsu $rS, $dst", IIC_LdStSTFDU, []>,
1784                    RegConstraint<"$dst.reg = $ea_res">, NoEncode<"$ea_res">;
1785def STFDU : DForm_1<55, (outs ptr_rc_nor0:$ea_res), (ins f8rc:$rS, memri:$dst),
1786                    "stfdu $rS, $dst", IIC_LdStSTFDU, []>,
1787                    RegConstraint<"$dst.reg = $ea_res">, NoEncode<"$ea_res">;
1788}
1789
1790// Patterns to match the pre-inc stores.  We can't put the patterns on
1791// the instruction definitions directly as ISel wants the address base
1792// and offset to be separate operands, not a single complex operand.
1793def : Pat<(pre_truncsti8 i32:$rS, iPTR:$ptrreg, iaddroff:$ptroff),
1794          (STBU $rS, iaddroff:$ptroff, $ptrreg)>;
1795def : Pat<(pre_truncsti16 i32:$rS, iPTR:$ptrreg, iaddroff:$ptroff),
1796          (STHU $rS, iaddroff:$ptroff, $ptrreg)>;
1797def : Pat<(pre_store i32:$rS, iPTR:$ptrreg, iaddroff:$ptroff),
1798          (STWU $rS, iaddroff:$ptroff, $ptrreg)>;
1799def : Pat<(pre_store f32:$rS, iPTR:$ptrreg, iaddroff:$ptroff),
1800          (STFSU $rS, iaddroff:$ptroff, $ptrreg)>;
1801def : Pat<(pre_store f64:$rS, iPTR:$ptrreg, iaddroff:$ptroff),
1802          (STFDU $rS, iaddroff:$ptroff, $ptrreg)>;
1803
1804// Indexed (r+r) Stores.
1805let PPC970_Unit = 2 in {
1806def STBX  : XForm_8<31, 215, (outs), (ins gprc:$rS, memrr:$dst),
1807                   "stbx $rS, $dst", IIC_LdStStore,
1808                   [(truncstorei8 i32:$rS, xaddr:$dst)]>,
1809                   PPC970_DGroup_Cracked;
1810def STHX  : XForm_8<31, 407, (outs), (ins gprc:$rS, memrr:$dst),
1811                   "sthx $rS, $dst", IIC_LdStStore,
1812                   [(truncstorei16 i32:$rS, xaddr:$dst)]>,
1813                   PPC970_DGroup_Cracked;
1814def STWX  : XForm_8<31, 151, (outs), (ins gprc:$rS, memrr:$dst),
1815                   "stwx $rS, $dst", IIC_LdStStore,
1816                   [(store i32:$rS, xaddr:$dst)]>,
1817                   PPC970_DGroup_Cracked;
1818
1819def STHBRX: XForm_8<31, 918, (outs), (ins gprc:$rS, memrr:$dst),
1820                   "sthbrx $rS, $dst", IIC_LdStStore,
1821                   [(PPCstbrx i32:$rS, xoaddr:$dst, i16)]>,
1822                   PPC970_DGroup_Cracked;
1823def STWBRX: XForm_8<31, 662, (outs), (ins gprc:$rS, memrr:$dst),
1824                   "stwbrx $rS, $dst", IIC_LdStStore,
1825                   [(PPCstbrx i32:$rS, xoaddr:$dst, i32)]>,
1826                   PPC970_DGroup_Cracked;
1827
1828def STFIWX: XForm_28<31, 983, (outs), (ins f8rc:$frS, memrr:$dst),
1829                     "stfiwx $frS, $dst", IIC_LdStSTFD,
1830                     [(PPCstfiwx f64:$frS, xoaddr:$dst)]>;
1831
1832def STFSX : XForm_28<31, 663, (outs), (ins f4rc:$frS, memrr:$dst),
1833                     "stfsx $frS, $dst", IIC_LdStSTFD,
1834                     [(store f32:$frS, xaddr:$dst)]>;
1835def STFDX : XForm_28<31, 727, (outs), (ins f8rc:$frS, memrr:$dst),
1836                     "stfdx $frS, $dst", IIC_LdStSTFD,
1837                     [(store f64:$frS, xaddr:$dst)]>;
1838}
1839
1840// Indexed (r+r) Stores with Update (preinc).
1841let PPC970_Unit = 2, mayStore = 1 in {
1842def STBUX : XForm_8<31, 247, (outs ptr_rc_nor0:$ea_res), (ins gprc:$rS, memrr:$dst),
1843                    "stbux $rS, $dst", IIC_LdStStoreUpd, []>,
1844                    RegConstraint<"$dst.ptrreg = $ea_res">, NoEncode<"$ea_res">,
1845                    PPC970_DGroup_Cracked;
1846def STHUX : XForm_8<31, 439, (outs ptr_rc_nor0:$ea_res), (ins gprc:$rS, memrr:$dst),
1847                    "sthux $rS, $dst", IIC_LdStStoreUpd, []>,
1848                    RegConstraint<"$dst.ptrreg = $ea_res">, NoEncode<"$ea_res">,
1849                    PPC970_DGroup_Cracked;
1850def STWUX : XForm_8<31, 183, (outs ptr_rc_nor0:$ea_res), (ins gprc:$rS, memrr:$dst),
1851                    "stwux $rS, $dst", IIC_LdStStoreUpd, []>,
1852                    RegConstraint<"$dst.ptrreg = $ea_res">, NoEncode<"$ea_res">,
1853                    PPC970_DGroup_Cracked;
1854def STFSUX: XForm_8<31, 695, (outs ptr_rc_nor0:$ea_res), (ins f4rc:$rS, memrr:$dst),
1855                    "stfsux $rS, $dst", IIC_LdStSTFDU, []>,
1856                    RegConstraint<"$dst.ptrreg = $ea_res">, NoEncode<"$ea_res">,
1857                    PPC970_DGroup_Cracked;
1858def STFDUX: XForm_8<31, 759, (outs ptr_rc_nor0:$ea_res), (ins f8rc:$rS, memrr:$dst),
1859                    "stfdux $rS, $dst", IIC_LdStSTFDU, []>,
1860                    RegConstraint<"$dst.ptrreg = $ea_res">, NoEncode<"$ea_res">,
1861                    PPC970_DGroup_Cracked;
1862}
1863
1864// Patterns to match the pre-inc stores.  We can't put the patterns on
1865// the instruction definitions directly as ISel wants the address base
1866// and offset to be separate operands, not a single complex operand.
1867def : Pat<(pre_truncsti8 i32:$rS, iPTR:$ptrreg, iPTR:$ptroff),
1868          (STBUX $rS, $ptrreg, $ptroff)>;
1869def : Pat<(pre_truncsti16 i32:$rS, iPTR:$ptrreg, iPTR:$ptroff),
1870          (STHUX $rS, $ptrreg, $ptroff)>;
1871def : Pat<(pre_store i32:$rS, iPTR:$ptrreg, iPTR:$ptroff),
1872          (STWUX $rS, $ptrreg, $ptroff)>;
1873def : Pat<(pre_store f32:$rS, iPTR:$ptrreg, iPTR:$ptroff),
1874          (STFSUX $rS, $ptrreg, $ptroff)>;
1875def : Pat<(pre_store f64:$rS, iPTR:$ptrreg, iPTR:$ptroff),
1876          (STFDUX $rS, $ptrreg, $ptroff)>;
1877
1878// Store Multiple
1879def STMW : DForm_1<47, (outs), (ins gprc:$rS, memri:$dst),
1880                   "stmw $rS, $dst", IIC_LdStLMW, []>;
1881
1882def SYNC : XForm_24_sync<31, 598, (outs), (ins i32imm:$L),
1883                        "sync $L", IIC_LdStSync, []>;
1884
1885let isCodeGenOnly = 1 in {
1886  def MSYNC : XForm_24_sync<31, 598, (outs), (ins),
1887                           "msync", IIC_LdStSync, []> {
1888    let L = 0;
1889  }
1890}
1891
1892def : Pat<(int_ppc_sync),   (SYNC 0)>, Requires<[HasSYNC]>;
1893def : Pat<(int_ppc_lwsync), (SYNC 1)>, Requires<[HasSYNC]>;
1894def : Pat<(int_ppc_sync),   (MSYNC)>, Requires<[HasOnlyMSYNC]>;
1895def : Pat<(int_ppc_lwsync), (MSYNC)>, Requires<[HasOnlyMSYNC]>;
1896
1897//===----------------------------------------------------------------------===//
1898// PPC32 Arithmetic Instructions.
1899//
1900
1901let PPC970_Unit = 1 in {  // FXU Operations.
1902def ADDI   : DForm_2<14, (outs gprc:$rD), (ins gprc_nor0:$rA, s16imm:$imm),
1903                     "addi $rD, $rA, $imm", IIC_IntSimple,
1904                     [(set i32:$rD, (add i32:$rA, imm32SExt16:$imm))]>;
1905let BaseName = "addic" in {
1906let Defs = [CARRY] in
1907def ADDIC  : DForm_2<12, (outs gprc:$rD), (ins gprc:$rA, s16imm:$imm),
1908                     "addic $rD, $rA, $imm", IIC_IntGeneral,
1909                     [(set i32:$rD, (addc i32:$rA, imm32SExt16:$imm))]>,
1910                     RecFormRel, PPC970_DGroup_Cracked;
1911let Defs = [CARRY, CR0] in
1912def ADDICo : DForm_2<13, (outs gprc:$rD), (ins gprc:$rA, s16imm:$imm),
1913                     "addic. $rD, $rA, $imm", IIC_IntGeneral,
1914                     []>, isDOT, RecFormRel;
1915}
1916def ADDIS  : DForm_2<15, (outs gprc:$rD), (ins gprc_nor0:$rA, s17imm:$imm),
1917                     "addis $rD, $rA, $imm", IIC_IntSimple,
1918                     [(set i32:$rD, (add i32:$rA, imm16ShiftedSExt:$imm))]>;
1919let isCodeGenOnly = 1 in
1920def LA     : DForm_2<14, (outs gprc:$rD), (ins gprc_nor0:$rA, s16imm:$sym),
1921                     "la $rD, $sym($rA)", IIC_IntGeneral,
1922                     [(set i32:$rD, (add i32:$rA,
1923                                          (PPClo tglobaladdr:$sym, 0)))]>;
1924def MULLI  : DForm_2< 7, (outs gprc:$rD), (ins gprc:$rA, s16imm:$imm),
1925                     "mulli $rD, $rA, $imm", IIC_IntMulLI,
1926                     [(set i32:$rD, (mul i32:$rA, imm32SExt16:$imm))]>;
1927let Defs = [CARRY] in
1928def SUBFIC : DForm_2< 8, (outs gprc:$rD), (ins gprc:$rA, s16imm:$imm),
1929                     "subfic $rD, $rA, $imm", IIC_IntGeneral,
1930                     [(set i32:$rD, (subc imm32SExt16:$imm, i32:$rA))]>;
1931
1932let isReMaterializable = 1, isAsCheapAsAMove = 1, isMoveImm = 1 in {
1933  def LI  : DForm_2_r0<14, (outs gprc:$rD), (ins s16imm:$imm),
1934                       "li $rD, $imm", IIC_IntSimple,
1935                       [(set i32:$rD, imm32SExt16:$imm)]>;
1936  def LIS : DForm_2_r0<15, (outs gprc:$rD), (ins s17imm:$imm),
1937                       "lis $rD, $imm", IIC_IntSimple,
1938                       [(set i32:$rD, imm16ShiftedSExt:$imm)]>;
1939}
1940}
1941
1942let PPC970_Unit = 1 in {  // FXU Operations.
1943let Defs = [CR0] in {
1944def ANDIo : DForm_4<28, (outs gprc:$dst), (ins gprc:$src1, u16imm:$src2),
1945                    "andi. $dst, $src1, $src2", IIC_IntGeneral,
1946                    [(set i32:$dst, (and i32:$src1, immZExt16:$src2))]>,
1947                    isDOT;
1948def ANDISo : DForm_4<29, (outs gprc:$dst), (ins gprc:$src1, u16imm:$src2),
1949                    "andis. $dst, $src1, $src2", IIC_IntGeneral,
1950                    [(set i32:$dst, (and i32:$src1, imm16ShiftedZExt:$src2))]>,
1951                    isDOT;
1952}
1953def ORI   : DForm_4<24, (outs gprc:$dst), (ins gprc:$src1, u16imm:$src2),
1954                    "ori $dst, $src1, $src2", IIC_IntSimple,
1955                    [(set i32:$dst, (or i32:$src1, immZExt16:$src2))]>;
1956def ORIS  : DForm_4<25, (outs gprc:$dst), (ins gprc:$src1, u16imm:$src2),
1957                    "oris $dst, $src1, $src2", IIC_IntSimple,
1958                    [(set i32:$dst, (or i32:$src1, imm16ShiftedZExt:$src2))]>;
1959def XORI  : DForm_4<26, (outs gprc:$dst), (ins gprc:$src1, u16imm:$src2),
1960                    "xori $dst, $src1, $src2", IIC_IntSimple,
1961                    [(set i32:$dst, (xor i32:$src1, immZExt16:$src2))]>;
1962def XORIS : DForm_4<27, (outs gprc:$dst), (ins gprc:$src1, u16imm:$src2),
1963                    "xoris $dst, $src1, $src2", IIC_IntSimple,
1964                    [(set i32:$dst, (xor i32:$src1, imm16ShiftedZExt:$src2))]>;
1965
1966def NOP   : DForm_4_zero<24, (outs), (ins), "nop", IIC_IntSimple,
1967                         []>;
1968let isCodeGenOnly = 1 in {
1969// The POWER6 and POWER7 have special group-terminating nops.
1970def NOP_GT_PWR6 : DForm_4_fixedreg_zero<24, 1, (outs), (ins),
1971                                        "ori 1, 1, 0", IIC_IntSimple, []>;
1972def NOP_GT_PWR7 : DForm_4_fixedreg_zero<24, 2, (outs), (ins),
1973                                        "ori 2, 2, 0", IIC_IntSimple, []>;
1974}
1975
1976let isCompare = 1, hasSideEffects = 0 in {
1977  def CMPWI : DForm_5_ext<11, (outs crrc:$crD), (ins gprc:$rA, s16imm:$imm),
1978                          "cmpwi $crD, $rA, $imm", IIC_IntCompare>;
1979  def CMPLWI : DForm_6_ext<10, (outs crrc:$dst), (ins gprc:$src1, u16imm:$src2),
1980                           "cmplwi $dst, $src1, $src2", IIC_IntCompare>;
1981}
1982}
1983
1984let PPC970_Unit = 1, hasSideEffects = 0 in {  // FXU Operations.
1985let isCommutable = 1 in {
1986defm NAND : XForm_6r<31, 476, (outs gprc:$rA), (ins gprc:$rS, gprc:$rB),
1987                     "nand", "$rA, $rS, $rB", IIC_IntSimple,
1988                     [(set i32:$rA, (not (and i32:$rS, i32:$rB)))]>;
1989defm AND  : XForm_6r<31,  28, (outs gprc:$rA), (ins gprc:$rS, gprc:$rB),
1990                     "and", "$rA, $rS, $rB", IIC_IntSimple,
1991                     [(set i32:$rA, (and i32:$rS, i32:$rB))]>;
1992} // isCommutable
1993defm ANDC : XForm_6r<31,  60, (outs gprc:$rA), (ins gprc:$rS, gprc:$rB),
1994                     "andc", "$rA, $rS, $rB", IIC_IntSimple,
1995                     [(set i32:$rA, (and i32:$rS, (not i32:$rB)))]>;
1996let isCommutable = 1 in {
1997defm OR   : XForm_6r<31, 444, (outs gprc:$rA), (ins gprc:$rS, gprc:$rB),
1998                     "or", "$rA, $rS, $rB", IIC_IntSimple,
1999                     [(set i32:$rA, (or i32:$rS, i32:$rB))]>;
2000defm NOR  : XForm_6r<31, 124, (outs gprc:$rA), (ins gprc:$rS, gprc:$rB),
2001                     "nor", "$rA, $rS, $rB", IIC_IntSimple,
2002                     [(set i32:$rA, (not (or i32:$rS, i32:$rB)))]>;
2003} // isCommutable
2004defm ORC  : XForm_6r<31, 412, (outs gprc:$rA), (ins gprc:$rS, gprc:$rB),
2005                     "orc", "$rA, $rS, $rB", IIC_IntSimple,
2006                     [(set i32:$rA, (or i32:$rS, (not i32:$rB)))]>;
2007let isCommutable = 1 in {
2008defm EQV  : XForm_6r<31, 284, (outs gprc:$rA), (ins gprc:$rS, gprc:$rB),
2009                     "eqv", "$rA, $rS, $rB", IIC_IntSimple,
2010                     [(set i32:$rA, (not (xor i32:$rS, i32:$rB)))]>;
2011defm XOR  : XForm_6r<31, 316, (outs gprc:$rA), (ins gprc:$rS, gprc:$rB),
2012                     "xor", "$rA, $rS, $rB", IIC_IntSimple,
2013                     [(set i32:$rA, (xor i32:$rS, i32:$rB))]>;
2014} // isCommutable
2015defm SLW  : XForm_6r<31,  24, (outs gprc:$rA), (ins gprc:$rS, gprc:$rB),
2016                     "slw", "$rA, $rS, $rB", IIC_IntGeneral,
2017                     [(set i32:$rA, (PPCshl i32:$rS, i32:$rB))]>;
2018defm SRW  : XForm_6r<31, 536, (outs gprc:$rA), (ins gprc:$rS, gprc:$rB),
2019                     "srw", "$rA, $rS, $rB", IIC_IntGeneral,
2020                     [(set i32:$rA, (PPCsrl i32:$rS, i32:$rB))]>;
2021defm SRAW : XForm_6rc<31, 792, (outs gprc:$rA), (ins gprc:$rS, gprc:$rB),
2022                      "sraw", "$rA, $rS, $rB", IIC_IntShift,
2023                      [(set i32:$rA, (PPCsra i32:$rS, i32:$rB))]>;
2024}
2025
2026let PPC970_Unit = 1 in {  // FXU Operations.
2027let hasSideEffects = 0 in {
2028defm SRAWI : XForm_10rc<31, 824, (outs gprc:$rA), (ins gprc:$rS, u5imm:$SH),
2029                        "srawi", "$rA, $rS, $SH", IIC_IntShift,
2030                        [(set i32:$rA, (sra i32:$rS, (i32 imm:$SH)))]>;
2031defm CNTLZW : XForm_11r<31,  26, (outs gprc:$rA), (ins gprc:$rS),
2032                        "cntlzw", "$rA, $rS", IIC_IntGeneral,
2033                        [(set i32:$rA, (ctlz i32:$rS))]>;
2034defm EXTSB  : XForm_11r<31, 954, (outs gprc:$rA), (ins gprc:$rS),
2035                        "extsb", "$rA, $rS", IIC_IntSimple,
2036                        [(set i32:$rA, (sext_inreg i32:$rS, i8))]>;
2037defm EXTSH  : XForm_11r<31, 922, (outs gprc:$rA), (ins gprc:$rS),
2038                        "extsh", "$rA, $rS", IIC_IntSimple,
2039                        [(set i32:$rA, (sext_inreg i32:$rS, i16))]>;
2040
2041let isCommutable = 1 in
2042def CMPB : XForm_6<31, 508, (outs gprc:$rA), (ins gprc:$rS, gprc:$rB),
2043                   "cmpb $rA, $rS, $rB", IIC_IntGeneral,
2044                   [(set i32:$rA, (PPCcmpb i32:$rS, i32:$rB))]>;
2045}
2046let isCompare = 1, hasSideEffects = 0 in {
2047  def CMPW   : XForm_16_ext<31, 0, (outs crrc:$crD), (ins gprc:$rA, gprc:$rB),
2048                            "cmpw $crD, $rA, $rB", IIC_IntCompare>;
2049  def CMPLW  : XForm_16_ext<31, 32, (outs crrc:$crD), (ins gprc:$rA, gprc:$rB),
2050                            "cmplw $crD, $rA, $rB", IIC_IntCompare>;
2051}
2052}
2053let PPC970_Unit = 3 in {  // FPU Operations.
2054//def FCMPO  : XForm_17<63, 32, (outs CRRC:$crD), (ins FPRC:$fA, FPRC:$fB),
2055//                      "fcmpo $crD, $fA, $fB", IIC_FPCompare>;
2056let isCompare = 1, hasSideEffects = 0 in {
2057  def FCMPUS : XForm_17<63, 0, (outs crrc:$crD), (ins f4rc:$fA, f4rc:$fB),
2058                        "fcmpu $crD, $fA, $fB", IIC_FPCompare>;
2059  let Interpretation64Bit = 1, isCodeGenOnly = 1 in
2060  def FCMPUD : XForm_17<63, 0, (outs crrc:$crD), (ins f8rc:$fA, f8rc:$fB),
2061                        "fcmpu $crD, $fA, $fB", IIC_FPCompare>;
2062}
2063
2064let Uses = [RM] in {
2065  let hasSideEffects = 0 in {
2066  defm FCTIW  : XForm_26r<63, 14, (outs f8rc:$frD), (ins f8rc:$frB),
2067                          "fctiw", "$frD, $frB", IIC_FPGeneral,
2068                          []>;
2069  defm FCTIWZ : XForm_26r<63, 15, (outs f8rc:$frD), (ins f8rc:$frB),
2070                          "fctiwz", "$frD, $frB", IIC_FPGeneral,
2071                          [(set f64:$frD, (PPCfctiwz f64:$frB))]>;
2072
2073  defm FRSP   : XForm_26r<63, 12, (outs f4rc:$frD), (ins f8rc:$frB),
2074                          "frsp", "$frD, $frB", IIC_FPGeneral,
2075                          [(set f32:$frD, (fround f64:$frB))]>;
2076
2077  let Interpretation64Bit = 1, isCodeGenOnly = 1 in
2078  defm FRIND  : XForm_26r<63, 392, (outs f8rc:$frD), (ins f8rc:$frB),
2079                          "frin", "$frD, $frB", IIC_FPGeneral,
2080                          [(set f64:$frD, (frnd f64:$frB))]>;
2081  defm FRINS  : XForm_26r<63, 392, (outs f4rc:$frD), (ins f4rc:$frB),
2082                          "frin", "$frD, $frB", IIC_FPGeneral,
2083                          [(set f32:$frD, (frnd f32:$frB))]>;
2084  }
2085
2086  let hasSideEffects = 0 in {
2087  let Interpretation64Bit = 1, isCodeGenOnly = 1 in
2088  defm FRIPD  : XForm_26r<63, 456, (outs f8rc:$frD), (ins f8rc:$frB),
2089                          "frip", "$frD, $frB", IIC_FPGeneral,
2090                          [(set f64:$frD, (fceil f64:$frB))]>;
2091  defm FRIPS  : XForm_26r<63, 456, (outs f4rc:$frD), (ins f4rc:$frB),
2092                          "frip", "$frD, $frB", IIC_FPGeneral,
2093                          [(set f32:$frD, (fceil f32:$frB))]>;
2094  let Interpretation64Bit = 1, isCodeGenOnly = 1 in
2095  defm FRIZD  : XForm_26r<63, 424, (outs f8rc:$frD), (ins f8rc:$frB),
2096                          "friz", "$frD, $frB", IIC_FPGeneral,
2097                          [(set f64:$frD, (ftrunc f64:$frB))]>;
2098  defm FRIZS  : XForm_26r<63, 424, (outs f4rc:$frD), (ins f4rc:$frB),
2099                          "friz", "$frD, $frB", IIC_FPGeneral,
2100                          [(set f32:$frD, (ftrunc f32:$frB))]>;
2101  let Interpretation64Bit = 1, isCodeGenOnly = 1 in
2102  defm FRIMD  : XForm_26r<63, 488, (outs f8rc:$frD), (ins f8rc:$frB),
2103                          "frim", "$frD, $frB", IIC_FPGeneral,
2104                          [(set f64:$frD, (ffloor f64:$frB))]>;
2105  defm FRIMS  : XForm_26r<63, 488, (outs f4rc:$frD), (ins f4rc:$frB),
2106                          "frim", "$frD, $frB", IIC_FPGeneral,
2107                          [(set f32:$frD, (ffloor f32:$frB))]>;
2108
2109  defm FSQRT  : XForm_26r<63, 22, (outs f8rc:$frD), (ins f8rc:$frB),
2110                          "fsqrt", "$frD, $frB", IIC_FPSqrtD,
2111                          [(set f64:$frD, (fsqrt f64:$frB))]>;
2112  defm FSQRTS : XForm_26r<59, 22, (outs f4rc:$frD), (ins f4rc:$frB),
2113                          "fsqrts", "$frD, $frB", IIC_FPSqrtS,
2114                          [(set f32:$frD, (fsqrt f32:$frB))]>;
2115  }
2116  }
2117}
2118
2119/// Note that FMR is defined as pseudo-ops on the PPC970 because they are
2120/// often coalesced away and we don't want the dispatch group builder to think
2121/// that they will fill slots (which could cause the load of a LSU reject to
2122/// sneak into a d-group with a store).
2123let hasSideEffects = 0 in
2124defm FMR   : XForm_26r<63, 72, (outs f4rc:$frD), (ins f4rc:$frB),
2125                       "fmr", "$frD, $frB", IIC_FPGeneral,
2126                       []>,  // (set f32:$frD, f32:$frB)
2127                       PPC970_Unit_Pseudo;
2128
2129let PPC970_Unit = 3, hasSideEffects = 0 in {  // FPU Operations.
2130// These are artificially split into two different forms, for 4/8 byte FP.
2131defm FABSS  : XForm_26r<63, 264, (outs f4rc:$frD), (ins f4rc:$frB),
2132                        "fabs", "$frD, $frB", IIC_FPGeneral,
2133                        [(set f32:$frD, (fabs f32:$frB))]>;
2134let Interpretation64Bit = 1, isCodeGenOnly = 1 in
2135defm FABSD  : XForm_26r<63, 264, (outs f8rc:$frD), (ins f8rc:$frB),
2136                        "fabs", "$frD, $frB", IIC_FPGeneral,
2137                        [(set f64:$frD, (fabs f64:$frB))]>;
2138defm FNABSS : XForm_26r<63, 136, (outs f4rc:$frD), (ins f4rc:$frB),
2139                        "fnabs", "$frD, $frB", IIC_FPGeneral,
2140                        [(set f32:$frD, (fneg (fabs f32:$frB)))]>;
2141let Interpretation64Bit = 1, isCodeGenOnly = 1 in
2142defm FNABSD : XForm_26r<63, 136, (outs f8rc:$frD), (ins f8rc:$frB),
2143                        "fnabs", "$frD, $frB", IIC_FPGeneral,
2144                        [(set f64:$frD, (fneg (fabs f64:$frB)))]>;
2145defm FNEGS  : XForm_26r<63, 40, (outs f4rc:$frD), (ins f4rc:$frB),
2146                        "fneg", "$frD, $frB", IIC_FPGeneral,
2147                        [(set f32:$frD, (fneg f32:$frB))]>;
2148let Interpretation64Bit = 1, isCodeGenOnly = 1 in
2149defm FNEGD  : XForm_26r<63, 40, (outs f8rc:$frD), (ins f8rc:$frB),
2150                        "fneg", "$frD, $frB", IIC_FPGeneral,
2151                        [(set f64:$frD, (fneg f64:$frB))]>;
2152
2153defm FCPSGNS : XForm_28r<63, 8, (outs f4rc:$frD), (ins f4rc:$frA, f4rc:$frB),
2154                        "fcpsgn", "$frD, $frA, $frB", IIC_FPGeneral,
2155                        [(set f32:$frD, (fcopysign f32:$frB, f32:$frA))]>;
2156let Interpretation64Bit = 1, isCodeGenOnly = 1 in
2157defm FCPSGND : XForm_28r<63, 8, (outs f8rc:$frD), (ins f8rc:$frA, f8rc:$frB),
2158                        "fcpsgn", "$frD, $frA, $frB", IIC_FPGeneral,
2159                        [(set f64:$frD, (fcopysign f64:$frB, f64:$frA))]>;
2160
2161// Reciprocal estimates.
2162defm FRE      : XForm_26r<63, 24, (outs f8rc:$frD), (ins f8rc:$frB),
2163                          "fre", "$frD, $frB", IIC_FPGeneral,
2164                          [(set f64:$frD, (PPCfre f64:$frB))]>;
2165defm FRES     : XForm_26r<59, 24, (outs f4rc:$frD), (ins f4rc:$frB),
2166                          "fres", "$frD, $frB", IIC_FPGeneral,
2167                          [(set f32:$frD, (PPCfre f32:$frB))]>;
2168defm FRSQRTE  : XForm_26r<63, 26, (outs f8rc:$frD), (ins f8rc:$frB),
2169                          "frsqrte", "$frD, $frB", IIC_FPGeneral,
2170                          [(set f64:$frD, (PPCfrsqrte f64:$frB))]>;
2171defm FRSQRTES : XForm_26r<59, 26, (outs f4rc:$frD), (ins f4rc:$frB),
2172                          "frsqrtes", "$frD, $frB", IIC_FPGeneral,
2173                          [(set f32:$frD, (PPCfrsqrte f32:$frB))]>;
2174}
2175
2176// XL-Form instructions.  condition register logical ops.
2177//
2178let hasSideEffects = 0 in
2179def MCRF   : XLForm_3<19, 0, (outs crrc:$BF), (ins crrc:$BFA),
2180                      "mcrf $BF, $BFA", IIC_BrMCR>,
2181             PPC970_DGroup_First, PPC970_Unit_CRU;
2182
2183// FIXME: According to the ISA (section 2.5.1 of version 2.06), the
2184// condition-register logical instructions have preferred forms. Specifically,
2185// it is preferred that the bit specified by the BT field be in the same
2186// condition register as that specified by the bit BB. We might want to account
2187// for this via hinting the register allocator and anti-dep breakers, or we
2188// could constrain the register class to force this constraint and then loosen
2189// it during register allocation via convertToThreeAddress or some similar
2190// mechanism.
2191
2192let isCommutable = 1 in {
2193def CRAND  : XLForm_1<19, 257, (outs crbitrc:$CRD),
2194                               (ins crbitrc:$CRA, crbitrc:$CRB),
2195                      "crand $CRD, $CRA, $CRB", IIC_BrCR,
2196                      [(set i1:$CRD, (and i1:$CRA, i1:$CRB))]>;
2197
2198def CRNAND : XLForm_1<19, 225, (outs crbitrc:$CRD),
2199                               (ins crbitrc:$CRA, crbitrc:$CRB),
2200                      "crnand $CRD, $CRA, $CRB", IIC_BrCR,
2201                      [(set i1:$CRD, (not (and i1:$CRA, i1:$CRB)))]>;
2202
2203def CROR   : XLForm_1<19, 449, (outs crbitrc:$CRD),
2204                               (ins crbitrc:$CRA, crbitrc:$CRB),
2205                      "cror $CRD, $CRA, $CRB", IIC_BrCR,
2206                      [(set i1:$CRD, (or i1:$CRA, i1:$CRB))]>;
2207
2208def CRXOR  : XLForm_1<19, 193, (outs crbitrc:$CRD),
2209                               (ins crbitrc:$CRA, crbitrc:$CRB),
2210                      "crxor $CRD, $CRA, $CRB", IIC_BrCR,
2211                      [(set i1:$CRD, (xor i1:$CRA, i1:$CRB))]>;
2212
2213def CRNOR  : XLForm_1<19, 33, (outs crbitrc:$CRD),
2214                              (ins crbitrc:$CRA, crbitrc:$CRB),
2215                      "crnor $CRD, $CRA, $CRB", IIC_BrCR,
2216                      [(set i1:$CRD, (not (or i1:$CRA, i1:$CRB)))]>;
2217
2218def CREQV  : XLForm_1<19, 289, (outs crbitrc:$CRD),
2219                               (ins crbitrc:$CRA, crbitrc:$CRB),
2220                      "creqv $CRD, $CRA, $CRB", IIC_BrCR,
2221                      [(set i1:$CRD, (not (xor i1:$CRA, i1:$CRB)))]>;
2222} // isCommutable
2223
2224def CRANDC : XLForm_1<19, 129, (outs crbitrc:$CRD),
2225                               (ins crbitrc:$CRA, crbitrc:$CRB),
2226                      "crandc $CRD, $CRA, $CRB", IIC_BrCR,
2227                      [(set i1:$CRD, (and i1:$CRA, (not i1:$CRB)))]>;
2228
2229def CRORC  : XLForm_1<19, 417, (outs crbitrc:$CRD),
2230                               (ins crbitrc:$CRA, crbitrc:$CRB),
2231                      "crorc $CRD, $CRA, $CRB", IIC_BrCR,
2232                      [(set i1:$CRD, (or i1:$CRA, (not i1:$CRB)))]>;
2233
2234let isCodeGenOnly = 1 in {
2235def CRSET  : XLForm_1_ext<19, 289, (outs crbitrc:$dst), (ins),
2236              "creqv $dst, $dst, $dst", IIC_BrCR,
2237              [(set i1:$dst, 1)]>;
2238
2239def CRUNSET: XLForm_1_ext<19, 193, (outs crbitrc:$dst), (ins),
2240              "crxor $dst, $dst, $dst", IIC_BrCR,
2241              [(set i1:$dst, 0)]>;
2242
2243let Defs = [CR1EQ], CRD = 6 in {
2244def CR6SET  : XLForm_1_ext<19, 289, (outs), (ins),
2245              "creqv 6, 6, 6", IIC_BrCR,
2246              [(PPCcr6set)]>;
2247
2248def CR6UNSET: XLForm_1_ext<19, 193, (outs), (ins),
2249              "crxor 6, 6, 6", IIC_BrCR,
2250              [(PPCcr6unset)]>;
2251}
2252}
2253
2254// XFX-Form instructions.  Instructions that deal with SPRs.
2255//
2256
2257def MFSPR : XFXForm_1<31, 339, (outs gprc:$RT), (ins i32imm:$SPR),
2258                      "mfspr $RT, $SPR", IIC_SprMFSPR>;
2259def MTSPR : XFXForm_1<31, 467, (outs), (ins i32imm:$SPR, gprc:$RT),
2260                      "mtspr $SPR, $RT", IIC_SprMTSPR>;
2261
2262def MFTB : XFXForm_1<31, 371, (outs gprc:$RT), (ins i32imm:$SPR),
2263                     "mftb $RT, $SPR", IIC_SprMFTB>;
2264
2265// A pseudo-instruction used to implement the read of the 64-bit cycle counter
2266// on a 32-bit target.
2267let hasSideEffects = 1, usesCustomInserter = 1 in
2268def ReadTB : Pseudo<(outs gprc:$lo, gprc:$hi), (ins),
2269                    "#ReadTB", []>;
2270
2271let Uses = [CTR] in {
2272def MFCTR : XFXForm_1_ext<31, 339, 9, (outs gprc:$rT), (ins),
2273                          "mfctr $rT", IIC_SprMFSPR>,
2274            PPC970_DGroup_First, PPC970_Unit_FXU;
2275}
2276let Defs = [CTR], Pattern = [(PPCmtctr i32:$rS)] in {
2277def MTCTR : XFXForm_7_ext<31, 467, 9, (outs), (ins gprc:$rS),
2278                          "mtctr $rS", IIC_SprMTSPR>,
2279            PPC970_DGroup_First, PPC970_Unit_FXU;
2280}
2281let hasSideEffects = 1, isCodeGenOnly = 1, Defs = [CTR] in {
2282let Pattern = [(int_ppc_mtctr i32:$rS)] in
2283def MTCTRloop : XFXForm_7_ext<31, 467, 9, (outs), (ins gprc:$rS),
2284                              "mtctr $rS", IIC_SprMTSPR>,
2285                PPC970_DGroup_First, PPC970_Unit_FXU;
2286}
2287
2288let Defs = [LR] in {
2289def MTLR  : XFXForm_7_ext<31, 467, 8, (outs), (ins gprc:$rS),
2290                          "mtlr $rS", IIC_SprMTSPR>,
2291            PPC970_DGroup_First, PPC970_Unit_FXU;
2292}
2293let Uses = [LR] in {
2294def MFLR  : XFXForm_1_ext<31, 339, 8, (outs gprc:$rT), (ins),
2295                          "mflr $rT", IIC_SprMFSPR>,
2296            PPC970_DGroup_First, PPC970_Unit_FXU;
2297}
2298
2299let isCodeGenOnly = 1 in {
2300  // Move to/from VRSAVE: despite being a SPR, the VRSAVE register is renamed
2301  // like a GPR on the PPC970.  As such, copies in and out have the same
2302  // performance characteristics as an OR instruction.
2303  def MTVRSAVE : XFXForm_7_ext<31, 467, 256, (outs), (ins gprc:$rS),
2304                               "mtspr 256, $rS", IIC_IntGeneral>,
2305                 PPC970_DGroup_Single, PPC970_Unit_FXU;
2306  def MFVRSAVE : XFXForm_1_ext<31, 339, 256, (outs gprc:$rT), (ins),
2307                               "mfspr $rT, 256", IIC_IntGeneral>,
2308                 PPC970_DGroup_First, PPC970_Unit_FXU;
2309
2310  def MTVRSAVEv : XFXForm_7_ext<31, 467, 256,
2311                                (outs VRSAVERC:$reg), (ins gprc:$rS),
2312                                "mtspr 256, $rS", IIC_IntGeneral>,
2313                  PPC970_DGroup_Single, PPC970_Unit_FXU;
2314  def MFVRSAVEv : XFXForm_1_ext<31, 339, 256, (outs gprc:$rT),
2315                                (ins VRSAVERC:$reg),
2316                                "mfspr $rT, 256", IIC_IntGeneral>,
2317                  PPC970_DGroup_First, PPC970_Unit_FXU;
2318}
2319
2320// SPILL_VRSAVE - Indicate that we're dumping the VRSAVE register,
2321// so we'll need to scavenge a register for it.
2322let mayStore = 1 in
2323def SPILL_VRSAVE : Pseudo<(outs), (ins VRSAVERC:$vrsave, memri:$F),
2324                     "#SPILL_VRSAVE", []>;
2325
2326// RESTORE_VRSAVE - Indicate that we're restoring the VRSAVE register (previously
2327// spilled), so we'll need to scavenge a register for it.
2328let mayLoad = 1 in
2329def RESTORE_VRSAVE : Pseudo<(outs VRSAVERC:$vrsave), (ins memri:$F),
2330                     "#RESTORE_VRSAVE", []>;
2331
2332let hasSideEffects = 0 in {
2333// mtocrf's input needs to be prepared by shifting by an amount dependent
2334// on the cr register selected. Thus, post-ra anti-dep breaking must not
2335// later change that register assignment.
2336let hasExtraDefRegAllocReq = 1 in {
2337def MTOCRF: XFXForm_5a<31, 144, (outs crbitm:$FXM), (ins gprc:$ST),
2338                       "mtocrf $FXM, $ST", IIC_BrMCRX>,
2339            PPC970_DGroup_First, PPC970_Unit_CRU;
2340
2341// Similarly to mtocrf, the mask for mtcrf must be prepared in a way that
2342// is dependent on the cr fields being set.
2343def MTCRF : XFXForm_5<31, 144, (outs), (ins i32imm:$FXM, gprc:$rS),
2344                      "mtcrf $FXM, $rS", IIC_BrMCRX>,
2345            PPC970_MicroCode, PPC970_Unit_CRU;
2346} // hasExtraDefRegAllocReq = 1
2347
2348// mfocrf's input needs to be prepared by shifting by an amount dependent
2349// on the cr register selected. Thus, post-ra anti-dep breaking must not
2350// later change that register assignment.
2351let hasExtraSrcRegAllocReq = 1 in {
2352def MFOCRF: XFXForm_5a<31, 19, (outs gprc:$rT), (ins crbitm:$FXM),
2353                       "mfocrf $rT, $FXM", IIC_SprMFCRF>,
2354            PPC970_DGroup_First, PPC970_Unit_CRU;
2355
2356// Similarly to mfocrf, the mask for mfcrf must be prepared in a way that
2357// is dependent on the cr fields being copied.
2358def MFCR : XFXForm_3<31, 19, (outs gprc:$rT), (ins),
2359                     "mfcr $rT", IIC_SprMFCR>,
2360                     PPC970_MicroCode, PPC970_Unit_CRU;
2361} // hasExtraSrcRegAllocReq = 1
2362} // hasSideEffects = 0
2363
2364// Pseudo instruction to perform FADD in round-to-zero mode.
2365let usesCustomInserter = 1, Uses = [RM] in {
2366  def FADDrtz: Pseudo<(outs f8rc:$FRT), (ins f8rc:$FRA, f8rc:$FRB), "",
2367                      [(set f64:$FRT, (PPCfaddrtz f64:$FRA, f64:$FRB))]>;
2368}
2369
2370// The above pseudo gets expanded to make use of the following instructions
2371// to manipulate FPSCR.  Note that FPSCR is not modeled at the DAG level.
2372let Uses = [RM], Defs = [RM] in {
2373  def MTFSB0 : XForm_43<63, 70, (outs), (ins u5imm:$FM),
2374                        "mtfsb0 $FM", IIC_IntMTFSB0, []>,
2375               PPC970_DGroup_Single, PPC970_Unit_FPU;
2376  def MTFSB1 : XForm_43<63, 38, (outs), (ins u5imm:$FM),
2377                        "mtfsb1 $FM", IIC_IntMTFSB0, []>,
2378               PPC970_DGroup_Single, PPC970_Unit_FPU;
2379  let isCodeGenOnly = 1 in
2380  def MTFSFb  : XFLForm<63, 711, (outs), (ins i32imm:$FM, f8rc:$rT),
2381                        "mtfsf $FM, $rT", IIC_IntMTFSB0, []>,
2382                PPC970_DGroup_Single, PPC970_Unit_FPU;
2383}
2384let Uses = [RM] in {
2385  def MFFS   : XForm_42<63, 583, (outs f8rc:$rT), (ins),
2386                         "mffs $rT", IIC_IntMFFS,
2387                         [(set f64:$rT, (PPCmffs))]>,
2388               PPC970_DGroup_Single, PPC970_Unit_FPU;
2389
2390  let Defs = [CR1] in
2391  def MFFSo : XForm_42<63, 583, (outs f8rc:$rT), (ins),
2392                      "mffs. $rT", IIC_IntMFFS, []>, isDOT;
2393}
2394
2395
2396let PPC970_Unit = 1, hasSideEffects = 0 in {  // FXU Operations.
2397// XO-Form instructions.  Arithmetic instructions that can set overflow bit
2398let isCommutable = 1 in
2399defm ADD4  : XOForm_1r<31, 266, 0, (outs gprc:$rT), (ins gprc:$rA, gprc:$rB),
2400                       "add", "$rT, $rA, $rB", IIC_IntSimple,
2401                       [(set i32:$rT, (add i32:$rA, i32:$rB))]>;
2402let isCodeGenOnly = 1 in
2403def ADD4TLS  : XOForm_1<31, 266, 0, (outs gprc:$rT), (ins gprc:$rA, tlsreg32:$rB),
2404                       "add $rT, $rA, $rB", IIC_IntSimple,
2405                       [(set i32:$rT, (add i32:$rA, tglobaltlsaddr:$rB))]>;
2406let isCommutable = 1 in
2407defm ADDC  : XOForm_1rc<31, 10, 0, (outs gprc:$rT), (ins gprc:$rA, gprc:$rB),
2408                        "addc", "$rT, $rA, $rB", IIC_IntGeneral,
2409                        [(set i32:$rT, (addc i32:$rA, i32:$rB))]>,
2410                        PPC970_DGroup_Cracked;
2411
2412defm DIVW  : XOForm_1rcr<31, 491, 0, (outs gprc:$rT), (ins gprc:$rA, gprc:$rB),
2413                          "divw", "$rT, $rA, $rB", IIC_IntDivW,
2414                          [(set i32:$rT, (sdiv i32:$rA, i32:$rB))]>;
2415defm DIVWU : XOForm_1rcr<31, 459, 0, (outs gprc:$rT), (ins gprc:$rA, gprc:$rB),
2416                          "divwu", "$rT, $rA, $rB", IIC_IntDivW,
2417                          [(set i32:$rT, (udiv i32:$rA, i32:$rB))]>;
2418def DIVWE : XOForm_1<31, 427, 0, (outs gprc:$rT), (ins gprc:$rA, gprc:$rB),
2419                     "divwe $rT, $rA, $rB", IIC_IntDivW,
2420                     [(set i32:$rT, (int_ppc_divwe gprc:$rA, gprc:$rB))]>,
2421                     Requires<[HasExtDiv]>;
2422let Defs = [CR0] in
2423def DIVWEo : XOForm_1<31, 427, 0, (outs gprc:$rT), (ins gprc:$rA, gprc:$rB),
2424                      "divwe. $rT, $rA, $rB", IIC_IntDivW,
2425                      []>, isDOT, PPC970_DGroup_Cracked, PPC970_DGroup_First,
2426                      Requires<[HasExtDiv]>;
2427def DIVWEU : XOForm_1<31, 395, 0, (outs gprc:$rT), (ins gprc:$rA, gprc:$rB),
2428                      "divweu $rT, $rA, $rB", IIC_IntDivW,
2429                      [(set i32:$rT, (int_ppc_divweu gprc:$rA, gprc:$rB))]>,
2430                      Requires<[HasExtDiv]>;
2431let Defs = [CR0] in
2432def DIVWEUo : XOForm_1<31, 395, 0, (outs gprc:$rT), (ins gprc:$rA, gprc:$rB),
2433                       "divweu. $rT, $rA, $rB", IIC_IntDivW,
2434                       []>, isDOT, PPC970_DGroup_Cracked, PPC970_DGroup_First,
2435                       Requires<[HasExtDiv]>;
2436let isCommutable = 1 in {
2437defm MULHW : XOForm_1r<31, 75, 0, (outs gprc:$rT), (ins gprc:$rA, gprc:$rB),
2438                       "mulhw", "$rT, $rA, $rB", IIC_IntMulHW,
2439                       [(set i32:$rT, (mulhs i32:$rA, i32:$rB))]>;
2440defm MULHWU : XOForm_1r<31, 11, 0, (outs gprc:$rT), (ins gprc:$rA, gprc:$rB),
2441                       "mulhwu", "$rT, $rA, $rB", IIC_IntMulHWU,
2442                       [(set i32:$rT, (mulhu i32:$rA, i32:$rB))]>;
2443defm MULLW : XOForm_1r<31, 235, 0, (outs gprc:$rT), (ins gprc:$rA, gprc:$rB),
2444                       "mullw", "$rT, $rA, $rB", IIC_IntMulHW,
2445                       [(set i32:$rT, (mul i32:$rA, i32:$rB))]>;
2446} // isCommutable
2447defm SUBF  : XOForm_1r<31, 40, 0, (outs gprc:$rT), (ins gprc:$rA, gprc:$rB),
2448                       "subf", "$rT, $rA, $rB", IIC_IntGeneral,
2449                       [(set i32:$rT, (sub i32:$rB, i32:$rA))]>;
2450defm SUBFC : XOForm_1rc<31, 8, 0, (outs gprc:$rT), (ins gprc:$rA, gprc:$rB),
2451                        "subfc", "$rT, $rA, $rB", IIC_IntGeneral,
2452                        [(set i32:$rT, (subc i32:$rB, i32:$rA))]>,
2453                        PPC970_DGroup_Cracked;
2454defm NEG    : XOForm_3r<31, 104, 0, (outs gprc:$rT), (ins gprc:$rA),
2455                        "neg", "$rT, $rA", IIC_IntSimple,
2456                        [(set i32:$rT, (ineg i32:$rA))]>;
2457let Uses = [CARRY] in {
2458let isCommutable = 1 in
2459defm ADDE  : XOForm_1rc<31, 138, 0, (outs gprc:$rT), (ins gprc:$rA, gprc:$rB),
2460                        "adde", "$rT, $rA, $rB", IIC_IntGeneral,
2461                        [(set i32:$rT, (adde i32:$rA, i32:$rB))]>;
2462defm ADDME  : XOForm_3rc<31, 234, 0, (outs gprc:$rT), (ins gprc:$rA),
2463                         "addme", "$rT, $rA", IIC_IntGeneral,
2464                         [(set i32:$rT, (adde i32:$rA, -1))]>;
2465defm ADDZE  : XOForm_3rc<31, 202, 0, (outs gprc:$rT), (ins gprc:$rA),
2466                         "addze", "$rT, $rA", IIC_IntGeneral,
2467                         [(set i32:$rT, (adde i32:$rA, 0))]>;
2468defm SUBFE : XOForm_1rc<31, 136, 0, (outs gprc:$rT), (ins gprc:$rA, gprc:$rB),
2469                        "subfe", "$rT, $rA, $rB", IIC_IntGeneral,
2470                        [(set i32:$rT, (sube i32:$rB, i32:$rA))]>;
2471defm SUBFME : XOForm_3rc<31, 232, 0, (outs gprc:$rT), (ins gprc:$rA),
2472                         "subfme", "$rT, $rA", IIC_IntGeneral,
2473                         [(set i32:$rT, (sube -1, i32:$rA))]>;
2474defm SUBFZE : XOForm_3rc<31, 200, 0, (outs gprc:$rT), (ins gprc:$rA),
2475                         "subfze", "$rT, $rA", IIC_IntGeneral,
2476                         [(set i32:$rT, (sube 0, i32:$rA))]>;
2477}
2478}
2479
2480// A-Form instructions.  Most of the instructions executed in the FPU are of
2481// this type.
2482//
2483let PPC970_Unit = 3, hasSideEffects = 0 in {  // FPU Operations.
2484let Uses = [RM] in {
2485let isCommutable = 1 in {
2486  defm FMADD : AForm_1r<63, 29,
2487                      (outs f8rc:$FRT), (ins f8rc:$FRA, f8rc:$FRC, f8rc:$FRB),
2488                      "fmadd", "$FRT, $FRA, $FRC, $FRB", IIC_FPFused,
2489                      [(set f64:$FRT, (fma f64:$FRA, f64:$FRC, f64:$FRB))]>;
2490  defm FMADDS : AForm_1r<59, 29,
2491                      (outs f4rc:$FRT), (ins f4rc:$FRA, f4rc:$FRC, f4rc:$FRB),
2492                      "fmadds", "$FRT, $FRA, $FRC, $FRB", IIC_FPGeneral,
2493                      [(set f32:$FRT, (fma f32:$FRA, f32:$FRC, f32:$FRB))]>;
2494  defm FMSUB : AForm_1r<63, 28,
2495                      (outs f8rc:$FRT), (ins f8rc:$FRA, f8rc:$FRC, f8rc:$FRB),
2496                      "fmsub", "$FRT, $FRA, $FRC, $FRB", IIC_FPFused,
2497                      [(set f64:$FRT,
2498                            (fma f64:$FRA, f64:$FRC, (fneg f64:$FRB)))]>;
2499  defm FMSUBS : AForm_1r<59, 28,
2500                      (outs f4rc:$FRT), (ins f4rc:$FRA, f4rc:$FRC, f4rc:$FRB),
2501                      "fmsubs", "$FRT, $FRA, $FRC, $FRB", IIC_FPGeneral,
2502                      [(set f32:$FRT,
2503                            (fma f32:$FRA, f32:$FRC, (fneg f32:$FRB)))]>;
2504  defm FNMADD : AForm_1r<63, 31,
2505                      (outs f8rc:$FRT), (ins f8rc:$FRA, f8rc:$FRC, f8rc:$FRB),
2506                      "fnmadd", "$FRT, $FRA, $FRC, $FRB", IIC_FPFused,
2507                      [(set f64:$FRT,
2508                            (fneg (fma f64:$FRA, f64:$FRC, f64:$FRB)))]>;
2509  defm FNMADDS : AForm_1r<59, 31,
2510                      (outs f4rc:$FRT), (ins f4rc:$FRA, f4rc:$FRC, f4rc:$FRB),
2511                      "fnmadds", "$FRT, $FRA, $FRC, $FRB", IIC_FPGeneral,
2512                      [(set f32:$FRT,
2513                            (fneg (fma f32:$FRA, f32:$FRC, f32:$FRB)))]>;
2514  defm FNMSUB : AForm_1r<63, 30,
2515                      (outs f8rc:$FRT), (ins f8rc:$FRA, f8rc:$FRC, f8rc:$FRB),
2516                      "fnmsub", "$FRT, $FRA, $FRC, $FRB", IIC_FPFused,
2517                      [(set f64:$FRT, (fneg (fma f64:$FRA, f64:$FRC,
2518                                                 (fneg f64:$FRB))))]>;
2519  defm FNMSUBS : AForm_1r<59, 30,
2520                      (outs f4rc:$FRT), (ins f4rc:$FRA, f4rc:$FRC, f4rc:$FRB),
2521                      "fnmsubs", "$FRT, $FRA, $FRC, $FRB", IIC_FPGeneral,
2522                      [(set f32:$FRT, (fneg (fma f32:$FRA, f32:$FRC,
2523                                                 (fneg f32:$FRB))))]>;
2524} // isCommutable
2525}
2526// FSEL is artificially split into 4 and 8-byte forms for the result.  To avoid
2527// having 4 of these, force the comparison to always be an 8-byte double (code
2528// should use an FMRSD if the input comparison value really wants to be a float)
2529// and 4/8 byte forms for the result and operand type..
2530let Interpretation64Bit = 1, isCodeGenOnly = 1 in
2531defm FSELD : AForm_1r<63, 23,
2532                      (outs f8rc:$FRT), (ins f8rc:$FRA, f8rc:$FRC, f8rc:$FRB),
2533                      "fsel", "$FRT, $FRA, $FRC, $FRB", IIC_FPGeneral,
2534                      [(set f64:$FRT, (PPCfsel f64:$FRA, f64:$FRC, f64:$FRB))]>;
2535defm FSELS : AForm_1r<63, 23,
2536                      (outs f4rc:$FRT), (ins f8rc:$FRA, f4rc:$FRC, f4rc:$FRB),
2537                      "fsel", "$FRT, $FRA, $FRC, $FRB", IIC_FPGeneral,
2538                      [(set f32:$FRT, (PPCfsel f64:$FRA, f32:$FRC, f32:$FRB))]>;
2539let Uses = [RM] in {
2540  let isCommutable = 1 in {
2541  defm FADD  : AForm_2r<63, 21,
2542                        (outs f8rc:$FRT), (ins f8rc:$FRA, f8rc:$FRB),
2543                        "fadd", "$FRT, $FRA, $FRB", IIC_FPAddSub,
2544                        [(set f64:$FRT, (fadd f64:$FRA, f64:$FRB))]>;
2545  defm FADDS : AForm_2r<59, 21,
2546                        (outs f4rc:$FRT), (ins f4rc:$FRA, f4rc:$FRB),
2547                        "fadds", "$FRT, $FRA, $FRB", IIC_FPGeneral,
2548                        [(set f32:$FRT, (fadd f32:$FRA, f32:$FRB))]>;
2549  } // isCommutable
2550  defm FDIV  : AForm_2r<63, 18,
2551                        (outs f8rc:$FRT), (ins f8rc:$FRA, f8rc:$FRB),
2552                        "fdiv", "$FRT, $FRA, $FRB", IIC_FPDivD,
2553                        [(set f64:$FRT, (fdiv f64:$FRA, f64:$FRB))]>;
2554  defm FDIVS : AForm_2r<59, 18,
2555                        (outs f4rc:$FRT), (ins f4rc:$FRA, f4rc:$FRB),
2556                        "fdivs", "$FRT, $FRA, $FRB", IIC_FPDivS,
2557                        [(set f32:$FRT, (fdiv f32:$FRA, f32:$FRB))]>;
2558  let isCommutable = 1 in {
2559  defm FMUL  : AForm_3r<63, 25,
2560                        (outs f8rc:$FRT), (ins f8rc:$FRA, f8rc:$FRC),
2561                        "fmul", "$FRT, $FRA, $FRC", IIC_FPFused,
2562                        [(set f64:$FRT, (fmul f64:$FRA, f64:$FRC))]>;
2563  defm FMULS : AForm_3r<59, 25,
2564                        (outs f4rc:$FRT), (ins f4rc:$FRA, f4rc:$FRC),
2565                        "fmuls", "$FRT, $FRA, $FRC", IIC_FPGeneral,
2566                        [(set f32:$FRT, (fmul f32:$FRA, f32:$FRC))]>;
2567  } // isCommutable
2568  defm FSUB  : AForm_2r<63, 20,
2569                        (outs f8rc:$FRT), (ins f8rc:$FRA, f8rc:$FRB),
2570                        "fsub", "$FRT, $FRA, $FRB", IIC_FPAddSub,
2571                        [(set f64:$FRT, (fsub f64:$FRA, f64:$FRB))]>;
2572  defm FSUBS : AForm_2r<59, 20,
2573                        (outs f4rc:$FRT), (ins f4rc:$FRA, f4rc:$FRB),
2574                        "fsubs", "$FRT, $FRA, $FRB", IIC_FPGeneral,
2575                        [(set f32:$FRT, (fsub f32:$FRA, f32:$FRB))]>;
2576  }
2577}
2578
2579let hasSideEffects = 0 in {
2580let PPC970_Unit = 1 in {  // FXU Operations.
2581  let isSelect = 1 in
2582  def ISEL  : AForm_4<31, 15,
2583                     (outs gprc:$rT), (ins gprc_nor0:$rA, gprc:$rB, crbitrc:$cond),
2584                     "isel $rT, $rA, $rB, $cond", IIC_IntISEL,
2585                     []>;
2586}
2587
2588let PPC970_Unit = 1 in {  // FXU Operations.
2589// M-Form instructions.  rotate and mask instructions.
2590//
2591let isCommutable = 1 in {
2592// RLWIMI can be commuted if the rotate amount is zero.
2593defm RLWIMI : MForm_2r<20, (outs gprc:$rA),
2594                       (ins gprc:$rSi, gprc:$rS, u5imm:$SH, u5imm:$MB,
2595                       u5imm:$ME), "rlwimi", "$rA, $rS, $SH, $MB, $ME",
2596                       IIC_IntRotate, []>, PPC970_DGroup_Cracked,
2597                       RegConstraint<"$rSi = $rA">, NoEncode<"$rSi">;
2598}
2599let BaseName = "rlwinm" in {
2600def RLWINM : MForm_2<21,
2601                     (outs gprc:$rA), (ins gprc:$rS, u5imm:$SH, u5imm:$MB, u5imm:$ME),
2602                     "rlwinm $rA, $rS, $SH, $MB, $ME", IIC_IntGeneral,
2603                     []>, RecFormRel;
2604let Defs = [CR0] in
2605def RLWINMo : MForm_2<21,
2606                      (outs gprc:$rA), (ins gprc:$rS, u5imm:$SH, u5imm:$MB, u5imm:$ME),
2607                      "rlwinm. $rA, $rS, $SH, $MB, $ME", IIC_IntGeneral,
2608                      []>, isDOT, RecFormRel, PPC970_DGroup_Cracked;
2609}
2610defm RLWNM  : MForm_2r<23, (outs gprc:$rA),
2611                       (ins gprc:$rS, gprc:$rB, u5imm:$MB, u5imm:$ME),
2612                       "rlwnm", "$rA, $rS, $rB, $MB, $ME", IIC_IntGeneral,
2613                       []>;
2614}
2615} // hasSideEffects = 0
2616
2617//===----------------------------------------------------------------------===//
2618// PowerPC Instruction Patterns
2619//
2620
2621// Arbitrary immediate support.  Implement in terms of LIS/ORI.
2622def : Pat<(i32 imm:$imm),
2623          (ORI (LIS (HI16 imm:$imm)), (LO16 imm:$imm))>;
2624
2625// Implement the 'not' operation with the NOR instruction.
2626def i32not : OutPatFrag<(ops node:$in),
2627                        (NOR $in, $in)>;
2628def        : Pat<(not i32:$in),
2629                 (i32not $in)>;
2630
2631// ADD an arbitrary immediate.
2632def : Pat<(add i32:$in, imm:$imm),
2633          (ADDIS (ADDI $in, (LO16 imm:$imm)), (HA16 imm:$imm))>;
2634// OR an arbitrary immediate.
2635def : Pat<(or i32:$in, imm:$imm),
2636          (ORIS (ORI $in, (LO16 imm:$imm)), (HI16 imm:$imm))>;
2637// XOR an arbitrary immediate.
2638def : Pat<(xor i32:$in, imm:$imm),
2639          (XORIS (XORI $in, (LO16 imm:$imm)), (HI16 imm:$imm))>;
2640// SUBFIC
2641def : Pat<(sub imm32SExt16:$imm, i32:$in),
2642          (SUBFIC $in, imm:$imm)>;
2643
2644// SHL/SRL
2645def : Pat<(shl i32:$in, (i32 imm:$imm)),
2646          (RLWINM $in, imm:$imm, 0, (SHL32 imm:$imm))>;
2647def : Pat<(srl i32:$in, (i32 imm:$imm)),
2648          (RLWINM $in, (SRL32 imm:$imm), imm:$imm, 31)>;
2649
2650// ROTL
2651def : Pat<(rotl i32:$in, i32:$sh),
2652          (RLWNM $in, $sh, 0, 31)>;
2653def : Pat<(rotl i32:$in, (i32 imm:$imm)),
2654          (RLWINM $in, imm:$imm, 0, 31)>;
2655
2656// RLWNM
2657def : Pat<(and (rotl i32:$in, i32:$sh), maskimm32:$imm),
2658          (RLWNM $in, $sh, (MB maskimm32:$imm), (ME maskimm32:$imm))>;
2659
2660// Calls
2661def : Pat<(PPCcall (i32 tglobaladdr:$dst)),
2662          (BL tglobaladdr:$dst)>;
2663def : Pat<(PPCcall (i32 texternalsym:$dst)),
2664          (BL texternalsym:$dst)>;
2665
2666def : Pat<(PPCtc_return (i32 tglobaladdr:$dst),  imm:$imm),
2667          (TCRETURNdi tglobaladdr:$dst, imm:$imm)>;
2668
2669def : Pat<(PPCtc_return (i32 texternalsym:$dst), imm:$imm),
2670          (TCRETURNdi texternalsym:$dst, imm:$imm)>;
2671
2672def : Pat<(PPCtc_return CTRRC:$dst, imm:$imm),
2673          (TCRETURNri CTRRC:$dst, imm:$imm)>;
2674
2675
2676
2677// Hi and Lo for Darwin Global Addresses.
2678def : Pat<(PPChi tglobaladdr:$in, 0), (LIS tglobaladdr:$in)>;
2679def : Pat<(PPClo tglobaladdr:$in, 0), (LI tglobaladdr:$in)>;
2680def : Pat<(PPChi tconstpool:$in, 0), (LIS tconstpool:$in)>;
2681def : Pat<(PPClo tconstpool:$in, 0), (LI tconstpool:$in)>;
2682def : Pat<(PPChi tjumptable:$in, 0), (LIS tjumptable:$in)>;
2683def : Pat<(PPClo tjumptable:$in, 0), (LI tjumptable:$in)>;
2684def : Pat<(PPChi tblockaddress:$in, 0), (LIS tblockaddress:$in)>;
2685def : Pat<(PPClo tblockaddress:$in, 0), (LI tblockaddress:$in)>;
2686def : Pat<(PPChi tglobaltlsaddr:$g, i32:$in),
2687          (ADDIS $in, tglobaltlsaddr:$g)>;
2688def : Pat<(PPClo tglobaltlsaddr:$g, i32:$in),
2689          (ADDI $in, tglobaltlsaddr:$g)>;
2690def : Pat<(add i32:$in, (PPChi tglobaladdr:$g, 0)),
2691          (ADDIS $in, tglobaladdr:$g)>;
2692def : Pat<(add i32:$in, (PPChi tconstpool:$g, 0)),
2693          (ADDIS $in, tconstpool:$g)>;
2694def : Pat<(add i32:$in, (PPChi tjumptable:$g, 0)),
2695          (ADDIS $in, tjumptable:$g)>;
2696def : Pat<(add i32:$in, (PPChi tblockaddress:$g, 0)),
2697          (ADDIS $in, tblockaddress:$g)>;
2698
2699// Support for thread-local storage.
2700def PPC32GOT: Pseudo<(outs gprc:$rD), (ins), "#PPC32GOT",
2701                [(set i32:$rD, (PPCppc32GOT))]>;
2702
2703// Get the _GLOBAL_OFFSET_TABLE_ in PIC mode.
2704// This uses two output registers, the first as the real output, the second as a
2705// temporary register, used internally in code generation.
2706def PPC32PICGOT: Pseudo<(outs gprc:$rD, gprc:$rT), (ins), "#PPC32PICGOT",
2707                []>, NoEncode<"$rT">;
2708
2709def LDgotTprelL32: Pseudo<(outs gprc:$rD), (ins s16imm:$disp, gprc_nor0:$reg),
2710                           "#LDgotTprelL32",
2711                           [(set i32:$rD,
2712                             (PPCldGotTprelL tglobaltlsaddr:$disp, i32:$reg))]>;
2713def : Pat<(PPCaddTls i32:$in, tglobaltlsaddr:$g),
2714          (ADD4TLS $in, tglobaltlsaddr:$g)>;
2715
2716def ADDItlsgdL32 : Pseudo<(outs gprc:$rD), (ins gprc_nor0:$reg, s16imm:$disp),
2717                         "#ADDItlsgdL32",
2718                         [(set i32:$rD,
2719                           (PPCaddiTlsgdL i32:$reg, tglobaltlsaddr:$disp))]>;
2720// LR is a true define, while the rest of the Defs are clobbers.  R3 is
2721// explicitly defined when this op is created, so not mentioned here.
2722let hasExtraSrcRegAllocReq = 1, hasExtraDefRegAllocReq = 1,
2723    Defs = [R0,R4,R5,R6,R7,R8,R9,R10,R11,R12,LR,CTR,CR0,CR1,CR5,CR6,CR7] in
2724def GETtlsADDR32 : Pseudo<(outs gprc:$rD), (ins gprc:$reg, tlsgd32:$sym),
2725                          "GETtlsADDR32",
2726                          [(set i32:$rD,
2727                            (PPCgetTlsAddr i32:$reg, tglobaltlsaddr:$sym))]>;
2728// Combined op for ADDItlsgdL32 and GETtlsADDR32, late expanded.  R3 and LR
2729// are true defines while the rest of the Defs are clobbers.
2730let hasExtraSrcRegAllocReq = 1, hasExtraDefRegAllocReq = 1,
2731    Defs = [R0,R3,R4,R5,R6,R7,R8,R9,R10,R11,R12,LR,CTR,CR0,CR1,CR5,CR6,CR7] in
2732def ADDItlsgdLADDR32 : Pseudo<(outs gprc:$rD),
2733                              (ins gprc_nor0:$reg, s16imm:$disp, tlsgd32:$sym),
2734                              "#ADDItlsgdLADDR32",
2735                              [(set i32:$rD,
2736                                (PPCaddiTlsgdLAddr i32:$reg,
2737                                                   tglobaltlsaddr:$disp,
2738                                                   tglobaltlsaddr:$sym))]>;
2739def ADDItlsldL32 : Pseudo<(outs gprc:$rD), (ins gprc_nor0:$reg, s16imm:$disp),
2740                          "#ADDItlsldL32",
2741                          [(set i32:$rD,
2742                            (PPCaddiTlsldL i32:$reg, tglobaltlsaddr:$disp))]>;
2743// LR is a true define, while the rest of the Defs are clobbers.  R3 is
2744// explicitly defined when this op is created, so not mentioned here.
2745let hasExtraSrcRegAllocReq = 1, hasExtraDefRegAllocReq = 1,
2746    Defs = [R0,R4,R5,R6,R7,R8,R9,R10,R11,R12,LR,CTR,CR0,CR1,CR5,CR6,CR7] in
2747def GETtlsldADDR32 : Pseudo<(outs gprc:$rD), (ins gprc:$reg, tlsgd32:$sym),
2748                            "GETtlsldADDR32",
2749                            [(set i32:$rD,
2750                              (PPCgetTlsldAddr i32:$reg,
2751                                               tglobaltlsaddr:$sym))]>;
2752// Combined op for ADDItlsldL32 and GETtlsADDR32, late expanded.  R3 and LR
2753// are true defines while the rest of the Defs are clobbers.
2754let hasExtraSrcRegAllocReq = 1, hasExtraDefRegAllocReq = 1,
2755    Defs = [R0,R3,R4,R5,R6,R7,R8,R9,R10,R11,R12,LR,CTR,CR0,CR1,CR5,CR6,CR7] in
2756def ADDItlsldLADDR32 : Pseudo<(outs gprc:$rD),
2757                              (ins gprc_nor0:$reg, s16imm:$disp, tlsgd32:$sym),
2758                              "#ADDItlsldLADDR32",
2759                              [(set i32:$rD,
2760                                (PPCaddiTlsldLAddr i32:$reg,
2761                                                   tglobaltlsaddr:$disp,
2762                                                   tglobaltlsaddr:$sym))]>;
2763def ADDIdtprelL32 : Pseudo<(outs gprc:$rD), (ins gprc_nor0:$reg, s16imm:$disp),
2764                           "#ADDIdtprelL32",
2765                           [(set i32:$rD,
2766                             (PPCaddiDtprelL i32:$reg, tglobaltlsaddr:$disp))]>;
2767def ADDISdtprelHA32 : Pseudo<(outs gprc:$rD), (ins gprc_nor0:$reg, s16imm:$disp),
2768                            "#ADDISdtprelHA32",
2769                            [(set i32:$rD,
2770                              (PPCaddisDtprelHA i32:$reg,
2771                                                tglobaltlsaddr:$disp))]>;
2772
2773// Support for Position-independent code
2774def LWZtoc : Pseudo<(outs gprc:$rD), (ins tocentry32:$disp, gprc:$reg),
2775                   "#LWZtoc",
2776                   [(set i32:$rD,
2777                      (PPCtoc_entry tglobaladdr:$disp, i32:$reg))]>;
2778// Get Global (GOT) Base Register offset, from the word immediately preceding
2779// the function label.
2780def UpdateGBR : Pseudo<(outs gprc:$rD, gprc:$rT), (ins gprc:$rI), "#UpdateGBR", []>;
2781
2782
2783// Standard shifts.  These are represented separately from the real shifts above
2784// so that we can distinguish between shifts that allow 5-bit and 6-bit shift
2785// amounts.
2786def : Pat<(sra i32:$rS, i32:$rB),
2787          (SRAW $rS, $rB)>;
2788def : Pat<(srl i32:$rS, i32:$rB),
2789          (SRW $rS, $rB)>;
2790def : Pat<(shl i32:$rS, i32:$rB),
2791          (SLW $rS, $rB)>;
2792
2793def : Pat<(zextloadi1 iaddr:$src),
2794          (LBZ iaddr:$src)>;
2795def : Pat<(zextloadi1 xaddr:$src),
2796          (LBZX xaddr:$src)>;
2797def : Pat<(extloadi1 iaddr:$src),
2798          (LBZ iaddr:$src)>;
2799def : Pat<(extloadi1 xaddr:$src),
2800          (LBZX xaddr:$src)>;
2801def : Pat<(extloadi8 iaddr:$src),
2802          (LBZ iaddr:$src)>;
2803def : Pat<(extloadi8 xaddr:$src),
2804          (LBZX xaddr:$src)>;
2805def : Pat<(extloadi16 iaddr:$src),
2806          (LHZ iaddr:$src)>;
2807def : Pat<(extloadi16 xaddr:$src),
2808          (LHZX xaddr:$src)>;
2809def : Pat<(f64 (extloadf32 iaddr:$src)),
2810          (COPY_TO_REGCLASS (LFS iaddr:$src), F8RC)>;
2811def : Pat<(f64 (extloadf32 xaddr:$src)),
2812          (COPY_TO_REGCLASS (LFSX xaddr:$src), F8RC)>;
2813
2814def : Pat<(f64 (fextend f32:$src)),
2815          (COPY_TO_REGCLASS $src, F8RC)>;
2816
2817// Only seq_cst fences require the heavyweight sync (SYNC 0).
2818// All others can use the lightweight sync (SYNC 1).
2819// source: http://www.cl.cam.ac.uk/~pes20/cpp/cpp0xmappings.html
2820// The rule for seq_cst is duplicated to work with both 64 bits and 32 bits
2821// versions of Power.
2822def : Pat<(atomic_fence (i64 7), (imm)), (SYNC 0)>, Requires<[HasSYNC]>;
2823def : Pat<(atomic_fence (i32 7), (imm)), (SYNC 0)>, Requires<[HasSYNC]>;
2824def : Pat<(atomic_fence (imm),   (imm)), (SYNC 1)>, Requires<[HasSYNC]>;
2825def : Pat<(atomic_fence (imm), (imm)), (MSYNC)>, Requires<[HasOnlyMSYNC]>;
2826
2827// Additional FNMSUB patterns: -a*c + b == -(a*c - b)
2828def : Pat<(fma (fneg f64:$A), f64:$C, f64:$B),
2829          (FNMSUB $A, $C, $B)>;
2830def : Pat<(fma f64:$A, (fneg f64:$C), f64:$B),
2831          (FNMSUB $A, $C, $B)>;
2832def : Pat<(fma (fneg f32:$A), f32:$C, f32:$B),
2833          (FNMSUBS $A, $C, $B)>;
2834def : Pat<(fma f32:$A, (fneg f32:$C), f32:$B),
2835          (FNMSUBS $A, $C, $B)>;
2836
2837// FCOPYSIGN's operand types need not agree.
2838def : Pat<(fcopysign f64:$frB, f32:$frA),
2839          (FCPSGND (COPY_TO_REGCLASS $frA, F8RC), $frB)>;
2840def : Pat<(fcopysign f32:$frB, f64:$frA),
2841          (FCPSGNS (COPY_TO_REGCLASS $frA, F4RC), $frB)>;
2842
2843include "PPCInstrAltivec.td"
2844include "PPCInstrSPE.td"
2845include "PPCInstr64Bit.td"
2846include "PPCInstrVSX.td"
2847include "PPCInstrQPX.td"
2848include "PPCInstrHTM.td"
2849
2850def crnot : OutPatFrag<(ops node:$in),
2851                       (CRNOR $in, $in)>;
2852def       : Pat<(not i1:$in),
2853                (crnot $in)>;
2854
2855// Patterns for arithmetic i1 operations.
2856def : Pat<(add i1:$a, i1:$b),
2857          (CRXOR $a, $b)>;
2858def : Pat<(sub i1:$a, i1:$b),
2859          (CRXOR $a, $b)>;
2860def : Pat<(mul i1:$a, i1:$b),
2861          (CRAND $a, $b)>;
2862
2863// We're sometimes asked to materialize i1 -1, which is just 1 in this case
2864// (-1 is used to mean all bits set).
2865def : Pat<(i1 -1), (CRSET)>;
2866
2867// i1 extensions, implemented in terms of isel.
2868def : Pat<(i32 (zext i1:$in)),
2869          (SELECT_I4 $in, (LI 1), (LI 0))>;
2870def : Pat<(i32 (sext i1:$in)),
2871          (SELECT_I4 $in, (LI -1), (LI 0))>;
2872
2873def : Pat<(i64 (zext i1:$in)),
2874          (SELECT_I8 $in, (LI8 1), (LI8 0))>;
2875def : Pat<(i64 (sext i1:$in)),
2876          (SELECT_I8 $in, (LI8 -1), (LI8 0))>;
2877
2878// FIXME: We should choose either a zext or a sext based on other constants
2879// already around.
2880def : Pat<(i32 (anyext i1:$in)),
2881          (SELECT_I4 $in, (LI 1), (LI 0))>;
2882def : Pat<(i64 (anyext i1:$in)),
2883          (SELECT_I8 $in, (LI8 1), (LI8 0))>;
2884
2885// match setcc on i1 variables.
2886// CRANDC is:
2887//   1 1 : F
2888//   1 0 : T
2889//   0 1 : F
2890//   0 0 : F
2891//
2892// LT is:
2893//  -1 -1  : F
2894//  -1  0  : T
2895//   0 -1  : F
2896//   0  0  : F
2897//
2898// ULT is:
2899//   1 1 : F
2900//   1 0 : F
2901//   0 1 : T
2902//   0 0 : F
2903def : Pat<(i1 (setcc i1:$s1, i1:$s2, SETLT)),
2904          (CRANDC $s1, $s2)>;
2905def : Pat<(i1 (setcc i1:$s1, i1:$s2, SETULT)),
2906          (CRANDC $s2, $s1)>;
2907// CRORC is:
2908//   1 1 : T
2909//   1 0 : T
2910//   0 1 : F
2911//   0 0 : T
2912//
2913// LE is:
2914//  -1 -1 : T
2915//  -1  0 : T
2916//   0 -1 : F
2917//   0  0 : T
2918//
2919// ULE is:
2920//   1 1 : T
2921//   1 0 : F
2922//   0 1 : T
2923//   0 0 : T
2924def : Pat<(i1 (setcc i1:$s1, i1:$s2, SETLE)),
2925          (CRORC $s1, $s2)>;
2926def : Pat<(i1 (setcc i1:$s1, i1:$s2, SETULE)),
2927          (CRORC $s2, $s1)>;
2928
2929def : Pat<(i1 (setcc i1:$s1, i1:$s2, SETEQ)),
2930          (CREQV $s1, $s2)>;
2931
2932// GE is:
2933//  -1 -1 : T
2934//  -1  0 : F
2935//   0 -1 : T
2936//   0  0 : T
2937//
2938// UGE is:
2939//   1 1 : T
2940//   1 0 : T
2941//   0 1 : F
2942//   0 0 : T
2943def : Pat<(i1 (setcc i1:$s1, i1:$s2, SETGE)),
2944          (CRORC $s2, $s1)>;
2945def : Pat<(i1 (setcc i1:$s1, i1:$s2, SETUGE)),
2946          (CRORC $s1, $s2)>;
2947
2948// GT is:
2949//  -1 -1 : F
2950//  -1  0 : F
2951//   0 -1 : T
2952//   0  0 : F
2953//
2954// UGT is:
2955//  1 1 : F
2956//  1 0 : T
2957//  0 1 : F
2958//  0 0 : F
2959def : Pat<(i1 (setcc i1:$s1, i1:$s2, SETGT)),
2960          (CRANDC $s2, $s1)>;
2961def : Pat<(i1 (setcc i1:$s1, i1:$s2, SETUGT)),
2962          (CRANDC $s1, $s2)>;
2963
2964def : Pat<(i1 (setcc i1:$s1, i1:$s2, SETNE)),
2965          (CRXOR $s1, $s2)>;
2966
2967// match setcc on non-i1 (non-vector) variables. Note that SETUEQ, SETOGE,
2968// SETOLE, SETONE, SETULT and SETUGT should be expanded by legalize for
2969// floating-point types.
2970
2971multiclass CRNotPat<dag pattern, dag result> {
2972  def : Pat<pattern, (crnot result)>;
2973  def : Pat<(not pattern), result>;
2974
2975  // We can also fold the crnot into an extension:
2976  def : Pat<(i32 (zext pattern)),
2977            (SELECT_I4 result, (LI 0), (LI 1))>;
2978  def : Pat<(i32 (sext pattern)),
2979            (SELECT_I4 result, (LI 0), (LI -1))>;
2980
2981  // We can also fold the crnot into an extension:
2982  def : Pat<(i64 (zext pattern)),
2983            (SELECT_I8 result, (LI8 0), (LI8 1))>;
2984  def : Pat<(i64 (sext pattern)),
2985            (SELECT_I8 result, (LI8 0), (LI8 -1))>;
2986
2987  // FIXME: We should choose either a zext or a sext based on other constants
2988  // already around.
2989  def : Pat<(i32 (anyext pattern)),
2990            (SELECT_I4 result, (LI 0), (LI 1))>;
2991
2992  def : Pat<(i64 (anyext pattern)),
2993            (SELECT_I8 result, (LI8 0), (LI8 1))>;
2994}
2995
2996// FIXME: Because of what seems like a bug in TableGen's type-inference code,
2997// we need to write imm:$imm in the output patterns below, not just $imm, or
2998// else the resulting matcher will not correctly add the immediate operand
2999// (making it a register operand instead).
3000
3001// extended SETCC.
3002multiclass ExtSetCCPat<CondCode cc, PatFrag pfrag,
3003                       OutPatFrag rfrag, OutPatFrag rfrag8> {
3004  def : Pat<(i32 (zext (i1 (pfrag i32:$s1, cc)))),
3005            (rfrag $s1)>;
3006  def : Pat<(i64 (zext (i1 (pfrag i64:$s1, cc)))),
3007            (rfrag8 $s1)>;
3008  def : Pat<(i64 (zext (i1 (pfrag i32:$s1, cc)))),
3009            (INSERT_SUBREG (i64 (IMPLICIT_DEF)), (rfrag $s1), sub_32)>;
3010  def : Pat<(i32 (zext (i1 (pfrag i64:$s1, cc)))),
3011            (EXTRACT_SUBREG (rfrag8 $s1), sub_32)>;
3012
3013  def : Pat<(i32 (anyext (i1 (pfrag i32:$s1, cc)))),
3014            (rfrag $s1)>;
3015  def : Pat<(i64 (anyext (i1 (pfrag i64:$s1, cc)))),
3016            (rfrag8 $s1)>;
3017  def : Pat<(i64 (anyext (i1 (pfrag i32:$s1, cc)))),
3018            (INSERT_SUBREG (i64 (IMPLICIT_DEF)), (rfrag $s1), sub_32)>;
3019  def : Pat<(i32 (anyext (i1 (pfrag i64:$s1, cc)))),
3020            (EXTRACT_SUBREG (rfrag8 $s1), sub_32)>;
3021}
3022
3023// Note that we do all inversions below with i(32|64)not, instead of using
3024// (xori x, 1) because on the A2 nor has single-cycle latency while xori
3025// has 2-cycle latency.
3026
3027defm : ExtSetCCPat<SETEQ,
3028                   PatFrag<(ops node:$in, node:$cc),
3029                           (setcc $in, 0, $cc)>,
3030                   OutPatFrag<(ops node:$in),
3031                              (RLWINM (CNTLZW $in), 27, 31, 31)>,
3032                   OutPatFrag<(ops node:$in),
3033                              (RLDICL (CNTLZD $in), 58, 63)> >;
3034
3035defm : ExtSetCCPat<SETNE,
3036                   PatFrag<(ops node:$in, node:$cc),
3037                           (setcc $in, 0, $cc)>,
3038                   OutPatFrag<(ops node:$in),
3039                              (RLWINM (i32not (CNTLZW $in)), 27, 31, 31)>,
3040                   OutPatFrag<(ops node:$in),
3041                              (RLDICL (i64not (CNTLZD $in)), 58, 63)> >;
3042
3043defm : ExtSetCCPat<SETLT,
3044                   PatFrag<(ops node:$in, node:$cc),
3045                           (setcc $in, 0, $cc)>,
3046                   OutPatFrag<(ops node:$in),
3047                              (RLWINM $in, 1, 31, 31)>,
3048                   OutPatFrag<(ops node:$in),
3049                              (RLDICL $in, 1, 63)> >;
3050
3051defm : ExtSetCCPat<SETGE,
3052                   PatFrag<(ops node:$in, node:$cc),
3053                           (setcc $in, 0, $cc)>,
3054                   OutPatFrag<(ops node:$in),
3055                              (RLWINM (i32not $in), 1, 31, 31)>,
3056                   OutPatFrag<(ops node:$in),
3057                              (RLDICL (i64not $in), 1, 63)> >;
3058
3059defm : ExtSetCCPat<SETGT,
3060                   PatFrag<(ops node:$in, node:$cc),
3061                           (setcc $in, 0, $cc)>,
3062                   OutPatFrag<(ops node:$in),
3063                              (RLWINM (ANDC (NEG $in), $in), 1, 31, 31)>,
3064                   OutPatFrag<(ops node:$in),
3065                              (RLDICL (ANDC8 (NEG8 $in), $in), 1, 63)> >;
3066
3067defm : ExtSetCCPat<SETLE,
3068                   PatFrag<(ops node:$in, node:$cc),
3069                           (setcc $in, 0, $cc)>,
3070                   OutPatFrag<(ops node:$in),
3071                              (RLWINM (ORC $in, (NEG $in)), 1, 31, 31)>,
3072                   OutPatFrag<(ops node:$in),
3073                              (RLDICL (ORC8 $in, (NEG8 $in)), 1, 63)> >;
3074
3075defm : ExtSetCCPat<SETLT,
3076                   PatFrag<(ops node:$in, node:$cc),
3077                           (setcc $in, -1, $cc)>,
3078                   OutPatFrag<(ops node:$in),
3079                              (RLWINM (AND $in, (ADDI $in, 1)), 1, 31, 31)>,
3080                   OutPatFrag<(ops node:$in),
3081                              (RLDICL (AND8 $in, (ADDI8 $in, 1)), 1, 63)> >;
3082
3083defm : ExtSetCCPat<SETGE,
3084                   PatFrag<(ops node:$in, node:$cc),
3085                           (setcc $in, -1, $cc)>,
3086                   OutPatFrag<(ops node:$in),
3087                              (RLWINM (NAND $in, (ADDI $in, 1)), 1, 31, 31)>,
3088                   OutPatFrag<(ops node:$in),
3089                              (RLDICL (NAND8 $in, (ADDI8 $in, 1)), 1, 63)> >;
3090
3091defm : ExtSetCCPat<SETGT,
3092                   PatFrag<(ops node:$in, node:$cc),
3093                           (setcc $in, -1, $cc)>,
3094                   OutPatFrag<(ops node:$in),
3095                              (RLWINM (i32not $in), 1, 31, 31)>,
3096                   OutPatFrag<(ops node:$in),
3097                              (RLDICL (i64not $in), 1, 63)> >;
3098
3099defm : ExtSetCCPat<SETLE,
3100                   PatFrag<(ops node:$in, node:$cc),
3101                           (setcc $in, -1, $cc)>,
3102                   OutPatFrag<(ops node:$in),
3103                              (RLWINM $in, 1, 31, 31)>,
3104                   OutPatFrag<(ops node:$in),
3105                              (RLDICL $in, 1, 63)> >;
3106
3107// SETCC for i32.
3108def : Pat<(i1 (setcc i32:$s1, immZExt16:$imm, SETULT)),
3109          (EXTRACT_SUBREG (CMPLWI $s1, imm:$imm), sub_lt)>;
3110def : Pat<(i1 (setcc i32:$s1, imm32SExt16:$imm, SETLT)),
3111          (EXTRACT_SUBREG (CMPWI $s1, imm:$imm), sub_lt)>;
3112def : Pat<(i1 (setcc i32:$s1, immZExt16:$imm, SETUGT)),
3113          (EXTRACT_SUBREG (CMPLWI $s1, imm:$imm), sub_gt)>;
3114def : Pat<(i1 (setcc i32:$s1, imm32SExt16:$imm, SETGT)),
3115          (EXTRACT_SUBREG (CMPWI $s1, imm:$imm), sub_gt)>;
3116def : Pat<(i1 (setcc i32:$s1, imm32SExt16:$imm, SETEQ)),
3117          (EXTRACT_SUBREG (CMPWI $s1, imm:$imm), sub_eq)>;
3118def : Pat<(i1 (setcc i32:$s1, immZExt16:$imm, SETEQ)),
3119          (EXTRACT_SUBREG (CMPLWI $s1, imm:$imm), sub_eq)>;
3120
3121// For non-equality comparisons, the default code would materialize the
3122// constant, then compare against it, like this:
3123//   lis r2, 4660
3124//   ori r2, r2, 22136
3125//   cmpw cr0, r3, r2
3126//   beq cr0,L6
3127// Since we are just comparing for equality, we can emit this instead:
3128//   xoris r0,r3,0x1234
3129//   cmplwi cr0,r0,0x5678
3130//   beq cr0,L6
3131
3132def : Pat<(i1 (setcc i32:$s1, imm:$imm, SETEQ)),
3133          (EXTRACT_SUBREG (CMPLWI (XORIS $s1, (HI16 imm:$imm)),
3134                                  (LO16 imm:$imm)), sub_eq)>;
3135
3136defm : CRNotPat<(i1 (setcc i32:$s1, immZExt16:$imm, SETUGE)),
3137                (EXTRACT_SUBREG (CMPLWI $s1, imm:$imm), sub_lt)>;
3138defm : CRNotPat<(i1 (setcc i32:$s1, imm32SExt16:$imm, SETGE)),
3139                (EXTRACT_SUBREG (CMPWI $s1, imm:$imm), sub_lt)>;
3140defm : CRNotPat<(i1 (setcc i32:$s1, immZExt16:$imm, SETULE)),
3141                (EXTRACT_SUBREG (CMPLWI $s1, imm:$imm), sub_gt)>;
3142defm : CRNotPat<(i1 (setcc i32:$s1, imm32SExt16:$imm, SETLE)),
3143                (EXTRACT_SUBREG (CMPWI $s1, imm:$imm), sub_gt)>;
3144defm : CRNotPat<(i1 (setcc i32:$s1, imm32SExt16:$imm, SETNE)),
3145                (EXTRACT_SUBREG (CMPWI $s1, imm:$imm), sub_eq)>;
3146defm : CRNotPat<(i1 (setcc i32:$s1, immZExt16:$imm, SETNE)),
3147                (EXTRACT_SUBREG (CMPLWI $s1, imm:$imm), sub_eq)>;
3148
3149defm : CRNotPat<(i1 (setcc i32:$s1, imm:$imm, SETNE)),
3150                (EXTRACT_SUBREG (CMPLWI (XORIS $s1, (HI16 imm:$imm)),
3151                                        (LO16 imm:$imm)), sub_eq)>;
3152
3153def : Pat<(i1 (setcc i32:$s1, i32:$s2, SETULT)),
3154          (EXTRACT_SUBREG (CMPLW $s1, $s2), sub_lt)>;
3155def : Pat<(i1 (setcc i32:$s1, i32:$s2, SETLT)),
3156          (EXTRACT_SUBREG (CMPW $s1, $s2), sub_lt)>;
3157def : Pat<(i1 (setcc i32:$s1, i32:$s2, SETUGT)),
3158          (EXTRACT_SUBREG (CMPLW $s1, $s2), sub_gt)>;
3159def : Pat<(i1 (setcc i32:$s1, i32:$s2, SETGT)),
3160          (EXTRACT_SUBREG (CMPW $s1, $s2), sub_gt)>;
3161def : Pat<(i1 (setcc i32:$s1, i32:$s2, SETEQ)),
3162          (EXTRACT_SUBREG (CMPW $s1, $s2), sub_eq)>;
3163
3164defm : CRNotPat<(i1 (setcc i32:$s1, i32:$s2, SETUGE)),
3165                (EXTRACT_SUBREG (CMPLW $s1, $s2), sub_lt)>;
3166defm : CRNotPat<(i1 (setcc i32:$s1, i32:$s2, SETGE)),
3167                (EXTRACT_SUBREG (CMPW $s1, $s2), sub_lt)>;
3168defm : CRNotPat<(i1 (setcc i32:$s1, i32:$s2, SETULE)),
3169                (EXTRACT_SUBREG (CMPLW $s1, $s2), sub_gt)>;
3170defm : CRNotPat<(i1 (setcc i32:$s1, i32:$s2, SETLE)),
3171                (EXTRACT_SUBREG (CMPW $s1, $s2), sub_gt)>;
3172defm : CRNotPat<(i1 (setcc i32:$s1, i32:$s2, SETNE)),
3173                (EXTRACT_SUBREG (CMPW $s1, $s2), sub_eq)>;
3174
3175// SETCC for i64.
3176def : Pat<(i1 (setcc i64:$s1, immZExt16:$imm, SETULT)),
3177          (EXTRACT_SUBREG (CMPLDI $s1, imm:$imm), sub_lt)>;
3178def : Pat<(i1 (setcc i64:$s1, imm64SExt16:$imm, SETLT)),
3179          (EXTRACT_SUBREG (CMPDI $s1, imm:$imm), sub_lt)>;
3180def : Pat<(i1 (setcc i64:$s1, immZExt16:$imm, SETUGT)),
3181          (EXTRACT_SUBREG (CMPLDI $s1, imm:$imm), sub_gt)>;
3182def : Pat<(i1 (setcc i64:$s1, imm64SExt16:$imm, SETGT)),
3183          (EXTRACT_SUBREG (CMPDI $s1, imm:$imm), sub_gt)>;
3184def : Pat<(i1 (setcc i64:$s1, imm64SExt16:$imm, SETEQ)),
3185          (EXTRACT_SUBREG (CMPDI $s1, imm:$imm), sub_eq)>;
3186def : Pat<(i1 (setcc i64:$s1, immZExt16:$imm, SETEQ)),
3187          (EXTRACT_SUBREG (CMPLDI $s1, imm:$imm), sub_eq)>;
3188
3189// For non-equality comparisons, the default code would materialize the
3190// constant, then compare against it, like this:
3191//   lis r2, 4660
3192//   ori r2, r2, 22136
3193//   cmpd cr0, r3, r2
3194//   beq cr0,L6
3195// Since we are just comparing for equality, we can emit this instead:
3196//   xoris r0,r3,0x1234
3197//   cmpldi cr0,r0,0x5678
3198//   beq cr0,L6
3199
3200def : Pat<(i1 (setcc i64:$s1, imm64ZExt32:$imm, SETEQ)),
3201          (EXTRACT_SUBREG (CMPLDI (XORIS8 $s1, (HI16 imm:$imm)),
3202                                  (LO16 imm:$imm)), sub_eq)>;
3203
3204defm : CRNotPat<(i1 (setcc i64:$s1, immZExt16:$imm, SETUGE)),
3205                (EXTRACT_SUBREG (CMPLDI $s1, imm:$imm), sub_lt)>;
3206defm : CRNotPat<(i1 (setcc i64:$s1, imm64SExt16:$imm, SETGE)),
3207                (EXTRACT_SUBREG (CMPDI $s1, imm:$imm), sub_lt)>;
3208defm : CRNotPat<(i1 (setcc i64:$s1, immZExt16:$imm, SETULE)),
3209                (EXTRACT_SUBREG (CMPLDI $s1, imm:$imm), sub_gt)>;
3210defm : CRNotPat<(i1 (setcc i64:$s1, imm64SExt16:$imm, SETLE)),
3211                (EXTRACT_SUBREG (CMPDI $s1, imm:$imm), sub_gt)>;
3212defm : CRNotPat<(i1 (setcc i64:$s1, imm64SExt16:$imm, SETNE)),
3213                (EXTRACT_SUBREG (CMPDI $s1, imm:$imm), sub_eq)>;
3214defm : CRNotPat<(i1 (setcc i64:$s1, immZExt16:$imm, SETNE)),
3215                (EXTRACT_SUBREG (CMPLDI $s1, imm:$imm), sub_eq)>;
3216
3217defm : CRNotPat<(i1 (setcc i64:$s1, imm64ZExt32:$imm, SETNE)),
3218                (EXTRACT_SUBREG (CMPLDI (XORIS8 $s1, (HI16 imm:$imm)),
3219                                        (LO16 imm:$imm)), sub_eq)>;
3220
3221def : Pat<(i1 (setcc i64:$s1, i64:$s2, SETULT)),
3222          (EXTRACT_SUBREG (CMPLD $s1, $s2), sub_lt)>;
3223def : Pat<(i1 (setcc i64:$s1, i64:$s2, SETLT)),
3224          (EXTRACT_SUBREG (CMPD $s1, $s2), sub_lt)>;
3225def : Pat<(i1 (setcc i64:$s1, i64:$s2, SETUGT)),
3226          (EXTRACT_SUBREG (CMPLD $s1, $s2), sub_gt)>;
3227def : Pat<(i1 (setcc i64:$s1, i64:$s2, SETGT)),
3228          (EXTRACT_SUBREG (CMPD $s1, $s2), sub_gt)>;
3229def : Pat<(i1 (setcc i64:$s1, i64:$s2, SETEQ)),
3230          (EXTRACT_SUBREG (CMPD $s1, $s2), sub_eq)>;
3231
3232defm : CRNotPat<(i1 (setcc i64:$s1, i64:$s2, SETUGE)),
3233                (EXTRACT_SUBREG (CMPLD $s1, $s2), sub_lt)>;
3234defm : CRNotPat<(i1 (setcc i64:$s1, i64:$s2, SETGE)),
3235                (EXTRACT_SUBREG (CMPD $s1, $s2), sub_lt)>;
3236defm : CRNotPat<(i1 (setcc i64:$s1, i64:$s2, SETULE)),
3237                (EXTRACT_SUBREG (CMPLD $s1, $s2), sub_gt)>;
3238defm : CRNotPat<(i1 (setcc i64:$s1, i64:$s2, SETLE)),
3239                (EXTRACT_SUBREG (CMPD $s1, $s2), sub_gt)>;
3240defm : CRNotPat<(i1 (setcc i64:$s1, i64:$s2, SETNE)),
3241                (EXTRACT_SUBREG (CMPD $s1, $s2), sub_eq)>;
3242
3243// SETCC for f32.
3244def : Pat<(i1 (setcc f32:$s1, f32:$s2, SETOLT)),
3245          (EXTRACT_SUBREG (FCMPUS $s1, $s2), sub_lt)>;
3246def : Pat<(i1 (setcc f32:$s1, f32:$s2, SETLT)),
3247          (EXTRACT_SUBREG (FCMPUS $s1, $s2), sub_lt)>;
3248def : Pat<(i1 (setcc f32:$s1, f32:$s2, SETOGT)),
3249          (EXTRACT_SUBREG (FCMPUS $s1, $s2), sub_gt)>;
3250def : Pat<(i1 (setcc f32:$s1, f32:$s2, SETGT)),
3251          (EXTRACT_SUBREG (FCMPUS $s1, $s2), sub_gt)>;
3252def : Pat<(i1 (setcc f32:$s1, f32:$s2, SETOEQ)),
3253          (EXTRACT_SUBREG (FCMPUS $s1, $s2), sub_eq)>;
3254def : Pat<(i1 (setcc f32:$s1, f32:$s2, SETEQ)),
3255          (EXTRACT_SUBREG (FCMPUS $s1, $s2), sub_eq)>;
3256def : Pat<(i1 (setcc f32:$s1, f32:$s2, SETUO)),
3257          (EXTRACT_SUBREG (FCMPUS $s1, $s2), sub_un)>;
3258
3259defm : CRNotPat<(i1 (setcc f32:$s1, f32:$s2, SETUGE)),
3260                (EXTRACT_SUBREG (FCMPUS $s1, $s2), sub_lt)>;
3261defm : CRNotPat<(i1 (setcc f32:$s1, f32:$s2, SETGE)),
3262                (EXTRACT_SUBREG (FCMPUS $s1, $s2), sub_lt)>;
3263defm : CRNotPat<(i1 (setcc f32:$s1, f32:$s2, SETULE)),
3264                (EXTRACT_SUBREG (FCMPUS $s1, $s2), sub_gt)>;
3265defm : CRNotPat<(i1 (setcc f32:$s1, f32:$s2, SETLE)),
3266                (EXTRACT_SUBREG (FCMPUS $s1, $s2), sub_gt)>;
3267defm : CRNotPat<(i1 (setcc f32:$s1, f32:$s2, SETUNE)),
3268                (EXTRACT_SUBREG (FCMPUS $s1, $s2), sub_eq)>;
3269defm : CRNotPat<(i1 (setcc f32:$s1, f32:$s2, SETNE)),
3270                (EXTRACT_SUBREG (FCMPUS $s1, $s2), sub_eq)>;
3271defm : CRNotPat<(i1 (setcc f32:$s1, f32:$s2, SETO)),
3272                (EXTRACT_SUBREG (FCMPUS $s1, $s2), sub_un)>;
3273
3274// SETCC for f64.
3275def : Pat<(i1 (setcc f64:$s1, f64:$s2, SETOLT)),
3276          (EXTRACT_SUBREG (FCMPUD $s1, $s2), sub_lt)>;
3277def : Pat<(i1 (setcc f64:$s1, f64:$s2, SETLT)),
3278          (EXTRACT_SUBREG (FCMPUD $s1, $s2), sub_lt)>;
3279def : Pat<(i1 (setcc f64:$s1, f64:$s2, SETOGT)),
3280          (EXTRACT_SUBREG (FCMPUD $s1, $s2), sub_gt)>;
3281def : Pat<(i1 (setcc f64:$s1, f64:$s2, SETGT)),
3282          (EXTRACT_SUBREG (FCMPUD $s1, $s2), sub_gt)>;
3283def : Pat<(i1 (setcc f64:$s1, f64:$s2, SETOEQ)),
3284          (EXTRACT_SUBREG (FCMPUD $s1, $s2), sub_eq)>;
3285def : Pat<(i1 (setcc f64:$s1, f64:$s2, SETEQ)),
3286          (EXTRACT_SUBREG (FCMPUD $s1, $s2), sub_eq)>;
3287def : Pat<(i1 (setcc f64:$s1, f64:$s2, SETUO)),
3288          (EXTRACT_SUBREG (FCMPUD $s1, $s2), sub_un)>;
3289
3290defm : CRNotPat<(i1 (setcc f64:$s1, f64:$s2, SETUGE)),
3291                (EXTRACT_SUBREG (FCMPUD $s1, $s2), sub_lt)>;
3292defm : CRNotPat<(i1 (setcc f64:$s1, f64:$s2, SETGE)),
3293                (EXTRACT_SUBREG (FCMPUD $s1, $s2), sub_lt)>;
3294defm : CRNotPat<(i1 (setcc f64:$s1, f64:$s2, SETULE)),
3295                (EXTRACT_SUBREG (FCMPUD $s1, $s2), sub_gt)>;
3296defm : CRNotPat<(i1 (setcc f64:$s1, f64:$s2, SETLE)),
3297                (EXTRACT_SUBREG (FCMPUD $s1, $s2), sub_gt)>;
3298defm : CRNotPat<(i1 (setcc f64:$s1, f64:$s2, SETUNE)),
3299                (EXTRACT_SUBREG (FCMPUD $s1, $s2), sub_eq)>;
3300defm : CRNotPat<(i1 (setcc f64:$s1, f64:$s2, SETNE)),
3301                (EXTRACT_SUBREG (FCMPUD $s1, $s2), sub_eq)>;
3302defm : CRNotPat<(i1 (setcc f64:$s1, f64:$s2, SETO)),
3303                (EXTRACT_SUBREG (FCMPUD $s1, $s2), sub_un)>;
3304
3305// match select on i1 variables:
3306def : Pat<(i1 (select i1:$cond, i1:$tval, i1:$fval)),
3307          (CROR (CRAND        $cond , $tval),
3308                (CRAND (crnot $cond), $fval))>;
3309
3310// match selectcc on i1 variables:
3311//   select (lhs == rhs), tval, fval is:
3312//   ((lhs == rhs) & tval) | (!(lhs == rhs) & fval)
3313def : Pat <(i1 (selectcc i1:$lhs, i1:$rhs, i1:$tval, i1:$fval, SETLT)),
3314           (CROR (CRAND (CRANDC $lhs, $rhs), $tval),
3315                 (CRAND (CRORC  $rhs, $lhs), $fval))>;
3316def : Pat <(i1 (selectcc i1:$lhs, i1:$rhs, i1:$tval, i1:$fval, SETULT)),
3317           (CROR (CRAND (CRANDC $rhs, $lhs), $tval),
3318                 (CRAND (CRORC  $lhs, $rhs), $fval))>;
3319def : Pat <(i1 (selectcc i1:$lhs, i1:$rhs, i1:$tval, i1:$fval, SETLE)),
3320           (CROR (CRAND (CRORC  $lhs, $rhs), $tval),
3321                 (CRAND (CRANDC $rhs, $lhs), $fval))>;
3322def : Pat <(i1 (selectcc i1:$lhs, i1:$rhs, i1:$tval, i1:$fval, SETULE)),
3323           (CROR (CRAND (CRORC  $rhs, $lhs), $tval),
3324                 (CRAND (CRANDC $lhs, $rhs), $fval))>;
3325def : Pat <(i1 (selectcc i1:$lhs, i1:$rhs, i1:$tval, i1:$fval, SETEQ)),
3326           (CROR (CRAND (CREQV $lhs, $rhs), $tval),
3327                 (CRAND (CRXOR $lhs, $rhs), $fval))>;
3328def : Pat <(i1 (selectcc i1:$lhs, i1:$rhs, i1:$tval, i1:$fval, SETGE)),
3329           (CROR (CRAND (CRORC  $rhs, $lhs), $tval),
3330                 (CRAND (CRANDC $lhs, $rhs), $fval))>;
3331def : Pat <(i1 (selectcc i1:$lhs, i1:$rhs, i1:$tval, i1:$fval, SETUGE)),
3332           (CROR (CRAND (CRORC  $lhs, $rhs), $tval),
3333                 (CRAND (CRANDC $rhs, $lhs), $fval))>;
3334def : Pat <(i1 (selectcc i1:$lhs, i1:$rhs, i1:$tval, i1:$fval, SETGT)),
3335           (CROR (CRAND (CRANDC $rhs, $lhs), $tval),
3336                 (CRAND (CRORC  $lhs, $rhs), $fval))>;
3337def : Pat <(i1 (selectcc i1:$lhs, i1:$rhs, i1:$tval, i1:$fval, SETUGT)),
3338           (CROR (CRAND (CRANDC $lhs, $rhs), $tval),
3339                 (CRAND (CRORC  $rhs, $lhs), $fval))>;
3340def : Pat <(i1 (selectcc i1:$lhs, i1:$rhs, i1:$tval, i1:$fval, SETNE)),
3341           (CROR (CRAND (CREQV $lhs, $rhs), $fval),
3342                 (CRAND (CRXOR $lhs, $rhs), $tval))>;
3343
3344// match selectcc on i1 variables with non-i1 output.
3345def : Pat<(i32 (selectcc i1:$lhs, i1:$rhs, i32:$tval, i32:$fval, SETLT)),
3346          (SELECT_I4 (CRANDC $lhs, $rhs), $tval, $fval)>;
3347def : Pat<(i32 (selectcc i1:$lhs, i1:$rhs, i32:$tval, i32:$fval, SETULT)),
3348          (SELECT_I4 (CRANDC $rhs, $lhs), $tval, $fval)>;
3349def : Pat<(i32 (selectcc i1:$lhs, i1:$rhs, i32:$tval, i32:$fval, SETLE)),
3350          (SELECT_I4 (CRORC  $lhs, $rhs), $tval, $fval)>;
3351def : Pat<(i32 (selectcc i1:$lhs, i1:$rhs, i32:$tval, i32:$fval, SETULE)),
3352          (SELECT_I4 (CRORC  $rhs, $lhs), $tval, $fval)>;
3353def : Pat<(i32 (selectcc i1:$lhs, i1:$rhs, i32:$tval, i32:$fval, SETEQ)),
3354          (SELECT_I4 (CREQV $lhs, $rhs), $tval, $fval)>;
3355def : Pat<(i32 (selectcc i1:$lhs, i1:$rhs, i32:$tval, i32:$fval, SETGE)),
3356          (SELECT_I4 (CRORC  $rhs, $lhs), $tval, $fval)>;
3357def : Pat<(i32 (selectcc i1:$lhs, i1:$rhs, i32:$tval, i32:$fval, SETUGE)),
3358          (SELECT_I4 (CRORC  $lhs, $rhs), $tval, $fval)>;
3359def : Pat<(i32 (selectcc i1:$lhs, i1:$rhs, i32:$tval, i32:$fval, SETGT)),
3360          (SELECT_I4 (CRANDC $rhs, $lhs), $tval, $fval)>;
3361def : Pat<(i32 (selectcc i1:$lhs, i1:$rhs, i32:$tval, i32:$fval, SETUGT)),
3362          (SELECT_I4 (CRANDC $lhs, $rhs), $tval, $fval)>;
3363def : Pat<(i32 (selectcc i1:$lhs, i1:$rhs, i32:$tval, i32:$fval, SETNE)),
3364          (SELECT_I4 (CRXOR $lhs, $rhs), $tval, $fval)>;
3365
3366def : Pat<(i64 (selectcc i1:$lhs, i1:$rhs, i64:$tval, i64:$fval, SETLT)),
3367          (SELECT_I8 (CRANDC $lhs, $rhs), $tval, $fval)>;
3368def : Pat<(i64 (selectcc i1:$lhs, i1:$rhs, i64:$tval, i64:$fval, SETULT)),
3369          (SELECT_I8 (CRANDC $rhs, $lhs), $tval, $fval)>;
3370def : Pat<(i64 (selectcc i1:$lhs, i1:$rhs, i64:$tval, i64:$fval, SETLE)),
3371          (SELECT_I8 (CRORC  $lhs, $rhs), $tval, $fval)>;
3372def : Pat<(i64 (selectcc i1:$lhs, i1:$rhs, i64:$tval, i64:$fval, SETULE)),
3373          (SELECT_I8 (CRORC  $rhs, $lhs), $tval, $fval)>;
3374def : Pat<(i64 (selectcc i1:$lhs, i1:$rhs, i64:$tval, i64:$fval, SETEQ)),
3375          (SELECT_I8 (CREQV $lhs, $rhs), $tval, $fval)>;
3376def : Pat<(i64 (selectcc i1:$lhs, i1:$rhs, i64:$tval, i64:$fval, SETGE)),
3377          (SELECT_I8 (CRORC  $rhs, $lhs), $tval, $fval)>;
3378def : Pat<(i64 (selectcc i1:$lhs, i1:$rhs, i64:$tval, i64:$fval, SETUGE)),
3379          (SELECT_I8 (CRORC  $lhs, $rhs), $tval, $fval)>;
3380def : Pat<(i64 (selectcc i1:$lhs, i1:$rhs, i64:$tval, i64:$fval, SETGT)),
3381          (SELECT_I8 (CRANDC $rhs, $lhs), $tval, $fval)>;
3382def : Pat<(i64 (selectcc i1:$lhs, i1:$rhs, i64:$tval, i64:$fval, SETUGT)),
3383          (SELECT_I8 (CRANDC $lhs, $rhs), $tval, $fval)>;
3384def : Pat<(i64 (selectcc i1:$lhs, i1:$rhs, i64:$tval, i64:$fval, SETNE)),
3385          (SELECT_I8 (CRXOR $lhs, $rhs), $tval, $fval)>;
3386
3387def : Pat<(f32 (selectcc i1:$lhs, i1:$rhs, f32:$tval, f32:$fval, SETLT)),
3388          (SELECT_F4 (CRANDC $lhs, $rhs), $tval, $fval)>;
3389def : Pat<(f32 (selectcc i1:$lhs, i1:$rhs, f32:$tval, f32:$fval, SETULT)),
3390          (SELECT_F4 (CRANDC $rhs, $lhs), $tval, $fval)>;
3391def : Pat<(f32 (selectcc i1:$lhs, i1:$rhs, f32:$tval, f32:$fval, SETLE)),
3392          (SELECT_F4 (CRORC  $lhs, $rhs), $tval, $fval)>;
3393def : Pat<(f32 (selectcc i1:$lhs, i1:$rhs, f32:$tval, f32:$fval, SETULE)),
3394          (SELECT_F4 (CRORC  $rhs, $lhs), $tval, $fval)>;
3395def : Pat<(f32 (selectcc i1:$lhs, i1:$rhs, f32:$tval, f32:$fval, SETEQ)),
3396          (SELECT_F4 (CREQV $lhs, $rhs), $tval, $fval)>;
3397def : Pat<(f32 (selectcc i1:$lhs, i1:$rhs, f32:$tval, f32:$fval, SETGE)),
3398          (SELECT_F4 (CRORC  $rhs, $lhs), $tval, $fval)>;
3399def : Pat<(f32 (selectcc i1:$lhs, i1:$rhs, f32:$tval, f32:$fval, SETUGE)),
3400          (SELECT_F4 (CRORC  $lhs, $rhs), $tval, $fval)>;
3401def : Pat<(f32 (selectcc i1:$lhs, i1:$rhs, f32:$tval, f32:$fval, SETGT)),
3402          (SELECT_F4 (CRANDC $rhs, $lhs), $tval, $fval)>;
3403def : Pat<(f32 (selectcc i1:$lhs, i1:$rhs, f32:$tval, f32:$fval, SETUGT)),
3404          (SELECT_F4 (CRANDC $lhs, $rhs), $tval, $fval)>;
3405def : Pat<(f32 (selectcc i1:$lhs, i1:$rhs, f32:$tval, f32:$fval, SETNE)),
3406          (SELECT_F4 (CRXOR $lhs, $rhs), $tval, $fval)>;
3407
3408def : Pat<(f64 (selectcc i1:$lhs, i1:$rhs, f64:$tval, f64:$fval, SETLT)),
3409          (SELECT_F8 (CRANDC $lhs, $rhs), $tval, $fval)>;
3410def : Pat<(f64 (selectcc i1:$lhs, i1:$rhs, f64:$tval, f64:$fval, SETULT)),
3411          (SELECT_F8 (CRANDC $rhs, $lhs), $tval, $fval)>;
3412def : Pat<(f64 (selectcc i1:$lhs, i1:$rhs, f64:$tval, f64:$fval, SETLE)),
3413          (SELECT_F8 (CRORC  $lhs, $rhs), $tval, $fval)>;
3414def : Pat<(f64 (selectcc i1:$lhs, i1:$rhs, f64:$tval, f64:$fval, SETULE)),
3415          (SELECT_F8 (CRORC  $rhs, $lhs), $tval, $fval)>;
3416def : Pat<(f64 (selectcc i1:$lhs, i1:$rhs, f64:$tval, f64:$fval, SETEQ)),
3417          (SELECT_F8 (CREQV $lhs, $rhs), $tval, $fval)>;
3418def : Pat<(f64 (selectcc i1:$lhs, i1:$rhs, f64:$tval, f64:$fval, SETGE)),
3419          (SELECT_F8 (CRORC  $rhs, $lhs), $tval, $fval)>;
3420def : Pat<(f64 (selectcc i1:$lhs, i1:$rhs, f64:$tval, f64:$fval, SETUGE)),
3421          (SELECT_F8 (CRORC  $lhs, $rhs), $tval, $fval)>;
3422def : Pat<(f64 (selectcc i1:$lhs, i1:$rhs, f64:$tval, f64:$fval, SETGT)),
3423          (SELECT_F8 (CRANDC $rhs, $lhs), $tval, $fval)>;
3424def : Pat<(f64 (selectcc i1:$lhs, i1:$rhs, f64:$tval, f64:$fval, SETUGT)),
3425          (SELECT_F8 (CRANDC $lhs, $rhs), $tval, $fval)>;
3426def : Pat<(f64 (selectcc i1:$lhs, i1:$rhs, f64:$tval, f64:$fval, SETNE)),
3427          (SELECT_F8 (CRXOR $lhs, $rhs), $tval, $fval)>;
3428
3429def : Pat<(v4i32 (selectcc i1:$lhs, i1:$rhs, v4i32:$tval, v4i32:$fval, SETLT)),
3430          (SELECT_VRRC (CRANDC $lhs, $rhs), $tval, $fval)>;
3431def : Pat<(v4i32 (selectcc i1:$lhs, i1:$rhs, v4i32:$tval, v4i32:$fval, SETULT)),
3432          (SELECT_VRRC (CRANDC $rhs, $lhs), $tval, $fval)>;
3433def : Pat<(v4i32 (selectcc i1:$lhs, i1:$rhs, v4i32:$tval, v4i32:$fval, SETLE)),
3434          (SELECT_VRRC (CRORC  $lhs, $rhs), $tval, $fval)>;
3435def : Pat<(v4i32 (selectcc i1:$lhs, i1:$rhs, v4i32:$tval, v4i32:$fval, SETULE)),
3436          (SELECT_VRRC (CRORC  $rhs, $lhs), $tval, $fval)>;
3437def : Pat<(v4i32 (selectcc i1:$lhs, i1:$rhs, v4i32:$tval, v4i32:$fval, SETEQ)),
3438          (SELECT_VRRC (CREQV $lhs, $rhs), $tval, $fval)>;
3439def : Pat<(v4i32 (selectcc i1:$lhs, i1:$rhs, v4i32:$tval, v4i32:$fval, SETGE)),
3440          (SELECT_VRRC (CRORC  $rhs, $lhs), $tval, $fval)>;
3441def : Pat<(v4i32 (selectcc i1:$lhs, i1:$rhs, v4i32:$tval, v4i32:$fval, SETUGE)),
3442          (SELECT_VRRC (CRORC  $lhs, $rhs), $tval, $fval)>;
3443def : Pat<(v4i32 (selectcc i1:$lhs, i1:$rhs, v4i32:$tval, v4i32:$fval, SETGT)),
3444          (SELECT_VRRC (CRANDC $rhs, $lhs), $tval, $fval)>;
3445def : Pat<(v4i32 (selectcc i1:$lhs, i1:$rhs, v4i32:$tval, v4i32:$fval, SETUGT)),
3446          (SELECT_VRRC (CRANDC $lhs, $rhs), $tval, $fval)>;
3447def : Pat<(v4i32 (selectcc i1:$lhs, i1:$rhs, v4i32:$tval, v4i32:$fval, SETNE)),
3448          (SELECT_VRRC (CRXOR $lhs, $rhs), $tval, $fval)>;
3449
3450let usesCustomInserter = 1 in {
3451def ANDIo_1_EQ_BIT : Pseudo<(outs crbitrc:$dst), (ins gprc:$in),
3452                             "#ANDIo_1_EQ_BIT",
3453                             [(set i1:$dst, (trunc (not i32:$in)))]>;
3454def ANDIo_1_GT_BIT : Pseudo<(outs crbitrc:$dst), (ins gprc:$in),
3455                             "#ANDIo_1_GT_BIT",
3456                             [(set i1:$dst, (trunc i32:$in))]>;
3457
3458def ANDIo_1_EQ_BIT8 : Pseudo<(outs crbitrc:$dst), (ins g8rc:$in),
3459                              "#ANDIo_1_EQ_BIT8",
3460                              [(set i1:$dst, (trunc (not i64:$in)))]>;
3461def ANDIo_1_GT_BIT8 : Pseudo<(outs crbitrc:$dst), (ins g8rc:$in),
3462                              "#ANDIo_1_GT_BIT8",
3463                              [(set i1:$dst, (trunc i64:$in))]>;
3464}
3465
3466def : Pat<(i1 (not (trunc i32:$in))),
3467           (ANDIo_1_EQ_BIT $in)>;
3468def : Pat<(i1 (not (trunc i64:$in))),
3469           (ANDIo_1_EQ_BIT8 $in)>;
3470
3471//===----------------------------------------------------------------------===//
3472// PowerPC Instructions used for assembler/disassembler only
3473//
3474
3475// FIXME: For B=0 or B > 8, the registers following RT are used.
3476// WARNING: Do not add patterns for this instruction without fixing this.
3477def LSWI  : XForm_base_r3xo<31, 597, (outs gprc:$RT), (ins gprc:$A, u5imm:$B),
3478                            "lswi $RT, $A, $B", IIC_LdStLoad, []>;
3479
3480// FIXME: For B=0 or B > 8, the registers following RT are used.
3481// WARNING: Do not add patterns for this instruction without fixing this.
3482def STSWI : XForm_base_r3xo<31, 725, (outs), (ins gprc:$RT, gprc:$A, u5imm:$B),
3483                            "stswi $RT, $A, $B", IIC_LdStLoad, []>;
3484
3485def ISYNC : XLForm_2_ext<19, 150, 0, 0, 0, (outs), (ins),
3486                         "isync", IIC_SprISYNC, []>;
3487
3488def ICBI : XForm_1a<31, 982, (outs), (ins memrr:$src),
3489                    "icbi $src", IIC_LdStICBI, []>;
3490
3491// We used to have EIEIO as value but E[0-9A-Z] is a reserved name
3492def EnforceIEIO : XForm_24_eieio<31, 854, (outs), (ins),
3493                           "eieio", IIC_LdStLoad, []>;
3494
3495def WAIT : XForm_24_sync<31, 62, (outs), (ins i32imm:$L),
3496                         "wait $L", IIC_LdStLoad, []>;
3497
3498def MBAR : XForm_mbar<31, 854, (outs), (ins u5imm:$MO),
3499                         "mbar $MO", IIC_LdStLoad>, Requires<[IsBookE]>;
3500
3501def MTSR: XForm_sr<31, 210, (outs), (ins gprc:$RS, u4imm:$SR),
3502            "mtsr $SR, $RS", IIC_SprMTSR>;
3503
3504def MFSR: XForm_sr<31, 595, (outs gprc:$RS), (ins u4imm:$SR),
3505            "mfsr $RS, $SR", IIC_SprMFSR>;
3506
3507def MTSRIN: XForm_srin<31, 242, (outs), (ins gprc:$RS, gprc:$RB),
3508            "mtsrin $RS, $RB", IIC_SprMTSR>;
3509
3510def MFSRIN: XForm_srin<31, 659, (outs gprc:$RS), (ins gprc:$RB),
3511            "mfsrin $RS, $RB", IIC_SprMFSR>;
3512
3513def MTMSR: XForm_mtmsr<31, 146, (outs), (ins gprc:$RS, i32imm:$L),
3514                    "mtmsr $RS, $L", IIC_SprMTMSR>;
3515
3516def WRTEE: XForm_mtmsr<31, 131, (outs), (ins gprc:$RS),
3517                    "wrtee $RS", IIC_SprMTMSR>, Requires<[IsBookE]> {
3518  let L = 0;
3519}
3520
3521def WRTEEI: I<31, (outs), (ins i1imm:$E), "wrteei $E", IIC_SprMTMSR>,
3522              Requires<[IsBookE]> {
3523  bits<1> E;
3524
3525  let Inst{16} = E;
3526  let Inst{21-30} = 163;
3527}
3528
3529def DCCCI : XForm_tlb<454, (outs), (ins gprc:$A, gprc:$B),
3530               "dccci $A, $B", IIC_LdStLoad>, Requires<[IsPPC4xx]>;
3531def ICCCI : XForm_tlb<966, (outs), (ins gprc:$A, gprc:$B),
3532               "iccci $A, $B", IIC_LdStLoad>, Requires<[IsPPC4xx]>;
3533
3534def : InstAlias<"dci 0", (DCCCI R0, R0)>, Requires<[IsPPC4xx]>;
3535def : InstAlias<"dccci", (DCCCI R0, R0)>, Requires<[IsPPC4xx]>;
3536def : InstAlias<"ici 0", (ICCCI R0, R0)>, Requires<[IsPPC4xx]>;
3537def : InstAlias<"iccci", (ICCCI R0, R0)>, Requires<[IsPPC4xx]>;
3538
3539def MFMSR : XForm_rs<31, 83, (outs gprc:$RT), (ins),
3540                  "mfmsr $RT", IIC_SprMFMSR, []>;
3541
3542def MTMSRD : XForm_mtmsr<31, 178, (outs), (ins gprc:$RS, i32imm:$L),
3543                    "mtmsrd $RS, $L", IIC_SprMTMSRD>;
3544
3545def MCRFS : XLForm_3<63, 64, (outs crrc:$BF), (ins crrc:$BFA),
3546                     "mcrfs $BF, $BFA", IIC_BrMCR>;
3547
3548def MTFSFI : XLForm_4<63, 134, (outs crrc:$BF), (ins i32imm:$U, i32imm:$W),
3549                      "mtfsfi $BF, $U, $W", IIC_IntMFFS>;
3550
3551def MTFSFIo : XLForm_4<63, 134, (outs crrc:$BF), (ins i32imm:$U, i32imm:$W),
3552                       "mtfsfi. $BF, $U, $W", IIC_IntMFFS>, isDOT;
3553
3554def : InstAlias<"mtfsfi $BF, $U", (MTFSFI crrc:$BF, i32imm:$U, 0)>;
3555def : InstAlias<"mtfsfi. $BF, $U", (MTFSFIo crrc:$BF, i32imm:$U, 0)>;
3556
3557def MTFSF : XFLForm_1<63, 711, (outs),
3558                      (ins i32imm:$FLM, f8rc:$FRB, i32imm:$L, i32imm:$W),
3559                      "mtfsf $FLM, $FRB, $L, $W", IIC_IntMFFS, []>;
3560def MTFSFo : XFLForm_1<63, 711, (outs),
3561                       (ins i32imm:$FLM, f8rc:$FRB, i32imm:$L, i32imm:$W),
3562                       "mtfsf. $FLM, $FRB, $L, $W", IIC_IntMFFS, []>, isDOT;
3563
3564def : InstAlias<"mtfsf $FLM, $FRB", (MTFSF i32imm:$FLM, f8rc:$FRB, 0, 0)>;
3565def : InstAlias<"mtfsf. $FLM, $FRB", (MTFSFo i32imm:$FLM, f8rc:$FRB, 0, 0)>;
3566
3567def SLBIE : XForm_16b<31, 434, (outs), (ins gprc:$RB),
3568                        "slbie $RB", IIC_SprSLBIE, []>;
3569
3570def SLBMTE : XForm_26<31, 402, (outs), (ins gprc:$RS, gprc:$RB),
3571                    "slbmte $RS, $RB", IIC_SprSLBMTE, []>;
3572
3573def SLBMFEE : XForm_26<31, 915, (outs gprc:$RT), (ins gprc:$RB),
3574                       "slbmfee $RT, $RB", IIC_SprSLBMFEE, []>;
3575
3576def SLBIA : XForm_0<31, 498, (outs), (ins), "slbia", IIC_SprSLBIA, []>;
3577
3578def TLBIA : XForm_0<31, 370, (outs), (ins),
3579                        "tlbia", IIC_SprTLBIA, []>;
3580
3581def TLBSYNC : XForm_0<31, 566, (outs), (ins),
3582                        "tlbsync", IIC_SprTLBSYNC, []>;
3583
3584def TLBIEL : XForm_16b<31, 274, (outs), (ins gprc:$RB),
3585                          "tlbiel $RB", IIC_SprTLBIEL, []>;
3586
3587def TLBLD : XForm_16b<31, 978, (outs), (ins gprc:$RB),
3588                          "tlbld $RB", IIC_LdStLoad, []>, Requires<[IsPPC6xx]>;
3589def TLBLI : XForm_16b<31, 1010, (outs), (ins gprc:$RB),
3590                          "tlbli $RB", IIC_LdStLoad, []>, Requires<[IsPPC6xx]>;
3591
3592def TLBIE : XForm_26<31, 306, (outs), (ins gprc:$RS, gprc:$RB),
3593                          "tlbie $RB,$RS", IIC_SprTLBIE, []>;
3594
3595def TLBSX : XForm_tlb<914, (outs), (ins gprc:$A, gprc:$B), "tlbsx $A, $B",
3596                IIC_LdStLoad>, Requires<[IsBookE]>;
3597
3598def TLBIVAX : XForm_tlb<786, (outs), (ins gprc:$A, gprc:$B), "tlbivax $A, $B",
3599                IIC_LdStLoad>, Requires<[IsBookE]>;
3600
3601def TLBRE : XForm_24_eieio<31, 946, (outs), (ins),
3602                           "tlbre", IIC_LdStLoad, []>, Requires<[IsBookE]>;
3603
3604def TLBWE : XForm_24_eieio<31, 978, (outs), (ins),
3605                           "tlbwe", IIC_LdStLoad, []>, Requires<[IsBookE]>;
3606
3607def TLBRE2 : XForm_tlbws<31, 946, (outs gprc:$RS), (ins gprc:$A, i1imm:$WS),
3608               "tlbre $RS, $A, $WS", IIC_LdStLoad, []>, Requires<[IsPPC4xx]>;
3609
3610def TLBWE2 : XForm_tlbws<31, 978, (outs), (ins gprc:$RS, gprc:$A, i1imm:$WS),
3611               "tlbwe $RS, $A, $WS", IIC_LdStLoad, []>, Requires<[IsPPC4xx]>;
3612
3613def TLBSX2 : XForm_base_r3xo<31, 914, (outs), (ins gprc:$RST, gprc:$A, gprc:$B),
3614                             "tlbsx $RST, $A, $B", IIC_LdStLoad, []>,
3615                             Requires<[IsPPC4xx]>;
3616def TLBSX2D : XForm_base_r3xo<31, 914, (outs),
3617                              (ins gprc:$RST, gprc:$A, gprc:$B),
3618                              "tlbsx. $RST, $A, $B", IIC_LdStLoad, []>,
3619                              Requires<[IsPPC4xx]>, isDOT;
3620
3621def RFID : XForm_0<19, 18, (outs), (ins), "rfid", IIC_IntRFID, []>;
3622
3623def RFI : XForm_0<19, 50, (outs), (ins), "rfi", IIC_SprRFI, []>,
3624                  Requires<[IsBookE]>;
3625def RFCI : XForm_0<19, 51, (outs), (ins), "rfci", IIC_BrB, []>,
3626                   Requires<[IsBookE]>;
3627
3628def RFDI : XForm_0<19, 39, (outs), (ins), "rfdi", IIC_BrB, []>,
3629                   Requires<[IsE500]>;
3630def RFMCI : XForm_0<19, 38, (outs), (ins), "rfmci", IIC_BrB, []>,
3631                    Requires<[IsE500]>;
3632
3633def MFDCR : XFXForm_1<31, 323, (outs gprc:$RT), (ins i32imm:$SPR),
3634                      "mfdcr $RT, $SPR", IIC_SprMFSPR>, Requires<[IsPPC4xx]>;
3635def MTDCR : XFXForm_1<31, 451, (outs), (ins gprc:$RT, i32imm:$SPR),
3636                      "mtdcr $SPR, $RT", IIC_SprMTSPR>, Requires<[IsPPC4xx]>;
3637
3638def ATTN : XForm_attn<0, 256, (outs), (ins), "attn", IIC_BrB>;
3639
3640def LBZCIX : XForm_base_r3xo<31, 853, (outs gprc:$RST), (ins gprc:$A, gprc:$B),
3641                             "lbzcix $RST, $A, $B", IIC_LdStLoad, []>;
3642def LHZCIX : XForm_base_r3xo<31, 821, (outs gprc:$RST), (ins gprc:$A, gprc:$B),
3643                             "lhzcix $RST, $A, $B", IIC_LdStLoad, []>;
3644def LWZCIX : XForm_base_r3xo<31, 789, (outs gprc:$RST), (ins gprc:$A, gprc:$B),
3645                             "lwzcix $RST, $A, $B", IIC_LdStLoad, []>;
3646def LDCIX :  XForm_base_r3xo<31, 885, (outs gprc:$RST), (ins gprc:$A, gprc:$B),
3647                             "ldcix $RST, $A, $B", IIC_LdStLoad, []>;
3648
3649def STBCIX : XForm_base_r3xo<31, 981, (outs), (ins gprc:$RST, gprc:$A, gprc:$B),
3650                             "stbcix $RST, $A, $B", IIC_LdStLoad, []>;
3651def STHCIX : XForm_base_r3xo<31, 949, (outs), (ins gprc:$RST, gprc:$A, gprc:$B),
3652                             "sthcix $RST, $A, $B", IIC_LdStLoad, []>;
3653def STWCIX : XForm_base_r3xo<31, 917, (outs), (ins gprc:$RST, gprc:$A, gprc:$B),
3654                             "stwcix $RST, $A, $B", IIC_LdStLoad, []>;
3655def STDCIX : XForm_base_r3xo<31, 1013, (outs), (ins gprc:$RST, gprc:$A, gprc:$B),
3656                             "stdcix $RST, $A, $B", IIC_LdStLoad, []>;
3657
3658//===----------------------------------------------------------------------===//
3659// PowerPC Assembler Instruction Aliases
3660//
3661
3662// Pseudo-instructions for alternate assembly syntax (never used by codegen).
3663// These are aliases that require C++ handling to convert to the target
3664// instruction, while InstAliases can be handled directly by tblgen.
3665class PPCAsmPseudo<string asm, dag iops>
3666  : Instruction {
3667  let Namespace = "PPC";
3668  bit PPC64 = 0;  // Default value, override with isPPC64
3669
3670  let OutOperandList = (outs);
3671  let InOperandList = iops;
3672  let Pattern = [];
3673  let AsmString = asm;
3674  let isAsmParserOnly = 1;
3675  let isPseudo = 1;
3676}
3677
3678def : InstAlias<"sc", (SC 0)>;
3679
3680def : InstAlias<"sync", (SYNC 0)>, Requires<[HasSYNC]>;
3681def : InstAlias<"msync", (SYNC 0), 0>, Requires<[HasSYNC]>;
3682def : InstAlias<"lwsync", (SYNC 1)>, Requires<[HasSYNC]>;
3683def : InstAlias<"ptesync", (SYNC 2)>, Requires<[HasSYNC]>;
3684
3685def : InstAlias<"wait", (WAIT 0)>;
3686def : InstAlias<"waitrsv", (WAIT 1)>;
3687def : InstAlias<"waitimpl", (WAIT 2)>;
3688
3689def : InstAlias<"mbar", (MBAR 0)>, Requires<[IsBookE]>;
3690
3691def DCBTx   : PPCAsmPseudo<"dcbt $dst", (ins memrr:$dst)>;
3692def DCBTSTx : PPCAsmPseudo<"dcbtst $dst", (ins memrr:$dst)>;
3693
3694def DCBTCT : PPCAsmPseudo<"dcbtct $dst, $TH", (ins memrr:$dst, u5imm:$TH)>;
3695def DCBTDS : PPCAsmPseudo<"dcbtds $dst, $TH", (ins memrr:$dst, u5imm:$TH)>;
3696def DCBTT  : PPCAsmPseudo<"dcbtt $dst", (ins memrr:$dst)>;
3697
3698def DCBTSTCT : PPCAsmPseudo<"dcbtstct $dst, $TH", (ins memrr:$dst, u5imm:$TH)>;
3699def DCBTSTDS : PPCAsmPseudo<"dcbtstds $dst, $TH", (ins memrr:$dst, u5imm:$TH)>;
3700def DCBTSTT  : PPCAsmPseudo<"dcbtstt $dst", (ins memrr:$dst)>;
3701
3702def : InstAlias<"crset $bx", (CREQV crbitrc:$bx, crbitrc:$bx, crbitrc:$bx)>;
3703def : InstAlias<"crclr $bx", (CRXOR crbitrc:$bx, crbitrc:$bx, crbitrc:$bx)>;
3704def : InstAlias<"crmove $bx, $by", (CROR crbitrc:$bx, crbitrc:$by, crbitrc:$by)>;
3705def : InstAlias<"crnot $bx, $by", (CRNOR crbitrc:$bx, crbitrc:$by, crbitrc:$by)>;
3706
3707def : InstAlias<"mtxer $Rx", (MTSPR 1, gprc:$Rx)>;
3708def : InstAlias<"mfxer $Rx", (MFSPR gprc:$Rx, 1)>;
3709
3710def : InstAlias<"mfrtcu $Rx", (MFSPR gprc:$Rx, 4)>;
3711def : InstAlias<"mfrtcl $Rx", (MFSPR gprc:$Rx, 5)>;
3712
3713def : InstAlias<"mtdscr $Rx", (MTSPR 17, gprc:$Rx)>;
3714def : InstAlias<"mfdscr $Rx", (MFSPR gprc:$Rx, 17)>;
3715
3716def : InstAlias<"mtdsisr $Rx", (MTSPR 18, gprc:$Rx)>;
3717def : InstAlias<"mfdsisr $Rx", (MFSPR gprc:$Rx, 18)>;
3718
3719def : InstAlias<"mtdar $Rx", (MTSPR 19, gprc:$Rx)>;
3720def : InstAlias<"mfdar $Rx", (MFSPR gprc:$Rx, 19)>;
3721
3722def : InstAlias<"mtdec $Rx", (MTSPR 22, gprc:$Rx)>;
3723def : InstAlias<"mfdec $Rx", (MFSPR gprc:$Rx, 22)>;
3724
3725def : InstAlias<"mtsdr1 $Rx", (MTSPR 25, gprc:$Rx)>;
3726def : InstAlias<"mfsdr1 $Rx", (MFSPR gprc:$Rx, 25)>;
3727
3728def : InstAlias<"mtsrr0 $Rx", (MTSPR 26, gprc:$Rx)>;
3729def : InstAlias<"mfsrr0 $Rx", (MFSPR gprc:$Rx, 26)>;
3730
3731def : InstAlias<"mtsrr1 $Rx", (MTSPR 27, gprc:$Rx)>;
3732def : InstAlias<"mfsrr1 $Rx", (MFSPR gprc:$Rx, 27)>;
3733
3734def : InstAlias<"mtsrr2 $Rx", (MTSPR 990, gprc:$Rx)>, Requires<[IsPPC4xx]>;
3735def : InstAlias<"mfsrr2 $Rx", (MFSPR gprc:$Rx, 990)>, Requires<[IsPPC4xx]>;
3736
3737def : InstAlias<"mtsrr3 $Rx", (MTSPR 991, gprc:$Rx)>, Requires<[IsPPC4xx]>;
3738def : InstAlias<"mfsrr3 $Rx", (MFSPR gprc:$Rx, 991)>, Requires<[IsPPC4xx]>;
3739
3740def : InstAlias<"mtcfar $Rx", (MTSPR 28, gprc:$Rx)>;
3741def : InstAlias<"mfcfar $Rx", (MFSPR gprc:$Rx, 28)>;
3742
3743def : InstAlias<"mtamr $Rx", (MTSPR 29, gprc:$Rx)>;
3744def : InstAlias<"mfamr $Rx", (MFSPR gprc:$Rx, 29)>;
3745
3746def : InstAlias<"mtpid $Rx", (MTSPR 48, gprc:$Rx)>, Requires<[IsBookE]>;
3747def : InstAlias<"mfpid $Rx", (MFSPR gprc:$Rx, 48)>, Requires<[IsBookE]>;
3748
3749def : InstAlias<"mftb $Rx", (MFTB gprc:$Rx, 268)>;
3750def : InstAlias<"mftbl $Rx", (MFTB gprc:$Rx, 268)>;
3751def : InstAlias<"mftbu $Rx", (MFTB gprc:$Rx, 269)>;
3752
3753def : InstAlias<"mttbl $Rx", (MTSPR 284, gprc:$Rx)>;
3754def : InstAlias<"mttbu $Rx", (MTSPR 285, gprc:$Rx)>;
3755
3756def : InstAlias<"mftblo $Rx", (MFSPR gprc:$Rx, 989)>, Requires<[IsPPC4xx]>;
3757def : InstAlias<"mttblo $Rx", (MTSPR 989, gprc:$Rx)>, Requires<[IsPPC4xx]>;
3758def : InstAlias<"mftbhi $Rx", (MFSPR gprc:$Rx, 988)>, Requires<[IsPPC4xx]>;
3759def : InstAlias<"mttbhi $Rx", (MTSPR 988, gprc:$Rx)>, Requires<[IsPPC4xx]>;
3760
3761def : InstAlias<"xnop", (XORI R0, R0, 0)>;
3762
3763def : InstAlias<"mr $rA, $rB", (OR8 g8rc:$rA, g8rc:$rB, g8rc:$rB)>;
3764def : InstAlias<"mr. $rA, $rB", (OR8o g8rc:$rA, g8rc:$rB, g8rc:$rB)>;
3765
3766def : InstAlias<"not $rA, $rB", (NOR8 g8rc:$rA, g8rc:$rB, g8rc:$rB)>;
3767def : InstAlias<"not. $rA, $rB", (NOR8o g8rc:$rA, g8rc:$rB, g8rc:$rB)>;
3768
3769def : InstAlias<"mtcr $rA", (MTCRF8 255, g8rc:$rA)>;
3770
3771foreach BATR = 0-3 in {
3772    def : InstAlias<"mtdbatu "#BATR#", $Rx",
3773                    (MTSPR !add(BATR, !add(BATR, 536)), gprc:$Rx)>,
3774                    Requires<[IsPPC6xx]>;
3775    def : InstAlias<"mfdbatu $Rx, "#BATR,
3776                    (MFSPR gprc:$Rx, !add(BATR, !add(BATR, 536)))>,
3777                    Requires<[IsPPC6xx]>;
3778    def : InstAlias<"mtdbatl "#BATR#", $Rx",
3779                    (MTSPR !add(BATR, !add(BATR, 537)), gprc:$Rx)>,
3780                    Requires<[IsPPC6xx]>;
3781    def : InstAlias<"mfdbatl $Rx, "#BATR,
3782                    (MFSPR gprc:$Rx, !add(BATR, !add(BATR, 537)))>,
3783                    Requires<[IsPPC6xx]>;
3784    def : InstAlias<"mtibatu "#BATR#", $Rx",
3785                    (MTSPR !add(BATR, !add(BATR, 528)), gprc:$Rx)>,
3786                    Requires<[IsPPC6xx]>;
3787    def : InstAlias<"mfibatu $Rx, "#BATR,
3788                    (MFSPR gprc:$Rx, !add(BATR, !add(BATR, 528)))>,
3789                    Requires<[IsPPC6xx]>;
3790    def : InstAlias<"mtibatl "#BATR#", $Rx",
3791                    (MTSPR !add(BATR, !add(BATR, 529)), gprc:$Rx)>,
3792                    Requires<[IsPPC6xx]>;
3793    def : InstAlias<"mfibatl $Rx, "#BATR,
3794                    (MFSPR gprc:$Rx, !add(BATR, !add(BATR, 529)))>,
3795                    Requires<[IsPPC6xx]>;
3796}
3797
3798foreach BR = 0-7 in {
3799    def : InstAlias<"mfbr"#BR#" $Rx",
3800                    (MFDCR gprc:$Rx, !add(BR, 0x80))>,
3801                    Requires<[IsPPC4xx]>;
3802    def : InstAlias<"mtbr"#BR#" $Rx",
3803                    (MTDCR gprc:$Rx, !add(BR, 0x80))>,
3804                    Requires<[IsPPC4xx]>;
3805}
3806
3807def : InstAlias<"mtdccr $Rx", (MTSPR 1018, gprc:$Rx)>, Requires<[IsPPC4xx]>;
3808def : InstAlias<"mfdccr $Rx", (MFSPR gprc:$Rx, 1018)>, Requires<[IsPPC4xx]>;
3809
3810def : InstAlias<"mticcr $Rx", (MTSPR 1019, gprc:$Rx)>, Requires<[IsPPC4xx]>;
3811def : InstAlias<"mficcr $Rx", (MFSPR gprc:$Rx, 1019)>, Requires<[IsPPC4xx]>;
3812
3813def : InstAlias<"mtdear $Rx", (MTSPR 981, gprc:$Rx)>, Requires<[IsPPC4xx]>;
3814def : InstAlias<"mfdear $Rx", (MFSPR gprc:$Rx, 981)>, Requires<[IsPPC4xx]>;
3815
3816def : InstAlias<"mtesr $Rx", (MTSPR 980, gprc:$Rx)>, Requires<[IsPPC4xx]>;
3817def : InstAlias<"mfesr $Rx", (MFSPR gprc:$Rx, 980)>, Requires<[IsPPC4xx]>;
3818
3819def : InstAlias<"mfspefscr $Rx", (MFSPR gprc:$Rx, 512)>;
3820def : InstAlias<"mtspefscr $Rx", (MTSPR 512, gprc:$Rx)>;
3821
3822def : InstAlias<"mttcr $Rx", (MTSPR 986, gprc:$Rx)>, Requires<[IsPPC4xx]>;
3823def : InstAlias<"mftcr $Rx", (MFSPR gprc:$Rx, 986)>, Requires<[IsPPC4xx]>;
3824
3825def LAx : PPCAsmPseudo<"la $rA, $addr", (ins gprc:$rA, memri:$addr)>;
3826
3827def SUBI : PPCAsmPseudo<"subi $rA, $rB, $imm",
3828                        (ins gprc:$rA, gprc:$rB, s16imm:$imm)>;
3829def SUBIS : PPCAsmPseudo<"subis $rA, $rB, $imm",
3830                         (ins gprc:$rA, gprc:$rB, s16imm:$imm)>;
3831def SUBIC : PPCAsmPseudo<"subic $rA, $rB, $imm",
3832                         (ins gprc:$rA, gprc:$rB, s16imm:$imm)>;
3833def SUBICo : PPCAsmPseudo<"subic. $rA, $rB, $imm",
3834                          (ins gprc:$rA, gprc:$rB, s16imm:$imm)>;
3835
3836def : InstAlias<"sub $rA, $rB, $rC", (SUBF8 g8rc:$rA, g8rc:$rC, g8rc:$rB)>;
3837def : InstAlias<"sub. $rA, $rB, $rC", (SUBF8o g8rc:$rA, g8rc:$rC, g8rc:$rB)>;
3838def : InstAlias<"subc $rA, $rB, $rC", (SUBFC8 g8rc:$rA, g8rc:$rC, g8rc:$rB)>;
3839def : InstAlias<"subc. $rA, $rB, $rC", (SUBFC8o g8rc:$rA, g8rc:$rC, g8rc:$rB)>;
3840
3841def : InstAlias<"mtmsrd $RS", (MTMSRD gprc:$RS, 0)>;
3842def : InstAlias<"mtmsr $RS", (MTMSR gprc:$RS, 0)>;
3843
3844def : InstAlias<"mfasr $RT", (MFSPR gprc:$RT, 280)>;
3845def : InstAlias<"mtasr $RT", (MTSPR 280, gprc:$RT)>;
3846
3847foreach SPRG = 0-3 in {
3848  def : InstAlias<"mfsprg $RT, "#SPRG, (MFSPR gprc:$RT, !add(SPRG, 272))>;
3849  def : InstAlias<"mfsprg"#SPRG#" $RT", (MFSPR gprc:$RT, !add(SPRG, 272))>;
3850  def : InstAlias<"mtsprg "#SPRG#", $RT", (MTSPR !add(SPRG, 272), gprc:$RT)>;
3851  def : InstAlias<"mtsprg"#SPRG#" $RT", (MTSPR !add(SPRG, 272), gprc:$RT)>;
3852}
3853foreach SPRG = 4-7 in {
3854  def : InstAlias<"mfsprg $RT, "#SPRG, (MFSPR gprc:$RT, !add(SPRG, 256))>,
3855                  Requires<[IsBookE]>;
3856  def : InstAlias<"mfsprg"#SPRG#" $RT", (MFSPR gprc:$RT, !add(SPRG, 256))>,
3857                  Requires<[IsBookE]>;
3858  def : InstAlias<"mtsprg "#SPRG#", $RT", (MTSPR !add(SPRG, 256), gprc:$RT)>,
3859                  Requires<[IsBookE]>;
3860  def : InstAlias<"mtsprg"#SPRG#" $RT", (MTSPR !add(SPRG, 256), gprc:$RT)>,
3861                  Requires<[IsBookE]>;
3862}
3863
3864def : InstAlias<"mtasr $RS", (MTSPR 280, gprc:$RS)>;
3865
3866def : InstAlias<"mfdec $RT", (MFSPR gprc:$RT, 22)>;
3867def : InstAlias<"mtdec $RT", (MTSPR 22, gprc:$RT)>;
3868
3869def : InstAlias<"mfpvr $RT", (MFSPR gprc:$RT, 287)>;
3870
3871def : InstAlias<"mfsdr1 $RT", (MFSPR gprc:$RT, 25)>;
3872def : InstAlias<"mtsdr1 $RT", (MTSPR 25, gprc:$RT)>;
3873
3874def : InstAlias<"mfsrr0 $RT", (MFSPR gprc:$RT, 26)>;
3875def : InstAlias<"mfsrr1 $RT", (MFSPR gprc:$RT, 27)>;
3876def : InstAlias<"mtsrr0 $RT", (MTSPR 26, gprc:$RT)>;
3877def : InstAlias<"mtsrr1 $RT", (MTSPR 27, gprc:$RT)>;
3878
3879def : InstAlias<"tlbie $RB", (TLBIE R0, gprc:$RB)>;
3880
3881def : InstAlias<"tlbrehi $RS, $A", (TLBRE2 gprc:$RS, gprc:$A, 0)>,
3882                Requires<[IsPPC4xx]>;
3883def : InstAlias<"tlbrelo $RS, $A", (TLBRE2 gprc:$RS, gprc:$A, 1)>,
3884                Requires<[IsPPC4xx]>;
3885def : InstAlias<"tlbwehi $RS, $A", (TLBWE2 gprc:$RS, gprc:$A, 0)>,
3886                Requires<[IsPPC4xx]>;
3887def : InstAlias<"tlbwelo $RS, $A", (TLBWE2 gprc:$RS, gprc:$A, 1)>,
3888                Requires<[IsPPC4xx]>;
3889
3890def EXTLWI : PPCAsmPseudo<"extlwi $rA, $rS, $n, $b",
3891                          (ins gprc:$rA, gprc:$rS, u5imm:$n, u5imm:$b)>;
3892def EXTLWIo : PPCAsmPseudo<"extlwi. $rA, $rS, $n, $b",
3893                           (ins gprc:$rA, gprc:$rS, u5imm:$n, u5imm:$b)>;
3894def EXTRWI : PPCAsmPseudo<"extrwi $rA, $rS, $n, $b",
3895                          (ins gprc:$rA, gprc:$rS, u5imm:$n, u5imm:$b)>;
3896def EXTRWIo : PPCAsmPseudo<"extrwi. $rA, $rS, $n, $b",
3897                           (ins gprc:$rA, gprc:$rS, u5imm:$n, u5imm:$b)>;
3898def INSLWI : PPCAsmPseudo<"inslwi $rA, $rS, $n, $b",
3899                          (ins gprc:$rA, gprc:$rS, u5imm:$n, u5imm:$b)>;
3900def INSLWIo : PPCAsmPseudo<"inslwi. $rA, $rS, $n, $b",
3901                           (ins gprc:$rA, gprc:$rS, u5imm:$n, u5imm:$b)>;
3902def INSRWI : PPCAsmPseudo<"insrwi $rA, $rS, $n, $b",
3903                          (ins gprc:$rA, gprc:$rS, u5imm:$n, u5imm:$b)>;
3904def INSRWIo : PPCAsmPseudo<"insrwi. $rA, $rS, $n, $b",
3905                           (ins gprc:$rA, gprc:$rS, u5imm:$n, u5imm:$b)>;
3906def ROTRWI : PPCAsmPseudo<"rotrwi $rA, $rS, $n",
3907                          (ins gprc:$rA, gprc:$rS, u5imm:$n)>;
3908def ROTRWIo : PPCAsmPseudo<"rotrwi. $rA, $rS, $n",
3909                           (ins gprc:$rA, gprc:$rS, u5imm:$n)>;
3910def SLWI : PPCAsmPseudo<"slwi $rA, $rS, $n",
3911                        (ins gprc:$rA, gprc:$rS, u5imm:$n)>;
3912def SLWIo : PPCAsmPseudo<"slwi. $rA, $rS, $n",
3913                         (ins gprc:$rA, gprc:$rS, u5imm:$n)>;
3914def SRWI : PPCAsmPseudo<"srwi $rA, $rS, $n",
3915                        (ins gprc:$rA, gprc:$rS, u5imm:$n)>;
3916def SRWIo : PPCAsmPseudo<"srwi. $rA, $rS, $n",
3917                         (ins gprc:$rA, gprc:$rS, u5imm:$n)>;
3918def CLRRWI : PPCAsmPseudo<"clrrwi $rA, $rS, $n",
3919                          (ins gprc:$rA, gprc:$rS, u5imm:$n)>;
3920def CLRRWIo : PPCAsmPseudo<"clrrwi. $rA, $rS, $n",
3921                           (ins gprc:$rA, gprc:$rS, u5imm:$n)>;
3922def CLRLSLWI : PPCAsmPseudo<"clrlslwi $rA, $rS, $b, $n",
3923                            (ins gprc:$rA, gprc:$rS, u5imm:$b, u5imm:$n)>;
3924def CLRLSLWIo : PPCAsmPseudo<"clrlslwi. $rA, $rS, $b, $n",
3925                             (ins gprc:$rA, gprc:$rS, u5imm:$b, u5imm:$n)>;
3926
3927def : InstAlias<"rotlwi $rA, $rS, $n", (RLWINM gprc:$rA, gprc:$rS, u5imm:$n, 0, 31)>;
3928def : InstAlias<"rotlwi. $rA, $rS, $n", (RLWINMo gprc:$rA, gprc:$rS, u5imm:$n, 0, 31)>;
3929def : InstAlias<"rotlw $rA, $rS, $rB", (RLWNM gprc:$rA, gprc:$rS, gprc:$rB, 0, 31)>;
3930def : InstAlias<"rotlw. $rA, $rS, $rB", (RLWNMo gprc:$rA, gprc:$rS, gprc:$rB, 0, 31)>;
3931def : InstAlias<"clrlwi $rA, $rS, $n", (RLWINM gprc:$rA, gprc:$rS, 0, u5imm:$n, 31)>;
3932def : InstAlias<"clrlwi. $rA, $rS, $n", (RLWINMo gprc:$rA, gprc:$rS, 0, u5imm:$n, 31)>;
3933
3934def : InstAlias<"cntlzw $rA, $rS", (CNTLZW gprc:$rA, gprc:$rS)>;
3935def : InstAlias<"cntlzw. $rA, $rS", (CNTLZWo gprc:$rA, gprc:$rS)>;
3936// The POWER variant
3937def : MnemonicAlias<"cntlz",  "cntlzw">;
3938def : MnemonicAlias<"cntlz.", "cntlzw.">;
3939
3940def EXTLDI : PPCAsmPseudo<"extldi $rA, $rS, $n, $b",
3941                          (ins g8rc:$rA, g8rc:$rS, u6imm:$n, u6imm:$b)>;
3942def EXTLDIo : PPCAsmPseudo<"extldi. $rA, $rS, $n, $b",
3943                           (ins g8rc:$rA, g8rc:$rS, u6imm:$n, u6imm:$b)>;
3944def EXTRDI : PPCAsmPseudo<"extrdi $rA, $rS, $n, $b",
3945                          (ins g8rc:$rA, g8rc:$rS, u6imm:$n, u6imm:$b)>;
3946def EXTRDIo : PPCAsmPseudo<"extrdi. $rA, $rS, $n, $b",
3947                           (ins g8rc:$rA, g8rc:$rS, u6imm:$n, u6imm:$b)>;
3948def INSRDI : PPCAsmPseudo<"insrdi $rA, $rS, $n, $b",
3949                          (ins g8rc:$rA, g8rc:$rS, u6imm:$n, u6imm:$b)>;
3950def INSRDIo : PPCAsmPseudo<"insrdi. $rA, $rS, $n, $b",
3951                           (ins g8rc:$rA, g8rc:$rS, u6imm:$n, u6imm:$b)>;
3952def ROTRDI : PPCAsmPseudo<"rotrdi $rA, $rS, $n",
3953                          (ins g8rc:$rA, g8rc:$rS, u6imm:$n)>;
3954def ROTRDIo : PPCAsmPseudo<"rotrdi. $rA, $rS, $n",
3955                           (ins g8rc:$rA, g8rc:$rS, u6imm:$n)>;
3956def SLDI : PPCAsmPseudo<"sldi $rA, $rS, $n",
3957                        (ins g8rc:$rA, g8rc:$rS, u6imm:$n)>;
3958def SLDIo : PPCAsmPseudo<"sldi. $rA, $rS, $n",
3959                         (ins g8rc:$rA, g8rc:$rS, u6imm:$n)>;
3960def SRDI : PPCAsmPseudo<"srdi $rA, $rS, $n",
3961                        (ins g8rc:$rA, g8rc:$rS, u6imm:$n)>;
3962def SRDIo : PPCAsmPseudo<"srdi. $rA, $rS, $n",
3963                         (ins g8rc:$rA, g8rc:$rS, u6imm:$n)>;
3964def CLRRDI : PPCAsmPseudo<"clrrdi $rA, $rS, $n",
3965                          (ins g8rc:$rA, g8rc:$rS, u6imm:$n)>;
3966def CLRRDIo : PPCAsmPseudo<"clrrdi. $rA, $rS, $n",
3967                           (ins g8rc:$rA, g8rc:$rS, u6imm:$n)>;
3968def CLRLSLDI : PPCAsmPseudo<"clrlsldi $rA, $rS, $b, $n",
3969                            (ins g8rc:$rA, g8rc:$rS, u6imm:$b, u6imm:$n)>;
3970def CLRLSLDIo : PPCAsmPseudo<"clrlsldi. $rA, $rS, $b, $n",
3971                             (ins g8rc:$rA, g8rc:$rS, u6imm:$b, u6imm:$n)>;
3972
3973def : InstAlias<"rotldi $rA, $rS, $n", (RLDICL g8rc:$rA, g8rc:$rS, u6imm:$n, 0)>;
3974def : InstAlias<"rotldi. $rA, $rS, $n", (RLDICLo g8rc:$rA, g8rc:$rS, u6imm:$n, 0)>;
3975def : InstAlias<"rotld $rA, $rS, $rB", (RLDCL g8rc:$rA, g8rc:$rS, gprc:$rB, 0)>;
3976def : InstAlias<"rotld. $rA, $rS, $rB", (RLDCLo g8rc:$rA, g8rc:$rS, gprc:$rB, 0)>;
3977def : InstAlias<"clrldi $rA, $rS, $n", (RLDICL g8rc:$rA, g8rc:$rS, 0, u6imm:$n)>;
3978def : InstAlias<"clrldi. $rA, $rS, $n", (RLDICLo g8rc:$rA, g8rc:$rS, 0, u6imm:$n)>;
3979
3980def RLWINMbm : PPCAsmPseudo<"rlwinm $rA, $rS, $n, $b",
3981                            (ins g8rc:$rA, g8rc:$rS, u5imm:$n, i32imm:$b)>;
3982def RLWINMobm : PPCAsmPseudo<"rlwinm. $rA, $rS, $n, $b",
3983                            (ins g8rc:$rA, g8rc:$rS, u5imm:$n, i32imm:$b)>;
3984def RLWIMIbm : PPCAsmPseudo<"rlwimi $rA, $rS, $n, $b",
3985                           (ins g8rc:$rA, g8rc:$rS, u5imm:$n, i32imm:$b)>;
3986def RLWIMIobm : PPCAsmPseudo<"rlwimi. $rA, $rS, $n, $b",
3987                            (ins g8rc:$rA, g8rc:$rS, u5imm:$n, i32imm:$b)>;
3988def RLWNMbm : PPCAsmPseudo<"rlwnm $rA, $rS, $n, $b",
3989                          (ins g8rc:$rA, g8rc:$rS, u5imm:$n, i32imm:$b)>;
3990def RLWNMobm : PPCAsmPseudo<"rlwnm. $rA, $rS, $n, $b",
3991                           (ins g8rc:$rA, g8rc:$rS, u5imm:$n, i32imm:$b)>;
3992
3993// These generic branch instruction forms are used for the assembler parser only.
3994// Defs and Uses are conservative, since we don't know the BO value.
3995let PPC970_Unit = 7 in {
3996  let Defs = [CTR], Uses = [CTR, RM] in {
3997    def gBC : BForm_3<16, 0, 0, (outs),
3998                      (ins u5imm:$bo, crbitrc:$bi, condbrtarget:$dst),
3999                      "bc $bo, $bi, $dst">;
4000    def gBCA : BForm_3<16, 1, 0, (outs),
4001                       (ins u5imm:$bo, crbitrc:$bi, abscondbrtarget:$dst),
4002                       "bca $bo, $bi, $dst">;
4003  }
4004  let Defs = [LR, CTR], Uses = [CTR, RM] in {
4005    def gBCL : BForm_3<16, 0, 1, (outs),
4006                       (ins u5imm:$bo, crbitrc:$bi, condbrtarget:$dst),
4007                       "bcl $bo, $bi, $dst">;
4008    def gBCLA : BForm_3<16, 1, 1, (outs),
4009                        (ins u5imm:$bo, crbitrc:$bi, abscondbrtarget:$dst),
4010                        "bcla $bo, $bi, $dst">;
4011  }
4012  let Defs = [CTR], Uses = [CTR, LR, RM] in
4013    def gBCLR : XLForm_2<19, 16, 0, (outs),
4014                         (ins u5imm:$bo, crbitrc:$bi, i32imm:$bh),
4015                         "bclr $bo, $bi, $bh", IIC_BrB, []>;
4016  let Defs = [LR, CTR], Uses = [CTR, LR, RM] in
4017    def gBCLRL : XLForm_2<19, 16, 1, (outs),
4018                          (ins u5imm:$bo, crbitrc:$bi, i32imm:$bh),
4019                          "bclrl $bo, $bi, $bh", IIC_BrB, []>;
4020  let Defs = [CTR], Uses = [CTR, LR, RM] in
4021    def gBCCTR : XLForm_2<19, 528, 0, (outs),
4022                          (ins u5imm:$bo, crbitrc:$bi, i32imm:$bh),
4023                          "bcctr $bo, $bi, $bh", IIC_BrB, []>;
4024  let Defs = [LR, CTR], Uses = [CTR, LR, RM] in
4025    def gBCCTRL : XLForm_2<19, 528, 1, (outs),
4026                           (ins u5imm:$bo, crbitrc:$bi, i32imm:$bh),
4027                           "bcctrl $bo, $bi, $bh", IIC_BrB, []>;
4028}
4029def : InstAlias<"bclr $bo, $bi", (gBCLR u5imm:$bo, crbitrc:$bi, 0)>;
4030def : InstAlias<"bclrl $bo, $bi", (gBCLRL u5imm:$bo, crbitrc:$bi, 0)>;
4031def : InstAlias<"bcctr $bo, $bi", (gBCCTR u5imm:$bo, crbitrc:$bi, 0)>;
4032def : InstAlias<"bcctrl $bo, $bi", (gBCCTRL u5imm:$bo, crbitrc:$bi, 0)>;
4033
4034multiclass BranchSimpleMnemonic1<string name, string pm, int bo> {
4035  def : InstAlias<"b"#name#pm#" $bi, $dst", (gBC bo, crbitrc:$bi, condbrtarget:$dst)>;
4036  def : InstAlias<"b"#name#"a"#pm#" $bi, $dst", (gBCA bo, crbitrc:$bi, abscondbrtarget:$dst)>;
4037  def : InstAlias<"b"#name#"lr"#pm#" $bi", (gBCLR bo, crbitrc:$bi, 0)>;
4038  def : InstAlias<"b"#name#"l"#pm#" $bi, $dst", (gBCL bo, crbitrc:$bi, condbrtarget:$dst)>;
4039  def : InstAlias<"b"#name#"la"#pm#" $bi, $dst", (gBCLA bo, crbitrc:$bi, abscondbrtarget:$dst)>;
4040  def : InstAlias<"b"#name#"lrl"#pm#" $bi", (gBCLRL bo, crbitrc:$bi, 0)>;
4041}
4042multiclass BranchSimpleMnemonic2<string name, string pm, int bo>
4043  : BranchSimpleMnemonic1<name, pm, bo> {
4044  def : InstAlias<"b"#name#"ctr"#pm#" $bi", (gBCCTR bo, crbitrc:$bi, 0)>;
4045  def : InstAlias<"b"#name#"ctrl"#pm#" $bi", (gBCCTRL bo, crbitrc:$bi, 0)>;
4046}
4047defm : BranchSimpleMnemonic2<"t", "", 12>;
4048defm : BranchSimpleMnemonic2<"f", "", 4>;
4049defm : BranchSimpleMnemonic2<"t", "-", 14>;
4050defm : BranchSimpleMnemonic2<"f", "-", 6>;
4051defm : BranchSimpleMnemonic2<"t", "+", 15>;
4052defm : BranchSimpleMnemonic2<"f", "+", 7>;
4053defm : BranchSimpleMnemonic1<"dnzt", "", 8>;
4054defm : BranchSimpleMnemonic1<"dnzf", "", 0>;
4055defm : BranchSimpleMnemonic1<"dzt", "", 10>;
4056defm : BranchSimpleMnemonic1<"dzf", "", 2>;
4057
4058multiclass BranchExtendedMnemonicPM<string name, string pm, int bibo> {
4059  def : InstAlias<"b"#name#pm#" $cc, $dst",
4060                  (BCC bibo, crrc:$cc, condbrtarget:$dst)>;
4061  def : InstAlias<"b"#name#pm#" $dst",
4062                  (BCC bibo, CR0, condbrtarget:$dst)>;
4063
4064  def : InstAlias<"b"#name#"a"#pm#" $cc, $dst",
4065                  (BCCA bibo, crrc:$cc, abscondbrtarget:$dst)>;
4066  def : InstAlias<"b"#name#"a"#pm#" $dst",
4067                  (BCCA bibo, CR0, abscondbrtarget:$dst)>;
4068
4069  def : InstAlias<"b"#name#"lr"#pm#" $cc",
4070                  (BCCLR bibo, crrc:$cc)>;
4071  def : InstAlias<"b"#name#"lr"#pm,
4072                  (BCCLR bibo, CR0)>;
4073
4074  def : InstAlias<"b"#name#"ctr"#pm#" $cc",
4075                  (BCCCTR bibo, crrc:$cc)>;
4076  def : InstAlias<"b"#name#"ctr"#pm,
4077                  (BCCCTR bibo, CR0)>;
4078
4079  def : InstAlias<"b"#name#"l"#pm#" $cc, $dst",
4080                  (BCCL bibo, crrc:$cc, condbrtarget:$dst)>;
4081  def : InstAlias<"b"#name#"l"#pm#" $dst",
4082                  (BCCL bibo, CR0, condbrtarget:$dst)>;
4083
4084  def : InstAlias<"b"#name#"la"#pm#" $cc, $dst",
4085                  (BCCLA bibo, crrc:$cc, abscondbrtarget:$dst)>;
4086  def : InstAlias<"b"#name#"la"#pm#" $dst",
4087                  (BCCLA bibo, CR0, abscondbrtarget:$dst)>;
4088
4089  def : InstAlias<"b"#name#"lrl"#pm#" $cc",
4090                  (BCCLRL bibo, crrc:$cc)>;
4091  def : InstAlias<"b"#name#"lrl"#pm,
4092                  (BCCLRL bibo, CR0)>;
4093
4094  def : InstAlias<"b"#name#"ctrl"#pm#" $cc",
4095                  (BCCCTRL bibo, crrc:$cc)>;
4096  def : InstAlias<"b"#name#"ctrl"#pm,
4097                  (BCCCTRL bibo, CR0)>;
4098}
4099multiclass BranchExtendedMnemonic<string name, int bibo> {
4100  defm : BranchExtendedMnemonicPM<name, "", bibo>;
4101  defm : BranchExtendedMnemonicPM<name, "-", !add(bibo, 2)>;
4102  defm : BranchExtendedMnemonicPM<name, "+", !add(bibo, 3)>;
4103}
4104defm : BranchExtendedMnemonic<"lt", 12>;
4105defm : BranchExtendedMnemonic<"gt", 44>;
4106defm : BranchExtendedMnemonic<"eq", 76>;
4107defm : BranchExtendedMnemonic<"un", 108>;
4108defm : BranchExtendedMnemonic<"so", 108>;
4109defm : BranchExtendedMnemonic<"ge", 4>;
4110defm : BranchExtendedMnemonic<"nl", 4>;
4111defm : BranchExtendedMnemonic<"le", 36>;
4112defm : BranchExtendedMnemonic<"ng", 36>;
4113defm : BranchExtendedMnemonic<"ne", 68>;
4114defm : BranchExtendedMnemonic<"nu", 100>;
4115defm : BranchExtendedMnemonic<"ns", 100>;
4116
4117def : InstAlias<"cmpwi $rA, $imm", (CMPWI CR0, gprc:$rA, s16imm:$imm)>;
4118def : InstAlias<"cmpw $rA, $rB", (CMPW CR0, gprc:$rA, gprc:$rB)>;
4119def : InstAlias<"cmplwi $rA, $imm", (CMPLWI CR0, gprc:$rA, u16imm:$imm)>;
4120def : InstAlias<"cmplw $rA, $rB", (CMPLW CR0, gprc:$rA, gprc:$rB)>;
4121def : InstAlias<"cmpdi $rA, $imm", (CMPDI CR0, g8rc:$rA, s16imm64:$imm)>;
4122def : InstAlias<"cmpd $rA, $rB", (CMPD CR0, g8rc:$rA, g8rc:$rB)>;
4123def : InstAlias<"cmpldi $rA, $imm", (CMPLDI CR0, g8rc:$rA, u16imm64:$imm)>;
4124def : InstAlias<"cmpld $rA, $rB", (CMPLD CR0, g8rc:$rA, g8rc:$rB)>;
4125
4126def : InstAlias<"cmpi $bf, 0, $rA, $imm", (CMPWI crrc:$bf, gprc:$rA, s16imm:$imm)>;
4127def : InstAlias<"cmp $bf, 0, $rA, $rB", (CMPW crrc:$bf, gprc:$rA, gprc:$rB)>;
4128def : InstAlias<"cmpli $bf, 0, $rA, $imm", (CMPLWI crrc:$bf, gprc:$rA, u16imm:$imm)>;
4129def : InstAlias<"cmpl $bf, 0, $rA, $rB", (CMPLW crrc:$bf, gprc:$rA, gprc:$rB)>;
4130def : InstAlias<"cmpi $bf, 1, $rA, $imm", (CMPDI crrc:$bf, g8rc:$rA, s16imm64:$imm)>;
4131def : InstAlias<"cmp $bf, 1, $rA, $rB", (CMPD crrc:$bf, g8rc:$rA, g8rc:$rB)>;
4132def : InstAlias<"cmpli $bf, 1, $rA, $imm", (CMPLDI crrc:$bf, g8rc:$rA, u16imm64:$imm)>;
4133def : InstAlias<"cmpl $bf, 1, $rA, $rB", (CMPLD crrc:$bf, g8rc:$rA, g8rc:$rB)>;
4134
4135multiclass TrapExtendedMnemonic<string name, int to> {
4136  def : InstAlias<"td"#name#"i $rA, $imm", (TDI to, g8rc:$rA, s16imm:$imm)>;
4137  def : InstAlias<"td"#name#" $rA, $rB", (TD to, g8rc:$rA, g8rc:$rB)>;
4138  def : InstAlias<"tw"#name#"i $rA, $imm", (TWI to, gprc:$rA, s16imm:$imm)>;
4139  def : InstAlias<"tw"#name#" $rA, $rB", (TW to, gprc:$rA, gprc:$rB)>;
4140}
4141defm : TrapExtendedMnemonic<"lt", 16>;
4142defm : TrapExtendedMnemonic<"le", 20>;
4143defm : TrapExtendedMnemonic<"eq", 4>;
4144defm : TrapExtendedMnemonic<"ge", 12>;
4145defm : TrapExtendedMnemonic<"gt", 8>;
4146defm : TrapExtendedMnemonic<"nl", 12>;
4147defm : TrapExtendedMnemonic<"ne", 24>;
4148defm : TrapExtendedMnemonic<"ng", 20>;
4149defm : TrapExtendedMnemonic<"llt", 2>;
4150defm : TrapExtendedMnemonic<"lle", 6>;
4151defm : TrapExtendedMnemonic<"lge", 5>;
4152defm : TrapExtendedMnemonic<"lgt", 1>;
4153defm : TrapExtendedMnemonic<"lnl", 5>;
4154defm : TrapExtendedMnemonic<"lng", 6>;
4155defm : TrapExtendedMnemonic<"u", 31>;
4156
4157// Atomic loads
4158def : Pat<(atomic_load_8  iaddr:$src), (LBZ  memri:$src)>;
4159def : Pat<(atomic_load_16 iaddr:$src), (LHZ  memri:$src)>;
4160def : Pat<(atomic_load_32 iaddr:$src), (LWZ  memri:$src)>;
4161def : Pat<(atomic_load_8  xaddr:$src), (LBZX memrr:$src)>;
4162def : Pat<(atomic_load_16 xaddr:$src), (LHZX memrr:$src)>;
4163def : Pat<(atomic_load_32 xaddr:$src), (LWZX memrr:$src)>;
4164
4165// Atomic stores
4166def : Pat<(atomic_store_8  iaddr:$ptr, i32:$val), (STB  gprc:$val, memri:$ptr)>;
4167def : Pat<(atomic_store_16 iaddr:$ptr, i32:$val), (STH  gprc:$val, memri:$ptr)>;
4168def : Pat<(atomic_store_32 iaddr:$ptr, i32:$val), (STW  gprc:$val, memri:$ptr)>;
4169def : Pat<(atomic_store_8  xaddr:$ptr, i32:$val), (STBX gprc:$val, memrr:$ptr)>;
4170def : Pat<(atomic_store_16 xaddr:$ptr, i32:$val), (STHX gprc:$val, memrr:$ptr)>;
4171def : Pat<(atomic_store_32 xaddr:$ptr, i32:$val), (STWX gprc:$val, memrr:$ptr)>;
4172