[PowerPC] Ensure that the TOC reload directly follows bctrl on PPC64
[oota-llvm.git] / lib / Target / PowerPC / PPCInstrInfo.td
1 //===-- PPCInstrInfo.td - The PowerPC Instruction Set ------*- tablegen -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file describes the subset of the 32-bit PowerPC instruction set, as used
11 // by the PowerPC instruction selector.
12 //
13 //===----------------------------------------------------------------------===//
14
15 include "PPCInstrFormats.td"
16
17 //===----------------------------------------------------------------------===//
18 // PowerPC specific type constraints.
19 //
20 def SDT_PPCstfiwx : SDTypeProfile<0, 2, [ // stfiwx
21   SDTCisVT<0, f64>, SDTCisPtrTy<1>
22 ]>;
23 def SDT_PPClfiwx : SDTypeProfile<1, 1, [ // lfiw[az]x
24   SDTCisVT<0, f64>, SDTCisPtrTy<1>
25 ]>;
26
27 def SDT_PPCCallSeqStart : SDCallSeqStart<[ SDTCisVT<0, i32> ]>;
28 def SDT_PPCCallSeqEnd   : SDCallSeqEnd<[ SDTCisVT<0, i32>,
29                                          SDTCisVT<1, i32> ]>;
30 def SDT_PPCvperm   : SDTypeProfile<1, 3, [
31   SDTCisVT<3, v16i8>, SDTCisSameAs<0, 1>, SDTCisSameAs<0, 2>
32 ]>;
33
34 def SDT_PPCvcmp : SDTypeProfile<1, 3, [
35   SDTCisSameAs<0, 1>, SDTCisSameAs<1, 2>, SDTCisVT<3, i32>
36 ]>;
37
38 def SDT_PPCcondbr : SDTypeProfile<0, 3, [
39   SDTCisVT<0, i32>, SDTCisVT<2, OtherVT>
40 ]>;
41
42 def SDT_PPClbrx : SDTypeProfile<1, 2, [
43   SDTCisInt<0>, SDTCisPtrTy<1>, SDTCisVT<2, OtherVT>
44 ]>;
45 def SDT_PPCstbrx : SDTypeProfile<0, 3, [
46   SDTCisInt<0>, SDTCisPtrTy<1>, SDTCisVT<2, OtherVT>
47 ]>;
48
49 def SDT_PPClarx : SDTypeProfile<1, 1, [
50   SDTCisInt<0>, SDTCisPtrTy<1>
51 ]>;
52 def SDT_PPCstcx : SDTypeProfile<0, 2, [
53   SDTCisInt<0>, SDTCisPtrTy<1>
54 ]>;
55
56 def SDT_PPCTC_ret : SDTypeProfile<0, 2, [
57   SDTCisPtrTy<0>, SDTCisVT<1, i32>
58 ]>;
59
60 def tocentry32 : Operand<iPTR> {
61   let MIOperandInfo = (ops i32imm:$imm);
62 }
63
64 //===----------------------------------------------------------------------===//
65 // PowerPC specific DAG Nodes.
66 //
67
68 def PPCfre    : SDNode<"PPCISD::FRE",     SDTFPUnaryOp, []>;
69 def PPCfrsqrte: SDNode<"PPCISD::FRSQRTE", SDTFPUnaryOp, []>;
70
71 def PPCfcfid  : SDNode<"PPCISD::FCFID",   SDTFPUnaryOp, []>;
72 def PPCfcfidu : SDNode<"PPCISD::FCFIDU",  SDTFPUnaryOp, []>;
73 def PPCfcfids : SDNode<"PPCISD::FCFIDS",  SDTFPRoundOp, []>;
74 def PPCfcfidus: SDNode<"PPCISD::FCFIDUS", SDTFPRoundOp, []>;
75 def PPCfctidz : SDNode<"PPCISD::FCTIDZ", SDTFPUnaryOp, []>;
76 def PPCfctiwz : SDNode<"PPCISD::FCTIWZ", SDTFPUnaryOp, []>;
77 def PPCfctiduz: SDNode<"PPCISD::FCTIDUZ",SDTFPUnaryOp, []>;
78 def PPCfctiwuz: SDNode<"PPCISD::FCTIWUZ",SDTFPUnaryOp, []>;
79 def PPCstfiwx : SDNode<"PPCISD::STFIWX", SDT_PPCstfiwx,
80                        [SDNPHasChain, SDNPMayStore]>;
81 def PPClfiwax : SDNode<"PPCISD::LFIWAX", SDT_PPClfiwx,
82                        [SDNPHasChain, SDNPMayLoad]>;
83 def PPClfiwzx : SDNode<"PPCISD::LFIWZX", SDT_PPClfiwx,
84                        [SDNPHasChain, SDNPMayLoad]>;
85
86 // Extract FPSCR (not modeled at the DAG level).
87 def PPCmffs   : SDNode<"PPCISD::MFFS",
88                        SDTypeProfile<1, 0, [SDTCisVT<0, f64>]>, []>;
89
90 // Perform FADD in round-to-zero mode.
91 def PPCfaddrtz: SDNode<"PPCISD::FADDRTZ", SDTFPBinOp, []>;
92
93
94 def PPCfsel   : SDNode<"PPCISD::FSEL",  
95    // Type constraint for fsel.
96    SDTypeProfile<1, 3, [SDTCisSameAs<0, 2>, SDTCisSameAs<0, 3>, 
97                         SDTCisFP<0>, SDTCisVT<1, f64>]>, []>;
98
99 def PPChi       : SDNode<"PPCISD::Hi", SDTIntBinOp, []>;
100 def PPClo       : SDNode<"PPCISD::Lo", SDTIntBinOp, []>;
101 def PPCtoc_entry: SDNode<"PPCISD::TOC_ENTRY", SDTIntBinOp, [SDNPMayLoad]>;
102 def PPCvmaddfp  : SDNode<"PPCISD::VMADDFP", SDTFPTernaryOp, []>;
103 def PPCvnmsubfp : SDNode<"PPCISD::VNMSUBFP", SDTFPTernaryOp, []>;
104
105 def PPCppc32GOT : SDNode<"PPCISD::PPC32_GOT", SDTIntLeaf, []>;
106
107 def PPCaddisGotTprelHA : SDNode<"PPCISD::ADDIS_GOT_TPREL_HA", SDTIntBinOp>;
108 def PPCldGotTprelL : SDNode<"PPCISD::LD_GOT_TPREL_L", SDTIntBinOp,
109                             [SDNPMayLoad]>;
110 def PPCaddTls     : SDNode<"PPCISD::ADD_TLS", SDTIntBinOp, []>;
111 def PPCaddisTlsgdHA : SDNode<"PPCISD::ADDIS_TLSGD_HA", SDTIntBinOp>;
112 def PPCaddiTlsgdL   : SDNode<"PPCISD::ADDI_TLSGD_L", SDTIntBinOp>;
113 def PPCaddisTlsldHA : SDNode<"PPCISD::ADDIS_TLSLD_HA", SDTIntBinOp>;
114 def PPCaddiTlsldL   : SDNode<"PPCISD::ADDI_TLSLD_L", SDTIntBinOp>;
115 def PPCaddisDtprelHA : SDNode<"PPCISD::ADDIS_DTPREL_HA", SDTIntBinOp,
116                               [SDNPHasChain]>;
117 def PPCaddiDtprelL   : SDNode<"PPCISD::ADDI_DTPREL_L", SDTIntBinOp>;
118
119 def PPCvperm    : SDNode<"PPCISD::VPERM", SDT_PPCvperm, []>;
120
121 // These nodes represent the 32-bit PPC shifts that operate on 6-bit shift
122 // amounts.  These nodes are generated by the multi-precision shift code.
123 def PPCsrl        : SDNode<"PPCISD::SRL"       , SDTIntShiftOp>;
124 def PPCsra        : SDNode<"PPCISD::SRA"       , SDTIntShiftOp>;
125 def PPCshl        : SDNode<"PPCISD::SHL"       , SDTIntShiftOp>;
126
127 // These are target-independent nodes, but have target-specific formats.
128 def callseq_start : SDNode<"ISD::CALLSEQ_START", SDT_PPCCallSeqStart,
129                            [SDNPHasChain, SDNPOutGlue]>;
130 def callseq_end   : SDNode<"ISD::CALLSEQ_END",   SDT_PPCCallSeqEnd,
131                            [SDNPHasChain, SDNPOptInGlue, SDNPOutGlue]>;
132
133 def SDT_PPCCall   : SDTypeProfile<0, -1, [SDTCisInt<0>]>;
134 def PPCcall  : SDNode<"PPCISD::CALL", SDT_PPCCall,
135                       [SDNPHasChain, SDNPOptInGlue, SDNPOutGlue,
136                        SDNPVariadic]>;
137 def PPCcall_tls : SDNode<"PPCISD::CALL_TLS", SDT_PPCCall,
138                          [SDNPHasChain, SDNPOptInGlue, SDNPOutGlue,
139                           SDNPVariadic]>;
140 def PPCcall_nop  : SDNode<"PPCISD::CALL_NOP", SDT_PPCCall,
141                           [SDNPHasChain, SDNPOptInGlue, SDNPOutGlue,
142                            SDNPVariadic]>;
143 def PPCcall_nop_tls : SDNode<"PPCISD::CALL_NOP_TLS", SDT_PPCCall,
144                              [SDNPHasChain, SDNPOptInGlue, SDNPOutGlue,
145                               SDNPVariadic]>;
146 def PPCload   : SDNode<"PPCISD::LOAD", SDTypeProfile<1, 1, []>,
147                        [SDNPHasChain, SDNPOptInGlue, SDNPOutGlue]>;
148 def PPCload_toc : SDNode<"PPCISD::LOAD_TOC", SDTypeProfile<0, 1, []>,
149                           [SDNPHasChain, SDNPSideEffect,
150                            SDNPInGlue, SDNPOutGlue]>;
151 def PPCmtctr      : SDNode<"PPCISD::MTCTR", SDT_PPCCall,
152                            [SDNPHasChain, SDNPOptInGlue, SDNPOutGlue]>;
153 def PPCbctrl : SDNode<"PPCISD::BCTRL", SDTNone,
154                       [SDNPHasChain, SDNPOptInGlue, SDNPOutGlue,
155                        SDNPVariadic]>;
156 def PPCbctrl_load_toc : SDNode<"PPCISD::BCTRL_LOAD_TOC",
157                                SDTypeProfile<0, 1, []>,
158                                [SDNPHasChain, SDNPOptInGlue, SDNPOutGlue,
159                                 SDNPVariadic]>;
160
161 def retflag       : SDNode<"PPCISD::RET_FLAG", SDTNone,
162                            [SDNPHasChain, SDNPOptInGlue, SDNPVariadic]>;
163
164 def PPCtc_return : SDNode<"PPCISD::TC_RETURN", SDT_PPCTC_ret,
165                         [SDNPHasChain,  SDNPOptInGlue, SDNPVariadic]>;
166
167 def PPCeh_sjlj_setjmp  : SDNode<"PPCISD::EH_SJLJ_SETJMP",
168                                 SDTypeProfile<1, 1, [SDTCisInt<0>,
169                                                      SDTCisPtrTy<1>]>,
170                                 [SDNPHasChain, SDNPSideEffect]>;
171 def PPCeh_sjlj_longjmp : SDNode<"PPCISD::EH_SJLJ_LONGJMP",
172                                 SDTypeProfile<0, 1, [SDTCisPtrTy<0>]>,
173                                 [SDNPHasChain, SDNPSideEffect]>;
174
175 def SDT_PPCsc     : SDTypeProfile<0, 1, [SDTCisInt<0>]>;
176 def PPCsc         : SDNode<"PPCISD::SC", SDT_PPCsc,
177                            [SDNPHasChain, SDNPSideEffect]>;
178
179 def PPCvcmp       : SDNode<"PPCISD::VCMP" , SDT_PPCvcmp, []>;
180 def PPCvcmp_o     : SDNode<"PPCISD::VCMPo", SDT_PPCvcmp, [SDNPOutGlue]>;
181
182 def PPCcondbranch : SDNode<"PPCISD::COND_BRANCH", SDT_PPCcondbr,
183                            [SDNPHasChain, SDNPOptInGlue]>;
184
185 def PPClbrx       : SDNode<"PPCISD::LBRX", SDT_PPClbrx,
186                            [SDNPHasChain, SDNPMayLoad]>;
187 def PPCstbrx      : SDNode<"PPCISD::STBRX", SDT_PPCstbrx,
188                            [SDNPHasChain, SDNPMayStore]>;
189
190 // Instructions to set/unset CR bit 6 for SVR4 vararg calls
191 def PPCcr6set   : SDNode<"PPCISD::CR6SET", SDTNone,
192                          [SDNPHasChain, SDNPOptInGlue, SDNPOutGlue]>;
193 def PPCcr6unset : SDNode<"PPCISD::CR6UNSET", SDTNone,
194                          [SDNPHasChain, SDNPOptInGlue, SDNPOutGlue]>;
195
196 // Instructions to support atomic operations
197 def PPClarx      : SDNode<"PPCISD::LARX", SDT_PPClarx,
198                           [SDNPHasChain, SDNPMayLoad]>;
199 def PPCstcx      : SDNode<"PPCISD::STCX", SDT_PPCstcx,
200                           [SDNPHasChain, SDNPMayStore]>;
201
202 // Instructions to support medium and large code model
203 def PPCaddisTocHA : SDNode<"PPCISD::ADDIS_TOC_HA", SDTIntBinOp, []>;
204 def PPCldTocL     : SDNode<"PPCISD::LD_TOC_L", SDTIntBinOp, [SDNPMayLoad]>;
205 def PPCaddiTocL   : SDNode<"PPCISD::ADDI_TOC_L", SDTIntBinOp, []>;
206
207
208 // Instructions to support dynamic alloca.
209 def SDTDynOp  : SDTypeProfile<1, 2, []>;
210 def PPCdynalloc   : SDNode<"PPCISD::DYNALLOC", SDTDynOp, [SDNPHasChain]>;
211
212 //===----------------------------------------------------------------------===//
213 // PowerPC specific transformation functions and pattern fragments.
214 //
215
216 def SHL32 : SDNodeXForm<imm, [{
217   // Transformation function: 31 - imm
218   return getI32Imm(31 - N->getZExtValue());
219 }]>;
220
221 def SRL32 : SDNodeXForm<imm, [{
222   // Transformation function: 32 - imm
223   return N->getZExtValue() ? getI32Imm(32 - N->getZExtValue()) : getI32Imm(0);
224 }]>;
225
226 def LO16 : SDNodeXForm<imm, [{
227   // Transformation function: get the low 16 bits.
228   return getI32Imm((unsigned short)N->getZExtValue());
229 }]>;
230
231 def HI16 : SDNodeXForm<imm, [{
232   // Transformation function: shift the immediate value down into the low bits.
233   return getI32Imm((unsigned)N->getZExtValue() >> 16);
234 }]>;
235
236 def HA16 : SDNodeXForm<imm, [{
237   // Transformation function: shift the immediate value down into the low bits.
238   signed int Val = N->getZExtValue();
239   return getI32Imm((Val - (signed short)Val) >> 16);
240 }]>;
241 def MB : SDNodeXForm<imm, [{
242   // Transformation function: get the start bit of a mask
243   unsigned mb = 0, me;
244   (void)isRunOfOnes((unsigned)N->getZExtValue(), mb, me);
245   return getI32Imm(mb);
246 }]>;
247
248 def ME : SDNodeXForm<imm, [{
249   // Transformation function: get the end bit of a mask
250   unsigned mb, me = 0;
251   (void)isRunOfOnes((unsigned)N->getZExtValue(), mb, me);
252   return getI32Imm(me);
253 }]>;
254 def maskimm32 : PatLeaf<(imm), [{
255   // maskImm predicate - True if immediate is a run of ones.
256   unsigned mb, me;
257   if (N->getValueType(0) == MVT::i32)
258     return isRunOfOnes((unsigned)N->getZExtValue(), mb, me);
259   else
260     return false;
261 }]>;
262
263 def imm32SExt16  : Operand<i32>, ImmLeaf<i32, [{
264   // imm32SExt16 predicate - True if the i32 immediate fits in a 16-bit
265   // sign extended field.  Used by instructions like 'addi'.
266   return (int32_t)Imm == (short)Imm;
267 }]>;
268 def imm64SExt16  : Operand<i64>, ImmLeaf<i64, [{
269   // imm64SExt16 predicate - True if the i64 immediate fits in a 16-bit
270   // sign extended field.  Used by instructions like 'addi'.
271   return (int64_t)Imm == (short)Imm;
272 }]>;
273 def immZExt16  : PatLeaf<(imm), [{
274   // immZExt16 predicate - True if the immediate fits in a 16-bit zero extended
275   // field.  Used by instructions like 'ori'.
276   return (uint64_t)N->getZExtValue() == (unsigned short)N->getZExtValue();
277 }], LO16>;
278
279 // imm16Shifted* - These match immediates where the low 16-bits are zero.  There
280 // are two forms: imm16ShiftedSExt and imm16ShiftedZExt.  These two forms are
281 // identical in 32-bit mode, but in 64-bit mode, they return true if the
282 // immediate fits into a sign/zero extended 32-bit immediate (with the low bits
283 // clear).
284 def imm16ShiftedZExt : PatLeaf<(imm), [{
285   // imm16ShiftedZExt predicate - True if only bits in the top 16-bits of the
286   // immediate are set.  Used by instructions like 'xoris'.
287   return (N->getZExtValue() & ~uint64_t(0xFFFF0000)) == 0;
288 }], HI16>;
289
290 def imm16ShiftedSExt : PatLeaf<(imm), [{
291   // imm16ShiftedSExt predicate - True if only bits in the top 16-bits of the
292   // immediate are set.  Used by instructions like 'addis'.  Identical to 
293   // imm16ShiftedZExt in 32-bit mode.
294   if (N->getZExtValue() & 0xFFFF) return false;
295   if (N->getValueType(0) == MVT::i32)
296     return true;
297   // For 64-bit, make sure it is sext right.
298   return N->getZExtValue() == (uint64_t)(int)N->getZExtValue();
299 }], HI16>;
300
301 def imm64ZExt32  : Operand<i64>, ImmLeaf<i64, [{
302   // imm64ZExt32 predicate - True if the i64 immediate fits in a 32-bit
303   // zero extended field.
304   return isUInt<32>(Imm);
305 }]>;
306
307 // Some r+i load/store instructions (such as LD, STD, LDU, etc.) that require
308 // restricted memrix (4-aligned) constants are alignment sensitive. If these
309 // offsets are hidden behind TOC entries than the values of the lower-order
310 // bits cannot be checked directly. As a result, we need to also incorporate
311 // an alignment check into the relevant patterns.
312
313 def aligned4load : PatFrag<(ops node:$ptr), (load node:$ptr), [{
314   return cast<LoadSDNode>(N)->getAlignment() >= 4;
315 }]>;
316 def aligned4store : PatFrag<(ops node:$val, node:$ptr),
317                             (store node:$val, node:$ptr), [{
318   return cast<StoreSDNode>(N)->getAlignment() >= 4;
319 }]>;
320 def aligned4sextloadi32 : PatFrag<(ops node:$ptr), (sextloadi32 node:$ptr), [{
321   return cast<LoadSDNode>(N)->getAlignment() >= 4;
322 }]>;
323 def aligned4pre_store : PatFrag<
324                           (ops node:$val, node:$base, node:$offset),
325                           (pre_store node:$val, node:$base, node:$offset), [{
326   return cast<StoreSDNode>(N)->getAlignment() >= 4;
327 }]>;
328
329 def unaligned4load : PatFrag<(ops node:$ptr), (load node:$ptr), [{
330   return cast<LoadSDNode>(N)->getAlignment() < 4;
331 }]>;
332 def unaligned4store : PatFrag<(ops node:$val, node:$ptr),
333                               (store node:$val, node:$ptr), [{
334   return cast<StoreSDNode>(N)->getAlignment() < 4;
335 }]>;
336 def unaligned4sextloadi32 : PatFrag<(ops node:$ptr), (sextloadi32 node:$ptr), [{
337   return cast<LoadSDNode>(N)->getAlignment() < 4;
338 }]>;
339
340 //===----------------------------------------------------------------------===//
341 // PowerPC Flag Definitions.
342
343 class isPPC64 { bit PPC64 = 1; }
344 class isDOT   { bit RC = 1; }
345
346 class RegConstraint<string C> {
347   string Constraints = C;
348 }
349 class NoEncode<string E> {
350   string DisableEncoding = E;
351 }
352
353
354 //===----------------------------------------------------------------------===//
355 // PowerPC Operand Definitions.
356
357 // In the default PowerPC assembler syntax, registers are specified simply
358 // by number, so they cannot be distinguished from immediate values (without
359 // looking at the opcode).  This means that the default operand matching logic
360 // for the asm parser does not work, and we need to specify custom matchers.
361 // Since those can only be specified with RegisterOperand classes and not
362 // directly on the RegisterClass, all instructions patterns used by the asm
363 // parser need to use a RegisterOperand (instead of a RegisterClass) for
364 // all their register operands.
365 // For this purpose, we define one RegisterOperand for each RegisterClass,
366 // using the same name as the class, just in lower case.
367
368 def PPCRegGPRCAsmOperand : AsmOperandClass {
369   let Name = "RegGPRC"; let PredicateMethod = "isRegNumber";
370 }
371 def gprc : RegisterOperand<GPRC> {
372   let ParserMatchClass = PPCRegGPRCAsmOperand;
373 }
374 def PPCRegG8RCAsmOperand : AsmOperandClass {
375   let Name = "RegG8RC"; let PredicateMethod = "isRegNumber";
376 }
377 def g8rc : RegisterOperand<G8RC> {
378   let ParserMatchClass = PPCRegG8RCAsmOperand;
379 }
380 def PPCRegGPRCNoR0AsmOperand : AsmOperandClass {
381   let Name = "RegGPRCNoR0"; let PredicateMethod = "isRegNumber";
382 }
383 def gprc_nor0 : RegisterOperand<GPRC_NOR0> {
384   let ParserMatchClass = PPCRegGPRCNoR0AsmOperand;
385 }
386 def PPCRegG8RCNoX0AsmOperand : AsmOperandClass {
387   let Name = "RegG8RCNoX0"; let PredicateMethod = "isRegNumber";
388 }
389 def g8rc_nox0 : RegisterOperand<G8RC_NOX0> {
390   let ParserMatchClass = PPCRegG8RCNoX0AsmOperand;
391 }
392 def PPCRegF8RCAsmOperand : AsmOperandClass {
393   let Name = "RegF8RC"; let PredicateMethod = "isRegNumber";
394 }
395 def f8rc : RegisterOperand<F8RC> {
396   let ParserMatchClass = PPCRegF8RCAsmOperand;
397 }
398 def PPCRegF4RCAsmOperand : AsmOperandClass {
399   let Name = "RegF4RC"; let PredicateMethod = "isRegNumber";
400 }
401 def f4rc : RegisterOperand<F4RC> {
402   let ParserMatchClass = PPCRegF4RCAsmOperand;
403 }
404 def PPCRegVRRCAsmOperand : AsmOperandClass {
405   let Name = "RegVRRC"; let PredicateMethod = "isRegNumber";
406 }
407 def vrrc : RegisterOperand<VRRC> {
408   let ParserMatchClass = PPCRegVRRCAsmOperand;
409 }
410 def PPCRegCRBITRCAsmOperand : AsmOperandClass {
411   let Name = "RegCRBITRC"; let PredicateMethod = "isCRBitNumber";
412 }
413 def crbitrc : RegisterOperand<CRBITRC> {
414   let ParserMatchClass = PPCRegCRBITRCAsmOperand;
415 }
416 def PPCRegCRRCAsmOperand : AsmOperandClass {
417   let Name = "RegCRRC"; let PredicateMethod = "isCCRegNumber";
418 }
419 def crrc : RegisterOperand<CRRC> {
420   let ParserMatchClass = PPCRegCRRCAsmOperand;
421 }
422
423 def PPCU2ImmAsmOperand : AsmOperandClass {
424   let Name = "U2Imm"; let PredicateMethod = "isU2Imm";
425   let RenderMethod = "addImmOperands";
426 }
427 def u2imm   : Operand<i32> {
428   let PrintMethod = "printU2ImmOperand";
429   let ParserMatchClass = PPCU2ImmAsmOperand;
430 }
431
432 def PPCU4ImmAsmOperand : AsmOperandClass {
433   let Name = "U4Imm"; let PredicateMethod = "isU4Imm";
434   let RenderMethod = "addImmOperands";
435 }
436 def u4imm   : Operand<i32> {
437   let PrintMethod = "printU4ImmOperand";
438   let ParserMatchClass = PPCU4ImmAsmOperand;
439 }
440 def PPCS5ImmAsmOperand : AsmOperandClass {
441   let Name = "S5Imm"; let PredicateMethod = "isS5Imm";
442   let RenderMethod = "addImmOperands";
443 }
444 def s5imm   : Operand<i32> {
445   let PrintMethod = "printS5ImmOperand";
446   let ParserMatchClass = PPCS5ImmAsmOperand;
447   let DecoderMethod = "decodeSImmOperand<5>";
448 }
449 def PPCU5ImmAsmOperand : AsmOperandClass {
450   let Name = "U5Imm"; let PredicateMethod = "isU5Imm";
451   let RenderMethod = "addImmOperands";
452 }
453 def u5imm   : Operand<i32> {
454   let PrintMethod = "printU5ImmOperand";
455   let ParserMatchClass = PPCU5ImmAsmOperand;
456   let DecoderMethod = "decodeUImmOperand<5>";
457 }
458 def PPCU6ImmAsmOperand : AsmOperandClass {
459   let Name = "U6Imm"; let PredicateMethod = "isU6Imm";
460   let RenderMethod = "addImmOperands";
461 }
462 def u6imm   : Operand<i32> {
463   let PrintMethod = "printU6ImmOperand";
464   let ParserMatchClass = PPCU6ImmAsmOperand;
465   let DecoderMethod = "decodeUImmOperand<6>";
466 }
467 def PPCS16ImmAsmOperand : AsmOperandClass {
468   let Name = "S16Imm"; let PredicateMethod = "isS16Imm";
469   let RenderMethod = "addS16ImmOperands";
470 }
471 def s16imm  : Operand<i32> {
472   let PrintMethod = "printS16ImmOperand";
473   let EncoderMethod = "getImm16Encoding";
474   let ParserMatchClass = PPCS16ImmAsmOperand;
475   let DecoderMethod = "decodeSImmOperand<16>";
476 }
477 def PPCU16ImmAsmOperand : AsmOperandClass {
478   let Name = "U16Imm"; let PredicateMethod = "isU16Imm";
479   let RenderMethod = "addU16ImmOperands";
480 }
481 def u16imm  : Operand<i32> {
482   let PrintMethod = "printU16ImmOperand";
483   let EncoderMethod = "getImm16Encoding";
484   let ParserMatchClass = PPCU16ImmAsmOperand;
485   let DecoderMethod = "decodeUImmOperand<16>";
486 }
487 def PPCS17ImmAsmOperand : AsmOperandClass {
488   let Name = "S17Imm"; let PredicateMethod = "isS17Imm";
489   let RenderMethod = "addS16ImmOperands";
490 }
491 def s17imm  : Operand<i32> {
492   // This operand type is used for addis/lis to allow the assembler parser
493   // to accept immediates in the range -65536..65535 for compatibility with
494   // the GNU assembler.  The operand is treated as 16-bit otherwise.
495   let PrintMethod = "printS16ImmOperand";
496   let EncoderMethod = "getImm16Encoding";
497   let ParserMatchClass = PPCS17ImmAsmOperand;
498   let DecoderMethod = "decodeSImmOperand<16>";
499 }
500 def PPCDirectBrAsmOperand : AsmOperandClass {
501   let Name = "DirectBr"; let PredicateMethod = "isDirectBr";
502   let RenderMethod = "addBranchTargetOperands";
503 }
504 def directbrtarget : Operand<OtherVT> {
505   let PrintMethod = "printBranchOperand";
506   let EncoderMethod = "getDirectBrEncoding";
507   let ParserMatchClass = PPCDirectBrAsmOperand;
508 }
509 def absdirectbrtarget : Operand<OtherVT> {
510   let PrintMethod = "printAbsBranchOperand";
511   let EncoderMethod = "getAbsDirectBrEncoding";
512   let ParserMatchClass = PPCDirectBrAsmOperand;
513 }
514 def PPCCondBrAsmOperand : AsmOperandClass {
515   let Name = "CondBr"; let PredicateMethod = "isCondBr";
516   let RenderMethod = "addBranchTargetOperands";
517 }
518 def condbrtarget : Operand<OtherVT> {
519   let PrintMethod = "printBranchOperand";
520   let EncoderMethod = "getCondBrEncoding";
521   let ParserMatchClass = PPCCondBrAsmOperand;
522 }
523 def abscondbrtarget : Operand<OtherVT> {
524   let PrintMethod = "printAbsBranchOperand";
525   let EncoderMethod = "getAbsCondBrEncoding";
526   let ParserMatchClass = PPCCondBrAsmOperand;
527 }
528 def calltarget : Operand<iPTR> {
529   let PrintMethod = "printBranchOperand";
530   let EncoderMethod = "getDirectBrEncoding";
531   let ParserMatchClass = PPCDirectBrAsmOperand;
532 }
533 def abscalltarget : Operand<iPTR> {
534   let PrintMethod = "printAbsBranchOperand";
535   let EncoderMethod = "getAbsDirectBrEncoding";
536   let ParserMatchClass = PPCDirectBrAsmOperand;
537 }
538 def PPCCRBitMaskOperand : AsmOperandClass {
539  let Name = "CRBitMask"; let PredicateMethod = "isCRBitMask";
540 }
541 def crbitm: Operand<i8> {
542   let PrintMethod = "printcrbitm";
543   let EncoderMethod = "get_crbitm_encoding";
544   let DecoderMethod = "decodeCRBitMOperand";
545   let ParserMatchClass = PPCCRBitMaskOperand;
546 }
547 // Address operands
548 // A version of ptr_rc which excludes R0 (or X0 in 64-bit mode).
549 def PPCRegGxRCNoR0Operand : AsmOperandClass {
550   let Name = "RegGxRCNoR0"; let PredicateMethod = "isRegNumber";
551 }
552 def ptr_rc_nor0 : Operand<iPTR>, PointerLikeRegClass<1> {
553   let ParserMatchClass = PPCRegGxRCNoR0Operand;
554 }
555 // A version of ptr_rc usable with the asm parser.
556 def PPCRegGxRCOperand : AsmOperandClass {
557   let Name = "RegGxRC"; let PredicateMethod = "isRegNumber";
558 }
559 def ptr_rc_idx : Operand<iPTR>, PointerLikeRegClass<0> {
560   let ParserMatchClass = PPCRegGxRCOperand;
561 }
562
563 def PPCDispRIOperand : AsmOperandClass {
564  let Name = "DispRI"; let PredicateMethod = "isS16Imm";
565  let RenderMethod = "addS16ImmOperands";
566 }
567 def dispRI : Operand<iPTR> {
568   let ParserMatchClass = PPCDispRIOperand;
569 }
570 def PPCDispRIXOperand : AsmOperandClass {
571  let Name = "DispRIX"; let PredicateMethod = "isS16ImmX4";
572  let RenderMethod = "addImmOperands";
573 }
574 def dispRIX : Operand<iPTR> {
575   let ParserMatchClass = PPCDispRIXOperand;
576 }
577 def PPCDispSPE8Operand : AsmOperandClass {
578  let Name = "DispSPE8"; let PredicateMethod = "isU8ImmX8";
579  let RenderMethod = "addImmOperands";
580 }
581 def dispSPE8 : Operand<iPTR> {
582   let ParserMatchClass = PPCDispSPE8Operand;
583 }
584 def PPCDispSPE4Operand : AsmOperandClass {
585  let Name = "DispSPE4"; let PredicateMethod = "isU7ImmX4";
586  let RenderMethod = "addImmOperands";
587 }
588 def dispSPE4 : Operand<iPTR> {
589   let ParserMatchClass = PPCDispSPE4Operand;
590 }
591 def PPCDispSPE2Operand : AsmOperandClass {
592  let Name = "DispSPE2"; let PredicateMethod = "isU6ImmX2";
593  let RenderMethod = "addImmOperands";
594 }
595 def dispSPE2 : Operand<iPTR> {
596   let ParserMatchClass = PPCDispSPE2Operand;
597 }
598
599 def memri : Operand<iPTR> {
600   let PrintMethod = "printMemRegImm";
601   let MIOperandInfo = (ops dispRI:$imm, ptr_rc_nor0:$reg);
602   let EncoderMethod = "getMemRIEncoding";
603   let DecoderMethod = "decodeMemRIOperands";
604 }
605 def memrr : Operand<iPTR> {
606   let PrintMethod = "printMemRegReg";
607   let MIOperandInfo = (ops ptr_rc_nor0:$ptrreg, ptr_rc_idx:$offreg);
608 }
609 def memrix : Operand<iPTR> {   // memri where the imm is 4-aligned.
610   let PrintMethod = "printMemRegImm";
611   let MIOperandInfo = (ops dispRIX:$imm, ptr_rc_nor0:$reg);
612   let EncoderMethod = "getMemRIXEncoding";
613   let DecoderMethod = "decodeMemRIXOperands";
614 }
615 def spe8dis : Operand<iPTR> {   // SPE displacement where the imm is 8-aligned.
616   let PrintMethod = "printMemRegImm";
617   let MIOperandInfo = (ops dispSPE8:$imm, ptr_rc_nor0:$reg);
618   let EncoderMethod = "getSPE8DisEncoding";
619 }
620 def spe4dis : Operand<iPTR> {   // SPE displacement where the imm is 4-aligned.
621   let PrintMethod = "printMemRegImm";
622   let MIOperandInfo = (ops dispSPE4:$imm, ptr_rc_nor0:$reg);
623   let EncoderMethod = "getSPE4DisEncoding";
624 }
625 def spe2dis : Operand<iPTR> {   // SPE displacement where the imm is 2-aligned.
626   let PrintMethod = "printMemRegImm";
627   let MIOperandInfo = (ops dispSPE2:$imm, ptr_rc_nor0:$reg);
628   let EncoderMethod = "getSPE2DisEncoding";
629 }
630
631 // A single-register address. This is used with the SjLj
632 // pseudo-instructions.
633 def memr : Operand<iPTR> {
634   let MIOperandInfo = (ops ptr_rc:$ptrreg);
635 }
636 def PPCTLSRegOperand : AsmOperandClass {
637   let Name = "TLSReg"; let PredicateMethod = "isTLSReg";
638   let RenderMethod = "addTLSRegOperands";
639 }
640 def tlsreg32 : Operand<i32> {
641   let EncoderMethod = "getTLSRegEncoding";
642   let ParserMatchClass = PPCTLSRegOperand;
643 }
644 def tlsgd32 : Operand<i32> {}
645 def tlscall32 : Operand<i32> {
646   let PrintMethod = "printTLSCall";
647   let MIOperandInfo = (ops calltarget:$func, tlsgd32:$sym);
648   let EncoderMethod = "getTLSCallEncoding";
649 }
650
651 // PowerPC Predicate operand.
652 def pred : Operand<OtherVT> {
653   let PrintMethod = "printPredicateOperand";
654   let MIOperandInfo = (ops i32imm:$bibo, crrc:$reg);
655 }
656
657 // Define PowerPC specific addressing mode.
658 def iaddr  : ComplexPattern<iPTR, 2, "SelectAddrImm",    [], []>;
659 def xaddr  : ComplexPattern<iPTR, 2, "SelectAddrIdx",    [], []>;
660 def xoaddr : ComplexPattern<iPTR, 2, "SelectAddrIdxOnly",[], []>;
661 def ixaddr : ComplexPattern<iPTR, 2, "SelectAddrImmX4",  [], []>; // "std"
662
663 // The address in a single register. This is used with the SjLj
664 // pseudo-instructions.
665 def addr   : ComplexPattern<iPTR, 1, "SelectAddr",[], []>;
666
667 /// This is just the offset part of iaddr, used for preinc.
668 def iaddroff : ComplexPattern<iPTR, 1, "SelectAddrImmOffs", [], []>;
669
670 //===----------------------------------------------------------------------===//
671 // PowerPC Instruction Predicate Definitions.
672 def In32BitMode  : Predicate<"!PPCSubTarget->isPPC64()">;
673 def In64BitMode  : Predicate<"PPCSubTarget->isPPC64()">;
674 def IsBookE  : Predicate<"PPCSubTarget->isBookE()">;
675 def IsNotBookE  : Predicate<"!PPCSubTarget->isBookE()">;
676 def HasOnlyMSYNC : Predicate<"PPCSubTarget->hasOnlyMSYNC()">;
677 def HasSYNC   : Predicate<"!PPCSubTarget->hasOnlyMSYNC()">;
678 def IsPPC4xx  : Predicate<"PPCSubTarget->isPPC4xx()">;
679 def IsPPC6xx  : Predicate<"PPCSubTarget->isPPC6xx()">;
680 def IsE500  : Predicate<"PPCSubTarget->isE500()">;
681 def HasSPE  : Predicate<"PPCSubTarget->HasSPE()">;
682
683 //===----------------------------------------------------------------------===//
684 // PowerPC Multiclass Definitions.
685
686 multiclass XForm_6r<bits<6> opcode, bits<10> xo, dag OOL, dag IOL,
687                     string asmbase, string asmstr, InstrItinClass itin,
688                     list<dag> pattern> {
689   let BaseName = asmbase in {
690     def NAME : XForm_6<opcode, xo, OOL, IOL,
691                        !strconcat(asmbase, !strconcat(" ", asmstr)), itin,
692                        pattern>, RecFormRel;
693     let Defs = [CR0] in
694     def o    : XForm_6<opcode, xo, OOL, IOL,
695                        !strconcat(asmbase, !strconcat(". ", asmstr)), itin,
696                        []>, isDOT, RecFormRel;
697   }
698 }
699
700 multiclass XForm_6rc<bits<6> opcode, bits<10> xo, dag OOL, dag IOL,
701                      string asmbase, string asmstr, InstrItinClass itin,
702                      list<dag> pattern> {
703   let BaseName = asmbase in {
704     let Defs = [CARRY] in
705     def NAME : XForm_6<opcode, xo, OOL, IOL,
706                        !strconcat(asmbase, !strconcat(" ", asmstr)), itin,
707                        pattern>, RecFormRel;
708     let Defs = [CARRY, CR0] in
709     def o    : XForm_6<opcode, xo, OOL, IOL,
710                        !strconcat(asmbase, !strconcat(". ", asmstr)), itin,
711                        []>, isDOT, RecFormRel;
712   }
713 }
714
715 multiclass XForm_10rc<bits<6> opcode, bits<10> xo, dag OOL, dag IOL,
716                       string asmbase, string asmstr, InstrItinClass itin,
717                       list<dag> pattern> {
718   let BaseName = asmbase in {
719     let Defs = [CARRY] in
720     def NAME : XForm_10<opcode, xo, OOL, IOL,
721                        !strconcat(asmbase, !strconcat(" ", asmstr)), itin,
722                        pattern>, RecFormRel;
723     let Defs = [CARRY, CR0] in
724     def o    : XForm_10<opcode, xo, OOL, IOL,
725                        !strconcat(asmbase, !strconcat(". ", asmstr)), itin,
726                        []>, isDOT, RecFormRel;
727   }
728 }
729
730 multiclass XForm_11r<bits<6> opcode, bits<10> xo, dag OOL, dag IOL,
731                     string asmbase, string asmstr, InstrItinClass itin,
732                     list<dag> pattern> {
733   let BaseName = asmbase in {
734     def NAME : XForm_11<opcode, xo, OOL, IOL,
735                        !strconcat(asmbase, !strconcat(" ", asmstr)), itin,
736                        pattern>, RecFormRel;
737     let Defs = [CR0] in
738     def o    : XForm_11<opcode, xo, OOL, IOL,
739                        !strconcat(asmbase, !strconcat(". ", asmstr)), itin,
740                        []>, isDOT, RecFormRel;
741   }
742 }
743
744 multiclass XOForm_1r<bits<6> opcode, bits<9> xo, bit oe, dag OOL, dag IOL,
745                     string asmbase, string asmstr, InstrItinClass itin,
746                     list<dag> pattern> {
747   let BaseName = asmbase in {
748     def NAME : XOForm_1<opcode, xo, oe, OOL, IOL,
749                        !strconcat(asmbase, !strconcat(" ", asmstr)), itin,
750                        pattern>, RecFormRel;
751     let Defs = [CR0] in
752     def o    : XOForm_1<opcode, xo, oe, OOL, IOL,
753                        !strconcat(asmbase, !strconcat(". ", asmstr)), itin,
754                        []>, isDOT, RecFormRel;
755   }
756 }
757
758 multiclass XOForm_1rc<bits<6> opcode, bits<9> xo, bit oe, dag OOL, dag IOL,
759                       string asmbase, string asmstr, InstrItinClass itin,
760                       list<dag> pattern> {
761   let BaseName = asmbase in {
762     let Defs = [CARRY] in
763     def NAME : XOForm_1<opcode, xo, oe, OOL, IOL,
764                        !strconcat(asmbase, !strconcat(" ", asmstr)), itin,
765                        pattern>, RecFormRel;
766     let Defs = [CARRY, CR0] in
767     def o    : XOForm_1<opcode, xo, oe, OOL, IOL,
768                        !strconcat(asmbase, !strconcat(". ", asmstr)), itin,
769                        []>, isDOT, RecFormRel;
770   }
771 }
772
773 multiclass XOForm_3r<bits<6> opcode, bits<9> xo, bit oe, dag OOL, dag IOL,
774                     string asmbase, string asmstr, InstrItinClass itin,
775                     list<dag> pattern> {
776   let BaseName = asmbase in {
777     def NAME : XOForm_3<opcode, xo, oe, OOL, IOL,
778                        !strconcat(asmbase, !strconcat(" ", asmstr)), itin,
779                        pattern>, RecFormRel;
780     let Defs = [CR0] in
781     def o    : XOForm_3<opcode, xo, oe, OOL, IOL,
782                        !strconcat(asmbase, !strconcat(". ", asmstr)), itin,
783                        []>, isDOT, RecFormRel;
784   }
785 }
786
787 multiclass XOForm_3rc<bits<6> opcode, bits<9> xo, bit oe, dag OOL, dag IOL,
788                       string asmbase, string asmstr, InstrItinClass itin,
789                       list<dag> pattern> {
790   let BaseName = asmbase in {
791     let Defs = [CARRY] in
792     def NAME : XOForm_3<opcode, xo, oe, OOL, IOL,
793                        !strconcat(asmbase, !strconcat(" ", asmstr)), itin,
794                        pattern>, RecFormRel;
795     let Defs = [CARRY, CR0] in
796     def o    : XOForm_3<opcode, xo, oe, OOL, IOL,
797                        !strconcat(asmbase, !strconcat(". ", asmstr)), itin,
798                        []>, isDOT, RecFormRel;
799   }
800 }
801
802 multiclass MForm_2r<bits<6> opcode, dag OOL, dag IOL,
803                     string asmbase, string asmstr, InstrItinClass itin,
804                     list<dag> pattern> {
805   let BaseName = asmbase in {
806     def NAME : MForm_2<opcode, OOL, IOL,
807                        !strconcat(asmbase, !strconcat(" ", asmstr)), itin,
808                        pattern>, RecFormRel;
809     let Defs = [CR0] in
810     def o    : MForm_2<opcode, OOL, IOL,
811                        !strconcat(asmbase, !strconcat(". ", asmstr)), itin,
812                        []>, isDOT, RecFormRel;
813   }
814 }
815
816 multiclass MDForm_1r<bits<6> opcode, bits<3> xo, dag OOL, dag IOL,
817                     string asmbase, string asmstr, InstrItinClass itin,
818                     list<dag> pattern> {
819   let BaseName = asmbase in {
820     def NAME : MDForm_1<opcode, xo, OOL, IOL,
821                        !strconcat(asmbase, !strconcat(" ", asmstr)), itin,
822                        pattern>, RecFormRel;
823     let Defs = [CR0] in
824     def o    : MDForm_1<opcode, xo, OOL, IOL,
825                        !strconcat(asmbase, !strconcat(". ", asmstr)), itin,
826                        []>, isDOT, RecFormRel;
827   }
828 }
829
830 multiclass MDSForm_1r<bits<6> opcode, bits<4> xo, dag OOL, dag IOL,
831                      string asmbase, string asmstr, InstrItinClass itin,
832                      list<dag> pattern> {
833   let BaseName = asmbase in {
834     def NAME : MDSForm_1<opcode, xo, OOL, IOL,
835                         !strconcat(asmbase, !strconcat(" ", asmstr)), itin,
836                         pattern>, RecFormRel;
837     let Defs = [CR0] in
838     def o    : MDSForm_1<opcode, xo, OOL, IOL,
839                         !strconcat(asmbase, !strconcat(". ", asmstr)), itin,
840                         []>, isDOT, RecFormRel;
841   }
842 }
843
844 multiclass XSForm_1rc<bits<6> opcode, bits<9> xo, dag OOL, dag IOL,
845                       string asmbase, string asmstr, InstrItinClass itin,
846                       list<dag> pattern> {
847   let BaseName = asmbase in {
848     let Defs = [CARRY] in
849     def NAME : XSForm_1<opcode, xo, OOL, IOL,
850                        !strconcat(asmbase, !strconcat(" ", asmstr)), itin,
851                        pattern>, RecFormRel;
852     let Defs = [CARRY, CR0] in
853     def o    : XSForm_1<opcode, xo, OOL, IOL,
854                        !strconcat(asmbase, !strconcat(". ", asmstr)), itin,
855                        []>, isDOT, RecFormRel;
856   }
857 }
858
859 multiclass XForm_26r<bits<6> opcode, bits<10> xo, dag OOL, dag IOL,
860                     string asmbase, string asmstr, InstrItinClass itin,
861                     list<dag> pattern> {
862   let BaseName = asmbase in {
863     def NAME : XForm_26<opcode, xo, OOL, IOL,
864                        !strconcat(asmbase, !strconcat(" ", asmstr)), itin,
865                        pattern>, RecFormRel;
866     let Defs = [CR1] in
867     def o    : XForm_26<opcode, xo, OOL, IOL,
868                        !strconcat(asmbase, !strconcat(". ", asmstr)), itin,
869                        []>, isDOT, RecFormRel;
870   }
871 }
872
873 multiclass XForm_28r<bits<6> opcode, bits<10> xo, dag OOL, dag IOL,
874                     string asmbase, string asmstr, InstrItinClass itin,
875                     list<dag> pattern> {
876   let BaseName = asmbase in {
877     def NAME : XForm_28<opcode, xo, OOL, IOL,
878                        !strconcat(asmbase, !strconcat(" ", asmstr)), itin,
879                        pattern>, RecFormRel;
880     let Defs = [CR1] in
881     def o    : XForm_28<opcode, xo, OOL, IOL,
882                        !strconcat(asmbase, !strconcat(". ", asmstr)), itin,
883                        []>, isDOT, RecFormRel;
884   }
885 }
886
887 multiclass AForm_1r<bits<6> opcode, bits<5> xo, dag OOL, dag IOL,
888                     string asmbase, string asmstr, InstrItinClass itin,
889                     list<dag> pattern> {
890   let BaseName = asmbase in {
891     def NAME : AForm_1<opcode, xo, OOL, IOL,
892                        !strconcat(asmbase, !strconcat(" ", asmstr)), itin,
893                        pattern>, RecFormRel;
894     let Defs = [CR1] in
895     def o    : AForm_1<opcode, xo, OOL, IOL,
896                        !strconcat(asmbase, !strconcat(". ", asmstr)), itin,
897                        []>, isDOT, RecFormRel;
898   }
899 }
900
901 multiclass AForm_2r<bits<6> opcode, bits<5> xo, dag OOL, dag IOL,
902                     string asmbase, string asmstr, InstrItinClass itin,
903                     list<dag> pattern> {
904   let BaseName = asmbase in {
905     def NAME : AForm_2<opcode, xo, OOL, IOL,
906                        !strconcat(asmbase, !strconcat(" ", asmstr)), itin,
907                        pattern>, RecFormRel;
908     let Defs = [CR1] in
909     def o    : AForm_2<opcode, xo, OOL, IOL,
910                        !strconcat(asmbase, !strconcat(". ", asmstr)), itin,
911                        []>, isDOT, RecFormRel;
912   }
913 }
914
915 multiclass AForm_3r<bits<6> opcode, bits<5> xo, dag OOL, dag IOL,
916                     string asmbase, string asmstr, InstrItinClass itin,
917                     list<dag> pattern> {
918   let BaseName = asmbase in {
919     def NAME : AForm_3<opcode, xo, OOL, IOL,
920                        !strconcat(asmbase, !strconcat(" ", asmstr)), itin,
921                        pattern>, RecFormRel;
922     let Defs = [CR1] in
923     def o    : AForm_3<opcode, xo, OOL, IOL,
924                        !strconcat(asmbase, !strconcat(". ", asmstr)), itin,
925                        []>, isDOT, RecFormRel;
926   }
927 }
928
929 //===----------------------------------------------------------------------===//
930 // PowerPC Instruction Definitions.
931
932 // Pseudo-instructions:
933
934 let hasCtrlDep = 1 in {
935 let Defs = [R1], Uses = [R1] in {
936 def ADJCALLSTACKDOWN : Pseudo<(outs), (ins u16imm:$amt), "#ADJCALLSTACKDOWN $amt",
937                               [(callseq_start timm:$amt)]>;
938 def ADJCALLSTACKUP   : Pseudo<(outs), (ins u16imm:$amt1, u16imm:$amt2), "#ADJCALLSTACKUP $amt1 $amt2",
939                               [(callseq_end timm:$amt1, timm:$amt2)]>;
940 }
941
942 def UPDATE_VRSAVE    : Pseudo<(outs gprc:$rD), (ins gprc:$rS),
943                               "UPDATE_VRSAVE $rD, $rS", []>;
944 }
945
946 let Defs = [R1], Uses = [R1] in
947 def DYNALLOC : Pseudo<(outs gprc:$result), (ins gprc:$negsize, memri:$fpsi), "#DYNALLOC",
948                        [(set i32:$result,
949                              (PPCdynalloc i32:$negsize, iaddr:$fpsi))]>;
950                          
951 // SELECT_CC_* - Used to implement the SELECT_CC DAG operation.  Expanded after
952 // instruction selection into a branch sequence.
953 let usesCustomInserter = 1,    // Expanded after instruction selection.
954     PPC970_Single = 1 in {
955   // Note that SELECT_CC_I4 and SELECT_CC_I8 use the no-r0 register classes
956   // because either operand might become the first operand in an isel, and
957   // that operand cannot be r0.
958   def SELECT_CC_I4 : Pseudo<(outs gprc:$dst), (ins crrc:$cond,
959                               gprc_nor0:$T, gprc_nor0:$F,
960                               i32imm:$BROPC), "#SELECT_CC_I4",
961                               []>;
962   def SELECT_CC_I8 : Pseudo<(outs g8rc:$dst), (ins crrc:$cond,
963                               g8rc_nox0:$T, g8rc_nox0:$F,
964                               i32imm:$BROPC), "#SELECT_CC_I8",
965                               []>;
966   def SELECT_CC_F4  : Pseudo<(outs f4rc:$dst), (ins crrc:$cond, f4rc:$T, f4rc:$F,
967                               i32imm:$BROPC), "#SELECT_CC_F4",
968                               []>;
969   def SELECT_CC_F8  : Pseudo<(outs f8rc:$dst), (ins crrc:$cond, f8rc:$T, f8rc:$F,
970                               i32imm:$BROPC), "#SELECT_CC_F8",
971                               []>;
972   def SELECT_CC_VRRC: Pseudo<(outs vrrc:$dst), (ins crrc:$cond, vrrc:$T, vrrc:$F,
973                               i32imm:$BROPC), "#SELECT_CC_VRRC",
974                               []>;
975
976   // SELECT_* pseudo instructions, like SELECT_CC_* but taking condition
977   // register bit directly.
978   def SELECT_I4 : Pseudo<(outs gprc:$dst), (ins crbitrc:$cond,
979                           gprc_nor0:$T, gprc_nor0:$F), "#SELECT_I4",
980                           [(set i32:$dst, (select i1:$cond, i32:$T, i32:$F))]>;
981   def SELECT_I8 : Pseudo<(outs g8rc:$dst), (ins crbitrc:$cond,
982                           g8rc_nox0:$T, g8rc_nox0:$F), "#SELECT_I8",
983                           [(set i64:$dst, (select i1:$cond, i64:$T, i64:$F))]>;
984   def SELECT_F4  : Pseudo<(outs f4rc:$dst), (ins crbitrc:$cond,
985                           f4rc:$T, f4rc:$F), "#SELECT_F4",
986                           [(set f32:$dst, (select i1:$cond, f32:$T, f32:$F))]>;
987   def SELECT_F8  : Pseudo<(outs f8rc:$dst), (ins crbitrc:$cond,
988                           f8rc:$T, f8rc:$F), "#SELECT_F8",
989                           [(set f64:$dst, (select i1:$cond, f64:$T, f64:$F))]>;
990   def SELECT_VRRC: Pseudo<(outs vrrc:$dst), (ins crbitrc:$cond,
991                           vrrc:$T, vrrc:$F), "#SELECT_VRRC",
992                           [(set v4i32:$dst,
993                                 (select i1:$cond, v4i32:$T, v4i32:$F))]>;
994 }
995
996 // SPILL_CR - Indicate that we're dumping the CR register, so we'll need to
997 // scavenge a register for it.
998 let mayStore = 1 in {
999 def SPILL_CR : Pseudo<(outs), (ins crrc:$cond, memri:$F),
1000                      "#SPILL_CR", []>;
1001 def SPILL_CRBIT : Pseudo<(outs), (ins crbitrc:$cond, memri:$F),
1002                          "#SPILL_CRBIT", []>;
1003 }
1004
1005 // RESTORE_CR - Indicate that we're restoring the CR register (previously
1006 // spilled), so we'll need to scavenge a register for it.
1007 let mayLoad = 1 in {
1008 def RESTORE_CR : Pseudo<(outs crrc:$cond), (ins memri:$F),
1009                      "#RESTORE_CR", []>;
1010 def RESTORE_CRBIT : Pseudo<(outs crbitrc:$cond), (ins memri:$F),
1011                            "#RESTORE_CRBIT", []>;
1012 }
1013
1014 let isTerminator = 1, isBarrier = 1, PPC970_Unit = 7 in {
1015   let isReturn = 1, Uses = [LR, RM] in
1016     def BLR : XLForm_2_ext<19, 16, 20, 0, 0, (outs), (ins), "blr", IIC_BrB,
1017                            [(retflag)]>;
1018   let isBranch = 1, isIndirectBranch = 1, Uses = [CTR] in {
1019     def BCTR : XLForm_2_ext<19, 528, 20, 0, 0, (outs), (ins), "bctr", IIC_BrB,
1020                             []>;
1021
1022     let isCodeGenOnly = 1 in {
1023       def BCCCTR : XLForm_2_br<19, 528, 0, (outs), (ins pred:$cond),
1024                                "b${cond:cc}ctr${cond:pm} ${cond:reg}", IIC_BrB,
1025                                []>;
1026
1027       def BCCTR :  XLForm_2_br2<19, 528, 12, 0, (outs), (ins crbitrc:$bi),
1028                                 "bcctr 12, $bi, 0", IIC_BrB, []>;
1029       def BCCTRn : XLForm_2_br2<19, 528, 4, 0, (outs), (ins crbitrc:$bi),
1030                                 "bcctr 4, $bi, 0", IIC_BrB, []>;
1031     }
1032   }
1033 }
1034
1035 let Defs = [LR] in
1036   def MovePCtoLR : Pseudo<(outs), (ins), "#MovePCtoLR", []>,
1037                    PPC970_Unit_BRU;
1038 let Defs = [LR] in
1039   def MoveGOTtoLR : Pseudo<(outs), (ins), "#MoveGOTtoLR", []>,
1040                     PPC970_Unit_BRU;
1041
1042 let isBranch = 1, isTerminator = 1, hasCtrlDep = 1, PPC970_Unit = 7 in {
1043   let isBarrier = 1 in {
1044   def B   : IForm<18, 0, 0, (outs), (ins directbrtarget:$dst),
1045                   "b $dst", IIC_BrB,
1046                   [(br bb:$dst)]>;
1047   def BA  : IForm<18, 1, 0, (outs), (ins absdirectbrtarget:$dst),
1048                   "ba $dst", IIC_BrB, []>;
1049   }
1050
1051   // BCC represents an arbitrary conditional branch on a predicate.
1052   // FIXME: should be able to write a pattern for PPCcondbranch, but can't use
1053   // a two-value operand where a dag node expects two operands. :(
1054   let isCodeGenOnly = 1 in {
1055     def BCC : BForm<16, 0, 0, (outs), (ins pred:$cond, condbrtarget:$dst),
1056                     "b${cond:cc}${cond:pm} ${cond:reg}, $dst"
1057                     /*[(PPCcondbranch crrc:$crS, imm:$opc, bb:$dst)]*/>;
1058     def BCCA : BForm<16, 1, 0, (outs), (ins pred:$cond, abscondbrtarget:$dst),
1059                      "b${cond:cc}a${cond:pm} ${cond:reg}, $dst">;
1060
1061     let isReturn = 1, Uses = [LR, RM] in
1062     def BCCLR : XLForm_2_br<19, 16, 0, (outs), (ins pred:$cond),
1063                            "b${cond:cc}lr${cond:pm} ${cond:reg}", IIC_BrB, []>;
1064   }
1065
1066   let isCodeGenOnly = 1 in {
1067     let Pattern = [(brcond i1:$bi, bb:$dst)] in
1068     def BC  : BForm_4<16, 12, 0, 0, (outs), (ins crbitrc:$bi, condbrtarget:$dst),
1069              "bc 12, $bi, $dst">;
1070
1071     let Pattern = [(brcond (not i1:$bi), bb:$dst)] in
1072     def BCn : BForm_4<16, 4, 0, 0, (outs), (ins crbitrc:$bi, condbrtarget:$dst),
1073              "bc 4, $bi, $dst">;
1074
1075     let isReturn = 1, Uses = [LR, RM] in
1076     def BCLR  : XLForm_2_br2<19, 16, 12, 0, (outs), (ins crbitrc:$bi),
1077                              "bclr 12, $bi, 0", IIC_BrB, []>;
1078     def BCLRn : XLForm_2_br2<19, 16, 4, 0, (outs), (ins crbitrc:$bi),
1079                              "bclr 4, $bi, 0", IIC_BrB, []>;
1080   }
1081
1082   let isReturn = 1, Defs = [CTR], Uses = [CTR, LR, RM] in {
1083    def BDZLR  : XLForm_2_ext<19, 16, 18, 0, 0, (outs), (ins),
1084                              "bdzlr", IIC_BrB, []>;
1085    def BDNZLR : XLForm_2_ext<19, 16, 16, 0, 0, (outs), (ins),
1086                              "bdnzlr", IIC_BrB, []>;
1087    def BDZLRp : XLForm_2_ext<19, 16, 27, 0, 0, (outs), (ins),
1088                              "bdzlr+", IIC_BrB, []>;
1089    def BDNZLRp: XLForm_2_ext<19, 16, 25, 0, 0, (outs), (ins),
1090                              "bdnzlr+", IIC_BrB, []>;
1091    def BDZLRm : XLForm_2_ext<19, 16, 26, 0, 0, (outs), (ins),
1092                              "bdzlr-", IIC_BrB, []>;
1093    def BDNZLRm: XLForm_2_ext<19, 16, 24, 0, 0, (outs), (ins),
1094                              "bdnzlr-", IIC_BrB, []>;
1095   }
1096
1097   let Defs = [CTR], Uses = [CTR] in {
1098     def BDZ  : BForm_1<16, 18, 0, 0, (outs), (ins condbrtarget:$dst),
1099                        "bdz $dst">;
1100     def BDNZ : BForm_1<16, 16, 0, 0, (outs), (ins condbrtarget:$dst),
1101                        "bdnz $dst">;
1102     def BDZA  : BForm_1<16, 18, 1, 0, (outs), (ins abscondbrtarget:$dst),
1103                         "bdza $dst">;
1104     def BDNZA : BForm_1<16, 16, 1, 0, (outs), (ins abscondbrtarget:$dst),
1105                         "bdnza $dst">;
1106     def BDZp : BForm_1<16, 27, 0, 0, (outs), (ins condbrtarget:$dst),
1107                        "bdz+ $dst">;
1108     def BDNZp: BForm_1<16, 25, 0, 0, (outs), (ins condbrtarget:$dst),
1109                        "bdnz+ $dst">;
1110     def BDZAp : BForm_1<16, 27, 1, 0, (outs), (ins abscondbrtarget:$dst),
1111                         "bdza+ $dst">;
1112     def BDNZAp: BForm_1<16, 25, 1, 0, (outs), (ins abscondbrtarget:$dst),
1113                         "bdnza+ $dst">;
1114     def BDZm : BForm_1<16, 26, 0, 0, (outs), (ins condbrtarget:$dst),
1115                        "bdz- $dst">;
1116     def BDNZm: BForm_1<16, 24, 0, 0, (outs), (ins condbrtarget:$dst),
1117                        "bdnz- $dst">;
1118     def BDZAm : BForm_1<16, 26, 1, 0, (outs), (ins abscondbrtarget:$dst),
1119                         "bdza- $dst">;
1120     def BDNZAm: BForm_1<16, 24, 1, 0, (outs), (ins abscondbrtarget:$dst),
1121                         "bdnza- $dst">;
1122   }
1123 }
1124
1125 // The unconditional BCL used by the SjLj setjmp code.
1126 let isCall = 1, hasCtrlDep = 1, isCodeGenOnly = 1, PPC970_Unit = 7 in {
1127   let Defs = [LR], Uses = [RM] in {
1128     def BCLalways  : BForm_2<16, 20, 31, 0, 1, (outs), (ins condbrtarget:$dst),
1129                             "bcl 20, 31, $dst">;
1130   }
1131 }
1132
1133 let isCall = 1, PPC970_Unit = 7, Defs = [LR] in {
1134   // Convenient aliases for call instructions
1135   let Uses = [RM] in {
1136     def BL  : IForm<18, 0, 1, (outs), (ins calltarget:$func),
1137                     "bl $func", IIC_BrB, []>;  // See Pat patterns below.
1138     def BLA : IForm<18, 1, 1, (outs), (ins abscalltarget:$func),
1139                     "bla $func", IIC_BrB, [(PPCcall (i32 imm:$func))]>;
1140
1141     let isCodeGenOnly = 1 in {
1142       def BL_TLS  : IForm<18, 0, 1, (outs), (ins tlscall32:$func),
1143                           "bl $func", IIC_BrB, []>;
1144       def BCCL : BForm<16, 0, 1, (outs), (ins pred:$cond, condbrtarget:$dst),
1145                        "b${cond:cc}l${cond:pm} ${cond:reg}, $dst">;
1146       def BCCLA : BForm<16, 1, 1, (outs), (ins pred:$cond, abscondbrtarget:$dst),
1147                         "b${cond:cc}la${cond:pm} ${cond:reg}, $dst">;
1148
1149       def BCL  : BForm_4<16, 12, 0, 1, (outs),
1150                          (ins crbitrc:$bi, condbrtarget:$dst),
1151                          "bcl 12, $bi, $dst">;
1152       def BCLn : BForm_4<16, 4, 0, 1, (outs),
1153                          (ins crbitrc:$bi, condbrtarget:$dst),
1154                          "bcl 4, $bi, $dst">;
1155     }
1156   }
1157   let Uses = [CTR, RM] in {
1158     def BCTRL : XLForm_2_ext<19, 528, 20, 0, 1, (outs), (ins),
1159                              "bctrl", IIC_BrB, [(PPCbctrl)]>,
1160                 Requires<[In32BitMode]>;
1161
1162     let isCodeGenOnly = 1 in {
1163       def BCCCTRL : XLForm_2_br<19, 528, 1, (outs), (ins pred:$cond),
1164                                 "b${cond:cc}ctrl${cond:pm} ${cond:reg}", IIC_BrB,
1165                                 []>;
1166
1167       def BCCTRL  : XLForm_2_br2<19, 528, 12, 1, (outs), (ins crbitrc:$bi),
1168                                  "bcctrl 12, $bi, 0", IIC_BrB, []>;
1169       def BCCTRLn : XLForm_2_br2<19, 528, 4, 1, (outs), (ins crbitrc:$bi),
1170                                  "bcctrl 4, $bi, 0", IIC_BrB, []>;
1171     }
1172   }
1173   let Uses = [LR, RM] in {
1174     def BLRL : XLForm_2_ext<19, 16, 20, 0, 1, (outs), (ins),
1175                             "blrl", IIC_BrB, []>;
1176
1177     let isCodeGenOnly = 1 in {
1178       def BCCLRL : XLForm_2_br<19, 16, 1, (outs), (ins pred:$cond),
1179                               "b${cond:cc}lrl${cond:pm} ${cond:reg}", IIC_BrB,
1180                               []>;
1181
1182       def BCLRL  : XLForm_2_br2<19, 16, 12, 1, (outs), (ins crbitrc:$bi),
1183                                 "bclrl 12, $bi, 0", IIC_BrB, []>;
1184       def BCLRLn : XLForm_2_br2<19, 16, 4, 1, (outs), (ins crbitrc:$bi),
1185                                 "bclrl 4, $bi, 0", IIC_BrB, []>;
1186     }
1187   }
1188   let Defs = [CTR], Uses = [CTR, RM] in {
1189     def BDZL  : BForm_1<16, 18, 0, 1, (outs), (ins condbrtarget:$dst),
1190                         "bdzl $dst">;
1191     def BDNZL : BForm_1<16, 16, 0, 1, (outs), (ins condbrtarget:$dst),
1192                         "bdnzl $dst">;
1193     def BDZLA  : BForm_1<16, 18, 1, 1, (outs), (ins abscondbrtarget:$dst),
1194                          "bdzla $dst">;
1195     def BDNZLA : BForm_1<16, 16, 1, 1, (outs), (ins abscondbrtarget:$dst),
1196                          "bdnzla $dst">;
1197     def BDZLp : BForm_1<16, 27, 0, 1, (outs), (ins condbrtarget:$dst),
1198                         "bdzl+ $dst">;
1199     def BDNZLp: BForm_1<16, 25, 0, 1, (outs), (ins condbrtarget:$dst),
1200                         "bdnzl+ $dst">;
1201     def BDZLAp : BForm_1<16, 27, 1, 1, (outs), (ins abscondbrtarget:$dst),
1202                          "bdzla+ $dst">;
1203     def BDNZLAp: BForm_1<16, 25, 1, 1, (outs), (ins abscondbrtarget:$dst),
1204                          "bdnzla+ $dst">;
1205     def BDZLm : BForm_1<16, 26, 0, 1, (outs), (ins condbrtarget:$dst),
1206                         "bdzl- $dst">;
1207     def BDNZLm: BForm_1<16, 24, 0, 1, (outs), (ins condbrtarget:$dst),
1208                         "bdnzl- $dst">;
1209     def BDZLAm : BForm_1<16, 26, 1, 1, (outs), (ins abscondbrtarget:$dst),
1210                          "bdzla- $dst">;
1211     def BDNZLAm: BForm_1<16, 24, 1, 1, (outs), (ins abscondbrtarget:$dst),
1212                          "bdnzla- $dst">;
1213   }
1214   let Defs = [CTR], Uses = [CTR, LR, RM] in {
1215     def BDZLRL  : XLForm_2_ext<19, 16, 18, 0, 1, (outs), (ins),
1216                                "bdzlrl", IIC_BrB, []>;
1217     def BDNZLRL : XLForm_2_ext<19, 16, 16, 0, 1, (outs), (ins),
1218                                "bdnzlrl", IIC_BrB, []>;
1219     def BDZLRLp : XLForm_2_ext<19, 16, 27, 0, 1, (outs), (ins),
1220                                "bdzlrl+", IIC_BrB, []>;
1221     def BDNZLRLp: XLForm_2_ext<19, 16, 25, 0, 1, (outs), (ins),
1222                                "bdnzlrl+", IIC_BrB, []>;
1223     def BDZLRLm : XLForm_2_ext<19, 16, 26, 0, 1, (outs), (ins),
1224                                "bdzlrl-", IIC_BrB, []>;
1225     def BDNZLRLm: XLForm_2_ext<19, 16, 24, 0, 1, (outs), (ins),
1226                                "bdnzlrl-", IIC_BrB, []>;
1227   }
1228 }
1229
1230 let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1, Uses = [RM] in
1231 def TCRETURNdi :Pseudo< (outs),
1232                         (ins calltarget:$dst, i32imm:$offset),
1233                  "#TC_RETURNd $dst $offset",
1234                  []>;
1235
1236
1237 let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1, Uses = [RM] in
1238 def TCRETURNai :Pseudo<(outs), (ins abscalltarget:$func, i32imm:$offset),
1239                  "#TC_RETURNa $func $offset",
1240                  [(PPCtc_return (i32 imm:$func), imm:$offset)]>;
1241
1242 let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1, Uses = [RM] in
1243 def TCRETURNri : Pseudo<(outs), (ins CTRRC:$dst, i32imm:$offset),
1244                  "#TC_RETURNr $dst $offset",
1245                  []>;
1246
1247
1248 let isCodeGenOnly = 1 in {
1249
1250 let isTerminator = 1, isBarrier = 1, PPC970_Unit = 7, isBranch = 1,
1251     isIndirectBranch = 1, isCall = 1, isReturn = 1, Uses = [CTR, RM]  in
1252 def TAILBCTR : XLForm_2_ext<19, 528, 20, 0, 0, (outs), (ins), "bctr", IIC_BrB,
1253                             []>, Requires<[In32BitMode]>;
1254
1255 let isBranch = 1, isTerminator = 1, hasCtrlDep = 1, PPC970_Unit = 7,
1256     isBarrier = 1, isCall = 1, isReturn = 1, Uses = [RM] in
1257 def TAILB   : IForm<18, 0, 0, (outs), (ins calltarget:$dst),
1258                   "b $dst", IIC_BrB,
1259                   []>;
1260
1261 let isBranch = 1, isTerminator = 1, hasCtrlDep = 1, PPC970_Unit = 7,
1262     isBarrier = 1, isCall = 1, isReturn = 1, Uses = [RM] in
1263 def TAILBA   : IForm<18, 0, 0, (outs), (ins abscalltarget:$dst),
1264                   "ba $dst", IIC_BrB,
1265                   []>;
1266
1267 }
1268
1269 let hasSideEffects = 1, isBarrier = 1, usesCustomInserter = 1 in {
1270   let Defs = [CTR] in
1271   def EH_SjLj_SetJmp32  : Pseudo<(outs gprc:$dst), (ins memr:$buf),
1272                             "#EH_SJLJ_SETJMP32",
1273                             [(set i32:$dst, (PPCeh_sjlj_setjmp addr:$buf))]>,
1274                           Requires<[In32BitMode]>;
1275   let isTerminator = 1 in
1276   def EH_SjLj_LongJmp32 : Pseudo<(outs), (ins memr:$buf),
1277                             "#EH_SJLJ_LONGJMP32",
1278                             [(PPCeh_sjlj_longjmp addr:$buf)]>,
1279                           Requires<[In32BitMode]>;
1280 }
1281
1282 let isBranch = 1, isTerminator = 1 in {
1283   def EH_SjLj_Setup : Pseudo<(outs), (ins directbrtarget:$dst),
1284                         "#EH_SjLj_Setup\t$dst", []>;
1285 }
1286
1287 // System call.
1288 let PPC970_Unit = 7 in {
1289   def SC     : SCForm<17, 1, (outs), (ins i32imm:$lev),
1290                       "sc $lev", IIC_BrB, [(PPCsc (i32 imm:$lev))]>;
1291 }
1292
1293 // DCB* instructions.
1294 def DCBA   : DCB_Form<758, 0, (outs), (ins memrr:$dst), "dcba $dst",
1295                       IIC_LdStDCBF, [(int_ppc_dcba xoaddr:$dst)]>,
1296                       PPC970_DGroup_Single;
1297 def DCBF   : DCB_Form<86, 0, (outs), (ins memrr:$dst), "dcbf $dst",
1298                       IIC_LdStDCBF, [(int_ppc_dcbf xoaddr:$dst)]>,
1299                       PPC970_DGroup_Single;
1300 def DCBI   : DCB_Form<470, 0, (outs), (ins memrr:$dst), "dcbi $dst",
1301                       IIC_LdStDCBF, [(int_ppc_dcbi xoaddr:$dst)]>,
1302                       PPC970_DGroup_Single;
1303 def DCBST  : DCB_Form<54, 0, (outs), (ins memrr:$dst), "dcbst $dst",
1304                       IIC_LdStDCBF, [(int_ppc_dcbst xoaddr:$dst)]>,
1305                       PPC970_DGroup_Single;
1306 def DCBT   : DCB_Form<278, 0, (outs), (ins memrr:$dst), "dcbt $dst",
1307                       IIC_LdStDCBF, [(int_ppc_dcbt xoaddr:$dst)]>,
1308                       PPC970_DGroup_Single;
1309 def DCBTST : DCB_Form<246, 0, (outs), (ins memrr:$dst), "dcbtst $dst",
1310                       IIC_LdStDCBF, [(int_ppc_dcbtst xoaddr:$dst)]>,
1311                       PPC970_DGroup_Single;
1312 def DCBZ   : DCB_Form<1014, 0, (outs), (ins memrr:$dst), "dcbz $dst",
1313                       IIC_LdStDCBF, [(int_ppc_dcbz xoaddr:$dst)]>,
1314                       PPC970_DGroup_Single;
1315 def DCBZL  : DCB_Form<1014, 1, (outs), (ins memrr:$dst), "dcbzl $dst",
1316                       IIC_LdStDCBF, [(int_ppc_dcbzl xoaddr:$dst)]>,
1317                       PPC970_DGroup_Single;
1318
1319 def ICBT  : XForm_icbt<31, 22, (outs), (ins u4imm:$CT, memrr:$src),
1320                        "icbt $CT, $src", IIC_LdStLoad>, Requires<[IsBookE]>;
1321
1322 def : Pat<(prefetch xoaddr:$dst, (i32 0), imm, (i32 1)),
1323           (DCBT xoaddr:$dst)>;   // data prefetch for loads
1324 def : Pat<(prefetch xoaddr:$dst, (i32 1), imm, (i32 1)),
1325           (DCBTST xoaddr:$dst)>; // data prefetch for stores
1326 def : Pat<(prefetch xoaddr:$dst, (i32 0), imm, (i32 0)),
1327           (ICBT 0, xoaddr:$dst)>; // inst prefetch (for read)
1328
1329 // Atomic operations
1330 let usesCustomInserter = 1 in {
1331   let Defs = [CR0] in {
1332     def ATOMIC_LOAD_ADD_I8 : Pseudo<
1333       (outs gprc:$dst), (ins memrr:$ptr, gprc:$incr), "#ATOMIC_LOAD_ADD_I8",
1334       [(set i32:$dst, (atomic_load_add_8 xoaddr:$ptr, i32:$incr))]>;
1335     def ATOMIC_LOAD_SUB_I8 : Pseudo<
1336       (outs gprc:$dst), (ins memrr:$ptr, gprc:$incr), "#ATOMIC_LOAD_SUB_I8",
1337       [(set i32:$dst, (atomic_load_sub_8 xoaddr:$ptr, i32:$incr))]>;
1338     def ATOMIC_LOAD_AND_I8 : Pseudo<
1339       (outs gprc:$dst), (ins memrr:$ptr, gprc:$incr), "#ATOMIC_LOAD_AND_I8",
1340       [(set i32:$dst, (atomic_load_and_8 xoaddr:$ptr, i32:$incr))]>;
1341     def ATOMIC_LOAD_OR_I8 : Pseudo<
1342       (outs gprc:$dst), (ins memrr:$ptr, gprc:$incr), "#ATOMIC_LOAD_OR_I8",
1343       [(set i32:$dst, (atomic_load_or_8 xoaddr:$ptr, i32:$incr))]>;
1344     def ATOMIC_LOAD_XOR_I8 : Pseudo<
1345       (outs gprc:$dst), (ins memrr:$ptr, gprc:$incr), "ATOMIC_LOAD_XOR_I8",
1346       [(set i32:$dst, (atomic_load_xor_8 xoaddr:$ptr, i32:$incr))]>;
1347     def ATOMIC_LOAD_NAND_I8 : Pseudo<
1348       (outs gprc:$dst), (ins memrr:$ptr, gprc:$incr), "#ATOMIC_LOAD_NAND_I8",
1349       [(set i32:$dst, (atomic_load_nand_8 xoaddr:$ptr, i32:$incr))]>;
1350     def ATOMIC_LOAD_ADD_I16 : Pseudo<
1351       (outs gprc:$dst), (ins memrr:$ptr, gprc:$incr), "#ATOMIC_LOAD_ADD_I16",
1352       [(set i32:$dst, (atomic_load_add_16 xoaddr:$ptr, i32:$incr))]>;
1353     def ATOMIC_LOAD_SUB_I16 : Pseudo<
1354       (outs gprc:$dst), (ins memrr:$ptr, gprc:$incr), "#ATOMIC_LOAD_SUB_I16",
1355       [(set i32:$dst, (atomic_load_sub_16 xoaddr:$ptr, i32:$incr))]>;
1356     def ATOMIC_LOAD_AND_I16 : Pseudo<
1357       (outs gprc:$dst), (ins memrr:$ptr, gprc:$incr), "#ATOMIC_LOAD_AND_I16",
1358       [(set i32:$dst, (atomic_load_and_16 xoaddr:$ptr, i32:$incr))]>;
1359     def ATOMIC_LOAD_OR_I16 : Pseudo<
1360       (outs gprc:$dst), (ins memrr:$ptr, gprc:$incr), "#ATOMIC_LOAD_OR_I16",
1361       [(set i32:$dst, (atomic_load_or_16 xoaddr:$ptr, i32:$incr))]>;
1362     def ATOMIC_LOAD_XOR_I16 : Pseudo<
1363       (outs gprc:$dst), (ins memrr:$ptr, gprc:$incr), "#ATOMIC_LOAD_XOR_I16",
1364       [(set i32:$dst, (atomic_load_xor_16 xoaddr:$ptr, i32:$incr))]>;
1365     def ATOMIC_LOAD_NAND_I16 : Pseudo<
1366       (outs gprc:$dst), (ins memrr:$ptr, gprc:$incr), "#ATOMIC_LOAD_NAND_I16",
1367       [(set i32:$dst, (atomic_load_nand_16 xoaddr:$ptr, i32:$incr))]>;
1368     def ATOMIC_LOAD_ADD_I32 : Pseudo<
1369       (outs gprc:$dst), (ins memrr:$ptr, gprc:$incr), "#ATOMIC_LOAD_ADD_I32",
1370       [(set i32:$dst, (atomic_load_add_32 xoaddr:$ptr, i32:$incr))]>;
1371     def ATOMIC_LOAD_SUB_I32 : Pseudo<
1372       (outs gprc:$dst), (ins memrr:$ptr, gprc:$incr), "#ATOMIC_LOAD_SUB_I32",
1373       [(set i32:$dst, (atomic_load_sub_32 xoaddr:$ptr, i32:$incr))]>;
1374     def ATOMIC_LOAD_AND_I32 : Pseudo<
1375       (outs gprc:$dst), (ins memrr:$ptr, gprc:$incr), "#ATOMIC_LOAD_AND_I32",
1376       [(set i32:$dst, (atomic_load_and_32 xoaddr:$ptr, i32:$incr))]>;
1377     def ATOMIC_LOAD_OR_I32 : Pseudo<
1378       (outs gprc:$dst), (ins memrr:$ptr, gprc:$incr), "#ATOMIC_LOAD_OR_I32",
1379       [(set i32:$dst, (atomic_load_or_32 xoaddr:$ptr, i32:$incr))]>;
1380     def ATOMIC_LOAD_XOR_I32 : Pseudo<
1381       (outs gprc:$dst), (ins memrr:$ptr, gprc:$incr), "#ATOMIC_LOAD_XOR_I32",
1382       [(set i32:$dst, (atomic_load_xor_32 xoaddr:$ptr, i32:$incr))]>;
1383     def ATOMIC_LOAD_NAND_I32 : Pseudo<
1384       (outs gprc:$dst), (ins memrr:$ptr, gprc:$incr), "#ATOMIC_LOAD_NAND_I32",
1385       [(set i32:$dst, (atomic_load_nand_32 xoaddr:$ptr, i32:$incr))]>;
1386
1387     def ATOMIC_CMP_SWAP_I8 : Pseudo<
1388       (outs gprc:$dst), (ins memrr:$ptr, gprc:$old, gprc:$new), "#ATOMIC_CMP_SWAP_I8",
1389       [(set i32:$dst, (atomic_cmp_swap_8 xoaddr:$ptr, i32:$old, i32:$new))]>;
1390     def ATOMIC_CMP_SWAP_I16 : Pseudo<
1391       (outs gprc:$dst), (ins memrr:$ptr, gprc:$old, gprc:$new), "#ATOMIC_CMP_SWAP_I16 $dst $ptr $old $new",
1392       [(set i32:$dst, (atomic_cmp_swap_16 xoaddr:$ptr, i32:$old, i32:$new))]>;
1393     def ATOMIC_CMP_SWAP_I32 : Pseudo<
1394       (outs gprc:$dst), (ins memrr:$ptr, gprc:$old, gprc:$new), "#ATOMIC_CMP_SWAP_I32 $dst $ptr $old $new",
1395       [(set i32:$dst, (atomic_cmp_swap_32 xoaddr:$ptr, i32:$old, i32:$new))]>;
1396
1397     def ATOMIC_SWAP_I8 : Pseudo<
1398       (outs gprc:$dst), (ins memrr:$ptr, gprc:$new), "#ATOMIC_SWAP_i8",
1399       [(set i32:$dst, (atomic_swap_8 xoaddr:$ptr, i32:$new))]>;
1400     def ATOMIC_SWAP_I16 : Pseudo<
1401       (outs gprc:$dst), (ins memrr:$ptr, gprc:$new), "#ATOMIC_SWAP_I16",
1402       [(set i32:$dst, (atomic_swap_16 xoaddr:$ptr, i32:$new))]>;
1403     def ATOMIC_SWAP_I32 : Pseudo<
1404       (outs gprc:$dst), (ins memrr:$ptr, gprc:$new), "#ATOMIC_SWAP_I32",
1405       [(set i32:$dst, (atomic_swap_32 xoaddr:$ptr, i32:$new))]>;
1406   }
1407 }
1408
1409 // Instructions to support atomic operations
1410 def LWARX : XForm_1<31,  20, (outs gprc:$rD), (ins memrr:$src),
1411                    "lwarx $rD, $src", IIC_LdStLWARX,
1412                    [(set i32:$rD, (PPClarx xoaddr:$src))]>;
1413
1414 let Defs = [CR0] in
1415 def STWCX : XForm_1<31, 150, (outs), (ins gprc:$rS, memrr:$dst),
1416                    "stwcx. $rS, $dst", IIC_LdStSTWCX,
1417                    [(PPCstcx i32:$rS, xoaddr:$dst)]>,
1418                    isDOT;
1419
1420 let isTerminator = 1, isBarrier = 1, hasCtrlDep = 1 in
1421 def TRAP  : XForm_24<31, 4, (outs), (ins), "trap", IIC_LdStLoad, [(trap)]>;
1422
1423 def TWI : DForm_base<3, (outs), (ins u5imm:$to, gprc:$rA, s16imm:$imm),
1424                      "twi $to, $rA, $imm", IIC_IntTrapW, []>;
1425 def TW : XForm_1<31, 4, (outs), (ins u5imm:$to, gprc:$rA, gprc:$rB),
1426                  "tw $to, $rA, $rB", IIC_IntTrapW, []>;
1427 def TDI : DForm_base<2, (outs), (ins u5imm:$to, g8rc:$rA, s16imm:$imm),
1428                      "tdi $to, $rA, $imm", IIC_IntTrapD, []>;
1429 def TD : XForm_1<31, 68, (outs), (ins u5imm:$to, g8rc:$rA, g8rc:$rB),
1430                  "td $to, $rA, $rB", IIC_IntTrapD, []>;
1431
1432 //===----------------------------------------------------------------------===//
1433 // PPC32 Load Instructions.
1434 //
1435
1436 // Unindexed (r+i) Loads. 
1437 let canFoldAsLoad = 1, PPC970_Unit = 2 in {
1438 def LBZ : DForm_1<34, (outs gprc:$rD), (ins memri:$src),
1439                   "lbz $rD, $src", IIC_LdStLoad,
1440                   [(set i32:$rD, (zextloadi8 iaddr:$src))]>;
1441 def LHA : DForm_1<42, (outs gprc:$rD), (ins memri:$src),
1442                   "lha $rD, $src", IIC_LdStLHA,
1443                   [(set i32:$rD, (sextloadi16 iaddr:$src))]>,
1444                   PPC970_DGroup_Cracked;
1445 def LHZ : DForm_1<40, (outs gprc:$rD), (ins memri:$src),
1446                   "lhz $rD, $src", IIC_LdStLoad,
1447                   [(set i32:$rD, (zextloadi16 iaddr:$src))]>;
1448 def LWZ : DForm_1<32, (outs gprc:$rD), (ins memri:$src),
1449                   "lwz $rD, $src", IIC_LdStLoad,
1450                   [(set i32:$rD, (load iaddr:$src))]>;
1451
1452 def LFS : DForm_1<48, (outs f4rc:$rD), (ins memri:$src),
1453                   "lfs $rD, $src", IIC_LdStLFD,
1454                   [(set f32:$rD, (load iaddr:$src))]>;
1455 def LFD : DForm_1<50, (outs f8rc:$rD), (ins memri:$src),
1456                   "lfd $rD, $src", IIC_LdStLFD,
1457                   [(set f64:$rD, (load iaddr:$src))]>;
1458
1459
1460 // Unindexed (r+i) Loads with Update (preinc).
1461 let mayLoad = 1, hasSideEffects = 0 in {
1462 def LBZU : DForm_1<35, (outs gprc:$rD, ptr_rc_nor0:$ea_result), (ins memri:$addr),
1463                    "lbzu $rD, $addr", IIC_LdStLoadUpd,
1464                    []>, RegConstraint<"$addr.reg = $ea_result">,
1465                    NoEncode<"$ea_result">;
1466
1467 def LHAU : DForm_1<43, (outs gprc:$rD, ptr_rc_nor0:$ea_result), (ins memri:$addr),
1468                    "lhau $rD, $addr", IIC_LdStLHAU,
1469                    []>, RegConstraint<"$addr.reg = $ea_result">,
1470                    NoEncode<"$ea_result">;
1471
1472 def LHZU : DForm_1<41, (outs gprc:$rD, ptr_rc_nor0:$ea_result), (ins memri:$addr),
1473                    "lhzu $rD, $addr", IIC_LdStLoadUpd,
1474                    []>, RegConstraint<"$addr.reg = $ea_result">,
1475                    NoEncode<"$ea_result">;
1476
1477 def LWZU : DForm_1<33, (outs gprc:$rD, ptr_rc_nor0:$ea_result), (ins memri:$addr),
1478                    "lwzu $rD, $addr", IIC_LdStLoadUpd,
1479                    []>, RegConstraint<"$addr.reg = $ea_result">,
1480                    NoEncode<"$ea_result">;
1481
1482 def LFSU : DForm_1<49, (outs f4rc:$rD, ptr_rc_nor0:$ea_result), (ins memri:$addr),
1483                   "lfsu $rD, $addr", IIC_LdStLFDU,
1484                   []>, RegConstraint<"$addr.reg = $ea_result">,
1485                    NoEncode<"$ea_result">;
1486
1487 def LFDU : DForm_1<51, (outs f8rc:$rD, ptr_rc_nor0:$ea_result), (ins memri:$addr),
1488                   "lfdu $rD, $addr", IIC_LdStLFDU,
1489                   []>, RegConstraint<"$addr.reg = $ea_result">,
1490                    NoEncode<"$ea_result">;
1491
1492
1493 // Indexed (r+r) Loads with Update (preinc).
1494 def LBZUX : XForm_1<31, 119, (outs gprc:$rD, ptr_rc_nor0:$ea_result),
1495                    (ins memrr:$addr),
1496                    "lbzux $rD, $addr", IIC_LdStLoadUpdX,
1497                    []>, RegConstraint<"$addr.ptrreg = $ea_result">,
1498                    NoEncode<"$ea_result">;
1499
1500 def LHAUX : XForm_1<31, 375, (outs gprc:$rD, ptr_rc_nor0:$ea_result),
1501                    (ins memrr:$addr),
1502                    "lhaux $rD, $addr", IIC_LdStLHAUX,
1503                    []>, RegConstraint<"$addr.ptrreg = $ea_result">,
1504                    NoEncode<"$ea_result">;
1505
1506 def LHZUX : XForm_1<31, 311, (outs gprc:$rD, ptr_rc_nor0:$ea_result),
1507                    (ins memrr:$addr),
1508                    "lhzux $rD, $addr", IIC_LdStLoadUpdX,
1509                    []>, RegConstraint<"$addr.ptrreg = $ea_result">,
1510                    NoEncode<"$ea_result">;
1511
1512 def LWZUX : XForm_1<31, 55, (outs gprc:$rD, ptr_rc_nor0:$ea_result),
1513                    (ins memrr:$addr),
1514                    "lwzux $rD, $addr", IIC_LdStLoadUpdX,
1515                    []>, RegConstraint<"$addr.ptrreg = $ea_result">,
1516                    NoEncode<"$ea_result">;
1517
1518 def LFSUX : XForm_1<31, 567, (outs f4rc:$rD, ptr_rc_nor0:$ea_result),
1519                    (ins memrr:$addr),
1520                    "lfsux $rD, $addr", IIC_LdStLFDUX,
1521                    []>, RegConstraint<"$addr.ptrreg = $ea_result">,
1522                    NoEncode<"$ea_result">;
1523
1524 def LFDUX : XForm_1<31, 631, (outs f8rc:$rD, ptr_rc_nor0:$ea_result),
1525                    (ins memrr:$addr),
1526                    "lfdux $rD, $addr", IIC_LdStLFDUX,
1527                    []>, RegConstraint<"$addr.ptrreg = $ea_result">,
1528                    NoEncode<"$ea_result">;
1529 }
1530 }
1531
1532 // Indexed (r+r) Loads.
1533 //
1534 let canFoldAsLoad = 1, PPC970_Unit = 2 in {
1535 def LBZX : XForm_1<31,  87, (outs gprc:$rD), (ins memrr:$src),
1536                    "lbzx $rD, $src", IIC_LdStLoad,
1537                    [(set i32:$rD, (zextloadi8 xaddr:$src))]>;
1538 def LHAX : XForm_1<31, 343, (outs gprc:$rD), (ins memrr:$src),
1539                    "lhax $rD, $src", IIC_LdStLHA,
1540                    [(set i32:$rD, (sextloadi16 xaddr:$src))]>,
1541                    PPC970_DGroup_Cracked;
1542 def LHZX : XForm_1<31, 279, (outs gprc:$rD), (ins memrr:$src),
1543                    "lhzx $rD, $src", IIC_LdStLoad,
1544                    [(set i32:$rD, (zextloadi16 xaddr:$src))]>;
1545 def LWZX : XForm_1<31,  23, (outs gprc:$rD), (ins memrr:$src),
1546                    "lwzx $rD, $src", IIC_LdStLoad,
1547                    [(set i32:$rD, (load xaddr:$src))]>;
1548                    
1549                    
1550 def LHBRX : XForm_1<31, 790, (outs gprc:$rD), (ins memrr:$src),
1551                    "lhbrx $rD, $src", IIC_LdStLoad,
1552                    [(set i32:$rD, (PPClbrx xoaddr:$src, i16))]>;
1553 def LWBRX : XForm_1<31,  534, (outs gprc:$rD), (ins memrr:$src),
1554                    "lwbrx $rD, $src", IIC_LdStLoad,
1555                    [(set i32:$rD, (PPClbrx xoaddr:$src, i32))]>;
1556
1557 def LFSX   : XForm_25<31, 535, (outs f4rc:$frD), (ins memrr:$src),
1558                       "lfsx $frD, $src", IIC_LdStLFD,
1559                       [(set f32:$frD, (load xaddr:$src))]>;
1560 def LFDX   : XForm_25<31, 599, (outs f8rc:$frD), (ins memrr:$src),
1561                       "lfdx $frD, $src", IIC_LdStLFD,
1562                       [(set f64:$frD, (load xaddr:$src))]>;
1563
1564 def LFIWAX : XForm_25<31, 855, (outs f8rc:$frD), (ins memrr:$src),
1565                       "lfiwax $frD, $src", IIC_LdStLFD,
1566                       [(set f64:$frD, (PPClfiwax xoaddr:$src))]>;
1567 def LFIWZX : XForm_25<31, 887, (outs f8rc:$frD), (ins memrr:$src),
1568                       "lfiwzx $frD, $src", IIC_LdStLFD,
1569                       [(set f64:$frD, (PPClfiwzx xoaddr:$src))]>;
1570 }
1571
1572 // Load Multiple
1573 def LMW : DForm_1<46, (outs gprc:$rD), (ins memri:$src),
1574                   "lmw $rD, $src", IIC_LdStLMW, []>;
1575
1576 //===----------------------------------------------------------------------===//
1577 // PPC32 Store Instructions.
1578 //
1579
1580 // Unindexed (r+i) Stores.
1581 let PPC970_Unit = 2 in {
1582 def STB  : DForm_1<38, (outs), (ins gprc:$rS, memri:$src),
1583                    "stb $rS, $src", IIC_LdStStore,
1584                    [(truncstorei8 i32:$rS, iaddr:$src)]>;
1585 def STH  : DForm_1<44, (outs), (ins gprc:$rS, memri:$src),
1586                    "sth $rS, $src", IIC_LdStStore,
1587                    [(truncstorei16 i32:$rS, iaddr:$src)]>;
1588 def STW  : DForm_1<36, (outs), (ins gprc:$rS, memri:$src),
1589                    "stw $rS, $src", IIC_LdStStore,
1590                    [(store i32:$rS, iaddr:$src)]>;
1591 def STFS : DForm_1<52, (outs), (ins f4rc:$rS, memri:$dst),
1592                    "stfs $rS, $dst", IIC_LdStSTFD,
1593                    [(store f32:$rS, iaddr:$dst)]>;
1594 def STFD : DForm_1<54, (outs), (ins f8rc:$rS, memri:$dst),
1595                    "stfd $rS, $dst", IIC_LdStSTFD,
1596                    [(store f64:$rS, iaddr:$dst)]>;
1597 }
1598
1599 // Unindexed (r+i) Stores with Update (preinc).
1600 let PPC970_Unit = 2, mayStore = 1 in {
1601 def STBU  : DForm_1<39, (outs ptr_rc_nor0:$ea_res), (ins gprc:$rS, memri:$dst),
1602                     "stbu $rS, $dst", IIC_LdStStoreUpd, []>,
1603                     RegConstraint<"$dst.reg = $ea_res">, NoEncode<"$ea_res">;
1604 def STHU  : DForm_1<45, (outs ptr_rc_nor0:$ea_res), (ins gprc:$rS, memri:$dst),
1605                     "sthu $rS, $dst", IIC_LdStStoreUpd, []>,
1606                     RegConstraint<"$dst.reg = $ea_res">, NoEncode<"$ea_res">;
1607 def STWU  : DForm_1<37, (outs ptr_rc_nor0:$ea_res), (ins gprc:$rS, memri:$dst),
1608                     "stwu $rS, $dst", IIC_LdStStoreUpd, []>,
1609                     RegConstraint<"$dst.reg = $ea_res">, NoEncode<"$ea_res">;
1610 def STFSU : DForm_1<53, (outs ptr_rc_nor0:$ea_res), (ins f4rc:$rS, memri:$dst),
1611                     "stfsu $rS, $dst", IIC_LdStSTFDU, []>,
1612                     RegConstraint<"$dst.reg = $ea_res">, NoEncode<"$ea_res">;
1613 def STFDU : DForm_1<55, (outs ptr_rc_nor0:$ea_res), (ins f8rc:$rS, memri:$dst),
1614                     "stfdu $rS, $dst", IIC_LdStSTFDU, []>,
1615                     RegConstraint<"$dst.reg = $ea_res">, NoEncode<"$ea_res">;
1616 }
1617
1618 // Patterns to match the pre-inc stores.  We can't put the patterns on
1619 // the instruction definitions directly as ISel wants the address base
1620 // and offset to be separate operands, not a single complex operand.
1621 def : Pat<(pre_truncsti8 i32:$rS, iPTR:$ptrreg, iaddroff:$ptroff),
1622           (STBU $rS, iaddroff:$ptroff, $ptrreg)>;
1623 def : Pat<(pre_truncsti16 i32:$rS, iPTR:$ptrreg, iaddroff:$ptroff),
1624           (STHU $rS, iaddroff:$ptroff, $ptrreg)>;
1625 def : Pat<(pre_store i32:$rS, iPTR:$ptrreg, iaddroff:$ptroff),
1626           (STWU $rS, iaddroff:$ptroff, $ptrreg)>;
1627 def : Pat<(pre_store f32:$rS, iPTR:$ptrreg, iaddroff:$ptroff),
1628           (STFSU $rS, iaddroff:$ptroff, $ptrreg)>;
1629 def : Pat<(pre_store f64:$rS, iPTR:$ptrreg, iaddroff:$ptroff),
1630           (STFDU $rS, iaddroff:$ptroff, $ptrreg)>;
1631
1632 // Indexed (r+r) Stores.
1633 let PPC970_Unit = 2 in {
1634 def STBX  : XForm_8<31, 215, (outs), (ins gprc:$rS, memrr:$dst),
1635                    "stbx $rS, $dst", IIC_LdStStore,
1636                    [(truncstorei8 i32:$rS, xaddr:$dst)]>,
1637                    PPC970_DGroup_Cracked;
1638 def STHX  : XForm_8<31, 407, (outs), (ins gprc:$rS, memrr:$dst),
1639                    "sthx $rS, $dst", IIC_LdStStore,
1640                    [(truncstorei16 i32:$rS, xaddr:$dst)]>,
1641                    PPC970_DGroup_Cracked;
1642 def STWX  : XForm_8<31, 151, (outs), (ins gprc:$rS, memrr:$dst),
1643                    "stwx $rS, $dst", IIC_LdStStore,
1644                    [(store i32:$rS, xaddr:$dst)]>,
1645                    PPC970_DGroup_Cracked;
1646  
1647 def STHBRX: XForm_8<31, 918, (outs), (ins gprc:$rS, memrr:$dst),
1648                    "sthbrx $rS, $dst", IIC_LdStStore,
1649                    [(PPCstbrx i32:$rS, xoaddr:$dst, i16)]>,
1650                    PPC970_DGroup_Cracked;
1651 def STWBRX: XForm_8<31, 662, (outs), (ins gprc:$rS, memrr:$dst),
1652                    "stwbrx $rS, $dst", IIC_LdStStore,
1653                    [(PPCstbrx i32:$rS, xoaddr:$dst, i32)]>,
1654                    PPC970_DGroup_Cracked;
1655
1656 def STFIWX: XForm_28<31, 983, (outs), (ins f8rc:$frS, memrr:$dst),
1657                      "stfiwx $frS, $dst", IIC_LdStSTFD,
1658                      [(PPCstfiwx f64:$frS, xoaddr:$dst)]>;
1659                      
1660 def STFSX : XForm_28<31, 663, (outs), (ins f4rc:$frS, memrr:$dst),
1661                      "stfsx $frS, $dst", IIC_LdStSTFD,
1662                      [(store f32:$frS, xaddr:$dst)]>;
1663 def STFDX : XForm_28<31, 727, (outs), (ins f8rc:$frS, memrr:$dst),
1664                      "stfdx $frS, $dst", IIC_LdStSTFD,
1665                      [(store f64:$frS, xaddr:$dst)]>;
1666 }
1667
1668 // Indexed (r+r) Stores with Update (preinc).
1669 let PPC970_Unit = 2, mayStore = 1 in {
1670 def STBUX : XForm_8<31, 247, (outs ptr_rc_nor0:$ea_res), (ins gprc:$rS, memrr:$dst),
1671                     "stbux $rS, $dst", IIC_LdStStoreUpd, []>,
1672                     RegConstraint<"$dst.ptrreg = $ea_res">, NoEncode<"$ea_res">,
1673                     PPC970_DGroup_Cracked;
1674 def STHUX : XForm_8<31, 439, (outs ptr_rc_nor0:$ea_res), (ins gprc:$rS, memrr:$dst),
1675                     "sthux $rS, $dst", IIC_LdStStoreUpd, []>,
1676                     RegConstraint<"$dst.ptrreg = $ea_res">, NoEncode<"$ea_res">,
1677                     PPC970_DGroup_Cracked;
1678 def STWUX : XForm_8<31, 183, (outs ptr_rc_nor0:$ea_res), (ins gprc:$rS, memrr:$dst),
1679                     "stwux $rS, $dst", IIC_LdStStoreUpd, []>,
1680                     RegConstraint<"$dst.ptrreg = $ea_res">, NoEncode<"$ea_res">,
1681                     PPC970_DGroup_Cracked;
1682 def STFSUX: XForm_8<31, 695, (outs ptr_rc_nor0:$ea_res), (ins f4rc:$rS, memrr:$dst),
1683                     "stfsux $rS, $dst", IIC_LdStSTFDU, []>,
1684                     RegConstraint<"$dst.ptrreg = $ea_res">, NoEncode<"$ea_res">,
1685                     PPC970_DGroup_Cracked;
1686 def STFDUX: XForm_8<31, 759, (outs ptr_rc_nor0:$ea_res), (ins f8rc:$rS, memrr:$dst),
1687                     "stfdux $rS, $dst", IIC_LdStSTFDU, []>,
1688                     RegConstraint<"$dst.ptrreg = $ea_res">, NoEncode<"$ea_res">,
1689                     PPC970_DGroup_Cracked;
1690 }
1691
1692 // Patterns to match the pre-inc stores.  We can't put the patterns on
1693 // the instruction definitions directly as ISel wants the address base
1694 // and offset to be separate operands, not a single complex operand.
1695 def : Pat<(pre_truncsti8 i32:$rS, iPTR:$ptrreg, iPTR:$ptroff),
1696           (STBUX $rS, $ptrreg, $ptroff)>;
1697 def : Pat<(pre_truncsti16 i32:$rS, iPTR:$ptrreg, iPTR:$ptroff),
1698           (STHUX $rS, $ptrreg, $ptroff)>;
1699 def : Pat<(pre_store i32:$rS, iPTR:$ptrreg, iPTR:$ptroff),
1700           (STWUX $rS, $ptrreg, $ptroff)>;
1701 def : Pat<(pre_store f32:$rS, iPTR:$ptrreg, iPTR:$ptroff),
1702           (STFSUX $rS, $ptrreg, $ptroff)>;
1703 def : Pat<(pre_store f64:$rS, iPTR:$ptrreg, iPTR:$ptroff),
1704           (STFDUX $rS, $ptrreg, $ptroff)>;
1705
1706 // Store Multiple
1707 def STMW : DForm_1<47, (outs), (ins gprc:$rS, memri:$dst),
1708                    "stmw $rS, $dst", IIC_LdStLMW, []>;
1709
1710 def SYNC : XForm_24_sync<31, 598, (outs), (ins i32imm:$L),
1711                         "sync $L", IIC_LdStSync, []>;
1712
1713 let isCodeGenOnly = 1 in {
1714   def MSYNC : XForm_24_sync<31, 598, (outs), (ins),
1715                            "msync", IIC_LdStSync, []> {
1716     let L = 0;
1717   }
1718 }
1719
1720 def : Pat<(int_ppc_sync),   (SYNC 0)>, Requires<[HasSYNC]>;
1721 def : Pat<(int_ppc_lwsync), (SYNC 1)>, Requires<[HasSYNC]>;
1722 def : Pat<(int_ppc_sync),   (MSYNC)>, Requires<[HasOnlyMSYNC]>;
1723 def : Pat<(int_ppc_lwsync), (MSYNC)>, Requires<[HasOnlyMSYNC]>;
1724
1725 //===----------------------------------------------------------------------===//
1726 // PPC32 Arithmetic Instructions.
1727 //
1728
1729 let PPC970_Unit = 1 in {  // FXU Operations.
1730 def ADDI   : DForm_2<14, (outs gprc:$rD), (ins gprc_nor0:$rA, s16imm:$imm),
1731                      "addi $rD, $rA, $imm", IIC_IntSimple,
1732                      [(set i32:$rD, (add i32:$rA, imm32SExt16:$imm))]>;
1733 let BaseName = "addic" in {
1734 let Defs = [CARRY] in
1735 def ADDIC  : DForm_2<12, (outs gprc:$rD), (ins gprc:$rA, s16imm:$imm),
1736                      "addic $rD, $rA, $imm", IIC_IntGeneral,
1737                      [(set i32:$rD, (addc i32:$rA, imm32SExt16:$imm))]>,
1738                      RecFormRel, PPC970_DGroup_Cracked;
1739 let Defs = [CARRY, CR0] in
1740 def ADDICo : DForm_2<13, (outs gprc:$rD), (ins gprc:$rA, s16imm:$imm),
1741                      "addic. $rD, $rA, $imm", IIC_IntGeneral,
1742                      []>, isDOT, RecFormRel;
1743 }
1744 def ADDIS  : DForm_2<15, (outs gprc:$rD), (ins gprc_nor0:$rA, s17imm:$imm),
1745                      "addis $rD, $rA, $imm", IIC_IntSimple,
1746                      [(set i32:$rD, (add i32:$rA, imm16ShiftedSExt:$imm))]>;
1747 let isCodeGenOnly = 1 in
1748 def LA     : DForm_2<14, (outs gprc:$rD), (ins gprc_nor0:$rA, s16imm:$sym),
1749                      "la $rD, $sym($rA)", IIC_IntGeneral,
1750                      [(set i32:$rD, (add i32:$rA,
1751                                           (PPClo tglobaladdr:$sym, 0)))]>;
1752 def MULLI  : DForm_2< 7, (outs gprc:$rD), (ins gprc:$rA, s16imm:$imm),
1753                      "mulli $rD, $rA, $imm", IIC_IntMulLI,
1754                      [(set i32:$rD, (mul i32:$rA, imm32SExt16:$imm))]>;
1755 let Defs = [CARRY] in
1756 def SUBFIC : DForm_2< 8, (outs gprc:$rD), (ins gprc:$rA, s16imm:$imm),
1757                      "subfic $rD, $rA, $imm", IIC_IntGeneral,
1758                      [(set i32:$rD, (subc imm32SExt16:$imm, i32:$rA))]>;
1759
1760 let isReMaterializable = 1, isAsCheapAsAMove = 1, isMoveImm = 1 in {
1761   def LI  : DForm_2_r0<14, (outs gprc:$rD), (ins s16imm:$imm),
1762                        "li $rD, $imm", IIC_IntSimple,
1763                        [(set i32:$rD, imm32SExt16:$imm)]>;
1764   def LIS : DForm_2_r0<15, (outs gprc:$rD), (ins s17imm:$imm),
1765                        "lis $rD, $imm", IIC_IntSimple,
1766                        [(set i32:$rD, imm16ShiftedSExt:$imm)]>;
1767 }
1768 }
1769
1770 let PPC970_Unit = 1 in {  // FXU Operations.
1771 let Defs = [CR0] in {
1772 def ANDIo : DForm_4<28, (outs gprc:$dst), (ins gprc:$src1, u16imm:$src2),
1773                     "andi. $dst, $src1, $src2", IIC_IntGeneral,
1774                     [(set i32:$dst, (and i32:$src1, immZExt16:$src2))]>,
1775                     isDOT;
1776 def ANDISo : DForm_4<29, (outs gprc:$dst), (ins gprc:$src1, u16imm:$src2),
1777                     "andis. $dst, $src1, $src2", IIC_IntGeneral,
1778                     [(set i32:$dst, (and i32:$src1, imm16ShiftedZExt:$src2))]>,
1779                     isDOT;
1780 }
1781 def ORI   : DForm_4<24, (outs gprc:$dst), (ins gprc:$src1, u16imm:$src2),
1782                     "ori $dst, $src1, $src2", IIC_IntSimple,
1783                     [(set i32:$dst, (or i32:$src1, immZExt16:$src2))]>;
1784 def ORIS  : DForm_4<25, (outs gprc:$dst), (ins gprc:$src1, u16imm:$src2),
1785                     "oris $dst, $src1, $src2", IIC_IntSimple,
1786                     [(set i32:$dst, (or i32:$src1, imm16ShiftedZExt:$src2))]>;
1787 def XORI  : DForm_4<26, (outs gprc:$dst), (ins gprc:$src1, u16imm:$src2),
1788                     "xori $dst, $src1, $src2", IIC_IntSimple,
1789                     [(set i32:$dst, (xor i32:$src1, immZExt16:$src2))]>;
1790 def XORIS : DForm_4<27, (outs gprc:$dst), (ins gprc:$src1, u16imm:$src2),
1791                     "xoris $dst, $src1, $src2", IIC_IntSimple,
1792                     [(set i32:$dst, (xor i32:$src1, imm16ShiftedZExt:$src2))]>;
1793
1794 def NOP   : DForm_4_zero<24, (outs), (ins), "nop", IIC_IntSimple,
1795                          []>;
1796 let isCodeGenOnly = 1 in {
1797 // The POWER6 and POWER7 have special group-terminating nops.
1798 def NOP_GT_PWR6 : DForm_4_fixedreg_zero<24, 1, (outs), (ins),
1799                                         "ori 1, 1, 0", IIC_IntSimple, []>;
1800 def NOP_GT_PWR7 : DForm_4_fixedreg_zero<24, 2, (outs), (ins),
1801                                         "ori 2, 2, 0", IIC_IntSimple, []>;
1802 }
1803
1804 let isCompare = 1, hasSideEffects = 0 in {
1805   def CMPWI : DForm_5_ext<11, (outs crrc:$crD), (ins gprc:$rA, s16imm:$imm),
1806                           "cmpwi $crD, $rA, $imm", IIC_IntCompare>;
1807   def CMPLWI : DForm_6_ext<10, (outs crrc:$dst), (ins gprc:$src1, u16imm:$src2),
1808                            "cmplwi $dst, $src1, $src2", IIC_IntCompare>;
1809 }
1810 }
1811
1812 let PPC970_Unit = 1, hasSideEffects = 0 in {  // FXU Operations.
1813 let isCommutable = 1 in {
1814 defm NAND : XForm_6r<31, 476, (outs gprc:$rA), (ins gprc:$rS, gprc:$rB),
1815                      "nand", "$rA, $rS, $rB", IIC_IntSimple,
1816                      [(set i32:$rA, (not (and i32:$rS, i32:$rB)))]>;
1817 defm AND  : XForm_6r<31,  28, (outs gprc:$rA), (ins gprc:$rS, gprc:$rB),
1818                      "and", "$rA, $rS, $rB", IIC_IntSimple,
1819                      [(set i32:$rA, (and i32:$rS, i32:$rB))]>;
1820 } // isCommutable
1821 defm ANDC : XForm_6r<31,  60, (outs gprc:$rA), (ins gprc:$rS, gprc:$rB),
1822                      "andc", "$rA, $rS, $rB", IIC_IntSimple,
1823                      [(set i32:$rA, (and i32:$rS, (not i32:$rB)))]>;
1824 let isCommutable = 1 in {
1825 defm OR   : XForm_6r<31, 444, (outs gprc:$rA), (ins gprc:$rS, gprc:$rB),
1826                      "or", "$rA, $rS, $rB", IIC_IntSimple,
1827                      [(set i32:$rA, (or i32:$rS, i32:$rB))]>;
1828 defm NOR  : XForm_6r<31, 124, (outs gprc:$rA), (ins gprc:$rS, gprc:$rB),
1829                      "nor", "$rA, $rS, $rB", IIC_IntSimple,
1830                      [(set i32:$rA, (not (or i32:$rS, i32:$rB)))]>;
1831 } // isCommutable
1832 defm ORC  : XForm_6r<31, 412, (outs gprc:$rA), (ins gprc:$rS, gprc:$rB),
1833                      "orc", "$rA, $rS, $rB", IIC_IntSimple,
1834                      [(set i32:$rA, (or i32:$rS, (not i32:$rB)))]>;
1835 let isCommutable = 1 in {
1836 defm EQV  : XForm_6r<31, 284, (outs gprc:$rA), (ins gprc:$rS, gprc:$rB),
1837                      "eqv", "$rA, $rS, $rB", IIC_IntSimple,
1838                      [(set i32:$rA, (not (xor i32:$rS, i32:$rB)))]>;
1839 defm XOR  : XForm_6r<31, 316, (outs gprc:$rA), (ins gprc:$rS, gprc:$rB),
1840                      "xor", "$rA, $rS, $rB", IIC_IntSimple,
1841                      [(set i32:$rA, (xor i32:$rS, i32:$rB))]>;
1842 } // isCommutable
1843 defm SLW  : XForm_6r<31,  24, (outs gprc:$rA), (ins gprc:$rS, gprc:$rB),
1844                      "slw", "$rA, $rS, $rB", IIC_IntGeneral,
1845                      [(set i32:$rA, (PPCshl i32:$rS, i32:$rB))]>;
1846 defm SRW  : XForm_6r<31, 536, (outs gprc:$rA), (ins gprc:$rS, gprc:$rB),
1847                      "srw", "$rA, $rS, $rB", IIC_IntGeneral,
1848                      [(set i32:$rA, (PPCsrl i32:$rS, i32:$rB))]>;
1849 defm SRAW : XForm_6rc<31, 792, (outs gprc:$rA), (ins gprc:$rS, gprc:$rB),
1850                       "sraw", "$rA, $rS, $rB", IIC_IntShift,
1851                       [(set i32:$rA, (PPCsra i32:$rS, i32:$rB))]>;
1852 }
1853
1854 let PPC970_Unit = 1 in {  // FXU Operations.
1855 let hasSideEffects = 0 in {
1856 defm SRAWI : XForm_10rc<31, 824, (outs gprc:$rA), (ins gprc:$rS, u5imm:$SH),
1857                         "srawi", "$rA, $rS, $SH", IIC_IntShift,
1858                         [(set i32:$rA, (sra i32:$rS, (i32 imm:$SH)))]>;
1859 defm CNTLZW : XForm_11r<31,  26, (outs gprc:$rA), (ins gprc:$rS),
1860                         "cntlzw", "$rA, $rS", IIC_IntGeneral,
1861                         [(set i32:$rA, (ctlz i32:$rS))]>;
1862 defm EXTSB  : XForm_11r<31, 954, (outs gprc:$rA), (ins gprc:$rS),
1863                         "extsb", "$rA, $rS", IIC_IntSimple,
1864                         [(set i32:$rA, (sext_inreg i32:$rS, i8))]>;
1865 defm EXTSH  : XForm_11r<31, 922, (outs gprc:$rA), (ins gprc:$rS),
1866                         "extsh", "$rA, $rS", IIC_IntSimple,
1867                         [(set i32:$rA, (sext_inreg i32:$rS, i16))]>;
1868 }
1869 let isCompare = 1, hasSideEffects = 0 in {
1870   def CMPW   : XForm_16_ext<31, 0, (outs crrc:$crD), (ins gprc:$rA, gprc:$rB),
1871                             "cmpw $crD, $rA, $rB", IIC_IntCompare>;
1872   def CMPLW  : XForm_16_ext<31, 32, (outs crrc:$crD), (ins gprc:$rA, gprc:$rB),
1873                             "cmplw $crD, $rA, $rB", IIC_IntCompare>;
1874 }
1875 }
1876 let PPC970_Unit = 3 in {  // FPU Operations.
1877 //def FCMPO  : XForm_17<63, 32, (outs CRRC:$crD), (ins FPRC:$fA, FPRC:$fB),
1878 //                      "fcmpo $crD, $fA, $fB", IIC_FPCompare>;
1879 let isCompare = 1, hasSideEffects = 0 in {
1880   def FCMPUS : XForm_17<63, 0, (outs crrc:$crD), (ins f4rc:$fA, f4rc:$fB),
1881                         "fcmpu $crD, $fA, $fB", IIC_FPCompare>;
1882   let Interpretation64Bit = 1, isCodeGenOnly = 1 in
1883   def FCMPUD : XForm_17<63, 0, (outs crrc:$crD), (ins f8rc:$fA, f8rc:$fB),
1884                         "fcmpu $crD, $fA, $fB", IIC_FPCompare>;
1885 }
1886
1887 let Uses = [RM] in {
1888   let hasSideEffects = 0 in {
1889   defm FCTIW  : XForm_26r<63, 14, (outs f8rc:$frD), (ins f8rc:$frB),
1890                           "fctiw", "$frD, $frB", IIC_FPGeneral,
1891                           []>;
1892   defm FCTIWZ : XForm_26r<63, 15, (outs f8rc:$frD), (ins f8rc:$frB),
1893                           "fctiwz", "$frD, $frB", IIC_FPGeneral,
1894                           [(set f64:$frD, (PPCfctiwz f64:$frB))]>;
1895
1896   defm FRSP   : XForm_26r<63, 12, (outs f4rc:$frD), (ins f8rc:$frB),
1897                           "frsp", "$frD, $frB", IIC_FPGeneral,
1898                           [(set f32:$frD, (fround f64:$frB))]>;
1899
1900   let Interpretation64Bit = 1, isCodeGenOnly = 1 in
1901   defm FRIND  : XForm_26r<63, 392, (outs f8rc:$frD), (ins f8rc:$frB),
1902                           "frin", "$frD, $frB", IIC_FPGeneral,
1903                           [(set f64:$frD, (frnd f64:$frB))]>;
1904   defm FRINS  : XForm_26r<63, 392, (outs f4rc:$frD), (ins f4rc:$frB),
1905                           "frin", "$frD, $frB", IIC_FPGeneral,
1906                           [(set f32:$frD, (frnd f32:$frB))]>;
1907   }
1908
1909   let hasSideEffects = 0 in {
1910   let Interpretation64Bit = 1, isCodeGenOnly = 1 in
1911   defm FRIPD  : XForm_26r<63, 456, (outs f8rc:$frD), (ins f8rc:$frB),
1912                           "frip", "$frD, $frB", IIC_FPGeneral,
1913                           [(set f64:$frD, (fceil f64:$frB))]>;
1914   defm FRIPS  : XForm_26r<63, 456, (outs f4rc:$frD), (ins f4rc:$frB),
1915                           "frip", "$frD, $frB", IIC_FPGeneral,
1916                           [(set f32:$frD, (fceil f32:$frB))]>;
1917   let Interpretation64Bit = 1, isCodeGenOnly = 1 in
1918   defm FRIZD  : XForm_26r<63, 424, (outs f8rc:$frD), (ins f8rc:$frB),
1919                           "friz", "$frD, $frB", IIC_FPGeneral,
1920                           [(set f64:$frD, (ftrunc f64:$frB))]>;
1921   defm FRIZS  : XForm_26r<63, 424, (outs f4rc:$frD), (ins f4rc:$frB),
1922                           "friz", "$frD, $frB", IIC_FPGeneral,
1923                           [(set f32:$frD, (ftrunc f32:$frB))]>;
1924   let Interpretation64Bit = 1, isCodeGenOnly = 1 in
1925   defm FRIMD  : XForm_26r<63, 488, (outs f8rc:$frD), (ins f8rc:$frB),
1926                           "frim", "$frD, $frB", IIC_FPGeneral,
1927                           [(set f64:$frD, (ffloor f64:$frB))]>;
1928   defm FRIMS  : XForm_26r<63, 488, (outs f4rc:$frD), (ins f4rc:$frB),
1929                           "frim", "$frD, $frB", IIC_FPGeneral,
1930                           [(set f32:$frD, (ffloor f32:$frB))]>;
1931
1932   defm FSQRT  : XForm_26r<63, 22, (outs f8rc:$frD), (ins f8rc:$frB),
1933                           "fsqrt", "$frD, $frB", IIC_FPSqrtD,
1934                           [(set f64:$frD, (fsqrt f64:$frB))]>;
1935   defm FSQRTS : XForm_26r<59, 22, (outs f4rc:$frD), (ins f4rc:$frB),
1936                           "fsqrts", "$frD, $frB", IIC_FPSqrtS,
1937                           [(set f32:$frD, (fsqrt f32:$frB))]>;
1938   }
1939   }
1940 }
1941
1942 /// Note that FMR is defined as pseudo-ops on the PPC970 because they are
1943 /// often coalesced away and we don't want the dispatch group builder to think
1944 /// that they will fill slots (which could cause the load of a LSU reject to
1945 /// sneak into a d-group with a store).
1946 let hasSideEffects = 0 in
1947 defm FMR   : XForm_26r<63, 72, (outs f4rc:$frD), (ins f4rc:$frB),
1948                        "fmr", "$frD, $frB", IIC_FPGeneral,
1949                        []>,  // (set f32:$frD, f32:$frB)
1950                        PPC970_Unit_Pseudo;
1951
1952 let PPC970_Unit = 3, hasSideEffects = 0 in {  // FPU Operations.
1953 // These are artificially split into two different forms, for 4/8 byte FP.
1954 defm FABSS  : XForm_26r<63, 264, (outs f4rc:$frD), (ins f4rc:$frB),
1955                         "fabs", "$frD, $frB", IIC_FPGeneral,
1956                         [(set f32:$frD, (fabs f32:$frB))]>;
1957 let Interpretation64Bit = 1, isCodeGenOnly = 1 in
1958 defm FABSD  : XForm_26r<63, 264, (outs f8rc:$frD), (ins f8rc:$frB),
1959                         "fabs", "$frD, $frB", IIC_FPGeneral,
1960                         [(set f64:$frD, (fabs f64:$frB))]>;
1961 defm FNABSS : XForm_26r<63, 136, (outs f4rc:$frD), (ins f4rc:$frB),
1962                         "fnabs", "$frD, $frB", IIC_FPGeneral,
1963                         [(set f32:$frD, (fneg (fabs f32:$frB)))]>;
1964 let Interpretation64Bit = 1, isCodeGenOnly = 1 in
1965 defm FNABSD : XForm_26r<63, 136, (outs f8rc:$frD), (ins f8rc:$frB),
1966                         "fnabs", "$frD, $frB", IIC_FPGeneral,
1967                         [(set f64:$frD, (fneg (fabs f64:$frB)))]>;
1968 defm FNEGS  : XForm_26r<63, 40, (outs f4rc:$frD), (ins f4rc:$frB),
1969                         "fneg", "$frD, $frB", IIC_FPGeneral,
1970                         [(set f32:$frD, (fneg f32:$frB))]>;
1971 let Interpretation64Bit = 1, isCodeGenOnly = 1 in
1972 defm FNEGD  : XForm_26r<63, 40, (outs f8rc:$frD), (ins f8rc:$frB),
1973                         "fneg", "$frD, $frB", IIC_FPGeneral,
1974                         [(set f64:$frD, (fneg f64:$frB))]>;
1975
1976 defm FCPSGNS : XForm_28r<63, 8, (outs f4rc:$frD), (ins f4rc:$frA, f4rc:$frB),
1977                         "fcpsgn", "$frD, $frA, $frB", IIC_FPGeneral,
1978                         [(set f32:$frD, (fcopysign f32:$frB, f32:$frA))]>;
1979 let Interpretation64Bit = 1, isCodeGenOnly = 1 in
1980 defm FCPSGND : XForm_28r<63, 8, (outs f8rc:$frD), (ins f8rc:$frA, f8rc:$frB),
1981                         "fcpsgn", "$frD, $frA, $frB", IIC_FPGeneral,
1982                         [(set f64:$frD, (fcopysign f64:$frB, f64:$frA))]>;
1983
1984 // Reciprocal estimates.
1985 defm FRE      : XForm_26r<63, 24, (outs f8rc:$frD), (ins f8rc:$frB),
1986                           "fre", "$frD, $frB", IIC_FPGeneral,
1987                           [(set f64:$frD, (PPCfre f64:$frB))]>;
1988 defm FRES     : XForm_26r<59, 24, (outs f4rc:$frD), (ins f4rc:$frB),
1989                           "fres", "$frD, $frB", IIC_FPGeneral,
1990                           [(set f32:$frD, (PPCfre f32:$frB))]>;
1991 defm FRSQRTE  : XForm_26r<63, 26, (outs f8rc:$frD), (ins f8rc:$frB),
1992                           "frsqrte", "$frD, $frB", IIC_FPGeneral,
1993                           [(set f64:$frD, (PPCfrsqrte f64:$frB))]>;
1994 defm FRSQRTES : XForm_26r<59, 26, (outs f4rc:$frD), (ins f4rc:$frB),
1995                           "frsqrtes", "$frD, $frB", IIC_FPGeneral,
1996                           [(set f32:$frD, (PPCfrsqrte f32:$frB))]>;
1997 }
1998
1999 // XL-Form instructions.  condition register logical ops.
2000 //
2001 let hasSideEffects = 0 in
2002 def MCRF   : XLForm_3<19, 0, (outs crrc:$BF), (ins crrc:$BFA),
2003                       "mcrf $BF, $BFA", IIC_BrMCR>,
2004              PPC970_DGroup_First, PPC970_Unit_CRU;
2005
2006 let isCommutable = 1 in {
2007 def CRAND  : XLForm_1<19, 257, (outs crbitrc:$CRD),
2008                                (ins crbitrc:$CRA, crbitrc:$CRB),
2009                       "crand $CRD, $CRA, $CRB", IIC_BrCR,
2010                       [(set i1:$CRD, (and i1:$CRA, i1:$CRB))]>;
2011
2012 def CRNAND : XLForm_1<19, 225, (outs crbitrc:$CRD),
2013                                (ins crbitrc:$CRA, crbitrc:$CRB),
2014                       "crnand $CRD, $CRA, $CRB", IIC_BrCR,
2015                       [(set i1:$CRD, (not (and i1:$CRA, i1:$CRB)))]>;
2016
2017 def CROR   : XLForm_1<19, 449, (outs crbitrc:$CRD),
2018                                (ins crbitrc:$CRA, crbitrc:$CRB),
2019                       "cror $CRD, $CRA, $CRB", IIC_BrCR,
2020                       [(set i1:$CRD, (or i1:$CRA, i1:$CRB))]>;
2021
2022 def CRXOR  : XLForm_1<19, 193, (outs crbitrc:$CRD),
2023                                (ins crbitrc:$CRA, crbitrc:$CRB),
2024                       "crxor $CRD, $CRA, $CRB", IIC_BrCR,
2025                       [(set i1:$CRD, (xor i1:$CRA, i1:$CRB))]>;
2026
2027 def CRNOR  : XLForm_1<19, 33, (outs crbitrc:$CRD),
2028                               (ins crbitrc:$CRA, crbitrc:$CRB),
2029                       "crnor $CRD, $CRA, $CRB", IIC_BrCR,
2030                       [(set i1:$CRD, (not (or i1:$CRA, i1:$CRB)))]>;
2031
2032 def CREQV  : XLForm_1<19, 289, (outs crbitrc:$CRD),
2033                                (ins crbitrc:$CRA, crbitrc:$CRB),
2034                       "creqv $CRD, $CRA, $CRB", IIC_BrCR,
2035                       [(set i1:$CRD, (not (xor i1:$CRA, i1:$CRB)))]>;
2036 } // isCommutable
2037
2038 def CRANDC : XLForm_1<19, 129, (outs crbitrc:$CRD),
2039                                (ins crbitrc:$CRA, crbitrc:$CRB),
2040                       "crandc $CRD, $CRA, $CRB", IIC_BrCR,
2041                       [(set i1:$CRD, (and i1:$CRA, (not i1:$CRB)))]>;
2042
2043 def CRORC  : XLForm_1<19, 417, (outs crbitrc:$CRD),
2044                                (ins crbitrc:$CRA, crbitrc:$CRB),
2045                       "crorc $CRD, $CRA, $CRB", IIC_BrCR,
2046                       [(set i1:$CRD, (or i1:$CRA, (not i1:$CRB)))]>;
2047
2048 let isCodeGenOnly = 1 in {
2049 def CRSET  : XLForm_1_ext<19, 289, (outs crbitrc:$dst), (ins),
2050               "creqv $dst, $dst, $dst", IIC_BrCR,
2051               [(set i1:$dst, 1)]>;
2052
2053 def CRUNSET: XLForm_1_ext<19, 193, (outs crbitrc:$dst), (ins),
2054               "crxor $dst, $dst, $dst", IIC_BrCR,
2055               [(set i1:$dst, 0)]>;
2056
2057 let Defs = [CR1EQ], CRD = 6 in {
2058 def CR6SET  : XLForm_1_ext<19, 289, (outs), (ins),
2059               "creqv 6, 6, 6", IIC_BrCR,
2060               [(PPCcr6set)]>;
2061
2062 def CR6UNSET: XLForm_1_ext<19, 193, (outs), (ins),
2063               "crxor 6, 6, 6", IIC_BrCR,
2064               [(PPCcr6unset)]>;
2065 }
2066 }
2067
2068 // XFX-Form instructions.  Instructions that deal with SPRs.
2069 //
2070
2071 def MFSPR : XFXForm_1<31, 339, (outs gprc:$RT), (ins i32imm:$SPR),
2072                       "mfspr $RT, $SPR", IIC_SprMFSPR>;
2073 def MTSPR : XFXForm_1<31, 467, (outs), (ins i32imm:$SPR, gprc:$RT),
2074                       "mtspr $SPR, $RT", IIC_SprMTSPR>;
2075
2076 def MFTB : XFXForm_1<31, 371, (outs gprc:$RT), (ins i32imm:$SPR),
2077                      "mftb $RT, $SPR", IIC_SprMFTB>, Deprecated<DeprecatedMFTB>;
2078
2079 // A pseudo-instruction used to implement the read of the 64-bit cycle counter
2080 // on a 32-bit target.
2081 let hasSideEffects = 1, usesCustomInserter = 1 in
2082 def ReadTB : Pseudo<(outs gprc:$lo, gprc:$hi), (ins),
2083                     "#ReadTB", []>;
2084
2085 let Uses = [CTR] in {
2086 def MFCTR : XFXForm_1_ext<31, 339, 9, (outs gprc:$rT), (ins),
2087                           "mfctr $rT", IIC_SprMFSPR>,
2088             PPC970_DGroup_First, PPC970_Unit_FXU;
2089 }
2090 let Defs = [CTR], Pattern = [(PPCmtctr i32:$rS)] in {
2091 def MTCTR : XFXForm_7_ext<31, 467, 9, (outs), (ins gprc:$rS),
2092                           "mtctr $rS", IIC_SprMTSPR>,
2093             PPC970_DGroup_First, PPC970_Unit_FXU;
2094 }
2095 let hasSideEffects = 1, isCodeGenOnly = 1, Defs = [CTR] in {
2096 let Pattern = [(int_ppc_mtctr i32:$rS)] in
2097 def MTCTRloop : XFXForm_7_ext<31, 467, 9, (outs), (ins gprc:$rS),
2098                               "mtctr $rS", IIC_SprMTSPR>,
2099                 PPC970_DGroup_First, PPC970_Unit_FXU;
2100 }
2101
2102 let Defs = [LR] in {
2103 def MTLR  : XFXForm_7_ext<31, 467, 8, (outs), (ins gprc:$rS),
2104                           "mtlr $rS", IIC_SprMTSPR>,
2105             PPC970_DGroup_First, PPC970_Unit_FXU;
2106 }
2107 let Uses = [LR] in {
2108 def MFLR  : XFXForm_1_ext<31, 339, 8, (outs gprc:$rT), (ins),
2109                           "mflr $rT", IIC_SprMFSPR>,
2110             PPC970_DGroup_First, PPC970_Unit_FXU;
2111 }
2112
2113 let isCodeGenOnly = 1 in {
2114   // Move to/from VRSAVE: despite being a SPR, the VRSAVE register is renamed
2115   // like a GPR on the PPC970.  As such, copies in and out have the same
2116   // performance characteristics as an OR instruction.
2117   def MTVRSAVE : XFXForm_7_ext<31, 467, 256, (outs), (ins gprc:$rS),
2118                                "mtspr 256, $rS", IIC_IntGeneral>,
2119                  PPC970_DGroup_Single, PPC970_Unit_FXU;
2120   def MFVRSAVE : XFXForm_1_ext<31, 339, 256, (outs gprc:$rT), (ins),
2121                                "mfspr $rT, 256", IIC_IntGeneral>,
2122                  PPC970_DGroup_First, PPC970_Unit_FXU;
2123
2124   def MTVRSAVEv : XFXForm_7_ext<31, 467, 256,
2125                                 (outs VRSAVERC:$reg), (ins gprc:$rS),
2126                                 "mtspr 256, $rS", IIC_IntGeneral>,
2127                   PPC970_DGroup_Single, PPC970_Unit_FXU;
2128   def MFVRSAVEv : XFXForm_1_ext<31, 339, 256, (outs gprc:$rT),
2129                                 (ins VRSAVERC:$reg),
2130                                 "mfspr $rT, 256", IIC_IntGeneral>,
2131                   PPC970_DGroup_First, PPC970_Unit_FXU;
2132 }
2133
2134 // SPILL_VRSAVE - Indicate that we're dumping the VRSAVE register,
2135 // so we'll need to scavenge a register for it.
2136 let mayStore = 1 in
2137 def SPILL_VRSAVE : Pseudo<(outs), (ins VRSAVERC:$vrsave, memri:$F),
2138                      "#SPILL_VRSAVE", []>;
2139
2140 // RESTORE_VRSAVE - Indicate that we're restoring the VRSAVE register (previously
2141 // spilled), so we'll need to scavenge a register for it.
2142 let mayLoad = 1 in
2143 def RESTORE_VRSAVE : Pseudo<(outs VRSAVERC:$vrsave), (ins memri:$F),
2144                      "#RESTORE_VRSAVE", []>;
2145
2146 let hasSideEffects = 0 in {
2147 def MTOCRF: XFXForm_5a<31, 144, (outs crbitm:$FXM), (ins gprc:$ST),
2148                        "mtocrf $FXM, $ST", IIC_BrMCRX>,
2149             PPC970_DGroup_First, PPC970_Unit_CRU;
2150
2151 def MTCRF : XFXForm_5<31, 144, (outs), (ins i32imm:$FXM, gprc:$rS),
2152                       "mtcrf $FXM, $rS", IIC_BrMCRX>,
2153             PPC970_MicroCode, PPC970_Unit_CRU;
2154
2155 let hasExtraSrcRegAllocReq = 1 in // to enable post-ra anti-dep breaking.
2156 def MFOCRF: XFXForm_5a<31, 19, (outs gprc:$rT), (ins crbitm:$FXM),
2157                        "mfocrf $rT, $FXM", IIC_SprMFCRF>,
2158             PPC970_DGroup_First, PPC970_Unit_CRU;
2159
2160 def MFCR : XFXForm_3<31, 19, (outs gprc:$rT), (ins),
2161                      "mfcr $rT", IIC_SprMFCR>,
2162                      PPC970_MicroCode, PPC970_Unit_CRU;
2163 } // hasSideEffects = 0
2164
2165 // Pseudo instruction to perform FADD in round-to-zero mode.
2166 let usesCustomInserter = 1, Uses = [RM] in {
2167   def FADDrtz: Pseudo<(outs f8rc:$FRT), (ins f8rc:$FRA, f8rc:$FRB), "",
2168                       [(set f64:$FRT, (PPCfaddrtz f64:$FRA, f64:$FRB))]>;
2169 }
2170
2171 // The above pseudo gets expanded to make use of the following instructions
2172 // to manipulate FPSCR.  Note that FPSCR is not modeled at the DAG level.
2173 let Uses = [RM], Defs = [RM] in { 
2174   def MTFSB0 : XForm_43<63, 70, (outs), (ins u5imm:$FM),
2175                         "mtfsb0 $FM", IIC_IntMTFSB0, []>,
2176                PPC970_DGroup_Single, PPC970_Unit_FPU;
2177   def MTFSB1 : XForm_43<63, 38, (outs), (ins u5imm:$FM),
2178                         "mtfsb1 $FM", IIC_IntMTFSB0, []>,
2179                PPC970_DGroup_Single, PPC970_Unit_FPU;
2180   def MTFSF  : XFLForm<63, 711, (outs), (ins i32imm:$FM, f8rc:$rT),
2181                        "mtfsf $FM, $rT", IIC_IntMTFSB0, []>,
2182                PPC970_DGroup_Single, PPC970_Unit_FPU;
2183 }
2184 let Uses = [RM] in {
2185   def MFFS   : XForm_42<63, 583, (outs f8rc:$rT), (ins),
2186                          "mffs $rT", IIC_IntMFFS,
2187                          [(set f64:$rT, (PPCmffs))]>,
2188                PPC970_DGroup_Single, PPC970_Unit_FPU;
2189 }
2190
2191
2192 let PPC970_Unit = 1, hasSideEffects = 0 in {  // FXU Operations.
2193 // XO-Form instructions.  Arithmetic instructions that can set overflow bit
2194 let isCommutable = 1 in
2195 defm ADD4  : XOForm_1r<31, 266, 0, (outs gprc:$rT), (ins gprc:$rA, gprc:$rB),
2196                        "add", "$rT, $rA, $rB", IIC_IntSimple,
2197                        [(set i32:$rT, (add i32:$rA, i32:$rB))]>;
2198 let isCodeGenOnly = 1 in
2199 def ADD4TLS  : XOForm_1<31, 266, 0, (outs gprc:$rT), (ins gprc:$rA, tlsreg32:$rB),
2200                        "add $rT, $rA, $rB", IIC_IntSimple,
2201                        [(set i32:$rT, (add i32:$rA, tglobaltlsaddr:$rB))]>;
2202 let isCommutable = 1 in
2203 defm ADDC  : XOForm_1rc<31, 10, 0, (outs gprc:$rT), (ins gprc:$rA, gprc:$rB),
2204                         "addc", "$rT, $rA, $rB", IIC_IntGeneral,
2205                         [(set i32:$rT, (addc i32:$rA, i32:$rB))]>,
2206                         PPC970_DGroup_Cracked;
2207
2208 defm DIVW  : XOForm_1r<31, 491, 0, (outs gprc:$rT), (ins gprc:$rA, gprc:$rB),
2209                        "divw", "$rT, $rA, $rB", IIC_IntDivW,
2210                        [(set i32:$rT, (sdiv i32:$rA, i32:$rB))]>,
2211                        PPC970_DGroup_First, PPC970_DGroup_Cracked;
2212 defm DIVWU : XOForm_1r<31, 459, 0, (outs gprc:$rT), (ins gprc:$rA, gprc:$rB),
2213                        "divwu", "$rT, $rA, $rB", IIC_IntDivW,
2214                        [(set i32:$rT, (udiv i32:$rA, i32:$rB))]>,
2215                        PPC970_DGroup_First, PPC970_DGroup_Cracked;
2216 let isCommutable = 1 in {
2217 defm MULHW : XOForm_1r<31, 75, 0, (outs gprc:$rT), (ins gprc:$rA, gprc:$rB),
2218                        "mulhw", "$rT, $rA, $rB", IIC_IntMulHW,
2219                        [(set i32:$rT, (mulhs i32:$rA, i32:$rB))]>;
2220 defm MULHWU : XOForm_1r<31, 11, 0, (outs gprc:$rT), (ins gprc:$rA, gprc:$rB),
2221                        "mulhwu", "$rT, $rA, $rB", IIC_IntMulHWU,
2222                        [(set i32:$rT, (mulhu i32:$rA, i32:$rB))]>;
2223 defm MULLW : XOForm_1r<31, 235, 0, (outs gprc:$rT), (ins gprc:$rA, gprc:$rB),
2224                        "mullw", "$rT, $rA, $rB", IIC_IntMulHW,
2225                        [(set i32:$rT, (mul i32:$rA, i32:$rB))]>;
2226 } // isCommutable
2227 defm SUBF  : XOForm_1r<31, 40, 0, (outs gprc:$rT), (ins gprc:$rA, gprc:$rB),
2228                        "subf", "$rT, $rA, $rB", IIC_IntGeneral,
2229                        [(set i32:$rT, (sub i32:$rB, i32:$rA))]>;
2230 defm SUBFC : XOForm_1rc<31, 8, 0, (outs gprc:$rT), (ins gprc:$rA, gprc:$rB),
2231                         "subfc", "$rT, $rA, $rB", IIC_IntGeneral,
2232                         [(set i32:$rT, (subc i32:$rB, i32:$rA))]>,
2233                         PPC970_DGroup_Cracked;
2234 defm NEG    : XOForm_3r<31, 104, 0, (outs gprc:$rT), (ins gprc:$rA),
2235                         "neg", "$rT, $rA", IIC_IntSimple,
2236                         [(set i32:$rT, (ineg i32:$rA))]>;
2237 let Uses = [CARRY] in {
2238 let isCommutable = 1 in
2239 defm ADDE  : XOForm_1rc<31, 138, 0, (outs gprc:$rT), (ins gprc:$rA, gprc:$rB),
2240                         "adde", "$rT, $rA, $rB", IIC_IntGeneral,
2241                         [(set i32:$rT, (adde i32:$rA, i32:$rB))]>;
2242 defm ADDME  : XOForm_3rc<31, 234, 0, (outs gprc:$rT), (ins gprc:$rA),
2243                          "addme", "$rT, $rA", IIC_IntGeneral,
2244                          [(set i32:$rT, (adde i32:$rA, -1))]>;
2245 defm ADDZE  : XOForm_3rc<31, 202, 0, (outs gprc:$rT), (ins gprc:$rA),
2246                          "addze", "$rT, $rA", IIC_IntGeneral,
2247                          [(set i32:$rT, (adde i32:$rA, 0))]>;
2248 defm SUBFE : XOForm_1rc<31, 136, 0, (outs gprc:$rT), (ins gprc:$rA, gprc:$rB),
2249                         "subfe", "$rT, $rA, $rB", IIC_IntGeneral,
2250                         [(set i32:$rT, (sube i32:$rB, i32:$rA))]>;
2251 defm SUBFME : XOForm_3rc<31, 232, 0, (outs gprc:$rT), (ins gprc:$rA),
2252                          "subfme", "$rT, $rA", IIC_IntGeneral,
2253                          [(set i32:$rT, (sube -1, i32:$rA))]>;
2254 defm SUBFZE : XOForm_3rc<31, 200, 0, (outs gprc:$rT), (ins gprc:$rA),
2255                          "subfze", "$rT, $rA", IIC_IntGeneral,
2256                          [(set i32:$rT, (sube 0, i32:$rA))]>;
2257 }
2258 }
2259
2260 // A-Form instructions.  Most of the instructions executed in the FPU are of
2261 // this type.
2262 //
2263 let PPC970_Unit = 3, hasSideEffects = 0 in {  // FPU Operations.
2264 let Uses = [RM] in {
2265 let isCommutable = 1 in {
2266   defm FMADD : AForm_1r<63, 29, 
2267                       (outs f8rc:$FRT), (ins f8rc:$FRA, f8rc:$FRC, f8rc:$FRB),
2268                       "fmadd", "$FRT, $FRA, $FRC, $FRB", IIC_FPFused,
2269                       [(set f64:$FRT, (fma f64:$FRA, f64:$FRC, f64:$FRB))]>;
2270   defm FMADDS : AForm_1r<59, 29,
2271                       (outs f4rc:$FRT), (ins f4rc:$FRA, f4rc:$FRC, f4rc:$FRB),
2272                       "fmadds", "$FRT, $FRA, $FRC, $FRB", IIC_FPGeneral,
2273                       [(set f32:$FRT, (fma f32:$FRA, f32:$FRC, f32:$FRB))]>;
2274   defm FMSUB : AForm_1r<63, 28,
2275                       (outs f8rc:$FRT), (ins f8rc:$FRA, f8rc:$FRC, f8rc:$FRB),
2276                       "fmsub", "$FRT, $FRA, $FRC, $FRB", IIC_FPFused,
2277                       [(set f64:$FRT,
2278                             (fma f64:$FRA, f64:$FRC, (fneg f64:$FRB)))]>;
2279   defm FMSUBS : AForm_1r<59, 28,
2280                       (outs f4rc:$FRT), (ins f4rc:$FRA, f4rc:$FRC, f4rc:$FRB),
2281                       "fmsubs", "$FRT, $FRA, $FRC, $FRB", IIC_FPGeneral,
2282                       [(set f32:$FRT,
2283                             (fma f32:$FRA, f32:$FRC, (fneg f32:$FRB)))]>;
2284   defm FNMADD : AForm_1r<63, 31,
2285                       (outs f8rc:$FRT), (ins f8rc:$FRA, f8rc:$FRC, f8rc:$FRB),
2286                       "fnmadd", "$FRT, $FRA, $FRC, $FRB", IIC_FPFused,
2287                       [(set f64:$FRT,
2288                             (fneg (fma f64:$FRA, f64:$FRC, f64:$FRB)))]>;
2289   defm FNMADDS : AForm_1r<59, 31,
2290                       (outs f4rc:$FRT), (ins f4rc:$FRA, f4rc:$FRC, f4rc:$FRB),
2291                       "fnmadds", "$FRT, $FRA, $FRC, $FRB", IIC_FPGeneral,
2292                       [(set f32:$FRT,
2293                             (fneg (fma f32:$FRA, f32:$FRC, f32:$FRB)))]>;
2294   defm FNMSUB : AForm_1r<63, 30,
2295                       (outs f8rc:$FRT), (ins f8rc:$FRA, f8rc:$FRC, f8rc:$FRB),
2296                       "fnmsub", "$FRT, $FRA, $FRC, $FRB", IIC_FPFused,
2297                       [(set f64:$FRT, (fneg (fma f64:$FRA, f64:$FRC,
2298                                                  (fneg f64:$FRB))))]>;
2299   defm FNMSUBS : AForm_1r<59, 30,
2300                       (outs f4rc:$FRT), (ins f4rc:$FRA, f4rc:$FRC, f4rc:$FRB),
2301                       "fnmsubs", "$FRT, $FRA, $FRC, $FRB", IIC_FPGeneral,
2302                       [(set f32:$FRT, (fneg (fma f32:$FRA, f32:$FRC,
2303                                                  (fneg f32:$FRB))))]>;
2304 } // isCommutable
2305 }
2306 // FSEL is artificially split into 4 and 8-byte forms for the result.  To avoid
2307 // having 4 of these, force the comparison to always be an 8-byte double (code
2308 // should use an FMRSD if the input comparison value really wants to be a float)
2309 // and 4/8 byte forms for the result and operand type..
2310 let Interpretation64Bit = 1, isCodeGenOnly = 1 in
2311 defm FSELD : AForm_1r<63, 23,
2312                       (outs f8rc:$FRT), (ins f8rc:$FRA, f8rc:$FRC, f8rc:$FRB),
2313                       "fsel", "$FRT, $FRA, $FRC, $FRB", IIC_FPGeneral,
2314                       [(set f64:$FRT, (PPCfsel f64:$FRA, f64:$FRC, f64:$FRB))]>;
2315 defm FSELS : AForm_1r<63, 23,
2316                       (outs f4rc:$FRT), (ins f8rc:$FRA, f4rc:$FRC, f4rc:$FRB),
2317                       "fsel", "$FRT, $FRA, $FRC, $FRB", IIC_FPGeneral,
2318                       [(set f32:$FRT, (PPCfsel f64:$FRA, f32:$FRC, f32:$FRB))]>;
2319 let Uses = [RM] in {
2320   let isCommutable = 1 in {
2321   defm FADD  : AForm_2r<63, 21,
2322                         (outs f8rc:$FRT), (ins f8rc:$FRA, f8rc:$FRB),
2323                         "fadd", "$FRT, $FRA, $FRB", IIC_FPAddSub,
2324                         [(set f64:$FRT, (fadd f64:$FRA, f64:$FRB))]>;
2325   defm FADDS : AForm_2r<59, 21,
2326                         (outs f4rc:$FRT), (ins f4rc:$FRA, f4rc:$FRB),
2327                         "fadds", "$FRT, $FRA, $FRB", IIC_FPGeneral,
2328                         [(set f32:$FRT, (fadd f32:$FRA, f32:$FRB))]>;
2329   } // isCommutable
2330   defm FDIV  : AForm_2r<63, 18,
2331                         (outs f8rc:$FRT), (ins f8rc:$FRA, f8rc:$FRB),
2332                         "fdiv", "$FRT, $FRA, $FRB", IIC_FPDivD,
2333                         [(set f64:$FRT, (fdiv f64:$FRA, f64:$FRB))]>;
2334   defm FDIVS : AForm_2r<59, 18,
2335                         (outs f4rc:$FRT), (ins f4rc:$FRA, f4rc:$FRB),
2336                         "fdivs", "$FRT, $FRA, $FRB", IIC_FPDivS,
2337                         [(set f32:$FRT, (fdiv f32:$FRA, f32:$FRB))]>;
2338   let isCommutable = 1 in {
2339   defm FMUL  : AForm_3r<63, 25,
2340                         (outs f8rc:$FRT), (ins f8rc:$FRA, f8rc:$FRC),
2341                         "fmul", "$FRT, $FRA, $FRC", IIC_FPFused,
2342                         [(set f64:$FRT, (fmul f64:$FRA, f64:$FRC))]>;
2343   defm FMULS : AForm_3r<59, 25,
2344                         (outs f4rc:$FRT), (ins f4rc:$FRA, f4rc:$FRC),
2345                         "fmuls", "$FRT, $FRA, $FRC", IIC_FPGeneral,
2346                         [(set f32:$FRT, (fmul f32:$FRA, f32:$FRC))]>;
2347   } // isCommutable
2348   defm FSUB  : AForm_2r<63, 20,
2349                         (outs f8rc:$FRT), (ins f8rc:$FRA, f8rc:$FRB),
2350                         "fsub", "$FRT, $FRA, $FRB", IIC_FPAddSub,
2351                         [(set f64:$FRT, (fsub f64:$FRA, f64:$FRB))]>;
2352   defm FSUBS : AForm_2r<59, 20,
2353                         (outs f4rc:$FRT), (ins f4rc:$FRA, f4rc:$FRB),
2354                         "fsubs", "$FRT, $FRA, $FRB", IIC_FPGeneral,
2355                         [(set f32:$FRT, (fsub f32:$FRA, f32:$FRB))]>;
2356   }
2357 }
2358
2359 let hasSideEffects = 0 in {
2360 let PPC970_Unit = 1 in {  // FXU Operations.
2361   let isSelect = 1 in
2362   def ISEL  : AForm_4<31, 15,
2363                      (outs gprc:$rT), (ins gprc_nor0:$rA, gprc:$rB, crbitrc:$cond),
2364                      "isel $rT, $rA, $rB, $cond", IIC_IntGeneral,
2365                      []>;
2366 }
2367
2368 let PPC970_Unit = 1 in {  // FXU Operations.
2369 // M-Form instructions.  rotate and mask instructions.
2370 //
2371 let isCommutable = 1 in {
2372 // RLWIMI can be commuted if the rotate amount is zero.
2373 defm RLWIMI : MForm_2r<20, (outs gprc:$rA),
2374                        (ins gprc:$rSi, gprc:$rS, u5imm:$SH, u5imm:$MB,
2375                        u5imm:$ME), "rlwimi", "$rA, $rS, $SH, $MB, $ME",
2376                        IIC_IntRotate, []>, PPC970_DGroup_Cracked,
2377                        RegConstraint<"$rSi = $rA">, NoEncode<"$rSi">;
2378 }
2379 let BaseName = "rlwinm" in {
2380 def RLWINM : MForm_2<21,
2381                      (outs gprc:$rA), (ins gprc:$rS, u5imm:$SH, u5imm:$MB, u5imm:$ME),
2382                      "rlwinm $rA, $rS, $SH, $MB, $ME", IIC_IntGeneral,
2383                      []>, RecFormRel;
2384 let Defs = [CR0] in
2385 def RLWINMo : MForm_2<21,
2386                       (outs gprc:$rA), (ins gprc:$rS, u5imm:$SH, u5imm:$MB, u5imm:$ME),
2387                       "rlwinm. $rA, $rS, $SH, $MB, $ME", IIC_IntGeneral,
2388                       []>, isDOT, RecFormRel, PPC970_DGroup_Cracked;
2389 }
2390 defm RLWNM  : MForm_2r<23, (outs gprc:$rA),
2391                        (ins gprc:$rS, gprc:$rB, u5imm:$MB, u5imm:$ME),
2392                        "rlwnm", "$rA, $rS, $rB, $MB, $ME", IIC_IntGeneral,
2393                        []>;
2394 }
2395 } // hasSideEffects = 0
2396
2397 //===----------------------------------------------------------------------===//
2398 // PowerPC Instruction Patterns
2399 //
2400
2401 // Arbitrary immediate support.  Implement in terms of LIS/ORI.
2402 def : Pat<(i32 imm:$imm),
2403           (ORI (LIS (HI16 imm:$imm)), (LO16 imm:$imm))>;
2404
2405 // Implement the 'not' operation with the NOR instruction.
2406 def i32not : OutPatFrag<(ops node:$in),
2407                         (NOR $in, $in)>;
2408 def        : Pat<(not i32:$in),
2409                  (i32not $in)>;
2410
2411 // ADD an arbitrary immediate.
2412 def : Pat<(add i32:$in, imm:$imm),
2413           (ADDIS (ADDI $in, (LO16 imm:$imm)), (HA16 imm:$imm))>;
2414 // OR an arbitrary immediate.
2415 def : Pat<(or i32:$in, imm:$imm),
2416           (ORIS (ORI $in, (LO16 imm:$imm)), (HI16 imm:$imm))>;
2417 // XOR an arbitrary immediate.
2418 def : Pat<(xor i32:$in, imm:$imm),
2419           (XORIS (XORI $in, (LO16 imm:$imm)), (HI16 imm:$imm))>;
2420 // SUBFIC
2421 def : Pat<(sub imm32SExt16:$imm, i32:$in),
2422           (SUBFIC $in, imm:$imm)>;
2423
2424 // SHL/SRL
2425 def : Pat<(shl i32:$in, (i32 imm:$imm)),
2426           (RLWINM $in, imm:$imm, 0, (SHL32 imm:$imm))>;
2427 def : Pat<(srl i32:$in, (i32 imm:$imm)),
2428           (RLWINM $in, (SRL32 imm:$imm), imm:$imm, 31)>;
2429
2430 // ROTL
2431 def : Pat<(rotl i32:$in, i32:$sh),
2432           (RLWNM $in, $sh, 0, 31)>;
2433 def : Pat<(rotl i32:$in, (i32 imm:$imm)),
2434           (RLWINM $in, imm:$imm, 0, 31)>;
2435
2436 // RLWNM
2437 def : Pat<(and (rotl i32:$in, i32:$sh), maskimm32:$imm),
2438           (RLWNM $in, $sh, (MB maskimm32:$imm), (ME maskimm32:$imm))>;
2439
2440 // Calls
2441 def : Pat<(PPCcall (i32 tglobaladdr:$dst)),
2442           (BL tglobaladdr:$dst)>;
2443 def : Pat<(PPCcall (i32 texternalsym:$dst)),
2444           (BL texternalsym:$dst)>;
2445
2446 def : Pat<(PPCcall_tls texternalsym:$func, tglobaltlsaddr:$sym),
2447           (BL_TLS texternalsym:$func, tglobaltlsaddr:$sym)>;
2448
2449 def : Pat<(PPCtc_return (i32 tglobaladdr:$dst),  imm:$imm),
2450           (TCRETURNdi tglobaladdr:$dst, imm:$imm)>;
2451
2452 def : Pat<(PPCtc_return (i32 texternalsym:$dst), imm:$imm),
2453           (TCRETURNdi texternalsym:$dst, imm:$imm)>;
2454
2455 def : Pat<(PPCtc_return CTRRC:$dst, imm:$imm),
2456           (TCRETURNri CTRRC:$dst, imm:$imm)>;
2457
2458
2459
2460 // Hi and Lo for Darwin Global Addresses.
2461 def : Pat<(PPChi tglobaladdr:$in, 0), (LIS tglobaladdr:$in)>;
2462 def : Pat<(PPClo tglobaladdr:$in, 0), (LI tglobaladdr:$in)>;
2463 def : Pat<(PPChi tconstpool:$in, 0), (LIS tconstpool:$in)>;
2464 def : Pat<(PPClo tconstpool:$in, 0), (LI tconstpool:$in)>;
2465 def : Pat<(PPChi tjumptable:$in, 0), (LIS tjumptable:$in)>;
2466 def : Pat<(PPClo tjumptable:$in, 0), (LI tjumptable:$in)>;
2467 def : Pat<(PPChi tblockaddress:$in, 0), (LIS tblockaddress:$in)>;
2468 def : Pat<(PPClo tblockaddress:$in, 0), (LI tblockaddress:$in)>;
2469 def : Pat<(PPChi tglobaltlsaddr:$g, i32:$in),
2470           (ADDIS $in, tglobaltlsaddr:$g)>;
2471 def : Pat<(PPClo tglobaltlsaddr:$g, i32:$in),
2472           (ADDI $in, tglobaltlsaddr:$g)>;
2473 def : Pat<(add i32:$in, (PPChi tglobaladdr:$g, 0)),
2474           (ADDIS $in, tglobaladdr:$g)>;
2475 def : Pat<(add i32:$in, (PPChi tconstpool:$g, 0)),
2476           (ADDIS $in, tconstpool:$g)>;
2477 def : Pat<(add i32:$in, (PPChi tjumptable:$g, 0)),
2478           (ADDIS $in, tjumptable:$g)>;
2479 def : Pat<(add i32:$in, (PPChi tblockaddress:$g, 0)),
2480           (ADDIS $in, tblockaddress:$g)>;
2481
2482 // Support for thread-local storage.
2483 def PPC32GOT: Pseudo<(outs gprc:$rD), (ins), "#PPC32GOT", 
2484                 [(set i32:$rD, (PPCppc32GOT))]>;
2485
2486 // Get the _GLOBAL_OFFSET_TABLE_ in PIC mode.
2487 // This uses two output registers, the first as the real output, the second as a
2488 // temporary register, used internally in code generation.
2489 def PPC32PICGOT: Pseudo<(outs gprc:$rD, gprc:$rT), (ins), "#PPC32PICGOT", 
2490                 []>, NoEncode<"$rT">;
2491
2492 def LDgotTprelL32: Pseudo<(outs gprc:$rD), (ins s16imm:$disp, gprc_nor0:$reg),
2493                            "#LDgotTprelL32",
2494                            [(set i32:$rD,
2495                              (PPCldGotTprelL tglobaltlsaddr:$disp, i32:$reg))]>;
2496 def : Pat<(PPCaddTls i32:$in, tglobaltlsaddr:$g),
2497           (ADD4TLS $in, tglobaltlsaddr:$g)>;
2498
2499 def ADDItlsgdL32 : Pseudo<(outs gprc:$rD), (ins gprc_nor0:$reg, s16imm:$disp),
2500                          "#ADDItlsgdL32",
2501                          [(set i32:$rD,
2502                            (PPCaddiTlsgdL i32:$reg, tglobaltlsaddr:$disp))]>;
2503 def ADDItlsldL32 : Pseudo<(outs gprc:$rD), (ins gprc_nor0:$reg, s16imm:$disp),
2504                           "#ADDItlsldL32",
2505                           [(set i32:$rD,
2506                             (PPCaddiTlsldL i32:$reg, tglobaltlsaddr:$disp))]>;
2507 def ADDIdtprelL32 : Pseudo<(outs gprc:$rD), (ins gprc_nor0:$reg, s16imm:$disp),
2508                            "#ADDIdtprelL32",
2509                            [(set i32:$rD,
2510                              (PPCaddiDtprelL i32:$reg, tglobaltlsaddr:$disp))]>;
2511 def ADDISdtprelHA32 : Pseudo<(outs gprc:$rD), (ins gprc_nor0:$reg, s16imm:$disp),
2512                             "#ADDISdtprelHA32",
2513                             [(set i32:$rD,
2514                               (PPCaddisDtprelHA i32:$reg,
2515                                                 tglobaltlsaddr:$disp))]>;
2516
2517 // Support for Position-independent code
2518 def LWZtoc : Pseudo<(outs gprc:$rD), (ins tocentry32:$disp, gprc:$reg),
2519                    "#LWZtoc",
2520                    [(set i32:$rD,
2521                       (PPCtoc_entry tglobaladdr:$disp, i32:$reg))]>;
2522 // Get Global (GOT) Base Register offset, from the word immediately preceding
2523 // the function label.
2524 def UpdateGBR : Pseudo<(outs gprc:$rD, gprc:$rT), (ins gprc:$rI), "#UpdateGBR", []>;
2525
2526
2527 // Standard shifts.  These are represented separately from the real shifts above
2528 // so that we can distinguish between shifts that allow 5-bit and 6-bit shift
2529 // amounts.
2530 def : Pat<(sra i32:$rS, i32:$rB),
2531           (SRAW $rS, $rB)>;
2532 def : Pat<(srl i32:$rS, i32:$rB),
2533           (SRW $rS, $rB)>;
2534 def : Pat<(shl i32:$rS, i32:$rB),
2535           (SLW $rS, $rB)>;
2536
2537 def : Pat<(zextloadi1 iaddr:$src),
2538           (LBZ iaddr:$src)>;
2539 def : Pat<(zextloadi1 xaddr:$src),
2540           (LBZX xaddr:$src)>;
2541 def : Pat<(extloadi1 iaddr:$src),
2542           (LBZ iaddr:$src)>;
2543 def : Pat<(extloadi1 xaddr:$src),
2544           (LBZX xaddr:$src)>;
2545 def : Pat<(extloadi8 iaddr:$src),
2546           (LBZ iaddr:$src)>;
2547 def : Pat<(extloadi8 xaddr:$src),
2548           (LBZX xaddr:$src)>;
2549 def : Pat<(extloadi16 iaddr:$src),
2550           (LHZ iaddr:$src)>;
2551 def : Pat<(extloadi16 xaddr:$src),
2552           (LHZX xaddr:$src)>;
2553 def : Pat<(f64 (extloadf32 iaddr:$src)),
2554           (COPY_TO_REGCLASS (LFS iaddr:$src), F8RC)>;
2555 def : Pat<(f64 (extloadf32 xaddr:$src)),
2556           (COPY_TO_REGCLASS (LFSX xaddr:$src), F8RC)>;
2557
2558 def : Pat<(f64 (fextend f32:$src)),
2559           (COPY_TO_REGCLASS $src, F8RC)>;
2560
2561 // Only seq_cst fences require the heavyweight sync (SYNC 0).
2562 // All others can use the lightweight sync (SYNC 1).
2563 // source: http://www.cl.cam.ac.uk/~pes20/cpp/cpp0xmappings.html
2564 // The rule for seq_cst is duplicated to work with both 64 bits and 32 bits
2565 // versions of Power.
2566 def : Pat<(atomic_fence (i64 7), (imm)), (SYNC 0)>, Requires<[HasSYNC]>;
2567 def : Pat<(atomic_fence (i32 7), (imm)), (SYNC 0)>, Requires<[HasSYNC]>;
2568 def : Pat<(atomic_fence (imm),   (imm)), (SYNC 1)>, Requires<[HasSYNC]>;
2569 def : Pat<(atomic_fence (imm), (imm)), (MSYNC)>, Requires<[HasOnlyMSYNC]>;
2570
2571 // Additional FNMSUB patterns: -a*c + b == -(a*c - b)
2572 def : Pat<(fma (fneg f64:$A), f64:$C, f64:$B),
2573           (FNMSUB $A, $C, $B)>;
2574 def : Pat<(fma f64:$A, (fneg f64:$C), f64:$B),
2575           (FNMSUB $A, $C, $B)>;
2576 def : Pat<(fma (fneg f32:$A), f32:$C, f32:$B),
2577           (FNMSUBS $A, $C, $B)>;
2578 def : Pat<(fma f32:$A, (fneg f32:$C), f32:$B),
2579           (FNMSUBS $A, $C, $B)>;
2580
2581 // FCOPYSIGN's operand types need not agree.
2582 def : Pat<(fcopysign f64:$frB, f32:$frA),
2583           (FCPSGND (COPY_TO_REGCLASS $frA, F8RC), $frB)>;
2584 def : Pat<(fcopysign f32:$frB, f64:$frA),
2585           (FCPSGNS (COPY_TO_REGCLASS $frA, F4RC), $frB)>;
2586
2587 include "PPCInstrAltivec.td"
2588 include "PPCInstrSPE.td"
2589 include "PPCInstr64Bit.td"
2590 include "PPCInstrVSX.td"
2591
2592 def crnot : OutPatFrag<(ops node:$in),
2593                        (CRNOR $in, $in)>;
2594 def       : Pat<(not i1:$in),
2595                 (crnot $in)>;
2596
2597 // Patterns for arithmetic i1 operations.
2598 def : Pat<(add i1:$a, i1:$b),
2599           (CRXOR $a, $b)>;
2600 def : Pat<(sub i1:$a, i1:$b),
2601           (CRXOR $a, $b)>;
2602 def : Pat<(mul i1:$a, i1:$b),
2603           (CRAND $a, $b)>;
2604
2605 // We're sometimes asked to materialize i1 -1, which is just 1 in this case
2606 // (-1 is used to mean all bits set).
2607 def : Pat<(i1 -1), (CRSET)>;
2608
2609 // i1 extensions, implemented in terms of isel.
2610 def : Pat<(i32 (zext i1:$in)),
2611           (SELECT_I4 $in, (LI 1), (LI 0))>;
2612 def : Pat<(i32 (sext i1:$in)),
2613           (SELECT_I4 $in, (LI -1), (LI 0))>;
2614
2615 def : Pat<(i64 (zext i1:$in)),
2616           (SELECT_I8 $in, (LI8 1), (LI8 0))>;
2617 def : Pat<(i64 (sext i1:$in)),
2618           (SELECT_I8 $in, (LI8 -1), (LI8 0))>;
2619
2620 // FIXME: We should choose either a zext or a sext based on other constants
2621 // already around.
2622 def : Pat<(i32 (anyext i1:$in)),
2623           (SELECT_I4 $in, (LI 1), (LI 0))>;
2624 def : Pat<(i64 (anyext i1:$in)),
2625           (SELECT_I8 $in, (LI8 1), (LI8 0))>;
2626
2627 // match setcc on i1 variables.
2628 def : Pat<(i1 (setcc i1:$s1, i1:$s2, SETLT)),
2629           (CRANDC $s2, $s1)>;
2630 def : Pat<(i1 (setcc i1:$s1, i1:$s2, SETULT)),
2631           (CRANDC $s2, $s1)>;
2632 def : Pat<(i1 (setcc i1:$s1, i1:$s2, SETLE)),
2633           (CRORC $s2, $s1)>;
2634 def : Pat<(i1 (setcc i1:$s1, i1:$s2, SETULE)),
2635           (CRORC $s2, $s1)>;
2636 def : Pat<(i1 (setcc i1:$s1, i1:$s2, SETEQ)),
2637           (CREQV $s1, $s2)>;
2638 def : Pat<(i1 (setcc i1:$s1, i1:$s2, SETGE)),
2639           (CRORC $s1, $s2)>;
2640 def : Pat<(i1 (setcc i1:$s1, i1:$s2, SETUGE)),
2641           (CRORC $s1, $s2)>;
2642 def : Pat<(i1 (setcc i1:$s1, i1:$s2, SETGT)),
2643           (CRANDC $s1, $s2)>;
2644 def : Pat<(i1 (setcc i1:$s1, i1:$s2, SETUGT)),
2645           (CRANDC $s1, $s2)>;
2646 def : Pat<(i1 (setcc i1:$s1, i1:$s2, SETNE)),
2647           (CRXOR $s1, $s2)>;
2648
2649 // match setcc on non-i1 (non-vector) variables. Note that SETUEQ, SETOGE,
2650 // SETOLE, SETONE, SETULT and SETUGT should be expanded by legalize for
2651 // floating-point types.
2652
2653 multiclass CRNotPat<dag pattern, dag result> {
2654   def : Pat<pattern, (crnot result)>;
2655   def : Pat<(not pattern), result>;
2656
2657   // We can also fold the crnot into an extension:
2658   def : Pat<(i32 (zext pattern)),
2659             (SELECT_I4 result, (LI 0), (LI 1))>;
2660   def : Pat<(i32 (sext pattern)),
2661             (SELECT_I4 result, (LI 0), (LI -1))>;
2662
2663   // We can also fold the crnot into an extension:
2664   def : Pat<(i64 (zext pattern)),
2665             (SELECT_I8 result, (LI8 0), (LI8 1))>;
2666   def : Pat<(i64 (sext pattern)),
2667             (SELECT_I8 result, (LI8 0), (LI8 -1))>;
2668
2669   // FIXME: We should choose either a zext or a sext based on other constants
2670   // already around.
2671   def : Pat<(i32 (anyext pattern)),
2672             (SELECT_I4 result, (LI 0), (LI 1))>;
2673
2674   def : Pat<(i64 (anyext pattern)),
2675             (SELECT_I8 result, (LI8 0), (LI8 1))>;
2676 }
2677
2678 // FIXME: Because of what seems like a bug in TableGen's type-inference code,
2679 // we need to write imm:$imm in the output patterns below, not just $imm, or
2680 // else the resulting matcher will not correctly add the immediate operand
2681 // (making it a register operand instead).
2682
2683 // extended SETCC.
2684 multiclass ExtSetCCPat<CondCode cc, PatFrag pfrag,
2685                        OutPatFrag rfrag, OutPatFrag rfrag8> {
2686   def : Pat<(i32 (zext (i1 (pfrag i32:$s1, cc)))),
2687             (rfrag $s1)>;
2688   def : Pat<(i64 (zext (i1 (pfrag i64:$s1, cc)))),
2689             (rfrag8 $s1)>;
2690   def : Pat<(i64 (zext (i1 (pfrag i32:$s1, cc)))),
2691             (INSERT_SUBREG (i64 (IMPLICIT_DEF)), (rfrag $s1), sub_32)>;
2692   def : Pat<(i32 (zext (i1 (pfrag i64:$s1, cc)))),
2693             (EXTRACT_SUBREG (rfrag8 $s1), sub_32)>;
2694
2695   def : Pat<(i32 (anyext (i1 (pfrag i32:$s1, cc)))),
2696             (rfrag $s1)>;
2697   def : Pat<(i64 (anyext (i1 (pfrag i64:$s1, cc)))),
2698             (rfrag8 $s1)>;
2699   def : Pat<(i64 (anyext (i1 (pfrag i32:$s1, cc)))),
2700             (INSERT_SUBREG (i64 (IMPLICIT_DEF)), (rfrag $s1), sub_32)>;
2701   def : Pat<(i32 (anyext (i1 (pfrag i64:$s1, cc)))),
2702             (EXTRACT_SUBREG (rfrag8 $s1), sub_32)>;
2703 }
2704
2705 // Note that we do all inversions below with i(32|64)not, instead of using
2706 // (xori x, 1) because on the A2 nor has single-cycle latency while xori
2707 // has 2-cycle latency.
2708
2709 defm : ExtSetCCPat<SETEQ,
2710                    PatFrag<(ops node:$in, node:$cc),
2711                            (setcc $in, 0, $cc)>,
2712                    OutPatFrag<(ops node:$in),
2713                               (RLWINM (CNTLZW $in), 27, 31, 31)>,
2714                    OutPatFrag<(ops node:$in),
2715                               (RLDICL (CNTLZD $in), 58, 63)> >;
2716  
2717 defm : ExtSetCCPat<SETNE,
2718                    PatFrag<(ops node:$in, node:$cc),
2719                            (setcc $in, 0, $cc)>,
2720                    OutPatFrag<(ops node:$in),
2721                               (RLWINM (i32not (CNTLZW $in)), 27, 31, 31)>,
2722                    OutPatFrag<(ops node:$in),
2723                               (RLDICL (i64not (CNTLZD $in)), 58, 63)> >;
2724                  
2725 defm : ExtSetCCPat<SETLT,
2726                    PatFrag<(ops node:$in, node:$cc),
2727                            (setcc $in, 0, $cc)>,
2728                    OutPatFrag<(ops node:$in),
2729                               (RLWINM $in, 1, 31, 31)>,
2730                    OutPatFrag<(ops node:$in),
2731                               (RLDICL $in, 1, 63)> >;
2732
2733 defm : ExtSetCCPat<SETGE,
2734                    PatFrag<(ops node:$in, node:$cc),
2735                            (setcc $in, 0, $cc)>,
2736                    OutPatFrag<(ops node:$in),
2737                               (RLWINM (i32not $in), 1, 31, 31)>,
2738                    OutPatFrag<(ops node:$in),
2739                               (RLDICL (i64not $in), 1, 63)> >;
2740
2741 defm : ExtSetCCPat<SETGT,
2742                    PatFrag<(ops node:$in, node:$cc),
2743                            (setcc $in, 0, $cc)>,
2744                    OutPatFrag<(ops node:$in),
2745                               (RLWINM (ANDC (NEG $in), $in), 1, 31, 31)>,
2746                    OutPatFrag<(ops node:$in),
2747                               (RLDICL (ANDC8 (NEG8 $in), $in), 1, 63)> >;
2748
2749 defm : ExtSetCCPat<SETLE,
2750                    PatFrag<(ops node:$in, node:$cc),
2751                            (setcc $in, 0, $cc)>,
2752                    OutPatFrag<(ops node:$in),
2753                               (RLWINM (ORC $in, (NEG $in)), 1, 31, 31)>,
2754                    OutPatFrag<(ops node:$in),
2755                               (RLDICL (ORC8 $in, (NEG8 $in)), 1, 63)> >;
2756
2757 defm : ExtSetCCPat<SETLT,
2758                    PatFrag<(ops node:$in, node:$cc),
2759                            (setcc $in, -1, $cc)>,
2760                    OutPatFrag<(ops node:$in),
2761                               (RLWINM (AND $in, (ADDI $in, 1)), 1, 31, 31)>,
2762                    OutPatFrag<(ops node:$in),
2763                               (RLDICL (AND8 $in, (ADDI8 $in, 1)), 1, 63)> >;
2764
2765 defm : ExtSetCCPat<SETGE,
2766                    PatFrag<(ops node:$in, node:$cc),
2767                            (setcc $in, -1, $cc)>,
2768                    OutPatFrag<(ops node:$in),
2769                               (RLWINM (NAND $in, (ADDI $in, 1)), 1, 31, 31)>,
2770                    OutPatFrag<(ops node:$in),
2771                               (RLDICL (NAND8 $in, (ADDI8 $in, 1)), 1, 63)> >;
2772
2773 defm : ExtSetCCPat<SETGT,
2774                    PatFrag<(ops node:$in, node:$cc),
2775                            (setcc $in, -1, $cc)>,
2776                    OutPatFrag<(ops node:$in),
2777                               (RLWINM (i32not $in), 1, 31, 31)>,
2778                    OutPatFrag<(ops node:$in),
2779                               (RLDICL (i64not $in), 1, 63)> >;
2780
2781 defm : ExtSetCCPat<SETLE,
2782                    PatFrag<(ops node:$in, node:$cc),
2783                            (setcc $in, -1, $cc)>,
2784                    OutPatFrag<(ops node:$in),
2785                               (RLWINM $in, 1, 31, 31)>,
2786                    OutPatFrag<(ops node:$in),
2787                               (RLDICL $in, 1, 63)> >;
2788
2789 // SETCC for i32.
2790 def : Pat<(i1 (setcc i32:$s1, immZExt16:$imm, SETULT)),
2791           (EXTRACT_SUBREG (CMPLWI $s1, imm:$imm), sub_lt)>;
2792 def : Pat<(i1 (setcc i32:$s1, imm32SExt16:$imm, SETLT)),
2793           (EXTRACT_SUBREG (CMPWI $s1, imm:$imm), sub_lt)>;
2794 def : Pat<(i1 (setcc i32:$s1, immZExt16:$imm, SETUGT)),
2795           (EXTRACT_SUBREG (CMPLWI $s1, imm:$imm), sub_gt)>;
2796 def : Pat<(i1 (setcc i32:$s1, imm32SExt16:$imm, SETGT)),
2797           (EXTRACT_SUBREG (CMPWI $s1, imm:$imm), sub_gt)>;
2798 def : Pat<(i1 (setcc i32:$s1, imm32SExt16:$imm, SETEQ)),
2799           (EXTRACT_SUBREG (CMPWI $s1, imm:$imm), sub_eq)>;
2800 def : Pat<(i1 (setcc i32:$s1, immZExt16:$imm, SETEQ)),
2801           (EXTRACT_SUBREG (CMPLWI $s1, imm:$imm), sub_eq)>;
2802
2803 // For non-equality comparisons, the default code would materialize the
2804 // constant, then compare against it, like this:
2805 //   lis r2, 4660
2806 //   ori r2, r2, 22136
2807 //   cmpw cr0, r3, r2
2808 //   beq cr0,L6
2809 // Since we are just comparing for equality, we can emit this instead:
2810 //   xoris r0,r3,0x1234
2811 //   cmplwi cr0,r0,0x5678
2812 //   beq cr0,L6
2813
2814 def : Pat<(i1 (setcc i32:$s1, imm:$imm, SETEQ)),
2815           (EXTRACT_SUBREG (CMPLWI (XORIS $s1, (HI16 imm:$imm)),
2816                                   (LO16 imm:$imm)), sub_eq)>;
2817
2818 defm : CRNotPat<(i1 (setcc i32:$s1, immZExt16:$imm, SETUGE)),
2819                 (EXTRACT_SUBREG (CMPLWI $s1, imm:$imm), sub_lt)>;
2820 defm : CRNotPat<(i1 (setcc i32:$s1, imm32SExt16:$imm, SETGE)),
2821                 (EXTRACT_SUBREG (CMPWI $s1, imm:$imm), sub_lt)>;
2822 defm : CRNotPat<(i1 (setcc i32:$s1, immZExt16:$imm, SETULE)),
2823                 (EXTRACT_SUBREG (CMPLWI $s1, imm:$imm), sub_gt)>;
2824 defm : CRNotPat<(i1 (setcc i32:$s1, imm32SExt16:$imm, SETLE)),
2825                 (EXTRACT_SUBREG (CMPWI $s1, imm:$imm), sub_gt)>;
2826 defm : CRNotPat<(i1 (setcc i32:$s1, imm32SExt16:$imm, SETNE)),
2827                 (EXTRACT_SUBREG (CMPWI $s1, imm:$imm), sub_eq)>;
2828 defm : CRNotPat<(i1 (setcc i32:$s1, immZExt16:$imm, SETNE)),
2829                 (EXTRACT_SUBREG (CMPLWI $s1, imm:$imm), sub_eq)>;
2830
2831 defm : CRNotPat<(i1 (setcc i32:$s1, imm:$imm, SETNE)),
2832                 (EXTRACT_SUBREG (CMPLWI (XORIS $s1, (HI16 imm:$imm)),
2833                                         (LO16 imm:$imm)), sub_eq)>;
2834
2835 def : Pat<(i1 (setcc i32:$s1, i32:$s2, SETULT)),
2836           (EXTRACT_SUBREG (CMPLW $s1, $s2), sub_lt)>;
2837 def : Pat<(i1 (setcc i32:$s1, i32:$s2, SETLT)),
2838           (EXTRACT_SUBREG (CMPW $s1, $s2), sub_lt)>;
2839 def : Pat<(i1 (setcc i32:$s1, i32:$s2, SETUGT)),
2840           (EXTRACT_SUBREG (CMPLW $s1, $s2), sub_gt)>;
2841 def : Pat<(i1 (setcc i32:$s1, i32:$s2, SETGT)),
2842           (EXTRACT_SUBREG (CMPW $s1, $s2), sub_gt)>;
2843 def : Pat<(i1 (setcc i32:$s1, i32:$s2, SETEQ)),
2844           (EXTRACT_SUBREG (CMPW $s1, $s2), sub_eq)>;
2845
2846 defm : CRNotPat<(i1 (setcc i32:$s1, i32:$s2, SETUGE)),
2847                 (EXTRACT_SUBREG (CMPLW $s1, $s2), sub_lt)>;
2848 defm : CRNotPat<(i1 (setcc i32:$s1, i32:$s2, SETGE)),
2849                 (EXTRACT_SUBREG (CMPW $s1, $s2), sub_lt)>;
2850 defm : CRNotPat<(i1 (setcc i32:$s1, i32:$s2, SETULE)),
2851                 (EXTRACT_SUBREG (CMPLW $s1, $s2), sub_gt)>;
2852 defm : CRNotPat<(i1 (setcc i32:$s1, i32:$s2, SETLE)),
2853                 (EXTRACT_SUBREG (CMPW $s1, $s2), sub_gt)>;
2854 defm : CRNotPat<(i1 (setcc i32:$s1, i32:$s2, SETNE)),
2855                 (EXTRACT_SUBREG (CMPW $s1, $s2), sub_eq)>;
2856
2857 // SETCC for i64.
2858 def : Pat<(i1 (setcc i64:$s1, immZExt16:$imm, SETULT)),
2859           (EXTRACT_SUBREG (CMPLDI $s1, imm:$imm), sub_lt)>;
2860 def : Pat<(i1 (setcc i64:$s1, imm64SExt16:$imm, SETLT)),
2861           (EXTRACT_SUBREG (CMPDI $s1, imm:$imm), sub_lt)>;
2862 def : Pat<(i1 (setcc i64:$s1, immZExt16:$imm, SETUGT)),
2863           (EXTRACT_SUBREG (CMPLDI $s1, imm:$imm), sub_gt)>;
2864 def : Pat<(i1 (setcc i64:$s1, imm64SExt16:$imm, SETGT)),
2865           (EXTRACT_SUBREG (CMPDI $s1, imm:$imm), sub_gt)>;
2866 def : Pat<(i1 (setcc i64:$s1, imm64SExt16:$imm, SETEQ)),
2867           (EXTRACT_SUBREG (CMPDI $s1, imm:$imm), sub_eq)>;
2868 def : Pat<(i1 (setcc i64:$s1, immZExt16:$imm, SETEQ)),
2869           (EXTRACT_SUBREG (CMPLDI $s1, imm:$imm), sub_eq)>;
2870
2871 // For non-equality comparisons, the default code would materialize the
2872 // constant, then compare against it, like this:
2873 //   lis r2, 4660
2874 //   ori r2, r2, 22136
2875 //   cmpd cr0, r3, r2
2876 //   beq cr0,L6
2877 // Since we are just comparing for equality, we can emit this instead:
2878 //   xoris r0,r3,0x1234
2879 //   cmpldi cr0,r0,0x5678
2880 //   beq cr0,L6
2881
2882 def : Pat<(i1 (setcc i64:$s1, imm64ZExt32:$imm, SETEQ)),
2883           (EXTRACT_SUBREG (CMPLDI (XORIS8 $s1, (HI16 imm:$imm)),
2884                                   (LO16 imm:$imm)), sub_eq)>;
2885
2886 defm : CRNotPat<(i1 (setcc i64:$s1, immZExt16:$imm, SETUGE)),
2887                 (EXTRACT_SUBREG (CMPLDI $s1, imm:$imm), sub_lt)>;
2888 defm : CRNotPat<(i1 (setcc i64:$s1, imm64SExt16:$imm, SETGE)),
2889                 (EXTRACT_SUBREG (CMPDI $s1, imm:$imm), sub_lt)>;
2890 defm : CRNotPat<(i1 (setcc i64:$s1, immZExt16:$imm, SETULE)),
2891                 (EXTRACT_SUBREG (CMPLDI $s1, imm:$imm), sub_gt)>;
2892 defm : CRNotPat<(i1 (setcc i64:$s1, imm64SExt16:$imm, SETLE)),
2893                 (EXTRACT_SUBREG (CMPDI $s1, imm:$imm), sub_gt)>;
2894 defm : CRNotPat<(i1 (setcc i64:$s1, imm64SExt16:$imm, SETNE)),
2895                 (EXTRACT_SUBREG (CMPDI $s1, imm:$imm), sub_eq)>;
2896 defm : CRNotPat<(i1 (setcc i64:$s1, immZExt16:$imm, SETNE)),
2897                 (EXTRACT_SUBREG (CMPLDI $s1, imm:$imm), sub_eq)>;
2898
2899 defm : CRNotPat<(i1 (setcc i64:$s1, imm64ZExt32:$imm, SETNE)),
2900                 (EXTRACT_SUBREG (CMPLDI (XORIS8 $s1, (HI16 imm:$imm)),
2901                                         (LO16 imm:$imm)), sub_eq)>;
2902
2903 def : Pat<(i1 (setcc i64:$s1, i64:$s2, SETULT)),
2904           (EXTRACT_SUBREG (CMPLD $s1, $s2), sub_lt)>;
2905 def : Pat<(i1 (setcc i64:$s1, i64:$s2, SETLT)),
2906           (EXTRACT_SUBREG (CMPD $s1, $s2), sub_lt)>;
2907 def : Pat<(i1 (setcc i64:$s1, i64:$s2, SETUGT)),
2908           (EXTRACT_SUBREG (CMPLD $s1, $s2), sub_gt)>;
2909 def : Pat<(i1 (setcc i64:$s1, i64:$s2, SETGT)),
2910           (EXTRACT_SUBREG (CMPD $s1, $s2), sub_gt)>;
2911 def : Pat<(i1 (setcc i64:$s1, i64:$s2, SETEQ)),
2912           (EXTRACT_SUBREG (CMPD $s1, $s2), sub_eq)>;
2913
2914 defm : CRNotPat<(i1 (setcc i64:$s1, i64:$s2, SETUGE)),
2915                 (EXTRACT_SUBREG (CMPLD $s1, $s2), sub_lt)>;
2916 defm : CRNotPat<(i1 (setcc i64:$s1, i64:$s2, SETGE)),
2917                 (EXTRACT_SUBREG (CMPD $s1, $s2), sub_lt)>;
2918 defm : CRNotPat<(i1 (setcc i64:$s1, i64:$s2, SETULE)),
2919                 (EXTRACT_SUBREG (CMPLD $s1, $s2), sub_gt)>;
2920 defm : CRNotPat<(i1 (setcc i64:$s1, i64:$s2, SETLE)),
2921                 (EXTRACT_SUBREG (CMPD $s1, $s2), sub_gt)>;
2922 defm : CRNotPat<(i1 (setcc i64:$s1, i64:$s2, SETNE)),
2923                 (EXTRACT_SUBREG (CMPD $s1, $s2), sub_eq)>;
2924
2925 // SETCC for f32.
2926 def : Pat<(i1 (setcc f32:$s1, f32:$s2, SETOLT)),
2927           (EXTRACT_SUBREG (FCMPUS $s1, $s2), sub_lt)>;
2928 def : Pat<(i1 (setcc f32:$s1, f32:$s2, SETLT)),
2929           (EXTRACT_SUBREG (FCMPUS $s1, $s2), sub_lt)>;
2930 def : Pat<(i1 (setcc f32:$s1, f32:$s2, SETOGT)),
2931           (EXTRACT_SUBREG (FCMPUS $s1, $s2), sub_gt)>;
2932 def : Pat<(i1 (setcc f32:$s1, f32:$s2, SETGT)),
2933           (EXTRACT_SUBREG (FCMPUS $s1, $s2), sub_gt)>;
2934 def : Pat<(i1 (setcc f32:$s1, f32:$s2, SETOEQ)),
2935           (EXTRACT_SUBREG (FCMPUS $s1, $s2), sub_eq)>;
2936 def : Pat<(i1 (setcc f32:$s1, f32:$s2, SETEQ)),
2937           (EXTRACT_SUBREG (FCMPUS $s1, $s2), sub_eq)>;
2938 def : Pat<(i1 (setcc f32:$s1, f32:$s2, SETUO)),
2939           (EXTRACT_SUBREG (FCMPUS $s1, $s2), sub_un)>;
2940
2941 defm : CRNotPat<(i1 (setcc f32:$s1, f32:$s2, SETUGE)),
2942                 (EXTRACT_SUBREG (FCMPUS $s1, $s2), sub_lt)>;
2943 defm : CRNotPat<(i1 (setcc f32:$s1, f32:$s2, SETGE)),
2944                 (EXTRACT_SUBREG (FCMPUS $s1, $s2), sub_lt)>;
2945 defm : CRNotPat<(i1 (setcc f32:$s1, f32:$s2, SETULE)),
2946                 (EXTRACT_SUBREG (FCMPUS $s1, $s2), sub_gt)>;
2947 defm : CRNotPat<(i1 (setcc f32:$s1, f32:$s2, SETLE)),
2948                 (EXTRACT_SUBREG (FCMPUS $s1, $s2), sub_gt)>;
2949 defm : CRNotPat<(i1 (setcc f32:$s1, f32:$s2, SETUNE)),
2950                 (EXTRACT_SUBREG (FCMPUS $s1, $s2), sub_eq)>;
2951 defm : CRNotPat<(i1 (setcc f32:$s1, f32:$s2, SETNE)),
2952                 (EXTRACT_SUBREG (FCMPUS $s1, $s2), sub_eq)>;
2953 defm : CRNotPat<(i1 (setcc f32:$s1, f32:$s2, SETO)),
2954                 (EXTRACT_SUBREG (FCMPUS $s1, $s2), sub_un)>;
2955
2956 // SETCC for f64.
2957 def : Pat<(i1 (setcc f64:$s1, f64:$s2, SETOLT)),
2958           (EXTRACT_SUBREG (FCMPUD $s1, $s2), sub_lt)>;
2959 def : Pat<(i1 (setcc f64:$s1, f64:$s2, SETLT)),
2960           (EXTRACT_SUBREG (FCMPUD $s1, $s2), sub_lt)>;
2961 def : Pat<(i1 (setcc f64:$s1, f64:$s2, SETOGT)),
2962           (EXTRACT_SUBREG (FCMPUD $s1, $s2), sub_gt)>;
2963 def : Pat<(i1 (setcc f64:$s1, f64:$s2, SETGT)),
2964           (EXTRACT_SUBREG (FCMPUD $s1, $s2), sub_gt)>;
2965 def : Pat<(i1 (setcc f64:$s1, f64:$s2, SETOEQ)),
2966           (EXTRACT_SUBREG (FCMPUD $s1, $s2), sub_eq)>;
2967 def : Pat<(i1 (setcc f64:$s1, f64:$s2, SETEQ)),
2968           (EXTRACT_SUBREG (FCMPUD $s1, $s2), sub_eq)>;
2969 def : Pat<(i1 (setcc f64:$s1, f64:$s2, SETUO)),
2970           (EXTRACT_SUBREG (FCMPUD $s1, $s2), sub_un)>;
2971
2972 defm : CRNotPat<(i1 (setcc f64:$s1, f64:$s2, SETUGE)),
2973                 (EXTRACT_SUBREG (FCMPUD $s1, $s2), sub_lt)>;
2974 defm : CRNotPat<(i1 (setcc f64:$s1, f64:$s2, SETGE)),
2975                 (EXTRACT_SUBREG (FCMPUD $s1, $s2), sub_lt)>;
2976 defm : CRNotPat<(i1 (setcc f64:$s1, f64:$s2, SETULE)),
2977                 (EXTRACT_SUBREG (FCMPUD $s1, $s2), sub_gt)>;
2978 defm : CRNotPat<(i1 (setcc f64:$s1, f64:$s2, SETLE)),
2979                 (EXTRACT_SUBREG (FCMPUD $s1, $s2), sub_gt)>;
2980 defm : CRNotPat<(i1 (setcc f64:$s1, f64:$s2, SETUNE)),
2981                 (EXTRACT_SUBREG (FCMPUD $s1, $s2), sub_eq)>;
2982 defm : CRNotPat<(i1 (setcc f64:$s1, f64:$s2, SETNE)),
2983                 (EXTRACT_SUBREG (FCMPUD $s1, $s2), sub_eq)>;
2984 defm : CRNotPat<(i1 (setcc f64:$s1, f64:$s2, SETO)),
2985                 (EXTRACT_SUBREG (FCMPUD $s1, $s2), sub_un)>;
2986
2987 // match select on i1 variables:
2988 def : Pat<(i1 (select i1:$cond, i1:$tval, i1:$fval)),
2989           (CROR (CRAND        $cond , $tval),
2990                 (CRAND (crnot $cond), $fval))>;
2991
2992 // match selectcc on i1 variables:
2993 //   select (lhs == rhs), tval, fval is:
2994 //   ((lhs == rhs) & tval) | (!(lhs == rhs) & fval)
2995 def : Pat <(i1 (selectcc i1:$lhs, i1:$rhs, i1:$tval, i1:$fval, SETLT)),
2996            (CROR (CRAND (CRANDC $rhs, $lhs), $tval),
2997                  (CRAND (CRORC  $lhs, $rhs), $fval))>;
2998 def : Pat <(i1 (selectcc i1:$lhs, i1:$rhs, i1:$tval, i1:$fval, SETLE)),
2999            (CROR (CRAND (CRORC  $rhs, $lhs), $tval),
3000                  (CRAND (CRANDC $lhs, $rhs), $fval))>;
3001 def : Pat <(i1 (selectcc i1:$lhs, i1:$rhs, i1:$tval, i1:$fval, SETEQ)),
3002            (CROR (CRAND (CREQV $lhs, $rhs), $tval),
3003                  (CRAND (CRXOR $lhs, $rhs), $fval))>;
3004 def : Pat <(i1 (selectcc i1:$lhs, i1:$rhs, i1:$tval, i1:$fval, SETGE)),
3005            (CROR (CRAND (CRORC  $lhs, $rhs), $tval),
3006                  (CRAND (CRANDC $rhs, $lhs), $fval))>;
3007 def : Pat <(i1 (selectcc i1:$lhs, i1:$rhs, i1:$tval, i1:$fval, SETGT)),
3008            (CROR (CRAND (CRANDC $lhs, $rhs), $tval),
3009                  (CRAND (CRORC  $rhs, $lhs), $fval))>;
3010 def : Pat <(i1 (selectcc i1:$lhs, i1:$rhs, i1:$tval, i1:$fval, SETNE)),
3011            (CROR (CRAND (CREQV $lhs, $rhs), $fval),
3012                  (CRAND (CRXOR $lhs, $rhs), $tval))>;
3013
3014 // match selectcc on i1 variables with non-i1 output.
3015 def : Pat<(i32 (selectcc i1:$lhs, i1:$rhs, i32:$tval, i32:$fval, SETLT)),
3016           (SELECT_I4 (CRANDC $rhs, $lhs), $tval, $fval)>;
3017 def : Pat<(i32 (selectcc i1:$lhs, i1:$rhs, i32:$tval, i32:$fval, SETLE)),
3018           (SELECT_I4 (CRORC  $rhs, $lhs), $tval, $fval)>;
3019 def : Pat<(i32 (selectcc i1:$lhs, i1:$rhs, i32:$tval, i32:$fval, SETEQ)),
3020           (SELECT_I4 (CREQV $lhs, $rhs), $tval, $fval)>;
3021 def : Pat<(i32 (selectcc i1:$lhs, i1:$rhs, i32:$tval, i32:$fval, SETGE)),
3022           (SELECT_I4 (CRORC  $lhs, $rhs), $tval, $fval)>;
3023 def : Pat<(i32 (selectcc i1:$lhs, i1:$rhs, i32:$tval, i32:$fval, SETGT)),
3024           (SELECT_I4 (CRANDC $lhs, $rhs), $tval, $fval)>;
3025 def : Pat<(i32 (selectcc i1:$lhs, i1:$rhs, i32:$tval, i32:$fval, SETNE)),
3026           (SELECT_I4 (CRXOR $lhs, $rhs), $tval, $fval)>;
3027
3028 def : Pat<(i64 (selectcc i1:$lhs, i1:$rhs, i64:$tval, i64:$fval, SETLT)),
3029           (SELECT_I8 (CRANDC $rhs, $lhs), $tval, $fval)>;
3030 def : Pat<(i64 (selectcc i1:$lhs, i1:$rhs, i64:$tval, i64:$fval, SETLE)),
3031           (SELECT_I8 (CRORC  $rhs, $lhs), $tval, $fval)>;
3032 def : Pat<(i64 (selectcc i1:$lhs, i1:$rhs, i64:$tval, i64:$fval, SETEQ)),
3033           (SELECT_I8 (CREQV $lhs, $rhs), $tval, $fval)>;
3034 def : Pat<(i64 (selectcc i1:$lhs, i1:$rhs, i64:$tval, i64:$fval, SETGE)),
3035           (SELECT_I8 (CRORC  $lhs, $rhs), $tval, $fval)>;
3036 def : Pat<(i64 (selectcc i1:$lhs, i1:$rhs, i64:$tval, i64:$fval, SETGT)),
3037           (SELECT_I8 (CRANDC $lhs, $rhs), $tval, $fval)>;
3038 def : Pat<(i64 (selectcc i1:$lhs, i1:$rhs, i64:$tval, i64:$fval, SETNE)),
3039           (SELECT_I8 (CRXOR $lhs, $rhs), $tval, $fval)>;
3040
3041 def : Pat<(f32 (selectcc i1:$lhs, i1:$rhs, f32:$tval, f32:$fval, SETLT)),
3042           (SELECT_F4 (CRANDC $rhs, $lhs), $tval, $fval)>;
3043 def : Pat<(f32 (selectcc i1:$lhs, i1:$rhs, f32:$tval, f32:$fval, SETLE)),
3044           (SELECT_F4 (CRORC  $rhs, $lhs), $tval, $fval)>;
3045 def : Pat<(f32 (selectcc i1:$lhs, i1:$rhs, f32:$tval, f32:$fval, SETEQ)),
3046           (SELECT_F4 (CREQV $lhs, $rhs), $tval, $fval)>;
3047 def : Pat<(f32 (selectcc i1:$lhs, i1:$rhs, f32:$tval, f32:$fval, SETGE)),
3048           (SELECT_F4 (CRORC  $lhs, $rhs), $tval, $fval)>;
3049 def : Pat<(f32 (selectcc i1:$lhs, i1:$rhs, f32:$tval, f32:$fval, SETGT)),
3050           (SELECT_F4 (CRANDC $lhs, $rhs), $tval, $fval)>;
3051 def : Pat<(f32 (selectcc i1:$lhs, i1:$rhs, f32:$tval, f32:$fval, SETNE)),
3052           (SELECT_F4 (CRXOR $lhs, $rhs), $tval, $fval)>;
3053
3054 def : Pat<(f64 (selectcc i1:$lhs, i1:$rhs, f64:$tval, f64:$fval, SETLT)),
3055           (SELECT_F8 (CRANDC $rhs, $lhs), $tval, $fval)>;
3056 def : Pat<(f64 (selectcc i1:$lhs, i1:$rhs, f64:$tval, f64:$fval, SETLE)),
3057           (SELECT_F8 (CRORC  $rhs, $lhs), $tval, $fval)>;
3058 def : Pat<(f64 (selectcc i1:$lhs, i1:$rhs, f64:$tval, f64:$fval, SETEQ)),
3059           (SELECT_F8 (CREQV $lhs, $rhs), $tval, $fval)>;
3060 def : Pat<(f64 (selectcc i1:$lhs, i1:$rhs, f64:$tval, f64:$fval, SETGE)),
3061           (SELECT_F8 (CRORC  $lhs, $rhs), $tval, $fval)>;
3062 def : Pat<(f64 (selectcc i1:$lhs, i1:$rhs, f64:$tval, f64:$fval, SETGT)),
3063           (SELECT_F8 (CRANDC $lhs, $rhs), $tval, $fval)>;
3064 def : Pat<(f64 (selectcc i1:$lhs, i1:$rhs, f64:$tval, f64:$fval, SETNE)),
3065           (SELECT_F8 (CRXOR $lhs, $rhs), $tval, $fval)>;
3066
3067 def : Pat<(v4i32 (selectcc i1:$lhs, i1:$rhs, v4i32:$tval, v4i32:$fval, SETLT)),
3068           (SELECT_VRRC (CRANDC $rhs, $lhs), $tval, $fval)>;
3069 def : Pat<(v4i32 (selectcc i1:$lhs, i1:$rhs, v4i32:$tval, v4i32:$fval, SETLE)),
3070           (SELECT_VRRC (CRORC  $rhs, $lhs), $tval, $fval)>;
3071 def : Pat<(v4i32 (selectcc i1:$lhs, i1:$rhs, v4i32:$tval, v4i32:$fval, SETEQ)),
3072           (SELECT_VRRC (CREQV $lhs, $rhs), $tval, $fval)>;
3073 def : Pat<(v4i32 (selectcc i1:$lhs, i1:$rhs, v4i32:$tval, v4i32:$fval, SETGE)),
3074           (SELECT_VRRC (CRORC  $lhs, $rhs), $tval, $fval)>;
3075 def : Pat<(v4i32 (selectcc i1:$lhs, i1:$rhs, v4i32:$tval, v4i32:$fval, SETGT)),
3076           (SELECT_VRRC (CRANDC $lhs, $rhs), $tval, $fval)>;
3077 def : Pat<(v4i32 (selectcc i1:$lhs, i1:$rhs, v4i32:$tval, v4i32:$fval, SETNE)),
3078           (SELECT_VRRC (CRXOR $lhs, $rhs), $tval, $fval)>;
3079
3080 let usesCustomInserter = 1 in {
3081 def ANDIo_1_EQ_BIT : Pseudo<(outs crbitrc:$dst), (ins gprc:$in),
3082                              "#ANDIo_1_EQ_BIT",
3083                              [(set i1:$dst, (trunc (not i32:$in)))]>;
3084 def ANDIo_1_GT_BIT : Pseudo<(outs crbitrc:$dst), (ins gprc:$in),
3085                              "#ANDIo_1_GT_BIT",
3086                              [(set i1:$dst, (trunc i32:$in))]>;
3087
3088 def ANDIo_1_EQ_BIT8 : Pseudo<(outs crbitrc:$dst), (ins g8rc:$in),
3089                               "#ANDIo_1_EQ_BIT8",
3090                               [(set i1:$dst, (trunc (not i64:$in)))]>;
3091 def ANDIo_1_GT_BIT8 : Pseudo<(outs crbitrc:$dst), (ins g8rc:$in),
3092                               "#ANDIo_1_GT_BIT8",
3093                               [(set i1:$dst, (trunc i64:$in))]>;
3094 }
3095
3096 def : Pat<(i1 (not (trunc i32:$in))),
3097            (ANDIo_1_EQ_BIT $in)>;
3098 def : Pat<(i1 (not (trunc i64:$in))),
3099            (ANDIo_1_EQ_BIT8 $in)>;
3100
3101 //===----------------------------------------------------------------------===//
3102 // PowerPC Instructions used for assembler/disassembler only
3103 //
3104
3105 // FIXME: For B=0 or B > 8, the registers following RT are used.
3106 // WARNING: Do not add patterns for this instruction without fixing this.
3107 def LSWI  : XForm_base_r3xo<31, 597, (outs gprc:$RT), (ins gprc:$A, u5imm:$B),
3108                             "lswi $RT, $A, $B", IIC_LdStLoad, []>;
3109
3110 // FIXME: For B=0 or B > 8, the registers following RT are used.
3111 // WARNING: Do not add patterns for this instruction without fixing this.
3112 def STSWI : XForm_base_r3xo<31, 725, (outs), (ins gprc:$RT, gprc:$A, u5imm:$B),
3113                             "stswi $RT, $A, $B", IIC_LdStLoad, []>;
3114
3115 def ISYNC : XLForm_2_ext<19, 150, 0, 0, 0, (outs), (ins),
3116                          "isync", IIC_SprISYNC, []>;
3117
3118 def ICBI : XForm_1a<31, 982, (outs), (ins memrr:$src),
3119                     "icbi $src", IIC_LdStICBI, []>;
3120
3121 def EIEIO : XForm_24_eieio<31, 854, (outs), (ins),
3122                            "eieio", IIC_LdStLoad, []>;
3123
3124 def WAIT : XForm_24_sync<31, 62, (outs), (ins i32imm:$L),
3125                          "wait $L", IIC_LdStLoad, []>;
3126
3127 def MBAR : XForm_mbar<31, 854, (outs), (ins u5imm:$MO),
3128                          "mbar $MO", IIC_LdStLoad>, Requires<[IsBookE]>;
3129
3130 def MTSR: XForm_sr<31, 210, (outs), (ins gprc:$RS, u4imm:$SR),
3131             "mtsr $SR, $RS", IIC_SprMTSR>;
3132
3133 def MFSR: XForm_sr<31, 595, (outs gprc:$RS), (ins u4imm:$SR),
3134             "mfsr $RS, $SR", IIC_SprMFSR>;
3135
3136 def MTSRIN: XForm_srin<31, 242, (outs), (ins gprc:$RS, gprc:$RB),
3137             "mtsrin $RS, $RB", IIC_SprMTSR>;
3138
3139 def MFSRIN: XForm_srin<31, 659, (outs gprc:$RS), (ins gprc:$RB),
3140             "mfsrin $RS, $RB", IIC_SprMFSR>;
3141
3142 def MTMSR: XForm_mtmsr<31, 146, (outs), (ins gprc:$RS, i32imm:$L),
3143                     "mtmsr $RS, $L", IIC_SprMTMSR>;
3144
3145 def WRTEE: XForm_mtmsr<31, 131, (outs), (ins gprc:$RS),
3146                     "wrtee $RS", IIC_SprMTMSR>, Requires<[IsBookE]> {
3147   let L = 0;
3148 }
3149
3150 def WRTEEI: I<31, (outs), (ins i1imm:$E), "wrteei $E", IIC_SprMTMSR>,
3151               Requires<[IsBookE]> {
3152   bits<1> E;
3153
3154   let Inst{16} = E;
3155   let Inst{21-30} = 163;
3156 }
3157
3158 def DCCCI : XForm_tlb<454, (outs), (ins gprc:$A, gprc:$B),
3159                "dccci $A, $B", IIC_LdStLoad>, Requires<[IsPPC4xx]>;
3160 def ICCCI : XForm_tlb<966, (outs), (ins gprc:$A, gprc:$B),
3161                "iccci $A, $B", IIC_LdStLoad>, Requires<[IsPPC4xx]>;
3162
3163 def : InstAlias<"dci 0", (DCCCI R0, R0)>, Requires<[IsPPC4xx]>;
3164 def : InstAlias<"dccci", (DCCCI R0, R0)>, Requires<[IsPPC4xx]>;
3165 def : InstAlias<"ici 0", (ICCCI R0, R0)>, Requires<[IsPPC4xx]>;
3166 def : InstAlias<"iccci", (ICCCI R0, R0)>, Requires<[IsPPC4xx]>;
3167
3168 def MFMSR : XForm_rs<31, 83, (outs gprc:$RT), (ins),
3169                   "mfmsr $RT", IIC_SprMFMSR, []>;
3170
3171 def MTMSRD : XForm_mtmsr<31, 178, (outs), (ins gprc:$RS, i32imm:$L),
3172                     "mtmsrd $RS, $L", IIC_SprMTMSRD>;
3173
3174 def SLBIE : XForm_16b<31, 434, (outs), (ins gprc:$RB),
3175                         "slbie $RB", IIC_SprSLBIE, []>;
3176
3177 def SLBMTE : XForm_26<31, 402, (outs), (ins gprc:$RS, gprc:$RB),
3178                     "slbmte $RS, $RB", IIC_SprSLBMTE, []>;
3179
3180 def SLBMFEE : XForm_26<31, 915, (outs gprc:$RT), (ins gprc:$RB),
3181                        "slbmfee $RT, $RB", IIC_SprSLBMFEE, []>;
3182
3183 def SLBIA : XForm_0<31, 498, (outs), (ins), "slbia", IIC_SprSLBIA, []>;
3184
3185 def TLBIA : XForm_0<31, 370, (outs), (ins),
3186                         "tlbia", IIC_SprTLBIA, []>;
3187
3188 def TLBSYNC : XForm_0<31, 566, (outs), (ins),
3189                         "tlbsync", IIC_SprTLBSYNC, []>;
3190
3191 def TLBIEL : XForm_16b<31, 274, (outs), (ins gprc:$RB),
3192                           "tlbiel $RB", IIC_SprTLBIEL, []>;
3193
3194 def TLBLD : XForm_16b<31, 978, (outs), (ins gprc:$RB),
3195                           "tlbld $RB", IIC_LdStLoad, []>, Requires<[IsPPC6xx]>;
3196 def TLBLI : XForm_16b<31, 1010, (outs), (ins gprc:$RB),
3197                           "tlbli $RB", IIC_LdStLoad, []>, Requires<[IsPPC6xx]>;
3198
3199 def TLBIE : XForm_26<31, 306, (outs), (ins gprc:$RS, gprc:$RB),
3200                           "tlbie $RB,$RS", IIC_SprTLBIE, []>;
3201
3202 def TLBSX : XForm_tlb<914, (outs), (ins gprc:$A, gprc:$B), "tlbsx $A, $B",
3203                 IIC_LdStLoad>, Requires<[IsBookE]>;
3204
3205 def TLBIVAX : XForm_tlb<786, (outs), (ins gprc:$A, gprc:$B), "tlbivax $A, $B",
3206                 IIC_LdStLoad>, Requires<[IsBookE]>;
3207
3208 def TLBRE : XForm_24_eieio<31, 946, (outs), (ins),
3209                            "tlbre", IIC_LdStLoad, []>, Requires<[IsBookE]>;
3210
3211 def TLBWE : XForm_24_eieio<31, 978, (outs), (ins),
3212                            "tlbwe", IIC_LdStLoad, []>, Requires<[IsBookE]>;
3213
3214 def TLBRE2 : XForm_tlbws<31, 946, (outs gprc:$RS), (ins gprc:$A, i1imm:$WS),
3215                "tlbre $RS, $A, $WS", IIC_LdStLoad, []>, Requires<[IsPPC4xx]>;
3216
3217 def TLBWE2 : XForm_tlbws<31, 978, (outs), (ins gprc:$RS, gprc:$A, i1imm:$WS),
3218                "tlbwe $RS, $A, $WS", IIC_LdStLoad, []>, Requires<[IsPPC4xx]>;
3219
3220 def TLBSX2 : XForm_base_r3xo<31, 914, (outs), (ins gprc:$RST, gprc:$A, gprc:$B),
3221                              "tlbsx $RST, $A, $B", IIC_LdStLoad, []>,
3222                              Requires<[IsPPC4xx]>;
3223 def TLBSX2D : XForm_base_r3xo<31, 914, (outs),
3224                               (ins gprc:$RST, gprc:$A, gprc:$B),
3225                               "tlbsx. $RST, $A, $B", IIC_LdStLoad, []>,
3226                               Requires<[IsPPC4xx]>, isDOT;
3227
3228 def RFID : XForm_0<19, 18, (outs), (ins), "rfid", IIC_IntRFID, []>;
3229
3230 def RFI : XForm_0<19, 50, (outs), (ins), "rfi", IIC_SprRFI, []>,
3231                   Requires<[IsBookE]>;
3232 def RFCI : XForm_0<19, 51, (outs), (ins), "rfci", IIC_BrB, []>,
3233                    Requires<[IsBookE]>;
3234
3235 def RFDI : XForm_0<19, 39, (outs), (ins), "rfdi", IIC_BrB, []>,
3236                    Requires<[IsE500]>;
3237 def RFMCI : XForm_0<19, 38, (outs), (ins), "rfmci", IIC_BrB, []>,
3238                     Requires<[IsE500]>;
3239
3240 def MFDCR : XFXForm_1<31, 323, (outs gprc:$RT), (ins i32imm:$SPR),
3241                       "mfdcr $RT, $SPR", IIC_SprMFSPR>, Requires<[IsPPC4xx]>;
3242 def MTDCR : XFXForm_1<31, 451, (outs), (ins gprc:$RT, i32imm:$SPR),
3243                       "mtdcr $SPR, $RT", IIC_SprMTSPR>, Requires<[IsPPC4xx]>;
3244
3245 def ATTN : XForm_attn<0, 256, (outs), (ins), "attn", IIC_BrB>;
3246
3247 def LBZCIX : XForm_base_r3xo<31, 853, (outs gprc:$RST), (ins gprc:$A, gprc:$B),
3248                              "lbzcix $RST, $A, $B", IIC_LdStLoad, []>;
3249 def LHZCIX : XForm_base_r3xo<31, 821, (outs gprc:$RST), (ins gprc:$A, gprc:$B),
3250                              "lhzcix $RST, $A, $B", IIC_LdStLoad, []>;
3251 def LWZCIX : XForm_base_r3xo<31, 789, (outs gprc:$RST), (ins gprc:$A, gprc:$B),
3252                              "lwzcix $RST, $A, $B", IIC_LdStLoad, []>;
3253 def LDCIX :  XForm_base_r3xo<31, 885, (outs gprc:$RST), (ins gprc:$A, gprc:$B),
3254                              "ldcix $RST, $A, $B", IIC_LdStLoad, []>;
3255
3256 def STBCIX : XForm_base_r3xo<31, 981, (outs), (ins gprc:$RST, gprc:$A, gprc:$B),
3257                              "stbcix $RST, $A, $B", IIC_LdStLoad, []>;
3258 def STHCIX : XForm_base_r3xo<31, 949, (outs), (ins gprc:$RST, gprc:$A, gprc:$B),
3259                              "sthcix $RST, $A, $B", IIC_LdStLoad, []>;
3260 def STWCIX : XForm_base_r3xo<31, 917, (outs), (ins gprc:$RST, gprc:$A, gprc:$B),
3261                              "stwcix $RST, $A, $B", IIC_LdStLoad, []>;
3262 def STDCIX : XForm_base_r3xo<31, 1013, (outs), (ins gprc:$RST, gprc:$A, gprc:$B),
3263                              "stdcix $RST, $A, $B", IIC_LdStLoad, []>;
3264
3265 //===----------------------------------------------------------------------===//
3266 // PowerPC Assembler Instruction Aliases
3267 //
3268
3269 // Pseudo-instructions for alternate assembly syntax (never used by codegen).
3270 // These are aliases that require C++ handling to convert to the target
3271 // instruction, while InstAliases can be handled directly by tblgen.
3272 class PPCAsmPseudo<string asm, dag iops>
3273   : Instruction {
3274   let Namespace = "PPC";
3275   bit PPC64 = 0;  // Default value, override with isPPC64
3276
3277   let OutOperandList = (outs);
3278   let InOperandList = iops;
3279   let Pattern = [];
3280   let AsmString = asm;
3281   let isAsmParserOnly = 1;
3282   let isPseudo = 1;
3283 }
3284
3285 def : InstAlias<"sc", (SC 0)>;
3286
3287 def : InstAlias<"sync", (SYNC 0)>, Requires<[HasSYNC]>;
3288 def : InstAlias<"msync", (SYNC 0)>, Requires<[HasSYNC]>;
3289 def : InstAlias<"lwsync", (SYNC 1)>, Requires<[HasSYNC]>;
3290 def : InstAlias<"ptesync", (SYNC 2)>, Requires<[HasSYNC]>;
3291
3292 def : InstAlias<"wait", (WAIT 0)>;
3293 def : InstAlias<"waitrsv", (WAIT 1)>;
3294 def : InstAlias<"waitimpl", (WAIT 2)>;
3295
3296 def : InstAlias<"mbar", (MBAR 0)>, Requires<[IsBookE]>;
3297
3298 def : InstAlias<"crset $bx", (CREQV crbitrc:$bx, crbitrc:$bx, crbitrc:$bx)>;
3299 def : InstAlias<"crclr $bx", (CRXOR crbitrc:$bx, crbitrc:$bx, crbitrc:$bx)>;
3300 def : InstAlias<"crmove $bx, $by", (CROR crbitrc:$bx, crbitrc:$by, crbitrc:$by)>;
3301 def : InstAlias<"crnot $bx, $by", (CRNOR crbitrc:$bx, crbitrc:$by, crbitrc:$by)>;
3302
3303 def : InstAlias<"mtxer $Rx", (MTSPR 1, gprc:$Rx)>;
3304 def : InstAlias<"mfxer $Rx", (MFSPR gprc:$Rx, 1)>;
3305
3306 def : InstAlias<"mfrtcu $Rx", (MFSPR gprc:$Rx, 4)>;
3307 def : InstAlias<"mfrtcl $Rx", (MFSPR gprc:$Rx, 5)>;
3308
3309 def : InstAlias<"mtdscr $Rx", (MTSPR 17, gprc:$Rx)>;
3310 def : InstAlias<"mfdscr $Rx", (MFSPR gprc:$Rx, 17)>;
3311
3312 def : InstAlias<"mtdsisr $Rx", (MTSPR 18, gprc:$Rx)>;
3313 def : InstAlias<"mfdsisr $Rx", (MFSPR gprc:$Rx, 18)>;
3314
3315 def : InstAlias<"mtdar $Rx", (MTSPR 19, gprc:$Rx)>;
3316 def : InstAlias<"mfdar $Rx", (MFSPR gprc:$Rx, 19)>;
3317
3318 def : InstAlias<"mtdec $Rx", (MTSPR 22, gprc:$Rx)>;
3319 def : InstAlias<"mfdec $Rx", (MFSPR gprc:$Rx, 22)>;
3320
3321 def : InstAlias<"mtsdr1 $Rx", (MTSPR 25, gprc:$Rx)>;
3322 def : InstAlias<"mfsdr1 $Rx", (MFSPR gprc:$Rx, 25)>;
3323
3324 def : InstAlias<"mtsrr0 $Rx", (MTSPR 26, gprc:$Rx)>;
3325 def : InstAlias<"mfsrr0 $Rx", (MFSPR gprc:$Rx, 26)>;
3326
3327 def : InstAlias<"mtsrr1 $Rx", (MTSPR 27, gprc:$Rx)>;
3328 def : InstAlias<"mfsrr1 $Rx", (MFSPR gprc:$Rx, 27)>;
3329
3330 def : InstAlias<"mtsrr2 $Rx", (MTSPR 990, gprc:$Rx)>, Requires<[IsPPC4xx]>;
3331 def : InstAlias<"mfsrr2 $Rx", (MFSPR gprc:$Rx, 990)>, Requires<[IsPPC4xx]>;
3332
3333 def : InstAlias<"mtsrr3 $Rx", (MTSPR 991, gprc:$Rx)>, Requires<[IsPPC4xx]>;
3334 def : InstAlias<"mfsrr3 $Rx", (MFSPR gprc:$Rx, 991)>, Requires<[IsPPC4xx]>;
3335
3336 def : InstAlias<"mtcfar $Rx", (MTSPR 28, gprc:$Rx)>;
3337 def : InstAlias<"mfcfar $Rx", (MFSPR gprc:$Rx, 28)>;
3338
3339 def : InstAlias<"mtamr $Rx", (MTSPR 29, gprc:$Rx)>;
3340 def : InstAlias<"mfamr $Rx", (MFSPR gprc:$Rx, 29)>;
3341
3342 def : InstAlias<"mtpid $Rx", (MTSPR 48, gprc:$Rx)>, Requires<[IsBookE]>;
3343 def : InstAlias<"mfpid $Rx", (MFSPR gprc:$Rx, 48)>, Requires<[IsBookE]>;
3344
3345 def : InstAlias<"mftb $Rx", (MFTB gprc:$Rx, 268)>;
3346 def : InstAlias<"mftbl $Rx", (MFTB gprc:$Rx, 268)>;
3347 def : InstAlias<"mftbu $Rx", (MFTB gprc:$Rx, 269)>;
3348
3349 def : InstAlias<"mttbl $Rx", (MTSPR 284, gprc:$Rx)>;
3350 def : InstAlias<"mttbu $Rx", (MTSPR 285, gprc:$Rx)>;
3351
3352 def : InstAlias<"mftblo $Rx", (MFSPR gprc:$Rx, 989)>, Requires<[IsPPC4xx]>;
3353 def : InstAlias<"mttblo $Rx", (MTSPR 989, gprc:$Rx)>, Requires<[IsPPC4xx]>;
3354 def : InstAlias<"mftbhi $Rx", (MFSPR gprc:$Rx, 988)>, Requires<[IsPPC4xx]>;
3355 def : InstAlias<"mttbhi $Rx", (MTSPR 988, gprc:$Rx)>, Requires<[IsPPC4xx]>;
3356
3357 def : InstAlias<"xnop", (XORI R0, R0, 0)>;
3358
3359 def : InstAlias<"mr $rA, $rB", (OR8 g8rc:$rA, g8rc:$rB, g8rc:$rB)>;
3360 def : InstAlias<"mr. $rA, $rB", (OR8o g8rc:$rA, g8rc:$rB, g8rc:$rB)>;
3361
3362 def : InstAlias<"not $rA, $rB", (NOR8 g8rc:$rA, g8rc:$rB, g8rc:$rB)>;
3363 def : InstAlias<"not. $rA, $rB", (NOR8o g8rc:$rA, g8rc:$rB, g8rc:$rB)>;
3364
3365 def : InstAlias<"mtcr $rA", (MTCRF8 255, g8rc:$rA)>;
3366
3367 foreach BATR = 0-3 in {
3368     def : InstAlias<"mtdbatu "#BATR#", $Rx",
3369                     (MTSPR !add(BATR, !add(BATR, 536)), gprc:$Rx)>,
3370                     Requires<[IsPPC6xx]>;
3371     def : InstAlias<"mfdbatu $Rx, "#BATR,
3372                     (MFSPR gprc:$Rx, !add(BATR, !add(BATR, 536)))>,
3373                     Requires<[IsPPC6xx]>;
3374     def : InstAlias<"mtdbatl "#BATR#", $Rx",
3375                     (MTSPR !add(BATR, !add(BATR, 537)), gprc:$Rx)>,
3376                     Requires<[IsPPC6xx]>;
3377     def : InstAlias<"mfdbatl $Rx, "#BATR,
3378                     (MFSPR gprc:$Rx, !add(BATR, !add(BATR, 537)))>,
3379                     Requires<[IsPPC6xx]>;
3380     def : InstAlias<"mtibatu "#BATR#", $Rx",
3381                     (MTSPR !add(BATR, !add(BATR, 528)), gprc:$Rx)>,
3382                     Requires<[IsPPC6xx]>;
3383     def : InstAlias<"mfibatu $Rx, "#BATR,
3384                     (MFSPR gprc:$Rx, !add(BATR, !add(BATR, 528)))>,
3385                     Requires<[IsPPC6xx]>;
3386     def : InstAlias<"mtibatl "#BATR#", $Rx",
3387                     (MTSPR !add(BATR, !add(BATR, 529)), gprc:$Rx)>,
3388                     Requires<[IsPPC6xx]>;
3389     def : InstAlias<"mfibatl $Rx, "#BATR,
3390                     (MFSPR gprc:$Rx, !add(BATR, !add(BATR, 529)))>,
3391                     Requires<[IsPPC6xx]>;
3392 }
3393
3394 foreach BR = 0-7 in {
3395     def : InstAlias<"mfbr"#BR#" $Rx",
3396                     (MFDCR gprc:$Rx, !add(BR, 0x80))>,
3397                     Requires<[IsPPC4xx]>;
3398     def : InstAlias<"mtbr"#BR#" $Rx",
3399                     (MTDCR gprc:$Rx, !add(BR, 0x80))>,
3400                     Requires<[IsPPC4xx]>;
3401 }
3402
3403 def : InstAlias<"mtdccr $Rx", (MTSPR 1018, gprc:$Rx)>, Requires<[IsPPC4xx]>;
3404 def : InstAlias<"mfdccr $Rx", (MFSPR gprc:$Rx, 1018)>, Requires<[IsPPC4xx]>;
3405
3406 def : InstAlias<"mticcr $Rx", (MTSPR 1019, gprc:$Rx)>, Requires<[IsPPC4xx]>;
3407 def : InstAlias<"mficcr $Rx", (MFSPR gprc:$Rx, 1019)>, Requires<[IsPPC4xx]>;
3408
3409 def : InstAlias<"mtdear $Rx", (MTSPR 981, gprc:$Rx)>, Requires<[IsPPC4xx]>;
3410 def : InstAlias<"mfdear $Rx", (MFSPR gprc:$Rx, 981)>, Requires<[IsPPC4xx]>;
3411
3412 def : InstAlias<"mtesr $Rx", (MTSPR 980, gprc:$Rx)>, Requires<[IsPPC4xx]>;
3413 def : InstAlias<"mfesr $Rx", (MFSPR gprc:$Rx, 980)>, Requires<[IsPPC4xx]>;
3414
3415 def : InstAlias<"mfspefscr $Rx", (MFSPR gprc:$Rx, 512)>;
3416 def : InstAlias<"mtspefscr $Rx", (MTSPR 512, gprc:$Rx)>;
3417
3418 def : InstAlias<"mttcr $Rx", (MTSPR 986, gprc:$Rx)>, Requires<[IsPPC4xx]>;
3419 def : InstAlias<"mftcr $Rx", (MFSPR gprc:$Rx, 986)>, Requires<[IsPPC4xx]>;
3420
3421 def LAx : PPCAsmPseudo<"la $rA, $addr", (ins gprc:$rA, memri:$addr)>;
3422
3423 def SUBI : PPCAsmPseudo<"subi $rA, $rB, $imm",
3424                         (ins gprc:$rA, gprc:$rB, s16imm:$imm)>;
3425 def SUBIS : PPCAsmPseudo<"subis $rA, $rB, $imm",
3426                          (ins gprc:$rA, gprc:$rB, s16imm:$imm)>;
3427 def SUBIC : PPCAsmPseudo<"subic $rA, $rB, $imm",
3428                          (ins gprc:$rA, gprc:$rB, s16imm:$imm)>;
3429 def SUBICo : PPCAsmPseudo<"subic. $rA, $rB, $imm",
3430                           (ins gprc:$rA, gprc:$rB, s16imm:$imm)>;
3431
3432 def : InstAlias<"sub $rA, $rB, $rC", (SUBF8 g8rc:$rA, g8rc:$rC, g8rc:$rB)>;
3433 def : InstAlias<"sub. $rA, $rB, $rC", (SUBF8o g8rc:$rA, g8rc:$rC, g8rc:$rB)>;
3434 def : InstAlias<"subc $rA, $rB, $rC", (SUBFC8 g8rc:$rA, g8rc:$rC, g8rc:$rB)>;
3435 def : InstAlias<"subc. $rA, $rB, $rC", (SUBFC8o g8rc:$rA, g8rc:$rC, g8rc:$rB)>;
3436
3437 def : InstAlias<"mtmsrd $RS", (MTMSRD gprc:$RS, 0)>;
3438 def : InstAlias<"mtmsr $RS", (MTMSR gprc:$RS, 0)>;
3439
3440 def : InstAlias<"mfasr $RT", (MFSPR gprc:$RT, 280)>;
3441 def : InstAlias<"mtasr $RT", (MTSPR 280, gprc:$RT)>;
3442
3443 foreach SPRG = 0-3 in {
3444   def : InstAlias<"mfsprg $RT, "#SPRG, (MFSPR gprc:$RT, !add(SPRG, 272))>;
3445   def : InstAlias<"mfsprg"#SPRG#" $RT", (MFSPR gprc:$RT, !add(SPRG, 272))>;
3446   def : InstAlias<"mtsprg "#SPRG#", $RT", (MTSPR !add(SPRG, 272), gprc:$RT)>;
3447   def : InstAlias<"mtsprg"#SPRG#" $RT", (MTSPR !add(SPRG, 272), gprc:$RT)>;
3448 }
3449 foreach SPRG = 4-7 in {
3450   def : InstAlias<"mfsprg $RT, "#SPRG, (MFSPR gprc:$RT, !add(SPRG, 256))>,
3451                   Requires<[IsBookE]>;
3452   def : InstAlias<"mfsprg"#SPRG#" $RT", (MFSPR gprc:$RT, !add(SPRG, 256))>,
3453                   Requires<[IsBookE]>;
3454   def : InstAlias<"mtsprg "#SPRG#", $RT", (MTSPR !add(SPRG, 256), gprc:$RT)>,
3455                   Requires<[IsBookE]>;
3456   def : InstAlias<"mtsprg"#SPRG#" $RT", (MTSPR !add(SPRG, 256), gprc:$RT)>,
3457                   Requires<[IsBookE]>;
3458 }
3459
3460 def : InstAlias<"mtasr $RS", (MTSPR 280, gprc:$RS)>;
3461
3462 def : InstAlias<"mfdec $RT", (MFSPR gprc:$RT, 22)>;
3463 def : InstAlias<"mtdec $RT", (MTSPR 22, gprc:$RT)>;
3464
3465 def : InstAlias<"mfpvr $RT", (MFSPR gprc:$RT, 287)>;
3466
3467 def : InstAlias<"mfsdr1 $RT", (MFSPR gprc:$RT, 25)>;
3468 def : InstAlias<"mtsdr1 $RT", (MTSPR 25, gprc:$RT)>;
3469
3470 def : InstAlias<"mfsrr0 $RT", (MFSPR gprc:$RT, 26)>;
3471 def : InstAlias<"mfsrr1 $RT", (MFSPR gprc:$RT, 27)>;
3472 def : InstAlias<"mtsrr0 $RT", (MTSPR 26, gprc:$RT)>;
3473 def : InstAlias<"mtsrr1 $RT", (MTSPR 27, gprc:$RT)>;
3474
3475 def : InstAlias<"tlbie $RB", (TLBIE R0, gprc:$RB)>;
3476
3477 def : InstAlias<"tlbrehi $RS, $A", (TLBRE2 gprc:$RS, gprc:$A, 0)>,
3478                 Requires<[IsPPC4xx]>;
3479 def : InstAlias<"tlbrelo $RS, $A", (TLBRE2 gprc:$RS, gprc:$A, 1)>,
3480                 Requires<[IsPPC4xx]>;
3481 def : InstAlias<"tlbwehi $RS, $A", (TLBWE2 gprc:$RS, gprc:$A, 0)>,
3482                 Requires<[IsPPC4xx]>;
3483 def : InstAlias<"tlbwelo $RS, $A", (TLBWE2 gprc:$RS, gprc:$A, 1)>,
3484                 Requires<[IsPPC4xx]>;
3485
3486 def EXTLWI : PPCAsmPseudo<"extlwi $rA, $rS, $n, $b",
3487                           (ins gprc:$rA, gprc:$rS, u5imm:$n, u5imm:$b)>;
3488 def EXTLWIo : PPCAsmPseudo<"extlwi. $rA, $rS, $n, $b",
3489                            (ins gprc:$rA, gprc:$rS, u5imm:$n, u5imm:$b)>;
3490 def EXTRWI : PPCAsmPseudo<"extrwi $rA, $rS, $n, $b",
3491                           (ins gprc:$rA, gprc:$rS, u5imm:$n, u5imm:$b)>;
3492 def EXTRWIo : PPCAsmPseudo<"extrwi. $rA, $rS, $n, $b",
3493                            (ins gprc:$rA, gprc:$rS, u5imm:$n, u5imm:$b)>;
3494 def INSLWI : PPCAsmPseudo<"inslwi $rA, $rS, $n, $b",
3495                           (ins gprc:$rA, gprc:$rS, u5imm:$n, u5imm:$b)>;
3496 def INSLWIo : PPCAsmPseudo<"inslwi. $rA, $rS, $n, $b",
3497                            (ins gprc:$rA, gprc:$rS, u5imm:$n, u5imm:$b)>;
3498 def INSRWI : PPCAsmPseudo<"insrwi $rA, $rS, $n, $b",
3499                           (ins gprc:$rA, gprc:$rS, u5imm:$n, u5imm:$b)>;
3500 def INSRWIo : PPCAsmPseudo<"insrwi. $rA, $rS, $n, $b",
3501                            (ins gprc:$rA, gprc:$rS, u5imm:$n, u5imm:$b)>;
3502 def ROTRWI : PPCAsmPseudo<"rotrwi $rA, $rS, $n",
3503                           (ins gprc:$rA, gprc:$rS, u5imm:$n)>;
3504 def ROTRWIo : PPCAsmPseudo<"rotrwi. $rA, $rS, $n",
3505                            (ins gprc:$rA, gprc:$rS, u5imm:$n)>;
3506 def SLWI : PPCAsmPseudo<"slwi $rA, $rS, $n",
3507                         (ins gprc:$rA, gprc:$rS, u5imm:$n)>;
3508 def SLWIo : PPCAsmPseudo<"slwi. $rA, $rS, $n",
3509                          (ins gprc:$rA, gprc:$rS, u5imm:$n)>;
3510 def SRWI : PPCAsmPseudo<"srwi $rA, $rS, $n",
3511                         (ins gprc:$rA, gprc:$rS, u5imm:$n)>;
3512 def SRWIo : PPCAsmPseudo<"srwi. $rA, $rS, $n",
3513                          (ins gprc:$rA, gprc:$rS, u5imm:$n)>;
3514 def CLRRWI : PPCAsmPseudo<"clrrwi $rA, $rS, $n",
3515                           (ins gprc:$rA, gprc:$rS, u5imm:$n)>;
3516 def CLRRWIo : PPCAsmPseudo<"clrrwi. $rA, $rS, $n",
3517                            (ins gprc:$rA, gprc:$rS, u5imm:$n)>;
3518 def CLRLSLWI : PPCAsmPseudo<"clrlslwi $rA, $rS, $b, $n",
3519                             (ins gprc:$rA, gprc:$rS, u5imm:$b, u5imm:$n)>;
3520 def CLRLSLWIo : PPCAsmPseudo<"clrlslwi. $rA, $rS, $b, $n",
3521                              (ins gprc:$rA, gprc:$rS, u5imm:$b, u5imm:$n)>;
3522
3523 def : InstAlias<"rotlwi $rA, $rS, $n", (RLWINM gprc:$rA, gprc:$rS, u5imm:$n, 0, 31)>;
3524 def : InstAlias<"rotlwi. $rA, $rS, $n", (RLWINMo gprc:$rA, gprc:$rS, u5imm:$n, 0, 31)>;
3525 def : InstAlias<"rotlw $rA, $rS, $rB", (RLWNM gprc:$rA, gprc:$rS, gprc:$rB, 0, 31)>;
3526 def : InstAlias<"rotlw. $rA, $rS, $rB", (RLWNMo gprc:$rA, gprc:$rS, gprc:$rB, 0, 31)>;
3527 def : InstAlias<"clrlwi $rA, $rS, $n", (RLWINM gprc:$rA, gprc:$rS, 0, u5imm:$n, 31)>;
3528 def : InstAlias<"clrlwi. $rA, $rS, $n", (RLWINMo gprc:$rA, gprc:$rS, 0, u5imm:$n, 31)>;
3529
3530 def EXTLDI : PPCAsmPseudo<"extldi $rA, $rS, $n, $b",
3531                           (ins g8rc:$rA, g8rc:$rS, u6imm:$n, u6imm:$b)>;
3532 def EXTLDIo : PPCAsmPseudo<"extldi. $rA, $rS, $n, $b",
3533                            (ins g8rc:$rA, g8rc:$rS, u6imm:$n, u6imm:$b)>;
3534 def EXTRDI : PPCAsmPseudo<"extrdi $rA, $rS, $n, $b",
3535                           (ins g8rc:$rA, g8rc:$rS, u6imm:$n, u6imm:$b)>;
3536 def EXTRDIo : PPCAsmPseudo<"extrdi. $rA, $rS, $n, $b",
3537                            (ins g8rc:$rA, g8rc:$rS, u6imm:$n, u6imm:$b)>;
3538 def INSRDI : PPCAsmPseudo<"insrdi $rA, $rS, $n, $b",
3539                           (ins g8rc:$rA, g8rc:$rS, u6imm:$n, u6imm:$b)>;
3540 def INSRDIo : PPCAsmPseudo<"insrdi. $rA, $rS, $n, $b",
3541                            (ins g8rc:$rA, g8rc:$rS, u6imm:$n, u6imm:$b)>;
3542 def ROTRDI : PPCAsmPseudo<"rotrdi $rA, $rS, $n",
3543                           (ins g8rc:$rA, g8rc:$rS, u6imm:$n)>;
3544 def ROTRDIo : PPCAsmPseudo<"rotrdi. $rA, $rS, $n",
3545                            (ins g8rc:$rA, g8rc:$rS, u6imm:$n)>;
3546 def SLDI : PPCAsmPseudo<"sldi $rA, $rS, $n",
3547                         (ins g8rc:$rA, g8rc:$rS, u6imm:$n)>;
3548 def SLDIo : PPCAsmPseudo<"sldi. $rA, $rS, $n",
3549                          (ins g8rc:$rA, g8rc:$rS, u6imm:$n)>;
3550 def SRDI : PPCAsmPseudo<"srdi $rA, $rS, $n",
3551                         (ins g8rc:$rA, g8rc:$rS, u6imm:$n)>;
3552 def SRDIo : PPCAsmPseudo<"srdi. $rA, $rS, $n",
3553                          (ins g8rc:$rA, g8rc:$rS, u6imm:$n)>;
3554 def CLRRDI : PPCAsmPseudo<"clrrdi $rA, $rS, $n",
3555                           (ins g8rc:$rA, g8rc:$rS, u6imm:$n)>;
3556 def CLRRDIo : PPCAsmPseudo<"clrrdi. $rA, $rS, $n",
3557                            (ins g8rc:$rA, g8rc:$rS, u6imm:$n)>;
3558 def CLRLSLDI : PPCAsmPseudo<"clrlsldi $rA, $rS, $b, $n",
3559                             (ins g8rc:$rA, g8rc:$rS, u6imm:$b, u6imm:$n)>;
3560 def CLRLSLDIo : PPCAsmPseudo<"clrlsldi. $rA, $rS, $b, $n",
3561                              (ins g8rc:$rA, g8rc:$rS, u6imm:$b, u6imm:$n)>;
3562
3563 def : InstAlias<"rotldi $rA, $rS, $n", (RLDICL g8rc:$rA, g8rc:$rS, u6imm:$n, 0)>;
3564 def : InstAlias<"rotldi. $rA, $rS, $n", (RLDICLo g8rc:$rA, g8rc:$rS, u6imm:$n, 0)>;
3565 def : InstAlias<"rotld $rA, $rS, $rB", (RLDCL g8rc:$rA, g8rc:$rS, gprc:$rB, 0)>;
3566 def : InstAlias<"rotld. $rA, $rS, $rB", (RLDCLo g8rc:$rA, g8rc:$rS, gprc:$rB, 0)>;
3567 def : InstAlias<"clrldi $rA, $rS, $n", (RLDICL g8rc:$rA, g8rc:$rS, 0, u6imm:$n)>;
3568 def : InstAlias<"clrldi. $rA, $rS, $n", (RLDICLo g8rc:$rA, g8rc:$rS, 0, u6imm:$n)>;
3569
3570 // These generic branch instruction forms are used for the assembler parser only.
3571 // Defs and Uses are conservative, since we don't know the BO value.
3572 let PPC970_Unit = 7 in {
3573   let Defs = [CTR], Uses = [CTR, RM] in {
3574     def gBC : BForm_3<16, 0, 0, (outs),
3575                       (ins u5imm:$bo, crbitrc:$bi, condbrtarget:$dst),
3576                       "bc $bo, $bi, $dst">;
3577     def gBCA : BForm_3<16, 1, 0, (outs),
3578                        (ins u5imm:$bo, crbitrc:$bi, abscondbrtarget:$dst),
3579                        "bca $bo, $bi, $dst">;
3580   }
3581   let Defs = [LR, CTR], Uses = [CTR, RM] in {
3582     def gBCL : BForm_3<16, 0, 1, (outs),
3583                        (ins u5imm:$bo, crbitrc:$bi, condbrtarget:$dst),
3584                        "bcl $bo, $bi, $dst">;
3585     def gBCLA : BForm_3<16, 1, 1, (outs),
3586                         (ins u5imm:$bo, crbitrc:$bi, abscondbrtarget:$dst),
3587                         "bcla $bo, $bi, $dst">;
3588   }
3589   let Defs = [CTR], Uses = [CTR, LR, RM] in
3590     def gBCLR : XLForm_2<19, 16, 0, (outs),
3591                          (ins u5imm:$bo, crbitrc:$bi, i32imm:$bh),
3592                          "bclr $bo, $bi, $bh", IIC_BrB, []>;
3593   let Defs = [LR, CTR], Uses = [CTR, LR, RM] in
3594     def gBCLRL : XLForm_2<19, 16, 1, (outs),
3595                           (ins u5imm:$bo, crbitrc:$bi, i32imm:$bh),
3596                           "bclrl $bo, $bi, $bh", IIC_BrB, []>;
3597   let Defs = [CTR], Uses = [CTR, LR, RM] in
3598     def gBCCTR : XLForm_2<19, 528, 0, (outs),
3599                           (ins u5imm:$bo, crbitrc:$bi, i32imm:$bh),
3600                           "bcctr $bo, $bi, $bh", IIC_BrB, []>;
3601   let Defs = [LR, CTR], Uses = [CTR, LR, RM] in
3602     def gBCCTRL : XLForm_2<19, 528, 1, (outs),
3603                            (ins u5imm:$bo, crbitrc:$bi, i32imm:$bh),
3604                            "bcctrl $bo, $bi, $bh", IIC_BrB, []>;
3605 }
3606 def : InstAlias<"bclr $bo, $bi", (gBCLR u5imm:$bo, crbitrc:$bi, 0)>;
3607 def : InstAlias<"bclrl $bo, $bi", (gBCLRL u5imm:$bo, crbitrc:$bi, 0)>;
3608 def : InstAlias<"bcctr $bo, $bi", (gBCCTR u5imm:$bo, crbitrc:$bi, 0)>;
3609 def : InstAlias<"bcctrl $bo, $bi", (gBCCTRL u5imm:$bo, crbitrc:$bi, 0)>;
3610
3611 multiclass BranchSimpleMnemonic1<string name, string pm, int bo> {
3612   def : InstAlias<"b"#name#pm#" $bi, $dst", (gBC bo, crbitrc:$bi, condbrtarget:$dst)>;
3613   def : InstAlias<"b"#name#"a"#pm#" $bi, $dst", (gBCA bo, crbitrc:$bi, abscondbrtarget:$dst)>;
3614   def : InstAlias<"b"#name#"lr"#pm#" $bi", (gBCLR bo, crbitrc:$bi, 0)>;
3615   def : InstAlias<"b"#name#"l"#pm#" $bi, $dst", (gBCL bo, crbitrc:$bi, condbrtarget:$dst)>;
3616   def : InstAlias<"b"#name#"la"#pm#" $bi, $dst", (gBCLA bo, crbitrc:$bi, abscondbrtarget:$dst)>;
3617   def : InstAlias<"b"#name#"lrl"#pm#" $bi", (gBCLRL bo, crbitrc:$bi, 0)>;
3618 }
3619 multiclass BranchSimpleMnemonic2<string name, string pm, int bo>
3620   : BranchSimpleMnemonic1<name, pm, bo> {
3621   def : InstAlias<"b"#name#"ctr"#pm#" $bi", (gBCCTR bo, crbitrc:$bi, 0)>;
3622   def : InstAlias<"b"#name#"ctrl"#pm#" $bi", (gBCCTRL bo, crbitrc:$bi, 0)>;
3623 }
3624 defm : BranchSimpleMnemonic2<"t", "", 12>;
3625 defm : BranchSimpleMnemonic2<"f", "", 4>;
3626 defm : BranchSimpleMnemonic2<"t", "-", 14>;
3627 defm : BranchSimpleMnemonic2<"f", "-", 6>;
3628 defm : BranchSimpleMnemonic2<"t", "+", 15>;
3629 defm : BranchSimpleMnemonic2<"f", "+", 7>;
3630 defm : BranchSimpleMnemonic1<"dnzt", "", 8>;
3631 defm : BranchSimpleMnemonic1<"dnzf", "", 0>;
3632 defm : BranchSimpleMnemonic1<"dzt", "", 10>;
3633 defm : BranchSimpleMnemonic1<"dzf", "", 2>;
3634
3635 multiclass BranchExtendedMnemonicPM<string name, string pm, int bibo> {
3636   def : InstAlias<"b"#name#pm#" $cc, $dst",
3637                   (BCC bibo, crrc:$cc, condbrtarget:$dst)>;
3638   def : InstAlias<"b"#name#pm#" $dst",
3639                   (BCC bibo, CR0, condbrtarget:$dst)>;
3640
3641   def : InstAlias<"b"#name#"a"#pm#" $cc, $dst",
3642                   (BCCA bibo, crrc:$cc, abscondbrtarget:$dst)>;
3643   def : InstAlias<"b"#name#"a"#pm#" $dst",
3644                   (BCCA bibo, CR0, abscondbrtarget:$dst)>;
3645
3646   def : InstAlias<"b"#name#"lr"#pm#" $cc",
3647                   (BCCLR bibo, crrc:$cc)>;
3648   def : InstAlias<"b"#name#"lr"#pm,
3649                   (BCCLR bibo, CR0)>;
3650
3651   def : InstAlias<"b"#name#"ctr"#pm#" $cc",
3652                   (BCCCTR bibo, crrc:$cc)>;
3653   def : InstAlias<"b"#name#"ctr"#pm,
3654                   (BCCCTR bibo, CR0)>;
3655
3656   def : InstAlias<"b"#name#"l"#pm#" $cc, $dst",
3657                   (BCCL bibo, crrc:$cc, condbrtarget:$dst)>;
3658   def : InstAlias<"b"#name#"l"#pm#" $dst",
3659                   (BCCL bibo, CR0, condbrtarget:$dst)>;
3660
3661   def : InstAlias<"b"#name#"la"#pm#" $cc, $dst",
3662                   (BCCLA bibo, crrc:$cc, abscondbrtarget:$dst)>;
3663   def : InstAlias<"b"#name#"la"#pm#" $dst",
3664                   (BCCLA bibo, CR0, abscondbrtarget:$dst)>;
3665
3666   def : InstAlias<"b"#name#"lrl"#pm#" $cc",
3667                   (BCCLRL bibo, crrc:$cc)>;
3668   def : InstAlias<"b"#name#"lrl"#pm,
3669                   (BCCLRL bibo, CR0)>;
3670
3671   def : InstAlias<"b"#name#"ctrl"#pm#" $cc",
3672                   (BCCCTRL bibo, crrc:$cc)>;
3673   def : InstAlias<"b"#name#"ctrl"#pm,
3674                   (BCCCTRL bibo, CR0)>;
3675 }
3676 multiclass BranchExtendedMnemonic<string name, int bibo> {
3677   defm : BranchExtendedMnemonicPM<name, "", bibo>;
3678   defm : BranchExtendedMnemonicPM<name, "-", !add(bibo, 2)>;
3679   defm : BranchExtendedMnemonicPM<name, "+", !add(bibo, 3)>;
3680 }
3681 defm : BranchExtendedMnemonic<"lt", 12>;
3682 defm : BranchExtendedMnemonic<"gt", 44>;
3683 defm : BranchExtendedMnemonic<"eq", 76>;
3684 defm : BranchExtendedMnemonic<"un", 108>;
3685 defm : BranchExtendedMnemonic<"so", 108>;
3686 defm : BranchExtendedMnemonic<"ge", 4>;
3687 defm : BranchExtendedMnemonic<"nl", 4>;
3688 defm : BranchExtendedMnemonic<"le", 36>;
3689 defm : BranchExtendedMnemonic<"ng", 36>;
3690 defm : BranchExtendedMnemonic<"ne", 68>;
3691 defm : BranchExtendedMnemonic<"nu", 100>;
3692 defm : BranchExtendedMnemonic<"ns", 100>;
3693
3694 def : InstAlias<"cmpwi $rA, $imm", (CMPWI CR0, gprc:$rA, s16imm:$imm)>;
3695 def : InstAlias<"cmpw $rA, $rB", (CMPW CR0, gprc:$rA, gprc:$rB)>;
3696 def : InstAlias<"cmplwi $rA, $imm", (CMPLWI CR0, gprc:$rA, u16imm:$imm)>;
3697 def : InstAlias<"cmplw $rA, $rB", (CMPLW CR0, gprc:$rA, gprc:$rB)>;
3698 def : InstAlias<"cmpdi $rA, $imm", (CMPDI CR0, g8rc:$rA, s16imm64:$imm)>;
3699 def : InstAlias<"cmpd $rA, $rB", (CMPD CR0, g8rc:$rA, g8rc:$rB)>;
3700 def : InstAlias<"cmpldi $rA, $imm", (CMPLDI CR0, g8rc:$rA, u16imm64:$imm)>;
3701 def : InstAlias<"cmpld $rA, $rB", (CMPLD CR0, g8rc:$rA, g8rc:$rB)>;
3702
3703 def : InstAlias<"cmpi $bf, 0, $rA, $imm", (CMPWI crrc:$bf, gprc:$rA, s16imm:$imm)>;
3704 def : InstAlias<"cmp $bf, 0, $rA, $rB", (CMPW crrc:$bf, gprc:$rA, gprc:$rB)>;
3705 def : InstAlias<"cmpli $bf, 0, $rA, $imm", (CMPLWI crrc:$bf, gprc:$rA, u16imm:$imm)>;
3706 def : InstAlias<"cmpl $bf, 0, $rA, $rB", (CMPLW crrc:$bf, gprc:$rA, gprc:$rB)>;
3707 def : InstAlias<"cmpi $bf, 1, $rA, $imm", (CMPDI crrc:$bf, g8rc:$rA, s16imm64:$imm)>;
3708 def : InstAlias<"cmp $bf, 1, $rA, $rB", (CMPD crrc:$bf, g8rc:$rA, g8rc:$rB)>;
3709 def : InstAlias<"cmpli $bf, 1, $rA, $imm", (CMPLDI crrc:$bf, g8rc:$rA, u16imm64:$imm)>;
3710 def : InstAlias<"cmpl $bf, 1, $rA, $rB", (CMPLD crrc:$bf, g8rc:$rA, g8rc:$rB)>;
3711
3712 multiclass TrapExtendedMnemonic<string name, int to> {
3713   def : InstAlias<"td"#name#"i $rA, $imm", (TDI to, g8rc:$rA, s16imm:$imm)>;
3714   def : InstAlias<"td"#name#" $rA, $rB", (TD to, g8rc:$rA, g8rc:$rB)>;
3715   def : InstAlias<"tw"#name#"i $rA, $imm", (TWI to, gprc:$rA, s16imm:$imm)>;
3716   def : InstAlias<"tw"#name#" $rA, $rB", (TW to, gprc:$rA, gprc:$rB)>;
3717 }
3718 defm : TrapExtendedMnemonic<"lt", 16>;
3719 defm : TrapExtendedMnemonic<"le", 20>;
3720 defm : TrapExtendedMnemonic<"eq", 4>;
3721 defm : TrapExtendedMnemonic<"ge", 12>;
3722 defm : TrapExtendedMnemonic<"gt", 8>;
3723 defm : TrapExtendedMnemonic<"nl", 12>;
3724 defm : TrapExtendedMnemonic<"ne", 24>;
3725 defm : TrapExtendedMnemonic<"ng", 20>;
3726 defm : TrapExtendedMnemonic<"llt", 2>;
3727 defm : TrapExtendedMnemonic<"lle", 6>;
3728 defm : TrapExtendedMnemonic<"lge", 5>;
3729 defm : TrapExtendedMnemonic<"lgt", 1>;
3730 defm : TrapExtendedMnemonic<"lnl", 5>;
3731 defm : TrapExtendedMnemonic<"lng", 6>;
3732 defm : TrapExtendedMnemonic<"u", 31>;
3733
3734 // Atomic loads
3735 def : Pat<(atomic_load_8  iaddr:$src), (LBZ  memri:$src)>;
3736 def : Pat<(atomic_load_16 iaddr:$src), (LHZ  memri:$src)>;
3737 def : Pat<(atomic_load_32 iaddr:$src), (LWZ  memri:$src)>;
3738 def : Pat<(atomic_load_8  xaddr:$src), (LBZX memrr:$src)>;
3739 def : Pat<(atomic_load_16 xaddr:$src), (LHZX memrr:$src)>;
3740 def : Pat<(atomic_load_32 xaddr:$src), (LWZX memrr:$src)>;
3741
3742 // Atomic stores
3743 def : Pat<(atomic_store_8  iaddr:$ptr, i32:$val), (STB  gprc:$val, memri:$ptr)>;
3744 def : Pat<(atomic_store_16 iaddr:$ptr, i32:$val), (STH  gprc:$val, memri:$ptr)>;
3745 def : Pat<(atomic_store_32 iaddr:$ptr, i32:$val), (STW  gprc:$val, memri:$ptr)>;
3746 def : Pat<(atomic_store_8  xaddr:$ptr, i32:$val), (STBX gprc:$val, memrr:$ptr)>;
3747 def : Pat<(atomic_store_16 xaddr:$ptr, i32:$val), (STHX gprc:$val, memrr:$ptr)>;
3748 def : Pat<(atomic_store_32 xaddr:$ptr, i32:$val), (STWX gprc:$val, memrr:$ptr)>;