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