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