Merge ISD::TRUNCSTORE to ISD::STORE. Switch to using StoreSDNode.
[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
28 def SDT_PPCvperm   : SDTypeProfile<1, 3, [
29   SDTCisVT<3, v16i8>, SDTCisSameAs<0, 1>, SDTCisSameAs<0, 2>
30 ]>;
31
32 def SDT_PPCvcmp : SDTypeProfile<1, 3, [
33   SDTCisSameAs<0, 1>, SDTCisSameAs<1, 2>, SDTCisVT<3, i32>
34 ]>;
35
36 def SDT_PPCcondbr : SDTypeProfile<0, 3, [
37   SDTCisVT<1, i32>, SDTCisVT<2, OtherVT>
38 ]>;
39
40 def SDT_PPClbrx : SDTypeProfile<1, 3, [
41   SDTCisVT<0, i32>, SDTCisPtrTy<1>, SDTCisVT<2, OtherVT>, SDTCisVT<3, OtherVT>
42 ]>;
43 def SDT_PPCstbrx : SDTypeProfile<0, 4, [
44   SDTCisVT<0, i32>, SDTCisPtrTy<1>, SDTCisVT<2, OtherVT>, SDTCisVT<3, OtherVT>
45 ]>;
46
47 //===----------------------------------------------------------------------===//
48 // PowerPC specific DAG Nodes.
49 //
50
51 def PPCfcfid  : SDNode<"PPCISD::FCFID" , SDTFPUnaryOp, []>;
52 def PPCfctidz : SDNode<"PPCISD::FCTIDZ", SDTFPUnaryOp, []>;
53 def PPCfctiwz : SDNode<"PPCISD::FCTIWZ", SDTFPUnaryOp, []>;
54 def PPCstfiwx : SDNode<"PPCISD::STFIWX", SDT_PPCstfiwx, [SDNPHasChain]>;
55
56 def PPCfsel   : SDNode<"PPCISD::FSEL",  
57    // Type constraint for fsel.
58    SDTypeProfile<1, 3, [SDTCisSameAs<0, 2>, SDTCisSameAs<0, 3>, 
59                         SDTCisFP<0>, SDTCisVT<1, f64>]>, []>;
60
61 def PPChi       : SDNode<"PPCISD::Hi", SDTIntBinOp, []>;
62 def PPClo       : SDNode<"PPCISD::Lo", SDTIntBinOp, []>;
63 def PPCvmaddfp  : SDNode<"PPCISD::VMADDFP", SDTFPTernaryOp, []>;
64 def PPCvnmsubfp : SDNode<"PPCISD::VNMSUBFP", SDTFPTernaryOp, []>;
65
66 def PPCvperm    : SDNode<"PPCISD::VPERM", SDT_PPCvperm, []>;
67
68 // These nodes represent the 32-bit PPC shifts that operate on 6-bit shift
69 // amounts.  These nodes are generated by the multi-precision shift code.
70 def PPCsrl        : SDNode<"PPCISD::SRL"       , SDT_PPCShiftOp>;
71 def PPCsra        : SDNode<"PPCISD::SRA"       , SDT_PPCShiftOp>;
72 def PPCshl        : SDNode<"PPCISD::SHL"       , SDT_PPCShiftOp>;
73
74 def PPCextsw_32   : SDNode<"PPCISD::EXTSW_32"  , SDTIntUnaryOp>;
75 def PPCstd_32     : SDNode<"PPCISD::STD_32"    , SDTStore, [SDNPHasChain]>;
76
77 // These are target-independent nodes, but have target-specific formats.
78 def callseq_start : SDNode<"ISD::CALLSEQ_START", SDT_PPCCallSeq,
79                            [SDNPHasChain, SDNPOutFlag]>;
80 def callseq_end   : SDNode<"ISD::CALLSEQ_END",   SDT_PPCCallSeq,
81                            [SDNPHasChain, SDNPOutFlag]>;
82
83 def SDT_PPCCall   : SDTypeProfile<0, -1, [SDTCisInt<0>]>;
84 def PPCcall       : SDNode<"PPCISD::CALL", SDT_PPCCall,
85                            [SDNPHasChain, SDNPOptInFlag, SDNPOutFlag]>;
86 def PPCmtctr      : SDNode<"PPCISD::MTCTR", SDT_PPCCall,
87                            [SDNPHasChain, SDNPOptInFlag, SDNPOutFlag]>;
88 def PPCbctrl      : SDNode<"PPCISD::BCTRL", SDTRet,
89                            [SDNPHasChain, SDNPOptInFlag, SDNPOutFlag]>;
90
91 def retflag       : SDNode<"PPCISD::RET_FLAG", SDTRet,
92                            [SDNPHasChain, SDNPOptInFlag]>;
93
94 def PPCvcmp       : SDNode<"PPCISD::VCMP" , SDT_PPCvcmp, []>;
95 def PPCvcmp_o     : SDNode<"PPCISD::VCMPo", SDT_PPCvcmp, [SDNPOutFlag]>;
96
97 def PPCcondbranch : SDNode<"PPCISD::COND_BRANCH", SDT_PPCcondbr,
98                            [SDNPHasChain, SDNPOptInFlag]>;
99
100 def PPClbrx       : SDNode<"PPCISD::LBRX", SDT_PPClbrx, [SDNPHasChain]>;
101 def PPCstbrx      : SDNode<"PPCISD::STBRX", SDT_PPCstbrx, [SDNPHasChain]>;
102
103 //===----------------------------------------------------------------------===//
104 // PowerPC specific transformation functions and pattern fragments.
105 //
106
107 def SHL32 : SDNodeXForm<imm, [{
108   // Transformation function: 31 - imm
109   return getI32Imm(31 - N->getValue());
110 }]>;
111
112 def SRL32 : SDNodeXForm<imm, [{
113   // Transformation function: 32 - imm
114   return N->getValue() ? getI32Imm(32 - N->getValue()) : getI32Imm(0);
115 }]>;
116
117 def LO16 : SDNodeXForm<imm, [{
118   // Transformation function: get the low 16 bits.
119   return getI32Imm((unsigned short)N->getValue());
120 }]>;
121
122 def HI16 : SDNodeXForm<imm, [{
123   // Transformation function: shift the immediate value down into the low bits.
124   return getI32Imm((unsigned)N->getValue() >> 16);
125 }]>;
126
127 def HA16 : SDNodeXForm<imm, [{
128   // Transformation function: shift the immediate value down into the low bits.
129   signed int Val = N->getValue();
130   return getI32Imm((Val - (signed short)Val) >> 16);
131 }]>;
132 def MB : SDNodeXForm<imm, [{
133   // Transformation function: get the start bit of a mask
134   unsigned mb, me;
135   (void)isRunOfOnes((unsigned)N->getValue(), mb, me);
136   return getI32Imm(mb);
137 }]>;
138
139 def ME : SDNodeXForm<imm, [{
140   // Transformation function: get the end bit of a mask
141   unsigned mb, me;
142   (void)isRunOfOnes((unsigned)N->getValue(), mb, me);
143   return getI32Imm(me);
144 }]>;
145 def maskimm32 : PatLeaf<(imm), [{
146   // maskImm predicate - True if immediate is a run of ones.
147   unsigned mb, me;
148   if (N->getValueType(0) == MVT::i32)
149     return isRunOfOnes((unsigned)N->getValue(), mb, me);
150   else
151     return false;
152 }]>;
153
154 def immSExt16  : PatLeaf<(imm), [{
155   // immSExt16 predicate - True if the immediate fits in a 16-bit sign extended
156   // field.  Used by instructions like 'addi'.
157   if (N->getValueType(0) == MVT::i32)
158     return (int32_t)N->getValue() == (short)N->getValue();
159   else
160     return (int64_t)N->getValue() == (short)N->getValue();
161 }]>;
162 def immZExt16  : PatLeaf<(imm), [{
163   // immZExt16 predicate - True if the immediate fits in a 16-bit zero extended
164   // field.  Used by instructions like 'ori'.
165   return (uint64_t)N->getValue() == (unsigned short)N->getValue();
166 }], LO16>;
167
168 // imm16Shifted* - These match immediates where the low 16-bits are zero.  There
169 // are two forms: imm16ShiftedSExt and imm16ShiftedZExt.  These two forms are
170 // identical in 32-bit mode, but in 64-bit mode, they return true if the
171 // immediate fits into a sign/zero extended 32-bit immediate (with the low bits
172 // clear).
173 def imm16ShiftedZExt : PatLeaf<(imm), [{
174   // imm16ShiftedZExt predicate - True if only bits in the top 16-bits of the
175   // immediate are set.  Used by instructions like 'xoris'.
176   return (N->getValue() & ~uint64_t(0xFFFF0000)) == 0;
177 }], HI16>;
178
179 def imm16ShiftedSExt : PatLeaf<(imm), [{
180   // imm16ShiftedSExt predicate - True if only bits in the top 16-bits of the
181   // immediate are set.  Used by instructions like 'addis'.  Identical to 
182   // imm16ShiftedZExt in 32-bit mode.
183   if (N->getValue() & 0xFFFF) return false;
184   if (N->getValueType(0) == MVT::i32)
185     return true;
186   // For 64-bit, make sure it is sext right.
187   return N->getValue() == (uint64_t)(int)N->getValue();
188 }], HI16>;
189
190
191 //===----------------------------------------------------------------------===//
192 // PowerPC Flag Definitions.
193
194 class isPPC64 { bit PPC64 = 1; }
195 class isDOT   {
196   list<Register> Defs = [CR0];
197   bit RC  = 1;
198 }
199
200
201
202 //===----------------------------------------------------------------------===//
203 // PowerPC Operand Definitions.
204
205 def s5imm   : Operand<i32> {
206   let PrintMethod = "printS5ImmOperand";
207 }
208 def u5imm   : Operand<i32> {
209   let PrintMethod = "printU5ImmOperand";
210 }
211 def u6imm   : Operand<i32> {
212   let PrintMethod = "printU6ImmOperand";
213 }
214 def s16imm  : Operand<i32> {
215   let PrintMethod = "printS16ImmOperand";
216 }
217 def u16imm  : Operand<i32> {
218   let PrintMethod = "printU16ImmOperand";
219 }
220 def s16immX4  : Operand<i32> {   // Multiply imm by 4 before printing.
221   let PrintMethod = "printS16X4ImmOperand";
222 }
223 def target : Operand<OtherVT> {
224   let PrintMethod = "printBranchOperand";
225 }
226 def calltarget : Operand<iPTR> {
227   let PrintMethod = "printCallOperand";
228 }
229 def aaddr : Operand<iPTR> {
230   let PrintMethod = "printAbsAddrOperand";
231 }
232 def piclabel: Operand<iPTR> {
233   let PrintMethod = "printPICLabel";
234 }
235 def symbolHi: Operand<i32> {
236   let PrintMethod = "printSymbolHi";
237 }
238 def symbolLo: Operand<i32> {
239   let PrintMethod = "printSymbolLo";
240 }
241 def crbitm: Operand<i8> {
242   let PrintMethod = "printcrbitm";
243 }
244 // Address operands
245 def memri : Operand<iPTR> {
246   let PrintMethod = "printMemRegImm";
247   let NumMIOperands = 2;
248   let MIOperandInfo = (ops i32imm, ptr_rc);
249 }
250 def memrr : Operand<iPTR> {
251   let PrintMethod = "printMemRegReg";
252   let NumMIOperands = 2;
253   let MIOperandInfo = (ops ptr_rc, ptr_rc);
254 }
255 def memrix : Operand<iPTR> {   // memri where the imm is shifted 2 bits.
256   let PrintMethod = "printMemRegImmShifted";
257   let NumMIOperands = 2;
258   let MIOperandInfo = (ops i32imm, ptr_rc);
259 }
260
261 // Define PowerPC specific addressing mode.
262 def iaddr  : ComplexPattern<iPTR, 2, "SelectAddrImm",    [], []>;
263 def xaddr  : ComplexPattern<iPTR, 2, "SelectAddrIdx",    [], []>;
264 def xoaddr : ComplexPattern<iPTR, 2, "SelectAddrIdxOnly",[], []>;
265 def ixaddr : ComplexPattern<iPTR, 2, "SelectAddrImmShift", [], []>; // "std"
266
267 //===----------------------------------------------------------------------===//
268 // PowerPC Instruction Predicate Definitions.
269 def FPContractions : Predicate<"!NoExcessFPPrecision">;
270
271 //===----------------------------------------------------------------------===//
272 // PowerPC Instruction Definitions.
273
274 // Pseudo-instructions:
275
276 let hasCtrlDep = 1 in {
277 def ADJCALLSTACKDOWN : Pseudo<(ops u16imm:$amt),
278                               "${:comment} ADJCALLSTACKDOWN",
279                               [(callseq_start imm:$amt)]>, Imp<[R1],[R1]>;
280 def ADJCALLSTACKUP   : Pseudo<(ops u16imm:$amt),
281                               "${:comment} ADJCALLSTACKUP",
282                               [(callseq_end imm:$amt)]>, Imp<[R1],[R1]>;
283
284 def UPDATE_VRSAVE    : Pseudo<(ops GPRC:$rD, GPRC:$rS),
285                               "UPDATE_VRSAVE $rD, $rS", []>;
286 }
287 def IMPLICIT_DEF_GPRC: Pseudo<(ops GPRC:$rD),"${:comment}IMPLICIT_DEF_GPRC $rD",
288                               [(set GPRC:$rD, (undef))]>;
289 def IMPLICIT_DEF_F8  : Pseudo<(ops F8RC:$rD), "${:comment} IMPLICIT_DEF_F8 $rD",
290                               [(set F8RC:$rD, (undef))]>;
291 def IMPLICIT_DEF_F4  : Pseudo<(ops F4RC:$rD), "${:comment} IMPLICIT_DEF_F4 $rD",
292                               [(set F4RC:$rD, (undef))]>;
293
294 // SELECT_CC_* - Used to implement the SELECT_CC DAG operation.  Expanded by the
295 // scheduler into a branch sequence.
296 let usesCustomDAGSchedInserter = 1,    // Expanded by the scheduler.
297     PPC970_Single = 1 in {
298   def SELECT_CC_I4 : Pseudo<(ops GPRC:$dst, CRRC:$cond, GPRC:$T, GPRC:$F,
299                               i32imm:$BROPC), "${:comment} SELECT_CC PSEUDO!",
300                               []>;
301   def SELECT_CC_I8 : Pseudo<(ops G8RC:$dst, CRRC:$cond, G8RC:$T, G8RC:$F,
302                               i32imm:$BROPC), "${:comment} SELECT_CC PSEUDO!",
303                               []>;
304   def SELECT_CC_F4  : Pseudo<(ops F4RC:$dst, CRRC:$cond, F4RC:$T, F4RC:$F,
305                               i32imm:$BROPC), "${:comment} SELECT_CC PSEUDO!",
306                               []>;
307   def SELECT_CC_F8  : Pseudo<(ops F8RC:$dst, CRRC:$cond, F8RC:$T, F8RC:$F,
308                               i32imm:$BROPC), "${:comment} SELECT_CC PSEUDO!",
309                               []>;
310   def SELECT_CC_VRRC: Pseudo<(ops VRRC:$dst, CRRC:$cond, VRRC:$T, VRRC:$F,
311                               i32imm:$BROPC), "${:comment} SELECT_CC PSEUDO!",
312                               []>;
313 }
314
315 let isTerminator = 1, isBarrier = 1, noResults = 1, PPC970_Unit = 7 in {
316   let isReturn = 1 in
317     def BLR : XLForm_2_ext<19, 16, 20, 0, 0, (ops), "blr", BrB, [(retflag)]>;
318   def BCTR : XLForm_2_ext<19, 528, 20, 0, 0, (ops), "bctr", BrB, []>;
319 }
320
321 let Defs = [LR] in
322   def MovePCtoLR : Pseudo<(ops piclabel:$label), "bl $label", []>,
323                    PPC970_Unit_BRU;
324
325 let isBranch = 1, isTerminator = 1, hasCtrlDep = 1, 
326     noResults = 1, PPC970_Unit = 7 in {
327   // COND_BRANCH is formed before branch selection, it is turned into Bcc below.
328   def COND_BRANCH : Pseudo<(ops CRRC:$crS, u16imm:$opc, target:$dst),
329                            "${:comment} COND_BRANCH $crS, $opc, $dst",
330                            [(PPCcondbranch CRRC:$crS, imm:$opc, bb:$dst)]>;
331   let isBarrier = 1 in {
332   def B   : IForm<18, 0, 0, (ops target:$dst),
333                   "b $dst", BrB,
334                   [(br bb:$dst)]>;
335   }
336
337   def BLT : BForm<16, 0, 0, 12, 0, (ops CRRC:$crS, target:$block),
338                   "blt $crS, $block", BrB>;
339   def BLE : BForm<16, 0, 0, 4,  1, (ops CRRC:$crS, target:$block),
340                   "ble $crS, $block", BrB>;
341   def BEQ : BForm<16, 0, 0, 12, 2, (ops CRRC:$crS, target:$block),
342                   "beq $crS, $block", BrB>;
343   def BGE : BForm<16, 0, 0, 4,  0, (ops CRRC:$crS, target:$block),
344                   "bge $crS, $block", BrB>;
345   def BGT : BForm<16, 0, 0, 12, 1, (ops CRRC:$crS, target:$block),
346                   "bgt $crS, $block", BrB>;
347   def BNE : BForm<16, 0, 0, 4,  2, (ops CRRC:$crS, target:$block),
348                   "bne $crS, $block", BrB>;
349   def BUN : BForm<16, 0, 0, 12, 3, (ops CRRC:$crS, target:$block),
350                   "bun $crS, $block", BrB>;
351   def BNU : BForm<16, 0, 0, 4,  3, (ops CRRC:$crS, target:$block),
352                   "bnu $crS, $block", BrB>;
353 }
354
355 let isCall = 1, noResults = 1, PPC970_Unit = 7, 
356   // All calls clobber the non-callee saved registers...
357   Defs = [R0,R2,R3,R4,R5,R6,R7,R8,R9,R10,R11,R12,
358           F0,F1,F2,F3,F4,F5,F6,F7,F8,F9,F10,F11,F12,F13,
359           V0,V1,V2,V3,V4,V5,V6,V7,V8,V9,V10,V11,V12,V13,V14,V15,V16,V17,V18,V19,
360           LR,CTR,
361           CR0,CR1,CR5,CR6,CR7] in {
362   // Convenient aliases for call instructions
363   def BL  : IForm<18, 0, 1, (ops calltarget:$func, variable_ops), 
364                             "bl $func", BrB, []>;  // See Pat patterns below.
365   def BLA : IForm<18, 1, 1, (ops aaddr:$func, variable_ops),
366                             "bla $func", BrB, [(PPCcall (i32 imm:$func))]>;
367   def BCTRL : XLForm_2_ext<19, 528, 20, 0, 1, (ops variable_ops), "bctrl", BrB,
368                            [(PPCbctrl)]>;
369 }
370
371 // DCB* instructions.
372 def DCBZ : DCB_Form<1014, 0, (ops memrr:$dst),
373                     "dcbz $dst", LdStDCBF, [(int_ppc_dcbz xoaddr:$dst)]>,
374                     PPC970_DGroup_Single;
375 def DCBZL : DCB_Form<1014, 1, (ops memrr:$dst),
376                      "dcbzl $dst", LdStDCBF, [(int_ppc_dcbzl xoaddr:$dst)]>,
377                      PPC970_DGroup_Single;
378                        
379 // D-Form instructions.  Most instructions that perform an operation on a
380 // register and an immediate are of this type.
381 //
382 let isLoad = 1, PPC970_Unit = 2 in {
383 def LBZ : DForm_1<34, (ops GPRC:$rD, memri:$src),
384                   "lbz $rD, $src", LdStGeneral,
385                   [(set GPRC:$rD, (zextloadi8 iaddr:$src))]>;
386 def LHA : DForm_1<42, (ops GPRC:$rD, memri:$src),
387                   "lha $rD, $src", LdStLHA,
388                   [(set GPRC:$rD, (sextloadi16 iaddr:$src))]>,
389                   PPC970_DGroup_Cracked;
390 def LHZ : DForm_1<40, (ops GPRC:$rD, memri:$src),
391                   "lhz $rD, $src", LdStGeneral,
392                   [(set GPRC:$rD, (zextloadi16 iaddr:$src))]>;
393 def LWZ : DForm_1<32, (ops GPRC:$rD, memri:$src),
394                   "lwz $rD, $src", LdStGeneral,
395                   [(set GPRC:$rD, (load iaddr:$src))]>;
396 def LWZU : DForm_1<35, (ops GPRC:$rD, s16imm:$disp, GPRC:$rA),
397                    "lwzu $rD, $disp($rA)", LdStGeneral,
398                    []>;
399 }
400 let PPC970_Unit = 1 in {  // FXU Operations.
401 def ADDI   : DForm_2<14, (ops GPRC:$rD, GPRC:$rA, s16imm:$imm),
402                      "addi $rD, $rA, $imm", IntGeneral,
403                      [(set GPRC:$rD, (add GPRC:$rA, immSExt16:$imm))]>;
404 def ADDIC  : DForm_2<12, (ops GPRC:$rD, GPRC:$rA, s16imm:$imm),
405                      "addic $rD, $rA, $imm", IntGeneral,
406                      [(set GPRC:$rD, (addc GPRC:$rA, immSExt16:$imm))]>,
407                      PPC970_DGroup_Cracked;
408 def ADDICo : DForm_2<13, (ops GPRC:$rD, GPRC:$rA, s16imm:$imm),
409                      "addic. $rD, $rA, $imm", IntGeneral,
410                      []>;
411 def ADDIS  : DForm_2<15, (ops GPRC:$rD, GPRC:$rA, symbolHi:$imm),
412                      "addis $rD, $rA, $imm", IntGeneral,
413                      [(set GPRC:$rD, (add GPRC:$rA, imm16ShiftedSExt:$imm))]>;
414 def LA     : DForm_2<14, (ops GPRC:$rD, GPRC:$rA, symbolLo:$sym),
415                      "la $rD, $sym($rA)", IntGeneral,
416                      [(set GPRC:$rD, (add GPRC:$rA,
417                                           (PPClo tglobaladdr:$sym, 0)))]>;
418 def MULLI  : DForm_2< 7, (ops GPRC:$rD, GPRC:$rA, s16imm:$imm),
419                      "mulli $rD, $rA, $imm", IntMulLI,
420                      [(set GPRC:$rD, (mul GPRC:$rA, immSExt16:$imm))]>;
421 def SUBFIC : DForm_2< 8, (ops GPRC:$rD, GPRC:$rA, s16imm:$imm),
422                      "subfic $rD, $rA, $imm", IntGeneral,
423                      [(set GPRC:$rD, (subc immSExt16:$imm, GPRC:$rA))]>;
424 def LI  : DForm_2_r0<14, (ops GPRC:$rD, symbolLo:$imm),
425                      "li $rD, $imm", IntGeneral,
426                      [(set GPRC:$rD, immSExt16:$imm)]>;
427 def LIS : DForm_2_r0<15, (ops GPRC:$rD, symbolHi:$imm),
428                      "lis $rD, $imm", IntGeneral,
429                      [(set GPRC:$rD, imm16ShiftedSExt:$imm)]>;
430 }
431 let isStore = 1, noResults = 1, PPC970_Unit = 2 in {
432 def STB  : DForm_3<38, (ops GPRC:$rS, memri:$src),
433                    "stb $rS, $src", LdStGeneral,
434                    [(truncstorei8 GPRC:$rS, iaddr:$src)]>;
435 def STH  : DForm_3<44, (ops GPRC:$rS, memri:$src),
436                    "sth $rS, $src", LdStGeneral,
437                    [(truncstorei16 GPRC:$rS, iaddr:$src)]>;
438 def STW  : DForm_3<36, (ops GPRC:$rS, memri:$src),
439                    "stw $rS, $src", LdStGeneral,
440                    [(store GPRC:$rS, iaddr:$src)]>;
441 def STWU : DForm_3<37, (ops GPRC:$rS, s16imm:$disp, GPRC:$rA),
442                    "stwu $rS, $disp($rA)", LdStGeneral,
443                    []>;
444 }
445 let PPC970_Unit = 1 in {  // FXU Operations.
446 def ANDIo : DForm_4<28, (ops GPRC:$dst, GPRC:$src1, u16imm:$src2),
447                     "andi. $dst, $src1, $src2", IntGeneral,
448                     [(set GPRC:$dst, (and GPRC:$src1, immZExt16:$src2))]>,
449                     isDOT;
450 def ANDISo : DForm_4<29, (ops GPRC:$dst, GPRC:$src1, u16imm:$src2),
451                     "andis. $dst, $src1, $src2", IntGeneral,
452                     [(set GPRC:$dst, (and GPRC:$src1,imm16ShiftedZExt:$src2))]>,
453                     isDOT;
454 def ORI   : DForm_4<24, (ops GPRC:$dst, GPRC:$src1, u16imm:$src2),
455                     "ori $dst, $src1, $src2", IntGeneral,
456                     [(set GPRC:$dst, (or GPRC:$src1, immZExt16:$src2))]>;
457 def ORIS  : DForm_4<25, (ops GPRC:$dst, GPRC:$src1, u16imm:$src2),
458                     "oris $dst, $src1, $src2", IntGeneral,
459                     [(set GPRC:$dst, (or GPRC:$src1, imm16ShiftedZExt:$src2))]>;
460 def XORI  : DForm_4<26, (ops GPRC:$dst, GPRC:$src1, u16imm:$src2),
461                     "xori $dst, $src1, $src2", IntGeneral,
462                     [(set GPRC:$dst, (xor GPRC:$src1, immZExt16:$src2))]>;
463 def XORIS : DForm_4<27, (ops GPRC:$dst, GPRC:$src1, u16imm:$src2),
464                     "xoris $dst, $src1, $src2", IntGeneral,
465                     [(set GPRC:$dst, (xor GPRC:$src1,imm16ShiftedZExt:$src2))]>;
466 def NOP   : DForm_4_zero<24, (ops), "nop", IntGeneral,
467                          []>;
468 def CMPWI : DForm_5_ext<11, (ops CRRC:$crD, GPRC:$rA, s16imm:$imm),
469                         "cmpwi $crD, $rA, $imm", IntCompare>;
470 def CMPLWI : DForm_6_ext<10, (ops CRRC:$dst, GPRC:$src1, u16imm:$src2),
471                          "cmplwi $dst, $src1, $src2", IntCompare>;
472 }
473 let isLoad = 1, PPC970_Unit = 2 in {
474 def LFS : DForm_8<48, (ops F4RC:$rD, memri:$src),
475                   "lfs $rD, $src", LdStLFDU,
476                   [(set F4RC:$rD, (load iaddr:$src))]>;
477 def LFD : DForm_8<50, (ops F8RC:$rD, memri:$src),
478                   "lfd $rD, $src", LdStLFD,
479                   [(set F8RC:$rD, (load iaddr:$src))]>;
480 }
481 let isStore = 1, noResults = 1, PPC970_Unit = 2 in {
482 def STFS : DForm_9<52, (ops F4RC:$rS, memri:$dst),
483                    "stfs $rS, $dst", LdStUX,
484                    [(store F4RC:$rS, iaddr:$dst)]>;
485 def STFD : DForm_9<54, (ops F8RC:$rS, memri:$dst),
486                    "stfd $rS, $dst", LdStUX,
487                    [(store F8RC:$rS, iaddr:$dst)]>;
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, (zextloadi8 xaddr:$src))]>;
497 def LHAX : XForm_1<31, 343, (ops GPRC:$rD, memrr:$src),
498                    "lhax $rD, $src", LdStLHA,
499                    [(set GPRC:$rD, (sextloadi16 xaddr:$src))]>,
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, (zextloadi16 xaddr:$src))]>;
504 def LWZX : XForm_1<31,  23, (ops GPRC:$rD, memrr:$src),
505                    "lwzx $rD, $src", LdStGeneral,
506                    [(set GPRC:$rD, (load xaddr:$src))]>;
507                    
508                    
509 def LHBRX : XForm_1<31, 790, (ops GPRC:$rD, memrr:$src),
510                    "lhbrx $rD, $src", LdStGeneral,
511                    [(set GPRC:$rD, (PPClbrx xoaddr:$src, srcvalue:$sv, i16))]>;
512 def LWBRX : XForm_1<31,  534, (ops GPRC:$rD, memrr:$src),
513                    "lwbrx $rD, $src", LdStGeneral,
514                    [(set GPRC:$rD, (PPClbrx xoaddr:$src, srcvalue:$sv, i32))]>;
515
516 }
517
518 let PPC970_Unit = 1 in {  // FXU Operations.
519 def NAND : XForm_6<31, 476, (ops GPRC:$rA, GPRC:$rS, GPRC:$rB),
520                    "nand $rA, $rS, $rB", IntGeneral,
521                    [(set GPRC:$rA, (not (and GPRC:$rS, GPRC:$rB)))]>;
522 def AND  : XForm_6<31,  28, (ops GPRC:$rA, GPRC:$rS, GPRC:$rB),
523                    "and $rA, $rS, $rB", IntGeneral,
524                    [(set GPRC:$rA, (and GPRC:$rS, GPRC:$rB))]>;
525 def ANDC : XForm_6<31,  60, (ops GPRC:$rA, GPRC:$rS, GPRC:$rB),
526                    "andc $rA, $rS, $rB", IntGeneral,
527                    [(set GPRC:$rA, (and GPRC:$rS, (not GPRC:$rB)))]>;
528 def OR   : XForm_6<31, 444, (ops GPRC:$rA, GPRC:$rS, GPRC:$rB),
529                    "or $rA, $rS, $rB", IntGeneral,
530                    [(set GPRC:$rA, (or GPRC:$rS, GPRC:$rB))]>;
531 def NOR  : XForm_6<31, 124, (ops GPRC:$rA, GPRC:$rS, GPRC:$rB),
532                    "nor $rA, $rS, $rB", IntGeneral,
533                    [(set GPRC:$rA, (not (or GPRC:$rS, GPRC:$rB)))]>;
534 def ORC  : XForm_6<31, 412, (ops GPRC:$rA, GPRC:$rS, GPRC:$rB),
535                    "orc $rA, $rS, $rB", IntGeneral,
536                    [(set GPRC:$rA, (or GPRC:$rS, (not GPRC:$rB)))]>;
537 def EQV  : XForm_6<31, 284, (ops GPRC:$rA, GPRC:$rS, GPRC:$rB),
538                    "eqv $rA, $rS, $rB", IntGeneral,
539                    [(set GPRC:$rA, (not (xor GPRC:$rS, GPRC:$rB)))]>;
540 def XOR  : XForm_6<31, 316, (ops GPRC:$rA, GPRC:$rS, GPRC:$rB),
541                    "xor $rA, $rS, $rB", IntGeneral,
542                    [(set GPRC:$rA, (xor GPRC:$rS, GPRC:$rB))]>;
543 def SLW  : XForm_6<31,  24, (ops GPRC:$rA, GPRC:$rS, GPRC:$rB),
544                    "slw $rA, $rS, $rB", IntGeneral,
545                    [(set GPRC:$rA, (PPCshl GPRC:$rS, GPRC:$rB))]>;
546 def SRW  : XForm_6<31, 536, (ops GPRC:$rA, GPRC:$rS, GPRC:$rB),
547                    "srw $rA, $rS, $rB", IntGeneral,
548                    [(set GPRC:$rA, (PPCsrl GPRC:$rS, GPRC:$rB))]>;
549 def SRAW : XForm_6<31, 792, (ops GPRC:$rA, GPRC:$rS, GPRC:$rB),
550                    "sraw $rA, $rS, $rB", IntShift,
551                    [(set GPRC:$rA, (PPCsra GPRC:$rS, GPRC:$rB))]>;
552 }
553 let isStore = 1, noResults = 1, PPC970_Unit = 2 in {
554 def STBX  : XForm_8<31, 215, (ops GPRC:$rS, memrr:$dst),
555                    "stbx $rS, $dst", LdStGeneral,
556                    [(truncstorei8 GPRC:$rS, xaddr:$dst)]>, 
557                    PPC970_DGroup_Cracked;
558 def STHX  : XForm_8<31, 407, (ops GPRC:$rS, memrr:$dst),
559                    "sthx $rS, $dst", LdStGeneral,
560                    [(truncstorei16 GPRC:$rS, xaddr:$dst)]>, 
561                    PPC970_DGroup_Cracked;
562 def STWX  : XForm_8<31, 151, (ops GPRC:$rS, memrr:$dst),
563                    "stwx $rS, $dst", LdStGeneral,
564                    [(store GPRC:$rS, xaddr:$dst)]>,
565                    PPC970_DGroup_Cracked;
566 def STWUX : XForm_8<31, 183, (ops GPRC:$rS, GPRC:$rA, GPRC:$rB),
567                    "stwux $rS, $rA, $rB", LdStGeneral,
568                    []>;
569 def STHBRX: XForm_8<31, 918, (ops GPRC:$rS, memrr:$dst),
570                    "sthbrx $rS, $dst", LdStGeneral,
571                    [(PPCstbrx GPRC:$rS, xoaddr:$dst, srcvalue:$dummy, i16)]>, 
572                    PPC970_DGroup_Cracked;
573 def STWBRX: XForm_8<31, 662, (ops GPRC:$rS, memrr:$dst),
574                    "stwbrx $rS, $dst", LdStGeneral,
575                    [(PPCstbrx GPRC:$rS, xoaddr:$dst, srcvalue:$dummy, i32)]>,
576                    PPC970_DGroup_Cracked;
577 }
578 let PPC970_Unit = 1 in {  // FXU Operations.
579 def SRAWI : XForm_10<31, 824, (ops GPRC:$rA, GPRC:$rS, u5imm:$SH), 
580                      "srawi $rA, $rS, $SH", IntShift,
581                      [(set GPRC:$rA, (sra GPRC:$rS, (i32 imm:$SH)))]>;
582 def CNTLZW : XForm_11<31,  26, (ops GPRC:$rA, GPRC:$rS),
583                       "cntlzw $rA, $rS", IntGeneral,
584                       [(set GPRC:$rA, (ctlz GPRC:$rS))]>;
585 def EXTSB  : XForm_11<31, 954, (ops GPRC:$rA, GPRC:$rS),
586                       "extsb $rA, $rS", IntGeneral,
587                       [(set GPRC:$rA, (sext_inreg GPRC:$rS, i8))]>;
588 def EXTSH  : XForm_11<31, 922, (ops GPRC:$rA, GPRC:$rS),
589                       "extsh $rA, $rS", IntGeneral,
590                       [(set GPRC:$rA, (sext_inreg GPRC:$rS, i16))]>;
591
592 def CMPW   : XForm_16_ext<31, 0, (ops CRRC:$crD, GPRC:$rA, GPRC:$rB),
593                           "cmpw $crD, $rA, $rB", IntCompare>;
594 def CMPLW  : XForm_16_ext<31, 32, (ops CRRC:$crD, GPRC:$rA, GPRC:$rB),
595                           "cmplw $crD, $rA, $rB", IntCompare>;
596 }
597 let PPC970_Unit = 3 in {  // FPU Operations.
598 //def FCMPO  : XForm_17<63, 32, (ops CRRC:$crD, FPRC:$fA, FPRC:$fB),
599 //                      "fcmpo $crD, $fA, $fB", FPCompare>;
600 def FCMPUS : XForm_17<63, 0, (ops CRRC:$crD, F4RC:$fA, F4RC:$fB),
601                       "fcmpu $crD, $fA, $fB", FPCompare>;
602 def FCMPUD : XForm_17<63, 0, (ops CRRC:$crD, F8RC:$fA, F8RC:$fB),
603                       "fcmpu $crD, $fA, $fB", FPCompare>;
604 }
605 let isLoad = 1, PPC970_Unit = 2 in {
606 def LFSX   : XForm_25<31, 535, (ops F4RC:$frD, memrr:$src),
607                       "lfsx $frD, $src", LdStLFDU,
608                       [(set F4RC:$frD, (load xaddr:$src))]>;
609 def LFDX   : XForm_25<31, 599, (ops F8RC:$frD, memrr:$src),
610                       "lfdx $frD, $src", LdStLFDU,
611                       [(set F8RC:$frD, (load xaddr:$src))]>;
612 }
613 let PPC970_Unit = 3 in {  // FPU Operations.
614 def FCTIWZ : XForm_26<63, 15, (ops F8RC:$frD, F8RC:$frB),
615                       "fctiwz $frD, $frB", FPGeneral,
616                       [(set F8RC:$frD, (PPCfctiwz F8RC:$frB))]>;
617 def FRSP   : XForm_26<63, 12, (ops F4RC:$frD, F8RC:$frB),
618                       "frsp $frD, $frB", FPGeneral,
619                       [(set F4RC:$frD, (fround F8RC:$frB))]>;
620 def FSQRT  : XForm_26<63, 22, (ops F8RC:$frD, F8RC:$frB),
621                       "fsqrt $frD, $frB", FPSqrt,
622                       [(set F8RC:$frD, (fsqrt F8RC:$frB))]>;
623 def FSQRTS : XForm_26<59, 22, (ops F4RC:$frD, F4RC:$frB),
624                       "fsqrts $frD, $frB", FPSqrt,
625                       [(set F4RC:$frD, (fsqrt F4RC:$frB))]>;
626 }
627
628 /// FMR is split into 3 versions, one for 4/8 byte FP, and one for extending.
629 ///
630 /// Note that these are defined as pseudo-ops on the PPC970 because they are
631 /// often coalesced away and we don't want the dispatch group builder to think
632 /// that they will fill slots (which could cause the load of a LSU reject to
633 /// sneak into a d-group with a store).
634 def FMRS   : XForm_26<63, 72, (ops F4RC:$frD, F4RC:$frB),
635                       "fmr $frD, $frB", FPGeneral,
636                       []>,  // (set F4RC:$frD, F4RC:$frB)
637                       PPC970_Unit_Pseudo;
638 def FMRD   : XForm_26<63, 72, (ops F8RC:$frD, F8RC:$frB),
639                       "fmr $frD, $frB", FPGeneral,
640                       []>,  // (set F8RC:$frD, F8RC:$frB)
641                       PPC970_Unit_Pseudo;
642 def FMRSD  : XForm_26<63, 72, (ops F8RC:$frD, F4RC:$frB),
643                       "fmr $frD, $frB", FPGeneral,
644                       [(set F8RC:$frD, (fextend F4RC:$frB))]>,
645                       PPC970_Unit_Pseudo;
646
647 let PPC970_Unit = 3 in {  // FPU Operations.
648 // These are artificially split into two different forms, for 4/8 byte FP.
649 def FABSS  : XForm_26<63, 264, (ops F4RC:$frD, F4RC:$frB),
650                       "fabs $frD, $frB", FPGeneral,
651                       [(set F4RC:$frD, (fabs F4RC:$frB))]>;
652 def FABSD  : XForm_26<63, 264, (ops F8RC:$frD, F8RC:$frB),
653                       "fabs $frD, $frB", FPGeneral,
654                       [(set F8RC:$frD, (fabs F8RC:$frB))]>;
655 def FNABSS : XForm_26<63, 136, (ops F4RC:$frD, F4RC:$frB),
656                       "fnabs $frD, $frB", FPGeneral,
657                       [(set F4RC:$frD, (fneg (fabs F4RC:$frB)))]>;
658 def FNABSD : XForm_26<63, 136, (ops F8RC:$frD, F8RC:$frB),
659                       "fnabs $frD, $frB", FPGeneral,
660                       [(set F8RC:$frD, (fneg (fabs F8RC:$frB)))]>;
661 def FNEGS  : XForm_26<63, 40, (ops F4RC:$frD, F4RC:$frB),
662                       "fneg $frD, $frB", FPGeneral,
663                       [(set F4RC:$frD, (fneg F4RC:$frB))]>;
664 def FNEGD  : XForm_26<63, 40, (ops F8RC:$frD, F8RC:$frB),
665                       "fneg $frD, $frB", FPGeneral,
666                       [(set F8RC:$frD, (fneg F8RC:$frB))]>;
667 }
668                       
669 let isStore = 1, noResults = 1, PPC970_Unit = 2 in {
670 def STFIWX: XForm_28<31, 983, (ops F8RC:$frS, memrr:$dst),
671                      "stfiwx $frS, $dst", LdStUX,
672                      [(PPCstfiwx F8RC:$frS, xoaddr:$dst)]>;
673 def STFSX : XForm_28<31, 663, (ops F4RC:$frS, memrr:$dst),
674                      "stfsx $frS, $dst", LdStUX,
675                      [(store F4RC:$frS, xaddr:$dst)]>;
676 def STFDX : XForm_28<31, 727, (ops F8RC:$frS, memrr:$dst),
677                      "stfdx $frS, $dst", LdStUX,
678                      [(store F8RC:$frS, xaddr:$dst)]>;
679 }
680
681 // XL-Form instructions.  condition register logical ops.
682 //
683 def MCRF   : XLForm_3<19, 0, (ops CRRC:$BF, CRRC:$BFA),
684                       "mcrf $BF, $BFA", BrMCR>,
685              PPC970_DGroup_First, PPC970_Unit_CRU;
686
687 // XFX-Form instructions.  Instructions that deal with SPRs.
688 //
689 def MFCTR : XFXForm_1_ext<31, 339, 9, (ops GPRC:$rT), "mfctr $rT", SprMFSPR>,
690             PPC970_DGroup_First, PPC970_Unit_FXU;
691 let Pattern = [(PPCmtctr GPRC:$rS)] in {
692 def MTCTR : XFXForm_7_ext<31, 467, 9, (ops GPRC:$rS), "mtctr $rS", SprMTSPR>,
693             PPC970_DGroup_First, PPC970_Unit_FXU;
694 }
695
696 def MTLR  : XFXForm_7_ext<31, 467, 8, (ops GPRC:$rS), "mtlr $rS", SprMTSPR>,
697             PPC970_DGroup_First, PPC970_Unit_FXU;
698 def MFLR  : XFXForm_1_ext<31, 339, 8, (ops GPRC:$rT), "mflr $rT", SprMFSPR>,
699             PPC970_DGroup_First, PPC970_Unit_FXU;
700
701 // Move to/from VRSAVE: despite being a SPR, the VRSAVE register is renamed like
702 // a GPR on the PPC970.  As such, copies in and out have the same performance
703 // characteristics as an OR instruction.
704 def MTVRSAVE : XFXForm_7_ext<31, 467, 256, (ops GPRC:$rS),
705                              "mtspr 256, $rS", IntGeneral>,
706                PPC970_DGroup_Single, PPC970_Unit_FXU;
707 def MFVRSAVE : XFXForm_1_ext<31, 339, 256, (ops GPRC:$rT),
708                              "mfspr $rT, 256", IntGeneral>,
709                PPC970_DGroup_First, PPC970_Unit_FXU;
710
711 def MTCRF : XFXForm_5<31, 144, (ops crbitm:$FXM, GPRC:$rS),
712                       "mtcrf $FXM, $rS", BrMCRX>,
713             PPC970_MicroCode, PPC970_Unit_CRU;
714 def MFCR  : XFXForm_3<31, 19, (ops GPRC:$rT), "mfcr $rT", SprMFCR>,
715             PPC970_MicroCode, PPC970_Unit_CRU;
716 def MFOCRF: XFXForm_5a<31, 19, (ops GPRC:$rT, crbitm:$FXM),
717                        "mfcr $rT, $FXM", SprMFCR>,
718             PPC970_DGroup_First, PPC970_Unit_CRU;
719
720 let PPC970_Unit = 1 in {  // FXU Operations.
721
722 // XO-Form instructions.  Arithmetic instructions that can set overflow bit
723 //
724 def ADD4  : XOForm_1<31, 266, 0, (ops GPRC:$rT, GPRC:$rA, GPRC:$rB),
725                      "add $rT, $rA, $rB", IntGeneral,
726                      [(set GPRC:$rT, (add GPRC:$rA, GPRC:$rB))]>;
727 def ADDC  : XOForm_1<31, 10, 0, (ops GPRC:$rT, GPRC:$rA, GPRC:$rB),
728                      "addc $rT, $rA, $rB", IntGeneral,
729                      [(set GPRC:$rT, (addc GPRC:$rA, GPRC:$rB))]>,
730                      PPC970_DGroup_Cracked;
731 def ADDE  : XOForm_1<31, 138, 0, (ops GPRC:$rT, GPRC:$rA, GPRC:$rB),
732                      "adde $rT, $rA, $rB", IntGeneral,
733                      [(set GPRC:$rT, (adde GPRC:$rA, GPRC:$rB))]>;
734 def DIVW  : XOForm_1<31, 491, 0, (ops GPRC:$rT, GPRC:$rA, GPRC:$rB),
735                      "divw $rT, $rA, $rB", IntDivW,
736                      [(set GPRC:$rT, (sdiv GPRC:$rA, GPRC:$rB))]>,
737                      PPC970_DGroup_First, PPC970_DGroup_Cracked;
738 def DIVWU : XOForm_1<31, 459, 0, (ops GPRC:$rT, GPRC:$rA, GPRC:$rB),
739                      "divwu $rT, $rA, $rB", IntDivW,
740                      [(set GPRC:$rT, (udiv GPRC:$rA, GPRC:$rB))]>,
741                      PPC970_DGroup_First, PPC970_DGroup_Cracked;
742 def MULHW : XOForm_1<31, 75, 0, (ops GPRC:$rT, GPRC:$rA, GPRC:$rB),
743                      "mulhw $rT, $rA, $rB", IntMulHW,
744                      [(set GPRC:$rT, (mulhs GPRC:$rA, GPRC:$rB))]>;
745 def MULHWU : XOForm_1<31, 11, 0, (ops GPRC:$rT, GPRC:$rA, GPRC:$rB),
746                      "mulhwu $rT, $rA, $rB", IntMulHWU,
747                      [(set GPRC:$rT, (mulhu GPRC:$rA, GPRC:$rB))]>;
748 def MULLW : XOForm_1<31, 235, 0, (ops GPRC:$rT, GPRC:$rA, GPRC:$rB),
749                      "mullw $rT, $rA, $rB", IntMulHW,
750                      [(set GPRC:$rT, (mul GPRC:$rA, GPRC:$rB))]>;
751 def SUBF  : XOForm_1<31, 40, 0, (ops GPRC:$rT, GPRC:$rA, GPRC:$rB),
752                      "subf $rT, $rA, $rB", IntGeneral,
753                      [(set GPRC:$rT, (sub GPRC:$rB, GPRC:$rA))]>;
754 def SUBFC : XOForm_1<31, 8, 0, (ops GPRC:$rT, GPRC:$rA, GPRC:$rB),
755                      "subfc $rT, $rA, $rB", IntGeneral,
756                      [(set GPRC:$rT, (subc GPRC:$rB, GPRC:$rA))]>,
757                      PPC970_DGroup_Cracked;
758 def SUBFE : XOForm_1<31, 136, 0, (ops GPRC:$rT, GPRC:$rA, GPRC:$rB),
759                      "subfe $rT, $rA, $rB", IntGeneral,
760                      [(set GPRC:$rT, (sube GPRC:$rB, GPRC:$rA))]>;
761 def ADDME  : XOForm_3<31, 234, 0, (ops GPRC:$rT, GPRC:$rA),
762                       "addme $rT, $rA", IntGeneral,
763                       [(set GPRC:$rT, (adde GPRC:$rA, immAllOnes))]>;
764 def ADDZE  : XOForm_3<31, 202, 0, (ops GPRC:$rT, GPRC:$rA),
765                       "addze $rT, $rA", IntGeneral,
766                       [(set GPRC:$rT, (adde GPRC:$rA, 0))]>;
767 def NEG    : XOForm_3<31, 104, 0, (ops GPRC:$rT, GPRC:$rA),
768                       "neg $rT, $rA", IntGeneral,
769                       [(set GPRC:$rT, (ineg GPRC:$rA))]>;
770 def SUBFME : XOForm_3<31, 232, 0, (ops GPRC:$rT, GPRC:$rA),
771                       "subfme $rT, $rA", IntGeneral,
772                       [(set GPRC:$rT, (sube immAllOnes, GPRC:$rA))]>;
773 def SUBFZE : XOForm_3<31, 200, 0, (ops GPRC:$rT, GPRC:$rA),
774                       "subfze $rT, $rA", IntGeneral,
775                       [(set GPRC:$rT, (sube 0, GPRC:$rA))]>;
776 }
777
778 // A-Form instructions.  Most of the instructions executed in the FPU are of
779 // this type.
780 //
781 let PPC970_Unit = 3 in {  // FPU Operations.
782 def FMADD : AForm_1<63, 29, 
783                     (ops F8RC:$FRT, F8RC:$FRA, F8RC:$FRC, F8RC:$FRB),
784                     "fmadd $FRT, $FRA, $FRC, $FRB", FPFused,
785                     [(set F8RC:$FRT, (fadd (fmul F8RC:$FRA, F8RC:$FRC),
786                                            F8RC:$FRB))]>,
787                     Requires<[FPContractions]>;
788 def FMADDS : AForm_1<59, 29,
789                     (ops F4RC:$FRT, F4RC:$FRA, F4RC:$FRC, F4RC:$FRB),
790                     "fmadds $FRT, $FRA, $FRC, $FRB", FPGeneral,
791                     [(set F4RC:$FRT, (fadd (fmul F4RC:$FRA, F4RC:$FRC),
792                                            F4RC:$FRB))]>,
793                     Requires<[FPContractions]>;
794 def FMSUB : AForm_1<63, 28,
795                     (ops F8RC:$FRT, F8RC:$FRA, F8RC:$FRC, F8RC:$FRB),
796                     "fmsub $FRT, $FRA, $FRC, $FRB", FPFused,
797                     [(set F8RC:$FRT, (fsub (fmul F8RC:$FRA, F8RC:$FRC),
798                                            F8RC:$FRB))]>,
799                     Requires<[FPContractions]>;
800 def FMSUBS : AForm_1<59, 28,
801                     (ops F4RC:$FRT, F4RC:$FRA, F4RC:$FRC, F4RC:$FRB),
802                     "fmsubs $FRT, $FRA, $FRC, $FRB", FPGeneral,
803                     [(set F4RC:$FRT, (fsub (fmul F4RC:$FRA, F4RC:$FRC),
804                                            F4RC:$FRB))]>,
805                     Requires<[FPContractions]>;
806 def FNMADD : AForm_1<63, 31,
807                     (ops F8RC:$FRT, F8RC:$FRA, F8RC:$FRC, F8RC:$FRB),
808                     "fnmadd $FRT, $FRA, $FRC, $FRB", FPFused,
809                     [(set F8RC:$FRT, (fneg (fadd (fmul F8RC:$FRA, F8RC:$FRC),
810                                                  F8RC:$FRB)))]>,
811                     Requires<[FPContractions]>;
812 def FNMADDS : AForm_1<59, 31,
813                     (ops F4RC:$FRT, F4RC:$FRA, F4RC:$FRC, F4RC:$FRB),
814                     "fnmadds $FRT, $FRA, $FRC, $FRB", FPGeneral,
815                     [(set F4RC:$FRT, (fneg (fadd (fmul F4RC:$FRA, F4RC:$FRC),
816                                                  F4RC:$FRB)))]>,
817                     Requires<[FPContractions]>;
818 def FNMSUB : AForm_1<63, 30,
819                     (ops F8RC:$FRT, F8RC:$FRA, F8RC:$FRC, F8RC:$FRB),
820                     "fnmsub $FRT, $FRA, $FRC, $FRB", FPFused,
821                     [(set F8RC:$FRT, (fneg (fsub (fmul F8RC:$FRA, F8RC:$FRC),
822                                                  F8RC:$FRB)))]>,
823                     Requires<[FPContractions]>;
824 def FNMSUBS : AForm_1<59, 30,
825                     (ops F4RC:$FRT, F4RC:$FRA, F4RC:$FRC, F4RC:$FRB),
826                     "fnmsubs $FRT, $FRA, $FRC, $FRB", FPGeneral,
827                     [(set F4RC:$FRT, (fneg (fsub (fmul F4RC:$FRA, F4RC:$FRC),
828                                                  F4RC:$FRB)))]>,
829                     Requires<[FPContractions]>;
830 // FSEL is artificially split into 4 and 8-byte forms for the result.  To avoid
831 // having 4 of these, force the comparison to always be an 8-byte double (code
832 // should use an FMRSD if the input comparison value really wants to be a float)
833 // and 4/8 byte forms for the result and operand type..
834 def FSELD : AForm_1<63, 23,
835                     (ops F8RC:$FRT, F8RC:$FRA, F8RC:$FRC, F8RC:$FRB),
836                     "fsel $FRT, $FRA, $FRC, $FRB", FPGeneral,
837                     [(set F8RC:$FRT, (PPCfsel F8RC:$FRA,F8RC:$FRC,F8RC:$FRB))]>;
838 def FSELS : AForm_1<63, 23,
839                      (ops F4RC:$FRT, F8RC:$FRA, F4RC:$FRC, F4RC:$FRB),
840                      "fsel $FRT, $FRA, $FRC, $FRB", FPGeneral,
841                     [(set F4RC:$FRT, (PPCfsel F8RC:$FRA,F4RC:$FRC,F4RC:$FRB))]>;
842 def FADD  : AForm_2<63, 21,
843                     (ops F8RC:$FRT, F8RC:$FRA, F8RC:$FRB),
844                     "fadd $FRT, $FRA, $FRB", FPGeneral,
845                     [(set F8RC:$FRT, (fadd F8RC:$FRA, F8RC:$FRB))]>;
846 def FADDS : AForm_2<59, 21,
847                     (ops F4RC:$FRT, F4RC:$FRA, F4RC:$FRB),
848                     "fadds $FRT, $FRA, $FRB", FPGeneral,
849                     [(set F4RC:$FRT, (fadd F4RC:$FRA, F4RC:$FRB))]>;
850 def FDIV  : AForm_2<63, 18,
851                     (ops F8RC:$FRT, F8RC:$FRA, F8RC:$FRB),
852                     "fdiv $FRT, $FRA, $FRB", FPDivD,
853                     [(set F8RC:$FRT, (fdiv F8RC:$FRA, F8RC:$FRB))]>;
854 def FDIVS : AForm_2<59, 18,
855                     (ops F4RC:$FRT, F4RC:$FRA, F4RC:$FRB),
856                     "fdivs $FRT, $FRA, $FRB", FPDivS,
857                     [(set F4RC:$FRT, (fdiv F4RC:$FRA, F4RC:$FRB))]>;
858 def FMUL  : AForm_3<63, 25,
859                     (ops F8RC:$FRT, F8RC:$FRA, F8RC:$FRB),
860                     "fmul $FRT, $FRA, $FRB", FPFused,
861                     [(set F8RC:$FRT, (fmul F8RC:$FRA, F8RC:$FRB))]>;
862 def FMULS : AForm_3<59, 25,
863                     (ops F4RC:$FRT, F4RC:$FRA, F4RC:$FRB),
864                     "fmuls $FRT, $FRA, $FRB", FPGeneral,
865                     [(set F4RC:$FRT, (fmul F4RC:$FRA, F4RC:$FRB))]>;
866 def FSUB  : AForm_2<63, 20,
867                     (ops F8RC:$FRT, F8RC:$FRA, F8RC:$FRB),
868                     "fsub $FRT, $FRA, $FRB", FPGeneral,
869                     [(set F8RC:$FRT, (fsub F8RC:$FRA, F8RC:$FRB))]>;
870 def FSUBS : AForm_2<59, 20,
871                     (ops F4RC:$FRT, F4RC:$FRA, F4RC:$FRB),
872                     "fsubs $FRT, $FRA, $FRB", FPGeneral,
873                     [(set F4RC:$FRT, (fsub F4RC:$FRA, F4RC:$FRB))]>;
874 }
875
876 let PPC970_Unit = 1 in {  // FXU Operations.
877 // M-Form instructions.  rotate and mask instructions.
878 //
879 let isTwoAddress = 1, isCommutable = 1 in {
880 // RLWIMI can be commuted if the rotate amount is zero.
881 def RLWIMI : MForm_2<20,
882                      (ops GPRC:$rA, GPRC:$rSi, GPRC:$rS, u5imm:$SH, u5imm:$MB, 
883                       u5imm:$ME), "rlwimi $rA, $rS, $SH, $MB, $ME", IntRotate,
884                       []>, PPC970_DGroup_Cracked;
885 }
886 def RLWINM : MForm_2<21,
887                      (ops GPRC:$rA, GPRC:$rS, u5imm:$SH, u5imm:$MB, u5imm:$ME),
888                      "rlwinm $rA, $rS, $SH, $MB, $ME", IntGeneral,
889                      []>;
890 def RLWINMo : MForm_2<21,
891                      (ops GPRC:$rA, GPRC:$rS, u5imm:$SH, u5imm:$MB, u5imm:$ME),
892                      "rlwinm. $rA, $rS, $SH, $MB, $ME", IntGeneral,
893                      []>, isDOT, PPC970_DGroup_Cracked;
894 def RLWNM  : MForm_2<23,
895                      (ops GPRC:$rA, GPRC:$rS, GPRC:$rB, u5imm:$MB, u5imm:$ME),
896                      "rlwnm $rA, $rS, $rB, $MB, $ME", IntGeneral,
897                      []>;
898 }
899
900
901 //===----------------------------------------------------------------------===//
902 // DWARF Pseudo Instructions
903 //
904
905 def DWARF_LOC        : Pseudo<(ops i32imm:$line, i32imm:$col, i32imm:$file),
906                               "${:comment} .loc $file, $line, $col",
907                       [(dwarf_loc (i32 imm:$line), (i32 imm:$col),
908                                   (i32 imm:$file))]>;
909
910 def DWARF_LABEL      : Pseudo<(ops i32imm:$id),
911                               "\n${:private}debug_loc$id:",
912                       [(dwarf_label (i32 imm:$id))]>;
913
914 //===----------------------------------------------------------------------===//
915 // PowerPC Instruction Patterns
916 //
917
918 // Arbitrary immediate support.  Implement in terms of LIS/ORI.
919 def : Pat<(i32 imm:$imm),
920           (ORI (LIS (HI16 imm:$imm)), (LO16 imm:$imm))>;
921
922 // Implement the 'not' operation with the NOR instruction.
923 def NOT : Pat<(not GPRC:$in),
924               (NOR GPRC:$in, GPRC:$in)>;
925
926 // ADD an arbitrary immediate.
927 def : Pat<(add GPRC:$in, imm:$imm),
928           (ADDIS (ADDI GPRC:$in, (LO16 imm:$imm)), (HA16 imm:$imm))>;
929 // OR an arbitrary immediate.
930 def : Pat<(or GPRC:$in, imm:$imm),
931           (ORIS (ORI GPRC:$in, (LO16 imm:$imm)), (HI16 imm:$imm))>;
932 // XOR an arbitrary immediate.
933 def : Pat<(xor GPRC:$in, imm:$imm),
934           (XORIS (XORI GPRC:$in, (LO16 imm:$imm)), (HI16 imm:$imm))>;
935 // SUBFIC
936 def : Pat<(sub  immSExt16:$imm, GPRC:$in),
937           (SUBFIC GPRC:$in, imm:$imm)>;
938
939 // Return void support.
940 def : Pat<(ret), (BLR)>;
941
942 // SHL/SRL
943 def : Pat<(shl GPRC:$in, (i32 imm:$imm)),
944           (RLWINM GPRC:$in, imm:$imm, 0, (SHL32 imm:$imm))>;
945 def : Pat<(srl GPRC:$in, (i32 imm:$imm)),
946           (RLWINM GPRC:$in, (SRL32 imm:$imm), imm:$imm, 31)>;
947
948 // ROTL
949 def : Pat<(rotl GPRC:$in, GPRC:$sh),
950           (RLWNM GPRC:$in, GPRC:$sh, 0, 31)>;
951 def : Pat<(rotl GPRC:$in, (i32 imm:$imm)),
952           (RLWINM GPRC:$in, imm:$imm, 0, 31)>;
953
954 // RLWNM
955 def : Pat<(and (rotl GPRC:$in, GPRC:$sh), maskimm32:$imm),
956           (RLWNM GPRC:$in, GPRC:$sh, (MB maskimm32:$imm), (ME maskimm32:$imm))>;
957
958 // Calls
959 def : Pat<(PPCcall tglobaladdr:$dst),
960           (BL tglobaladdr:$dst)>;
961 def : Pat<(PPCcall texternalsym:$dst),
962           (BL texternalsym:$dst)>;
963
964 // Hi and Lo for Darwin Global Addresses.
965 def : Pat<(PPChi tglobaladdr:$in, 0), (LIS tglobaladdr:$in)>;
966 def : Pat<(PPClo tglobaladdr:$in, 0), (LI tglobaladdr:$in)>;
967 def : Pat<(PPChi tconstpool:$in, 0), (LIS tconstpool:$in)>;
968 def : Pat<(PPClo tconstpool:$in, 0), (LI tconstpool:$in)>;
969 def : Pat<(PPChi tjumptable:$in, 0), (LIS tjumptable:$in)>;
970 def : Pat<(PPClo tjumptable:$in, 0), (LI tjumptable:$in)>;
971 def : Pat<(add GPRC:$in, (PPChi tglobaladdr:$g, 0)),
972           (ADDIS GPRC:$in, tglobaladdr:$g)>;
973 def : Pat<(add GPRC:$in, (PPChi tconstpool:$g, 0)),
974           (ADDIS GPRC:$in, tconstpool:$g)>;
975 def : Pat<(add GPRC:$in, (PPChi tjumptable:$g, 0)),
976           (ADDIS GPRC:$in, tjumptable:$g)>;
977
978 // Fused negative multiply subtract, alternate pattern
979 def : Pat<(fsub F8RC:$B, (fmul F8RC:$A, F8RC:$C)),
980           (FNMSUB F8RC:$A, F8RC:$C, F8RC:$B)>,
981           Requires<[FPContractions]>;
982 def : Pat<(fsub F4RC:$B, (fmul F4RC:$A, F4RC:$C)),
983           (FNMSUBS F4RC:$A, F4RC:$C, F4RC:$B)>,
984           Requires<[FPContractions]>;
985
986 // Standard shifts.  These are represented separately from the real shifts above
987 // so that we can distinguish between shifts that allow 5-bit and 6-bit shift
988 // amounts.
989 def : Pat<(sra GPRC:$rS, GPRC:$rB),
990           (SRAW GPRC:$rS, GPRC:$rB)>;
991 def : Pat<(srl GPRC:$rS, GPRC:$rB),
992           (SRW GPRC:$rS, GPRC:$rB)>;
993 def : Pat<(shl GPRC:$rS, GPRC:$rB),
994           (SLW GPRC:$rS, GPRC:$rB)>;
995
996 def : Pat<(zextloadi1 iaddr:$src),
997           (LBZ iaddr:$src)>;
998 def : Pat<(zextloadi1 xaddr:$src),
999           (LBZX xaddr:$src)>;
1000 def : Pat<(extloadi1 iaddr:$src),
1001           (LBZ iaddr:$src)>;
1002 def : Pat<(extloadi1 xaddr:$src),
1003           (LBZX xaddr:$src)>;
1004 def : Pat<(extloadi8 iaddr:$src),
1005           (LBZ iaddr:$src)>;
1006 def : Pat<(extloadi8 xaddr:$src),
1007           (LBZX xaddr:$src)>;
1008 def : Pat<(extloadi16 iaddr:$src),
1009           (LHZ iaddr:$src)>;
1010 def : Pat<(extloadi16 xaddr:$src),
1011           (LHZX xaddr:$src)>;
1012 def : Pat<(extloadf32 iaddr:$src),
1013           (FMRSD (LFS iaddr:$src))>;
1014 def : Pat<(extloadf32 xaddr:$src),
1015           (FMRSD (LFSX xaddr:$src))>;
1016
1017 include "PPCInstrAltivec.td"
1018 include "PPCInstr64Bit.td"