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