Some preliminary call lowering
[oota-llvm.git] / lib / Target / SystemZ / SystemZInstrInfo.td
1 //===- SystemZInstrInfo.td - SystemZ Instruction defs ---------*- tblgen-*-===//
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 SystemZ instructions in TableGen format.
11 //
12 //===----------------------------------------------------------------------===//
13
14 include "SystemZInstrFormats.td"
15
16 //===----------------------------------------------------------------------===//
17 // Type Constraints.
18 //===----------------------------------------------------------------------===//
19 class SDTCisI8<int OpNum> : SDTCisVT<OpNum, i8>;
20 class SDTCisI16<int OpNum> : SDTCisVT<OpNum, i16>;
21 class SDTCisI32<int OpNum> : SDTCisVT<OpNum, i32>;
22 class SDTCisI64<int OpNum> : SDTCisVT<OpNum, i64>;
23
24 //===----------------------------------------------------------------------===//
25 // Type Profiles.
26 //===----------------------------------------------------------------------===//
27 def SDT_SystemZCall         : SDTypeProfile<0, -1, [SDTCisVT<0, iPTR>]>;
28 def SDT_SystemZCallSeqStart : SDCallSeqStart<[SDTCisI64<0>]>;
29 def SDT_SystemZCallSeqEnd   : SDCallSeqEnd<[SDTCisI64<0>, SDTCisI64<1>]>;
30
31 //===----------------------------------------------------------------------===//
32 // SystemZ Specific Node Definitions.
33 //===----------------------------------------------------------------------===//
34 def SystemZretflag : SDNode<"SystemZISD::RET_FLAG", SDTNone,
35                      [SDNPHasChain, SDNPOptInFlag]>;
36 def SystemZcall    : SDNode<"SystemZISD::CALL", SDT_SystemZCall,
37                      [SDNPHasChain, SDNPOutFlag, SDNPOptInFlag]>;
38 def SystemZcallseq_start :
39                  SDNode<"ISD::CALLSEQ_START", SDT_SystemZCallSeqStart,
40                         [SDNPHasChain, SDNPOutFlag]>;
41 def SystemZcallseq_end :
42                  SDNode<"ISD::CALLSEQ_END",   SDT_SystemZCallSeqEnd,
43                         [SDNPHasChain, SDNPOptInFlag, SDNPOutFlag]>;
44
45 //===----------------------------------------------------------------------===//
46 // Instruction Pattern Stuff.
47 //===----------------------------------------------------------------------===//
48 def LL16 : SDNodeXForm<imm, [{
49   // Transformation function: return low 16 bits.
50   return getI16Imm(N->getZExtValue() & 0x000000000000FFFFULL);
51 }]>;
52
53 def LH16 : SDNodeXForm<imm, [{
54   // Transformation function: return bits 16-31.
55   return getI16Imm((N->getZExtValue() & 0x00000000FFFF0000ULL) >> 16);
56 }]>;
57
58 def HL16 : SDNodeXForm<imm, [{
59   // Transformation function: return bits 32-47.
60   return getI16Imm((N->getZExtValue() & 0x0000FFFF00000000ULL) >> 32);
61 }]>;
62
63 def HH16 : SDNodeXForm<imm, [{
64   // Transformation function: return bits 48-63.
65   return getI16Imm((N->getZExtValue() & 0xFFFF000000000000ULL) >> 48);
66 }]>;
67
68 def LO32 : SDNodeXForm<imm, [{
69   // Transformation function: return low 32 bits.
70   return getI32Imm(N->getZExtValue() & 0x00000000FFFFFFFFULL);
71 }]>;
72
73 def HI32 : SDNodeXForm<imm, [{
74   // Transformation function: return bits 32-63.
75   return getI32Imm(N->getZExtValue() >> 32);
76 }]>;
77
78 def i64ll16 : PatLeaf<(imm), [{  
79   // i64ll16 predicate - true if the 64-bit immediate has only rightmost 16
80   // bits set.
81   return ((N->getZExtValue() & 0x000000000000FFFFULL) == N->getZExtValue());
82 }], LL16>;
83
84 def i64lh16 : PatLeaf<(imm), [{  
85   // i64lh16 predicate - true if the 64-bit immediate has only bits 16-31 set.
86   return ((N->getZExtValue() & 0x00000000FFFF0000ULL) == N->getZExtValue());
87 }], LH16>;
88
89 def i64hl16 : PatLeaf<(i64 imm), [{  
90   // i64hl16 predicate - true if the 64-bit immediate has only bits 32-47 set.
91   return ((N->getZExtValue() & 0x0000FFFF00000000ULL) == N->getZExtValue());
92 }], HL16>;
93
94 def i64hh16 : PatLeaf<(i64 imm), [{  
95   // i64hh16 predicate - true if the 64-bit immediate has only bits 48-63 set.
96   return ((N->getZExtValue() & 0xFFFF000000000000ULL) == N->getZExtValue());
97 }], HH16>;
98
99 def immSExt16 : PatLeaf<(imm), [{
100   // immSExt16 predicate - true if the immediate fits in a 16-bit sign extended
101   // field.
102   if (N->getValueType(0) == MVT::i64) {
103     uint64_t val = N->getZExtValue();
104     return ((int64_t)val == (int16_t)val);
105   } else if (N->getValueType(0) == MVT::i32) {
106     uint32_t val = N->getZExtValue();
107     return ((int32_t)val == (int16_t)val);
108   }
109
110   return false;
111 }]>;
112
113 def immSExt32 : PatLeaf<(i64 imm), [{
114   // immSExt32 predicate - true if the immediate fits in a 32-bit sign extended
115   // field.
116   uint64_t val = N->getZExtValue();
117   return ((int64_t)val == (int32_t)val);
118 }]>;
119
120 def i64lo32 : PatLeaf<(i64 imm), [{
121   // i64lo32 predicate - true if the 64-bit immediate has only rightmost 32
122   // bits set.
123   return ((N->getZExtValue() & 0x00000000FFFFFFFFULL) == N->getZExtValue());
124 }], LO32>;
125
126 def i64hi32 : PatLeaf<(i64 imm), [{
127   // i64hi32 predicate - true if the 64-bit immediate has only bits 32-63 set.
128   return ((N->getZExtValue() & 0xFFFFFFFF00000000ULL) == N->getZExtValue());
129 }], HI32>;
130
131 def i32immSExt8  : PatLeaf<(i32 imm), [{
132   // i32immSExt8 predicate - True if the 32-bit immediate fits in a 8-bit
133   // sign extended field.
134   return (int32_t)N->getZExtValue() == (int8_t)N->getZExtValue();
135 }]>;
136
137 def i32immSExt16 : PatLeaf<(i32 imm), [{
138   // i32immSExt16 predicate - True if the 32-bit immediate fits in a 16-bit
139   // sign extended field.
140   return (int32_t)N->getZExtValue() == (int16_t)N->getZExtValue();
141 }]>;
142
143 // extloads
144 def extloadi64i8   : PatFrag<(ops node:$ptr), (i64 (extloadi8  node:$ptr))>;
145 def extloadi64i16  : PatFrag<(ops node:$ptr), (i64 (extloadi16 node:$ptr))>;
146 def extloadi64i32  : PatFrag<(ops node:$ptr), (i64 (extloadi32 node:$ptr))>;
147
148 def sextloadi64i8   : PatFrag<(ops node:$ptr), (i64 (sextloadi8  node:$ptr))>;
149 def sextloadi64i16  : PatFrag<(ops node:$ptr), (i64 (sextloadi16 node:$ptr))>;
150 def sextloadi64i32  : PatFrag<(ops node:$ptr), (i64 (sextloadi32 node:$ptr))>;
151
152 def zextloadi64i8   : PatFrag<(ops node:$ptr), (i64 (zextloadi8  node:$ptr))>;
153 def zextloadi64i16  : PatFrag<(ops node:$ptr), (i64 (zextloadi16 node:$ptr))>;
154 def zextloadi64i32  : PatFrag<(ops node:$ptr), (i64 (zextloadi32 node:$ptr))>;
155
156 // A couple of more descriptive operand definitions.
157 // 32-bits but only 8 bits are significant.
158 def i32i8imm  : Operand<i32>;
159 // 32-bits but only 16 bits are significant.
160 def i32i16imm : Operand<i32>;
161
162 //===----------------------------------------------------------------------===//
163 // SystemZ Operand Definitions.
164 //===----------------------------------------------------------------------===//
165
166 // Address operands
167
168 // riaddr := reg + imm
169 def riaddr32 : Operand<i32>,
170                ComplexPattern<i32, 2, "SelectAddrRI", []> {
171   let PrintMethod = "printRIAddrOperand";
172   let MIOperandInfo = (ops ADDR32:$base, i32imm:$disp);
173 }
174
175 def riaddr : Operand<i64>,
176              ComplexPattern<i64, 2, "SelectAddrRI", []> {
177   let PrintMethod = "printRIAddrOperand";
178   let MIOperandInfo = (ops ADDR64:$base, i64imm:$disp);
179 }
180
181 //===----------------------------------------------------------------------===//
182
183 // rriaddr := reg + reg + imm
184 def rriaddr : Operand<i64>,
185               ComplexPattern<i64, 3, "SelectAddrRRI", [], []> {
186   let PrintMethod = "printRRIAddrOperand";
187   let MIOperandInfo = (ops ADDR64:$base, i64imm:$disp, ADDR64:$index);
188 }
189 def laaddr : Operand<i64>,
190              ComplexPattern<i64, 3, "SelectLAAddr", [add, sub, or, frameindex], []> {
191   let PrintMethod = "printRRIAddrOperand";
192   let MIOperandInfo = (ops ADDR64:$base, i64imm:$disp, ADDR64:$index);
193 }
194
195 //===----------------------------------------------------------------------===//
196 // Instruction list..
197
198 // ADJCALLSTACKDOWN/UP implicitly use/def SP because they may be expanded into
199 // a stack adjustment and the codegen must know that they may modify the stack
200 // pointer before prolog-epilog rewriting occurs.
201 // Pessimistically assume ADJCALLSTACKDOWN / ADJCALLSTACKUP will become
202 // sub / add which can clobber R15D.
203 let Defs = [R15D], Uses = [R15D] in {
204 def ADJCALLSTACKDOWN : Pseudo<(outs), (ins i64imm:$amt),
205                               "#ADJCALLSTACKDOWN",
206                               [(SystemZcallseq_start timm:$amt)]>;
207 def ADJCALLSTACKUP   : Pseudo<(outs), (ins i64imm:$amt1, i64imm:$amt2),
208                               "#ADJCALLSTACKUP",
209                               [(SystemZcallseq_end timm:$amt1, timm:$amt2)]>;
210 }
211
212
213 //===----------------------------------------------------------------------===//
214 //  Control Flow Instructions...
215 //
216
217 // FIXME: Provide proper encoding!
218 let isReturn = 1, isTerminator = 1, Uses = [R14D] in {
219   def RET : Pseudo<(outs), (ins), "br\t%r14", [(SystemZretflag)]>;
220 }
221
222 //===----------------------------------------------------------------------===//
223 //  Call Instructions...
224 //
225
226 let isCall = 1 in
227   // All calls clobber the non-callee saved registers. R15 is marked as
228   // a use to prevent stack-pointer assignments that appear immediately
229   // before calls from potentially appearing dead. Uses for argument
230   // registers are added manually.
231   let Defs = [R0D, R1D, R3D, R4D, R5D, R14D, R15D],
232       Uses = [R15D] in {
233     def CALLi     : Pseudo<(outs), (ins i64imm:$dst, variable_ops),
234                            "brasl\t%r14, $dst", [(SystemZcall imm:$dst)]>;
235     def CALLr     : Pseudo<(outs), (ins ADDR64:$dst, variable_ops),
236                            "brasl\t%r14, $dst", [(SystemZcall ADDR64:$dst)]>;
237   }
238
239 //===----------------------------------------------------------------------===//
240 //  Miscellaneous Instructions.
241 //
242
243 let isReMaterializable = 1 in
244 // FIXME: Provide imm12 variant
245 def LA64r  : Pseudo<(outs GR64:$dst), (ins laaddr:$src),
246                     "lay\t{$dst, $src}",
247                     [(set GR64:$dst, laaddr:$src)]>;
248
249 let neverHasSideEffects = 1 in
250 def NOP : Pseudo<(outs), (ins), "# no-op", []>;
251
252 //===----------------------------------------------------------------------===//
253 // Move Instructions
254
255 // FIXME: Provide proper encoding!
256 let neverHasSideEffects = 1 in {
257 def MOV32rr : Pseudo<(outs GR32:$dst), (ins GR32:$src),
258                      "lr\t{$dst, $src}",
259                      []>;
260 def MOV64rr : Pseudo<(outs GR64:$dst), (ins GR64:$src),
261                      "lgr\t{$dst, $src}",
262                      []>;
263 }
264
265 def MOVSX64rr32 : Pseudo<(outs GR64:$dst), (ins GR32:$src),
266                          "lgfr\t{$dst, $src}",
267                          [(set GR64:$dst, (sext GR32:$src))]>;
268 def MOVZX64rr32 : Pseudo<(outs GR64:$dst), (ins GR32:$src),
269                          "llgfr\t{$dst, $src}",
270                          [(set GR64:$dst, (zext GR32:$src))]>;
271
272 // FIXME: Provide proper encoding!
273 let isReMaterializable = 1, isAsCheapAsAMove = 1 in {
274 def MOV32ri16 : Pseudo<(outs GR32:$dst), (ins i32imm:$src),
275                        "lhi\t{$dst, $src}",
276                        [(set GR32:$dst, immSExt16:$src)]>;
277 def MOV64ri16 : Pseudo<(outs GR64:$dst), (ins i64imm:$src),
278                        "lghi\t{$dst, $src}",
279                        [(set GR64:$dst, immSExt16:$src)]>;
280
281 def MOV64rill16 : Pseudo<(outs GR64:$dst), (ins i64imm:$src),
282                          "llill\t{$dst, $src}",
283                          [(set GR64:$dst, i64ll16:$src)]>;
284 def MOV64rilh16 : Pseudo<(outs GR64:$dst), (ins i64imm:$src),
285                          "llilh\t{$dst, $src}",
286                          [(set GR64:$dst, i64lh16:$src)]>;
287 def MOV64rihl16 : Pseudo<(outs GR64:$dst), (ins i64imm:$src),
288                          "llihl\t{$dst, $src}",
289                          [(set GR64:$dst, i64hl16:$src)]>;
290 def MOV64rihh16 : Pseudo<(outs GR64:$dst), (ins i64imm:$src),
291                          "llihh\t{$dst, $src}",
292                          [(set GR64:$dst, i64hh16:$src)]>;
293 // FIXME: these 3 instructions seem to require extimm facility
294 def MOV64ri32 : Pseudo<(outs GR64:$dst), (ins i64imm:$src),
295                        "lgfi\t{$dst, $src}",
296                        [(set GR64:$dst, immSExt32:$src)]>;
297 def MOV64rilo32 : Pseudo<(outs GR64:$dst), (ins i64imm:$src),
298                          "llilf\t{$dst, $src}",
299                          [(set GR64:$dst, i64lo32:$src)]>;
300 def MOV64rihi32 : Pseudo<(outs GR64:$dst), (ins i64imm:$src),
301                          "llihf\t{$dst, $src}",
302                          [(set GR64:$dst, i64hi32:$src)]>;
303 }
304
305 let canFoldAsLoad = 1, isReMaterializable = 1, mayHaveSideEffects = 1 in {
306 def MOV64rm : Pseudo<(outs GR64:$dst), (ins rriaddr:$src),
307                      "lg\t{$dst, $src}",
308                      [(set GR64:$dst, (load rriaddr:$src))]>;
309
310 }
311
312 def MOV64mr : Pseudo<(outs), (ins rriaddr:$dst, GR64:$src),
313                      "stg\t{$src, $dst}",
314                      [(store GR64:$src, rriaddr:$dst)]>;
315
316 // FIXME: displacements here are really 12 bit, not 20!
317 def MOV8mi    : Pseudo<(outs), (ins riaddr:$dst, i32i8imm:$src),
318                        "mvi\t{$dst, $src}",
319                        [(truncstorei8 (i32 i32immSExt8:$src), riaddr:$dst)]>;
320 def MOV16mi   : Pseudo<(outs), (ins riaddr:$dst, i32i16imm:$src),
321                        "mvhhi\t{$dst, $src}",
322                        [(truncstorei16 (i32 i32immSExt16:$src), riaddr:$dst)]>;
323 def MOV32mi16 : Pseudo<(outs), (ins riaddr:$dst, i32imm:$src),
324                        "mvhi\t{$dst, $src}",
325                        [(store (i32 immSExt16:$src), riaddr:$dst)]>;
326 def MOV64mi16 : Pseudo<(outs), (ins riaddr:$dst, i64imm:$src),
327                        "mvghi\t{$dst, $src}",
328                        [(store (i64 immSExt16:$src), riaddr:$dst)]>;
329
330 // extloads
331 def MOVSX64rm8  : Pseudo<(outs GR64:$dst), (ins rriaddr:$src),
332                          "lgb\t{$dst, $src}",
333                          [(set GR64:$dst, (sextloadi64i8 rriaddr:$src))]>;
334 def MOVSX64rm16 : Pseudo<(outs GR64:$dst), (ins rriaddr:$src),
335                          "lgh\t{$dst, $src}",
336                          [(set GR64:$dst, (sextloadi64i16 rriaddr:$src))]>;
337 def MOVSX64rm32 : Pseudo<(outs GR64:$dst), (ins rriaddr:$src),
338                          "lgf\t{$dst, $src}",
339                          [(set GR64:$dst, (sextloadi64i32 rriaddr:$src))]>;
340
341 def MOVZX64rm8  : Pseudo<(outs GR64:$dst), (ins rriaddr:$src),
342                          "llgc\t{$dst, $src}",
343                          [(set GR64:$dst, (zextloadi64i8 rriaddr:$src))]>;
344 def MOVZX64rm16 : Pseudo<(outs GR64:$dst), (ins rriaddr:$src),
345                          "llgh\t{$dst, $src}",
346                          [(set GR64:$dst, (zextloadi64i16 rriaddr:$src))]>;
347 def MOVZX64rm32 : Pseudo<(outs GR64:$dst), (ins rriaddr:$src),
348                          "llgf\t{$dst, $src}",
349                          [(set GR64:$dst, (zextloadi64i32 rriaddr:$src))]>;
350
351 // truncstores
352 // FIXME: Implement 12-bit displacement stuff someday
353 def MOV32m8r  : Pseudo<(outs), (ins rriaddr:$dst, GR32:$src),
354                        "stcy\t{$src, $dst}",
355                        [(truncstorei8 GR32:$src, rriaddr:$dst)]>;
356
357 def MOV32m16r : Pseudo<(outs), (ins rriaddr:$dst, GR32:$src),
358                        "sthy\t{$src, $dst}",
359                        [(truncstorei16 GR32:$src, rriaddr:$dst)]>;
360
361 def MOV64m8r  : Pseudo<(outs), (ins rriaddr:$dst, GR64:$src),
362                        "stcy\t{$src, $dst}",
363                        [(truncstorei8 GR64:$src, rriaddr:$dst)]>;
364
365 def MOV64m16r : Pseudo<(outs), (ins rriaddr:$dst, GR64:$src),
366                        "sthy\t{$src, $dst}",
367                        [(truncstorei16 GR64:$src, rriaddr:$dst)]>;
368
369 def MOV64m32r : Pseudo<(outs), (ins rriaddr:$dst, GR64:$src),
370                        "sty\t{$src, $dst}",
371                        [(truncstorei32 GR64:$src, rriaddr:$dst)]>;
372
373 //===----------------------------------------------------------------------===//
374 // Arithmetic Instructions
375
376 let isTwoAddress = 1 in {
377
378 let Defs = [PSW] in {
379
380 let isCommutable = 1 in { // X = ADD Y, Z  == X = ADD Z, Y
381 // FIXME: Provide proper encoding!
382 def ADD32rr : Pseudo<(outs GR32:$dst), (ins GR32:$src1, GR32:$src2),
383                      "ar\t{$dst, $src2}",
384                      [(set GR32:$dst, (add GR32:$src1, GR32:$src2)),
385                       (implicit PSW)]>;
386 def ADD64rr : Pseudo<(outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
387                      "agr\t{$dst, $src2}",
388                      [(set GR64:$dst, (add GR64:$src1, GR64:$src2)),
389                       (implicit PSW)]>;
390 }
391
392 // FIXME: Provide proper encoding!
393 def ADD32ri16 : Pseudo<(outs GR32:$dst), (ins GR32:$src1, i32imm:$src2),
394                        "ahi\t{$dst, $src2}",
395                        [(set GR32:$dst, (add GR32:$src1, immSExt16:$src2)),
396                         (implicit PSW)]>;
397 def ADD32ri   : Pseudo<(outs GR32:$dst), (ins GR32:$src1, i32imm:$src2),
398                        "afi\t{$dst, $src2}",
399                        [(set GR32:$dst, (add GR32:$src1, imm:$src2)),
400                         (implicit PSW)]>;
401 def ADD64ri16 : Pseudo<(outs GR64:$dst), (ins GR64:$src1, i64imm:$src2),
402                        "aghi\t{$dst, $src2}",
403                        [(set GR64:$dst, (add GR64:$src1, immSExt16:$src2)),
404                         (implicit PSW)]>;
405 def ADD64ri32 : Pseudo<(outs GR64:$dst), (ins GR64:$src1, i64imm:$src2),
406                        "agfi\t{$dst, $src2}",
407                        [(set GR64:$dst, (add GR64:$src1, immSExt32:$src2)),
408                         (implicit PSW)]>;
409
410 let isCommutable = 1 in { // X = AND Y, Z  == X = AND Z, Y
411 // FIXME: Provide proper encoding!
412 def AND32rr : Pseudo<(outs GR32:$dst), (ins GR32:$src1, GR32:$src2),
413                      "nr\t{$dst, $src2}",
414                      [(set GR32:$dst, (and GR32:$src1, GR32:$src2))]>;
415 def AND64rr : Pseudo<(outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
416                      "ngr\t{$dst, $src2}",
417                      [(set GR64:$dst, (and GR64:$src1, GR64:$src2))]>;
418 }
419
420 // FIXME: Provide proper encoding!
421 def AND64rill16 : Pseudo<(outs GR64:$dst), (ins GR64:$src1, i64imm:$src2),
422                          "nill\t{$dst, $src2}",
423                          [(set GR64:$dst, (and GR64:$src1, i64ll16:$src2))]>;
424 def AND64rilh16 : Pseudo<(outs GR64:$dst), (ins GR64:$src1, i64imm:$src2),
425                          "nilh\t{$dst, $src2}",
426                          [(set GR64:$dst, (and GR64:$src1, i64lh16:$src2))]>;
427 def AND64rihl16 : Pseudo<(outs GR64:$dst), (ins GR64:$src1, i64imm:$src2),
428                          "nihl\t{$dst, $src2}",
429                          [(set GR64:$dst, (and GR64:$src1, i64hl16:$src2))]>;
430 def AND64rihh16 : Pseudo<(outs GR64:$dst), (ins GR64:$src1, i64imm:$src2),
431                          "nihh\t{$dst, $src2}",
432                          [(set GR64:$dst, (and GR64:$src1, i64hh16:$src2))]>;
433 // FIXME: these 2 instructions seem to require extimm facility
434 def AND64rilo32 : Pseudo<(outs GR64:$dst), (ins GR64:$src1, i64imm:$src2),
435                          "nilf\t{$dst, $src2}",
436                          [(set GR64:$dst, (and GR64:$src1, i64lo32:$src2))]>;
437 def AND64rihi32 : Pseudo<(outs GR64:$dst), (ins GR64:$src1, i64imm:$src2),
438                          "nihf\t{$dst, $src2}",
439                          [(set GR64:$dst, (and GR64:$src1, i64hi32:$src2))]>;
440
441 let isCommutable = 1 in { // X = OR Y, Z  == X = OR Z, Y
442 // FIXME: Provide proper encoding!
443 def OR32rr : Pseudo<(outs GR32:$dst), (ins GR32:$src1, GR32:$src2),
444                     "or\t{$dst, $src2}",
445                     [(set GR32:$dst, (or GR32:$src1, GR32:$src2))]>;
446 def OR64rr : Pseudo<(outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
447                     "ogr\t{$dst, $src2}",
448                     [(set GR64:$dst, (or GR64:$src1, GR64:$src2))]>;
449 }
450
451 def OR32ri16  : Pseudo<(outs GR32:$dst), (ins GR32:$src1, i16imm:$src2),
452                       "oill\t{$dst, $src2}",
453                       [(set GR32:$dst, (or GR32:$src1, i64ll16:$src2))]>;
454 def OR32ri16h : Pseudo<(outs GR32:$dst), (ins GR32:$src1, i16imm:$src2),
455                       "oilh\t{$dst, $src2}",
456                       [(set GR32:$dst, (or GR32:$src1, i64lh16:$src2))]>;
457 def OR32ri : Pseudo<(outs GR32:$dst), (ins GR32:$src1, i32imm:$src2),
458                     "oilf\t{$dst, $src2}",
459                     [(set GR32:$dst, (or GR32:$src1, imm:$src2))]>;
460
461 def OR64rill16 : Pseudo<(outs GR64:$dst), (ins GR64:$src1, i64imm:$src2),
462                         "oill\t{$dst, $src2}",
463                         [(set GR64:$dst, (or GR64:$src1, i64ll16:$src2))]>;
464 def OR64rilh16 : Pseudo<(outs GR64:$dst), (ins GR64:$src1, i64imm:$src2),
465                         "oilh\t{$dst, $src2}",
466                         [(set GR64:$dst, (or GR64:$src1, i64lh16:$src2))]>;
467 def OR64rihl16 : Pseudo<(outs GR64:$dst), (ins GR64:$src1, i64imm:$src2),
468                         "oihl\t{$dst, $src2}",
469                         [(set GR64:$dst, (or GR64:$src1, i64hl16:$src2))]>;
470 def OR64rihh16 : Pseudo<(outs GR64:$dst), (ins GR64:$src1, i64imm:$src2),
471                         "oihh\t{$dst, $src2}",
472                         [(set GR64:$dst, (or GR64:$src1, i64hh16:$src2))]>;
473 // FIXME: these 2 instructions seem to require extimm facility
474 def OR64rilo32 : Pseudo<(outs GR64:$dst), (ins GR64:$src1, i64imm:$src2),
475                         "oilf\t{$dst, $src2}",
476                         [(set GR64:$dst, (or GR64:$src1, i64lo32:$src2))]>;
477 def OR64rihi32 : Pseudo<(outs GR64:$dst), (ins GR64:$src1, i64imm:$src2),
478                         "oihf\t{$dst, $src2}",
479                         [(set GR64:$dst, (or GR64:$src1, i64hi32:$src2))]>;
480
481 // FIXME: Provide proper encoding!
482 def SUB32rr : Pseudo<(outs GR32:$dst), (ins GR32:$src1, GR32:$src2),
483                      "sr\t{$dst, $src2}",
484                      [(set GR32:$dst, (sub GR32:$src1, GR32:$src2))]>;
485 def SUB64rr : Pseudo<(outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
486                      "sgr\t{$dst, $src2}",
487                      [(set GR64:$dst, (sub GR64:$src1, GR64:$src2))]>;
488
489
490 let isCommutable = 1 in { // X = XOR Y, Z  == X = XOR Z, Y
491 // FIXME: Provide proper encoding!
492 def XOR32rr : Pseudo<(outs GR32:$dst), (ins GR32:$src1, GR32:$src2),
493                      "xr\t{$dst, $src2}",
494                      [(set GR32:$dst, (xor GR32:$src1, GR32:$src2))]>;
495 def XOR64rr : Pseudo<(outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
496                      "xgr\t{$dst, $src2}",
497                      [(set GR64:$dst, (xor GR64:$src1, GR64:$src2))]>;
498 }
499
500 def XOR32ri : Pseudo<(outs GR32:$dst), (ins GR32:$src1, i32imm:$src2),
501                      "xilf\t{$dst, $src2}",
502                      [(set GR32:$dst, (xor GR32:$src1, imm:$src2))]>;
503
504 // FIXME: these 2 instructions seem to require extimm facility
505 def XOR64rilo32 : Pseudo<(outs GR64:$dst), (ins GR64:$src1, i64imm:$src2),
506                          "xilf\t{$dst, $src2}",
507                          [(set GR64:$dst, (xor GR64:$src1, i64lo32:$src2))]>;
508 def XOR64rihi32 : Pseudo<(outs GR64:$dst), (ins GR64:$src1, i64imm:$src2),
509                          "xihf\t{$dst, $src2}",
510                          [(set GR64:$dst, (xor GR64:$src1, i64hi32:$src2))]>;
511
512 } // Defs = [PSW]
513 } // isTwoAddress = 1
514
515 //===----------------------------------------------------------------------===//
516 // Shifts
517
518 let isTwoAddress = 1 in
519 def SRL32rri : Pseudo<(outs GR32:$dst), (ins GR32:$src, riaddr32:$amt),
520                       "srl\t{$src, $amt}",
521                       [(set GR32:$dst, (srl GR32:$src, riaddr32:$amt))]>;
522 def SRL64rri : Pseudo<(outs GR64:$dst), (ins GR64:$src, riaddr:$amt),
523                       "srlg\t{$dst, $src, $amt}",
524                       [(set GR64:$dst, (srl GR64:$src, (i32 (trunc riaddr:$amt))))]>;
525 def SRLA64ri  : Pseudo<(outs GR64:$dst), (ins GR64:$src, i32imm:$amt),
526                       "srlg\t{$dst, $src, $amt}",
527                       [(set GR64:$dst, (srl GR64:$src, (i32 imm:$amt)))]>;
528
529 let isTwoAddress = 1 in
530 def SHL32rri : Pseudo<(outs GR32:$dst), (ins GR32:$src, riaddr32:$amt),
531                       "sll\t{$src, $amt}",
532                       [(set GR32:$dst, (shl GR32:$src, riaddr32:$amt))]>;
533 def SHL64rri : Pseudo<(outs GR64:$dst), (ins GR64:$src, riaddr:$amt),
534                       "sllg\t{$dst, $src, $amt}",
535                       [(set GR64:$dst, (shl GR64:$src, (i32 (trunc riaddr:$amt))))]>;
536 def SHL64ri  : Pseudo<(outs GR64:$dst), (ins GR64:$src, i32imm:$amt),
537                       "sllg\t{$dst, $src, $amt}",
538                       [(set GR64:$dst, (shl GR64:$src, (i32 imm:$amt)))]>;
539
540
541 let Defs = [PSW] in {
542 let isTwoAddress = 1 in
543 def SRA32rri : Pseudo<(outs GR32:$dst), (ins GR32:$src, riaddr32:$amt),
544                       "sra\t{$src, $amt}",
545                       [(set GR32:$dst, (sra GR32:$src, riaddr32:$amt)),
546                        (implicit PSW)]>;
547 def SRA64rri : Pseudo<(outs GR64:$dst), (ins GR64:$src, riaddr:$amt),
548                       "srag\t{$dst, $src, $amt}",
549                       [(set GR64:$dst, (sra GR64:$src, (i32 (trunc riaddr:$amt)))),
550                        (implicit PSW)]>;
551 def SRA64ri  : Pseudo<(outs GR64:$dst), (ins GR64:$src, i32imm:$amt),
552                       "srag\t{$dst, $src, $amt}",
553                       [(set GR64:$dst, (sra GR64:$src, (i32 imm:$amt))),
554                        (implicit PSW)]>;
555 } // Defs = [PSW]
556
557 //===----------------------------------------------------------------------===//
558 // Non-Instruction Patterns.
559 //===----------------------------------------------------------------------===//
560
561 // anyext
562 def : Pat<(i64 (anyext GR32:$src)),
563           (INSERT_SUBREG (i64 (IMPLICIT_DEF)), GR32:$src, subreg_32bit)>;
564
565 //===----------------------------------------------------------------------===//
566 // Peepholes.
567 //===----------------------------------------------------------------------===//
568
569 // FIXME: use add/sub tricks with 32678/-32768
570
571 // trunc patterns
572 def : Pat<(i32 (trunc GR64:$src)),
573           (EXTRACT_SUBREG GR64:$src, subreg_32bit)>;
574
575 // sext_inreg patterns
576 def : Pat<(sext_inreg GR64:$src, i32),
577           (MOVSX64rr32 (EXTRACT_SUBREG GR64:$src, subreg_32bit))>;
578
579 // extload patterns
580 def : Pat<(extloadi64i8  rriaddr:$src), (MOVZX64rm8  rriaddr:$src)>;
581 def : Pat<(extloadi64i16 rriaddr:$src), (MOVZX64rm16 rriaddr:$src)>;
582 def : Pat<(extloadi64i32 rriaddr:$src), (MOVZX64rm32 rriaddr:$src)>;
583
584 // calls
585 def : Pat<(SystemZcall (i64 tglobaladdr:$dst)),
586           (CALLi tglobaladdr:$dst)>;
587 def : Pat<(SystemZcall (i64 texternalsym:$dst)),
588           (CALLi texternalsym:$dst)>;