1 //===- SystemZInstrInfo.td - SystemZ Instruction defs ---------*- tblgen-*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file describes the SystemZ instructions in TableGen format.
12 //===----------------------------------------------------------------------===//
14 include "SystemZInstrFormats.td"
16 //===----------------------------------------------------------------------===//
17 // SystemZ Specific Node Definitions.
18 //===----------------------------------------------------------------------===//
19 def SystemZretflag : SDNode<"SystemZISD::RET_FLAG", SDTNone,
20 [SDNPHasChain, SDNPOptInFlag]>;
22 let neverHasSideEffects = 1 in
23 def NOP : Pseudo<(outs), (ins), "# no-op", []>;
25 //===----------------------------------------------------------------------===//
26 // Instruction Pattern Stuff.
27 //===----------------------------------------------------------------------===//
28 def LL16 : SDNodeXForm<imm, [{
29 // Transformation function: return low 16 bits.
30 return getI16Imm(N->getZExtValue() & 0x000000000000FFFFULL);
33 def LH16 : SDNodeXForm<imm, [{
34 // Transformation function: return bits 16-31.
35 return getI16Imm((N->getZExtValue() & 0x00000000FFFF0000ULL) >> 16);
38 def HL16 : SDNodeXForm<imm, [{
39 // Transformation function: return bits 32-47.
40 return getI16Imm((N->getZExtValue() & 0x0000FFFF00000000ULL) >> 32);
43 def HH16 : SDNodeXForm<imm, [{
44 // Transformation function: return bits 48-63.
45 return getI16Imm((N->getZExtValue() & 0xFFFF000000000000ULL) >> 48);
48 def LO32 : SDNodeXForm<imm, [{
49 // Transformation function: return low 32 bits.
50 return getI32Imm(N->getZExtValue() & 0x00000000FFFFFFFFULL);
53 def HI32 : SDNodeXForm<imm, [{
54 // Transformation function: return bits 32-63.
55 return getI32Imm(N->getZExtValue() >> 32);
58 def i64ll16 : PatLeaf<(imm), [{
59 // i64ll16 predicate - true if the 64-bit immediate has only rightmost 16
61 return ((N->getZExtValue() & 0x000000000000FFFFULL) == N->getZExtValue());
64 def i64lh16 : PatLeaf<(imm), [{
65 // i64lh16 predicate - true if the 64-bit immediate has only bits 16-31 set.
66 return ((N->getZExtValue() & 0x00000000FFFF0000ULL) == N->getZExtValue());
69 def i64hl16 : PatLeaf<(i64 imm), [{
70 // i64hl16 predicate - true if the 64-bit immediate has only bits 32-47 set.
71 return ((N->getZExtValue() & 0x0000FFFF00000000ULL) == N->getZExtValue());
74 def i64hh16 : PatLeaf<(i64 imm), [{
75 // i64hh16 predicate - true if the 64-bit immediate has only bits 48-63 set.
76 return ((N->getZExtValue() & 0xFFFF000000000000ULL) == N->getZExtValue());
79 def immSExt16 : PatLeaf<(imm), [{
80 // immSExt16 predicate - true if the immediate fits in a 16-bit sign extended
82 if (N->getValueType(0) == MVT::i64) {
83 uint64_t val = N->getZExtValue();
84 return ((int64_t)val == (int16_t)val);
85 } else if (N->getValueType(0) == MVT::i32) {
86 uint32_t val = N->getZExtValue();
87 return ((int32_t)val == (int16_t)val);
93 def immSExt32 : PatLeaf<(i64 imm), [{
94 // immSExt32 predicate - true if the immediate fits in a 32-bit sign extended
96 uint64_t val = N->getZExtValue();
97 return ((int64_t)val == (int32_t)val);
100 def i64lo32 : PatLeaf<(i64 imm), [{
101 // i64lo32 predicate - true if the 64-bit immediate has only rightmost 32
103 return ((N->getZExtValue() & 0x00000000FFFFFFFFULL) == N->getZExtValue());
106 def i64hi32 : PatLeaf<(i64 imm), [{
107 // i64hi32 predicate - true if the 64-bit immediate has only bits 32-63 set.
108 return ((N->getZExtValue() & 0xFFFFFFFF00000000ULL) == N->getZExtValue());
112 def extloadi64i8 : PatFrag<(ops node:$ptr), (i64 (extloadi8 node:$ptr))>;
113 def extloadi64i16 : PatFrag<(ops node:$ptr), (i64 (extloadi16 node:$ptr))>;
114 def extloadi64i32 : PatFrag<(ops node:$ptr), (i64 (extloadi32 node:$ptr))>;
116 def sextloadi64i8 : PatFrag<(ops node:$ptr), (i64 (sextloadi8 node:$ptr))>;
117 def sextloadi64i16 : PatFrag<(ops node:$ptr), (i64 (sextloadi16 node:$ptr))>;
118 def sextloadi64i32 : PatFrag<(ops node:$ptr), (i64 (sextloadi32 node:$ptr))>;
120 def zextloadi64i8 : PatFrag<(ops node:$ptr), (i64 (zextloadi8 node:$ptr))>;
121 def zextloadi64i16 : PatFrag<(ops node:$ptr), (i64 (zextloadi16 node:$ptr))>;
122 def zextloadi64i32 : PatFrag<(ops node:$ptr), (i64 (zextloadi32 node:$ptr))>;
125 //===----------------------------------------------------------------------===//
126 // SystemZ Operand Definitions.
127 //===----------------------------------------------------------------------===//
131 // riaddr := reg + imm
132 def riaddr32 : Operand<i32>,
133 ComplexPattern<i32, 2, "SelectAddrRI", []> {
134 let PrintMethod = "printRIAddrOperand";
135 let MIOperandInfo = (ops ADDR32:$base, i32imm:$disp);
138 def riaddr : Operand<i64>,
139 ComplexPattern<i64, 2, "SelectAddrRI", []> {
140 let PrintMethod = "printRIAddrOperand";
141 let MIOperandInfo = (ops ADDR64:$base, i32imm:$disp);
144 //===----------------------------------------------------------------------===//
146 // rriaddr := reg + reg + imm
147 def rriaddr : Operand<i64>,
148 ComplexPattern<i64, 3, "SelectAddrRRI", []> {
149 let PrintMethod = "printRRIAddrOperand";
150 let MIOperandInfo = (ops ADDR64:$base, ADDR64:$index, i32imm:$disp);
153 //===----------------------------------------------------------------------===//
154 // Control Flow Instructions...
157 // FIXME: Provide proper encoding!
158 let isReturn = 1, isTerminator = 1 in {
159 def RET : Pseudo<(outs), (ins), "br\t%r14", [(SystemZretflag)]>;
162 //===----------------------------------------------------------------------===//
165 // FIXME: Provide proper encoding!
166 let neverHasSideEffects = 1 in {
167 def MOV32rr : Pseudo<(outs GR32:$dst), (ins GR32:$src),
170 def MOV64rr : Pseudo<(outs GR64:$dst), (ins GR64:$src),
175 def MOVSX64rr32 : Pseudo<(outs GR64:$dst), (ins GR32:$src),
176 "lgfr\t{$dst, $src}",
177 [(set GR64:$dst, (sext GR32:$src))]>;
178 def MOVZX64rr32 : Pseudo<(outs GR64:$dst), (ins GR32:$src),
179 "llgfr\t{$dst, $src}",
180 [(set GR64:$dst, (zext GR32:$src))]>;
182 // FIXME: Provide proper encoding!
183 let isReMaterializable = 1, isAsCheapAsAMove = 1 in {
184 def MOV32ri16 : Pseudo<(outs GR32:$dst), (ins i32imm:$src),
186 [(set GR32:$dst, immSExt16:$src)]>;
187 def MOV64ri16 : Pseudo<(outs GR64:$dst), (ins i64imm:$src),
188 "lghi\t{$dst, $src}",
189 [(set GR64:$dst, immSExt16:$src)]>;
191 def MOV64rill16 : Pseudo<(outs GR64:$dst), (ins i64imm:$src),
192 "llill\t{$dst, $src}",
193 [(set GR64:$dst, i64ll16:$src)]>;
194 def MOV64rilh16 : Pseudo<(outs GR64:$dst), (ins i64imm:$src),
195 "llilh\t{$dst, $src}",
196 [(set GR64:$dst, i64lh16:$src)]>;
197 def MOV64rihl16 : Pseudo<(outs GR64:$dst), (ins i64imm:$src),
198 "llihl\t{$dst, $src}",
199 [(set GR64:$dst, i64hl16:$src)]>;
200 def MOV64rihh16 : Pseudo<(outs GR64:$dst), (ins i64imm:$src),
201 "llihh\t{$dst, $src}",
202 [(set GR64:$dst, i64hh16:$src)]>;
203 // FIXME: these 3 instructions seem to require extimm facility
204 def MOV64ri32 : Pseudo<(outs GR64:$dst), (ins i64imm:$src),
205 "lgfi\t{$dst, $src}",
206 [(set GR64:$dst, immSExt32:$src)]>;
207 def MOV64rilo32 : Pseudo<(outs GR64:$dst), (ins i64imm:$src),
208 "llilf\t{$dst, $src}",
209 [(set GR64:$dst, i64lo32:$src)]>;
210 def MOV64rihi32 : Pseudo<(outs GR64:$dst), (ins i64imm:$src),
211 "llihf\t{$dst, $src}",
212 [(set GR64:$dst, i64hi32:$src)]>;
215 let canFoldAsLoad = 1, isReMaterializable = 1, mayHaveSideEffects = 1 in {
216 def MOV64rm : Pseudo<(outs GR64:$dst), (ins rriaddr:$src),
218 [(set GR64:$dst, (load rriaddr:$src))]>;
222 def MOVSX64rm8 : Pseudo<(outs GR64:$dst), (ins rriaddr:$src),
224 [(set GR64:$dst, (sextloadi64i8 rriaddr:$src))]>;
225 def MOVSX64rm16 : Pseudo<(outs GR64:$dst), (ins rriaddr:$src),
227 [(set GR64:$dst, (sextloadi64i16 rriaddr:$src))]>;
228 def MOVSX64rm32 : Pseudo<(outs GR64:$dst), (ins rriaddr:$src),
230 [(set GR64:$dst, (sextloadi64i32 rriaddr:$src))]>;
232 def MOVZX64rm8 : Pseudo<(outs GR64:$dst), (ins rriaddr:$src),
233 "llgc\t{$dst, $src}",
234 [(set GR64:$dst, (zextloadi64i8 rriaddr:$src))]>;
235 def MOVZX64rm16 : Pseudo<(outs GR64:$dst), (ins rriaddr:$src),
236 "llgh\t{$dst, $src}",
237 [(set GR64:$dst, (zextloadi64i16 rriaddr:$src))]>;
238 def MOVZX64rm32 : Pseudo<(outs GR64:$dst), (ins rriaddr:$src),
239 "llgf\t{$dst, $src}",
240 [(set GR64:$dst, (zextloadi64i32 rriaddr:$src))]>;
243 //===----------------------------------------------------------------------===//
244 // Arithmetic Instructions
246 let isTwoAddress = 1 in {
248 let Defs = [PSW] in {
250 let isCommutable = 1 in { // X = ADD Y, Z == X = ADD Z, Y
251 // FIXME: Provide proper encoding!
252 def ADD32rr : Pseudo<(outs GR32:$dst), (ins GR32:$src1, GR32:$src2),
254 [(set GR32:$dst, (add GR32:$src1, GR32:$src2)),
256 def ADD64rr : Pseudo<(outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
257 "agr\t{$dst, $src2}",
258 [(set GR64:$dst, (add GR64:$src1, GR64:$src2)),
262 // FIXME: Provide proper encoding!
263 def ADD32ri16 : Pseudo<(outs GR32:$dst), (ins GR32:$src1, i32imm:$src2),
264 "ahi\t{$dst, $src2}",
265 [(set GR32:$dst, (add GR32:$src1, immSExt16:$src2)),
267 def ADD32ri : Pseudo<(outs GR32:$dst), (ins GR32:$src1, i32imm:$src2),
268 "afi\t{$dst, $src2}",
269 [(set GR32:$dst, (add GR32:$src1, imm:$src2)),
271 def ADD64ri16 : Pseudo<(outs GR64:$dst), (ins GR64:$src1, i64imm:$src2),
272 "aghi\t{$dst, $src2}",
273 [(set GR64:$dst, (add GR64:$src1, immSExt16:$src2)),
275 def ADD64ri32 : Pseudo<(outs GR64:$dst), (ins GR64:$src1, i64imm:$src2),
276 "agfi\t{$dst, $src2}",
277 [(set GR64:$dst, (add GR64:$src1, immSExt32:$src2)),
280 let isCommutable = 1 in { // X = AND Y, Z == X = AND Z, Y
281 // FIXME: Provide proper encoding!
282 def AND32rr : Pseudo<(outs GR32:$dst), (ins GR32:$src1, GR32:$src2),
284 [(set GR32:$dst, (and GR32:$src1, GR32:$src2))]>;
285 def AND64rr : Pseudo<(outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
286 "ngr\t{$dst, $src2}",
287 [(set GR64:$dst, (and GR64:$src1, GR64:$src2))]>;
290 // FIXME: Provide proper encoding!
291 def AND64rill16 : Pseudo<(outs GR64:$dst), (ins GR64:$src1, i64imm:$src2),
292 "nill\t{$dst, $src2}",
293 [(set GR64:$dst, (and GR64:$src1, i64ll16:$src2))]>;
294 def AND64rilh16 : Pseudo<(outs GR64:$dst), (ins GR64:$src1, i64imm:$src2),
295 "nilh\t{$dst, $src2}",
296 [(set GR64:$dst, (and GR64:$src1, i64lh16:$src2))]>;
297 def AND64rihl16 : Pseudo<(outs GR64:$dst), (ins GR64:$src1, i64imm:$src2),
298 "nihl\t{$dst, $src2}",
299 [(set GR64:$dst, (and GR64:$src1, i64hl16:$src2))]>;
300 def AND64rihh16 : Pseudo<(outs GR64:$dst), (ins GR64:$src1, i64imm:$src2),
301 "nihh\t{$dst, $src2}",
302 [(set GR64:$dst, (and GR64:$src1, i64hh16:$src2))]>;
303 // FIXME: these 2 instructions seem to require extimm facility
304 def AND64rilo32 : Pseudo<(outs GR64:$dst), (ins GR64:$src1, i64imm:$src2),
305 "nilf\t{$dst, $src2}",
306 [(set GR64:$dst, (and GR64:$src1, i64lo32:$src2))]>;
307 def AND64rihi32 : Pseudo<(outs GR64:$dst), (ins GR64:$src1, i64imm:$src2),
308 "nihf\t{$dst, $src2}",
309 [(set GR64:$dst, (and GR64:$src1, i64hi32:$src2))]>;
311 let isCommutable = 1 in { // X = OR Y, Z == X = OR Z, Y
312 // FIXME: Provide proper encoding!
313 def OR32rr : Pseudo<(outs GR32:$dst), (ins GR32:$src1, GR32:$src2),
315 [(set GR32:$dst, (or GR32:$src1, GR32:$src2))]>;
316 def OR64rr : Pseudo<(outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
317 "ogr\t{$dst, $src2}",
318 [(set GR64:$dst, (or GR64:$src1, GR64:$src2))]>;
321 def OR32ri16 : Pseudo<(outs GR32:$dst), (ins GR32:$src1, i16imm:$src2),
322 "oill\t{$dst, $src2}",
323 [(set GR32:$dst, (or GR32:$src1, i64ll16:$src2))]>;
324 def OR32ri16h : Pseudo<(outs GR32:$dst), (ins GR32:$src1, i16imm:$src2),
325 "oilh\t{$dst, $src2}",
326 [(set GR32:$dst, (or GR32:$src1, i64lh16:$src2))]>;
327 def OR32ri : Pseudo<(outs GR32:$dst), (ins GR32:$src1, i32imm:$src2),
328 "oilf\t{$dst, $src2}",
329 [(set GR32:$dst, (or GR32:$src1, imm:$src2))]>;
331 def OR64rill16 : Pseudo<(outs GR64:$dst), (ins GR64:$src1, i64imm:$src2),
332 "oill\t{$dst, $src2}",
333 [(set GR64:$dst, (or GR64:$src1, i64ll16:$src2))]>;
334 def OR64rilh16 : Pseudo<(outs GR64:$dst), (ins GR64:$src1, i64imm:$src2),
335 "oilh\t{$dst, $src2}",
336 [(set GR64:$dst, (or GR64:$src1, i64lh16:$src2))]>;
337 def OR64rihl16 : Pseudo<(outs GR64:$dst), (ins GR64:$src1, i64imm:$src2),
338 "oihl\t{$dst, $src2}",
339 [(set GR64:$dst, (or GR64:$src1, i64hl16:$src2))]>;
340 def OR64rihh16 : Pseudo<(outs GR64:$dst), (ins GR64:$src1, i64imm:$src2),
341 "oihh\t{$dst, $src2}",
342 [(set GR64:$dst, (or GR64:$src1, i64hh16:$src2))]>;
343 // FIXME: these 2 instructions seem to require extimm facility
344 def OR64rilo32 : Pseudo<(outs GR64:$dst), (ins GR64:$src1, i64imm:$src2),
345 "oilf\t{$dst, $src2}",
346 [(set GR64:$dst, (or GR64:$src1, i64lo32:$src2))]>;
347 def OR64rihi32 : Pseudo<(outs GR64:$dst), (ins GR64:$src1, i64imm:$src2),
348 "oihf\t{$dst, $src2}",
349 [(set GR64:$dst, (or GR64:$src1, i64hi32:$src2))]>;
351 // FIXME: Provide proper encoding!
352 def SUB32rr : Pseudo<(outs GR32:$dst), (ins GR32:$src1, GR32:$src2),
354 [(set GR32:$dst, (sub GR32:$src1, GR32:$src2))]>;
355 def SUB64rr : Pseudo<(outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
356 "sgr\t{$dst, $src2}",
357 [(set GR64:$dst, (sub GR64:$src1, GR64:$src2))]>;
360 let isCommutable = 1 in { // X = XOR Y, Z == X = XOR Z, Y
361 // FIXME: Provide proper encoding!
362 def XOR32rr : Pseudo<(outs GR32:$dst), (ins GR32:$src1, GR32:$src2),
364 [(set GR32:$dst, (xor GR32:$src1, GR32:$src2))]>;
365 def XOR64rr : Pseudo<(outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
366 "xgr\t{$dst, $src2}",
367 [(set GR64:$dst, (xor GR64:$src1, GR64:$src2))]>;
370 def XOR32ri : Pseudo<(outs GR32:$dst), (ins GR32:$src1, i32imm:$src2),
371 "xilf\t{$dst, $src2}",
372 [(set GR32:$dst, (xor GR32:$src1, imm:$src2))]>;
374 // FIXME: these 2 instructions seem to require extimm facility
375 def XOR64rilo32 : Pseudo<(outs GR64:$dst), (ins GR64:$src1, i64imm:$src2),
376 "xilf\t{$dst, $src2}",
377 [(set GR64:$dst, (xor GR64:$src1, i64lo32:$src2))]>;
378 def XOR64rihi32 : Pseudo<(outs GR64:$dst), (ins GR64:$src1, i64imm:$src2),
379 "xihf\t{$dst, $src2}",
380 [(set GR64:$dst, (xor GR64:$src1, i64hi32:$src2))]>;
383 } // isTwoAddress = 1
385 //===----------------------------------------------------------------------===//
388 let isTwoAddress = 1 in
389 def SRL32rri : Pseudo<(outs GR32:$dst), (ins GR32:$src, riaddr32:$amt),
391 [(set GR32:$dst, (srl GR32:$src, riaddr32:$amt))]>;
392 def SRL64rri : Pseudo<(outs GR64:$dst), (ins GR64:$src, riaddr:$amt),
393 "srlg\t{$dst, $src, $amt}",
394 [(set GR64:$dst, (srl GR64:$src, (i32 (trunc riaddr:$amt))))]>;
395 def SRLA64ri : Pseudo<(outs GR64:$dst), (ins GR64:$src, i32imm:$amt),
396 "srlg\t{$dst, $src, $amt}",
397 [(set GR64:$dst, (srl GR64:$src, (i32 imm:$amt)))]>;
399 let isTwoAddress = 1 in
400 def SHL32rri : Pseudo<(outs GR32:$dst), (ins GR32:$src, riaddr32:$amt),
402 [(set GR32:$dst, (shl GR32:$src, riaddr32:$amt))]>;
403 def SHL64rri : Pseudo<(outs GR64:$dst), (ins GR64:$src, riaddr:$amt),
404 "sllg\t{$dst, $src, $amt}",
405 [(set GR64:$dst, (shl GR64:$src, (i32 (trunc riaddr:$amt))))]>;
406 def SHL64ri : Pseudo<(outs GR64:$dst), (ins GR64:$src, i32imm:$amt),
407 "sllg\t{$dst, $src, $amt}",
408 [(set GR64:$dst, (shl GR64:$src, (i32 imm:$amt)))]>;
411 let Defs = [PSW] in {
412 let isTwoAddress = 1 in
413 def SRA32rri : Pseudo<(outs GR32:$dst), (ins GR32:$src, riaddr32:$amt),
415 [(set GR32:$dst, (sra GR32:$src, riaddr32:$amt)),
417 def SRA64rri : Pseudo<(outs GR64:$dst), (ins GR64:$src, riaddr:$amt),
418 "srag\t{$dst, $src, $amt}",
419 [(set GR64:$dst, (sra GR64:$src, (i32 (trunc riaddr:$amt)))),
421 def SRA64ri : Pseudo<(outs GR64:$dst), (ins GR64:$src, i32imm:$amt),
422 "srag\t{$dst, $src, $amt}",
423 [(set GR64:$dst, (sra GR64:$src, (i32 imm:$amt))),
427 //===----------------------------------------------------------------------===//
428 // Non-Instruction Patterns.
429 //===----------------------------------------------------------------------===//
432 def : Pat<(i64 (anyext GR32:$src)),
433 (INSERT_SUBREG (i64 (IMPLICIT_DEF)), GR32:$src, subreg_32bit)>;
435 //===----------------------------------------------------------------------===//
437 //===----------------------------------------------------------------------===//
439 // FIXME: use add/sub tricks with 32678/-32768
442 def : Pat<(i32 (trunc GR64:$src)),
443 (EXTRACT_SUBREG GR64:$src, subreg_32bit)>;
445 // sext_inreg patterns
446 def : Pat<(sext_inreg GR64:$src, i32),
447 (MOVSX64rr32 (EXTRACT_SUBREG GR64:$src, subreg_32bit))>;
450 def : Pat<(extloadi64i8 rriaddr:$src), (MOVZX64rm8 rriaddr:$src)>;
451 def : Pat<(extloadi64i16 rriaddr:$src), (MOVZX64rm16 rriaddr:$src)>;
452 def : Pat<(extloadi64i32 rriaddr:$src), (MOVZX64rm32 rriaddr:$src)>;