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