Add some basic patterns for other datatypes
[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 was developed by the LLVM research group and is distributed under
6 // the University of Illinois Open Source 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_PPCShiftOp : SDTypeProfile<1, 2, [   // PPCshl, PPCsra, PPCsrl
24   SDTCisVT<0, i32>, SDTCisVT<1, i32>, SDTCisVT<2, i32>
25 ]>;
26 def SDT_PPCCallSeq : SDTypeProfile<0, 1, [ SDTCisVT<0, i32> ]>;
27 def SDT_PPCRetFlag : SDTypeProfile<0, 0, []>;
28
29 def SDT_PPCvperm   : SDTypeProfile<1, 3, [
30   SDTCisVT<3, v16i8>, SDTCisSameAs<0, 1>, SDTCisSameAs<0, 2>
31 ]>;
32
33 //===----------------------------------------------------------------------===//
34 // PowerPC specific DAG Nodes.
35 //
36
37 def PPCfcfid  : SDNode<"PPCISD::FCFID" , SDTFPUnaryOp, []>;
38 def PPCfctidz : SDNode<"PPCISD::FCTIDZ", SDTFPUnaryOp, []>;
39 def PPCfctiwz : SDNode<"PPCISD::FCTIWZ", SDTFPUnaryOp, []>;
40 def PPCstfiwx : SDNode<"PPCISD::STFIWX", SDT_PPCstfiwx, [SDNPHasChain]>;
41
42 def PPCfsel   : SDNode<"PPCISD::FSEL",  
43    // Type constraint for fsel.
44    SDTypeProfile<1, 3, [SDTCisSameAs<0, 2>, SDTCisSameAs<0, 3>, 
45                         SDTCisFP<0>, SDTCisVT<1, f64>]>, []>;
46
47 def PPChi       : SDNode<"PPCISD::Hi", SDTIntBinOp, []>;
48 def PPClo       : SDNode<"PPCISD::Lo", SDTIntBinOp, []>;
49 def PPCvmaddfp  : SDNode<"PPCISD::VMADDFP", SDTFPTernaryOp, []>;
50 def PPCvnmsubfp : SDNode<"PPCISD::VNMSUBFP", SDTFPTernaryOp, []>;
51
52 def PPClve_x    : SDNode<"PPCISD::LVE_X", SDTLoad, [SDNPHasChain]>;
53 def PPCvperm    : SDNode<"PPCISD::VPERM", SDT_PPCvperm, []>;
54
55 // These nodes represent the 32-bit PPC shifts that operate on 6-bit shift
56 // amounts.  These nodes are generated by the multi-precision shift code.
57 def PPCsrl        : SDNode<"PPCISD::SRL"       , SDT_PPCShiftOp>;
58 def PPCsra        : SDNode<"PPCISD::SRA"       , SDT_PPCShiftOp>;
59 def PPCshl        : SDNode<"PPCISD::SHL"       , SDT_PPCShiftOp>;
60
61 def PPCextsw_32   : SDNode<"PPCISD::EXTSW_32"  , SDTIntUnaryOp>;
62 def PPCstd_32     : SDNode<"PPCISD::STD_32"    , SDTStore, [SDNPHasChain]>;
63
64 // These are target-independent nodes, but have target-specific formats.
65 def callseq_start : SDNode<"ISD::CALLSEQ_START", SDT_PPCCallSeq,[SDNPHasChain]>;
66 def callseq_end   : SDNode<"ISD::CALLSEQ_END",   SDT_PPCCallSeq,[SDNPHasChain]>;
67
68 def retflag       : SDNode<"PPCISD::RET_FLAG", SDT_PPCRetFlag,
69                            [SDNPHasChain, SDNPOptInFlag]>;
70
71 //===----------------------------------------------------------------------===//
72 // PowerPC specific transformation functions and pattern fragments.
73 //
74
75 def SHL32 : SDNodeXForm<imm, [{
76   // Transformation function: 31 - imm
77   return getI32Imm(31 - N->getValue());
78 }]>;
79
80 def SHL64 : SDNodeXForm<imm, [{
81   // Transformation function: 63 - imm
82   return getI32Imm(63 - N->getValue());
83 }]>;
84
85 def SRL32 : SDNodeXForm<imm, [{
86   // Transformation function: 32 - imm
87   return N->getValue() ? getI32Imm(32 - N->getValue()) : getI32Imm(0);
88 }]>;
89
90 def SRL64 : SDNodeXForm<imm, [{
91   // Transformation function: 64 - imm
92   return N->getValue() ? getI32Imm(64 - N->getValue()) : getI32Imm(0);
93 }]>;
94
95 def LO16 : SDNodeXForm<imm, [{
96   // Transformation function: get the low 16 bits.
97   return getI32Imm((unsigned short)N->getValue());
98 }]>;
99
100 def HI16 : SDNodeXForm<imm, [{
101   // Transformation function: shift the immediate value down into the low bits.
102   return getI32Imm((unsigned)N->getValue() >> 16);
103 }]>;
104
105 def HA16 : SDNodeXForm<imm, [{
106   // Transformation function: shift the immediate value down into the low bits.
107   signed int Val = N->getValue();
108   return getI32Imm((Val - (signed short)Val) >> 16);
109 }]>;
110
111
112 def immSExt16  : PatLeaf<(imm), [{
113   // immSExt16 predicate - True if the immediate fits in a 16-bit sign extended
114   // field.  Used by instructions like 'addi'.
115   return (int)N->getValue() == (short)N->getValue();
116 }]>;
117 def immZExt16  : PatLeaf<(imm), [{
118   // immZExt16 predicate - True if the immediate fits in a 16-bit zero extended
119   // field.  Used by instructions like 'ori'.
120   return (unsigned)N->getValue() == (unsigned short)N->getValue();
121 }], LO16>;
122
123 def imm16Shifted : PatLeaf<(imm), [{
124   // imm16Shifted predicate - True if only bits in the top 16-bits of the
125   // immediate are set.  Used by instructions like 'addis'.
126   return ((unsigned)N->getValue() & 0xFFFF0000U) == (unsigned)N->getValue();
127 }], HI16>;
128
129 // VSPLT_get_imm xform function: convert vector_shuffle mask to VSPLT* imm.
130 def VSPLT_get_imm : SDNodeXForm<build_vector, [{
131   return getI32Imm(PPC::getVSPLTImmediate(N));
132 }]>;
133
134 def VSPLT_shuffle_mask : PatLeaf<(build_vector), [{
135   return PPC::isSplatShuffleMask(N);
136 }], VSPLT_get_imm>;
137
138 def vecimm0 : PatLeaf<(build_vector), [{
139   return PPC::isZeroVector(N);
140 }]>;
141
142
143 // VSPLTISB_get_imm xform function: convert build_vector to VSPLTISB imm.
144 def VSPLTISB_get_imm : SDNodeXForm<build_vector, [{
145   char Val;
146   PPC::isVecSplatImm(N, 1, &Val);
147   return getI32Imm(Val);
148 }]>;
149 def vecspltisb : PatLeaf<(build_vector), [{
150   return PPC::isVecSplatImm(N, 1);
151 }], VSPLTISB_get_imm>;
152
153 // VSPLTISH_get_imm xform function: convert build_vector to VSPLTISH imm.
154 def VSPLTISH_get_imm : SDNodeXForm<build_vector, [{
155   char Val;
156   PPC::isVecSplatImm(N, 2, &Val);
157   return getI32Imm(Val);
158 }]>;
159 def vecspltish : PatLeaf<(build_vector), [{
160   return PPC::isVecSplatImm(N, 2);
161 }], VSPLTISH_get_imm>;
162
163 // VSPLTISW_get_imm xform function: convert build_vector to VSPLTISW imm.
164 def VSPLTISW_get_imm : SDNodeXForm<build_vector, [{
165   char Val;
166   PPC::isVecSplatImm(N, 4, &Val);
167   return getI32Imm(Val);
168 }]>;
169 def vecspltisw : PatLeaf<(build_vector), [{
170   return PPC::isVecSplatImm(N, 4);
171 }], VSPLTISW_get_imm>;
172
173
174 //===----------------------------------------------------------------------===//
175 // PowerPC Flag Definitions.
176
177 class isPPC64 { bit PPC64 = 1; }
178 class isVMX   { bit VMX = 1; }
179 class isDOT   {
180   list<Register> Defs = [CR0];
181   bit RC  = 1;
182 }
183
184
185
186 //===----------------------------------------------------------------------===//
187 // PowerPC Operand Definitions.
188
189 def s5imm   : Operand<i32> {
190   let PrintMethod = "printS5ImmOperand";
191 }
192 def u5imm   : Operand<i32> {
193   let PrintMethod = "printU5ImmOperand";
194 }
195 def u6imm   : Operand<i32> {
196   let PrintMethod = "printU6ImmOperand";
197 }
198 def s16imm  : Operand<i32> {
199   let PrintMethod = "printS16ImmOperand";
200 }
201 def u16imm  : Operand<i32> {
202   let PrintMethod = "printU16ImmOperand";
203 }
204 def s16immX4  : Operand<i32> {   // Multiply imm by 4 before printing.
205   let PrintMethod = "printS16X4ImmOperand";
206 }
207 def target : Operand<OtherVT> {
208   let PrintMethod = "printBranchOperand";
209 }
210 def calltarget : Operand<i32> {
211   let PrintMethod = "printCallOperand";
212 }
213 def aaddr : Operand<i32> {
214   let PrintMethod = "printAbsAddrOperand";
215 }
216 def piclabel: Operand<i32> {
217   let PrintMethod = "printPICLabel";
218 }
219 def symbolHi: Operand<i32> {
220   let PrintMethod = "printSymbolHi";
221 }
222 def symbolLo: Operand<i32> {
223   let PrintMethod = "printSymbolLo";
224 }
225 def crbitm: Operand<i8> {
226   let PrintMethod = "printcrbitm";
227 }
228 // Address operands
229 def memri : Operand<i32> {
230   let PrintMethod = "printMemRegImm";
231   let NumMIOperands = 2;
232   let MIOperandInfo = (ops i32imm, GPRC);
233 }
234 def memrr : Operand<i32> {
235   let PrintMethod = "printMemRegReg";
236   let NumMIOperands = 2;
237   let MIOperandInfo = (ops GPRC, GPRC);
238 }
239 def memrix : Operand<i32> {   // memri where the imm is shifted 2 bits.
240   let PrintMethod = "printMemRegImmShifted";
241   let NumMIOperands = 2;
242   let MIOperandInfo = (ops i32imm, GPRC);
243 }
244
245 // Define PowerPC specific addressing mode.
246 def iaddr  : ComplexPattern<i32, 2, "SelectAddrImm",    []>;
247 def xaddr  : ComplexPattern<i32, 2, "SelectAddrIdx",    []>;
248 def xoaddr : ComplexPattern<i32, 2, "SelectAddrIdxOnly",[]>;
249 def ixaddr : ComplexPattern<i32, 2, "SelectAddrImmShift", []>; // "std"
250
251 //===----------------------------------------------------------------------===//
252 // PowerPC Instruction Predicate Definitions.
253 def FPContractions : Predicate<"!NoExcessFPPrecision">;
254
255 //===----------------------------------------------------------------------===//
256 // PowerPC Instruction Definitions.
257
258 // Pseudo-instructions:
259
260 let hasCtrlDep = 1 in {
261 def ADJCALLSTACKDOWN : Pseudo<(ops u16imm:$amt),
262                               "; ADJCALLSTACKDOWN",
263                               [(callseq_start imm:$amt)]>;
264 def ADJCALLSTACKUP   : Pseudo<(ops u16imm:$amt),
265                               "; ADJCALLSTACKUP",
266                               [(callseq_end imm:$amt)]>;
267
268 def UPDATE_VRSAVE    : Pseudo<(ops GPRC:$rD, GPRC:$rS),
269                               "UPDATE_VRSAVE $rD, $rS", []>;
270 }
271 def IMPLICIT_DEF_GPR : Pseudo<(ops GPRC:$rD), "; $rD = IMPLICIT_DEF_GPRC",
272                               [(set GPRC:$rD, (undef))]>;
273 def IMPLICIT_DEF_F8  : Pseudo<(ops F8RC:$rD), "; $rD = IMPLICIT_DEF_F8",
274                               [(set F8RC:$rD, (undef))]>;
275 def IMPLICIT_DEF_F4  : Pseudo<(ops F4RC:$rD), "; $rD = IMPLICIT_DEF_F4",
276                               [(set F4RC:$rD, (undef))]>;
277 def IMPLICIT_DEF_VRRC : Pseudo<(ops VRRC:$rD), "; $rD = IMPLICIT_DEF_VRRC",
278                                [(set VRRC:$rD, (v4f32 (undef)))]>;
279
280 // SELECT_CC_* - Used to implement the SELECT_CC DAG operation.  Expanded by the
281 // scheduler into a branch sequence.
282 let usesCustomDAGSchedInserter = 1,    // Expanded by the scheduler.
283     PPC970_Single = 1 in {
284   def SELECT_CC_Int : Pseudo<(ops GPRC:$dst, CRRC:$cond, GPRC:$T, GPRC:$F,
285                               i32imm:$BROPC), "; SELECT_CC PSEUDO!", []>;
286   def SELECT_CC_F4  : Pseudo<(ops F4RC:$dst, CRRC:$cond, F4RC:$T, F4RC:$F,
287                               i32imm:$BROPC), "; SELECT_CC PSEUDO!", []>;
288   def SELECT_CC_F8  : Pseudo<(ops F8RC:$dst, CRRC:$cond, F8RC:$T, F8RC:$F,
289                               i32imm:$BROPC), "; SELECT_CC PSEUDO!", []>;
290 }
291
292 let isTerminator = 1, noResults = 1, PPC970_Unit = 7 in {
293   let isReturn = 1 in
294     def BLR : XLForm_2_ext<19, 16, 20, 0, 0, (ops), "blr", BrB, [(retflag)]>;
295   def BCTR : XLForm_2_ext<19, 528, 20, 0, 0, (ops), "bctr", BrB, []>;
296 }
297
298 let Defs = [LR] in
299   def MovePCtoLR : Pseudo<(ops piclabel:$label), "bl $label", []>,
300                    PPC970_Unit_BRU;
301
302 let isBranch = 1, isTerminator = 1, hasCtrlDep = 1, 
303     noResults = 1, PPC970_Unit = 7 in {
304   def COND_BRANCH : Pseudo<(ops CRRC:$crS, u16imm:$opc, target:$true),
305                            "; COND_BRANCH", []>;
306   def B   : IForm<18, 0, 0, (ops target:$dst),
307                   "b $dst", BrB,
308                   [(br bb:$dst)]>;
309
310   // FIXME: 4*CR# needs to be added to the BI field!
311   // This will only work for CR0 as it stands now
312   def BLT : BForm<16, 0, 0, 12, 0, (ops CRRC:$crS, target:$block),
313                   "blt $crS, $block", BrB>;
314   def BLE : BForm<16, 0, 0, 4,  1, (ops CRRC:$crS, target:$block),
315                   "ble $crS, $block", BrB>;
316   def BEQ : BForm<16, 0, 0, 12, 2, (ops CRRC:$crS, target:$block),
317                   "beq $crS, $block", BrB>;
318   def BGE : BForm<16, 0, 0, 4,  0, (ops CRRC:$crS, target:$block),
319                   "bge $crS, $block", BrB>;
320   def BGT : BForm<16, 0, 0, 12, 1, (ops CRRC:$crS, target:$block),
321                   "bgt $crS, $block", BrB>;
322   def BNE : BForm<16, 0, 0, 4,  2, (ops CRRC:$crS, target:$block),
323                   "bne $crS, $block", BrB>;
324   def BUN : BForm<16, 0, 0, 12, 3, (ops CRRC:$crS, target:$block),
325                   "bun $crS, $block", BrB>;
326   def BNU : BForm<16, 0, 0, 4,  3, (ops CRRC:$crS, target:$block),
327                   "bnu $crS, $block", BrB>;
328 }
329
330 let isCall = 1, noResults = 1, PPC970_Unit = 7, 
331   // All calls clobber the non-callee saved registers...
332   Defs = [R0,R2,R3,R4,R5,R6,R7,R8,R9,R10,R11,R12,
333           F0,F1,F2,F3,F4,F5,F6,F7,F8,F9,F10,F11,F12,F13,
334           V0,V1,V2,V3,V4,V5,V6,V7,V8,V9,V10,V11,V12,V13,V14,V15,V16,V17,V18,V19,
335           LR,CTR,
336           CR0,CR1,CR5,CR6,CR7] in {
337   // Convenient aliases for call instructions
338   def BL  : IForm<18, 0, 1, (ops calltarget:$func, variable_ops), 
339                             "bl $func", BrB, []>;
340   def BLA : IForm<18, 1, 1, (ops aaddr:$func, variable_ops),
341                             "bla $func", BrB, []>;
342   def BCTRL : XLForm_2_ext<19, 528, 20, 0, 1, (ops variable_ops), "bctrl", BrB,
343                            []>;
344 }
345
346 // D-Form instructions.  Most instructions that perform an operation on a
347 // register and an immediate are of this type.
348 //
349 let isLoad = 1, PPC970_Unit = 2 in {
350 def LBZ : DForm_1<34, (ops GPRC:$rD, memri:$src),
351                   "lbz $rD, $src", LdStGeneral,
352                   [(set GPRC:$rD, (zextload iaddr:$src, i8))]>;
353 def LHA : DForm_1<42, (ops GPRC:$rD, memri:$src),
354                   "lha $rD, $src", LdStLHA,
355                   [(set GPRC:$rD, (sextload iaddr:$src, i16))]>,
356                   PPC970_DGroup_Cracked;
357 def LHZ : DForm_1<40, (ops GPRC:$rD, memri:$src),
358                   "lhz $rD, $src", LdStGeneral,
359                   [(set GPRC:$rD, (zextload iaddr:$src, i16))]>;
360 def LWZ : DForm_1<32, (ops GPRC:$rD, memri:$src),
361                   "lwz $rD, $src", LdStGeneral,
362                   [(set GPRC:$rD, (load iaddr:$src))]>;
363 def LWZU : DForm_1<35, (ops GPRC:$rD, s16imm:$disp, GPRC:$rA),
364                    "lwzu $rD, $disp($rA)", LdStGeneral,
365                    []>;
366 }
367 let PPC970_Unit = 1 in {  // FXU Operations.
368 def ADDI   : DForm_2<14, (ops GPRC:$rD, GPRC:$rA, s16imm:$imm),
369                      "addi $rD, $rA, $imm", IntGeneral,
370                      [(set GPRC:$rD, (add GPRC:$rA, immSExt16:$imm))]>;
371 def ADDIC  : DForm_2<12, (ops GPRC:$rD, GPRC:$rA, s16imm:$imm),
372                      "addic $rD, $rA, $imm", IntGeneral,
373                      [(set GPRC:$rD, (addc GPRC:$rA, immSExt16:$imm))]>,
374                      PPC970_DGroup_Cracked;
375 def ADDICo : DForm_2<13, (ops GPRC:$rD, GPRC:$rA, s16imm:$imm),
376                      "addic. $rD, $rA, $imm", IntGeneral,
377                      []>;
378 def ADDIS  : DForm_2<15, (ops GPRC:$rD, GPRC:$rA, symbolHi:$imm),
379                      "addis $rD, $rA, $imm", IntGeneral,
380                      [(set GPRC:$rD, (add GPRC:$rA, imm16Shifted:$imm))]>;
381 def LA     : DForm_2<14, (ops GPRC:$rD, GPRC:$rA, symbolLo:$sym),
382                      "la $rD, $sym($rA)", IntGeneral,
383                      [(set GPRC:$rD, (add GPRC:$rA,
384                                           (PPClo tglobaladdr:$sym, 0)))]>;
385 def MULLI  : DForm_2< 7, (ops GPRC:$rD, GPRC:$rA, s16imm:$imm),
386                      "mulli $rD, $rA, $imm", IntMulLI,
387                      [(set GPRC:$rD, (mul GPRC:$rA, immSExt16:$imm))]>;
388 def SUBFIC : DForm_2< 8, (ops GPRC:$rD, GPRC:$rA, s16imm:$imm),
389                      "subfic $rD, $rA, $imm", IntGeneral,
390                      [(set GPRC:$rD, (subc immSExt16:$imm, GPRC:$rA))]>;
391 def LI  : DForm_2_r0<14, (ops GPRC:$rD, symbolLo:$imm),
392                      "li $rD, $imm", IntGeneral,
393                      [(set GPRC:$rD, immSExt16:$imm)]>;
394 def LIS : DForm_2_r0<15, (ops GPRC:$rD, symbolHi:$imm),
395                      "lis $rD, $imm", IntGeneral,
396                      [(set GPRC:$rD, imm16Shifted:$imm)]>;
397 }
398 let isStore = 1, noResults = 1, PPC970_Unit = 2 in {
399 def STB  : DForm_3<38, (ops GPRC:$rS, memri:$src),
400                    "stb $rS, $src", LdStGeneral,
401                    [(truncstore GPRC:$rS, iaddr:$src, i8)]>;
402 def STH  : DForm_3<44, (ops GPRC:$rS, memri:$src),
403                    "sth $rS, $src", LdStGeneral,
404                    [(truncstore GPRC:$rS, iaddr:$src, i16)]>;
405 def STW  : DForm_3<36, (ops GPRC:$rS, memri:$src),
406                    "stw $rS, $src", LdStGeneral,
407                    [(store GPRC:$rS, iaddr:$src)]>;
408 def STWU : DForm_3<37, (ops GPRC:$rS, s16imm:$disp, GPRC:$rA),
409                    "stwu $rS, $disp($rA)", LdStGeneral,
410                    []>;
411 }
412 let PPC970_Unit = 1 in {  // FXU Operations.
413 def ANDIo : DForm_4<28, (ops GPRC:$dst, GPRC:$src1, u16imm:$src2),
414                     "andi. $dst, $src1, $src2", IntGeneral,
415                     [(set GPRC:$dst, (and GPRC:$src1, immZExt16:$src2))]>,
416                     isDOT;
417 def ANDISo : DForm_4<29, (ops GPRC:$dst, GPRC:$src1, u16imm:$src2),
418                     "andis. $dst, $src1, $src2", IntGeneral,
419                     [(set GPRC:$dst, (and GPRC:$src1, imm16Shifted:$src2))]>,
420                     isDOT;
421 def ORI   : DForm_4<24, (ops GPRC:$dst, GPRC:$src1, u16imm:$src2),
422                     "ori $dst, $src1, $src2", IntGeneral,
423                     [(set GPRC:$dst, (or GPRC:$src1, immZExt16:$src2))]>;
424 def ORIS  : DForm_4<25, (ops GPRC:$dst, GPRC:$src1, u16imm:$src2),
425                     "oris $dst, $src1, $src2", IntGeneral,
426                     [(set GPRC:$dst, (or GPRC:$src1, imm16Shifted:$src2))]>;
427 def XORI  : DForm_4<26, (ops GPRC:$dst, GPRC:$src1, u16imm:$src2),
428                     "xori $dst, $src1, $src2", IntGeneral,
429                     [(set GPRC:$dst, (xor GPRC:$src1, immZExt16:$src2))]>;
430 def XORIS : DForm_4<27, (ops GPRC:$dst, GPRC:$src1, u16imm:$src2),
431                     "xoris $dst, $src1, $src2", IntGeneral,
432                     [(set GPRC:$dst, (xor GPRC:$src1, imm16Shifted:$src2))]>;
433 def NOP   : DForm_4_zero<24, (ops), "nop", IntGeneral,
434                          []>;
435 def CMPI  : DForm_5<11, (ops CRRC:$crD, i1imm:$L, GPRC:$rA, s16imm:$imm),
436                     "cmpi $crD, $L, $rA, $imm", IntCompare>;
437 def CMPWI : DForm_5_ext<11, (ops CRRC:$crD, GPRC:$rA, s16imm:$imm),
438                         "cmpwi $crD, $rA, $imm", IntCompare>;
439 def CMPDI : DForm_5_ext<11, (ops CRRC:$crD, GPRC:$rA, s16imm:$imm),
440                         "cmpdi $crD, $rA, $imm", IntCompare>, isPPC64;
441 def CMPLI  : DForm_6<10, (ops CRRC:$dst, i1imm:$size, GPRC:$src1, u16imm:$src2),
442                      "cmpli $dst, $size, $src1, $src2", IntCompare>;
443 def CMPLWI : DForm_6_ext<10, (ops CRRC:$dst, GPRC:$src1, u16imm:$src2),
444                          "cmplwi $dst, $src1, $src2", IntCompare>;
445 def CMPLDI : DForm_6_ext<10, (ops CRRC:$dst, GPRC:$src1, u16imm:$src2),
446                          "cmpldi $dst, $src1, $src2", IntCompare>, isPPC64;
447 }
448 let isLoad = 1, PPC970_Unit = 2 in {
449 def LFS : DForm_8<48, (ops F4RC:$rD, memri:$src),
450                   "lfs $rD, $src", LdStLFDU,
451                   [(set F4RC:$rD, (load iaddr:$src))]>;
452 def LFD : DForm_8<50, (ops F8RC:$rD, memri:$src),
453                   "lfd $rD, $src", LdStLFD,
454                   [(set F8RC:$rD, (load iaddr:$src))]>;
455 }
456 let isStore = 1, noResults = 1, PPC970_Unit = 2 in {
457 def STFS : DForm_9<52, (ops F4RC:$rS, memri:$dst),
458                    "stfs $rS, $dst", LdStUX,
459                    [(store F4RC:$rS, iaddr:$dst)]>;
460 def STFD : DForm_9<54, (ops F8RC:$rS, memri:$dst),
461                    "stfd $rS, $dst", LdStUX,
462                    [(store F8RC:$rS, iaddr:$dst)]>;
463 }
464
465 // DS-Form instructions.  Load/Store instructions available in PPC-64
466 //
467 let isLoad = 1, PPC970_Unit = 2 in {
468 def LWA  : DSForm_1<58, 2, (ops GPRC:$rT, s16immX4:$DS, GPRC:$rA),
469                     "lwa $rT, $DS($rA)", LdStLWA,
470                     []>, isPPC64, PPC970_DGroup_Cracked;
471 def LD   : DSForm_2<58, 0, (ops GPRC:$rT, s16immX4:$DS, GPRC:$rA),
472                     "ld $rT, $DS($rA)", LdStLD,
473                     []>, isPPC64;
474 }
475 let isStore = 1, noResults = 1, PPC970_Unit = 2 in {
476 def STD  : DSForm_2<62, 0, (ops GPRC:$rT, s16immX4:$DS, GPRC:$rA),
477                     "std $rT, $DS($rA)", LdStSTD,
478                     []>, isPPC64;
479
480 // STD_32/STDX_32 - Just like STD/STDX, but uses a '32-bit' input register.
481 def STD_32  : DSForm_2<62, 0, (ops GPRC:$rT, memrix:$dst),
482                        "std $rT, $dst", LdStSTD,
483                        [(PPCstd_32  GPRC:$rT, ixaddr:$dst)]>, isPPC64;
484 def STDX_32  : XForm_8<31, 149, (ops GPRC:$rT, memrr:$dst),
485                        "stdx $rT, $dst", LdStSTD,
486                        [(PPCstd_32  GPRC:$rT, xaddr:$dst)]>, isPPC64,
487                        PPC970_DGroup_Cracked;
488 }
489
490 // X-Form instructions.  Most instructions that perform an operation on a
491 // register and another register are of this type.
492 //
493 let isLoad = 1, PPC970_Unit = 2 in {
494 def LBZX : XForm_1<31,  87, (ops GPRC:$rD, memrr:$src),
495                    "lbzx $rD, $src", LdStGeneral,
496                    [(set GPRC:$rD, (zextload xaddr:$src, i8))]>;
497 def LHAX : XForm_1<31, 343, (ops GPRC:$rD, memrr:$src),
498                    "lhax $rD, $src", LdStLHA,
499                    [(set GPRC:$rD, (sextload xaddr:$src, i16))]>,
500                    PPC970_DGroup_Cracked;
501 def LHZX : XForm_1<31, 279, (ops GPRC:$rD, memrr:$src),
502                    "lhzx $rD, $src", LdStGeneral,
503                    [(set GPRC:$rD, (zextload xaddr:$src, i16))]>;
504 def LWAX : XForm_1<31, 341, (ops G8RC:$rD, memrr:$src),
505                    "lwax $rD, $src", LdStLHA,
506                    [(set G8RC:$rD, (sextload xaddr:$src, i32))]>, isPPC64,
507                    PPC970_DGroup_Cracked;
508 def LWZX : XForm_1<31,  23, (ops GPRC:$rD, memrr:$src),
509                    "lwzx $rD, $src", LdStGeneral,
510                    [(set GPRC:$rD, (load xaddr:$src))]>;
511 def LDX  : XForm_1<31,  21, (ops G8RC:$rD, memrr:$src),
512                    "ldx $rD, $src", LdStLD,
513                    [(set G8RC:$rD, (load xaddr:$src))]>, isPPC64;
514 def LVEBX: XForm_1<31,   7, (ops VRRC:$vD, memrr:$src),
515                    "lvebx $vD, $src", LdStGeneral,
516                    [(set VRRC:$vD, (v16i8 (PPClve_x xoaddr:$src)))]>;
517 def LVEHX: XForm_1<31,  39, (ops VRRC:$vD,  memrr:$src),
518                    "lvehx $vD, $src", LdStGeneral,
519                    [(set VRRC:$vD, (v8i16 (PPClve_x xoaddr:$src)))]>;
520 def LVEWX: XForm_1<31,  71, (ops VRRC:$vD,  memrr:$src),
521                    "lvewx $vD, $src", LdStGeneral,
522                    [(set VRRC:$vD, (v4f32 (PPClve_x xoaddr:$src)))]>;
523 def LVX  : XForm_1<31, 103, (ops VRRC:$vD,  memrr:$src),
524                    "lvx $vD, $src", LdStGeneral,
525                    [(set VRRC:$vD, (v4f32 (load xoaddr:$src)))]>;
526 }
527 def LVSL : XForm_1<31,   6, (ops VRRC:$vD,  GPRC:$base, GPRC:$rA),
528                    "lvsl $vD, $base, $rA", LdStGeneral,
529                    []>, PPC970_Unit_LSU;
530 def LVSR : XForm_1<31,  38, (ops VRRC:$vD,  GPRC:$base, GPRC:$rA),
531                    "lvsl $vD, $base, $rA", LdStGeneral,
532                    []>, PPC970_Unit_LSU;
533 let PPC970_Unit = 1 in {  // FXU Operations.
534 def NAND : XForm_6<31, 476, (ops GPRC:$rA, GPRC:$rS, GPRC:$rB),
535                    "nand $rA, $rS, $rB", IntGeneral,
536                    [(set GPRC:$rA, (not (and GPRC:$rS, GPRC:$rB)))]>;
537 def AND  : XForm_6<31,  28, (ops GPRC:$rA, GPRC:$rS, GPRC:$rB),
538                    "and $rA, $rS, $rB", IntGeneral,
539                    [(set GPRC:$rA, (and GPRC:$rS, GPRC:$rB))]>;
540 def ANDo : XForm_6<31,  28, (ops GPRC:$rA, GPRC:$rS, GPRC:$rB),
541                    "and. $rA, $rS, $rB", IntGeneral,
542                    []>, isDOT;
543 def ANDC : XForm_6<31,  60, (ops GPRC:$rA, GPRC:$rS, GPRC:$rB),
544                    "andc $rA, $rS, $rB", IntGeneral,
545                    [(set GPRC:$rA, (and GPRC:$rS, (not GPRC:$rB)))]>;
546 def OR4  : XForm_6<31, 444, (ops GPRC:$rA, GPRC:$rS, GPRC:$rB),
547                    "or $rA, $rS, $rB", IntGeneral,
548                    [(set GPRC:$rA, (or GPRC:$rS, GPRC:$rB))]>;
549 def OR8  : XForm_6<31, 444, (ops G8RC:$rA, G8RC:$rS, G8RC:$rB),
550                    "or $rA, $rS, $rB", IntGeneral,
551                    [(set G8RC:$rA, (or G8RC:$rS, G8RC:$rB))]>;
552 def OR4To8  : XForm_6<31, 444, (ops G8RC:$rA, GPRC:$rS, GPRC:$rB),
553                    "or $rA, $rS, $rB", IntGeneral,
554                    []>;
555 def OR8To4  : XForm_6<31, 444, (ops GPRC:$rA, G8RC:$rS, G8RC:$rB),
556                    "or $rA, $rS, $rB", IntGeneral,
557                    []>;
558 def NOR  : XForm_6<31, 124, (ops GPRC:$rA, GPRC:$rS, GPRC:$rB),
559                    "nor $rA, $rS, $rB", IntGeneral,
560                    [(set GPRC:$rA, (not (or GPRC:$rS, GPRC:$rB)))]>;
561 def ORo  : XForm_6<31, 444, (ops GPRC:$rA, GPRC:$rS, GPRC:$rB),
562                    "or. $rA, $rS, $rB", IntGeneral,
563                    []>, isDOT;
564 def ORC  : XForm_6<31, 412, (ops GPRC:$rA, GPRC:$rS, GPRC:$rB),
565                    "orc $rA, $rS, $rB", IntGeneral,
566                    [(set GPRC:$rA, (or GPRC:$rS, (not GPRC:$rB)))]>;
567 def EQV  : XForm_6<31, 284, (ops GPRC:$rA, GPRC:$rS, GPRC:$rB),
568                    "eqv $rA, $rS, $rB", IntGeneral,
569                    [(set GPRC:$rA, (not (xor GPRC:$rS, GPRC:$rB)))]>;
570 def XOR  : XForm_6<31, 316, (ops GPRC:$rA, GPRC:$rS, GPRC:$rB),
571                    "xor $rA, $rS, $rB", IntGeneral,
572                    [(set GPRC:$rA, (xor GPRC:$rS, GPRC:$rB))]>;                   
573 def SLD  : XForm_6<31,  27, (ops G8RC:$rA, G8RC:$rS, G8RC:$rB),
574                    "sld $rA, $rS, $rB", IntRotateD,
575                    [(set G8RC:$rA, (shl G8RC:$rS, G8RC:$rB))]>, isPPC64;
576 def SLW  : XForm_6<31,  24, (ops GPRC:$rA, GPRC:$rS, GPRC:$rB),
577                    "slw $rA, $rS, $rB", IntGeneral,
578                    [(set GPRC:$rA, (PPCshl GPRC:$rS, GPRC:$rB))]>;
579 def SRD  : XForm_6<31, 539, (ops G8RC:$rA, G8RC:$rS, G8RC:$rB),
580                    "srd $rA, $rS, $rB", IntRotateD,
581                    [(set G8RC:$rA, (srl G8RC:$rS, G8RC:$rB))]>, isPPC64;
582 def SRW  : XForm_6<31, 536, (ops GPRC:$rA, GPRC:$rS, GPRC:$rB),
583                    "srw $rA, $rS, $rB", IntGeneral,
584                    [(set GPRC:$rA, (PPCsrl GPRC:$rS, GPRC:$rB))]>;
585 def SRAD : XForm_6<31, 794, (ops G8RC:$rA, G8RC:$rS, G8RC:$rB),
586                    "srad $rA, $rS, $rB", IntRotateD,
587                    [(set G8RC:$rA, (sra G8RC:$rS, G8RC:$rB))]>, isPPC64;
588 def SRAW : XForm_6<31, 792, (ops GPRC:$rA, GPRC:$rS, GPRC:$rB),
589                    "sraw $rA, $rS, $rB", IntShift,
590                    [(set GPRC:$rA, (PPCsra GPRC:$rS, GPRC:$rB))]>;
591 }
592 let isStore = 1, noResults = 1, PPC970_Unit = 2 in {
593 def STBX  : XForm_8<31, 215, (ops GPRC:$rS, memrr:$dst),
594                    "stbx $rS, $dst", LdStGeneral,
595                    [(truncstore GPRC:$rS, xaddr:$dst, i8)]>, 
596                    PPC970_DGroup_Cracked;
597 def STHX  : XForm_8<31, 407, (ops GPRC:$rS, memrr:$dst),
598                    "sthx $rS, $dst", LdStGeneral,
599                    [(truncstore GPRC:$rS, xaddr:$dst, i16)]>, 
600                    PPC970_DGroup_Cracked;
601 def STWX  : XForm_8<31, 151, (ops GPRC:$rS, memrr:$dst),
602                    "stwx $rS, $dst", LdStGeneral,
603                    [(store GPRC:$rS, xaddr:$dst)]>,
604                    PPC970_DGroup_Cracked;
605 def STWUX : XForm_8<31, 183, (ops GPRC:$rS, GPRC:$rA, GPRC:$rB),
606                    "stwux $rS, $rA, $rB", LdStGeneral,
607                    []>;
608 def STDX  : XForm_8<31, 149, (ops GPRC:$rS, GPRC:$rA, GPRC:$rB),
609                    "stdx $rS, $rA, $rB", LdStSTD,
610                    []>, isPPC64, PPC970_DGroup_Cracked;
611 def STDUX : XForm_8<31, 181, (ops GPRC:$rS, GPRC:$rA, GPRC:$rB),
612                    "stdux $rS, $rA, $rB", LdStSTD,
613                    []>, isPPC64;
614 def STVEBX: XForm_8<31, 135, (ops VRRC:$rS, GPRC:$rA, GPRC:$rB),
615                    "stvebx $rS, $rA, $rB", LdStGeneral,
616                    []>;
617 def STVEHX: XForm_8<31, 167, (ops VRRC:$rS, GPRC:$rA, GPRC:$rB),
618                    "stvehx $rS, $rA, $rB", LdStGeneral,
619                    []>;
620 def STVEWX: XForm_8<31, 199, (ops VRRC:$rS, GPRC:$rA, GPRC:$rB),
621                    "stvewx $rS, $rA, $rB", LdStGeneral,
622                    []>;
623 def STVX  : XForm_8<31, 231, (ops VRRC:$rS, memrr:$dst),
624                    "stvx $rS, $dst", LdStGeneral,
625                    [(store (v4f32 VRRC:$rS), xoaddr:$dst)]>;
626 }
627 let PPC970_Unit = 1 in {  // FXU Operations.
628 def SRAWI : XForm_10<31, 824, (ops GPRC:$rA, GPRC:$rS, u5imm:$SH), 
629                      "srawi $rA, $rS, $SH", IntShift,
630                      [(set GPRC:$rA, (sra GPRC:$rS, (i32 imm:$SH)))]>;
631 def CNTLZW : XForm_11<31,  26, (ops GPRC:$rA, GPRC:$rS),
632                       "cntlzw $rA, $rS", IntGeneral,
633                       [(set GPRC:$rA, (ctlz GPRC:$rS))]>;
634 def EXTSB  : XForm_11<31, 954, (ops GPRC:$rA, GPRC:$rS),
635                       "extsb $rA, $rS", IntGeneral,
636                       [(set GPRC:$rA, (sext_inreg GPRC:$rS, i8))]>;
637 def EXTSH  : XForm_11<31, 922, (ops GPRC:$rA, GPRC:$rS),
638                       "extsh $rA, $rS", IntGeneral,
639                       [(set GPRC:$rA, (sext_inreg GPRC:$rS, i16))]>;
640 def EXTSW  : XForm_11<31, 986, (ops G8RC:$rA, G8RC:$rS),
641                       "extsw $rA, $rS", IntGeneral,
642                       [(set G8RC:$rA, (sext_inreg G8RC:$rS, i32))]>, isPPC64;
643 /// EXTSW_32 - Just like EXTSW, but works on '32-bit' registers.
644 def EXTSW_32 : XForm_11<31, 986, (ops GPRC:$rA, GPRC:$rS),
645                       "extsw $rA, $rS", IntGeneral,
646                       [(set GPRC:$rA, (PPCextsw_32 GPRC:$rS))]>, isPPC64;
647
648 def CMP    : XForm_16<31, 0, (ops CRRC:$crD, i1imm:$long, GPRC:$rA, GPRC:$rB),
649                       "cmp $crD, $long, $rA, $rB", IntCompare>;
650 def CMPL   : XForm_16<31, 32, (ops CRRC:$crD, i1imm:$long, GPRC:$rA, GPRC:$rB),
651                       "cmpl $crD, $long, $rA, $rB", IntCompare>;
652 def CMPW   : XForm_16_ext<31, 0, (ops CRRC:$crD, GPRC:$rA, GPRC:$rB),
653                           "cmpw $crD, $rA, $rB", IntCompare>;
654 def CMPD   : XForm_16_ext<31, 0, (ops CRRC:$crD, GPRC:$rA, GPRC:$rB),
655                           "cmpd $crD, $rA, $rB", IntCompare>, isPPC64;
656 def CMPLW  : XForm_16_ext<31, 32, (ops CRRC:$crD, GPRC:$rA, GPRC:$rB),
657                           "cmplw $crD, $rA, $rB", IntCompare>;
658 def CMPLD  : XForm_16_ext<31, 32, (ops CRRC:$crD, GPRC:$rA, GPRC:$rB),
659                           "cmpld $crD, $rA, $rB", IntCompare>, isPPC64;
660 }
661 let PPC970_Unit = 3 in {  // FPU Operations.
662 //def FCMPO  : XForm_17<63, 32, (ops CRRC:$crD, FPRC:$fA, FPRC:$fB),
663 //                      "fcmpo $crD, $fA, $fB", FPCompare>;
664 def FCMPUS : XForm_17<63, 0, (ops CRRC:$crD, F4RC:$fA, F4RC:$fB),
665                       "fcmpu $crD, $fA, $fB", FPCompare>;
666 def FCMPUD : XForm_17<63, 0, (ops CRRC:$crD, F8RC:$fA, F8RC:$fB),
667                       "fcmpu $crD, $fA, $fB", FPCompare>;
668 }
669 let isLoad = 1, PPC970_Unit = 2 in {
670 def LFSX   : XForm_25<31, 535, (ops F4RC:$frD, memrr:$src),
671                       "lfsx $frD, $src", LdStLFDU,
672                       [(set F4RC:$frD, (load xaddr:$src))]>;
673 def LFDX   : XForm_25<31, 599, (ops F8RC:$frD, memrr:$src),
674                       "lfdx $frD, $src", LdStLFDU,
675                       [(set F8RC:$frD, (load xaddr:$src))]>;
676 }
677 let PPC970_Unit = 3 in {  // FPU Operations.
678 def FCFID  : XForm_26<63, 846, (ops F8RC:$frD, F8RC:$frB),
679                       "fcfid $frD, $frB", FPGeneral,
680                       [(set F8RC:$frD, (PPCfcfid F8RC:$frB))]>, isPPC64;
681 def FCTIDZ : XForm_26<63, 815, (ops F8RC:$frD, F8RC:$frB),
682                       "fctidz $frD, $frB", FPGeneral,
683                       [(set F8RC:$frD, (PPCfctidz F8RC:$frB))]>, isPPC64;
684 def FCTIWZ : XForm_26<63, 15, (ops F8RC:$frD, F8RC:$frB),
685                       "fctiwz $frD, $frB", FPGeneral,
686                       [(set F8RC:$frD, (PPCfctiwz F8RC:$frB))]>;
687 def FRSP   : XForm_26<63, 12, (ops F4RC:$frD, F8RC:$frB),
688                       "frsp $frD, $frB", FPGeneral,
689                       [(set F4RC:$frD, (fround F8RC:$frB))]>;
690 def FSQRT  : XForm_26<63, 22, (ops F8RC:$frD, F8RC:$frB),
691                       "fsqrt $frD, $frB", FPSqrt,
692                       [(set F8RC:$frD, (fsqrt F8RC:$frB))]>;
693 def FSQRTS : XForm_26<59, 22, (ops F4RC:$frD, F4RC:$frB),
694                       "fsqrts $frD, $frB", FPSqrt,
695                       [(set F4RC:$frD, (fsqrt F4RC:$frB))]>;
696 }
697
698 /// FMR is split into 3 versions, one for 4/8 byte FP, and one for extending.
699 ///
700 /// Note that these are defined as pseudo-ops on the PPC970 because they are
701 /// often coalesced away and we don't want the dispatch group builder to think
702 /// that they will fill slots (which could cause the load of a LSU reject to
703 /// sneak into a d-group with a store).
704 def FMRS   : XForm_26<63, 72, (ops F4RC:$frD, F4RC:$frB),
705                       "fmr $frD, $frB", FPGeneral,
706                       []>,  // (set F4RC:$frD, F4RC:$frB)
707                       PPC970_Unit_Pseudo;
708 def FMRD   : XForm_26<63, 72, (ops F8RC:$frD, F8RC:$frB),
709                       "fmr $frD, $frB", FPGeneral,
710                       []>,  // (set F8RC:$frD, F8RC:$frB)
711                       PPC970_Unit_Pseudo;
712 def FMRSD  : XForm_26<63, 72, (ops F8RC:$frD, F4RC:$frB),
713                       "fmr $frD, $frB", FPGeneral,
714                       [(set F8RC:$frD, (fextend F4RC:$frB))]>,
715                       PPC970_Unit_Pseudo;
716
717 let PPC970_Unit = 3 in {  // FPU Operations.
718 // These are artificially split into two different forms, for 4/8 byte FP.
719 def FABSS  : XForm_26<63, 264, (ops F4RC:$frD, F4RC:$frB),
720                       "fabs $frD, $frB", FPGeneral,
721                       [(set F4RC:$frD, (fabs F4RC:$frB))]>;
722 def FABSD  : XForm_26<63, 264, (ops F8RC:$frD, F8RC:$frB),
723                       "fabs $frD, $frB", FPGeneral,
724                       [(set F8RC:$frD, (fabs F8RC:$frB))]>;
725 def FNABSS : XForm_26<63, 136, (ops F4RC:$frD, F4RC:$frB),
726                       "fnabs $frD, $frB", FPGeneral,
727                       [(set F4RC:$frD, (fneg (fabs F4RC:$frB)))]>;
728 def FNABSD : XForm_26<63, 136, (ops F8RC:$frD, F8RC:$frB),
729                       "fnabs $frD, $frB", FPGeneral,
730                       [(set F8RC:$frD, (fneg (fabs F8RC:$frB)))]>;
731 def FNEGS  : XForm_26<63, 40, (ops F4RC:$frD, F4RC:$frB),
732                       "fneg $frD, $frB", FPGeneral,
733                       [(set F4RC:$frD, (fneg F4RC:$frB))]>;
734 def FNEGD  : XForm_26<63, 40, (ops F8RC:$frD, F8RC:$frB),
735                       "fneg $frD, $frB", FPGeneral,
736                       [(set F8RC:$frD, (fneg F8RC:$frB))]>;
737 }
738                       
739 let isStore = 1, noResults = 1, PPC970_Unit = 2 in {
740 def STFIWX: XForm_28<31, 983, (ops F8RC:$frS, memrr:$dst),
741                      "stfiwx $frS, $dst", LdStUX,
742                      [(PPCstfiwx F8RC:$frS, xoaddr:$dst)]>;
743 def STFSX : XForm_28<31, 663, (ops F4RC:$frS, memrr:$dst),
744                      "stfsx $frS, $dst", LdStUX,
745                      [(store F4RC:$frS, xaddr:$dst)]>;
746 def STFDX : XForm_28<31, 727, (ops F8RC:$frS, memrr:$dst),
747                      "stfdx $frS, $dst", LdStUX,
748                      [(store F8RC:$frS, xaddr:$dst)]>;
749 }
750
751 // XL-Form instructions.  condition register logical ops.
752 //
753 def MCRF   : XLForm_3<19, 0, (ops CRRC:$BF, CRRC:$BFA),
754                       "mcrf $BF, $BFA", BrMCR>,
755              PPC970_DGroup_First, PPC970_Unit_CRU;
756
757 // XFX-Form instructions.  Instructions that deal with SPRs.
758 //
759 def MFCTR : XFXForm_1_ext<31, 339, 9, (ops GPRC:$rT), "mfctr $rT", SprMFSPR>,
760             PPC970_DGroup_First, PPC970_Unit_FXU;
761 def MTCTR : XFXForm_7_ext<31, 467, 9, (ops GPRC:$rS), "mtctr $rS", SprMTSPR>,
762             PPC970_DGroup_First, PPC970_Unit_FXU;
763
764 def MTLR  : XFXForm_7_ext<31, 467, 8, (ops GPRC:$rS), "mtlr $rS", SprMTSPR>,
765             PPC970_DGroup_First, PPC970_Unit_FXU;
766 def MFLR  : XFXForm_1_ext<31, 339, 8, (ops GPRC:$rT), "mflr $rT",  SprMFSPR>,
767             PPC970_DGroup_First, PPC970_Unit_FXU;
768
769 // Move to/from VRSAVE: despite being a SPR, the VRSAVE register is renamed like
770 // a GPR on the PPC970.  As such, copies in and out have the same performance
771 // characteristics as an OR instruction.
772 def MTVRSAVE : XFXForm_7_ext<31, 467, 256, (ops GPRC:$rS),
773                              "mtspr 256, $rS", IntGeneral>,
774                PPC970_DGroup_Single, PPC970_Unit_FXU;
775 def MFVRSAVE : XFXForm_1_ext<31, 339, 256, (ops GPRC:$rT),
776                              "mfspr $rT, 256", IntGeneral>,
777                PPC970_DGroup_First, PPC970_Unit_FXU;
778
779 def MFCR  : XFXForm_3<31, 19, (ops GPRC:$rT), "mfcr $rT", SprMFCR>,
780             PPC970_MicroCode, PPC970_Unit_CRU;
781 def MTCRF : XFXForm_5<31, 144, (ops crbitm:$FXM, GPRC:$rS),
782                       "mtcrf $FXM, $rS", BrMCRX>,
783             PPC970_MicroCode, PPC970_Unit_CRU;
784 def MFOCRF: XFXForm_5a<31, 19, (ops GPRC:$rT, crbitm:$FXM),
785                        "mfcr $rT, $FXM", SprMFCR>,
786             PPC970_DGroup_First, PPC970_Unit_CRU;
787
788 // XS-Form instructions.  Just 'sradi'
789 //
790 let PPC970_Unit = 1 in {  // FXU Operations.
791 def SRADI  : XSForm_1<31, 413, (ops GPRC:$rA, GPRC:$rS, u6imm:$SH),
792                       "sradi $rA, $rS, $SH", IntRotateD>, isPPC64;
793
794 // XO-Form instructions.  Arithmetic instructions that can set overflow bit
795 //
796 def ADD4  : XOForm_1<31, 266, 0, (ops GPRC:$rT, GPRC:$rA, GPRC:$rB),
797                      "add $rT, $rA, $rB", IntGeneral,
798                      [(set GPRC:$rT, (add GPRC:$rA, GPRC:$rB))]>;
799 def ADD8  : XOForm_1<31, 266, 0, (ops G8RC:$rT, G8RC:$rA, G8RC:$rB),
800                      "add $rT, $rA, $rB", IntGeneral,
801                      [(set G8RC:$rT, (add G8RC:$rA, G8RC:$rB))]>;
802 def ADDC  : XOForm_1<31, 10, 0, (ops GPRC:$rT, GPRC:$rA, GPRC:$rB),
803                      "addc $rT, $rA, $rB", IntGeneral,
804                      [(set GPRC:$rT, (addc GPRC:$rA, GPRC:$rB))]>,
805                      PPC970_DGroup_Cracked;
806 def ADDE  : XOForm_1<31, 138, 0, (ops GPRC:$rT, GPRC:$rA, GPRC:$rB),
807                      "adde $rT, $rA, $rB", IntGeneral,
808                      [(set GPRC:$rT, (adde GPRC:$rA, GPRC:$rB))]>;
809 def DIVD  : XOForm_1<31, 489, 0, (ops G8RC:$rT, G8RC:$rA, G8RC:$rB),
810                      "divd $rT, $rA, $rB", IntDivD,
811                      [(set G8RC:$rT, (sdiv G8RC:$rA, G8RC:$rB))]>, isPPC64,
812                      PPC970_DGroup_First, PPC970_DGroup_Cracked;
813 def DIVDU : XOForm_1<31, 457, 0, (ops G8RC:$rT, G8RC:$rA, G8RC:$rB),
814                      "divdu $rT, $rA, $rB", IntDivD,
815                      [(set G8RC:$rT, (udiv G8RC:$rA, G8RC:$rB))]>, isPPC64,
816                      PPC970_DGroup_First, PPC970_DGroup_Cracked;
817 def DIVW  : XOForm_1<31, 491, 0, (ops GPRC:$rT, GPRC:$rA, GPRC:$rB),
818                      "divw $rT, $rA, $rB", IntDivW,
819                      [(set GPRC:$rT, (sdiv GPRC:$rA, GPRC:$rB))]>,
820                      PPC970_DGroup_First, PPC970_DGroup_Cracked;
821 def DIVWU : XOForm_1<31, 459, 0, (ops GPRC:$rT, GPRC:$rA, GPRC:$rB),
822                      "divwu $rT, $rA, $rB", IntDivW,
823                      [(set GPRC:$rT, (udiv GPRC:$rA, GPRC:$rB))]>,
824                      PPC970_DGroup_First, PPC970_DGroup_Cracked;
825 def MULHD : XOForm_1<31, 73, 0, (ops G8RC:$rT, G8RC:$rA, G8RC:$rB),
826                      "mulhd $rT, $rA, $rB", IntMulHW,
827                      [(set G8RC:$rT, (mulhs G8RC:$rA, G8RC:$rB))]>;
828 def MULHDU : XOForm_1<31, 9, 0, (ops G8RC:$rT, G8RC:$rA, G8RC:$rB),
829                      "mulhdu $rT, $rA, $rB", IntMulHWU,
830                      [(set G8RC:$rT, (mulhu G8RC:$rA, G8RC:$rB))]>;
831 def MULHW : XOForm_1<31, 75, 0, (ops GPRC:$rT, GPRC:$rA, GPRC:$rB),
832                      "mulhw $rT, $rA, $rB", IntMulHW,
833                      [(set GPRC:$rT, (mulhs GPRC:$rA, GPRC:$rB))]>;
834 def MULHWU : XOForm_1<31, 11, 0, (ops GPRC:$rT, GPRC:$rA, GPRC:$rB),
835                      "mulhwu $rT, $rA, $rB", IntMulHWU,
836                      [(set GPRC:$rT, (mulhu GPRC:$rA, GPRC:$rB))]>;
837 def MULLD : XOForm_1<31, 233, 0, (ops G8RC:$rT, G8RC:$rA, G8RC:$rB),
838                      "mulld $rT, $rA, $rB", IntMulHD,
839                      [(set G8RC:$rT, (mul G8RC:$rA, G8RC:$rB))]>, isPPC64;
840 def MULLW : XOForm_1<31, 235, 0, (ops GPRC:$rT, GPRC:$rA, GPRC:$rB),
841                      "mullw $rT, $rA, $rB", IntMulHW,
842                      [(set GPRC:$rT, (mul GPRC:$rA, GPRC:$rB))]>;
843 def SUBF  : XOForm_1<31, 40, 0, (ops GPRC:$rT, GPRC:$rA, GPRC:$rB),
844                      "subf $rT, $rA, $rB", IntGeneral,
845                      [(set GPRC:$rT, (sub GPRC:$rB, GPRC:$rA))]>;
846 def SUBFC : XOForm_1<31, 8, 0, (ops GPRC:$rT, GPRC:$rA, GPRC:$rB),
847                      "subfc $rT, $rA, $rB", IntGeneral,
848                      [(set GPRC:$rT, (subc GPRC:$rB, GPRC:$rA))]>,
849                      PPC970_DGroup_Cracked;
850 def SUBFE : XOForm_1<31, 136, 0, (ops GPRC:$rT, GPRC:$rA, GPRC:$rB),
851                      "subfe $rT, $rA, $rB", IntGeneral,
852                      [(set GPRC:$rT, (sube GPRC:$rB, GPRC:$rA))]>;
853 def ADDME  : XOForm_3<31, 234, 0, (ops GPRC:$rT, GPRC:$rA),
854                       "addme $rT, $rA", IntGeneral,
855                       [(set GPRC:$rT, (adde GPRC:$rA, immAllOnes))]>;
856 def ADDZE  : XOForm_3<31, 202, 0, (ops GPRC:$rT, GPRC:$rA),
857                       "addze $rT, $rA", IntGeneral,
858                       [(set GPRC:$rT, (adde GPRC:$rA, 0))]>;
859 def NEG    : XOForm_3<31, 104, 0, (ops GPRC:$rT, GPRC:$rA),
860                       "neg $rT, $rA", IntGeneral,
861                       [(set GPRC:$rT, (ineg GPRC:$rA))]>;
862 def SUBFME : XOForm_3<31, 232, 0, (ops GPRC:$rT, GPRC:$rA),
863                       "subfme $rT, $rA", IntGeneral,
864                       [(set GPRC:$rT, (sube immAllOnes, GPRC:$rA))]>;
865 def SUBFZE : XOForm_3<31, 200, 0, (ops GPRC:$rT, GPRC:$rA),
866                       "subfze $rT, $rA", IntGeneral,
867                       [(set GPRC:$rT, (sube 0, GPRC:$rA))]>;
868 }
869
870 // A-Form instructions.  Most of the instructions executed in the FPU are of
871 // this type.
872 //
873 let PPC970_Unit = 3 in {  // FPU Operations.
874 def FMADD : AForm_1<63, 29, 
875                     (ops F8RC:$FRT, F8RC:$FRA, F8RC:$FRC, F8RC:$FRB),
876                     "fmadd $FRT, $FRA, $FRC, $FRB", FPFused,
877                     [(set F8RC:$FRT, (fadd (fmul F8RC:$FRA, F8RC:$FRC),
878                                            F8RC:$FRB))]>,
879                     Requires<[FPContractions]>;
880 def FMADDS : AForm_1<59, 29,
881                     (ops F4RC:$FRT, F4RC:$FRA, F4RC:$FRC, F4RC:$FRB),
882                     "fmadds $FRT, $FRA, $FRC, $FRB", FPGeneral,
883                     [(set F4RC:$FRT, (fadd (fmul F4RC:$FRA, F4RC:$FRC),
884                                            F4RC:$FRB))]>,
885                     Requires<[FPContractions]>;
886 def FMSUB : AForm_1<63, 28,
887                     (ops F8RC:$FRT, F8RC:$FRA, F8RC:$FRC, F8RC:$FRB),
888                     "fmsub $FRT, $FRA, $FRC, $FRB", FPFused,
889                     [(set F8RC:$FRT, (fsub (fmul F8RC:$FRA, F8RC:$FRC),
890                                            F8RC:$FRB))]>,
891                     Requires<[FPContractions]>;
892 def FMSUBS : AForm_1<59, 28,
893                     (ops F4RC:$FRT, F4RC:$FRA, F4RC:$FRC, F4RC:$FRB),
894                     "fmsubs $FRT, $FRA, $FRC, $FRB", FPGeneral,
895                     [(set F4RC:$FRT, (fsub (fmul F4RC:$FRA, F4RC:$FRC),
896                                            F4RC:$FRB))]>,
897                     Requires<[FPContractions]>;
898 def FNMADD : AForm_1<63, 31,
899                     (ops F8RC:$FRT, F8RC:$FRA, F8RC:$FRC, F8RC:$FRB),
900                     "fnmadd $FRT, $FRA, $FRC, $FRB", FPFused,
901                     [(set F8RC:$FRT, (fneg (fadd (fmul F8RC:$FRA, F8RC:$FRC),
902                                                  F8RC:$FRB)))]>,
903                     Requires<[FPContractions]>;
904 def FNMADDS : AForm_1<59, 31,
905                     (ops F4RC:$FRT, F4RC:$FRA, F4RC:$FRC, F4RC:$FRB),
906                     "fnmadds $FRT, $FRA, $FRC, $FRB", FPGeneral,
907                     [(set F4RC:$FRT, (fneg (fadd (fmul F4RC:$FRA, F4RC:$FRC),
908                                                  F4RC:$FRB)))]>,
909                     Requires<[FPContractions]>;
910 def FNMSUB : AForm_1<63, 30,
911                     (ops F8RC:$FRT, F8RC:$FRA, F8RC:$FRC, F8RC:$FRB),
912                     "fnmsub $FRT, $FRA, $FRC, $FRB", FPFused,
913                     [(set F8RC:$FRT, (fneg (fsub (fmul F8RC:$FRA, F8RC:$FRC),
914                                                  F8RC:$FRB)))]>,
915                     Requires<[FPContractions]>;
916 def FNMSUBS : AForm_1<59, 30,
917                     (ops F4RC:$FRT, F4RC:$FRA, F4RC:$FRC, F4RC:$FRB),
918                     "fnmsubs $FRT, $FRA, $FRC, $FRB", FPGeneral,
919                     [(set F4RC:$FRT, (fneg (fsub (fmul F4RC:$FRA, F4RC:$FRC),
920                                                  F4RC:$FRB)))]>,
921                     Requires<[FPContractions]>;
922 // FSEL is artificially split into 4 and 8-byte forms for the result.  To avoid
923 // having 4 of these, force the comparison to always be an 8-byte double (code
924 // should use an FMRSD if the input comparison value really wants to be a float)
925 // and 4/8 byte forms for the result and operand type..
926 def FSELD : AForm_1<63, 23,
927                     (ops F8RC:$FRT, F8RC:$FRA, F8RC:$FRC, F8RC:$FRB),
928                     "fsel $FRT, $FRA, $FRC, $FRB", FPGeneral,
929                     [(set F8RC:$FRT, (PPCfsel F8RC:$FRA,F8RC:$FRC,F8RC:$FRB))]>;
930 def FSELS : AForm_1<63, 23,
931                      (ops F4RC:$FRT, F8RC:$FRA, F4RC:$FRC, F4RC:$FRB),
932                      "fsel $FRT, $FRA, $FRC, $FRB", FPGeneral,
933                     [(set F4RC:$FRT, (PPCfsel F8RC:$FRA,F4RC:$FRC,F4RC:$FRB))]>;
934 def FADD  : AForm_2<63, 21,
935                     (ops F8RC:$FRT, F8RC:$FRA, F8RC:$FRB),
936                     "fadd $FRT, $FRA, $FRB", FPGeneral,
937                     [(set F8RC:$FRT, (fadd F8RC:$FRA, F8RC:$FRB))]>;
938 def FADDS : AForm_2<59, 21,
939                     (ops F4RC:$FRT, F4RC:$FRA, F4RC:$FRB),
940                     "fadds $FRT, $FRA, $FRB", FPGeneral,
941                     [(set F4RC:$FRT, (fadd F4RC:$FRA, F4RC:$FRB))]>;
942 def FDIV  : AForm_2<63, 18,
943                     (ops F8RC:$FRT, F8RC:$FRA, F8RC:$FRB),
944                     "fdiv $FRT, $FRA, $FRB", FPDivD,
945                     [(set F8RC:$FRT, (fdiv F8RC:$FRA, F8RC:$FRB))]>;
946 def FDIVS : AForm_2<59, 18,
947                     (ops F4RC:$FRT, F4RC:$FRA, F4RC:$FRB),
948                     "fdivs $FRT, $FRA, $FRB", FPDivS,
949                     [(set F4RC:$FRT, (fdiv F4RC:$FRA, F4RC:$FRB))]>;
950 def FMUL  : AForm_3<63, 25,
951                     (ops F8RC:$FRT, F8RC:$FRA, F8RC:$FRB),
952                     "fmul $FRT, $FRA, $FRB", FPFused,
953                     [(set F8RC:$FRT, (fmul F8RC:$FRA, F8RC:$FRB))]>;
954 def FMULS : AForm_3<59, 25,
955                     (ops F4RC:$FRT, F4RC:$FRA, F4RC:$FRB),
956                     "fmuls $FRT, $FRA, $FRB", FPGeneral,
957                     [(set F4RC:$FRT, (fmul F4RC:$FRA, F4RC:$FRB))]>;
958 def FSUB  : AForm_2<63, 20,
959                     (ops F8RC:$FRT, F8RC:$FRA, F8RC:$FRB),
960                     "fsub $FRT, $FRA, $FRB", FPGeneral,
961                     [(set F8RC:$FRT, (fsub F8RC:$FRA, F8RC:$FRB))]>;
962 def FSUBS : AForm_2<59, 20,
963                     (ops F4RC:$FRT, F4RC:$FRA, F4RC:$FRB),
964                     "fsubs $FRT, $FRA, $FRB", FPGeneral,
965                     [(set F4RC:$FRT, (fsub F4RC:$FRA, F4RC:$FRB))]>;
966 }
967
968 let PPC970_Unit = 1 in {  // FXU Operations.
969 // M-Form instructions.  rotate and mask instructions.
970 //
971 let isTwoAddress = 1, isCommutable = 1 in {
972 // RLWIMI can be commuted if the rotate amount is zero.
973 def RLWIMI : MForm_2<20,
974                      (ops GPRC:$rA, GPRC:$rSi, GPRC:$rS, u5imm:$SH, u5imm:$MB, 
975                       u5imm:$ME), "rlwimi $rA, $rS, $SH, $MB, $ME", IntRotate,
976                       []>, PPC970_DGroup_Cracked;
977 def RLDIMI : MDForm_1<30, 3,
978                       (ops G8RC:$rA, G8RC:$rSi, G8RC:$rS, u6imm:$SH, u6imm:$MB),
979                       "rldimi $rA, $rS, $SH, $MB", IntRotateD,
980                       []>, isPPC64;
981 }
982 def RLWINM : MForm_2<21,
983                      (ops GPRC:$rA, GPRC:$rS, u5imm:$SH, u5imm:$MB, u5imm:$ME),
984                      "rlwinm $rA, $rS, $SH, $MB, $ME", IntGeneral,
985                      []>;
986 def RLWINMo : MForm_2<21,
987                      (ops GPRC:$rA, GPRC:$rS, u5imm:$SH, u5imm:$MB, u5imm:$ME),
988                      "rlwinm. $rA, $rS, $SH, $MB, $ME", IntGeneral,
989                      []>, isDOT, PPC970_DGroup_Cracked;
990 def RLWNM  : MForm_2<23,
991                      (ops GPRC:$rA, GPRC:$rS, GPRC:$rB, u5imm:$MB, u5imm:$ME),
992                      "rlwnm $rA, $rS, $rB, $MB, $ME", IntGeneral,
993                      []>;
994
995 // MD-Form instructions.  64 bit rotate instructions.
996 //
997 def RLDICL : MDForm_1<30, 0,
998                       (ops G8RC:$rA, G8RC:$rS, u6imm:$SH, u6imm:$MB),
999                       "rldicl $rA, $rS, $SH, $MB", IntRotateD,
1000                       []>, isPPC64;
1001 def RLDICR : MDForm_1<30, 1,
1002                       (ops G8RC:$rA, G8RC:$rS, u6imm:$SH, u6imm:$ME),
1003                       "rldicr $rA, $rS, $SH, $ME", IntRotateD,
1004                       []>, isPPC64;
1005 }
1006
1007
1008 let PPC970_Unit = 5 in {  // VALU Operations.
1009 // VA-Form instructions.  3-input AltiVec ops.
1010 def VMADDFP : VAForm_1<46, (ops VRRC:$vD, VRRC:$vA, VRRC:$vC, VRRC:$vB),
1011                        "vmaddfp $vD, $vA, $vC, $vB", VecFP,
1012                        [(set VRRC:$vD, (fadd (fmul VRRC:$vA, VRRC:$vC),
1013                                              VRRC:$vB))]>,
1014                        Requires<[FPContractions]>;
1015 def VNMSUBFP: VAForm_1<47, (ops VRRC:$vD, VRRC:$vA, VRRC:$vC, VRRC:$vB),
1016                        "vnmsubfp $vD, $vA, $vC, $vB", VecFP,
1017                        [(set VRRC:$vD, (fneg (fsub (fmul VRRC:$vA, VRRC:$vC),
1018                                                    VRRC:$vB)))]>,
1019                        Requires<[FPContractions]>;
1020
1021 def VPERM   : VAForm_1<43, (ops VRRC:$vD, VRRC:$vA, VRRC:$vC, VRRC:$vB),
1022                        "vperm $vD, $vA, $vB, $vC", VecPerm,
1023                        [(set VRRC:$vD,
1024                              (PPCvperm (v4f32 VRRC:$vA), VRRC:$vB, VRRC:$vC))]>;
1025
1026
1027 // VX-Form instructions.  AltiVec arithmetic ops.
1028 def VADDFP : VXForm_1<10, (ops VRRC:$vD, VRRC:$vA, VRRC:$vB),
1029                       "vaddfp $vD, $vA, $vB", VecFP,
1030                       [(set VRRC:$vD, (fadd VRRC:$vA, VRRC:$vB))]>;
1031 def VADDUWM : VXForm_1<128, (ops VRRC:$vD, VRRC:$vA, VRRC:$vB),
1032                       "vadduwm $vD, $vA, $vB", VecGeneral,
1033                       [(set VRRC:$vD, (add (v4i32 VRRC:$vA), VRRC:$vB))]>;
1034 def VCFSX  : VXForm_1<842, (ops VRRC:$vD, u5imm:$UIMM, VRRC:$vB),
1035                       "vcfsx $vD, $vB, $UIMM", VecFP,
1036                       []>;
1037 def VCFUX  : VXForm_1<778, (ops VRRC:$vD, u5imm:$UIMM, VRRC:$vB),
1038                       "vcfux $vD, $vB, $UIMM", VecFP,
1039                       []>;
1040 def VCTSXS : VXForm_1<970, (ops VRRC:$vD, u5imm:$UIMM, VRRC:$vB),
1041                       "vctsxs $vD, $vB, $UIMM", VecFP,
1042                       []>;
1043 def VCTUXS : VXForm_1<906, (ops VRRC:$vD, u5imm:$UIMM, VRRC:$vB),
1044                       "vctuxs $vD, $vB, $UIMM", VecFP,
1045                       []>;
1046 def VEXPTEFP : VXForm_2<394, (ops VRRC:$vD, VRRC:$vB),
1047                         "vexptefp $vD, $vB", VecFP,
1048                         []>;
1049 def VLOGEFP  : VXForm_2<458, (ops VRRC:$vD, VRRC:$vB),
1050                         "vlogefp $vD, $vB", VecFP,
1051                         []>;
1052 def VMAXFP : VXForm_1<1034, (ops VRRC:$vD, VRRC:$vA, VRRC:$vB),
1053                       "vmaxfp $vD, $vA, $vB", VecFP,
1054                       []>;
1055 def VMINFP : VXForm_1<1098, (ops VRRC:$vD, VRRC:$vA, VRRC:$vB),
1056                       "vminfp $vD, $vA, $vB", VecFP,
1057                       []>;
1058 def VREFP  : VXForm_2<266, (ops VRRC:$vD, VRRC:$vB),
1059                       "vrefp $vD, $vB", VecFP,
1060                       []>;
1061 def VRFIM  : VXForm_2<714, (ops VRRC:$vD, VRRC:$vB),
1062                       "vrfim $vD, $vB", VecFP,
1063                       []>;
1064 def VRFIN  : VXForm_2<522, (ops VRRC:$vD, VRRC:$vB),
1065                       "vrfin $vD, $vB", VecFP,
1066                       []>;
1067 def VRFIP  : VXForm_2<650, (ops VRRC:$vD, VRRC:$vB),
1068                       "vrfip $vD, $vB", VecFP,
1069                       []>;
1070 def VRFIZ  : VXForm_2<586, (ops VRRC:$vD, VRRC:$vB),
1071                       "vrfiz $vD, $vB", VecFP,
1072                       []>;
1073 def VRSQRTEFP : VXForm_2<330, (ops VRRC:$vD, VRRC:$vB),
1074                          "vrsqrtefp $vD, $vB", VecFP,
1075                          []>;
1076 def VSUBFP : VXForm_1<74, (ops VRRC:$vD, VRRC:$vA, VRRC:$vB),
1077                       "vsubfp $vD, $vA, $vB", VecFP,
1078                       [(set VRRC:$vD, (fsub VRRC:$vA, VRRC:$vB))]>;
1079 def VOR : VXForm_1<1156, (ops VRRC:$vD, VRRC:$vA, VRRC:$vB),
1080                       "vor $vD, $vA, $vB", VecFP,
1081                       []>;
1082 def VXOR : VXForm_1<1220, (ops VRRC:$vD, VRRC:$vA, VRRC:$vB),
1083                       "vxor $vD, $vA, $vB", VecFP,
1084                       []>;
1085
1086 def VSPLTB : VXForm_1<524, (ops VRRC:$vD, u5imm:$UIMM, VRRC:$vB),
1087                       "vspltb $vD, $vB, $UIMM", VecPerm,
1088                       []>;
1089 def VSPLTH : VXForm_1<588, (ops VRRC:$vD, u5imm:$UIMM, VRRC:$vB),
1090                       "vsplth $vD, $vB, $UIMM", VecPerm,
1091                       []>;
1092 def VSPLTW : VXForm_1<652, (ops VRRC:$vD, u5imm:$UIMM, VRRC:$vB),
1093                       "vspltw $vD, $vB, $UIMM", VecPerm,
1094                       [(set VRRC:$vD, (vector_shuffle (v4f32 VRRC:$vB), (undef),
1095                                       VSPLT_shuffle_mask:$UIMM))]>;
1096
1097 def VSPLTISB : VXForm_1<780, (ops VRRC:$vD, s5imm:$SIMM),
1098                       "vspltisb $vD, $SIMM", VecPerm,
1099                       [(set VRRC:$vD, (v4f32 vecspltisb:$SIMM))]>;
1100 def VSPLTISH : VXForm_1<844, (ops VRRC:$vD, s5imm:$SIMM),
1101                       "vspltish $vD, $SIMM", VecPerm,
1102                       [(set VRRC:$vD, (v4f32 vecspltish:$SIMM))]>;
1103 def VSPLTISW : VXForm_1<908, (ops VRRC:$vD, s5imm:$SIMM),
1104                       "vspltisw $vD, $SIMM", VecPerm,
1105                       [(set VRRC:$vD, (v4f32 vecspltisw:$SIMM))]>;
1106
1107                       
1108 // VX-Form Pseudo Instructions
1109
1110 def V_SET0 : VXForm_setzero<1220, (ops VRRC:$vD),
1111                       "vxor $vD, $vD, $vD", VecFP,
1112                       [(set VRRC:$vD, (v4f32 vecimm0))]>;
1113 }
1114
1115
1116 //===----------------------------------------------------------------------===//
1117 // DWARF Pseudo Instructions
1118 //
1119
1120 def DWARF_LOC        : Pseudo<(ops i32imm:$line, i32imm:$col, i32imm:$file),
1121                               "; .loc $file, $line, $col",
1122                       [(dwarf_loc (i32 imm:$line), (i32 imm:$col),
1123                                   (i32 imm:$file))]>;
1124
1125 def DWARF_LABEL      : Pseudo<(ops i32imm:$id),
1126                               "\nLdebug_loc$id:",
1127                       [(dwarf_label (i32 imm:$id))]>;
1128
1129 //===----------------------------------------------------------------------===//
1130 // PowerPC Instruction Patterns
1131 //
1132
1133 // Arbitrary immediate support.  Implement in terms of LIS/ORI.
1134 def : Pat<(i32 imm:$imm),
1135           (ORI (LIS (HI16 imm:$imm)), (LO16 imm:$imm))>;
1136
1137 // Implement the 'not' operation with the NOR instruction.
1138 def NOT : Pat<(not GPRC:$in),
1139               (NOR GPRC:$in, GPRC:$in)>;
1140
1141 // ADD an arbitrary immediate.
1142 def : Pat<(add GPRC:$in, imm:$imm),
1143           (ADDIS (ADDI GPRC:$in, (LO16 imm:$imm)), (HA16 imm:$imm))>;
1144 // OR an arbitrary immediate.
1145 def : Pat<(or GPRC:$in, imm:$imm),
1146           (ORIS (ORI GPRC:$in, (LO16 imm:$imm)), (HI16 imm:$imm))>;
1147 // XOR an arbitrary immediate.
1148 def : Pat<(xor GPRC:$in, imm:$imm),
1149           (XORIS (XORI GPRC:$in, (LO16 imm:$imm)), (HI16 imm:$imm))>;
1150 // SUBFIC
1151 def : Pat<(sub  immSExt16:$imm, GPRC:$in),
1152           (SUBFIC GPRC:$in, imm:$imm)>;
1153
1154 // Return void support.
1155 def : Pat<(ret), (BLR)>;
1156
1157 // 64-bit support
1158 def : Pat<(i64 (zext GPRC:$in)),
1159           (RLDICL (OR4To8 GPRC:$in, GPRC:$in), 0, 32)>;
1160 def : Pat<(i64 (anyext GPRC:$in)),
1161           (OR4To8 GPRC:$in, GPRC:$in)>;
1162 def : Pat<(i32 (trunc G8RC:$in)),
1163           (OR8To4 G8RC:$in, G8RC:$in)>;
1164
1165 // SHL
1166 def : Pat<(shl GPRC:$in, (i32 imm:$imm)),
1167           (RLWINM GPRC:$in, imm:$imm, 0, (SHL32 imm:$imm))>;
1168 def : Pat<(shl G8RC:$in, (i64 imm:$imm)),
1169           (RLDICR G8RC:$in, imm:$imm, (SHL64 imm:$imm))>;
1170 // SRL
1171 def : Pat<(srl GPRC:$in, (i32 imm:$imm)),
1172           (RLWINM GPRC:$in, (SRL32 imm:$imm), imm:$imm, 31)>;
1173 def : Pat<(srl G8RC:$in, (i64 imm:$imm)),
1174           (RLDICL G8RC:$in, (SRL64 imm:$imm), imm:$imm)>;
1175
1176 // ROTL
1177 def : Pat<(rotl GPRC:$in, GPRC:$sh),
1178           (RLWNM GPRC:$in, GPRC:$sh, 0, 31)>;
1179 def : Pat<(rotl GPRC:$in, (i32 imm:$imm)),
1180           (RLWINM GPRC:$in, imm:$imm, 0, 31)>;
1181           
1182 // Hi and Lo for Darwin Global Addresses.
1183 def : Pat<(PPChi tglobaladdr:$in, 0), (LIS tglobaladdr:$in)>;
1184 def : Pat<(PPClo tglobaladdr:$in, 0), (LI tglobaladdr:$in)>;
1185 def : Pat<(PPChi tconstpool:$in, 0), (LIS tconstpool:$in)>;
1186 def : Pat<(PPClo tconstpool:$in, 0), (LI tconstpool:$in)>;
1187 def : Pat<(add GPRC:$in, (PPChi tglobaladdr:$g, 0)),
1188           (ADDIS GPRC:$in, tglobaladdr:$g)>;
1189 def : Pat<(add GPRC:$in, (PPChi tconstpool:$g, 0)),
1190           (ADDIS GPRC:$in, tconstpool:$g)>;
1191
1192 def : Pat<(fmul VRRC:$vA, VRRC:$vB),
1193           (VMADDFP VRRC:$vA, VRRC:$vB, (V_SET0))>; 
1194
1195 // Fused negative multiply subtract, alternate pattern
1196 def : Pat<(fsub F8RC:$B, (fmul F8RC:$A, F8RC:$C)),
1197           (FNMSUB F8RC:$A, F8RC:$C, F8RC:$B)>,
1198           Requires<[FPContractions]>;
1199 def : Pat<(fsub F4RC:$B, (fmul F4RC:$A, F4RC:$C)),
1200           (FNMSUBS F4RC:$A, F4RC:$C, F4RC:$B)>,
1201           Requires<[FPContractions]>;
1202
1203 // Fused multiply add and multiply sub for packed float.  These are represented
1204 // separately from the real instructions above, for operations that must have
1205 // the additional precision, such as Newton-Rhapson (used by divide, sqrt)
1206 def : Pat<(PPCvmaddfp VRRC:$A, VRRC:$B, VRRC:$C),
1207           (VMADDFP VRRC:$A, VRRC:$B, VRRC:$C)>;
1208 def : Pat<(PPCvnmsubfp VRRC:$A, VRRC:$B, VRRC:$C),
1209           (VNMSUBFP VRRC:$A, VRRC:$B, VRRC:$C)>;
1210
1211 def : Pat<(int_ppc_altivec_vmaddfp VRRC:$A, VRRC:$B, VRRC:$C),
1212           (VMADDFP VRRC:$A, VRRC:$B, VRRC:$C)>;
1213 def : Pat<(int_ppc_altivec_vnmsubfp VRRC:$A, VRRC:$B, VRRC:$C),
1214           (VNMSUBFP VRRC:$A, VRRC:$B, VRRC:$C)>;
1215
1216 // Standard shifts.  These are represented separately from the real shifts above
1217 // so that we can distinguish between shifts that allow 5-bit and 6-bit shift
1218 // amounts.
1219 def : Pat<(sra GPRC:$rS, GPRC:$rB),
1220           (SRAW GPRC:$rS, GPRC:$rB)>;
1221 def : Pat<(srl GPRC:$rS, GPRC:$rB),
1222           (SRW GPRC:$rS, GPRC:$rB)>;
1223 def : Pat<(shl GPRC:$rS, GPRC:$rB),
1224           (SLW GPRC:$rS, GPRC:$rB)>;
1225
1226 def : Pat<(i32 (zextload iaddr:$src, i1)),
1227           (LBZ iaddr:$src)>;
1228 def : Pat<(i32 (zextload xaddr:$src, i1)),
1229           (LBZX xaddr:$src)>;
1230 def : Pat<(i32 (extload iaddr:$src, i1)),
1231           (LBZ iaddr:$src)>;
1232 def : Pat<(i32 (extload xaddr:$src, i1)),
1233           (LBZX xaddr:$src)>;
1234 def : Pat<(i32 (extload iaddr:$src, i8)),
1235           (LBZ iaddr:$src)>;
1236 def : Pat<(i32 (extload xaddr:$src, i8)),
1237           (LBZX xaddr:$src)>;
1238 def : Pat<(i32 (extload iaddr:$src, i16)),
1239           (LHZ iaddr:$src)>;
1240 def : Pat<(i32 (extload xaddr:$src, i16)),
1241           (LHZX xaddr:$src)>;
1242 def : Pat<(f64 (extload iaddr:$src, f32)),
1243           (FMRSD (LFS iaddr:$src))>;
1244 def : Pat<(f64 (extload xaddr:$src, f32)),
1245           (FMRSD (LFSX xaddr:$src))>;
1246
1247 def : Pat<(v4i32 (load xoaddr:$src)), (v4i32 (LVX xoaddr:$src))>;
1248 def : Pat<(v8i16 (load xoaddr:$src)), (v8i16 (LVX xoaddr:$src))>;
1249 def : Pat<(v16i8 (load xoaddr:$src)), (v16i8 (LVX xoaddr:$src))>;
1250
1251
1252 def : Pat<(vector_shuffle (v4i32 VRRC:$vB), (undef), VSPLT_shuffle_mask:$UIMM),
1253           (v4i32 (VSPLTW VSPLT_shuffle_mask:$UIMM, VRRC:$vB))>;
1254
1255 def : Pat<(PPCvperm (v4i32 VRRC:$vA), VRRC:$vB, VRRC:$vC),
1256           (v4i32 (VPERM VRRC:$vA, VRRC:$vB, VRRC:$vC))>;
1257
1258 def : Pat<(store (v16i8 VRRC:$rS), xoaddr:$dst),
1259           (STVX (v16i8 VRRC:$rS), xoaddr:$dst)>;
1260 def : Pat<(store (v8i16 VRRC:$rS), xoaddr:$dst),
1261           (STVX (v8i16 VRRC:$rS), xoaddr:$dst)>;
1262 def : Pat<(store (v4i32 VRRC:$rS), xoaddr:$dst),
1263           (STVX (v4i32 VRRC:$rS), xoaddr:$dst)>;
1264
1265 def : Pat<(v4i32 (PPClve_x xoaddr:$src)),
1266           (v4i32 (LVEWX xoaddr:$src))>;
1267
1268 def : Pat<(v4i32 (undef)), (v4i32 (IMPLICIT_DEF_VRRC))>;
1269 def : Pat<(v4i32 vecimm0), (v4i32 (V_SET0))>;
1270
1271 def : Pat<(v4i32 vecspltisb:$invec), (v4i32 (VSPLTISB vecspltisb:$invec))>;
1272 def : Pat<(v4i32 vecspltish:$invec), (v4i32 (VSPLTISH vecspltish:$invec))>;
1273 def : Pat<(v4i32 vecspltisw:$invec), (v4i32 (VSPLTISW vecspltisw:$invec))>;
1274
1275
1276 // bit_convert
1277 def : Pat<(v4i32 (bitconvert (v4f32 VRRC:$src))), (v4i32 VRRC:$src)>;
1278 def : Pat<(v4f32 (bitconvert (v4i32 VRRC:$src))), (v4f32 VRRC:$src)>;
1279
1280 // Same as above, but using a temporary. FIXME: implement temporaries :)
1281 /*
1282 def : Pattern<(xor GPRC:$in, imm:$imm),
1283               [(set GPRC:$tmp, (XORI GPRC:$in, (LO16 imm:$imm))),
1284                (XORIS GPRC:$tmp, (HI16 imm:$imm))]>;
1285 */
1286