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