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