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