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