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