1 //===-- AMDGPUInstructions.td - Common instruction defs ---*- tablegen -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // This file contains instruction defs that are common to all hw codegen
12 //===----------------------------------------------------------------------===//
14 class AddressSpacesImpl {
23 def AddrSpaces : AddressSpacesImpl;
26 class AMDGPUInst <dag outs, dag ins, string asm = "",
27 list<dag> pattern = []> : Instruction {
28 field bit isRegisterLoad = 0;
29 field bit isRegisterStore = 0;
31 let Namespace = "AMDGPU";
32 let OutOperandList = outs;
33 let InOperandList = ins;
35 let Pattern = pattern;
36 let Itinerary = NullALU;
38 // SoftFail is a field the disassembler can use to provide a way for
39 // instructions to not match without killing the whole decode process. It is
40 // mainly used for ARM, but Tablegen expects this field to exist or it fails
41 // to build the decode table.
42 field bits<64> SoftFail = 0;
44 let DecoderNamespace = Namespace;
46 let TSFlags{63} = isRegisterLoad;
47 let TSFlags{62} = isRegisterStore;
50 class AMDGPUShaderInst <dag outs, dag ins, string asm = "",
51 list<dag> pattern = []> : AMDGPUInst<outs, ins, asm, pattern> {
53 field bits<32> Inst = 0xffffffff;
56 //===---------------------------------------------------------------------===//
58 //===---------------------------------------------------------------------===//
60 class ILFormat<dag outs, dag ins, string asmstr, list<dag> pattern>
63 let Namespace = "AMDGPU";
64 dag OutOperandList = outs;
65 dag InOperandList = ins;
66 let Pattern = pattern;
67 let AsmString = !strconcat(asmstr, "\n");
69 let Itinerary = NullALU;
71 bit hasZeroOpFlag = 0;
74 let hasSideEffects = 0;
75 let isCodeGenOnly = 1;
78 def TruePredicate : Predicate<"">;
80 class PredicateControl {
81 Predicate SubtargetPredicate = TruePredicate;
82 list<Predicate> AssemblerPredicates = [];
83 Predicate AssemblerPredicate = TruePredicate;
84 Predicate WaveSizePredicate = TruePredicate;
85 list<Predicate> OtherPredicates = [];
86 list<Predicate> Predicates = !listconcat([SubtargetPredicate,
92 class AMDGPUPat<dag pattern, dag result> : Pat<pattern, result>,
95 def FP16Denormals : Predicate<"Subtarget->hasFP16Denormals()">;
96 def FP32Denormals : Predicate<"Subtarget->hasFP32Denormals()">;
97 def FP64Denormals : Predicate<"Subtarget->hasFP64Denormals()">;
98 def NoFP16Denormals : Predicate<"!Subtarget->hasFP16Denormals()">;
99 def NoFP32Denormals : Predicate<"!Subtarget->hasFP32Denormals()">;
100 def NoFP64Denormals : Predicate<"!Subtarget->hasFP64Denormals()">;
101 def UnsafeFPMath : Predicate<"TM.Options.UnsafeFPMath">;
102 def FMA : Predicate<"Subtarget->hasFMA()">;
104 def InstFlag : OperandWithDefaultOps <i32, (ops (i32 0))>;
106 def u16ImmTarget : AsmOperandClass {
108 let RenderMethod = "addImmOperands";
111 def s16ImmTarget : AsmOperandClass {
113 let RenderMethod = "addImmOperands";
116 let OperandType = "OPERAND_IMMEDIATE" in {
118 def u32imm : Operand<i32> {
119 let PrintMethod = "printU32ImmOperand";
122 def u16imm : Operand<i16> {
123 let PrintMethod = "printU16ImmOperand";
124 let ParserMatchClass = u16ImmTarget;
127 def s16imm : Operand<i16> {
128 let PrintMethod = "printU16ImmOperand";
129 let ParserMatchClass = s16ImmTarget;
132 def u8imm : Operand<i8> {
133 let PrintMethod = "printU8ImmOperand";
136 } // End OperandType = "OPERAND_IMMEDIATE"
138 //===--------------------------------------------------------------------===//
140 //===--------------------------------------------------------------------===//
141 def brtarget : Operand<OtherVT>;
143 //===----------------------------------------------------------------------===//
145 //===----------------------------------------------------------------------===//
147 class HasOneUseUnaryOp<SDPatternOperator op> : PatFrag<
150 [{ return N->hasOneUse(); }]
153 class HasOneUseBinOp<SDPatternOperator op> : PatFrag<
154 (ops node:$src0, node:$src1),
156 [{ return N->hasOneUse(); }]
159 class HasOneUseTernaryOp<SDPatternOperator op> : PatFrag<
160 (ops node:$src0, node:$src1, node:$src2),
161 (op $src0, $src1, $src2),
162 [{ return N->hasOneUse(); }]
165 let Properties = [SDNPCommutative, SDNPAssociative] in {
166 def smax_oneuse : HasOneUseBinOp<smax>;
167 def smin_oneuse : HasOneUseBinOp<smin>;
168 def umax_oneuse : HasOneUseBinOp<umax>;
169 def umin_oneuse : HasOneUseBinOp<umin>;
171 def fminnum_oneuse : HasOneUseBinOp<fminnum>;
172 def fmaxnum_oneuse : HasOneUseBinOp<fmaxnum>;
174 def fminnum_ieee_oneuse : HasOneUseBinOp<fminnum_ieee>;
175 def fmaxnum_ieee_oneuse : HasOneUseBinOp<fmaxnum_ieee>;
178 def and_oneuse : HasOneUseBinOp<and>;
179 def or_oneuse : HasOneUseBinOp<or>;
180 def xor_oneuse : HasOneUseBinOp<xor>;
181 } // Properties = [SDNPCommutative, SDNPAssociative]
183 def not_oneuse : HasOneUseUnaryOp<not>;
185 def add_oneuse : HasOneUseBinOp<add>;
186 def sub_oneuse : HasOneUseBinOp<sub>;
188 def srl_oneuse : HasOneUseBinOp<srl>;
189 def shl_oneuse : HasOneUseBinOp<shl>;
191 def select_oneuse : HasOneUseTernaryOp<select>;
193 def AMDGPUmul_u24_oneuse : HasOneUseBinOp<AMDGPUmul_u24>;
194 def AMDGPUmul_i24_oneuse : HasOneUseBinOp<AMDGPUmul_i24>;
196 def srl_16 : PatFrag<
197 (ops node:$src0), (srl_oneuse node:$src0, (i32 16))
201 def hi_i16_elt : PatFrag<
202 (ops node:$src0), (i16 (trunc (i32 (srl_16 node:$src0))))
206 def hi_f16_elt : PatLeaf<
208 if (N->getOpcode() != ISD::BITCAST)
210 SDValue Tmp = N->getOperand(0);
212 if (Tmp.getOpcode() != ISD::SRL)
214 if (const auto *RHS = dyn_cast<ConstantSDNode>(Tmp.getOperand(1))
215 return RHS->getZExtValue() == 16;
219 //===----------------------------------------------------------------------===//
220 // PatLeafs for floating-point comparisons
221 //===----------------------------------------------------------------------===//
223 def COND_OEQ : PatFrags<(ops), [(OtherVT SETOEQ), (OtherVT SETEQ)]>;
224 def COND_ONE : PatFrags<(ops), [(OtherVT SETONE), (OtherVT SETNE)]>;
225 def COND_OGT : PatFrags<(ops), [(OtherVT SETOGT), (OtherVT SETGT)]>;
226 def COND_OGE : PatFrags<(ops), [(OtherVT SETOGE), (OtherVT SETGE)]>;
227 def COND_OLT : PatFrags<(ops), [(OtherVT SETOLT), (OtherVT SETLT)]>;
228 def COND_OLE : PatFrags<(ops), [(OtherVT SETOLE), (OtherVT SETLE)]>;
229 def COND_O : PatFrags<(ops), [(OtherVT SETO)]>;
230 def COND_UO : PatFrags<(ops), [(OtherVT SETUO)]>;
232 //===----------------------------------------------------------------------===//
233 // PatLeafs for unsigned / unordered comparisons
234 //===----------------------------------------------------------------------===//
236 def COND_UEQ : PatFrag<(ops), (OtherVT SETUEQ)>;
237 def COND_UNE : PatFrag<(ops), (OtherVT SETUNE)>;
238 def COND_UGT : PatFrag<(ops), (OtherVT SETUGT)>;
239 def COND_UGE : PatFrag<(ops), (OtherVT SETUGE)>;
240 def COND_ULT : PatFrag<(ops), (OtherVT SETULT)>;
241 def COND_ULE : PatFrag<(ops), (OtherVT SETULE)>;
243 // XXX - For some reason R600 version is preferring to use unordered
245 def COND_UNE_NE : PatFrags<(ops), [(OtherVT SETUNE), (OtherVT SETNE)]>;
247 //===----------------------------------------------------------------------===//
248 // PatLeafs for signed comparisons
249 //===----------------------------------------------------------------------===//
251 def COND_SGT : PatFrag<(ops), (OtherVT SETGT)>;
252 def COND_SGE : PatFrag<(ops), (OtherVT SETGE)>;
253 def COND_SLT : PatFrag<(ops), (OtherVT SETLT)>;
254 def COND_SLE : PatFrag<(ops), (OtherVT SETLE)>;
256 //===----------------------------------------------------------------------===//
257 // PatLeafs for integer equality
258 //===----------------------------------------------------------------------===//
260 def COND_EQ : PatFrags<(ops), [(OtherVT SETEQ), (OtherVT SETUEQ)]>;
261 def COND_NE : PatFrags<(ops), [(OtherVT SETNE), (OtherVT SETUNE)]>;
263 // FIXME: Should not need code predicate
264 //def COND_NULL : PatLeaf<(OtherVT null_frag)>;
265 def COND_NULL : PatLeaf <
267 [{(void)N; return false;}]
270 //===----------------------------------------------------------------------===//
271 // PatLeafs for Texture Constants
272 //===----------------------------------------------------------------------===//
274 def TEX_ARRAY : PatLeaf<
276 [{uint32_t TType = (uint32_t)N->getZExtValue();
277 return TType == 9 || TType == 10 || TType == 16;
281 def TEX_RECT : PatLeaf<
283 [{uint32_t TType = (uint32_t)N->getZExtValue();
288 def TEX_SHADOW : PatLeaf<
290 [{uint32_t TType = (uint32_t)N->getZExtValue();
291 return (TType >= 6 && TType <= 8) || TType == 13;
295 def TEX_SHADOW_ARRAY : PatLeaf<
297 [{uint32_t TType = (uint32_t)N->getZExtValue();
298 return TType == 11 || TType == 12 || TType == 17;
302 //===----------------------------------------------------------------------===//
303 // Load/Store Pattern Fragments
304 //===----------------------------------------------------------------------===//
306 def atomic_cmp_swap_glue : SDNode <"ISD::ATOMIC_CMP_SWAP", SDTAtomic3,
307 [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand, SDNPInGlue]
310 class AddressSpaceList<list<int> AS> {
311 list<int> AddrSpaces = AS;
314 class Aligned<int Bytes> {
315 int MinAlignment = Bytes;
318 class LoadFrag <SDPatternOperator op> : PatFrag<(ops node:$ptr), (op node:$ptr)>;
320 class StoreFrag<SDPatternOperator op> : PatFrag <
321 (ops node:$value, node:$ptr), (op node:$value, node:$ptr)
324 class StoreHi16<SDPatternOperator op> : PatFrag <
325 (ops node:$value, node:$ptr), (op (srl node:$value, (i32 16)), node:$ptr)
328 def LoadAddress_constant : AddressSpaceList<[ AddrSpaces.Constant ]>;
329 def LoadAddress_global : AddressSpaceList<[ AddrSpaces.Global, AddrSpaces.Constant ]>;
330 def StoreAddress_global : AddressSpaceList<[ AddrSpaces.Global ]>;
332 def LoadAddress_flat : AddressSpaceList<[ AddrSpaces.Flat,
334 AddrSpaces.Constant ]>;
335 def StoreAddress_flat : AddressSpaceList<[ AddrSpaces.Flat, AddrSpaces.Global ]>;
337 def LoadAddress_private : AddressSpaceList<[ AddrSpaces.Private ]>;
338 def StoreAddress_private : AddressSpaceList<[ AddrSpaces.Private ]>;
340 def LoadAddress_local : AddressSpaceList<[ AddrSpaces.Local ]>;
341 def StoreAddress_local : AddressSpaceList<[ AddrSpaces.Local ]>;
343 def LoadAddress_region : AddressSpaceList<[ AddrSpaces.Region ]>;
344 def StoreAddress_region : AddressSpaceList<[ AddrSpaces.Region ]>;
348 class GlobalLoadAddress : CodePatPred<[{
349 auto AS = cast<MemSDNode>(N)->getAddressSpace();
350 return AS == AMDGPUAS::GLOBAL_ADDRESS || AS == AMDGPUAS::CONSTANT_ADDRESS;
353 class FlatLoadAddress : CodePatPred<[{
354 const auto AS = cast<MemSDNode>(N)->getAddressSpace();
355 return AS == AMDGPUAS::FLAT_ADDRESS ||
356 AS == AMDGPUAS::GLOBAL_ADDRESS ||
357 AS == AMDGPUAS::CONSTANT_ADDRESS;
360 class GlobalAddress : CodePatPred<[{
361 return cast<MemSDNode>(N)->getAddressSpace() == AMDGPUAS::GLOBAL_ADDRESS;
364 class PrivateAddress : CodePatPred<[{
365 return cast<MemSDNode>(N)->getAddressSpace() == AMDGPUAS::PRIVATE_ADDRESS;
368 class LocalAddress : CodePatPred<[{
369 return cast<MemSDNode>(N)->getAddressSpace() == AMDGPUAS::LOCAL_ADDRESS;
372 class RegionAddress : CodePatPred<[{
373 return cast<MemSDNode>(N)->getAddressSpace() == AMDGPUAS::REGION_ADDRESS;
376 class FlatStoreAddress : CodePatPred<[{
377 const auto AS = cast<MemSDNode>(N)->getAddressSpace();
378 return AS == AMDGPUAS::FLAT_ADDRESS ||
379 AS == AMDGPUAS::GLOBAL_ADDRESS;
382 // TODO: Remove these when stores to new PatFrag format.
383 class PrivateStore <SDPatternOperator op> : StoreFrag <op>, PrivateAddress;
384 class LocalStore <SDPatternOperator op> : StoreFrag <op>, LocalAddress;
385 class RegionStore <SDPatternOperator op> : StoreFrag <op>, RegionAddress;
386 class GlobalStore <SDPatternOperator op> : StoreFrag<op>, GlobalAddress;
387 class FlatStore <SDPatternOperator op> : StoreFrag <op>, FlatStoreAddress;
390 foreach as = [ "global", "flat", "constant", "local", "private", "region" ] in {
391 let AddressSpaces = !cast<AddressSpaceList>("LoadAddress_"#as).AddrSpaces in {
393 def load_#as : PatFrag<(ops node:$ptr), (unindexedload node:$ptr)> {
395 let IsNonExtLoad = 1;
398 def extloadi8_#as : PatFrag<(ops node:$ptr), (extload node:$ptr)> {
403 def extloadi16_#as : PatFrag<(ops node:$ptr), (extload node:$ptr)> {
408 def sextloadi8_#as : PatFrag<(ops node:$ptr), (sextload node:$ptr)> {
413 def sextloadi16_#as : PatFrag<(ops node:$ptr), (sextload node:$ptr)> {
418 def zextloadi8_#as : PatFrag<(ops node:$ptr), (zextload node:$ptr)> {
423 def zextloadi16_#as : PatFrag<(ops node:$ptr), (zextload node:$ptr)> {
428 def atomic_load_32_#as : PatFrag<(ops node:$ptr), (atomic_load_32 node:$ptr)> {
433 def atomic_load_64_#as : PatFrag<(ops node:$ptr), (atomic_load_64 node:$ptr)> {
438 def store_#as : PatFrag<(ops node:$val, node:$ptr),
439 (unindexedstore node:$val, node:$ptr)> {
441 let IsTruncStore = 0;
444 // truncstore fragments.
445 def truncstore_#as : PatFrag<(ops node:$val, node:$ptr),
446 (unindexedstore node:$val, node:$ptr)> {
448 let IsTruncStore = 1;
451 // TODO: We don't really need the truncstore here. We can use
452 // unindexedstore with MemoryVT directly, which will save an
453 // unnecessary check that the memory size is less than the value type
454 // in the generated matcher table.
455 def truncstorei8_#as : PatFrag<(ops node:$val, node:$ptr),
456 (truncstore node:$val, node:$ptr)> {
461 def truncstorei16_#as : PatFrag<(ops node:$val, node:$ptr),
462 (truncstore node:$val, node:$ptr)> {
467 defm atomic_store_#as : binary_atomic_op<atomic_store>;
469 } // End let AddressSpaces = ...
470 } // End foreach AddrSpace
473 multiclass ret_noret_binary_atomic_op<SDNode atomic_op, bit IsInt = 1> {
474 foreach as = [ "global", "flat", "constant", "local", "private", "region" ] in {
475 let AddressSpaces = !cast<AddressSpaceList>("LoadAddress_"#as).AddrSpaces in {
476 defm "_"#as : binary_atomic_op<atomic_op, IsInt>;
478 let PredicateCode = [{return (SDValue(N, 0).use_empty());}] in {
479 defm "_"#as#"_noret" : binary_atomic_op<atomic_op, IsInt>;
482 let PredicateCode = [{return !(SDValue(N, 0).use_empty());}] in {
483 defm "_"#as#"_ret" : binary_atomic_op<atomic_op, IsInt>;
489 defm atomic_swap : ret_noret_binary_atomic_op<atomic_swap>;
490 defm atomic_load_add : ret_noret_binary_atomic_op<atomic_load_add>;
491 defm atomic_load_and : ret_noret_binary_atomic_op<atomic_load_and>;
492 defm atomic_load_max : ret_noret_binary_atomic_op<atomic_load_max>;
493 defm atomic_load_min : ret_noret_binary_atomic_op<atomic_load_min>;
494 defm atomic_load_or : ret_noret_binary_atomic_op<atomic_load_or>;
495 defm atomic_load_sub : ret_noret_binary_atomic_op<atomic_load_sub>;
496 defm atomic_load_umax : ret_noret_binary_atomic_op<atomic_load_umax>;
497 defm atomic_load_umin : ret_noret_binary_atomic_op<atomic_load_umin>;
498 defm atomic_load_xor : ret_noret_binary_atomic_op<atomic_load_xor>;
499 defm atomic_load_fadd : ret_noret_binary_atomic_op<atomic_load_fadd, 0>;
502 def store_hi16_private : StoreHi16 <truncstorei16>, PrivateAddress;
503 def truncstorei8_hi16_private : StoreHi16<truncstorei8>, PrivateAddress;
505 def store_atomic_global : GlobalStore<atomic_store>;
506 def truncstorei8_hi16_global : StoreHi16 <truncstorei8>, GlobalAddress;
507 def truncstorei16_hi16_global : StoreHi16 <truncstorei16>, GlobalAddress;
509 def store_local_hi16 : StoreHi16 <truncstorei16>, LocalAddress;
510 def truncstorei8_local_hi16 : StoreHi16<truncstorei8>, LocalAddress;
511 def atomic_store_local : LocalStore <atomic_store>;
514 def load_align8_local : PatFrag <(ops node:$ptr), (load_local node:$ptr)> {
516 let IsNonExtLoad = 1;
517 let MinAlignment = 8;
520 def load_align16_local : PatFrag <(ops node:$ptr), (load_local node:$ptr)> {
522 let IsNonExtLoad = 1;
523 let MinAlignment = 16;
526 def store_align8_local: PatFrag<(ops node:$val, node:$ptr),
527 (store_local node:$val, node:$ptr)>, Aligned<8> {
529 let IsTruncStore = 0;
532 def store_align16_local: PatFrag<(ops node:$val, node:$ptr),
533 (store_local node:$val, node:$ptr)>, Aligned<16> {
535 let IsTruncStore = 0;
539 def atomic_store_flat : FlatStore <atomic_store>;
540 def truncstorei8_hi16_flat : StoreHi16<truncstorei8>, FlatStoreAddress;
541 def truncstorei16_hi16_flat : StoreHi16<truncstorei16>, FlatStoreAddress;
544 class local_binary_atomic_op<SDNode atomic_op> :
545 PatFrag<(ops node:$ptr, node:$value),
546 (atomic_op node:$ptr, node:$value), [{
547 return cast<MemSDNode>(N)->getAddressSpace() == AMDGPUAS::LOCAL_ADDRESS;
550 class region_binary_atomic_op<SDNode atomic_op> :
551 PatFrag<(ops node:$ptr, node:$value),
552 (atomic_op node:$ptr, node:$value), [{
553 return cast<MemSDNode>(N)->getAddressSpace() == AMDGPUAS::REGION_ADDRESS;
557 def mskor_global : PatFrag<(ops node:$val, node:$ptr),
558 (AMDGPUstore_mskor node:$val, node:$ptr), [{
559 return cast<MemSDNode>(N)->getAddressSpace() == AMDGPUAS::GLOBAL_ADDRESS;
562 let AddressSpaces = StoreAddress_local.AddrSpaces in {
563 defm atomic_cmp_swap_local : ternary_atomic_op<atomic_cmp_swap>;
564 defm atomic_cmp_swap_local_m0 : ternary_atomic_op<atomic_cmp_swap_glue>;
567 let AddressSpaces = StoreAddress_region.AddrSpaces in {
568 defm atomic_cmp_swap_region : ternary_atomic_op<atomic_cmp_swap>;
569 defm atomic_cmp_swap_region_m0 : ternary_atomic_op<atomic_cmp_swap_glue>;
572 class global_binary_atomic_op_frag<SDNode atomic_op> : PatFrag<
573 (ops node:$ptr, node:$value),
574 (atomic_op node:$ptr, node:$value),
575 [{return cast<MemSDNode>(N)->getAddressSpace() == AMDGPUAS::GLOBAL_ADDRESS;}]>;
578 def AMDGPUatomic_cmp_swap_global : PatFrag<
579 (ops node:$ptr, node:$value),
580 (AMDGPUatomic_cmp_swap node:$ptr, node:$value)>, GlobalAddress;
582 def atomic_cmp_swap_global : PatFrag<
583 (ops node:$ptr, node:$cmp, node:$value),
584 (atomic_cmp_swap node:$ptr, node:$cmp, node:$value)>, GlobalAddress;
587 def atomic_cmp_swap_global_noret : PatFrag<
588 (ops node:$ptr, node:$cmp, node:$value),
589 (atomic_cmp_swap node:$ptr, node:$cmp, node:$value),
590 [{return cast<MemSDNode>(N)->getAddressSpace() == AMDGPUAS::GLOBAL_ADDRESS && (SDValue(N, 0).use_empty());}]>;
592 def atomic_cmp_swap_global_ret : PatFrag<
593 (ops node:$ptr, node:$cmp, node:$value),
594 (atomic_cmp_swap node:$ptr, node:$cmp, node:$value),
595 [{return cast<MemSDNode>(N)->getAddressSpace() == AMDGPUAS::GLOBAL_ADDRESS && (!SDValue(N, 0).use_empty());}]>;
597 //===----------------------------------------------------------------------===//
598 // Misc Pattern Fragments
599 //===----------------------------------------------------------------------===//
602 int TWO_PI = 0x40c90fdb;
604 int TWO_PI_INV = 0x3e22f983;
605 int FP_UINT_MAX_PLUS_1 = 0x4f800000; // 1 << 32 in floating point encoding
606 int FP16_ONE = 0x3C00;
607 int FP16_NEG_ONE = 0xBC00;
608 int FP32_ONE = 0x3f800000;
609 int FP32_NEG_ONE = 0xbf800000;
610 int FP64_ONE = 0x3ff0000000000000;
611 int FP64_NEG_ONE = 0xbff0000000000000;
613 def CONST : Constants;
615 def FP_ZERO : PatLeaf <
617 [{return N->getValueAPF().isZero();}]
620 def FP_ONE : PatLeaf <
622 [{return N->isExactlyValue(1.0);}]
625 def FP_HALF : PatLeaf <
627 [{return N->isExactlyValue(0.5);}]
630 /* Generic helper patterns for intrinsics */
631 /* -------------------------------------- */
633 class POW_Common <AMDGPUInst log_ieee, AMDGPUInst exp_ieee, AMDGPUInst mul>
635 (fpow f32:$src0, f32:$src1),
636 (exp_ieee (mul f32:$src1, (log_ieee f32:$src0)))
639 /* Other helper patterns */
640 /* --------------------- */
642 /* Extract element pattern */
643 class Extract_Element <ValueType sub_type, ValueType vec_type, int sub_idx,
646 (sub_type (extractelt vec_type:$src, sub_idx)),
647 (EXTRACT_SUBREG $src, sub_reg)
650 /* Insert element pattern */
651 class Insert_Element <ValueType elem_type, ValueType vec_type,
652 int sub_idx, SubRegIndex sub_reg>
654 (insertelt vec_type:$vec, elem_type:$elem, sub_idx),
655 (INSERT_SUBREG $vec, $elem, sub_reg)
658 // XXX: Convert to new syntax and use COPY_TO_REG, once the DFAPacketizer
659 // can handle COPY instructions.
660 // bitconvert pattern
661 class BitConvert <ValueType dt, ValueType st, RegisterClass rc> : AMDGPUPat <
662 (dt (bitconvert (st rc:$src0))),
666 // XXX: Convert to new syntax and use COPY_TO_REG, once the DFAPacketizer
667 // can handle COPY instructions.
668 class DwordAddrPat<ValueType vt, RegisterClass rc> : AMDGPUPat <
669 (vt (AMDGPUdwordaddr (vt rc:$addr))),
675 multiclass BFIPatterns <Instruction BFI_INT,
676 Instruction LoadImm32,
677 RegisterClass RC64> {
678 // Definition from ISA doc:
679 // (y & x) | (z & ~x)
681 (or (and i32:$y, i32:$x), (and i32:$z, (not i32:$x))),
687 (or (and i64:$y, i64:$x), (and i64:$z, (not i64:$x))),
689 (BFI_INT (i32 (EXTRACT_SUBREG $x, sub0)),
690 (i32 (EXTRACT_SUBREG $y, sub0)),
691 (i32 (EXTRACT_SUBREG $z, sub0))), sub0,
692 (BFI_INT (i32 (EXTRACT_SUBREG $x, sub1)),
693 (i32 (EXTRACT_SUBREG $y, sub1)),
694 (i32 (EXTRACT_SUBREG $z, sub1))), sub1)
697 // SHA-256 Ch function
700 (xor i32:$z, (and i32:$x, (xor i32:$y, i32:$z))),
706 (xor i64:$z, (and i64:$x, (xor i64:$y, i64:$z))),
708 (BFI_INT (i32 (EXTRACT_SUBREG $x, sub0)),
709 (i32 (EXTRACT_SUBREG $y, sub0)),
710 (i32 (EXTRACT_SUBREG $z, sub0))), sub0,
711 (BFI_INT (i32 (EXTRACT_SUBREG $x, sub1)),
712 (i32 (EXTRACT_SUBREG $y, sub1)),
713 (i32 (EXTRACT_SUBREG $z, sub1))), sub1)
717 (fcopysign f32:$src0, f32:$src1),
718 (BFI_INT (LoadImm32 (i32 0x7fffffff)), $src0, $src1)
722 (f32 (fcopysign f32:$src0, f64:$src1)),
723 (BFI_INT (LoadImm32 (i32 0x7fffffff)), $src0,
724 (i32 (EXTRACT_SUBREG $src1, sub1)))
728 (f64 (fcopysign f64:$src0, f64:$src1)),
730 (i32 (EXTRACT_SUBREG $src0, sub0)), sub0,
731 (BFI_INT (LoadImm32 (i32 0x7fffffff)),
732 (i32 (EXTRACT_SUBREG $src0, sub1)),
733 (i32 (EXTRACT_SUBREG $src1, sub1))), sub1)
737 (f64 (fcopysign f64:$src0, f32:$src1)),
739 (i32 (EXTRACT_SUBREG $src0, sub0)), sub0,
740 (BFI_INT (LoadImm32 (i32 0x7fffffff)),
741 (i32 (EXTRACT_SUBREG $src0, sub1)),
746 // SHA-256 Ma patterns
748 // ((x & z) | (y & (x | z))) -> BFI_INT (XOR x, y), z, y
749 multiclass SHA256MaPattern <Instruction BFI_INT, Instruction XOR, RegisterClass RC64> {
751 (or (and i32:$x, i32:$z), (and i32:$y, (or i32:$x, i32:$z))),
752 (BFI_INT (XOR i32:$x, i32:$y), i32:$z, i32:$y)
756 (or (and i64:$x, i64:$z), (and i64:$y, (or i64:$x, i64:$z))),
758 (BFI_INT (XOR (i32 (EXTRACT_SUBREG $x, sub0)),
759 (i32 (EXTRACT_SUBREG $y, sub0))),
760 (i32 (EXTRACT_SUBREG $z, sub0)),
761 (i32 (EXTRACT_SUBREG $y, sub0))), sub0,
762 (BFI_INT (XOR (i32 (EXTRACT_SUBREG $x, sub1)),
763 (i32 (EXTRACT_SUBREG $y, sub1))),
764 (i32 (EXTRACT_SUBREG $z, sub1)),
765 (i32 (EXTRACT_SUBREG $y, sub1))), sub1)
769 // Bitfield extract patterns
771 def IMMZeroBasedBitfieldMask : PatLeaf <(imm), [{
772 return isMask_32(N->getZExtValue());
775 def IMMPopCount : SDNodeXForm<imm, [{
776 return CurDAG->getTargetConstant(countPopulation(N->getZExtValue()), SDLoc(N),
780 multiclass BFEPattern <Instruction UBFE, Instruction SBFE, Instruction MOV> {
782 (i32 (and (i32 (srl i32:$src, i32:$rshift)), IMMZeroBasedBitfieldMask:$mask)),
783 (UBFE $src, $rshift, (MOV (i32 (IMMPopCount $mask))))
786 // x & ((1 << y) - 1)
788 (and i32:$src, (add_oneuse (shl_oneuse 1, i32:$width), -1)),
789 (UBFE $src, (MOV (i32 0)), $width)
794 (and i32:$src, (xor_oneuse (shl_oneuse -1, i32:$width), -1)),
795 (UBFE $src, (MOV (i32 0)), $width)
798 // x & (-1 >> (bitwidth - y))
800 (and i32:$src, (srl_oneuse -1, (sub 32, i32:$width))),
801 (UBFE $src, (MOV (i32 0)), $width)
804 // x << (bitwidth - y) >> (bitwidth - y)
806 (srl (shl_oneuse i32:$src, (sub 32, i32:$width)), (sub 32, i32:$width)),
807 (UBFE $src, (MOV (i32 0)), $width)
811 (sra (shl_oneuse i32:$src, (sub 32, i32:$width)), (sub 32, i32:$width)),
812 (SBFE $src, (MOV (i32 0)), $width)
817 class ROTRPattern <Instruction BIT_ALIGN> : AMDGPUPat <
818 (rotr i32:$src0, i32:$src1),
819 (BIT_ALIGN $src0, $src0, $src1)
822 multiclass IntMed3Pat<Instruction med3Inst,
823 SDPatternOperator min,
824 SDPatternOperator max,
825 SDPatternOperator min_oneuse,
826 SDPatternOperator max_oneuse,
827 ValueType vt = i32> {
829 // This matches 16 permutations of
830 // min(max(a, b), max(min(a, b), c))
832 (min (max_oneuse vt:$src0, vt:$src1),
833 (max_oneuse (min_oneuse vt:$src0, vt:$src1), vt:$src2)),
834 (med3Inst vt:$src0, vt:$src1, vt:$src2)
837 // This matches 16 permutations of
838 // max(min(x, y), min(max(x, y), z))
840 (max (min_oneuse vt:$src0, vt:$src1),
841 (min_oneuse (max_oneuse vt:$src0, vt:$src1), vt:$src2)),
842 (med3Inst $src0, $src1, $src2)
846 // Special conversion patterns
848 def cvt_rpi_i32_f32 : PatFrag <
850 (fp_to_sint (ffloor (fadd $src, FP_HALF))),
851 [{ (void) N; return TM.Options.NoNaNsFPMath; }]
854 def cvt_flr_i32_f32 : PatFrag <
856 (fp_to_sint (ffloor $src)),
857 [{ (void)N; return TM.Options.NoNaNsFPMath; }]
860 let AddedComplexity = 2 in {
861 class IMad24Pat<Instruction Inst, bit HasClamp = 0> : AMDGPUPat <
862 (add (AMDGPUmul_i24 i32:$src0, i32:$src1), i32:$src2),
863 !if(HasClamp, (Inst $src0, $src1, $src2, (i1 0)),
864 (Inst $src0, $src1, $src2))
867 class UMad24Pat<Instruction Inst, bit HasClamp = 0> : AMDGPUPat <
868 (add (AMDGPUmul_u24 i32:$src0, i32:$src1), i32:$src2),
869 !if(HasClamp, (Inst $src0, $src1, $src2, (i1 0)),
870 (Inst $src0, $src1, $src2))
872 } // AddedComplexity.
874 class RcpPat<Instruction RcpInst, ValueType vt> : AMDGPUPat <
875 (fdiv FP_ONE, vt:$src),
879 class RsqPat<Instruction RsqInst, ValueType vt> : AMDGPUPat <
880 (AMDGPUrcp (fsqrt vt:$src)),
884 // Instructions which select to the same v_min_f*
885 def fminnum_like : PatFrags<(ops node:$src0, node:$src1),
886 [(fminnum_ieee node:$src0, node:$src1),
887 (fminnum node:$src0, node:$src1)]
890 // Instructions which select to the same v_max_f*
891 def fmaxnum_like : PatFrags<(ops node:$src0, node:$src1),
892 [(fmaxnum_ieee node:$src0, node:$src1),
893 (fmaxnum node:$src0, node:$src1)]
896 def fminnum_like_oneuse : PatFrags<(ops node:$src0, node:$src1),
897 [(fminnum_ieee_oneuse node:$src0, node:$src1),
898 (fminnum_oneuse node:$src0, node:$src1)]
901 def fmaxnum_like_oneuse : PatFrags<(ops node:$src0, node:$src1),
902 [(fmaxnum_ieee_oneuse node:$src0, node:$src1),
903 (fmaxnum_oneuse node:$src0, node:$src1)]