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