16b983f8a50e824a8e08618baaa6240b4fa72d36
[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 let isSelect = 1, neverHasSideEffects = 1 in
519 def ISEL8   : AForm_4<31, 15,
520                      (outs G8RC:$rT), (ins G8RC_NOX0:$rA, G8RC:$rB, CRBITRC:$cond),
521                      "isel $rT, $rA, $rB, $cond", IntGeneral,
522                      []>;
523 }  // End FXU Operations.
524
525
526 //===----------------------------------------------------------------------===//
527 // Load/Store instructions.
528 //
529
530
531 // Sign extending loads.
532 let canFoldAsLoad = 1, PPC970_Unit = 2 in {
533 def LHA8: DForm_1<42, (outs G8RC:$rD), (ins memri:$src),
534                   "lha $rD, $src", LdStLHA,
535                   [(set i64:$rD, (sextloadi16 iaddr:$src))]>,
536                   PPC970_DGroup_Cracked;
537 def LWA  : DSForm_1<58, 2, (outs G8RC:$rD), (ins memrix:$src),
538                     "lwa $rD, $src", LdStLWA,
539                     [(set i64:$rD,
540                           (aligned4sextloadi32 ixaddr:$src))]>, isPPC64,
541                     PPC970_DGroup_Cracked;
542 def LHAX8: XForm_1<31, 343, (outs G8RC:$rD), (ins memrr:$src),
543                    "lhax $rD, $src", LdStLHA,
544                    [(set i64:$rD, (sextloadi16 xaddr:$src))]>,
545                    PPC970_DGroup_Cracked;
546 def LWAX : XForm_1<31, 341, (outs G8RC:$rD), (ins memrr:$src),
547                    "lwax $rD, $src", LdStLHA,
548                    [(set i64:$rD, (sextloadi32 xaddr:$src))]>, isPPC64,
549                    PPC970_DGroup_Cracked;
550
551 // Update forms.
552 let mayLoad = 1 in {
553 def LHAU8 : DForm_1<43, (outs G8RC:$rD, ptr_rc_nor0:$ea_result),
554                     (ins memri:$addr),
555                     "lhau $rD, $addr", LdStLHAU,
556                     []>, RegConstraint<"$addr.reg = $ea_result">,
557                     NoEncode<"$ea_result">;
558 // NO LWAU!
559
560 def LHAUX8 : XForm_1<31, 375, (outs G8RC:$rD, ptr_rc_nor0:$ea_result),
561                     (ins memrr:$addr),
562                     "lhaux $rD, $addr", LdStLHAU,
563                     []>, RegConstraint<"$addr.ptrreg = $ea_result">,
564                     NoEncode<"$ea_result">;
565 def LWAUX : XForm_1<31, 373, (outs G8RC:$rD, ptr_rc_nor0:$ea_result),
566                     (ins memrr:$addr),
567                     "lwaux $rD, $addr", LdStLHAU,
568                     []>, RegConstraint<"$addr.ptrreg = $ea_result">,
569                     NoEncode<"$ea_result">, isPPC64;
570 }
571 }
572
573 // Zero extending loads.
574 let canFoldAsLoad = 1, PPC970_Unit = 2 in {
575 def LBZ8 : DForm_1<34, (outs G8RC:$rD), (ins memri:$src),
576                   "lbz $rD, $src", LdStLoad,
577                   [(set i64:$rD, (zextloadi8 iaddr:$src))]>;
578 def LHZ8 : DForm_1<40, (outs G8RC:$rD), (ins memri:$src),
579                   "lhz $rD, $src", LdStLoad,
580                   [(set i64:$rD, (zextloadi16 iaddr:$src))]>;
581 def LWZ8 : DForm_1<32, (outs G8RC:$rD), (ins memri:$src),
582                   "lwz $rD, $src", LdStLoad,
583                   [(set i64:$rD, (zextloadi32 iaddr:$src))]>, isPPC64;
584
585 def LBZX8 : XForm_1<31,  87, (outs G8RC:$rD), (ins memrr:$src),
586                    "lbzx $rD, $src", LdStLoad,
587                    [(set i64:$rD, (zextloadi8 xaddr:$src))]>;
588 def LHZX8 : XForm_1<31, 279, (outs G8RC:$rD), (ins memrr:$src),
589                    "lhzx $rD, $src", LdStLoad,
590                    [(set i64:$rD, (zextloadi16 xaddr:$src))]>;
591 def LWZX8 : XForm_1<31,  23, (outs G8RC:$rD), (ins memrr:$src),
592                    "lwzx $rD, $src", LdStLoad,
593                    [(set i64:$rD, (zextloadi32 xaddr:$src))]>;
594                    
595                    
596 // Update forms.
597 let mayLoad = 1, neverHasSideEffects = 1 in {
598 def LBZU8 : DForm_1<35, (outs G8RC:$rD, ptr_rc_nor0:$ea_result), (ins memri:$addr),
599                     "lbzu $rD, $addr", LdStLoadUpd,
600                     []>, RegConstraint<"$addr.reg = $ea_result">,
601                     NoEncode<"$ea_result">;
602 def LHZU8 : DForm_1<41, (outs G8RC:$rD, ptr_rc_nor0:$ea_result), (ins memri:$addr),
603                     "lhzu $rD, $addr", LdStLoadUpd,
604                     []>, RegConstraint<"$addr.reg = $ea_result">,
605                     NoEncode<"$ea_result">;
606 def LWZU8 : DForm_1<33, (outs G8RC:$rD, ptr_rc_nor0:$ea_result), (ins memri:$addr),
607                     "lwzu $rD, $addr", LdStLoadUpd,
608                     []>, RegConstraint<"$addr.reg = $ea_result">,
609                     NoEncode<"$ea_result">;
610
611 def LBZUX8 : XForm_1<31, 119, (outs G8RC:$rD, ptr_rc_nor0:$ea_result),
612                    (ins memrr:$addr),
613                    "lbzux $rD, $addr", LdStLoadUpd,
614                    []>, RegConstraint<"$addr.ptrreg = $ea_result">,
615                    NoEncode<"$ea_result">;
616 def LHZUX8 : XForm_1<31, 311, (outs G8RC:$rD, ptr_rc_nor0:$ea_result),
617                    (ins memrr:$addr),
618                    "lhzux $rD, $addr", LdStLoadUpd,
619                    []>, RegConstraint<"$addr.ptrreg = $ea_result">,
620                    NoEncode<"$ea_result">;
621 def LWZUX8 : XForm_1<31, 55, (outs G8RC:$rD, ptr_rc_nor0:$ea_result),
622                    (ins memrr:$addr),
623                    "lwzux $rD, $addr", LdStLoadUpd,
624                    []>, RegConstraint<"$addr.ptrreg = $ea_result">,
625                    NoEncode<"$ea_result">;
626 }
627 }
628
629
630 // Full 8-byte loads.
631 let canFoldAsLoad = 1, PPC970_Unit = 2 in {
632 def LD   : DSForm_1<58, 0, (outs G8RC:$rD), (ins memrix:$src),
633                     "ld $rD, $src", LdStLD,
634                     [(set i64:$rD, (aligned4load ixaddr:$src))]>, isPPC64;
635 // The following three definitions are selected for small code model only.
636 // Otherwise, we need to create two instructions to form a 32-bit offset,
637 // so we have a custom matcher for TOC_ENTRY in PPCDAGToDAGIsel::Select().
638 def LDtoc: Pseudo<(outs G8RC:$rD), (ins tocentry:$disp, G8RC:$reg),
639                   "#LDtoc",
640                   [(set i64:$rD,
641                      (PPCtoc_entry tglobaladdr:$disp, i64:$reg))]>, isPPC64;
642 def LDtocJTI: Pseudo<(outs G8RC:$rD), (ins tocentry:$disp, G8RC:$reg),
643                   "#LDtocJTI",
644                   [(set i64:$rD,
645                      (PPCtoc_entry tjumptable:$disp, i64:$reg))]>, isPPC64;
646 def LDtocCPT: Pseudo<(outs G8RC:$rD), (ins tocentry:$disp, G8RC:$reg),
647                   "#LDtocCPT",
648                   [(set i64:$rD,
649                      (PPCtoc_entry tconstpool:$disp, i64:$reg))]>, isPPC64;
650
651 let hasSideEffects = 1, isCodeGenOnly = 1 in {
652 let RST = 2, DS = 2 in
653 def LDinto_toc: DSForm_1a<58, 0, (outs), (ins G8RC:$reg),
654                     "ld 2, 8($reg)", LdStLD,
655                     [(PPCload_toc i64:$reg)]>, isPPC64;
656                     
657 let RST = 2, DS = 10, RA = 1 in
658 def LDtoc_restore : DSForm_1a<58, 0, (outs), (ins),
659                     "ld 2, 40(1)", LdStLD,
660                     [(PPCtoc_restore)]>, isPPC64;
661 }
662 def LDX  : XForm_1<31,  21, (outs G8RC:$rD), (ins memrr:$src),
663                    "ldx $rD, $src", LdStLD,
664                    [(set i64:$rD, (load xaddr:$src))]>, isPPC64;
665 def LDBRX : XForm_1<31,  532, (outs G8RC:$rD), (ins memrr:$src),
666                    "ldbrx $rD, $src", LdStLoad,
667                    [(set i64:$rD, (PPClbrx xoaddr:$src, i64))]>, isPPC64;
668
669 let mayLoad = 1, neverHasSideEffects = 1 in
670 def LDU  : DSForm_1<58, 1, (outs G8RC:$rD, ptr_rc_nor0:$ea_result), (ins memrix:$addr),
671                     "ldu $rD, $addr", LdStLDU,
672                     []>, RegConstraint<"$addr.reg = $ea_result">, isPPC64,
673                     NoEncode<"$ea_result">;
674
675 def LDUX : XForm_1<31, 53, (outs G8RC:$rD, ptr_rc_nor0:$ea_result),
676                    (ins memrr:$addr),
677                    "ldux $rD, $addr", LdStLDU,
678                    []>, RegConstraint<"$addr.ptrreg = $ea_result">,
679                    NoEncode<"$ea_result">, isPPC64;
680 }
681
682 def : Pat<(PPCload ixaddr:$src),
683           (LD ixaddr:$src)>;
684 def : Pat<(PPCload xaddr:$src),
685           (LDX xaddr:$src)>;
686
687 // Support for medium and large code model.
688 def ADDIStocHA: Pseudo<(outs G8RC:$rD), (ins G8RC_NOX0:$reg, tocentry:$disp),
689                        "#ADDIStocHA",
690                        [(set i64:$rD,
691                          (PPCaddisTocHA i64:$reg, tglobaladdr:$disp))]>,
692                        isPPC64;
693 def LDtocL: Pseudo<(outs G8RC:$rD), (ins tocentry:$disp, G8RC_NOX0:$reg),
694                    "#LDtocL",
695                    [(set i64:$rD,
696                      (PPCldTocL tglobaladdr:$disp, i64:$reg))]>, isPPC64;
697 def ADDItocL: Pseudo<(outs G8RC:$rD), (ins G8RC_NOX0:$reg, tocentry:$disp),
698                      "#ADDItocL",
699                      [(set i64:$rD,
700                        (PPCaddiTocL i64:$reg, tglobaladdr:$disp))]>, isPPC64;
701
702 // Support for thread-local storage.
703 def ADDISgotTprelHA: Pseudo<(outs G8RC:$rD), (ins G8RC_NOX0:$reg, symbolHi64:$disp),
704                          "#ADDISgotTprelHA",
705                          [(set i64:$rD,
706                            (PPCaddisGotTprelHA i64:$reg,
707                                                tglobaltlsaddr:$disp))]>,
708                   isPPC64;
709 def LDgotTprelL: Pseudo<(outs G8RC:$rD), (ins symbolLo64:$disp, G8RC_NOX0:$reg),
710                         "#LDgotTprelL",
711                         [(set i64:$rD,
712                           (PPCldGotTprelL tglobaltlsaddr:$disp, i64:$reg))]>,
713                  isPPC64;
714 def : Pat<(PPCaddTls i64:$in, tglobaltlsaddr:$g),
715           (ADD8TLS $in, tglobaltlsaddr:$g)>;
716 def ADDIStlsgdHA: Pseudo<(outs G8RC:$rD), (ins G8RC_NOX0:$reg, symbolHi64:$disp),
717                          "#ADDIStlsgdHA",
718                          [(set i64:$rD,
719                            (PPCaddisTlsgdHA i64:$reg, tglobaltlsaddr:$disp))]>,
720                   isPPC64;
721 def ADDItlsgdL : Pseudo<(outs G8RC:$rD), (ins G8RC_NOX0:$reg, symbolLo64:$disp),
722                        "#ADDItlsgdL",
723                        [(set i64:$rD,
724                          (PPCaddiTlsgdL i64:$reg, tglobaltlsaddr:$disp))]>,
725                  isPPC64;
726 def GETtlsADDR : Pseudo<(outs G8RC:$rD), (ins G8RC:$reg, tlsgd:$sym),
727                         "#GETtlsADDR",
728                         [(set i64:$rD,
729                           (PPCgetTlsAddr i64:$reg, tglobaltlsaddr:$sym))]>,
730                  isPPC64;
731 def ADDIStlsldHA: Pseudo<(outs G8RC:$rD), (ins G8RC_NOX0:$reg, symbolHi64:$disp),
732                          "#ADDIStlsldHA",
733                          [(set i64:$rD,
734                            (PPCaddisTlsldHA i64:$reg, tglobaltlsaddr:$disp))]>,
735                   isPPC64;
736 def ADDItlsldL : Pseudo<(outs G8RC:$rD), (ins G8RC_NOX0:$reg, symbolLo64:$disp),
737                        "#ADDItlsldL",
738                        [(set i64:$rD,
739                          (PPCaddiTlsldL i64:$reg, tglobaltlsaddr:$disp))]>,
740                  isPPC64;
741 def GETtlsldADDR : Pseudo<(outs G8RC:$rD), (ins G8RC:$reg, tlsgd:$sym),
742                           "#GETtlsldADDR",
743                           [(set i64:$rD,
744                             (PPCgetTlsldAddr i64:$reg, tglobaltlsaddr:$sym))]>,
745                    isPPC64;
746 def ADDISdtprelHA: Pseudo<(outs G8RC:$rD), (ins G8RC_NOX0:$reg, symbolHi64:$disp),
747                           "#ADDISdtprelHA",
748                           [(set i64:$rD,
749                             (PPCaddisDtprelHA i64:$reg,
750                                               tglobaltlsaddr:$disp))]>,
751                    isPPC64;
752 def ADDIdtprelL : Pseudo<(outs G8RC:$rD), (ins G8RC_NOX0:$reg, symbolLo64:$disp),
753                          "#ADDIdtprelL",
754                          [(set i64:$rD,
755                            (PPCaddiDtprelL i64:$reg, tglobaltlsaddr:$disp))]>,
756                   isPPC64;
757
758 let PPC970_Unit = 2 in {
759 // Truncating stores.                       
760 def STB8 : DForm_1<38, (outs), (ins G8RC:$rS, memri:$src),
761                    "stb $rS, $src", LdStStore,
762                    [(truncstorei8 i64:$rS, iaddr:$src)]>;
763 def STH8 : DForm_1<44, (outs), (ins G8RC:$rS, memri:$src),
764                    "sth $rS, $src", LdStStore,
765                    [(truncstorei16 i64:$rS, iaddr:$src)]>;
766 def STW8 : DForm_1<36, (outs), (ins G8RC:$rS, memri:$src),
767                    "stw $rS, $src", LdStStore,
768                    [(truncstorei32 i64:$rS, iaddr:$src)]>;
769 def STBX8 : XForm_8<31, 215, (outs), (ins G8RC:$rS, memrr:$dst),
770                    "stbx $rS, $dst", LdStStore,
771                    [(truncstorei8 i64:$rS, xaddr:$dst)]>,
772                    PPC970_DGroup_Cracked;
773 def STHX8 : XForm_8<31, 407, (outs), (ins G8RC:$rS, memrr:$dst),
774                    "sthx $rS, $dst", LdStStore,
775                    [(truncstorei16 i64:$rS, xaddr:$dst)]>,
776                    PPC970_DGroup_Cracked;
777 def STWX8 : XForm_8<31, 151, (outs), (ins G8RC:$rS, memrr:$dst),
778                    "stwx $rS, $dst", LdStStore,
779                    [(truncstorei32 i64:$rS, xaddr:$dst)]>,
780                    PPC970_DGroup_Cracked;
781 // Normal 8-byte stores.
782 def STD  : DSForm_1<62, 0, (outs), (ins G8RC:$rS, memrix:$dst),
783                     "std $rS, $dst", LdStSTD,
784                     [(aligned4store i64:$rS, ixaddr:$dst)]>, isPPC64;
785 def STDX  : XForm_8<31, 149, (outs), (ins G8RC:$rS, memrr:$dst),
786                    "stdx $rS, $dst", LdStSTD,
787                    [(store i64:$rS, xaddr:$dst)]>, isPPC64,
788                    PPC970_DGroup_Cracked;
789 def STDBRX: XForm_8<31, 660, (outs), (ins G8RC:$rS, memrr:$dst),
790                    "stdbrx $rS, $dst", LdStStore,
791                    [(PPCstbrx i64:$rS, xoaddr:$dst, i64)]>, isPPC64,
792                    PPC970_DGroup_Cracked;
793 }
794
795 // Stores with Update (pre-inc).
796 let PPC970_Unit = 2, mayStore = 1 in {
797 def STBU8 : DForm_1<39, (outs ptr_rc_nor0:$ea_res), (ins G8RC:$rS, memri:$dst),
798                    "stbu $rS, $dst", LdStStoreUpd, []>,
799                    RegConstraint<"$dst.reg = $ea_res">, NoEncode<"$ea_res">;
800 def STHU8 : DForm_1<45, (outs ptr_rc_nor0:$ea_res), (ins G8RC:$rS, memri:$dst),
801                    "sthu $rS, $dst", LdStStoreUpd, []>,
802                    RegConstraint<"$dst.reg = $ea_res">, NoEncode<"$ea_res">;
803 def STWU8 : DForm_1<37, (outs ptr_rc_nor0:$ea_res), (ins G8RC:$rS, memri:$dst),
804                    "stwu $rS, $dst", LdStStoreUpd, []>,
805                    RegConstraint<"$dst.reg = $ea_res">, NoEncode<"$ea_res">;
806 def STDU : DSForm_1<62, 1, (outs ptr_rc_nor0:$ea_res), (ins G8RC:$rS, memrix:$dst),
807                    "stdu $rS, $dst", LdStSTDU, []>,
808                    RegConstraint<"$dst.reg = $ea_res">, NoEncode<"$ea_res">,
809                    isPPC64;
810
811 def STBUX8: XForm_8<31, 247, (outs ptr_rc_nor0:$ea_res), (ins G8RC:$rS, memrr:$dst),
812                     "stbux $rS, $dst", LdStStoreUpd, []>,
813                     RegConstraint<"$dst.ptrreg = $ea_res">, NoEncode<"$ea_res">,
814                     PPC970_DGroup_Cracked;
815 def STHUX8: XForm_8<31, 439, (outs ptr_rc_nor0:$ea_res), (ins G8RC:$rS, memrr:$dst),
816                     "sthux $rS, $dst", LdStStoreUpd, []>,
817                     RegConstraint<"$dst.ptrreg = $ea_res">, NoEncode<"$ea_res">,
818                     PPC970_DGroup_Cracked;
819 def STWUX8: XForm_8<31, 183, (outs ptr_rc_nor0:$ea_res), (ins G8RC:$rS, memrr:$dst),
820                     "stwux $rS, $dst", LdStStoreUpd, []>,
821                     RegConstraint<"$dst.ptrreg = $ea_res">, NoEncode<"$ea_res">,
822                     PPC970_DGroup_Cracked;
823 def STDUX : XForm_8<31, 181, (outs ptr_rc_nor0:$ea_res), (ins G8RC:$rS, memrr:$dst),
824                     "stdux $rS, $dst", LdStSTDU, []>,
825                     RegConstraint<"$dst.ptrreg = $ea_res">, NoEncode<"$ea_res">,
826                     PPC970_DGroup_Cracked, isPPC64;
827 }
828
829 // Patterns to match the pre-inc stores.  We can't put the patterns on
830 // the instruction definitions directly as ISel wants the address base
831 // and offset to be separate operands, not a single complex operand.
832 def : Pat<(pre_truncsti8 i64:$rS, iPTR:$ptrreg, iaddroff:$ptroff),
833           (STBU8 $rS, iaddroff:$ptroff, $ptrreg)>;
834 def : Pat<(pre_truncsti16 i64:$rS, iPTR:$ptrreg, iaddroff:$ptroff),
835           (STHU8 $rS, iaddroff:$ptroff, $ptrreg)>;
836 def : Pat<(pre_truncsti32 i64:$rS, iPTR:$ptrreg, iaddroff:$ptroff),
837           (STWU8 $rS, iaddroff:$ptroff, $ptrreg)>;
838 def : Pat<(aligned4pre_store i64:$rS, iPTR:$ptrreg, iaddroff:$ptroff),
839           (STDU $rS, iaddroff:$ptroff, $ptrreg)>;
840
841 def : Pat<(pre_truncsti8 i64:$rS, iPTR:$ptrreg, iPTR:$ptroff),
842           (STBUX8 $rS, $ptrreg, $ptroff)>;
843 def : Pat<(pre_truncsti16 i64:$rS, iPTR:$ptrreg, iPTR:$ptroff),
844           (STHUX8 $rS, $ptrreg, $ptroff)>;
845 def : Pat<(pre_truncsti32 i64:$rS, iPTR:$ptrreg, iPTR:$ptroff),
846           (STWUX8 $rS, $ptrreg, $ptroff)>;
847 def : Pat<(pre_store i64:$rS, iPTR:$ptrreg, iPTR:$ptroff),
848           (STDUX $rS, $ptrreg, $ptroff)>;
849
850
851 //===----------------------------------------------------------------------===//
852 // Floating point instructions.
853 //
854
855
856 let PPC970_Unit = 3, Uses = [RM] in {  // FPU Operations.
857 def FCFID  : XForm_26<63, 846, (outs F8RC:$frD), (ins F8RC:$frB),
858                       "fcfid $frD, $frB", FPGeneral,
859                       [(set f64:$frD, (PPCfcfid f64:$frB))]>, isPPC64;
860 def FCTIDZ : XForm_26<63, 815, (outs F8RC:$frD), (ins F8RC:$frB),
861                       "fctidz $frD, $frB", FPGeneral,
862                       [(set f64:$frD, (PPCfctidz f64:$frB))]>, isPPC64;
863
864 def FCFIDU  : XForm_26<63, 974, (outs F8RC:$frD), (ins F8RC:$frB),
865                       "fcfidu $frD, $frB", FPGeneral,
866                       [(set f64:$frD, (PPCfcfidu f64:$frB))]>, isPPC64;
867 def FCFIDS  : XForm_26<59, 846, (outs F4RC:$frD), (ins F8RC:$frB),
868                       "fcfids $frD, $frB", FPGeneral,
869                       [(set f32:$frD, (PPCfcfids f64:$frB))]>, isPPC64;
870 def FCFIDUS : XForm_26<59, 974, (outs F4RC:$frD), (ins F8RC:$frB),
871                       "fcfidus $frD, $frB", FPGeneral,
872                       [(set f32:$frD, (PPCfcfidus f64:$frB))]>, isPPC64;
873 def FCTIDUZ : XForm_26<63, 943, (outs F8RC:$frD), (ins F8RC:$frB),
874                       "fctiduz $frD, $frB", FPGeneral,
875                       [(set f64:$frD, (PPCfctiduz f64:$frB))]>, isPPC64;
876 def FCTIWUZ : XForm_26<63, 143, (outs F8RC:$frD), (ins F8RC:$frB),
877                       "fctiwuz $frD, $frB", FPGeneral,
878                       [(set f64:$frD, (PPCfctiwuz f64:$frB))]>, isPPC64;
879 }
880
881
882 //===----------------------------------------------------------------------===//
883 // Instruction Patterns
884 //
885
886 // Extensions and truncates to/from 32-bit regs.
887 def : Pat<(i64 (zext i32:$in)),
888           (RLDICL (INSERT_SUBREG (i64 (IMPLICIT_DEF)), $in, sub_32),
889                   0, 32)>;
890 def : Pat<(i64 (anyext i32:$in)),
891           (INSERT_SUBREG (i64 (IMPLICIT_DEF)), $in, sub_32)>;
892 def : Pat<(i32 (trunc i64:$in)),
893           (EXTRACT_SUBREG $in, sub_32)>;
894
895 // Extending loads with i64 targets.
896 def : Pat<(zextloadi1 iaddr:$src),
897           (LBZ8 iaddr:$src)>;
898 def : Pat<(zextloadi1 xaddr:$src),
899           (LBZX8 xaddr:$src)>;
900 def : Pat<(extloadi1 iaddr:$src),
901           (LBZ8 iaddr:$src)>;
902 def : Pat<(extloadi1 xaddr:$src),
903           (LBZX8 xaddr:$src)>;
904 def : Pat<(extloadi8 iaddr:$src),
905           (LBZ8 iaddr:$src)>;
906 def : Pat<(extloadi8 xaddr:$src),
907           (LBZX8 xaddr:$src)>;
908 def : Pat<(extloadi16 iaddr:$src),
909           (LHZ8 iaddr:$src)>;
910 def : Pat<(extloadi16 xaddr:$src),
911           (LHZX8 xaddr:$src)>;
912 def : Pat<(extloadi32 iaddr:$src),
913           (LWZ8 iaddr:$src)>;
914 def : Pat<(extloadi32 xaddr:$src),
915           (LWZX8 xaddr:$src)>;
916
917 // Standard shifts.  These are represented separately from the real shifts above
918 // so that we can distinguish between shifts that allow 6-bit and 7-bit shift
919 // amounts.
920 def : Pat<(sra i64:$rS, i32:$rB),
921           (SRAD $rS, $rB)>;
922 def : Pat<(srl i64:$rS, i32:$rB),
923           (SRD $rS, $rB)>;
924 def : Pat<(shl i64:$rS, i32:$rB),
925           (SLD $rS, $rB)>;
926
927 // SHL/SRL
928 def : Pat<(shl i64:$in, (i32 imm:$imm)),
929           (RLDICR $in, imm:$imm, (SHL64 imm:$imm))>;
930 def : Pat<(srl i64:$in, (i32 imm:$imm)),
931           (RLDICL $in, (SRL64 imm:$imm), imm:$imm)>;
932
933 // ROTL
934 def : Pat<(rotl i64:$in, i32:$sh),
935           (RLDCL $in, $sh, 0)>;
936 def : Pat<(rotl i64:$in, (i32 imm:$imm)),
937           (RLDICL $in, imm:$imm, 0)>;
938
939 // Hi and Lo for Darwin Global Addresses.
940 def : Pat<(PPChi tglobaladdr:$in, 0), (LIS8 tglobaladdr:$in)>;
941 def : Pat<(PPClo tglobaladdr:$in, 0), (LI8  tglobaladdr:$in)>;
942 def : Pat<(PPChi tconstpool:$in , 0), (LIS8 tconstpool:$in)>;
943 def : Pat<(PPClo tconstpool:$in , 0), (LI8  tconstpool:$in)>;
944 def : Pat<(PPChi tjumptable:$in , 0), (LIS8 tjumptable:$in)>;
945 def : Pat<(PPClo tjumptable:$in , 0), (LI8  tjumptable:$in)>;
946 def : Pat<(PPChi tblockaddress:$in, 0), (LIS8 tblockaddress:$in)>;
947 def : Pat<(PPClo tblockaddress:$in, 0), (LI8  tblockaddress:$in)>;
948 def : Pat<(PPChi tglobaltlsaddr:$g, i64:$in),
949           (ADDIS8 $in, tglobaltlsaddr:$g)>;
950 def : Pat<(PPClo tglobaltlsaddr:$g, i64:$in),
951           (ADDI8 $in, tglobaltlsaddr:$g)>;
952 def : Pat<(add i64:$in, (PPChi tglobaladdr:$g, 0)),
953           (ADDIS8 $in, tglobaladdr:$g)>;
954 def : Pat<(add i64:$in, (PPChi tconstpool:$g, 0)),
955           (ADDIS8 $in, tconstpool:$g)>;
956 def : Pat<(add i64:$in, (PPChi tjumptable:$g, 0)),
957           (ADDIS8 $in, tjumptable:$g)>;
958 def : Pat<(add i64:$in, (PPChi tblockaddress:$g, 0)),
959           (ADDIS8 $in, tblockaddress:$g)>;
960
961 // Patterns to match r+r indexed loads and stores for
962 // addresses without at least 4-byte alignment.
963 def : Pat<(i64 (unaligned4sextloadi32 xoaddr:$src)),
964           (LWAX xoaddr:$src)>;
965 def : Pat<(i64 (unaligned4load xoaddr:$src)),
966           (LDX xoaddr:$src)>;
967 def : Pat<(unaligned4store i64:$rS, xoaddr:$dst),
968           (STDX $rS, xoaddr:$dst)>;
969