1 //===- PPCInstr64Bit.td - The PowerPC 64-bit Support -------*- tablegen -*-===//
3 // The LLVM Compiler Infrastructure
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.
8 //===----------------------------------------------------------------------===//
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.
13 //===----------------------------------------------------------------------===//
15 //===----------------------------------------------------------------------===//
18 def s16imm64 : Operand<i64> {
19 let PrintMethod = "printS16ImmOperand";
21 def u16imm64 : Operand<i64> {
22 let PrintMethod = "printU16ImmOperand";
24 def symbolHi64 : Operand<i64> {
25 let PrintMethod = "printSymbolHi";
27 def symbolLo64 : Operand<i64> {
28 let PrintMethod = "printSymbolLo";
31 //===----------------------------------------------------------------------===//
32 // 64-bit transformation functions.
35 def SHL64 : SDNodeXForm<imm, [{
36 // Transformation function: 63 - imm
37 return getI32Imm(63 - N->getValue());
40 def SRL64 : SDNodeXForm<imm, [{
41 // Transformation function: 64 - imm
42 return N->getValue() ? getI32Imm(64 - N->getValue()) : getI32Imm(0);
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));
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));
56 //===----------------------------------------------------------------------===//
57 // Pseudo instructions.
60 def IMPLICIT_DEF_G8RC : Pseudo<(ops G8RC:$rD), "; $rD = IMPLICIT_DEF_G8RC",
61 [(set G8RC:$rD, (undef))]>;
64 //===----------------------------------------------------------------------===//
65 // Fixed point instructions.
68 let PPC970_Unit = 1 in { // FXU Operations.
70 // Copies, extends, truncates.
71 def OR4To8 : XForm_6<31, 444, (ops G8RC:$rA, GPRC:$rS, GPRC:$rB),
72 "or $rA, $rS, $rB", IntGeneral,
74 def OR8To4 : XForm_6<31, 444, (ops GPRC:$rA, G8RC:$rS, G8RC:$rB),
75 "or $rA, $rS, $rB", IntGeneral,
78 def LI8 : DForm_2_r0<14, (ops G8RC:$rD, symbolLo64:$imm),
79 "li $rD, $imm", IntGeneral,
80 [(set G8RC:$rD, immSExt16:$imm)]>;
81 def LIS8 : DForm_2_r0<15, (ops G8RC:$rD, symbolHi64:$imm),
82 "lis $rD, $imm", IntGeneral,
83 [(set G8RC:$rD, imm16ShiftedSExt:$imm)]>;
86 def NAND8: XForm_6<31, 476, (ops G8RC:$rA, G8RC:$rS, G8RC:$rB),
87 "nand $rA, $rS, $rB", IntGeneral,
88 [(set G8RC:$rA, (not (and G8RC:$rS, G8RC:$rB)))]>;
89 def AND8 : XForm_6<31, 28, (ops G8RC:$rA, G8RC:$rS, G8RC:$rB),
90 "and $rA, $rS, $rB", IntGeneral,
91 [(set G8RC:$rA, (and G8RC:$rS, G8RC:$rB))]>;
92 def ANDC8: XForm_6<31, 60, (ops G8RC:$rA, G8RC:$rS, G8RC:$rB),
93 "andc $rA, $rS, $rB", IntGeneral,
94 [(set G8RC:$rA, (and G8RC:$rS, (not G8RC:$rB)))]>;
95 def OR8 : XForm_6<31, 444, (ops G8RC:$rA, G8RC:$rS, G8RC:$rB),
96 "or $rA, $rS, $rB", IntGeneral,
97 [(set G8RC:$rA, (or G8RC:$rS, G8RC:$rB))]>;
98 def NOR8 : XForm_6<31, 124, (ops G8RC:$rA, G8RC:$rS, G8RC:$rB),
99 "nor $rA, $rS, $rB", IntGeneral,
100 [(set G8RC:$rA, (not (or G8RC:$rS, G8RC:$rB)))]>;
101 def ORC8 : XForm_6<31, 412, (ops G8RC:$rA, G8RC:$rS, G8RC:$rB),
102 "orc $rA, $rS, $rB", IntGeneral,
103 [(set G8RC:$rA, (or G8RC:$rS, (not G8RC:$rB)))]>;
104 def EQV8 : XForm_6<31, 284, (ops G8RC:$rA, G8RC:$rS, G8RC:$rB),
105 "eqv $rA, $rS, $rB", IntGeneral,
106 [(set G8RC:$rA, (not (xor G8RC:$rS, G8RC:$rB)))]>;
107 def XOR8 : XForm_6<31, 316, (ops G8RC:$rA, G8RC:$rS, G8RC:$rB),
108 "xor $rA, $rS, $rB", IntGeneral,
109 [(set G8RC:$rA, (xor G8RC:$rS, G8RC:$rB))]>;
111 // Logical ops with immediate.
112 def ANDIo8 : DForm_4<28, (ops G8RC:$dst, G8RC:$src1, u16imm:$src2),
113 "andi. $dst, $src1, $src2", IntGeneral,
114 [(set G8RC:$dst, (and G8RC:$src1, immZExt16:$src2))]>,
116 def ANDISo8 : DForm_4<29, (ops G8RC:$dst, G8RC:$src1, u16imm:$src2),
117 "andis. $dst, $src1, $src2", IntGeneral,
118 [(set G8RC:$dst, (and G8RC:$src1,imm16ShiftedZExt:$src2))]>,
120 def ORI8 : DForm_4<24, (ops G8RC:$dst, G8RC:$src1, u16imm:$src2),
121 "ori $dst, $src1, $src2", IntGeneral,
122 [(set G8RC:$dst, (or G8RC:$src1, immZExt16:$src2))]>;
123 def ORIS8 : DForm_4<25, (ops G8RC:$dst, G8RC:$src1, u16imm:$src2),
124 "oris $dst, $src1, $src2", IntGeneral,
125 [(set G8RC:$dst, (or G8RC:$src1, imm16ShiftedZExt:$src2))]>;
126 def XORI8 : DForm_4<26, (ops G8RC:$dst, G8RC:$src1, u16imm:$src2),
127 "xori $dst, $src1, $src2", IntGeneral,
128 [(set G8RC:$dst, (xor G8RC:$src1, immZExt16:$src2))]>;
129 def XORIS8 : DForm_4<27, (ops G8RC:$dst, G8RC:$src1, u16imm:$src2),
130 "xoris $dst, $src1, $src2", IntGeneral,
131 [(set G8RC:$dst, (xor G8RC:$src1, imm16ShiftedZExt:$src2))]>;
135 def ADD8 : XOForm_1<31, 266, 0, (ops G8RC:$rT, G8RC:$rA, G8RC:$rB),
136 "add $rT, $rA, $rB", IntGeneral,
137 [(set G8RC:$rT, (add G8RC:$rA, G8RC:$rB))]>;
138 def ADDI8 : DForm_2<14, (ops G8RC:$rD, G8RC:$rA, s16imm64:$imm),
139 "addi $rD, $rA, $imm", IntGeneral,
140 [(set G8RC:$rD, (add G8RC:$rA, immSExt16:$imm))]>;
141 def ADDIS8 : DForm_2<15, (ops G8RC:$rD, G8RC:$rA, symbolHi64:$imm),
142 "addis $rD, $rA, $imm", IntGeneral,
143 [(set G8RC:$rD, (add G8RC:$rA, imm16ShiftedSExt:$imm))]>;
145 def SUBFIC8: DForm_2< 8, (ops G8RC:$rD, G8RC:$rA, s16imm64:$imm),
146 "subfic $rD, $rA, $imm", IntGeneral,
147 [(set G8RC:$rD, (subc immSExt16:$imm, G8RC:$rA))]>;
148 def SUBF8 : XOForm_1<31, 40, 0, (ops G8RC:$rT, G8RC:$rA, G8RC:$rB),
149 "subf $rT, $rA, $rB", IntGeneral,
150 [(set G8RC:$rT, (sub G8RC:$rB, G8RC:$rA))]>;
153 def MULHD : XOForm_1<31, 73, 0, (ops G8RC:$rT, G8RC:$rA, G8RC:$rB),
154 "mulhd $rT, $rA, $rB", IntMulHW,
155 [(set G8RC:$rT, (mulhs G8RC:$rA, G8RC:$rB))]>;
156 def MULHDU : XOForm_1<31, 9, 0, (ops G8RC:$rT, G8RC:$rA, G8RC:$rB),
157 "mulhdu $rT, $rA, $rB", IntMulHWU,
158 [(set G8RC:$rT, (mulhu G8RC:$rA, G8RC:$rB))]>;
160 def CMPD : XForm_16_ext<31, 0, (ops CRRC:$crD, G8RC:$rA, G8RC:$rB),
161 "cmpd $crD, $rA, $rB", IntCompare>, isPPC64;
162 def CMPLD : XForm_16_ext<31, 32, (ops CRRC:$crD, G8RC:$rA, G8RC:$rB),
163 "cmpld $crD, $rA, $rB", IntCompare>, isPPC64;
164 def CMPDI : DForm_5_ext<11, (ops CRRC:$crD, G8RC:$rA, s16imm:$imm),
165 "cmpdi $crD, $rA, $imm", IntCompare>, isPPC64;
166 def CMPLDI : DForm_6_ext<10, (ops CRRC:$dst, G8RC:$src1, u16imm:$src2),
167 "cmpldi $dst, $src1, $src2", IntCompare>, isPPC64;
169 def SLD : XForm_6<31, 27, (ops G8RC:$rA, G8RC:$rS, G8RC:$rB),
170 "sld $rA, $rS, $rB", IntRotateD,
171 [(set G8RC:$rA, (shl G8RC:$rS, G8RC:$rB))]>, isPPC64;
172 def SRD : XForm_6<31, 539, (ops G8RC:$rA, G8RC:$rS, G8RC:$rB),
173 "srd $rA, $rS, $rB", IntRotateD,
174 [(set G8RC:$rA, (srl G8RC:$rS, G8RC:$rB))]>, isPPC64;
175 def SRAD : XForm_6<31, 794, (ops G8RC:$rA, G8RC:$rS, G8RC:$rB),
176 "srad $rA, $rS, $rB", IntRotateD,
177 [(set G8RC:$rA, (sra G8RC:$rS, G8RC:$rB))]>, isPPC64;
178 def EXTSW : XForm_11<31, 986, (ops G8RC:$rA, G8RC:$rS),
179 "extsw $rA, $rS", IntGeneral,
180 [(set G8RC:$rA, (sext_inreg G8RC:$rS, i32))]>, isPPC64;
181 /// EXTSW_32 - Just like EXTSW, but works on '32-bit' registers.
182 def EXTSW_32 : XForm_11<31, 986, (ops GPRC:$rA, GPRC:$rS),
183 "extsw $rA, $rS", IntGeneral,
184 [(set GPRC:$rA, (PPCextsw_32 GPRC:$rS))]>, isPPC64;
185 def EXTSW_32_64 : XForm_11<31, 986, (ops G8RC:$rA, GPRC:$rS),
186 "extsw $rA, $rS", IntGeneral,
187 [(set G8RC:$rA, (sext GPRC:$rS))]>, isPPC64;
189 def SRADI : XSForm_1<31, 413, (ops GPRC:$rA, GPRC:$rS, u6imm:$SH),
190 "sradi $rA, $rS, $SH", IntRotateD>, isPPC64;
191 def DIVD : XOForm_1<31, 489, 0, (ops G8RC:$rT, G8RC:$rA, G8RC:$rB),
192 "divd $rT, $rA, $rB", IntDivD,
193 [(set G8RC:$rT, (sdiv G8RC:$rA, G8RC:$rB))]>, isPPC64,
194 PPC970_DGroup_First, PPC970_DGroup_Cracked;
195 def DIVDU : XOForm_1<31, 457, 0, (ops G8RC:$rT, G8RC:$rA, G8RC:$rB),
196 "divdu $rT, $rA, $rB", IntDivD,
197 [(set G8RC:$rT, (udiv G8RC:$rA, G8RC:$rB))]>, isPPC64,
198 PPC970_DGroup_First, PPC970_DGroup_Cracked;
199 def MULLD : XOForm_1<31, 233, 0, (ops G8RC:$rT, G8RC:$rA, G8RC:$rB),
200 "mulld $rT, $rA, $rB", IntMulHD,
201 [(set G8RC:$rT, (mul G8RC:$rA, G8RC:$rB))]>, isPPC64;
204 let isTwoAddress = 1, isCommutable = 1 in {
205 def RLDIMI : MDForm_1<30, 3,
206 (ops G8RC:$rA, G8RC:$rSi, G8RC:$rS, u6imm:$SH, u6imm:$MB),
207 "rldimi $rA, $rS, $SH, $MB", IntRotateD,
211 // Rotate instructions.
212 def RLDICL : MDForm_1<30, 0,
213 (ops G8RC:$rA, G8RC:$rS, u6imm:$SH, u6imm:$MB),
214 "rldicl $rA, $rS, $SH, $MB", IntRotateD,
216 def RLDICR : MDForm_1<30, 1,
217 (ops G8RC:$rA, G8RC:$rS, u6imm:$SH, u6imm:$ME),
218 "rldicr $rA, $rS, $SH, $ME", IntRotateD,
220 } // End FXU Operations.
223 //===----------------------------------------------------------------------===//
224 // Load/Store instructions.
228 let isLoad = 1, PPC970_Unit = 2 in {
229 def LWA : DSForm_1<58, 2, (ops G8RC:$rD, memrix:$src),
230 "lwa $rD, $src", LdStLWA,
231 [(set G8RC:$rD, (sextload ixaddr:$src, i32))]>, isPPC64,
232 PPC970_DGroup_Cracked;
233 def LD : DSForm_2<58, 0, (ops G8RC:$rD, memrix:$src),
234 "ld $rD, $src", LdStLD,
235 [(set G8RC:$rD, (load ixaddr:$src))]>, isPPC64;
237 def LWAX : XForm_1<31, 341, (ops G8RC:$rD, memrr:$src),
238 "lwax $rD, $src", LdStLHA,
239 [(set G8RC:$rD, (sextload xaddr:$src, i32))]>, isPPC64,
240 PPC970_DGroup_Cracked;
241 def LDX : XForm_1<31, 21, (ops G8RC:$rD, memrr:$src),
242 "ldx $rD, $src", LdStLD,
243 [(set G8RC:$rD, (load xaddr:$src))]>, isPPC64;
244 def LWZ8 : DForm_1<32, (ops G8RC:$rD, memri:$src),
245 "lwz $rD, $src", LdStGeneral,
246 [(set G8RC:$rD, (zextload iaddr:$src, i32))]>, isPPC64;
248 let isStore = 1, noResults = 1, PPC970_Unit = 2 in {
249 def STD : DSForm_2<62, 0, (ops G8RC:$rS, memrix:$dst),
250 "std $rS, $dst", LdStSTD,
251 [(store G8RC:$rS, ixaddr:$dst)]>, isPPC64;
252 def STDX : XForm_8<31, 149, (ops G8RC:$rS, memrr:$dst),
253 "stdx $rS, $dst", LdStSTD,
254 [(store G8RC:$rS, xaddr:$dst)]>, isPPC64,
255 PPC970_DGroup_Cracked;
256 def STDUX : XForm_8<31, 181, (ops G8RC:$rS, memrr:$dst),
257 "stdux $rS, $dst", LdStSTD,
260 // STD_32/STDX_32 - Just like STD/STDX, but uses a '32-bit' input register.
261 def STD_32 : DSForm_2<62, 0, (ops GPRC:$rT, memrix:$dst),
262 "std $rT, $dst", LdStSTD,
263 [(PPCstd_32 GPRC:$rT, ixaddr:$dst)]>, isPPC64;
264 def STDX_32 : XForm_8<31, 149, (ops GPRC:$rT, memrr:$dst),
265 "stdx $rT, $dst", LdStSTD,
266 [(PPCstd_32 GPRC:$rT, xaddr:$dst)]>, isPPC64,
267 PPC970_DGroup_Cracked;
272 //===----------------------------------------------------------------------===//
273 // Floating point instructions.
277 let PPC970_Unit = 3 in { // FPU Operations.
278 def FCFID : XForm_26<63, 846, (ops F8RC:$frD, F8RC:$frB),
279 "fcfid $frD, $frB", FPGeneral,
280 [(set F8RC:$frD, (PPCfcfid F8RC:$frB))]>, isPPC64;
281 def FCTIDZ : XForm_26<63, 815, (ops F8RC:$frD, F8RC:$frB),
282 "fctidz $frD, $frB", FPGeneral,
283 [(set F8RC:$frD, (PPCfctidz F8RC:$frB))]>, isPPC64;
287 //===----------------------------------------------------------------------===//
288 // Instruction Patterns
291 // Immediate support.
293 // sext(0x0000_0000_0000_FFFF, i8) -> li imm
294 // sext(0x0000_0000_FFFF_0000, i16) -> lis imm>>16
296 // sext(0x0000_0000_FFFF_FFFF, i16) -> lis + ori
297 def sext_0x0000_0000_FFFF_FFFF_i16 : PatLeaf<(imm), [{
298 return N->getValue() == (uint64_t)(int32_t)N->getValue();
300 def : Pat<(i64 sext_0x0000_0000_FFFF_FFFF_i16:$imm),
301 (ORI8 (LIS8 (HI16 imm:$imm)), (LO16 imm:$imm))>;
303 // zext(0x0000_0000_FFFF_7FFF, i16) -> oris (li lo16(imm)), imm>>16
304 def zext_0x0000_0000_FFFF_7FFF_i16 : PatLeaf<(imm), [{
305 return (N->getValue() & 0xFFFFFFFF00008000ULL) == 0;
307 def : Pat<(i64 zext_0x0000_0000_FFFF_7FFF_i16:$imm),
308 (ORIS8 (LI8 (LO16 imm:$imm)), (HI16 imm:$imm))>;
310 // zext(0x0000_0000_FFFF_FFFF, i16) -> oris (ori (li 0), lo16(imm)), imm>>16
311 def zext_0x0000_0000_FFFF_FFFF_i16 : PatLeaf<(imm), [{
312 return (N->getValue() & 0xFFFFFFFF00000000ULL) == 0;
314 def : Pat<(i64 zext_0x0000_0000_FFFF_FFFF_i16:$imm),
315 (ORIS8 (ORI8 (LI8 0), (LO16 imm:$imm)), (HI16 imm:$imm))>;
317 // FIXME: Handle smart forms where the top 32-bits are set. Right now, stuff
318 // like 0xABCD0123BCDE0000 hits the case below, which produces ORI R, R, 0's!
320 // Fully general (and most expensive: 6 instructions!) immediate pattern.
321 def : Pat<(i64 imm:$imm),
326 (LIS8 (HI48_64 imm:$imm)),
333 // Extensions and truncates to/from 32-bit regs.
334 def : Pat<(i64 (zext GPRC:$in)),
335 (RLDICL (OR4To8 GPRC:$in, GPRC:$in), 0, 32)>;
336 def : Pat<(i64 (anyext GPRC:$in)),
337 (OR4To8 GPRC:$in, GPRC:$in)>;
338 def : Pat<(i32 (trunc G8RC:$in)),
339 (OR8To4 G8RC:$in, G8RC:$in)>;
342 def : Pat<(shl G8RC:$in, (i32 imm:$imm)),
343 (RLDICR G8RC:$in, imm:$imm, (SHL64 imm:$imm))>;
344 def : Pat<(srl G8RC:$in, (i32 imm:$imm)),
345 (RLDICL G8RC:$in, (SRL64 imm:$imm), imm:$imm)>;
347 // Hi and Lo for Darwin Global Addresses.
348 def : Pat<(PPChi tglobaladdr:$in, 0), (LIS8 tglobaladdr:$in)>;
349 def : Pat<(PPClo tglobaladdr:$in, 0), (LI8 tglobaladdr:$in)>;
350 def : Pat<(PPChi tconstpool:$in , 0), (LIS8 tconstpool:$in)>;
351 def : Pat<(PPClo tconstpool:$in , 0), (LI8 tconstpool:$in)>;
352 def : Pat<(PPChi tjumptable:$in , 0), (LIS8 tjumptable:$in)>;
353 def : Pat<(PPClo tjumptable:$in , 0), (LI8 tjumptable:$in)>;
354 def : Pat<(add G8RC:$in, (PPChi tglobaladdr:$g, 0)),
355 (ADDIS8 G8RC:$in, tglobaladdr:$g)>;
356 def : Pat<(add G8RC:$in, (PPChi tconstpool:$g, 0)),
357 (ADDIS8 G8RC:$in, tconstpool:$g)>;
358 def : Pat<(add G8RC:$in, (PPChi tjumptable:$g, 0)),
359 (ADDIS8 G8RC:$in, tjumptable:$g)>;