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