Add more PPC floating-point conversion instructions
[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   let EncoderMethod = "getHA16Encoding";
27 }
28 def symbolLo64 : Operand<i64> {
29   let PrintMethod = "printSymbolLo";
30   let EncoderMethod = "getLO16Encoding";
31 }
32 def tocentry : Operand<iPTR> {
33   let MIOperandInfo = (ops i64imm:$imm);
34 }
35 def tlsreg : Operand<i64> {
36   let EncoderMethod = "getTLSRegEncoding";
37 }
38 def tlsgd : Operand<i64> {}
39
40 //===----------------------------------------------------------------------===//
41 // 64-bit transformation functions.
42 //
43
44 def SHL64 : SDNodeXForm<imm, [{
45   // Transformation function: 63 - imm
46   return getI32Imm(63 - N->getZExtValue());
47 }]>;
48
49 def SRL64 : SDNodeXForm<imm, [{
50   // Transformation function: 64 - imm
51   return N->getZExtValue() ? getI32Imm(64 - N->getZExtValue()) : getI32Imm(0);
52 }]>;
53
54 def HI32_48 : SDNodeXForm<imm, [{
55   // Transformation function: shift the immediate value down into the low bits.
56   return getI32Imm((unsigned short)(N->getZExtValue() >> 32));
57 }]>;
58
59 def HI48_64 : SDNodeXForm<imm, [{
60   // Transformation function: shift the immediate value down into the low bits.
61   return getI32Imm((unsigned short)(N->getZExtValue() >> 48));
62 }]>;
63
64
65 //===----------------------------------------------------------------------===//
66 // Calls.
67 //
68
69 let isTerminator = 1, isBarrier = 1, PPC970_Unit = 7 in {
70   let isBranch = 1, isIndirectBranch = 1, Uses = [CTR8] in
71     def BCTR8 : XLForm_2_ext<19, 528, 20, 0, 0, (outs), (ins), "bctr", BrB, []>,
72         Requires<[In64BitMode]>;
73 }
74
75 let Defs = [LR8] in
76   def MovePCtoLR8 : Pseudo<(outs), (ins), "#MovePCtoLR8", []>,
77                     PPC970_Unit_BRU;
78
79 let isBranch = 1, isTerminator = 1, hasCtrlDep = 1, PPC970_Unit = 7 in {
80   let Defs = [CTR8], Uses = [CTR8] in {
81     def BDZ8  : BForm_1<16, 18, 0, 0, (outs), (ins condbrtarget:$dst),
82                         "bdz $dst">;
83     def BDNZ8 : BForm_1<16, 16, 0, 0, (outs), (ins condbrtarget:$dst),
84                         "bdnz $dst">;
85   }
86 }
87
88 let isCall = 1, PPC970_Unit = 7, Defs = [LR8] in {
89   // Convenient aliases for call instructions
90   let Uses = [RM] in {
91     def BL8  : IForm<18, 0, 1, (outs), (ins calltarget:$func),
92                      "bl $func", BrB, []>;  // See Pat patterns below.
93
94     def BLA8 : IForm<18, 1, 1, (outs), (ins aaddr:$func),
95                      "bla $func", BrB, [(PPCcall (i64 imm:$func))]>;
96   }
97   let Uses = [RM], isCodeGenOnly = 1 in {
98     def BL8_NOP  : IForm_and_DForm_4_zero<18, 0, 1, 24,
99                              (outs), (ins calltarget:$func),
100                              "bl $func\n\tnop", BrB, []>;
101
102     def BL8_NOP_TLSGD : IForm_and_DForm_4_zero<18, 0, 1, 24,
103                                   (outs), (ins calltarget:$func, tlsgd:$sym),
104                                   "bl $func($sym)\n\tnop", BrB, []>;
105
106     def BL8_NOP_TLSLD : IForm_and_DForm_4_zero<18, 0, 1, 24,
107                                   (outs), (ins calltarget:$func, tlsgd:$sym),
108                                   "bl $func($sym)\n\tnop", BrB, []>;
109
110     def BLA8_NOP : IForm_and_DForm_4_zero<18, 1, 1, 24,
111                              (outs), (ins aaddr:$func),
112                              "bla $func\n\tnop", BrB,
113                              [(PPCcall_nop (i64 imm:$func))]>;
114   }
115   let Uses = [CTR8, RM] in {
116     def BCTRL8 : XLForm_2_ext<19, 528, 20, 0, 1, (outs), (ins),
117                               "bctrl", BrB, [(PPCbctrl)]>,
118                  Requires<[In64BitMode]>;
119   }
120 }
121
122
123 // Calls
124 def : Pat<(PPCcall (i64 tglobaladdr:$dst)),
125           (BL8 tglobaladdr:$dst)>;
126 def : Pat<(PPCcall_nop (i64 tglobaladdr:$dst)),
127           (BL8_NOP tglobaladdr:$dst)>;
128
129 def : Pat<(PPCcall (i64 texternalsym:$dst)),
130           (BL8 texternalsym:$dst)>;
131 def : Pat<(PPCcall_nop (i64 texternalsym:$dst)),
132           (BL8_NOP texternalsym:$dst)>;
133
134 // Atomic operations
135 let usesCustomInserter = 1 in {
136   let Defs = [CR0] in {
137     def ATOMIC_LOAD_ADD_I64 : Pseudo<
138       (outs G8RC:$dst), (ins memrr:$ptr, G8RC:$incr), "#ATOMIC_LOAD_ADD_I64",
139       [(set i64:$dst, (atomic_load_add_64 xoaddr:$ptr, i64:$incr))]>;
140     def ATOMIC_LOAD_SUB_I64 : Pseudo<
141       (outs G8RC:$dst), (ins memrr:$ptr, G8RC:$incr), "#ATOMIC_LOAD_SUB_I64",
142       [(set i64:$dst, (atomic_load_sub_64 xoaddr:$ptr, i64:$incr))]>;
143     def ATOMIC_LOAD_OR_I64 : Pseudo<
144       (outs G8RC:$dst), (ins memrr:$ptr, G8RC:$incr), "#ATOMIC_LOAD_OR_I64",
145       [(set i64:$dst, (atomic_load_or_64 xoaddr:$ptr, i64:$incr))]>;
146     def ATOMIC_LOAD_XOR_I64 : Pseudo<
147       (outs G8RC:$dst), (ins memrr:$ptr, G8RC:$incr), "#ATOMIC_LOAD_XOR_I64",
148       [(set i64:$dst, (atomic_load_xor_64 xoaddr:$ptr, i64:$incr))]>;
149     def ATOMIC_LOAD_AND_I64 : Pseudo<
150       (outs G8RC:$dst), (ins memrr:$ptr, G8RC:$incr), "#ATOMIC_LOAD_AND_i64",
151       [(set i64:$dst, (atomic_load_and_64 xoaddr:$ptr, i64:$incr))]>;
152     def ATOMIC_LOAD_NAND_I64 : Pseudo<
153       (outs G8RC:$dst), (ins memrr:$ptr, G8RC:$incr), "#ATOMIC_LOAD_NAND_I64",
154       [(set i64:$dst, (atomic_load_nand_64 xoaddr:$ptr, i64:$incr))]>;
155
156     def ATOMIC_CMP_SWAP_I64 : Pseudo<
157       (outs G8RC:$dst), (ins memrr:$ptr, G8RC:$old, G8RC:$new), "#ATOMIC_CMP_SWAP_I64",
158       [(set i64:$dst, (atomic_cmp_swap_64 xoaddr:$ptr, i64:$old, i64:$new))]>;
159
160     def ATOMIC_SWAP_I64 : Pseudo<
161       (outs G8RC:$dst), (ins memrr:$ptr, G8RC:$new), "#ATOMIC_SWAP_I64",
162       [(set i64:$dst, (atomic_swap_64 xoaddr:$ptr, i64:$new))]>;
163   }
164 }
165
166 // Instructions to support atomic operations
167 def LDARX : XForm_1<31,  84, (outs G8RC:$rD), (ins memrr:$ptr),
168                    "ldarx $rD, $ptr", LdStLDARX,
169                    [(set i64:$rD, (PPClarx xoaddr:$ptr))]>;
170
171 let Defs = [CR0] in
172 def STDCX : XForm_1<31, 214, (outs), (ins G8RC:$rS, memrr:$dst),
173                    "stdcx. $rS, $dst", LdStSTDCX,
174                    [(PPCstcx i64:$rS, xoaddr:$dst)]>,
175                    isDOT;
176
177 let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1, Uses = [RM] in
178 def TCRETURNdi8 :Pseudo< (outs),
179                         (ins calltarget:$dst, i32imm:$offset),
180                  "#TC_RETURNd8 $dst $offset",
181                  []>;
182
183 let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1, Uses = [RM] in
184 def TCRETURNai8 :Pseudo<(outs), (ins aaddr:$func, i32imm:$offset),
185                  "#TC_RETURNa8 $func $offset",
186                  [(PPCtc_return (i64 imm:$func), imm:$offset)]>;
187
188 let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1, Uses = [RM] in
189 def TCRETURNri8 : Pseudo<(outs), (ins CTRRC8:$dst, i32imm:$offset),
190                  "#TC_RETURNr8 $dst $offset",
191                  []>;
192
193 let isCodeGenOnly = 1 in {
194
195 let isTerminator = 1, isBarrier = 1, PPC970_Unit = 7, isBranch = 1,
196     isIndirectBranch = 1, isCall = 1, isReturn = 1, Uses = [CTR8, RM] in
197 def TAILBCTR8 : XLForm_2_ext<19, 528, 20, 0, 0, (outs), (ins), "bctr", BrB, []>,
198     Requires<[In64BitMode]>;
199
200
201 let isBranch = 1, isTerminator = 1, hasCtrlDep = 1, PPC970_Unit = 7,
202     isBarrier = 1, isCall = 1, isReturn = 1, Uses = [RM] in
203 def TAILB8   : IForm<18, 0, 0, (outs), (ins calltarget:$dst),
204                   "b $dst", BrB,
205                   []>;
206
207
208 let isBranch = 1, isTerminator = 1, hasCtrlDep = 1, PPC970_Unit = 7,
209     isBarrier = 1, isCall = 1, isReturn = 1, Uses = [RM] in
210 def TAILBA8   : IForm<18, 0, 0, (outs), (ins aaddr:$dst),
211                   "ba $dst", BrB,
212                   []>;
213
214 }
215
216 def : Pat<(PPCtc_return (i64 tglobaladdr:$dst),  imm:$imm),
217           (TCRETURNdi8 tglobaladdr:$dst, imm:$imm)>;
218
219 def : Pat<(PPCtc_return (i64 texternalsym:$dst), imm:$imm),
220           (TCRETURNdi8 texternalsym:$dst, imm:$imm)>;
221
222 def : Pat<(PPCtc_return CTRRC8:$dst, imm:$imm),
223           (TCRETURNri8 CTRRC8:$dst, imm:$imm)>;
224
225
226 // 64-bit CR instructions
227 def MTCRF8 : XFXForm_5<31, 144, (outs crbitm:$FXM), (ins G8RC:$rS),
228                       "mtcrf $FXM, $rS", BrMCRX>,
229             PPC970_MicroCode, PPC970_Unit_CRU;
230
231 let isCodeGenOnly = 1 in
232 def MFCR8pseud: XFXForm_3<31, 19, (outs G8RC:$rT), (ins crbitm:$FXM),
233                        "#MFCR8pseud", SprMFCR>,
234             PPC970_MicroCode, PPC970_Unit_CRU;
235             
236 def MFCR8 : XFXForm_3<31, 19, (outs G8RC:$rT), (ins),
237                      "mfcr $rT", SprMFCR>,
238                      PPC970_MicroCode, PPC970_Unit_CRU;
239
240 let hasSideEffects = 1, isBarrier = 1, usesCustomInserter = 1 in {
241   def EH_SjLj_SetJmp64  : Pseudo<(outs GPRC:$dst), (ins memr:$buf),
242                             "#EH_SJLJ_SETJMP64",
243                             [(set i32:$dst, (PPCeh_sjlj_setjmp addr:$buf))]>,
244                           Requires<[In64BitMode]>;
245   let isTerminator = 1 in
246   def EH_SjLj_LongJmp64 : Pseudo<(outs), (ins memr:$buf),
247                             "#EH_SJLJ_LONGJMP64",
248                             [(PPCeh_sjlj_longjmp addr:$buf)]>,
249                           Requires<[In64BitMode]>;
250 }
251
252 //===----------------------------------------------------------------------===//
253 // 64-bit SPR manipulation instrs.
254
255 let Uses = [CTR8] in {
256 def MFCTR8 : XFXForm_1_ext<31, 339, 9, (outs G8RC:$rT), (ins),
257                            "mfctr $rT", SprMFSPR>,
258              PPC970_DGroup_First, PPC970_Unit_FXU;
259 }
260 let Pattern = [(PPCmtctr i64:$rS)], Defs = [CTR8] in {
261 def MTCTR8 : XFXForm_7_ext<31, 467, 9, (outs), (ins G8RC:$rS),
262                            "mtctr $rS", SprMTSPR>,
263              PPC970_DGroup_First, PPC970_Unit_FXU;
264 }
265
266 let Pattern = [(set i64:$rT, readcyclecounter)] in
267 def MFTB8 : XFXForm_1_ext<31, 339, 268, (outs G8RC:$rT), (ins),
268                           "mfspr $rT, 268", SprMFTB>,
269             PPC970_DGroup_First, PPC970_Unit_FXU;
270 // Note that encoding mftb using mfspr is now the preferred form,
271 // and has been since at least ISA v2.03. The mftb instruction has
272 // now been phased out. Using mfspr, however, is known not to work on
273 // the POWER3.
274
275 let Defs = [X1], Uses = [X1] in
276 def DYNALLOC8 : Pseudo<(outs G8RC:$result), (ins G8RC:$negsize, memri:$fpsi),"#DYNALLOC8",
277                        [(set i64:$result,
278                              (PPCdynalloc i64:$negsize, iaddr:$fpsi))]>;
279
280 let Defs = [LR8] in {
281 def MTLR8  : XFXForm_7_ext<31, 467, 8, (outs), (ins G8RC:$rS),
282                            "mtlr $rS", SprMTSPR>,
283              PPC970_DGroup_First, PPC970_Unit_FXU;
284 }
285 let Uses = [LR8] in {
286 def MFLR8  : XFXForm_1_ext<31, 339, 8, (outs G8RC:$rT), (ins),
287                            "mflr $rT", SprMFSPR>,
288              PPC970_DGroup_First, PPC970_Unit_FXU;
289 }
290
291 //===----------------------------------------------------------------------===//
292 // Fixed point instructions.
293 //
294
295 let PPC970_Unit = 1 in {  // FXU Operations.
296
297 let isReMaterializable = 1, isAsCheapAsAMove = 1, isMoveImm = 1 in {
298 def LI8  : DForm_2_r0<14, (outs G8RC:$rD), (ins symbolLo64:$imm),
299                       "li $rD, $imm", IntSimple,
300                       [(set i64:$rD, immSExt16:$imm)]>;
301 def LIS8 : DForm_2_r0<15, (outs G8RC:$rD), (ins symbolHi64:$imm),
302                       "lis $rD, $imm", IntSimple,
303                       [(set i64:$rD, imm16ShiftedSExt:$imm)]>;
304 }
305
306 // Logical ops.
307 def NAND8: XForm_6<31, 476, (outs G8RC:$rA), (ins G8RC:$rS, G8RC:$rB),
308                    "nand $rA, $rS, $rB", IntSimple,
309                    [(set i64:$rA, (not (and i64:$rS, i64:$rB)))]>;
310 def AND8 : XForm_6<31,  28, (outs G8RC:$rA), (ins G8RC:$rS, G8RC:$rB),
311                    "and $rA, $rS, $rB", IntSimple,
312                    [(set i64:$rA, (and i64:$rS, i64:$rB))]>;
313 def ANDC8: XForm_6<31,  60, (outs G8RC:$rA), (ins G8RC:$rS, G8RC:$rB),
314                    "andc $rA, $rS, $rB", IntSimple,
315                    [(set i64:$rA, (and i64:$rS, (not i64:$rB)))]>;
316 def OR8  : XForm_6<31, 444, (outs G8RC:$rA), (ins G8RC:$rS, G8RC:$rB),
317                    "or $rA, $rS, $rB", IntSimple,
318                    [(set i64:$rA, (or i64:$rS, i64:$rB))]>;
319 def NOR8 : XForm_6<31, 124, (outs G8RC:$rA), (ins G8RC:$rS, G8RC:$rB),
320                    "nor $rA, $rS, $rB", IntSimple,
321                    [(set i64:$rA, (not (or i64:$rS, i64:$rB)))]>;
322 def ORC8 : XForm_6<31, 412, (outs G8RC:$rA), (ins G8RC:$rS, G8RC:$rB),
323                    "orc $rA, $rS, $rB", IntSimple,
324                    [(set i64:$rA, (or i64:$rS, (not i64:$rB)))]>;
325 def EQV8 : XForm_6<31, 284, (outs G8RC:$rA), (ins G8RC:$rS, G8RC:$rB),
326                    "eqv $rA, $rS, $rB", IntSimple,
327                    [(set i64:$rA, (not (xor i64:$rS, i64:$rB)))]>;
328 def XOR8 : XForm_6<31, 316, (outs G8RC:$rA), (ins G8RC:$rS, G8RC:$rB),
329                    "xor $rA, $rS, $rB", IntSimple,
330                    [(set i64:$rA, (xor i64:$rS, i64:$rB))]>;
331
332 // Logical ops with immediate.
333 def ANDIo8  : DForm_4<28, (outs G8RC:$dst), (ins G8RC:$src1, u16imm:$src2),
334                       "andi. $dst, $src1, $src2", IntGeneral,
335                       [(set i64:$dst, (and i64:$src1, immZExt16:$src2))]>,
336                       isDOT;
337 def ANDISo8 : DForm_4<29, (outs G8RC:$dst), (ins G8RC:$src1, u16imm:$src2),
338                      "andis. $dst, $src1, $src2", IntGeneral,
339                     [(set i64:$dst, (and i64:$src1, imm16ShiftedZExt:$src2))]>,
340                      isDOT;
341 def ORI8    : DForm_4<24, (outs G8RC:$dst), (ins G8RC:$src1, u16imm:$src2),
342                       "ori $dst, $src1, $src2", IntSimple,
343                       [(set i64:$dst, (or i64:$src1, immZExt16:$src2))]>;
344 def ORIS8   : DForm_4<25, (outs G8RC:$dst), (ins G8RC:$src1, u16imm:$src2),
345                       "oris $dst, $src1, $src2", IntSimple,
346                     [(set i64:$dst, (or i64:$src1, imm16ShiftedZExt:$src2))]>;
347 def XORI8   : DForm_4<26, (outs G8RC:$dst), (ins G8RC:$src1, u16imm:$src2),
348                       "xori $dst, $src1, $src2", IntSimple,
349                       [(set i64:$dst, (xor i64:$src1, immZExt16:$src2))]>;
350 def XORIS8  : DForm_4<27, (outs G8RC:$dst), (ins G8RC:$src1, u16imm:$src2),
351                       "xoris $dst, $src1, $src2", IntSimple,
352                    [(set i64:$dst, (xor i64:$src1, imm16ShiftedZExt:$src2))]>;
353
354 def ADD8  : XOForm_1<31, 266, 0, (outs G8RC:$rT), (ins G8RC:$rA, G8RC:$rB),
355                      "add $rT, $rA, $rB", IntSimple,
356                      [(set i64:$rT, (add i64:$rA, i64:$rB))]>;
357 // ADD8 has a special form: reg = ADD8(reg, sym@tls) for use by the
358 // initial-exec thread-local storage model.
359 let isCodeGenOnly = 1 in
360 def ADD8TLS  : XOForm_1<31, 266, 0, (outs G8RC:$rT), (ins G8RC:$rA, tlsreg:$rB),
361                         "add $rT, $rA, $rB@tls", IntSimple,
362                         [(set i64:$rT, (add i64:$rA, tglobaltlsaddr:$rB))]>;
363                      
364 let Defs = [CARRY] in {
365 def ADDC8 : XOForm_1<31, 10, 0, (outs G8RC:$rT), (ins G8RC:$rA, G8RC:$rB),
366                      "addc $rT, $rA, $rB", IntGeneral,
367                      [(set i64:$rT, (addc i64:$rA, i64:$rB))]>,
368                      PPC970_DGroup_Cracked;
369 def ADDIC8 : DForm_2<12, (outs G8RC:$rD), (ins G8RC:$rA, s16imm64:$imm),
370                      "addic $rD, $rA, $imm", IntGeneral,
371                      [(set i64:$rD, (addc i64:$rA, immSExt16:$imm))]>;
372 }
373 def ADDI8  : DForm_2<14, (outs G8RC:$rD), (ins G8RC_NOX0:$rA, symbolLo64:$imm),
374                      "addi $rD, $rA, $imm", IntSimple,
375                      [(set i64:$rD, (add i64:$rA, immSExt16:$imm))]>;
376 def ADDIS8 : DForm_2<15, (outs G8RC:$rD), (ins G8RC_NOX0:$rA, symbolHi64:$imm),
377                      "addis $rD, $rA, $imm", IntSimple,
378                      [(set i64:$rD, (add i64:$rA, imm16ShiftedSExt:$imm))]>;
379
380 let Defs = [CARRY] in {
381 def SUBFIC8: DForm_2< 8, (outs G8RC:$rD), (ins G8RC:$rA, s16imm64:$imm),
382                      "subfic $rD, $rA, $imm", IntGeneral,
383                      [(set i64:$rD, (subc immSExt16:$imm, i64:$rA))]>;
384 def SUBFC8 : XOForm_1<31, 8, 0, (outs G8RC:$rT), (ins G8RC:$rA, G8RC:$rB),
385                       "subfc $rT, $rA, $rB", IntGeneral,
386                       [(set i64:$rT, (subc i64:$rB, i64:$rA))]>,
387                       PPC970_DGroup_Cracked;
388 }
389 def SUBF8 : XOForm_1<31, 40, 0, (outs G8RC:$rT), (ins G8RC:$rA, G8RC:$rB),
390                      "subf $rT, $rA, $rB", IntGeneral,
391                      [(set i64:$rT, (sub i64:$rB, i64:$rA))]>;
392 def NEG8    : XOForm_3<31, 104, 0, (outs G8RC:$rT), (ins G8RC:$rA),
393                        "neg $rT, $rA", IntSimple,
394                        [(set i64:$rT, (ineg i64:$rA))]>;
395 let Uses = [CARRY], Defs = [CARRY] in {
396 def ADDE8   : XOForm_1<31, 138, 0, (outs G8RC:$rT), (ins G8RC:$rA, G8RC:$rB),
397                        "adde $rT, $rA, $rB", IntGeneral,
398                        [(set i64:$rT, (adde i64:$rA, i64:$rB))]>;
399 def ADDME8  : XOForm_3<31, 234, 0, (outs G8RC:$rT), (ins G8RC:$rA),
400                        "addme $rT, $rA", IntGeneral,
401                        [(set i64:$rT, (adde i64:$rA, -1))]>;
402 def ADDZE8  : XOForm_3<31, 202, 0, (outs G8RC:$rT), (ins G8RC:$rA),
403                        "addze $rT, $rA", IntGeneral,
404                        [(set i64:$rT, (adde i64:$rA, 0))]>;
405 def SUBFE8  : XOForm_1<31, 136, 0, (outs G8RC:$rT), (ins G8RC:$rA, G8RC:$rB),
406                        "subfe $rT, $rA, $rB", IntGeneral,
407                        [(set i64:$rT, (sube i64:$rB, i64:$rA))]>;
408 def SUBFME8 : XOForm_3<31, 232, 0, (outs G8RC:$rT), (ins G8RC:$rA),
409                        "subfme $rT, $rA", IntGeneral,
410                        [(set i64:$rT, (sube -1, i64:$rA))]>;
411 def SUBFZE8 : XOForm_3<31, 200, 0, (outs G8RC:$rT), (ins G8RC:$rA),
412                        "subfze $rT, $rA", IntGeneral,
413                        [(set i64:$rT, (sube 0, i64:$rA))]>;
414 }
415
416
417 def MULHD : XOForm_1<31, 73, 0, (outs G8RC:$rT), (ins G8RC:$rA, G8RC:$rB),
418                      "mulhd $rT, $rA, $rB", IntMulHW,
419                      [(set i64:$rT, (mulhs i64:$rA, i64:$rB))]>;
420 def MULHDU : XOForm_1<31, 9, 0, (outs G8RC:$rT), (ins G8RC:$rA, G8RC:$rB),
421                      "mulhdu $rT, $rA, $rB", IntMulHWU,
422                      [(set i64:$rT, (mulhu i64:$rA, i64:$rB))]>;
423
424 def CMPD   : XForm_16_ext<31, 0, (outs CRRC:$crD), (ins G8RC:$rA, G8RC:$rB),
425                           "cmpd $crD, $rA, $rB", IntCompare>, isPPC64;
426 def CMPLD  : XForm_16_ext<31, 32, (outs CRRC:$crD), (ins G8RC:$rA, G8RC:$rB),
427                           "cmpld $crD, $rA, $rB", IntCompare>, isPPC64;
428 def CMPDI  : DForm_5_ext<11, (outs CRRC:$crD), (ins G8RC:$rA, s16imm:$imm),
429                          "cmpdi $crD, $rA, $imm", IntCompare>, isPPC64;
430 def CMPLDI : DForm_6_ext<10, (outs CRRC:$dst), (ins G8RC:$src1, u16imm:$src2),
431                          "cmpldi $dst, $src1, $src2", IntCompare>, isPPC64;
432
433 def SLD  : XForm_6<31,  27, (outs G8RC:$rA), (ins G8RC:$rS, GPRC:$rB),
434                    "sld $rA, $rS, $rB", IntRotateD,
435                    [(set i64:$rA, (PPCshl i64:$rS, i32:$rB))]>, isPPC64;
436 def SRD  : XForm_6<31, 539, (outs G8RC:$rA), (ins G8RC:$rS, GPRC:$rB),
437                    "srd $rA, $rS, $rB", IntRotateD,
438                    [(set i64:$rA, (PPCsrl i64:$rS, i32:$rB))]>, isPPC64;
439 let Defs = [CARRY] in {
440 def SRAD : XForm_6<31, 794, (outs G8RC:$rA), (ins G8RC:$rS, GPRC:$rB),
441                    "srad $rA, $rS, $rB", IntRotateD,
442                    [(set i64:$rA, (PPCsra i64:$rS, i32:$rB))]>, isPPC64;
443 }
444                    
445 def EXTSB8 : XForm_11<31, 954, (outs G8RC:$rA), (ins G8RC:$rS),
446                       "extsb $rA, $rS", IntSimple,
447                       [(set i64:$rA, (sext_inreg i64:$rS, i8))]>;
448 def EXTSH8 : XForm_11<31, 922, (outs G8RC:$rA), (ins G8RC:$rS),
449                       "extsh $rA, $rS", IntSimple,
450                       [(set i64:$rA, (sext_inreg i64:$rS, i16))]>;
451
452 def EXTSW  : XForm_11<31, 986, (outs G8RC:$rA), (ins G8RC:$rS),
453                       "extsw $rA, $rS", IntSimple,
454                       [(set i64:$rA, (sext_inreg i64:$rS, i32))]>, isPPC64;
455 def EXTSW_32_64 : XForm_11<31, 986, (outs G8RC:$rA), (ins GPRC:$rS),
456                       "extsw $rA, $rS", IntSimple,
457                       [(set i64:$rA, (sext i32:$rS))]>, isPPC64;
458
459 let Defs = [CARRY] in {
460 def SRADI  : XSForm_1<31, 413, (outs G8RC:$rA), (ins G8RC:$rS, u6imm:$SH),
461                       "sradi $rA, $rS, $SH", IntRotateDI,
462                       [(set i64:$rA, (sra i64:$rS, (i32 imm:$SH)))]>, isPPC64;
463 }
464 def CNTLZD : XForm_11<31, 58, (outs G8RC:$rA), (ins G8RC:$rS),
465                       "cntlzd $rA, $rS", IntGeneral,
466                       [(set i64:$rA, (ctlz i64:$rS))]>;
467 def POPCNTD : XForm_11<31, 506, (outs G8RC:$rA), (ins G8RC:$rS),
468                       "popcntd $rA, $rS", IntGeneral,
469                       [(set i64:$rA, (ctpop i64:$rS))]>;
470
471 // popcntw also does a population count on the high 32 bits (storing the
472 // results in the high 32-bits of the output). We'll ignore that here (which is
473 // safe because we never separately use the high part of the 64-bit registers).
474 def POPCNTW : XForm_11<31, 378, (outs GPRC:$rA), (ins GPRC:$rS),
475                       "popcntw $rA, $rS", IntGeneral,
476                       [(set i32:$rA, (ctpop i32:$rS))]>;
477
478 def DIVD  : XOForm_1<31, 489, 0, (outs G8RC:$rT), (ins G8RC:$rA, G8RC:$rB),
479                      "divd $rT, $rA, $rB", IntDivD,
480                      [(set i64:$rT, (sdiv i64:$rA, i64:$rB))]>, isPPC64,
481                      PPC970_DGroup_First, PPC970_DGroup_Cracked;
482 def DIVDU : XOForm_1<31, 457, 0, (outs G8RC:$rT), (ins G8RC:$rA, G8RC:$rB),
483                      "divdu $rT, $rA, $rB", IntDivD,
484                      [(set i64:$rT, (udiv i64:$rA, i64:$rB))]>, isPPC64,
485                      PPC970_DGroup_First, PPC970_DGroup_Cracked;
486 def MULLD : XOForm_1<31, 233, 0, (outs G8RC:$rT), (ins G8RC:$rA, G8RC:$rB),
487                      "mulld $rT, $rA, $rB", IntMulHD,
488                      [(set i64:$rT, (mul i64:$rA, i64:$rB))]>, isPPC64;
489
490
491 let isCommutable = 1 in {
492 def RLDIMI : MDForm_1<30, 3,
493                       (outs G8RC:$rA), (ins G8RC:$rSi, G8RC:$rS, u6imm:$SH, u6imm:$MB),
494                       "rldimi $rA, $rS, $SH, $MB", IntRotateDI,
495                       []>, isPPC64, RegConstraint<"$rSi = $rA">,
496                       NoEncode<"$rSi">;
497 }
498
499 // Rotate instructions.
500 def RLDCL  : MDForm_1<30, 0,
501                       (outs G8RC:$rA), (ins G8RC:$rS, GPRC:$rB, u6imm:$MBE),
502                       "rldcl $rA, $rS, $rB, $MBE", IntRotateD,
503                       []>, isPPC64;
504 def RLDICL : MDForm_1<30, 0,
505                       (outs G8RC:$rA), (ins G8RC:$rS, u6imm:$SH, u6imm:$MBE),
506                       "rldicl $rA, $rS, $SH, $MBE", IntRotateDI,
507                       []>, isPPC64;
508 def RLDICR : MDForm_1<30, 1,
509                       (outs G8RC:$rA), (ins G8RC:$rS, u6imm:$SH, u6imm:$MBE),
510                       "rldicr $rA, $rS, $SH, $MBE", IntRotateDI,
511                       []>, isPPC64;
512
513 def RLWINM8 : MForm_2<21,
514                      (outs G8RC:$rA), (ins G8RC:$rS, u5imm:$SH, u5imm:$MB, u5imm:$ME),
515                      "rlwinm $rA, $rS, $SH, $MB, $ME", IntGeneral,
516                      []>;
517
518 def ISEL8   : AForm_4<31, 15,
519                      (outs G8RC:$rT), (ins G8RC_NOX0:$rA, G8RC:$rB, CRBITRC:$cond),
520                      "isel $rT, $rA, $rB, $cond", IntGeneral,
521                      []>;
522 }  // End FXU Operations.
523
524
525 //===----------------------------------------------------------------------===//
526 // Load/Store instructions.
527 //
528
529
530 // Sign extending loads.
531 let canFoldAsLoad = 1, PPC970_Unit = 2 in {
532 def LHA8: DForm_1<42, (outs G8RC:$rD), (ins memri:$src),
533                   "lha $rD, $src", LdStLHA,
534                   [(set i64:$rD, (sextloadi16 iaddr:$src))]>,
535                   PPC970_DGroup_Cracked;
536 def LWA  : DSForm_1<58, 2, (outs G8RC:$rD), (ins memrix:$src),
537                     "lwa $rD, $src", LdStLWA,
538                     [(set i64:$rD,
539                           (aligned4sextloadi32 ixaddr:$src))]>, isPPC64,
540                     PPC970_DGroup_Cracked;
541 def LHAX8: XForm_1<31, 343, (outs G8RC:$rD), (ins memrr:$src),
542                    "lhax $rD, $src", LdStLHA,
543                    [(set i64:$rD, (sextloadi16 xaddr:$src))]>,
544                    PPC970_DGroup_Cracked;
545 def LWAX : XForm_1<31, 341, (outs G8RC:$rD), (ins memrr:$src),
546                    "lwax $rD, $src", LdStLHA,
547                    [(set i64:$rD, (sextloadi32 xaddr:$src))]>, isPPC64,
548                    PPC970_DGroup_Cracked;
549
550 // Update forms.
551 let mayLoad = 1 in {
552 def LHAU8 : DForm_1<43, (outs G8RC:$rD, ptr_rc_nor0:$ea_result),
553                     (ins memri:$addr),
554                     "lhau $rD, $addr", LdStLHAU,
555                     []>, RegConstraint<"$addr.reg = $ea_result">,
556                     NoEncode<"$ea_result">;
557 // NO LWAU!
558
559 def LHAUX8 : XForm_1<31, 375, (outs G8RC:$rD, ptr_rc_nor0:$ea_result),
560                     (ins memrr:$addr),
561                     "lhaux $rD, $addr", LdStLHAU,
562                     []>, RegConstraint<"$addr.ptrreg = $ea_result">,
563                     NoEncode<"$ea_result">;
564 def LWAUX : XForm_1<31, 373, (outs G8RC:$rD, ptr_rc_nor0:$ea_result),
565                     (ins memrr:$addr),
566                     "lwaux $rD, $addr", LdStLHAU,
567                     []>, RegConstraint<"$addr.ptrreg = $ea_result">,
568                     NoEncode<"$ea_result">, isPPC64;
569 }
570 }
571
572 // Zero extending loads.
573 let canFoldAsLoad = 1, PPC970_Unit = 2 in {
574 def LBZ8 : DForm_1<34, (outs G8RC:$rD), (ins memri:$src),
575                   "lbz $rD, $src", LdStLoad,
576                   [(set i64:$rD, (zextloadi8 iaddr:$src))]>;
577 def LHZ8 : DForm_1<40, (outs G8RC:$rD), (ins memri:$src),
578                   "lhz $rD, $src", LdStLoad,
579                   [(set i64:$rD, (zextloadi16 iaddr:$src))]>;
580 def LWZ8 : DForm_1<32, (outs G8RC:$rD), (ins memri:$src),
581                   "lwz $rD, $src", LdStLoad,
582                   [(set i64:$rD, (zextloadi32 iaddr:$src))]>, isPPC64;
583
584 def LBZX8 : XForm_1<31,  87, (outs G8RC:$rD), (ins memrr:$src),
585                    "lbzx $rD, $src", LdStLoad,
586                    [(set i64:$rD, (zextloadi8 xaddr:$src))]>;
587 def LHZX8 : XForm_1<31, 279, (outs G8RC:$rD), (ins memrr:$src),
588                    "lhzx $rD, $src", LdStLoad,
589                    [(set i64:$rD, (zextloadi16 xaddr:$src))]>;
590 def LWZX8 : XForm_1<31,  23, (outs G8RC:$rD), (ins memrr:$src),
591                    "lwzx $rD, $src", LdStLoad,
592                    [(set i64:$rD, (zextloadi32 xaddr:$src))]>;
593                    
594                    
595 // Update forms.
596 let mayLoad = 1 in {
597 def LBZU8 : DForm_1<35, (outs G8RC:$rD, ptr_rc_nor0:$ea_result), (ins memri:$addr),
598                     "lbzu $rD, $addr", LdStLoadUpd,
599                     []>, RegConstraint<"$addr.reg = $ea_result">,
600                     NoEncode<"$ea_result">;
601 def LHZU8 : DForm_1<41, (outs G8RC:$rD, ptr_rc_nor0:$ea_result), (ins memri:$addr),
602                     "lhzu $rD, $addr", LdStLoadUpd,
603                     []>, RegConstraint<"$addr.reg = $ea_result">,
604                     NoEncode<"$ea_result">;
605 def LWZU8 : DForm_1<33, (outs G8RC:$rD, ptr_rc_nor0:$ea_result), (ins memri:$addr),
606                     "lwzu $rD, $addr", LdStLoadUpd,
607                     []>, RegConstraint<"$addr.reg = $ea_result">,
608                     NoEncode<"$ea_result">;
609
610 def LBZUX8 : XForm_1<31, 119, (outs G8RC:$rD, ptr_rc_nor0:$ea_result),
611                    (ins memrr:$addr),
612                    "lbzux $rD, $addr", LdStLoadUpd,
613                    []>, RegConstraint<"$addr.ptrreg = $ea_result">,
614                    NoEncode<"$ea_result">;
615 def LHZUX8 : XForm_1<31, 311, (outs G8RC:$rD, ptr_rc_nor0:$ea_result),
616                    (ins memrr:$addr),
617                    "lhzux $rD, $addr", LdStLoadUpd,
618                    []>, RegConstraint<"$addr.ptrreg = $ea_result">,
619                    NoEncode<"$ea_result">;
620 def LWZUX8 : XForm_1<31, 55, (outs G8RC:$rD, ptr_rc_nor0:$ea_result),
621                    (ins memrr:$addr),
622                    "lwzux $rD, $addr", LdStLoadUpd,
623                    []>, RegConstraint<"$addr.ptrreg = $ea_result">,
624                    NoEncode<"$ea_result">;
625 }
626 }
627
628
629 // Full 8-byte loads.
630 let canFoldAsLoad = 1, PPC970_Unit = 2 in {
631 def LD   : DSForm_1<58, 0, (outs G8RC:$rD), (ins memrix:$src),
632                     "ld $rD, $src", LdStLD,
633                     [(set i64:$rD, (aligned4load ixaddr:$src))]>, isPPC64;
634 // The following three definitions are selected for small code model only.
635 // Otherwise, we need to create two instructions to form a 32-bit offset,
636 // so we have a custom matcher for TOC_ENTRY in PPCDAGToDAGIsel::Select().
637 def LDtoc: Pseudo<(outs G8RC:$rD), (ins tocentry:$disp, G8RC:$reg),
638                   "#LDtoc",
639                   [(set i64:$rD,
640                      (PPCtoc_entry tglobaladdr:$disp, i64:$reg))]>, isPPC64;
641 def LDtocJTI: Pseudo<(outs G8RC:$rD), (ins tocentry:$disp, G8RC:$reg),
642                   "#LDtocJTI",
643                   [(set i64:$rD,
644                      (PPCtoc_entry tjumptable:$disp, i64:$reg))]>, isPPC64;
645 def LDtocCPT: Pseudo<(outs G8RC:$rD), (ins tocentry:$disp, G8RC:$reg),
646                   "#LDtocCPT",
647                   [(set i64:$rD,
648                      (PPCtoc_entry tconstpool:$disp, i64:$reg))]>, isPPC64;
649
650 let hasSideEffects = 1, isCodeGenOnly = 1 in {
651 let RST = 2, DS = 2 in
652 def LDinto_toc: DSForm_1a<58, 0, (outs), (ins G8RC:$reg),
653                     "ld 2, 8($reg)", LdStLD,
654                     [(PPCload_toc i64:$reg)]>, isPPC64;
655                     
656 let RST = 2, DS = 10, RA = 1 in
657 def LDtoc_restore : DSForm_1a<58, 0, (outs), (ins),
658                     "ld 2, 40(1)", LdStLD,
659                     [(PPCtoc_restore)]>, isPPC64;
660 }
661 def LDX  : XForm_1<31,  21, (outs G8RC:$rD), (ins memrr:$src),
662                    "ldx $rD, $src", LdStLD,
663                    [(set i64:$rD, (load xaddr:$src))]>, isPPC64;
664 def LDBRX : XForm_1<31,  532, (outs G8RC:$rD), (ins memrr:$src),
665                    "ldbrx $rD, $src", LdStLoad,
666                    [(set i64:$rD, (PPClbrx xoaddr:$src, i64))]>, isPPC64;
667
668 let mayLoad = 1 in
669 def LDU  : DSForm_1<58, 1, (outs G8RC:$rD, ptr_rc_nor0:$ea_result), (ins memrix:$addr),
670                     "ldu $rD, $addr", LdStLDU,
671                     []>, RegConstraint<"$addr.reg = $ea_result">, isPPC64,
672                     NoEncode<"$ea_result">;
673
674 def LDUX : XForm_1<31, 53, (outs G8RC:$rD, ptr_rc_nor0:$ea_result),
675                    (ins memrr:$addr),
676                    "ldux $rD, $addr", LdStLDU,
677                    []>, RegConstraint<"$addr.ptrreg = $ea_result">,
678                    NoEncode<"$ea_result">, isPPC64;
679 }
680
681 def : Pat<(PPCload ixaddr:$src),
682           (LD ixaddr:$src)>;
683 def : Pat<(PPCload xaddr:$src),
684           (LDX xaddr:$src)>;
685
686 // Support for medium and large code model.
687 def ADDIStocHA: Pseudo<(outs G8RC:$rD), (ins G8RC_NOX0:$reg, tocentry:$disp),
688                        "#ADDIStocHA",
689                        [(set i64:$rD,
690                          (PPCaddisTocHA i64:$reg, tglobaladdr:$disp))]>,
691                        isPPC64;
692 def LDtocL: Pseudo<(outs G8RC:$rD), (ins tocentry:$disp, G8RC_NOX0:$reg),
693                    "#LDtocL",
694                    [(set i64:$rD,
695                      (PPCldTocL tglobaladdr:$disp, i64:$reg))]>, isPPC64;
696 def ADDItocL: Pseudo<(outs G8RC:$rD), (ins G8RC_NOX0:$reg, tocentry:$disp),
697                      "#ADDItocL",
698                      [(set i64:$rD,
699                        (PPCaddiTocL i64:$reg, tglobaladdr:$disp))]>, isPPC64;
700
701 // Support for thread-local storage.
702 def ADDISgotTprelHA: Pseudo<(outs G8RC:$rD), (ins G8RC_NOX0:$reg, symbolHi64:$disp),
703                          "#ADDISgotTprelHA",
704                          [(set i64:$rD,
705                            (PPCaddisGotTprelHA i64:$reg,
706                                                tglobaltlsaddr:$disp))]>,
707                   isPPC64;
708 def LDgotTprelL: Pseudo<(outs G8RC:$rD), (ins symbolLo64:$disp, G8RC_NOX0:$reg),
709                         "#LDgotTprelL",
710                         [(set i64:$rD,
711                           (PPCldGotTprelL tglobaltlsaddr:$disp, i64:$reg))]>,
712                  isPPC64;
713 def : Pat<(PPCaddTls i64:$in, tglobaltlsaddr:$g),
714           (ADD8TLS $in, tglobaltlsaddr:$g)>;
715 def ADDIStlsgdHA: Pseudo<(outs G8RC:$rD), (ins G8RC_NOX0:$reg, symbolHi64:$disp),
716                          "#ADDIStlsgdHA",
717                          [(set i64:$rD,
718                            (PPCaddisTlsgdHA i64:$reg, tglobaltlsaddr:$disp))]>,
719                   isPPC64;
720 def ADDItlsgdL : Pseudo<(outs G8RC:$rD), (ins G8RC_NOX0:$reg, symbolLo64:$disp),
721                        "#ADDItlsgdL",
722                        [(set i64:$rD,
723                          (PPCaddiTlsgdL i64:$reg, tglobaltlsaddr:$disp))]>,
724                  isPPC64;
725 def GETtlsADDR : Pseudo<(outs G8RC:$rD), (ins G8RC:$reg, tlsgd:$sym),
726                         "#GETtlsADDR",
727                         [(set i64:$rD,
728                           (PPCgetTlsAddr i64:$reg, tglobaltlsaddr:$sym))]>,
729                  isPPC64;
730 def ADDIStlsldHA: Pseudo<(outs G8RC:$rD), (ins G8RC_NOX0:$reg, symbolHi64:$disp),
731                          "#ADDIStlsldHA",
732                          [(set i64:$rD,
733                            (PPCaddisTlsldHA i64:$reg, tglobaltlsaddr:$disp))]>,
734                   isPPC64;
735 def ADDItlsldL : Pseudo<(outs G8RC:$rD), (ins G8RC_NOX0:$reg, symbolLo64:$disp),
736                        "#ADDItlsldL",
737                        [(set i64:$rD,
738                          (PPCaddiTlsldL i64:$reg, tglobaltlsaddr:$disp))]>,
739                  isPPC64;
740 def GETtlsldADDR : Pseudo<(outs G8RC:$rD), (ins G8RC:$reg, tlsgd:$sym),
741                           "#GETtlsldADDR",
742                           [(set i64:$rD,
743                             (PPCgetTlsldAddr i64:$reg, tglobaltlsaddr:$sym))]>,
744                    isPPC64;
745 def ADDISdtprelHA: Pseudo<(outs G8RC:$rD), (ins G8RC_NOX0:$reg, symbolHi64:$disp),
746                           "#ADDISdtprelHA",
747                           [(set i64:$rD,
748                             (PPCaddisDtprelHA i64:$reg,
749                                               tglobaltlsaddr:$disp))]>,
750                    isPPC64;
751 def ADDIdtprelL : Pseudo<(outs G8RC:$rD), (ins G8RC_NOX0:$reg, symbolLo64:$disp),
752                          "#ADDIdtprelL",
753                          [(set i64:$rD,
754                            (PPCaddiDtprelL i64:$reg, tglobaltlsaddr:$disp))]>,
755                   isPPC64;
756
757 let PPC970_Unit = 2 in {
758 // Truncating stores.                       
759 def STB8 : DForm_1<38, (outs), (ins G8RC:$rS, memri:$src),
760                    "stb $rS, $src", LdStStore,
761                    [(truncstorei8 i64:$rS, iaddr:$src)]>;
762 def STH8 : DForm_1<44, (outs), (ins G8RC:$rS, memri:$src),
763                    "sth $rS, $src", LdStStore,
764                    [(truncstorei16 i64:$rS, iaddr:$src)]>;
765 def STW8 : DForm_1<36, (outs), (ins G8RC:$rS, memri:$src),
766                    "stw $rS, $src", LdStStore,
767                    [(truncstorei32 i64:$rS, iaddr:$src)]>;
768 def STBX8 : XForm_8<31, 215, (outs), (ins G8RC:$rS, memrr:$dst),
769                    "stbx $rS, $dst", LdStStore,
770                    [(truncstorei8 i64:$rS, xaddr:$dst)]>,
771                    PPC970_DGroup_Cracked;
772 def STHX8 : XForm_8<31, 407, (outs), (ins G8RC:$rS, memrr:$dst),
773                    "sthx $rS, $dst", LdStStore,
774                    [(truncstorei16 i64:$rS, xaddr:$dst)]>,
775                    PPC970_DGroup_Cracked;
776 def STWX8 : XForm_8<31, 151, (outs), (ins G8RC:$rS, memrr:$dst),
777                    "stwx $rS, $dst", LdStStore,
778                    [(truncstorei32 i64:$rS, xaddr:$dst)]>,
779                    PPC970_DGroup_Cracked;
780 // Normal 8-byte stores.
781 def STD  : DSForm_1<62, 0, (outs), (ins G8RC:$rS, memrix:$dst),
782                     "std $rS, $dst", LdStSTD,
783                     [(aligned4store i64:$rS, ixaddr:$dst)]>, isPPC64;
784 def STDX  : XForm_8<31, 149, (outs), (ins G8RC:$rS, memrr:$dst),
785                    "stdx $rS, $dst", LdStSTD,
786                    [(store i64:$rS, xaddr:$dst)]>, isPPC64,
787                    PPC970_DGroup_Cracked;
788 def STDBRX: XForm_8<31, 660, (outs), (ins G8RC:$rS, memrr:$dst),
789                    "stdbrx $rS, $dst", LdStStore,
790                    [(PPCstbrx i64:$rS, xoaddr:$dst, i64)]>, isPPC64,
791                    PPC970_DGroup_Cracked;
792 }
793
794 // Stores with Update (pre-inc).
795 let PPC970_Unit = 2, mayStore = 1 in {
796 def STBU8 : DForm_1<39, (outs ptr_rc_nor0:$ea_res), (ins G8RC:$rS, memri:$dst),
797                    "stbu $rS, $dst", LdStStoreUpd, []>,
798                    RegConstraint<"$dst.reg = $ea_res">, NoEncode<"$ea_res">;
799 def STHU8 : DForm_1<45, (outs ptr_rc_nor0:$ea_res), (ins G8RC:$rS, memri:$dst),
800                    "sthu $rS, $dst", LdStStoreUpd, []>,
801                    RegConstraint<"$dst.reg = $ea_res">, NoEncode<"$ea_res">;
802 def STWU8 : DForm_1<37, (outs ptr_rc_nor0:$ea_res), (ins G8RC:$rS, memri:$dst),
803                    "stwu $rS, $dst", LdStStoreUpd, []>,
804                    RegConstraint<"$dst.reg = $ea_res">, NoEncode<"$ea_res">;
805 def STDU : DSForm_1<62, 1, (outs ptr_rc_nor0:$ea_res), (ins G8RC:$rS, memrix:$dst),
806                    "stdu $rS, $dst", LdStSTDU, []>,
807                    RegConstraint<"$dst.reg = $ea_res">, NoEncode<"$ea_res">,
808                    isPPC64;
809
810 def STBUX8: XForm_8<31, 247, (outs ptr_rc_nor0:$ea_res), (ins G8RC:$rS, memrr:$dst),
811                     "stbux $rS, $dst", LdStStoreUpd, []>,
812                     RegConstraint<"$dst.ptrreg = $ea_res">, NoEncode<"$ea_res">,
813                     PPC970_DGroup_Cracked;
814 def STHUX8: XForm_8<31, 439, (outs ptr_rc_nor0:$ea_res), (ins G8RC:$rS, memrr:$dst),
815                     "sthux $rS, $dst", LdStStoreUpd, []>,
816                     RegConstraint<"$dst.ptrreg = $ea_res">, NoEncode<"$ea_res">,
817                     PPC970_DGroup_Cracked;
818 def STWUX8: XForm_8<31, 183, (outs ptr_rc_nor0:$ea_res), (ins G8RC:$rS, memrr:$dst),
819                     "stwux $rS, $dst", LdStStoreUpd, []>,
820                     RegConstraint<"$dst.ptrreg = $ea_res">, NoEncode<"$ea_res">,
821                     PPC970_DGroup_Cracked;
822 def STDUX : XForm_8<31, 181, (outs ptr_rc_nor0:$ea_res), (ins G8RC:$rS, memrr:$dst),
823                     "stdux $rS, $dst", LdStSTDU, []>,
824                     RegConstraint<"$dst.ptrreg = $ea_res">, NoEncode<"$ea_res">,
825                     PPC970_DGroup_Cracked, isPPC64;
826 }
827
828 // Patterns to match the pre-inc stores.  We can't put the patterns on
829 // the instruction definitions directly as ISel wants the address base
830 // and offset to be separate operands, not a single complex operand.
831 def : Pat<(pre_truncsti8 i64:$rS, iPTR:$ptrreg, iaddroff:$ptroff),
832           (STBU8 $rS, iaddroff:$ptroff, $ptrreg)>;
833 def : Pat<(pre_truncsti16 i64:$rS, iPTR:$ptrreg, iaddroff:$ptroff),
834           (STHU8 $rS, iaddroff:$ptroff, $ptrreg)>;
835 def : Pat<(pre_truncsti32 i64:$rS, iPTR:$ptrreg, iaddroff:$ptroff),
836           (STWU8 $rS, iaddroff:$ptroff, $ptrreg)>;
837 def : Pat<(aligned4pre_store i64:$rS, iPTR:$ptrreg, iaddroff:$ptroff),
838           (STDU $rS, iaddroff:$ptroff, $ptrreg)>;
839
840 def : Pat<(pre_truncsti8 i64:$rS, iPTR:$ptrreg, iPTR:$ptroff),
841           (STBUX8 $rS, $ptrreg, $ptroff)>;
842 def : Pat<(pre_truncsti16 i64:$rS, iPTR:$ptrreg, iPTR:$ptroff),
843           (STHUX8 $rS, $ptrreg, $ptroff)>;
844 def : Pat<(pre_truncsti32 i64:$rS, iPTR:$ptrreg, iPTR:$ptroff),
845           (STWUX8 $rS, $ptrreg, $ptroff)>;
846 def : Pat<(pre_store i64:$rS, iPTR:$ptrreg, iPTR:$ptroff),
847           (STDUX $rS, $ptrreg, $ptroff)>;
848
849
850 //===----------------------------------------------------------------------===//
851 // Floating point instructions.
852 //
853
854
855 let PPC970_Unit = 3, Uses = [RM] in {  // FPU Operations.
856 def FCFID  : XForm_26<63, 846, (outs F8RC:$frD), (ins F8RC:$frB),
857                       "fcfid $frD, $frB", FPGeneral,
858                       [(set f64:$frD, (PPCfcfid f64:$frB))]>, isPPC64;
859 def FCTIDZ : XForm_26<63, 815, (outs F8RC:$frD), (ins F8RC:$frB),
860                       "fctidz $frD, $frB", FPGeneral,
861                       [(set f64:$frD, (PPCfctidz f64:$frB))]>, isPPC64;
862
863 def FCFIDU  : XForm_26<63, 974, (outs F8RC:$frD), (ins F8RC:$frB),
864                       "fcfidu $frD, $frB", FPGeneral,
865                       [(set f64:$frD, (PPCfcfidu f64:$frB))]>, isPPC64;
866 def FCFIDS  : XForm_26<59, 846, (outs F4RC:$frD), (ins F8RC:$frB),
867                       "fcfids $frD, $frB", FPGeneral,
868                       [(set f32:$frD, (PPCfcfids f64:$frB))]>, isPPC64;
869 def FCFIDUS : XForm_26<59, 974, (outs F4RC:$frD), (ins F8RC:$frB),
870                       "fcfidus $frD, $frB", FPGeneral,
871                       [(set f32:$frD, (PPCfcfidus f64:$frB))]>, isPPC64;
872 def FCTIDUZ : XForm_26<63, 943, (outs F8RC:$frD), (ins F8RC:$frB),
873                       "fctiduz $frD, $frB", FPGeneral,
874                       [(set f64:$frD, (PPCfctiduz f64:$frB))]>, isPPC64;
875 def FCTIWUZ : XForm_26<63, 143, (outs F8RC:$frD), (ins F8RC:$frB),
876                       "fctiwuz $frD, $frB", FPGeneral,
877                       [(set f64:$frD, (PPCfctiwuz f64:$frB))]>, isPPC64;
878 }
879
880
881 //===----------------------------------------------------------------------===//
882 // Instruction Patterns
883 //
884
885 // Extensions and truncates to/from 32-bit regs.
886 def : Pat<(i64 (zext i32:$in)),
887           (RLDICL (INSERT_SUBREG (i64 (IMPLICIT_DEF)), $in, sub_32),
888                   0, 32)>;
889 def : Pat<(i64 (anyext i32:$in)),
890           (INSERT_SUBREG (i64 (IMPLICIT_DEF)), $in, sub_32)>;
891 def : Pat<(i32 (trunc i64:$in)),
892           (EXTRACT_SUBREG $in, sub_32)>;
893
894 // Extending loads with i64 targets.
895 def : Pat<(zextloadi1 iaddr:$src),
896           (LBZ8 iaddr:$src)>;
897 def : Pat<(zextloadi1 xaddr:$src),
898           (LBZX8 xaddr:$src)>;
899 def : Pat<(extloadi1 iaddr:$src),
900           (LBZ8 iaddr:$src)>;
901 def : Pat<(extloadi1 xaddr:$src),
902           (LBZX8 xaddr:$src)>;
903 def : Pat<(extloadi8 iaddr:$src),
904           (LBZ8 iaddr:$src)>;
905 def : Pat<(extloadi8 xaddr:$src),
906           (LBZX8 xaddr:$src)>;
907 def : Pat<(extloadi16 iaddr:$src),
908           (LHZ8 iaddr:$src)>;
909 def : Pat<(extloadi16 xaddr:$src),
910           (LHZX8 xaddr:$src)>;
911 def : Pat<(extloadi32 iaddr:$src),
912           (LWZ8 iaddr:$src)>;
913 def : Pat<(extloadi32 xaddr:$src),
914           (LWZX8 xaddr:$src)>;
915
916 // Standard shifts.  These are represented separately from the real shifts above
917 // so that we can distinguish between shifts that allow 6-bit and 7-bit shift
918 // amounts.
919 def : Pat<(sra i64:$rS, i32:$rB),
920           (SRAD $rS, $rB)>;
921 def : Pat<(srl i64:$rS, i32:$rB),
922           (SRD $rS, $rB)>;
923 def : Pat<(shl i64:$rS, i32:$rB),
924           (SLD $rS, $rB)>;
925
926 // SHL/SRL
927 def : Pat<(shl i64:$in, (i32 imm:$imm)),
928           (RLDICR $in, imm:$imm, (SHL64 imm:$imm))>;
929 def : Pat<(srl i64:$in, (i32 imm:$imm)),
930           (RLDICL $in, (SRL64 imm:$imm), imm:$imm)>;
931
932 // ROTL
933 def : Pat<(rotl i64:$in, i32:$sh),
934           (RLDCL $in, $sh, 0)>;
935 def : Pat<(rotl i64:$in, (i32 imm:$imm)),
936           (RLDICL $in, imm:$imm, 0)>;
937
938 // Hi and Lo for Darwin Global Addresses.
939 def : Pat<(PPChi tglobaladdr:$in, 0), (LIS8 tglobaladdr:$in)>;
940 def : Pat<(PPClo tglobaladdr:$in, 0), (LI8  tglobaladdr:$in)>;
941 def : Pat<(PPChi tconstpool:$in , 0), (LIS8 tconstpool:$in)>;
942 def : Pat<(PPClo tconstpool:$in , 0), (LI8  tconstpool:$in)>;
943 def : Pat<(PPChi tjumptable:$in , 0), (LIS8 tjumptable:$in)>;
944 def : Pat<(PPClo tjumptable:$in , 0), (LI8  tjumptable:$in)>;
945 def : Pat<(PPChi tblockaddress:$in, 0), (LIS8 tblockaddress:$in)>;
946 def : Pat<(PPClo tblockaddress:$in, 0), (LI8  tblockaddress:$in)>;
947 def : Pat<(PPChi tglobaltlsaddr:$g, i64:$in),
948           (ADDIS8 $in, tglobaltlsaddr:$g)>;
949 def : Pat<(PPClo tglobaltlsaddr:$g, i64:$in),
950           (ADDI8 $in, tglobaltlsaddr:$g)>;
951 def : Pat<(add i64:$in, (PPChi tglobaladdr:$g, 0)),
952           (ADDIS8 $in, tglobaladdr:$g)>;
953 def : Pat<(add i64:$in, (PPChi tconstpool:$g, 0)),
954           (ADDIS8 $in, tconstpool:$g)>;
955 def : Pat<(add i64:$in, (PPChi tjumptable:$g, 0)),
956           (ADDIS8 $in, tjumptable:$g)>;
957 def : Pat<(add i64:$in, (PPChi tblockaddress:$g, 0)),
958           (ADDIS8 $in, tblockaddress:$g)>;
959
960 // Patterns to match r+r indexed loads and stores for
961 // addresses without at least 4-byte alignment.
962 def : Pat<(i64 (unaligned4sextloadi32 xoaddr:$src)),
963           (LWAX xoaddr:$src)>;
964 def : Pat<(i64 (unaligned4load xoaddr:$src)),
965           (LDX xoaddr:$src)>;
966 def : Pat<(unaligned4store i64:$rS, xoaddr:$dst),
967           (STDX $rS, xoaddr:$dst)>;
968