]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/lib/Target/AMDGPU/AMDGPUInstructions.td
Update llvm to release_39 branch r278877.
[FreeBSD/FreeBSD.git] / contrib / llvm / lib / Target / AMDGPU / AMDGPUInstructions.td
1 //===-- AMDGPUInstructions.td - Common instruction defs ---*- 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 contains instruction defs that are common to all hw codegen
11 // targets.
12 //
13 //===----------------------------------------------------------------------===//
14
15 class AMDGPUInst <dag outs, dag ins, string asm = "",
16   list<dag> pattern = []> : Instruction {
17   field bit isRegisterLoad = 0;
18   field bit isRegisterStore = 0;
19
20   let Namespace = "AMDGPU";
21   let OutOperandList = outs;
22   let InOperandList = ins;
23   let AsmString = asm;
24   let Pattern = pattern;
25   let Itinerary = NullALU;
26
27   // SoftFail is a field the disassembler can use to provide a way for
28   // instructions to not match without killing the whole decode process. It is
29   // mainly used for ARM, but Tablegen expects this field to exist or it fails
30   // to build the decode table.
31   field bits<64> SoftFail = 0;
32
33   let DecoderNamespace = Namespace;
34
35   let TSFlags{63} = isRegisterLoad;
36   let TSFlags{62} = isRegisterStore;
37 }
38
39 class AMDGPUShaderInst <dag outs, dag ins, string asm = "",
40   list<dag> pattern = []> : AMDGPUInst<outs, ins, asm, pattern> {
41
42   field bits<32> Inst = 0xffffffff;
43 }
44
45 def FP32Denormals : Predicate<"Subtarget.hasFP32Denormals()">;
46 def FP64Denormals : Predicate<"Subtarget.hasFP64Denormals()">;
47 def UnsafeFPMath : Predicate<"TM.Options.UnsafeFPMath">;
48
49 def InstFlag : OperandWithDefaultOps <i32, (ops (i32 0))>;
50 def ADDRIndirect : ComplexPattern<iPTR, 2, "SelectADDRIndirect", [], []>;
51
52 // 32-bit VALU immediate operand that uses the constant bus.
53 def u32kimm : Operand<i32> {
54   let OperandNamespace = "AMDGPU";
55   let OperandType = "OPERAND_KIMM32";
56   let PrintMethod = "printU32ImmOperand";
57 }
58
59 let OperandType = "OPERAND_IMMEDIATE" in {
60
61 def u32imm : Operand<i32> {
62   let PrintMethod = "printU32ImmOperand";
63 }
64
65 def u16imm : Operand<i16> {
66   let PrintMethod = "printU16ImmOperand";
67 }
68
69 def u8imm : Operand<i8> {
70   let PrintMethod = "printU8ImmOperand";
71 }
72
73 } // End OperandType = "OPERAND_IMMEDIATE"
74
75 //===--------------------------------------------------------------------===//
76 // Custom Operands
77 //===--------------------------------------------------------------------===//
78 def brtarget   : Operand<OtherVT>;
79
80 //===----------------------------------------------------------------------===//
81 // PatLeafs for floating-point comparisons
82 //===----------------------------------------------------------------------===//
83
84 def COND_OEQ : PatLeaf <
85   (cond),
86   [{return N->get() == ISD::SETOEQ || N->get() == ISD::SETEQ;}]
87 >;
88
89 def COND_ONE : PatLeaf <
90   (cond),
91   [{return N->get() == ISD::SETONE || N->get() == ISD::SETNE;}]
92 >;
93
94 def COND_OGT : PatLeaf <
95   (cond),
96   [{return N->get() == ISD::SETOGT || N->get() == ISD::SETGT;}]
97 >;
98
99 def COND_OGE : PatLeaf <
100   (cond),
101   [{return N->get() == ISD::SETOGE || N->get() == ISD::SETGE;}]
102 >;
103
104 def COND_OLT : PatLeaf <
105   (cond),
106   [{return N->get() == ISD::SETOLT || N->get() == ISD::SETLT;}]
107 >;
108
109 def COND_OLE : PatLeaf <
110   (cond),
111   [{return N->get() == ISD::SETOLE || N->get() == ISD::SETLE;}]
112 >;
113
114
115 def COND_O : PatLeaf <(cond), [{return N->get() == ISD::SETO;}]>;
116 def COND_UO : PatLeaf <(cond), [{return N->get() == ISD::SETUO;}]>;
117
118 //===----------------------------------------------------------------------===//
119 // PatLeafs for unsigned / unordered comparisons
120 //===----------------------------------------------------------------------===//
121
122 def COND_UEQ : PatLeaf <(cond), [{return N->get() == ISD::SETUEQ;}]>;
123 def COND_UNE : PatLeaf <(cond), [{return N->get() == ISD::SETUNE;}]>;
124 def COND_UGT : PatLeaf <(cond), [{return N->get() == ISD::SETUGT;}]>;
125 def COND_UGE : PatLeaf <(cond), [{return N->get() == ISD::SETUGE;}]>;
126 def COND_ULT : PatLeaf <(cond), [{return N->get() == ISD::SETULT;}]>;
127 def COND_ULE : PatLeaf <(cond), [{return N->get() == ISD::SETULE;}]>;
128
129 // XXX - For some reason R600 version is preferring to use unordered
130 // for setne?
131 def COND_UNE_NE : PatLeaf <
132   (cond),
133   [{return N->get() == ISD::SETUNE || N->get() == ISD::SETNE;}]
134 >;
135
136 //===----------------------------------------------------------------------===//
137 // PatLeafs for signed comparisons
138 //===----------------------------------------------------------------------===//
139
140 def COND_SGT : PatLeaf <(cond), [{return N->get() == ISD::SETGT;}]>;
141 def COND_SGE : PatLeaf <(cond), [{return N->get() == ISD::SETGE;}]>;
142 def COND_SLT : PatLeaf <(cond), [{return N->get() == ISD::SETLT;}]>;
143 def COND_SLE : PatLeaf <(cond), [{return N->get() == ISD::SETLE;}]>;
144
145 //===----------------------------------------------------------------------===//
146 // PatLeafs for integer equality
147 //===----------------------------------------------------------------------===//
148
149 def COND_EQ : PatLeaf <
150   (cond),
151   [{return N->get() == ISD::SETEQ || N->get() == ISD::SETUEQ;}]
152 >;
153
154 def COND_NE : PatLeaf <
155   (cond),
156   [{return N->get() == ISD::SETNE || N->get() == ISD::SETUNE;}]
157 >;
158
159 def COND_NULL : PatLeaf <
160   (cond),
161   [{(void)N; return false;}]
162 >;
163
164
165 //===----------------------------------------------------------------------===//
166 // Misc. PatFrags
167 //===----------------------------------------------------------------------===//
168
169 class HasOneUseBinOp<SDPatternOperator op> : PatFrag<
170   (ops node:$src0, node:$src1),
171   (op $src0, $src1),
172   [{ return N->hasOneUse(); }]
173 >;
174
175 //===----------------------------------------------------------------------===//
176 // Load/Store Pattern Fragments
177 //===----------------------------------------------------------------------===//
178
179 class PrivateMemOp <dag ops, dag frag> : PatFrag <ops, frag, [{
180   return cast<MemSDNode>(N)->getAddressSpace() == AMDGPUAS::PRIVATE_ADDRESS;
181 }]>;
182
183 class PrivateLoad <SDPatternOperator op> : PrivateMemOp <
184   (ops node:$ptr), (op node:$ptr)
185 >;
186
187 class PrivateStore <SDPatternOperator op> : PrivateMemOp <
188   (ops node:$value, node:$ptr), (op node:$value, node:$ptr)
189 >;
190
191 def load_private : PrivateLoad <load>;
192
193 def truncstorei8_private : PrivateStore <truncstorei8>;
194 def truncstorei16_private : PrivateStore <truncstorei16>;
195 def store_private : PrivateStore <store>;
196
197 class GlobalMemOp <dag ops, dag frag> : PatFrag <ops, frag, [{
198   return cast<MemSDNode>(N)->getAddressSpace() == AMDGPUAS::GLOBAL_ADDRESS;
199 }]>;
200
201 // Global address space loads
202 class GlobalLoad <SDPatternOperator op> : GlobalMemOp <
203   (ops node:$ptr), (op node:$ptr)
204 >;
205
206 def global_load : GlobalLoad <load>;
207
208 // Global address space stores
209 class GlobalStore <SDPatternOperator op> : GlobalMemOp <
210   (ops node:$value, node:$ptr), (op node:$value, node:$ptr)
211 >;
212
213 def global_store : GlobalStore <store>;
214 def global_store_atomic : GlobalStore<atomic_store>;
215
216
217 class ConstantMemOp <dag ops, dag frag> : PatFrag <ops, frag, [{
218   return cast<MemSDNode>(N)->getAddressSpace() == AMDGPUAS::CONSTANT_ADDRESS;
219 }]>;
220
221 // Constant address space loads
222 class ConstantLoad <SDPatternOperator op> : ConstantMemOp <
223   (ops node:$ptr), (op node:$ptr)
224 >;
225
226 def constant_load : ConstantLoad<load>;
227
228 class LocalMemOp <dag ops, dag frag> : PatFrag <ops, frag, [{
229   return cast<MemSDNode>(N)->getAddressSpace() == AMDGPUAS::LOCAL_ADDRESS;
230 }]>;
231
232 // Local address space loads
233 class LocalLoad <SDPatternOperator op> : LocalMemOp <
234   (ops node:$ptr), (op node:$ptr)
235 >;
236
237 class LocalStore <SDPatternOperator op> : LocalMemOp <
238   (ops node:$value, node:$ptr), (op node:$value, node:$ptr)
239 >;
240
241 class FlatMemOp <dag ops, dag frag> : PatFrag <ops, frag, [{
242   return cast<MemSDNode>(N)->getAddressSPace() == AMDGPUAS::FLAT_ADDRESS;
243 }]>;
244
245 class FlatLoad <SDPatternOperator op> : FlatMemOp <
246   (ops node:$ptr), (op node:$ptr)
247 >;
248
249 class AZExtLoadBase <SDPatternOperator ld_node>: PatFrag<(ops node:$ptr),
250                                               (ld_node node:$ptr), [{
251   LoadSDNode *L = cast<LoadSDNode>(N);
252   return L->getExtensionType() == ISD::ZEXTLOAD ||
253          L->getExtensionType() == ISD::EXTLOAD;
254 }]>;
255
256 def az_extload : AZExtLoadBase <unindexedload>;
257
258 def az_extloadi8 : PatFrag<(ops node:$ptr), (az_extload node:$ptr), [{
259   return cast<LoadSDNode>(N)->getMemoryVT() == MVT::i8;
260 }]>;
261
262 def az_extloadi8_global : GlobalLoad <az_extloadi8>;
263 def sextloadi8_global : GlobalLoad <sextloadi8>;
264
265 def az_extloadi8_constant : ConstantLoad <az_extloadi8>;
266 def sextloadi8_constant : ConstantLoad <sextloadi8>;
267
268 def az_extloadi8_local : LocalLoad <az_extloadi8>;
269 def sextloadi8_local : LocalLoad <sextloadi8>;
270
271 def extloadi8_private : PrivateLoad <az_extloadi8>;
272 def sextloadi8_private : PrivateLoad <sextloadi8>;
273
274 def az_extloadi16 : PatFrag<(ops node:$ptr), (az_extload node:$ptr), [{
275   return cast<LoadSDNode>(N)->getMemoryVT() == MVT::i16;
276 }]>;
277
278 def az_extloadi16_global : GlobalLoad <az_extloadi16>;
279 def sextloadi16_global : GlobalLoad <sextloadi16>;
280
281 def az_extloadi16_constant : ConstantLoad <az_extloadi16>;
282 def sextloadi16_constant : ConstantLoad <sextloadi16>;
283
284 def az_extloadi16_local : LocalLoad <az_extloadi16>;
285 def sextloadi16_local : LocalLoad <sextloadi16>;
286
287 def extloadi16_private : PrivateLoad <az_extloadi16>;
288 def sextloadi16_private : PrivateLoad <sextloadi16>;
289
290 def az_extloadi32 : PatFrag<(ops node:$ptr), (az_extload node:$ptr), [{
291   return cast<LoadSDNode>(N)->getMemoryVT() == MVT::i32;
292 }]>;
293
294 def az_extloadi32_global : GlobalLoad <az_extloadi32>;
295
296 def az_extloadi32_flat : FlatLoad <az_extloadi32>;
297
298 def az_extloadi32_constant : ConstantLoad <az_extloadi32>;
299
300 def truncstorei8_global : GlobalStore <truncstorei8>;
301 def truncstorei16_global : GlobalStore <truncstorei16>;
302
303 def local_store : LocalStore <store>;
304 def truncstorei8_local : LocalStore <truncstorei8>;
305 def truncstorei16_local : LocalStore <truncstorei16>;
306
307 def local_load : LocalLoad <load>;
308
309 class Aligned8Bytes <dag ops, dag frag> : PatFrag <ops, frag, [{
310     return cast<MemSDNode>(N)->getAlignment() % 8 == 0;
311 }]>;
312
313 def local_load_aligned8bytes : Aligned8Bytes <
314   (ops node:$ptr), (local_load node:$ptr)
315 >;
316
317 def local_store_aligned8bytes : Aligned8Bytes <
318   (ops node:$val, node:$ptr), (local_store node:$val, node:$ptr)
319 >;
320
321 class local_binary_atomic_op<SDNode atomic_op> :
322   PatFrag<(ops node:$ptr, node:$value),
323     (atomic_op node:$ptr, node:$value), [{
324   return cast<MemSDNode>(N)->getAddressSpace() == AMDGPUAS::LOCAL_ADDRESS;
325 }]>;
326
327
328 def atomic_swap_local : local_binary_atomic_op<atomic_swap>;
329 def atomic_load_add_local : local_binary_atomic_op<atomic_load_add>;
330 def atomic_load_sub_local : local_binary_atomic_op<atomic_load_sub>;
331 def atomic_load_and_local : local_binary_atomic_op<atomic_load_and>;
332 def atomic_load_or_local : local_binary_atomic_op<atomic_load_or>;
333 def atomic_load_xor_local : local_binary_atomic_op<atomic_load_xor>;
334 def atomic_load_nand_local : local_binary_atomic_op<atomic_load_nand>;
335 def atomic_load_min_local : local_binary_atomic_op<atomic_load_min>;
336 def atomic_load_max_local : local_binary_atomic_op<atomic_load_max>;
337 def atomic_load_umin_local : local_binary_atomic_op<atomic_load_umin>;
338 def atomic_load_umax_local : local_binary_atomic_op<atomic_load_umax>;
339
340 def mskor_global : PatFrag<(ops node:$val, node:$ptr),
341                             (AMDGPUstore_mskor node:$val, node:$ptr), [{
342   return cast<MemSDNode>(N)->getAddressSpace() == AMDGPUAS::GLOBAL_ADDRESS;
343 }]>;
344
345 multiclass AtomicCmpSwapLocal <SDNode cmp_swap_node> {
346
347   def _32_local : PatFrag <
348     (ops node:$ptr, node:$cmp, node:$swap),
349     (cmp_swap_node node:$ptr, node:$cmp, node:$swap), [{
350       AtomicSDNode *AN = cast<AtomicSDNode>(N);
351       return AN->getMemoryVT() == MVT::i32 &&
352              AN->getAddressSpace() == AMDGPUAS::LOCAL_ADDRESS;
353   }]>;
354
355   def _64_local : PatFrag<
356     (ops node:$ptr, node:$cmp, node:$swap),
357     (cmp_swap_node node:$ptr, node:$cmp, node:$swap), [{
358       AtomicSDNode *AN = cast<AtomicSDNode>(N);
359       return AN->getMemoryVT() == MVT::i64 &&
360              AN->getAddressSpace() == AMDGPUAS::LOCAL_ADDRESS;
361   }]>;
362 }
363
364 defm atomic_cmp_swap : AtomicCmpSwapLocal <atomic_cmp_swap>;
365
366 def mskor_flat : PatFrag<(ops node:$val, node:$ptr),
367                             (AMDGPUstore_mskor node:$val, node:$ptr), [{
368   return cast<MemSDNode>(N)->getAddressSpace() == AMDGPUAS::FLAT_ADDRESS;
369 }]>;
370
371 class global_binary_atomic_op<SDNode atomic_op> : PatFrag<
372   (ops node:$ptr, node:$value),
373   (atomic_op node:$ptr, node:$value),
374   [{return cast<MemSDNode>(N)->getAddressSpace() == AMDGPUAS::GLOBAL_ADDRESS;}]
375 >;
376
377 class flat_binary_atomic_op<SDNode atomic_op> : PatFrag<
378   (ops node:$ptr, node:$value),
379   (atomic_op node:$ptr, node:$value),
380   [{return cast<MemSDNode>(N)->getAddressSpace() == AMDGPUAS::FLAT_ADDRESS;}]
381 >;
382
383 def atomic_swap_global : global_binary_atomic_op<atomic_swap>;
384 def atomic_add_global : global_binary_atomic_op<atomic_load_add>;
385 def atomic_and_global : global_binary_atomic_op<atomic_load_and>;
386 def atomic_max_global : global_binary_atomic_op<atomic_load_max>;
387 def atomic_min_global : global_binary_atomic_op<atomic_load_min>;
388 def atomic_or_global : global_binary_atomic_op<atomic_load_or>;
389 def atomic_sub_global : global_binary_atomic_op<atomic_load_sub>;
390 def atomic_umax_global : global_binary_atomic_op<atomic_load_umax>;
391 def atomic_umin_global : global_binary_atomic_op<atomic_load_umin>;
392 def atomic_xor_global : global_binary_atomic_op<atomic_load_xor>;
393
394 def atomic_cmp_swap_global : global_binary_atomic_op<AMDGPUatomic_cmp_swap>;
395 def atomic_cmp_swap_global_nortn : PatFrag<
396   (ops node:$ptr, node:$value),
397   (atomic_cmp_swap_global node:$ptr, node:$value),
398   [{ return SDValue(N, 0).use_empty(); }]
399 >;
400
401 def atomic_swap_flat : flat_binary_atomic_op<atomic_swap>;
402 def atomic_add_flat : flat_binary_atomic_op<atomic_load_add>;
403 def atomic_and_flat : flat_binary_atomic_op<atomic_load_and>;
404 def atomic_max_flat : flat_binary_atomic_op<atomic_load_max>;
405 def atomic_min_flat : flat_binary_atomic_op<atomic_load_min>;
406 def atomic_or_flat : flat_binary_atomic_op<atomic_load_or>;
407 def atomic_sub_flat : flat_binary_atomic_op<atomic_load_sub>;
408 def atomic_umax_flat : flat_binary_atomic_op<atomic_load_umax>;
409 def atomic_umin_flat : flat_binary_atomic_op<atomic_load_umin>;
410 def atomic_xor_flat : flat_binary_atomic_op<atomic_load_xor>;
411
412 def atomic_cmp_swap_flat : flat_binary_atomic_op<AMDGPUatomic_cmp_swap>;
413
414 //===----------------------------------------------------------------------===//
415 // Misc Pattern Fragments
416 //===----------------------------------------------------------------------===//
417
418 class Constants {
419 int TWO_PI = 0x40c90fdb;
420 int PI = 0x40490fdb;
421 int TWO_PI_INV = 0x3e22f983;
422 int FP_UINT_MAX_PLUS_1 = 0x4f800000;    // 1 << 32 in floating point encoding
423 int FP32_ONE = 0x3f800000;
424 int FP32_NEG_ONE = 0xbf800000;
425 int FP64_ONE = 0x3ff0000000000000;
426 int FP64_NEG_ONE = 0xbff0000000000000;
427 }
428 def CONST : Constants;
429
430 def FP_ZERO : PatLeaf <
431   (fpimm),
432   [{return N->getValueAPF().isZero();}]
433 >;
434
435 def FP_ONE : PatLeaf <
436   (fpimm),
437   [{return N->isExactlyValue(1.0);}]
438 >;
439
440 def FP_HALF : PatLeaf <
441   (fpimm),
442   [{return N->isExactlyValue(0.5);}]
443 >;
444
445 let isCodeGenOnly = 1, isPseudo = 1 in {
446
447 let usesCustomInserter = 1  in {
448
449 class CLAMP <RegisterClass rc> : AMDGPUShaderInst <
450   (outs rc:$dst),
451   (ins rc:$src0),
452   "CLAMP $dst, $src0",
453   [(set f32:$dst, (AMDGPUclamp f32:$src0, (f32 FP_ZERO), (f32 FP_ONE)))]
454 >;
455
456 class FABS <RegisterClass rc> : AMDGPUShaderInst <
457   (outs rc:$dst),
458   (ins rc:$src0),
459   "FABS $dst, $src0",
460   [(set f32:$dst, (fabs f32:$src0))]
461 >;
462
463 class FNEG <RegisterClass rc> : AMDGPUShaderInst <
464   (outs rc:$dst),
465   (ins rc:$src0),
466   "FNEG $dst, $src0",
467   [(set f32:$dst, (fneg f32:$src0))]
468 >;
469
470 } // usesCustomInserter = 1
471
472 multiclass RegisterLoadStore <RegisterClass dstClass, Operand addrClass,
473                     ComplexPattern addrPat> {
474 let UseNamedOperandTable = 1 in {
475
476   def RegisterLoad : AMDGPUShaderInst <
477     (outs dstClass:$dst),
478     (ins addrClass:$addr, i32imm:$chan),
479     "RegisterLoad $dst, $addr",
480     [(set i32:$dst, (AMDGPUregister_load addrPat:$addr, (i32 timm:$chan)))]
481   > {
482     let isRegisterLoad = 1;
483   }
484
485   def RegisterStore : AMDGPUShaderInst <
486     (outs),
487     (ins dstClass:$val, addrClass:$addr, i32imm:$chan),
488     "RegisterStore $val, $addr",
489     [(AMDGPUregister_store i32:$val, addrPat:$addr, (i32 timm:$chan))]
490   > {
491     let isRegisterStore = 1;
492   }
493 }
494 }
495
496 } // End isCodeGenOnly = 1, isPseudo = 1
497
498 /* Generic helper patterns for intrinsics */
499 /* -------------------------------------- */
500
501 class POW_Common <AMDGPUInst log_ieee, AMDGPUInst exp_ieee, AMDGPUInst mul>
502   : Pat <
503   (fpow f32:$src0, f32:$src1),
504   (exp_ieee (mul f32:$src1, (log_ieee f32:$src0)))
505 >;
506
507 /* Other helper patterns */
508 /* --------------------- */
509
510 /* Extract element pattern */
511 class Extract_Element <ValueType sub_type, ValueType vec_type, int sub_idx,
512                        SubRegIndex sub_reg>
513   : Pat<
514   (sub_type (extractelt vec_type:$src, sub_idx)),
515   (EXTRACT_SUBREG $src, sub_reg)
516 >;
517
518 /* Insert element pattern */
519 class Insert_Element <ValueType elem_type, ValueType vec_type,
520                       int sub_idx, SubRegIndex sub_reg>
521   : Pat <
522   (insertelt vec_type:$vec, elem_type:$elem, sub_idx),
523   (INSERT_SUBREG $vec, $elem, sub_reg)
524 >;
525
526 // XXX: Convert to new syntax and use COPY_TO_REG, once the DFAPacketizer
527 // can handle COPY instructions.
528 // bitconvert pattern
529 class BitConvert <ValueType dt, ValueType st, RegisterClass rc> : Pat <
530   (dt (bitconvert (st rc:$src0))),
531   (dt rc:$src0)
532 >;
533
534 // XXX: Convert to new syntax and use COPY_TO_REG, once the DFAPacketizer
535 // can handle COPY instructions.
536 class DwordAddrPat<ValueType vt, RegisterClass rc> : Pat <
537   (vt (AMDGPUdwordaddr (vt rc:$addr))),
538   (vt rc:$addr)
539 >;
540
541 // BFI_INT patterns
542
543 multiclass BFIPatterns <Instruction BFI_INT,
544                         Instruction LoadImm32,
545                         RegisterClass RC64> {
546   // Definition from ISA doc:
547   // (y & x) | (z & ~x)
548   def : Pat <
549     (or (and i32:$y, i32:$x), (and i32:$z, (not i32:$x))),
550     (BFI_INT $x, $y, $z)
551   >;
552
553   // SHA-256 Ch function
554   // z ^ (x & (y ^ z))
555   def : Pat <
556     (xor i32:$z, (and i32:$x, (xor i32:$y, i32:$z))),
557     (BFI_INT $x, $y, $z)
558   >;
559
560   def : Pat <
561     (fcopysign f32:$src0, f32:$src1),
562     (BFI_INT (LoadImm32 0x7fffffff), $src0, $src1)
563   >;
564
565   def : Pat <
566     (f64 (fcopysign f64:$src0, f64:$src1)),
567     (REG_SEQUENCE RC64,
568       (i32 (EXTRACT_SUBREG $src0, sub0)), sub0,
569       (BFI_INT (LoadImm32 0x7fffffff),
570                (i32 (EXTRACT_SUBREG $src0, sub1)),
571                (i32 (EXTRACT_SUBREG $src1, sub1))), sub1)
572   >;
573 }
574
575 // SHA-256 Ma patterns
576
577 // ((x & z) | (y & (x | z))) -> BFI_INT (XOR x, y), z, y
578 class SHA256MaPattern <Instruction BFI_INT, Instruction XOR> : Pat <
579   (or (and i32:$x, i32:$z), (and i32:$y, (or i32:$x, i32:$z))),
580   (BFI_INT (XOR i32:$x, i32:$y), i32:$z, i32:$y)
581 >;
582
583 // Bitfield extract patterns
584
585 def IMMZeroBasedBitfieldMask : PatLeaf <(imm), [{
586   return isMask_32(N->getZExtValue());
587 }]>;
588
589 def IMMPopCount : SDNodeXForm<imm, [{
590   return CurDAG->getTargetConstant(countPopulation(N->getZExtValue()), SDLoc(N),
591                                    MVT::i32);
592 }]>;
593
594 class BFEPattern <Instruction BFE, Instruction MOV> : Pat <
595   (i32 (and (i32 (srl i32:$src, i32:$rshift)), IMMZeroBasedBitfieldMask:$mask)),
596   (BFE $src, $rshift, (MOV (i32 (IMMPopCount $mask))))
597 >;
598
599 // rotr pattern
600 class ROTRPattern <Instruction BIT_ALIGN> : Pat <
601   (rotr i32:$src0, i32:$src1),
602   (BIT_ALIGN $src0, $src0, $src1)
603 >;
604
605 // This matches 16 permutations of
606 // max(min(x, y), min(max(x, y), z))
607 class IntMed3Pat<Instruction med3Inst,
608                  SDPatternOperator max,
609                  SDPatternOperator max_oneuse,
610                  SDPatternOperator min_oneuse> : Pat<
611   (max (min_oneuse i32:$src0, i32:$src1),
612        (min_oneuse (max_oneuse i32:$src0, i32:$src1), i32:$src2)),
613   (med3Inst $src0, $src1, $src2)
614 >;
615
616 let Properties = [SDNPCommutative, SDNPAssociative] in {
617 def smax_oneuse : HasOneUseBinOp<smax>;
618 def smin_oneuse : HasOneUseBinOp<smin>;
619 def umax_oneuse : HasOneUseBinOp<umax>;
620 def umin_oneuse : HasOneUseBinOp<umin>;
621 } // Properties = [SDNPCommutative, SDNPAssociative]
622
623
624 // 24-bit arithmetic patterns
625 def umul24 : PatFrag <(ops node:$x, node:$y), (mul node:$x, node:$y)>;
626
627 // Special conversion patterns
628
629 def cvt_rpi_i32_f32 : PatFrag <
630   (ops node:$src),
631   (fp_to_sint (ffloor (fadd $src, FP_HALF))),
632   [{ (void) N; return TM.Options.NoNaNsFPMath; }]
633 >;
634
635 def cvt_flr_i32_f32 : PatFrag <
636   (ops node:$src),
637   (fp_to_sint (ffloor $src)),
638   [{ (void)N; return TM.Options.NoNaNsFPMath; }]
639 >;
640
641 class IMad24Pat<Instruction Inst> : Pat <
642   (add (AMDGPUmul_i24 i32:$src0, i32:$src1), i32:$src2),
643   (Inst $src0, $src1, $src2)
644 >;
645
646 class UMad24Pat<Instruction Inst> : Pat <
647   (add (AMDGPUmul_u24 i32:$src0, i32:$src1), i32:$src2),
648   (Inst $src0, $src1, $src2)
649 >;
650
651 class RcpPat<Instruction RcpInst, ValueType vt> : Pat <
652   (fdiv FP_ONE, vt:$src),
653   (RcpInst $src)
654 >;
655
656 class RsqPat<Instruction RsqInst, ValueType vt> : Pat <
657   (AMDGPUrcp (fsqrt vt:$src)),
658   (RsqInst $src)
659 >;
660
661 include "R600Instructions.td"
662 include "R700Instructions.td"
663 include "EvergreenInstructions.td"
664 include "CaymanInstructions.td"
665
666 include "SIInstrInfo.td"
667