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