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