Add zextload from i32 -> i64, with this, perimeter works.
[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 was developed by Chris Lattner and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
7 // 
8 //===----------------------------------------------------------------------===//
9 //
10 // This file describes the PowerPC 64-bit instructions.  These patterns are used
11 // both when in ppc64 mode and when in "use 64-bit extensions in 32-bit" mode.
12 //
13 //===----------------------------------------------------------------------===//
14
15 //===----------------------------------------------------------------------===//
16 // 64-bit operands.
17 //
18 def s16imm64 : Operand<i64> {
19   let PrintMethod = "printS16ImmOperand";
20 }
21 def u16imm64 : Operand<i64> {
22   let PrintMethod = "printU16ImmOperand";
23 }
24 def symbolHi64 : Operand<i64> {
25   let PrintMethod = "printSymbolHi";
26 }
27 def symbolLo64 : Operand<i64> {
28   let PrintMethod = "printSymbolLo";
29 }
30
31 //===----------------------------------------------------------------------===//
32 // 64-bit transformation functions.
33 //
34
35 def SHL64 : SDNodeXForm<imm, [{
36   // Transformation function: 63 - imm
37   return getI32Imm(63 - N->getValue());
38 }]>;
39
40 def SRL64 : SDNodeXForm<imm, [{
41   // Transformation function: 64 - imm
42   return N->getValue() ? getI32Imm(64 - N->getValue()) : getI32Imm(0);
43 }]>;
44
45 def HI32_48 : SDNodeXForm<imm, [{
46   // Transformation function: shift the immediate value down into the low bits.
47   return getI32Imm((unsigned short)(N->getValue() >> 32));
48 }]>;
49
50 def HI48_64 : SDNodeXForm<imm, [{
51   // Transformation function: shift the immediate value down into the low bits.
52   return getI32Imm((unsigned short)(N->getValue() >> 48));
53 }]>;
54
55
56 //===----------------------------------------------------------------------===//
57 // Fixed point instructions.
58 //
59
60 let PPC970_Unit = 1 in {  // FXU Operations.
61
62 // Copies, extends, truncates.
63 def OR4To8  : XForm_6<31, 444, (ops G8RC:$rA, GPRC:$rS, GPRC:$rB),
64                    "or $rA, $rS, $rB", IntGeneral,
65                    []>;
66 def OR8To4  : XForm_6<31, 444, (ops GPRC:$rA, G8RC:$rS, G8RC:$rB),
67                    "or $rA, $rS, $rB", IntGeneral,
68                    []>;
69
70 def LI8  : DForm_2_r0<14, (ops G8RC:$rD, symbolLo64:$imm),
71                       "li $rD, $imm", IntGeneral,
72                       [(set G8RC:$rD, immSExt16:$imm)]>;
73 def LIS8 : DForm_2_r0<15, (ops G8RC:$rD, symbolHi64:$imm),
74                       "lis $rD, $imm", IntGeneral,
75                       [(set G8RC:$rD, imm16ShiftedSExt:$imm)]>;
76
77 // Logical ops.
78 def NAND8: XForm_6<31, 476, (ops G8RC:$rA, G8RC:$rS, G8RC:$rB),
79                    "nand $rA, $rS, $rB", IntGeneral,
80                    [(set G8RC:$rA, (not (and G8RC:$rS, G8RC:$rB)))]>;
81 def AND8 : XForm_6<31,  28, (ops G8RC:$rA, G8RC:$rS, G8RC:$rB),
82                    "and $rA, $rS, $rB", IntGeneral,
83                    [(set G8RC:$rA, (and G8RC:$rS, G8RC:$rB))]>;
84 def ANDC8: XForm_6<31,  60, (ops G8RC:$rA, G8RC:$rS, G8RC:$rB),
85                    "andc $rA, $rS, $rB", IntGeneral,
86                    [(set G8RC:$rA, (and G8RC:$rS, (not G8RC:$rB)))]>;
87 def OR8  : XForm_6<31, 444, (ops G8RC:$rA, G8RC:$rS, G8RC:$rB),
88                    "or $rA, $rS, $rB", IntGeneral,
89                    [(set G8RC:$rA, (or G8RC:$rS, G8RC:$rB))]>;
90 def NOR8 : XForm_6<31, 124, (ops G8RC:$rA, G8RC:$rS, G8RC:$rB),
91                    "nor $rA, $rS, $rB", IntGeneral,
92                    [(set G8RC:$rA, (not (or G8RC:$rS, G8RC:$rB)))]>;
93 def ORC8 : XForm_6<31, 412, (ops G8RC:$rA, G8RC:$rS, G8RC:$rB),
94                    "orc $rA, $rS, $rB", IntGeneral,
95                    [(set G8RC:$rA, (or G8RC:$rS, (not G8RC:$rB)))]>;
96 def EQV8 : XForm_6<31, 284, (ops G8RC:$rA, G8RC:$rS, G8RC:$rB),
97                    "eqv $rA, $rS, $rB", IntGeneral,
98                    [(set G8RC:$rA, (not (xor G8RC:$rS, G8RC:$rB)))]>;
99 def XOR8 : XForm_6<31, 316, (ops G8RC:$rA, G8RC:$rS, G8RC:$rB),
100                    "xor $rA, $rS, $rB", IntGeneral,
101                    [(set G8RC:$rA, (xor G8RC:$rS, G8RC:$rB))]>;
102
103 // Logical ops with immediate.
104 def ANDIo8  : DForm_4<28, (ops G8RC:$dst, G8RC:$src1, u16imm:$src2),
105                       "andi. $dst, $src1, $src2", IntGeneral,
106                       [(set G8RC:$dst, (and G8RC:$src1, immZExt16:$src2))]>,
107                       isDOT;
108 def ANDISo8 : DForm_4<29, (ops G8RC:$dst, G8RC:$src1, u16imm:$src2),
109                      "andis. $dst, $src1, $src2", IntGeneral,
110                     [(set G8RC:$dst, (and G8RC:$src1,imm16ShiftedZExt:$src2))]>,
111                      isDOT;
112 def ORI8    : DForm_4<24, (ops G8RC:$dst, G8RC:$src1, u16imm:$src2),
113                       "ori $dst, $src1, $src2", IntGeneral,
114                       [(set G8RC:$dst, (or G8RC:$src1, immZExt16:$src2))]>;
115 def ORIS8   : DForm_4<25, (ops G8RC:$dst, G8RC:$src1, u16imm:$src2),
116                       "oris $dst, $src1, $src2", IntGeneral,
117                     [(set G8RC:$dst, (or G8RC:$src1, imm16ShiftedZExt:$src2))]>;
118 def XORI8   : DForm_4<26, (ops G8RC:$dst, G8RC:$src1, u16imm:$src2),
119                       "xori $dst, $src1, $src2", IntGeneral,
120                       [(set G8RC:$dst, (xor G8RC:$src1, immZExt16:$src2))]>;
121 def XORIS8  : DForm_4<27, (ops G8RC:$dst, G8RC:$src1, u16imm:$src2),
122                       "xoris $dst, $src1, $src2", IntGeneral,
123                    [(set G8RC:$dst, (xor G8RC:$src1, imm16ShiftedZExt:$src2))]>;
124
125
126                    
127 def ADD8  : XOForm_1<31, 266, 0, (ops G8RC:$rT, G8RC:$rA, G8RC:$rB),
128                      "add $rT, $rA, $rB", IntGeneral,
129                      [(set G8RC:$rT, (add G8RC:$rA, G8RC:$rB))]>;
130 def ADDI8  : DForm_2<14, (ops G8RC:$rD, G8RC:$rA, s16imm64:$imm),
131                      "addi $rD, $rA, $imm", IntGeneral,
132                      [(set G8RC:$rD, (add G8RC:$rA, immSExt16:$imm))]>;
133 def ADDIS8 : DForm_2<15, (ops G8RC:$rD, G8RC:$rA, symbolHi64:$imm),
134                      "addis $rD, $rA, $imm", IntGeneral,
135                      [(set G8RC:$rD, (add G8RC:$rA, imm16ShiftedSExt:$imm))]>;
136
137
138
139
140 def MULHD : XOForm_1<31, 73, 0, (ops G8RC:$rT, G8RC:$rA, G8RC:$rB),
141                      "mulhd $rT, $rA, $rB", IntMulHW,
142                      [(set G8RC:$rT, (mulhs G8RC:$rA, G8RC:$rB))]>;
143 def MULHDU : XOForm_1<31, 9, 0, (ops G8RC:$rT, G8RC:$rA, G8RC:$rB),
144                      "mulhdu $rT, $rA, $rB", IntMulHWU,
145                      [(set G8RC:$rT, (mulhu G8RC:$rA, G8RC:$rB))]>;
146
147 def CMPD   : XForm_16_ext<31, 0, (ops CRRC:$crD, G8RC:$rA, G8RC:$rB),
148                           "cmpd $crD, $rA, $rB", IntCompare>, isPPC64;
149 def CMPLD  : XForm_16_ext<31, 32, (ops CRRC:$crD, G8RC:$rA, G8RC:$rB),
150                           "cmpld $crD, $rA, $rB", IntCompare>, isPPC64;
151 def CMPDI  : DForm_5_ext<11, (ops CRRC:$crD, G8RC:$rA, s16imm:$imm),
152                          "cmpdi $crD, $rA, $imm", IntCompare>, isPPC64;
153 def CMPLDI : DForm_6_ext<10, (ops CRRC:$dst, G8RC:$src1, u16imm:$src2),
154                          "cmpldi $dst, $src1, $src2", IntCompare>, isPPC64;
155
156 def SLD  : XForm_6<31,  27, (ops G8RC:$rA, G8RC:$rS, G8RC:$rB),
157                    "sld $rA, $rS, $rB", IntRotateD,
158                    [(set G8RC:$rA, (shl G8RC:$rS, G8RC:$rB))]>, isPPC64;
159 def SRD  : XForm_6<31, 539, (ops G8RC:$rA, G8RC:$rS, G8RC:$rB),
160                    "srd $rA, $rS, $rB", IntRotateD,
161                    [(set G8RC:$rA, (srl G8RC:$rS, G8RC:$rB))]>, isPPC64;
162 def SRAD : XForm_6<31, 794, (ops G8RC:$rA, G8RC:$rS, G8RC:$rB),
163                    "srad $rA, $rS, $rB", IntRotateD,
164                    [(set G8RC:$rA, (sra G8RC:$rS, G8RC:$rB))]>, isPPC64;
165 def EXTSW  : XForm_11<31, 986, (ops G8RC:$rA, G8RC:$rS),
166                       "extsw $rA, $rS", IntGeneral,
167                       [(set G8RC:$rA, (sext_inreg G8RC:$rS, i32))]>, isPPC64;
168 /// EXTSW_32 - Just like EXTSW, but works on '32-bit' registers.
169 def EXTSW_32 : XForm_11<31, 986, (ops GPRC:$rA, GPRC:$rS),
170                       "extsw $rA, $rS", IntGeneral,
171                       [(set GPRC:$rA, (PPCextsw_32 GPRC:$rS))]>, isPPC64;
172 def EXTSW_32_64 : XForm_11<31, 986, (ops G8RC:$rA, GPRC:$rS),
173                       "extsw $rA, $rS", IntGeneral,
174                       [(set G8RC:$rA, (sext GPRC:$rS))]>, isPPC64;
175
176 def SRADI  : XSForm_1<31, 413, (ops GPRC:$rA, GPRC:$rS, u6imm:$SH),
177                       "sradi $rA, $rS, $SH", IntRotateD>, isPPC64;
178 def DIVD  : XOForm_1<31, 489, 0, (ops G8RC:$rT, G8RC:$rA, G8RC:$rB),
179                      "divd $rT, $rA, $rB", IntDivD,
180                      [(set G8RC:$rT, (sdiv G8RC:$rA, G8RC:$rB))]>, isPPC64,
181                      PPC970_DGroup_First, PPC970_DGroup_Cracked;
182 def DIVDU : XOForm_1<31, 457, 0, (ops G8RC:$rT, G8RC:$rA, G8RC:$rB),
183                      "divdu $rT, $rA, $rB", IntDivD,
184                      [(set G8RC:$rT, (udiv G8RC:$rA, G8RC:$rB))]>, isPPC64,
185                      PPC970_DGroup_First, PPC970_DGroup_Cracked;
186 def MULLD : XOForm_1<31, 233, 0, (ops G8RC:$rT, G8RC:$rA, G8RC:$rB),
187                      "mulld $rT, $rA, $rB", IntMulHD,
188                      [(set G8RC:$rT, (mul G8RC:$rA, G8RC:$rB))]>, isPPC64;
189
190
191 let isTwoAddress = 1, isCommutable = 1 in {
192 def RLDIMI : MDForm_1<30, 3,
193                       (ops G8RC:$rA, G8RC:$rSi, G8RC:$rS, u6imm:$SH, u6imm:$MB),
194                       "rldimi $rA, $rS, $SH, $MB", IntRotateD,
195                       []>, isPPC64;
196 }
197
198 // Rotate instructions.
199 def RLDICL : MDForm_1<30, 0,
200                       (ops G8RC:$rA, G8RC:$rS, u6imm:$SH, u6imm:$MB),
201                       "rldicl $rA, $rS, $SH, $MB", IntRotateD,
202                       []>, isPPC64;
203 def RLDICR : MDForm_1<30, 1,
204                       (ops G8RC:$rA, G8RC:$rS, u6imm:$SH, u6imm:$ME),
205                       "rldicr $rA, $rS, $SH, $ME", IntRotateD,
206                       []>, isPPC64;
207 }  // End FXU Operations.
208
209
210 //===----------------------------------------------------------------------===//
211 // Load/Store instructions.
212 //
213
214
215 let isLoad = 1, PPC970_Unit = 2 in {
216 def LWA  : DSForm_1<58, 2, (ops G8RC:$rD, memrix:$src),
217                     "lwa $rD, $src", LdStLWA,
218                     [(set G8RC:$rD, (sextload ixaddr:$src, i32))]>, isPPC64,
219                     PPC970_DGroup_Cracked;
220 def LD   : DSForm_2<58, 0, (ops G8RC:$rD, memrix:$src),
221                     "ld $rD, $src", LdStLD,
222                     [(set G8RC:$rD, (load ixaddr:$src))]>, isPPC64;
223
224 def LWAX : XForm_1<31, 341, (ops G8RC:$rD, memrr:$src),
225                    "lwax $rD, $src", LdStLHA,
226                    [(set G8RC:$rD, (sextload xaddr:$src, i32))]>, isPPC64,
227                    PPC970_DGroup_Cracked;
228 def LDX  : XForm_1<31,  21, (ops G8RC:$rD, memrr:$src),
229                    "ldx $rD, $src", LdStLD,
230                    [(set G8RC:$rD, (load xaddr:$src))]>, isPPC64;
231 def LWZ8 : DForm_1<32, (ops G8RC:$rD, memri:$src),
232                   "lwz $rD, $src", LdStGeneral,
233                   [(set G8RC:$rD, (zextload iaddr:$src, i32))]>, isPPC64;
234 }
235 let isStore = 1, noResults = 1, PPC970_Unit = 2 in {
236 def STD  : DSForm_2<62, 0, (ops G8RC:$rS, memrix:$dst),
237                     "std $rS, $dst", LdStSTD,
238                     [(store G8RC:$rS, ixaddr:$dst)]>, isPPC64;
239 def STDX  : XForm_8<31, 149, (ops G8RC:$rS, memrr:$dst),
240                    "stdx $rS, $dst", LdStSTD,
241                    [(store G8RC:$rS, iaddr:$dst)]>, isPPC64,
242                    PPC970_DGroup_Cracked;
243 def STDUX : XForm_8<31, 181, (ops G8RC:$rS, memrr:$dst),
244                    "stdux $rS, $dst", LdStSTD,
245                    []>, isPPC64;
246                    
247 // STD_32/STDX_32 - Just like STD/STDX, but uses a '32-bit' input register.
248 def STD_32  : DSForm_2<62, 0, (ops GPRC:$rT, memrix:$dst),
249                        "std $rT, $dst", LdStSTD,
250                        [(PPCstd_32  GPRC:$rT, ixaddr:$dst)]>, isPPC64;
251 def STDX_32  : XForm_8<31, 149, (ops GPRC:$rT, memrr:$dst),
252                        "stdx $rT, $dst", LdStSTD,
253                        [(PPCstd_32  GPRC:$rT, xaddr:$dst)]>, isPPC64,
254                        PPC970_DGroup_Cracked;
255 }
256
257
258
259 //===----------------------------------------------------------------------===//
260 // Floating point instructions.
261 //
262
263
264 let PPC970_Unit = 3 in {  // FPU Operations.
265 def FCFID  : XForm_26<63, 846, (ops F8RC:$frD, F8RC:$frB),
266                       "fcfid $frD, $frB", FPGeneral,
267                       [(set F8RC:$frD, (PPCfcfid F8RC:$frB))]>, isPPC64;
268 def FCTIDZ : XForm_26<63, 815, (ops F8RC:$frD, F8RC:$frB),
269                       "fctidz $frD, $frB", FPGeneral,
270                       [(set F8RC:$frD, (PPCfctidz F8RC:$frB))]>, isPPC64;
271 }
272
273
274 //===----------------------------------------------------------------------===//
275 // Instruction Patterns
276 //
277
278 // Immediate support.
279 // Handled above:
280 //   sext(0x0000_0000_0000_FFFF,  i8) -> li imm
281 //   sext(0x0000_0000_FFFF_0000, i16) -> lis imm>>16
282
283 // sext(0x0000_0000_FFFF_FFFF,  i16)  -> lis + ori
284 def sext_0x0000_0000_FFFF_FFFF_i16 : PatLeaf<(imm), [{
285   return N->getValue() == (uint64_t)(int32_t)N->getValue();
286 }]>;
287 def : Pat<(i64 sext_0x0000_0000_FFFF_FFFF_i16:$imm),
288           (ORI8 (LIS8 (HI16 imm:$imm)), (LO16 imm:$imm))>;
289
290 // zext(0x0000_0000_FFFF_7FFF, i16) -> oris (li lo16(imm)), imm>>16
291 def zext_0x0000_0000_FFFF_7FFF_i16 : PatLeaf<(imm), [{
292   return (N->getValue() & 0xFFFFFFFF00008000ULL) == 0;
293 }]>;
294 def : Pat<(i64 zext_0x0000_0000_FFFF_7FFF_i16:$imm),
295           (ORIS8 (LI8 (LO16 imm:$imm)), (HI16 imm:$imm))>;
296
297 // zext(0x0000_0000_FFFF_FFFF, i16) -> oris (ori (li 0), lo16(imm)), imm>>16
298 def zext_0x0000_0000_FFFF_FFFF_i16 : PatLeaf<(imm), [{
299   return (N->getValue() & 0xFFFFFFFF00000000ULL) == 0;
300 }]>;
301 def : Pat<(i64 zext_0x0000_0000_FFFF_FFFF_i16:$imm),
302           (ORIS8 (ORI8 (LI8 0), (LO16 imm:$imm)), (HI16 imm:$imm))>;
303
304 // FIXME: Handle smart forms where the top 32-bits are set.  Right now, stuff
305 // like 0xABCD0123BCDE0000 hits the case below, which produces ORI R, R, 0's! 
306
307 // Fully general (and most expensive: 6 instructions!) immediate pattern.
308 def : Pat<(i64 imm:$imm),
309           (ORI8 
310              (ORIS8 
311                 (RLDICR
312                    (ORI8
313                       (LIS8 (HI48_64 imm:$imm)),
314                       (HI32_48 imm:$imm)),
315                    32, 31),
316                 (HI16 imm:$imm)),
317              (LO16 imm:$imm))>;
318
319
320 // Extensions and truncates to/from 32-bit regs.
321 def : Pat<(i64 (zext GPRC:$in)),
322           (RLDICL (OR4To8 GPRC:$in, GPRC:$in), 0, 32)>;
323 def : Pat<(i64 (anyext GPRC:$in)),
324           (OR4To8 GPRC:$in, GPRC:$in)>;
325 def : Pat<(i32 (trunc G8RC:$in)),
326           (OR8To4 G8RC:$in, G8RC:$in)>;
327
328 // SHL/SRL
329 def : Pat<(shl G8RC:$in, (i64 imm:$imm)),
330           (RLDICR G8RC:$in, imm:$imm, (SHL64 imm:$imm))>;
331 def : Pat<(srl G8RC:$in, (i64 imm:$imm)),
332           (RLDICL G8RC:$in, (SRL64 imm:$imm), imm:$imm)>;
333
334 // Hi and Lo for Darwin Global Addresses.
335 def : Pat<(PPChi tglobaladdr:$in, 0), (LIS8 tglobaladdr:$in)>;
336 def : Pat<(PPClo tglobaladdr:$in, 0), (LI8  tglobaladdr:$in)>;
337 def : Pat<(PPChi tconstpool:$in , 0), (LIS8 tconstpool:$in)>;
338 def : Pat<(PPClo tconstpool:$in , 0), (LI8  tconstpool:$in)>;
339 def : Pat<(PPChi tjumptable:$in , 0), (LIS8 tjumptable:$in)>;
340 def : Pat<(PPClo tjumptable:$in , 0), (LI8  tjumptable:$in)>;
341 def : Pat<(add G8RC:$in, (PPChi tglobaladdr:$g, 0)),
342           (ADDIS8 G8RC:$in, tglobaladdr:$g)>;
343 def : Pat<(add G8RC:$in, (PPChi tconstpool:$g, 0)),
344           (ADDIS8 G8RC:$in, tconstpool:$g)>;
345 def : Pat<(add G8RC:$in, (PPChi tjumptable:$g, 0)),
346           (ADDIS8 G8RC:$in, tjumptable:$g)>;