remove some isStore flags that are now inferred automatically.
[oota-llvm.git] / lib / Target / PowerPC / PPCInstr64Bit.td
1 //===- PPCInstr64Bit.td - The PowerPC 64-bit Support -------*- tablegen -*-===//
2 // 
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 // 
8 //===----------------------------------------------------------------------===//
9 //
10 // This file describes the PowerPC 64-bit instructions.  These patterns are used
11 // both when in ppc64 mode and when in "use 64-bit extensions in 32-bit" mode.
12 //
13 //===----------------------------------------------------------------------===//
14
15 //===----------------------------------------------------------------------===//
16 // 64-bit operands.
17 //
18 def s16imm64 : Operand<i64> {
19   let PrintMethod = "printS16ImmOperand";
20 }
21 def u16imm64 : Operand<i64> {
22   let PrintMethod = "printU16ImmOperand";
23 }
24 def symbolHi64 : Operand<i64> {
25   let PrintMethod = "printSymbolHi";
26 }
27 def symbolLo64 : Operand<i64> {
28   let PrintMethod = "printSymbolLo";
29 }
30
31 //===----------------------------------------------------------------------===//
32 // 64-bit transformation functions.
33 //
34
35 def SHL64 : SDNodeXForm<imm, [{
36   // Transformation function: 63 - imm
37   return getI32Imm(63 - N->getValue());
38 }]>;
39
40 def SRL64 : SDNodeXForm<imm, [{
41   // Transformation function: 64 - imm
42   return N->getValue() ? getI32Imm(64 - N->getValue()) : getI32Imm(0);
43 }]>;
44
45 def HI32_48 : SDNodeXForm<imm, [{
46   // Transformation function: shift the immediate value down into the low bits.
47   return getI32Imm((unsigned short)(N->getValue() >> 32));
48 }]>;
49
50 def HI48_64 : SDNodeXForm<imm, [{
51   // Transformation function: shift the immediate value down into the low bits.
52   return getI32Imm((unsigned short)(N->getValue() >> 48));
53 }]>;
54
55
56 //===----------------------------------------------------------------------===//
57 // Pseudo instructions.
58 //
59
60 def IMPLICIT_DEF_G8RC : Pseudo<(outs G8RC:$rD), (ins),"; IMPLICIT_DEF_G8RC $rD",
61                               [(set G8RC:$rD, (undef))]>;
62
63
64 //===----------------------------------------------------------------------===//
65 // Calls.
66 //
67
68 let Defs = [LR8] in
69   def MovePCtoLR8 : Pseudo<(outs), (ins piclabel:$label), "bl $label", []>,
70                     PPC970_Unit_BRU;
71
72 // Macho ABI Calls.
73 let isCall = 1, PPC970_Unit = 7, 
74   // All calls clobber the PPC64 non-callee saved registers.
75   Defs = [X0,X2,X3,X4,X5,X6,X7,X8,X9,X10,X11,X12,
76           F0,F1,F2,F3,F4,F5,F6,F7,F8,F9,F10,F11,F12,F13,
77           V0,V1,V2,V3,V4,V5,V6,V7,V8,V9,V10,V11,V12,V13,V14,V15,V16,V17,V18,V19,
78           LR8,CTR8,
79           CR0,CR1,CR5,CR6,CR7] in {
80   // Convenient aliases for call instructions
81   def BL8_Macho  : IForm<18, 0, 1,
82                          (outs), (ins calltarget:$func, variable_ops), 
83                          "bl $func", BrB, []>;  // See Pat patterns below.
84   def BLA8_Macho : IForm<18, 1, 1,
85                          (outs), (ins aaddr:$func, variable_ops),
86                          "bla $func", BrB, [(PPCcall_Macho (i64 imm:$func))]>;
87   def BCTRL8_Macho : XLForm_2_ext<19, 528, 20, 0, 1, 
88                                  (outs), (ins variable_ops),
89                                  "bctrl", BrB,
90                                  [(PPCbctrl_Macho)]>, Requires<[In64BitMode]>;
91 }
92
93 // ELF 64 ABI Calls = Macho ABI Calls
94 // Used to define BL8_ELF and BLA8_ELF
95 let isCall = 1, PPC970_Unit = 7, 
96   // All calls clobber the PPC64 non-callee saved registers.
97   Defs = [X0,X2,X3,X4,X5,X6,X7,X8,X9,X10,X11,X12,
98           F0,F1,F2,F3,F4,F5,F6,F7,F8,F9,F10,F11,F12,F13,
99           V0,V1,V2,V3,V4,V5,V6,V7,V8,V9,V10,V11,V12,V13,V14,V15,V16,V17,V18,V19,
100           LR8,CTR8,
101           CR0,CR1,CR5,CR6,CR7] in {
102   // Convenient aliases for call instructions
103   def BL8_ELF  : IForm<18, 0, 1,
104                        (outs), (ins calltarget:$func, variable_ops), 
105                        "bl $func", BrB, []>;  // See Pat patterns below.                            
106   def BLA8_ELF : IForm<18, 1, 1,
107                        (outs), (ins aaddr:$func, variable_ops),
108                        "bla $func", BrB, [(PPCcall_ELF (i64 imm:$func))]>;
109   def BCTRL8_ELF : XLForm_2_ext<19, 528, 20, 0, 1,
110                                (outs), (ins variable_ops),
111                                "bctrl", BrB,
112                                [(PPCbctrl_ELF)]>, Requires<[In64BitMode]>;
113 }
114
115
116 // Calls
117 def : Pat<(PPCcall_Macho (i64 tglobaladdr:$dst)),
118           (BL8_Macho tglobaladdr:$dst)>;
119 def : Pat<(PPCcall_Macho (i64 texternalsym:$dst)),
120           (BL8_Macho texternalsym:$dst)>;
121
122 def : Pat<(PPCcall_ELF (i64 tglobaladdr:$dst)),
123           (BL8_ELF tglobaladdr:$dst)>;
124 def : Pat<(PPCcall_ELF (i64 texternalsym:$dst)),
125           (BL8_ELF texternalsym:$dst)>;
126
127 //===----------------------------------------------------------------------===//
128 // 64-bit SPR manipulation instrs.
129
130 def MFCTR8 : XFXForm_1_ext<31, 339, 9, (outs G8RC:$rT), (ins),
131                            "mfctr $rT", SprMFSPR>,
132              PPC970_DGroup_First, PPC970_Unit_FXU;
133 let Pattern = [(PPCmtctr G8RC:$rS)] in {
134 def MTCTR8 : XFXForm_7_ext<31, 467, 9, (outs), (ins G8RC:$rS),
135                            "mtctr $rS", SprMTSPR>,
136              PPC970_DGroup_First, PPC970_Unit_FXU;
137 }
138
139 let Defs = [X1], Uses = [X1] in
140 def DYNALLOC8 : Pseudo<(outs G8RC:$result), (ins G8RC:$negsize, memri:$fpsi),
141                        "${:comment} DYNALLOC8 $result, $negsize, $fpsi",
142                        [(set G8RC:$result,
143                              (PPCdynalloc G8RC:$negsize, iaddr:$fpsi))]>;
144
145 def MTLR8  : XFXForm_7_ext<31, 467, 8, (outs), (ins G8RC:$rS),
146                            "mtlr $rS", SprMTSPR>,
147              PPC970_DGroup_First, PPC970_Unit_FXU;
148 def MFLR8  : XFXForm_1_ext<31, 339, 8, (outs G8RC:$rT), (ins),
149                            "mflr $rT", SprMFSPR>,
150              PPC970_DGroup_First, PPC970_Unit_FXU;
151
152
153 //===----------------------------------------------------------------------===//
154 // Fixed point instructions.
155 //
156
157 let PPC970_Unit = 1 in {  // FXU Operations.
158
159 // Copies, extends, truncates.
160 def OR4To8  : XForm_6<31, 444, (outs G8RC:$rA), (ins GPRC:$rS, GPRC:$rB),
161                    "or $rA, $rS, $rB", IntGeneral,
162                    []>;
163 def OR8To4  : XForm_6<31, 444, (outs GPRC:$rA), (ins G8RC:$rS, G8RC:$rB),
164                    "or $rA, $rS, $rB", IntGeneral,
165                    []>;
166
167 def LI8  : DForm_2_r0<14, (outs G8RC:$rD), (ins symbolLo64:$imm),
168                       "li $rD, $imm", IntGeneral,
169                       [(set G8RC:$rD, immSExt16:$imm)]>;
170 def LIS8 : DForm_2_r0<15, (outs G8RC:$rD), (ins symbolHi64:$imm),
171                       "lis $rD, $imm", IntGeneral,
172                       [(set G8RC:$rD, imm16ShiftedSExt:$imm)]>;
173
174 // Logical ops.
175 def NAND8: XForm_6<31, 476, (outs G8RC:$rA), (ins G8RC:$rS, G8RC:$rB),
176                    "nand $rA, $rS, $rB", IntGeneral,
177                    [(set G8RC:$rA, (not (and G8RC:$rS, G8RC:$rB)))]>;
178 def AND8 : XForm_6<31,  28, (outs G8RC:$rA), (ins G8RC:$rS, G8RC:$rB),
179                    "and $rA, $rS, $rB", IntGeneral,
180                    [(set G8RC:$rA, (and G8RC:$rS, G8RC:$rB))]>;
181 def ANDC8: XForm_6<31,  60, (outs G8RC:$rA), (ins G8RC:$rS, G8RC:$rB),
182                    "andc $rA, $rS, $rB", IntGeneral,
183                    [(set G8RC:$rA, (and G8RC:$rS, (not G8RC:$rB)))]>;
184 def OR8  : XForm_6<31, 444, (outs G8RC:$rA), (ins G8RC:$rS, G8RC:$rB),
185                    "or $rA, $rS, $rB", IntGeneral,
186                    [(set G8RC:$rA, (or G8RC:$rS, G8RC:$rB))]>;
187 def NOR8 : XForm_6<31, 124, (outs G8RC:$rA), (ins G8RC:$rS, G8RC:$rB),
188                    "nor $rA, $rS, $rB", IntGeneral,
189                    [(set G8RC:$rA, (not (or G8RC:$rS, G8RC:$rB)))]>;
190 def ORC8 : XForm_6<31, 412, (outs G8RC:$rA), (ins G8RC:$rS, G8RC:$rB),
191                    "orc $rA, $rS, $rB", IntGeneral,
192                    [(set G8RC:$rA, (or G8RC:$rS, (not G8RC:$rB)))]>;
193 def EQV8 : XForm_6<31, 284, (outs G8RC:$rA), (ins G8RC:$rS, G8RC:$rB),
194                    "eqv $rA, $rS, $rB", IntGeneral,
195                    [(set G8RC:$rA, (not (xor G8RC:$rS, G8RC:$rB)))]>;
196 def XOR8 : XForm_6<31, 316, (outs G8RC:$rA), (ins G8RC:$rS, G8RC:$rB),
197                    "xor $rA, $rS, $rB", IntGeneral,
198                    [(set G8RC:$rA, (xor G8RC:$rS, G8RC:$rB))]>;
199
200 // Logical ops with immediate.
201 def ANDIo8  : DForm_4<28, (outs G8RC:$dst), (ins G8RC:$src1, u16imm:$src2),
202                       "andi. $dst, $src1, $src2", IntGeneral,
203                       [(set G8RC:$dst, (and G8RC:$src1, immZExt16:$src2))]>,
204                       isDOT;
205 def ANDISo8 : DForm_4<29, (outs G8RC:$dst), (ins G8RC:$src1, u16imm:$src2),
206                      "andis. $dst, $src1, $src2", IntGeneral,
207                     [(set G8RC:$dst, (and G8RC:$src1,imm16ShiftedZExt:$src2))]>,
208                      isDOT;
209 def ORI8    : DForm_4<24, (outs G8RC:$dst), (ins G8RC:$src1, u16imm:$src2),
210                       "ori $dst, $src1, $src2", IntGeneral,
211                       [(set G8RC:$dst, (or G8RC:$src1, immZExt16:$src2))]>;
212 def ORIS8   : DForm_4<25, (outs G8RC:$dst), (ins G8RC:$src1, u16imm:$src2),
213                       "oris $dst, $src1, $src2", IntGeneral,
214                     [(set G8RC:$dst, (or G8RC:$src1, imm16ShiftedZExt:$src2))]>;
215 def XORI8   : DForm_4<26, (outs G8RC:$dst), (ins G8RC:$src1, u16imm:$src2),
216                       "xori $dst, $src1, $src2", IntGeneral,
217                       [(set G8RC:$dst, (xor G8RC:$src1, immZExt16:$src2))]>;
218 def XORIS8  : DForm_4<27, (outs G8RC:$dst), (ins G8RC:$src1, u16imm:$src2),
219                       "xoris $dst, $src1, $src2", IntGeneral,
220                    [(set G8RC:$dst, (xor G8RC:$src1, imm16ShiftedZExt:$src2))]>;
221
222 def ADD8  : XOForm_1<31, 266, 0, (outs G8RC:$rT), (ins G8RC:$rA, G8RC:$rB),
223                      "add $rT, $rA, $rB", IntGeneral,
224                      [(set G8RC:$rT, (add G8RC:$rA, G8RC:$rB))]>;
225                      
226 def ADDC8 : XOForm_1<31, 10, 0, (outs G8RC:$rT), (ins G8RC:$rA, G8RC:$rB),
227                      "addc $rT, $rA, $rB", IntGeneral,
228                      [(set G8RC:$rT, (addc G8RC:$rA, G8RC:$rB))]>,
229                      PPC970_DGroup_Cracked;
230 def ADDE8 : XOForm_1<31, 138, 0, (outs G8RC:$rT), (ins G8RC:$rA, G8RC:$rB),
231                      "adde $rT, $rA, $rB", IntGeneral,
232                      [(set G8RC:$rT, (adde G8RC:$rA, G8RC:$rB))]>;
233                      
234 def ADDI8  : DForm_2<14, (outs G8RC:$rD), (ins G8RC:$rA, s16imm64:$imm),
235                      "addi $rD, $rA, $imm", IntGeneral,
236                      [(set G8RC:$rD, (add G8RC:$rA, immSExt16:$imm))]>;
237 def ADDIS8 : DForm_2<15, (outs G8RC:$rD), (ins G8RC:$rA, symbolHi64:$imm),
238                      "addis $rD, $rA, $imm", IntGeneral,
239                      [(set G8RC:$rD, (add G8RC:$rA, imm16ShiftedSExt:$imm))]>;
240
241 def SUBFIC8: DForm_2< 8, (outs G8RC:$rD), (ins G8RC:$rA, s16imm64:$imm),
242                      "subfic $rD, $rA, $imm", IntGeneral,
243                      [(set G8RC:$rD, (subc immSExt16:$imm, G8RC:$rA))]>;
244 def SUBF8 : XOForm_1<31, 40, 0, (outs G8RC:$rT), (ins G8RC:$rA, G8RC:$rB),
245                      "subf $rT, $rA, $rB", IntGeneral,
246                      [(set G8RC:$rT, (sub G8RC:$rB, G8RC:$rA))]>;
247
248 def SUBFC8 : XOForm_1<31, 8, 0, (outs G8RC:$rT), (ins G8RC:$rA, G8RC:$rB),
249                       "subfc $rT, $rA, $rB", IntGeneral,
250                       [(set G8RC:$rT, (subc G8RC:$rB, G8RC:$rA))]>,
251                       PPC970_DGroup_Cracked;
252
253 def SUBFE8 : XOForm_1<31, 136, 0, (outs G8RC:$rT), (ins G8RC:$rA, G8RC:$rB),
254                       "subfe $rT, $rA, $rB", IntGeneral,
255                       [(set G8RC:$rT, (sube G8RC:$rB, G8RC:$rA))]>;
256 def ADDME8  : XOForm_3<31, 234, 0, (outs G8RC:$rT), (ins G8RC:$rA),
257                        "addme $rT, $rA", IntGeneral,
258                        [(set G8RC:$rT, (adde G8RC:$rA, immAllOnes))]>;
259 def ADDZE8  : XOForm_3<31, 202, 0, (outs G8RC:$rT), (ins G8RC:$rA),
260                        "addze $rT, $rA", IntGeneral,
261                        [(set G8RC:$rT, (adde G8RC:$rA, 0))]>;
262 def NEG8    : XOForm_3<31, 104, 0, (outs G8RC:$rT), (ins G8RC:$rA),
263                        "neg $rT, $rA", IntGeneral,
264                        [(set G8RC:$rT, (ineg G8RC:$rA))]>;
265 def SUBFME8 : XOForm_3<31, 232, 0, (outs G8RC:$rT), (ins G8RC:$rA),
266                        "subfme $rT, $rA", IntGeneral,
267                        [(set G8RC:$rT, (sube immAllOnes, G8RC:$rA))]>;
268 def SUBFZE8 : XOForm_3<31, 200, 0, (outs G8RC:$rT), (ins G8RC:$rA),
269                        "subfze $rT, $rA", IntGeneral,
270                        [(set G8RC:$rT, (sube 0, G8RC:$rA))]>;
271
272
273
274 def MULHD : XOForm_1<31, 73, 0, (outs G8RC:$rT), (ins G8RC:$rA, G8RC:$rB),
275                      "mulhd $rT, $rA, $rB", IntMulHW,
276                      [(set G8RC:$rT, (mulhs G8RC:$rA, G8RC:$rB))]>;
277 def MULHDU : XOForm_1<31, 9, 0, (outs G8RC:$rT), (ins G8RC:$rA, G8RC:$rB),
278                      "mulhdu $rT, $rA, $rB", IntMulHWU,
279                      [(set G8RC:$rT, (mulhu G8RC:$rA, G8RC:$rB))]>;
280
281 def CMPD   : XForm_16_ext<31, 0, (outs CRRC:$crD), (ins G8RC:$rA, G8RC:$rB),
282                           "cmpd $crD, $rA, $rB", IntCompare>, isPPC64;
283 def CMPLD  : XForm_16_ext<31, 32, (outs CRRC:$crD), (ins G8RC:$rA, G8RC:$rB),
284                           "cmpld $crD, $rA, $rB", IntCompare>, isPPC64;
285 def CMPDI  : DForm_5_ext<11, (outs CRRC:$crD), (ins G8RC:$rA, s16imm:$imm),
286                          "cmpdi $crD, $rA, $imm", IntCompare>, isPPC64;
287 def CMPLDI : DForm_6_ext<10, (outs CRRC:$dst), (ins G8RC:$src1, u16imm:$src2),
288                          "cmpldi $dst, $src1, $src2", IntCompare>, isPPC64;
289
290 def SLD  : XForm_6<31,  27, (outs G8RC:$rA), (ins G8RC:$rS, GPRC:$rB),
291                    "sld $rA, $rS, $rB", IntRotateD,
292                    [(set G8RC:$rA, (shl G8RC:$rS, GPRC:$rB))]>, isPPC64;
293 def SRD  : XForm_6<31, 539, (outs G8RC:$rA), (ins G8RC:$rS, GPRC:$rB),
294                    "srd $rA, $rS, $rB", IntRotateD,
295                    [(set G8RC:$rA, (srl G8RC:$rS, GPRC:$rB))]>, isPPC64;
296 def SRAD : XForm_6<31, 794, (outs G8RC:$rA), (ins G8RC:$rS, GPRC:$rB),
297                    "srad $rA, $rS, $rB", IntRotateD,
298                    [(set G8RC:$rA, (sra G8RC:$rS, GPRC:$rB))]>, isPPC64;
299                    
300 def EXTSB8 : XForm_11<31, 954, (outs G8RC:$rA), (ins G8RC:$rS),
301                       "extsb $rA, $rS", IntGeneral,
302                       [(set G8RC:$rA, (sext_inreg G8RC:$rS, i8))]>;
303 def EXTSH8 : XForm_11<31, 922, (outs G8RC:$rA), (ins G8RC:$rS),
304                       "extsh $rA, $rS", IntGeneral,
305                       [(set G8RC:$rA, (sext_inreg G8RC:$rS, i16))]>;
306
307 def EXTSW  : XForm_11<31, 986, (outs G8RC:$rA), (ins G8RC:$rS),
308                       "extsw $rA, $rS", IntGeneral,
309                       [(set G8RC:$rA, (sext_inreg G8RC:$rS, i32))]>, isPPC64;
310 /// EXTSW_32 - Just like EXTSW, but works on '32-bit' registers.
311 def EXTSW_32 : XForm_11<31, 986, (outs GPRC:$rA), (ins GPRC:$rS),
312                       "extsw $rA, $rS", IntGeneral,
313                       [(set GPRC:$rA, (PPCextsw_32 GPRC:$rS))]>, isPPC64;
314 def EXTSW_32_64 : XForm_11<31, 986, (outs G8RC:$rA), (ins GPRC:$rS),
315                       "extsw $rA, $rS", IntGeneral,
316                       [(set G8RC:$rA, (sext GPRC:$rS))]>, isPPC64;
317
318 def SRADI  : XSForm_1<31, 413, (outs G8RC:$rA), (ins G8RC:$rS, u6imm:$SH),
319                       "sradi $rA, $rS, $SH", IntRotateD,
320                       [(set G8RC:$rA, (sra G8RC:$rS, (i32 imm:$SH)))]>, isPPC64;
321 def CNTLZD : XForm_11<31, 58, (outs G8RC:$rA), (ins G8RC:$rS),
322                       "cntlzd $rA, $rS", IntGeneral,
323                       [(set G8RC:$rA, (ctlz G8RC:$rS))]>;
324
325 def DIVD  : XOForm_1<31, 489, 0, (outs G8RC:$rT), (ins G8RC:$rA, G8RC:$rB),
326                      "divd $rT, $rA, $rB", IntDivD,
327                      [(set G8RC:$rT, (sdiv G8RC:$rA, G8RC:$rB))]>, isPPC64,
328                      PPC970_DGroup_First, PPC970_DGroup_Cracked;
329 def DIVDU : XOForm_1<31, 457, 0, (outs G8RC:$rT), (ins G8RC:$rA, G8RC:$rB),
330                      "divdu $rT, $rA, $rB", IntDivD,
331                      [(set G8RC:$rT, (udiv G8RC:$rA, G8RC:$rB))]>, isPPC64,
332                      PPC970_DGroup_First, PPC970_DGroup_Cracked;
333 def MULLD : XOForm_1<31, 233, 0, (outs G8RC:$rT), (ins G8RC:$rA, G8RC:$rB),
334                      "mulld $rT, $rA, $rB", IntMulHD,
335                      [(set G8RC:$rT, (mul G8RC:$rA, G8RC:$rB))]>, isPPC64;
336
337
338 let isCommutable = 1 in {
339 def RLDIMI : MDForm_1<30, 3,
340                       (outs G8RC:$rA), (ins G8RC:$rSi, G8RC:$rS, u6imm:$SH, u6imm:$MB),
341                       "rldimi $rA, $rS, $SH, $MB", IntRotateD,
342                       []>, isPPC64, RegConstraint<"$rSi = $rA">,
343                       NoEncode<"$rSi">;
344 }
345
346 // Rotate instructions.
347 def RLDCL  : MDForm_1<30, 0,
348                       (outs G8RC:$rA), (ins G8RC:$rS, GPRC:$rB, u6imm:$MB),
349                       "rldcl $rA, $rS, $rB, $MB", IntRotateD,
350                       []>, isPPC64;
351 def RLDICL : MDForm_1<30, 0,
352                       (outs G8RC:$rA), (ins G8RC:$rS, u6imm:$SH, u6imm:$MB),
353                       "rldicl $rA, $rS, $SH, $MB", IntRotateD,
354                       []>, isPPC64;
355 def RLDICR : MDForm_1<30, 1,
356                       (outs G8RC:$rA), (ins G8RC:$rS, u6imm:$SH, u6imm:$ME),
357                       "rldicr $rA, $rS, $SH, $ME", IntRotateD,
358                       []>, isPPC64;
359 }  // End FXU Operations.
360
361
362 //===----------------------------------------------------------------------===//
363 // Load/Store instructions.
364 //
365
366
367 // Sign extending loads.
368 let isLoad = 1, PPC970_Unit = 2 in {
369 def LHA8: DForm_1<42, (outs G8RC:$rD), (ins memri:$src),
370                   "lha $rD, $src", LdStLHA,
371                   [(set G8RC:$rD, (sextloadi16 iaddr:$src))]>,
372                   PPC970_DGroup_Cracked;
373 def LWA  : DSForm_1<58, 2, (outs G8RC:$rD), (ins memrix:$src),
374                     "lwa $rD, $src", LdStLWA,
375                     [(set G8RC:$rD, (sextloadi32 ixaddr:$src))]>, isPPC64,
376                     PPC970_DGroup_Cracked;
377 def LHAX8: XForm_1<31, 343, (outs G8RC:$rD), (ins memrr:$src),
378                    "lhax $rD, $src", LdStLHA,
379                    [(set G8RC:$rD, (sextloadi16 xaddr:$src))]>,
380                    PPC970_DGroup_Cracked;
381 def LWAX : XForm_1<31, 341, (outs G8RC:$rD), (ins memrr:$src),
382                    "lwax $rD, $src", LdStLHA,
383                    [(set G8RC:$rD, (sextloadi32 xaddr:$src))]>, isPPC64,
384                    PPC970_DGroup_Cracked;
385
386 // Update forms.
387 def LHAU8 : DForm_1<43, (outs G8RC:$rD, ptr_rc:$ea_result), (ins symbolLo:$disp,
388                             ptr_rc:$rA),
389                     "lhau $rD, $disp($rA)", LdStGeneral,
390                     []>, RegConstraint<"$rA = $ea_result">,
391                     NoEncode<"$ea_result">;
392 // NO LWAU!
393
394 }
395
396 // Zero extending loads.
397 let isLoad = 1, PPC970_Unit = 2 in {
398 def LBZ8 : DForm_1<34, (outs G8RC:$rD), (ins memri:$src),
399                   "lbz $rD, $src", LdStGeneral,
400                   [(set G8RC:$rD, (zextloadi8 iaddr:$src))]>;
401 def LHZ8 : DForm_1<40, (outs G8RC:$rD), (ins memri:$src),
402                   "lhz $rD, $src", LdStGeneral,
403                   [(set G8RC:$rD, (zextloadi16 iaddr:$src))]>;
404 def LWZ8 : DForm_1<32, (outs G8RC:$rD), (ins memri:$src),
405                   "lwz $rD, $src", LdStGeneral,
406                   [(set G8RC:$rD, (zextloadi32 iaddr:$src))]>, isPPC64;
407
408 def LBZX8 : XForm_1<31,  87, (outs G8RC:$rD), (ins memrr:$src),
409                    "lbzx $rD, $src", LdStGeneral,
410                    [(set G8RC:$rD, (zextloadi8 xaddr:$src))]>;
411 def LHZX8 : XForm_1<31, 279, (outs G8RC:$rD), (ins memrr:$src),
412                    "lhzx $rD, $src", LdStGeneral,
413                    [(set G8RC:$rD, (zextloadi16 xaddr:$src))]>;
414 def LWZX8 : XForm_1<31,  23, (outs G8RC:$rD), (ins memrr:$src),
415                    "lwzx $rD, $src", LdStGeneral,
416                    [(set G8RC:$rD, (zextloadi32 xaddr:$src))]>;
417                    
418                    
419 // Update forms.
420 def LBZU8 : DForm_1<35, (outs G8RC:$rD, ptr_rc:$ea_result), (ins memri:$addr),
421                     "lbzu $rD, $addr", LdStGeneral,
422                     []>, RegConstraint<"$addr.reg = $ea_result">,
423                     NoEncode<"$ea_result">;
424 def LHZU8 : DForm_1<41, (outs G8RC:$rD, ptr_rc:$ea_result), (ins memri:$addr),
425                     "lhzu $rD, $addr", LdStGeneral,
426                     []>, RegConstraint<"$addr.reg = $ea_result">,
427                     NoEncode<"$ea_result">;
428 def LWZU8 : DForm_1<33, (outs G8RC:$rD, ptr_rc:$ea_result), (ins memri:$addr),
429                     "lwzu $rD, $addr", LdStGeneral,
430                     []>, RegConstraint<"$addr.reg = $ea_result">,
431                     NoEncode<"$ea_result">;
432 }
433
434
435 // Full 8-byte loads.
436 let isLoad = 1, PPC970_Unit = 2 in {
437 def LD   : DSForm_1<58, 0, (outs G8RC:$rD), (ins memrix:$src),
438                     "ld $rD, $src", LdStLD,
439                     [(set G8RC:$rD, (load ixaddr:$src))]>, isPPC64;
440 def LDX  : XForm_1<31,  21, (outs G8RC:$rD), (ins memrr:$src),
441                    "ldx $rD, $src", LdStLD,
442                    [(set G8RC:$rD, (load xaddr:$src))]>, isPPC64;
443                    
444 def LDU  : DSForm_1<58, 1, (outs G8RC:$rD, ptr_rc:$ea_result), (ins memrix:$addr),
445                     "ldu $rD, $addr", LdStLD,
446                     []>, RegConstraint<"$addr.reg = $ea_result">, isPPC64,
447                     NoEncode<"$ea_result">;
448
449 }
450
451 let PPC970_Unit = 2 in {
452 // Truncating stores.                       
453 def STB8 : DForm_1<38, (outs), (ins G8RC:$rS, memri:$src),
454                    "stb $rS, $src", LdStGeneral,
455                    [(truncstorei8 G8RC:$rS, iaddr:$src)]>;
456 def STH8 : DForm_1<44, (outs), (ins G8RC:$rS, memri:$src),
457                    "sth $rS, $src", LdStGeneral,
458                    [(truncstorei16 G8RC:$rS, iaddr:$src)]>;
459 def STW8 : DForm_1<36, (outs), (ins G8RC:$rS, memri:$src),
460                    "stw $rS, $src", LdStGeneral,
461                    [(truncstorei32 G8RC:$rS, iaddr:$src)]>;
462 def STBX8 : XForm_8<31, 215, (outs), (ins G8RC:$rS, memrr:$dst),
463                    "stbx $rS, $dst", LdStGeneral,
464                    [(truncstorei8 G8RC:$rS, xaddr:$dst)]>, 
465                    PPC970_DGroup_Cracked;
466 def STHX8 : XForm_8<31, 407, (outs), (ins G8RC:$rS, memrr:$dst),
467                    "sthx $rS, $dst", LdStGeneral,
468                    [(truncstorei16 G8RC:$rS, xaddr:$dst)]>, 
469                    PPC970_DGroup_Cracked;
470 def STWX8 : XForm_8<31, 151, (outs), (ins G8RC:$rS, memrr:$dst),
471                    "stwx $rS, $dst", LdStGeneral,
472                    [(truncstorei32 G8RC:$rS, xaddr:$dst)]>,
473                    PPC970_DGroup_Cracked;
474 // Normal 8-byte stores.
475 def STD  : DSForm_1<62, 0, (outs), (ins G8RC:$rS, memrix:$dst),
476                     "std $rS, $dst", LdStSTD,
477                     [(store G8RC:$rS, ixaddr:$dst)]>, isPPC64;
478 def STDX  : XForm_8<31, 149, (outs), (ins G8RC:$rS, memrr:$dst),
479                    "stdx $rS, $dst", LdStSTD,
480                    [(store G8RC:$rS, xaddr:$dst)]>, isPPC64,
481                    PPC970_DGroup_Cracked;
482 }
483
484 let PPC970_Unit = 2 in {
485
486 def STBU8 : DForm_1<38, (outs ptr_rc:$ea_res), (ins G8RC:$rS,
487                              symbolLo:$ptroff, ptr_rc:$ptrreg),
488                     "stbu $rS, $ptroff($ptrreg)", LdStGeneral,
489                     [(set ptr_rc:$ea_res,
490                           (pre_truncsti8 G8RC:$rS, ptr_rc:$ptrreg, 
491                                          iaddroff:$ptroff))]>,
492                     RegConstraint<"$ptrreg = $ea_res">, NoEncode<"$ea_res">;
493 def STHU8 : DForm_1<45, (outs ptr_rc:$ea_res), (ins G8RC:$rS,
494                              symbolLo:$ptroff, ptr_rc:$ptrreg),
495                     "sthu $rS, $ptroff($ptrreg)", LdStGeneral,
496                     [(set ptr_rc:$ea_res,
497                         (pre_truncsti16 G8RC:$rS, ptr_rc:$ptrreg, 
498                                         iaddroff:$ptroff))]>,
499                     RegConstraint<"$ptrreg = $ea_res">, NoEncode<"$ea_res">;
500 def STWU8 : DForm_1<37, (outs ptr_rc:$ea_res), (ins G8RC:$rS,
501                              symbolLo:$ptroff, ptr_rc:$ptrreg),
502                     "stwu $rS, $ptroff($ptrreg)", LdStGeneral,
503                     [(set ptr_rc:$ea_res, (pre_store G8RC:$rS, ptr_rc:$ptrreg, 
504                                                      iaddroff:$ptroff))]>,
505                     RegConstraint<"$ptrreg = $ea_res">, NoEncode<"$ea_res">;
506
507
508 def STDU : DSForm_1<62, 1, (outs ptr_rc:$ea_res), (ins G8RC:$rS,
509                                 s16immX4:$ptroff, ptr_rc:$ptrreg),
510                     "stdu $rS, $ptroff($ptrreg)", LdStSTD,
511                     [(set ptr_rc:$ea_res, (pre_store G8RC:$rS, ptr_rc:$ptrreg, 
512                                                      iaddroff:$ptroff))]>,
513                     RegConstraint<"$ptrreg = $ea_res">, NoEncode<"$ea_res">,
514                     isPPC64;
515
516 }
517
518 let isStore = 1, PPC970_Unit = 2 in {
519
520 def STDUX : XForm_8<31, 181, (outs), (ins G8RC:$rS, memrr:$dst),
521                    "stdux $rS, $dst", LdStSTD,
522                    []>, isPPC64;
523                    
524
525 // STD_32/STDX_32 - Just like STD/STDX, but uses a '32-bit' input register.
526 def STD_32  : DSForm_1<62, 0, (outs), (ins GPRC:$rT, memrix:$dst),
527                        "std $rT, $dst", LdStSTD,
528                        [(PPCstd_32  GPRC:$rT, ixaddr:$dst)]>, isPPC64;
529 def STDX_32  : XForm_8<31, 149, (outs), (ins GPRC:$rT, memrr:$dst),
530                        "stdx $rT, $dst", LdStSTD,
531                        [(PPCstd_32  GPRC:$rT, xaddr:$dst)]>, isPPC64,
532                        PPC970_DGroup_Cracked;
533 }
534
535
536
537 //===----------------------------------------------------------------------===//
538 // Floating point instructions.
539 //
540
541
542 let PPC970_Unit = 3 in {  // FPU Operations.
543 def FCFID  : XForm_26<63, 846, (outs F8RC:$frD), (ins F8RC:$frB),
544                       "fcfid $frD, $frB", FPGeneral,
545                       [(set F8RC:$frD, (PPCfcfid F8RC:$frB))]>, isPPC64;
546 def FCTIDZ : XForm_26<63, 815, (outs F8RC:$frD), (ins F8RC:$frB),
547                       "fctidz $frD, $frB", FPGeneral,
548                       [(set F8RC:$frD, (PPCfctidz F8RC:$frB))]>, isPPC64;
549 }
550
551
552 //===----------------------------------------------------------------------===//
553 // Instruction Patterns
554 //
555
556 // Extensions and truncates to/from 32-bit regs.
557 def : Pat<(i64 (zext GPRC:$in)),
558           (RLDICL (OR4To8 GPRC:$in, GPRC:$in), 0, 32)>;
559 def : Pat<(i64 (anyext GPRC:$in)),
560           (OR4To8 GPRC:$in, GPRC:$in)>;
561 def : Pat<(i32 (trunc G8RC:$in)),
562           (OR8To4 G8RC:$in, G8RC:$in)>;
563
564 // Extending loads with i64 targets.
565 def : Pat<(zextloadi1 iaddr:$src),
566           (LBZ8 iaddr:$src)>;
567 def : Pat<(zextloadi1 xaddr:$src),
568           (LBZX8 xaddr:$src)>;
569 def : Pat<(extloadi1 iaddr:$src),
570           (LBZ8 iaddr:$src)>;
571 def : Pat<(extloadi1 xaddr:$src),
572           (LBZX8 xaddr:$src)>;
573 def : Pat<(extloadi8 iaddr:$src),
574           (LBZ8 iaddr:$src)>;
575 def : Pat<(extloadi8 xaddr:$src),
576           (LBZX8 xaddr:$src)>;
577 def : Pat<(extloadi16 iaddr:$src),
578           (LHZ8 iaddr:$src)>;
579 def : Pat<(extloadi16 xaddr:$src),
580           (LHZX8 xaddr:$src)>;
581 def : Pat<(extloadi32 iaddr:$src),
582           (LWZ8 iaddr:$src)>;
583 def : Pat<(extloadi32 xaddr:$src),
584           (LWZX8 xaddr:$src)>;
585
586 // SHL/SRL
587 def : Pat<(shl G8RC:$in, (i32 imm:$imm)),
588           (RLDICR G8RC:$in, imm:$imm, (SHL64 imm:$imm))>;
589 def : Pat<(srl G8RC:$in, (i32 imm:$imm)),
590           (RLDICL G8RC:$in, (SRL64 imm:$imm), imm:$imm)>;
591
592 // ROTL
593 def : Pat<(rotl G8RC:$in, GPRC:$sh),
594           (RLDCL G8RC:$in, GPRC:$sh, 0)>;
595 def : Pat<(rotl G8RC:$in, (i32 imm:$imm)),
596           (RLDICL G8RC:$in, imm:$imm, 0)>;
597
598 // Hi and Lo for Darwin Global Addresses.
599 def : Pat<(PPChi tglobaladdr:$in, 0), (LIS8 tglobaladdr:$in)>;
600 def : Pat<(PPClo tglobaladdr:$in, 0), (LI8  tglobaladdr:$in)>;
601 def : Pat<(PPChi tconstpool:$in , 0), (LIS8 tconstpool:$in)>;
602 def : Pat<(PPClo tconstpool:$in , 0), (LI8  tconstpool:$in)>;
603 def : Pat<(PPChi tjumptable:$in , 0), (LIS8 tjumptable:$in)>;
604 def : Pat<(PPClo tjumptable:$in , 0), (LI8  tjumptable:$in)>;
605 def : Pat<(add G8RC:$in, (PPChi tglobaladdr:$g, 0)),
606           (ADDIS8 G8RC:$in, tglobaladdr:$g)>;
607 def : Pat<(add G8RC:$in, (PPChi tconstpool:$g, 0)),
608           (ADDIS8 G8RC:$in, tconstpool:$g)>;
609 def : Pat<(add G8RC:$in, (PPChi tjumptable:$g, 0)),
610           (ADDIS8 G8RC:$in, tjumptable:$g)>;