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