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