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