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