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