blob: 43b6d2a2155b68060d66d77e716d7cac51bba5e0 [file] [log] [blame]
Matt Arsenault9be7b0d2017-02-27 18:49:11 +00001//===-- VOP3PInstructions.td - Vector Instruction Defintions --------------===//
2//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// 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
Matt Arsenault9be7b0d2017-02-27 18:49:11 +00006//
7//===----------------------------------------------------------------------===//
8
9//===----------------------------------------------------------------------===//
10// VOP3P Classes
11//===----------------------------------------------------------------------===//
12
13class VOP3PInst<string OpName, VOPProfile P, SDPatternOperator node = null_frag> :
14 VOP3P_Pseudo<OpName, P,
15 !if(P.HasModifiers, getVOP3PModPat<P, node>.ret, getVOP3Pat<P, node>.ret)
16>;
17
Dmitry Preobrazhenskyb2d24e22017-07-07 14:29:06 +000018// Non-packed instructions that use the VOP3P encoding.
19// VOP3 neg/abs and VOP3P opsel/opsel_hi modifiers are allowed.
Matt Arsenaulte135c4c2017-09-20 20:53:49 +000020class VOP3_VOP3PInst<string OpName, VOPProfile P, bit UseTiedOutput = 0,
21 SDPatternOperator node = null_frag> :
Dmitry Preobrazhenskyb2d24e22017-07-07 14:29:06 +000022 VOP3P_Pseudo<OpName, P> {
Matt Arsenaultc8f8cda2017-08-30 22:18:40 +000023 // These operands are only sort of f16 operands. Depending on
24 // op_sel_hi, these may be interpreted as f32. The inline immediate
25 // values are really f16 converted to f32, so we treat these as f16
26 // operands.
Dmitry Preobrazhenskyb2d24e22017-07-07 14:29:06 +000027 let InOperandList =
Matt Arsenaulte135c4c2017-09-20 20:53:49 +000028 !con(
29 !con(
30 (ins FP16InputMods:$src0_modifiers, VCSrc_f16:$src0,
31 FP16InputMods:$src1_modifiers, VCSrc_f16:$src1,
32 FP16InputMods:$src2_modifiers, VCSrc_f16:$src2,
33 clampmod:$clamp),
34 !if(UseTiedOutput, (ins VGPR_32:$vdst_in), (ins))),
35 (ins op_sel:$op_sel, op_sel_hi:$op_sel_hi));
36
37 let Constraints = !if(UseTiedOutput, "$vdst = $vdst_in", "");
38 let DisableEncoding = !if(UseTiedOutput, "$vdst_in", "");
Dmitry Preobrazhenskyb2d24e22017-07-07 14:29:06 +000039 let AsmOperands =
40 " $vdst, $src0_modifiers, $src1_modifiers, $src2_modifiers$op_sel$op_sel_hi$clamp";
41}
Matt Arsenault9be7b0d2017-02-27 18:49:11 +000042
43let isCommutable = 1 in {
Dmitry Preobrazhensky095ec3da2017-07-18 09:24:10 +000044def V_PK_MAD_I16 : VOP3PInst<"v_pk_mad_i16", VOP3_Profile<VOP_V2I16_V2I16_V2I16_V2I16>>;
45def V_PK_MAD_U16 : VOP3PInst<"v_pk_mad_u16", VOP3_Profile<VOP_V2I16_V2I16_V2I16_V2I16>>;
46
Tim Corringham4c4d2fe2018-12-10 12:06:10 +000047let FPDPRounding = 1 in {
48def V_PK_FMA_F16 : VOP3PInst<"v_pk_fma_f16", VOP3_Profile<VOP_V2F16_V2F16_V2F16_V2F16>, fma>;
Matt Arsenaulteb522e62017-02-27 22:15:25 +000049def V_PK_ADD_F16 : VOP3PInst<"v_pk_add_f16", VOP3_Profile<VOP_V2F16_V2F16_V2F16>, fadd>;
50def V_PK_MUL_F16 : VOP3PInst<"v_pk_mul_f16", VOP3_Profile<VOP_V2F16_V2F16_V2F16>, fmul>;
Tim Corringham4c4d2fe2018-12-10 12:06:10 +000051} // End FPDPRounding = 1
Matt Arsenault687ec752018-10-22 16:27:27 +000052def V_PK_MAX_F16 : VOP3PInst<"v_pk_max_f16", VOP3_Profile<VOP_V2F16_V2F16_V2F16>, fmaxnum_like>;
53def V_PK_MIN_F16 : VOP3PInst<"v_pk_min_f16", VOP3_Profile<VOP_V2F16_V2F16_V2F16>, fminnum_like>;
Matt Arsenault9be7b0d2017-02-27 18:49:11 +000054
Matt Arsenaulteb522e62017-02-27 22:15:25 +000055def V_PK_ADD_U16 : VOP3PInst<"v_pk_add_u16", VOP3_Profile<VOP_V2I16_V2I16_V2I16>, add>;
Matt Arsenault9be7b0d2017-02-27 18:49:11 +000056def V_PK_ADD_I16 : VOP3PInst<"v_pk_add_i16", VOP3_Profile<VOP_V2I16_V2I16_V2I16>>;
Matt Arsenaulteb522e62017-02-27 22:15:25 +000057def V_PK_MUL_LO_U16 : VOP3PInst<"v_pk_mul_lo_u16", VOP3_Profile<VOP_V2I16_V2I16_V2I16>, mul>;
Matt Arsenault9be7b0d2017-02-27 18:49:11 +000058
Matt Arsenaulteb522e62017-02-27 22:15:25 +000059def V_PK_MIN_I16 : VOP3PInst<"v_pk_min_i16", VOP3_Profile<VOP_V2I16_V2I16_V2I16>, smin>;
60def V_PK_MIN_U16 : VOP3PInst<"v_pk_min_u16", VOP3_Profile<VOP_V2I16_V2I16_V2I16>, umin>;
61def V_PK_MAX_I16 : VOP3PInst<"v_pk_max_i16", VOP3_Profile<VOP_V2I16_V2I16_V2I16>, smax>;
62def V_PK_MAX_U16 : VOP3PInst<"v_pk_max_u16", VOP3_Profile<VOP_V2I16_V2I16_V2I16>, umax>;
Matt Arsenault9be7b0d2017-02-27 18:49:11 +000063}
64
Dmitry Preobrazhensky095ec3da2017-07-18 09:24:10 +000065def V_PK_SUB_U16 : VOP3PInst<"v_pk_sub_u16", VOP3_Profile<VOP_V2I16_V2I16_V2I16>>;
66def V_PK_SUB_I16 : VOP3PInst<"v_pk_sub_i16", VOP3_Profile<VOP_V2I16_V2I16_V2I16>, sub>;
67
Matt Arsenaulteb522e62017-02-27 22:15:25 +000068def V_PK_LSHLREV_B16 : VOP3PInst<"v_pk_lshlrev_b16", VOP3_Profile<VOP_V2I16_V2I16_V2I16>, lshl_rev>;
69def V_PK_ASHRREV_I16 : VOP3PInst<"v_pk_ashrrev_i16", VOP3_Profile<VOP_V2I16_V2I16_V2I16>, ashr_rev>;
70def V_PK_LSHRREV_B16 : VOP3PInst<"v_pk_lshrrev_b16", VOP3_Profile<VOP_V2I16_V2I16_V2I16>, lshr_rev>;
Matt Arsenault9be7b0d2017-02-27 18:49:11 +000071
Matt Arsenault0084adc2018-04-30 19:08:16 +000072multiclass MadFmaMixPats<SDPatternOperator fma_like,
73 Instruction mix_inst,
74 Instruction mixlo_inst,
75 Instruction mixhi_inst> {
76 def : GCNPat <
77 (f16 (fpround (fma_like (f32 (VOP3PMadMixMods f16:$src0, i32:$src0_modifiers)),
78 (f32 (VOP3PMadMixMods f16:$src1, i32:$src1_modifiers)),
79 (f32 (VOP3PMadMixMods f16:$src2, i32:$src2_modifiers))))),
80 (mixlo_inst $src0_modifiers, $src0,
81 $src1_modifiers, $src1,
82 $src2_modifiers, $src2,
83 DSTCLAMP.NONE,
84 (i32 (IMPLICIT_DEF)))
85 >;
86
87 // FIXME: Special case handling for maxhi (especially for clamp)
88 // because dealing with the write to high half of the register is
89 // difficult.
90 def : GCNPat <
91 (build_vector f16:$elt0, (fpround (fma_like (f32 (VOP3PMadMixMods f16:$src0, i32:$src0_modifiers)),
92 (f32 (VOP3PMadMixMods f16:$src1, i32:$src1_modifiers)),
93 (f32 (VOP3PMadMixMods f16:$src2, i32:$src2_modifiers))))),
94 (v2f16 (mixhi_inst $src0_modifiers, $src0,
95 $src1_modifiers, $src1,
96 $src2_modifiers, $src2,
97 DSTCLAMP.NONE,
98 $elt0))
99 >;
100
101 def : GCNPat <
102 (build_vector
103 f16:$elt0,
104 (AMDGPUclamp (fpround (fma_like (f32 (VOP3PMadMixMods f16:$src0, i32:$src0_modifiers)),
105 (f32 (VOP3PMadMixMods f16:$src1, i32:$src1_modifiers)),
106 (f32 (VOP3PMadMixMods f16:$src2, i32:$src2_modifiers)))))),
107 (v2f16 (mixhi_inst $src0_modifiers, $src0,
108 $src1_modifiers, $src1,
109 $src2_modifiers, $src2,
110 DSTCLAMP.ENABLE,
111 $elt0))
112 >;
113
114 def : GCNPat <
115 (AMDGPUclamp (build_vector
116 (fpround (fma_like (f32 (VOP3PMadMixMods f16:$lo_src0, i32:$lo_src0_modifiers)),
117 (f32 (VOP3PMadMixMods f16:$lo_src1, i32:$lo_src1_modifiers)),
118 (f32 (VOP3PMadMixMods f16:$lo_src2, i32:$lo_src2_modifiers)))),
119 (fpround (fma_like (f32 (VOP3PMadMixMods f16:$hi_src0, i32:$hi_src0_modifiers)),
120 (f32 (VOP3PMadMixMods f16:$hi_src1, i32:$hi_src1_modifiers)),
121 (f32 (VOP3PMadMixMods f16:$hi_src2, i32:$hi_src2_modifiers)))))),
122 (v2f16 (mixhi_inst $hi_src0_modifiers, $hi_src0,
123 $hi_src1_modifiers, $hi_src1,
124 $hi_src2_modifiers, $hi_src2,
125 DSTCLAMP.ENABLE,
126 (mixlo_inst $lo_src0_modifiers, $lo_src0,
127 $lo_src1_modifiers, $lo_src1,
128 $lo_src2_modifiers, $lo_src2,
129 DSTCLAMP.ENABLE,
130 (i32 (IMPLICIT_DEF)))))
131 >;
132}
Matt Arsenault28f52e52017-10-25 07:00:51 +0000133
134let SubtargetPredicate = HasMadMixInsts in {
Dmitry Preobrazhenskyb2d24e22017-07-07 14:29:06 +0000135// These are VOP3a-like opcodes which accept no omod.
136// Size of src arguments (16/32) is controlled by op_sel.
137// For 16-bit src arguments their location (hi/lo) are controlled by op_sel_hi.
Matt Arsenaultc8f8cda2017-08-30 22:18:40 +0000138let isCommutable = 1 in {
Matt Arsenault644883f2017-09-20 19:09:28 +0000139def V_MAD_MIX_F32 : VOP3_VOP3PInst<"v_mad_mix_f32", VOP3_Profile<VOP_F32_F16_F16_F16, VOP3_OPSEL>>;
Matt Arsenault76935122017-09-20 20:28:39 +0000140
Tim Corringham4c4d2fe2018-12-10 12:06:10 +0000141let FPDPRounding = 1 in {
Matt Arsenault76935122017-09-20 20:28:39 +0000142// Clamp modifier is applied after conversion to f16.
Matt Arsenaulte135c4c2017-09-20 20:53:49 +0000143def V_MAD_MIXLO_F16 : VOP3_VOP3PInst<"v_mad_mixlo_f16", VOP3_Profile<VOP_F16_F16_F16_F16, VOP3_OPSEL>, 1>;
Matt Arsenault8cbb4882017-09-20 21:01:24 +0000144
145let ClampLo = 0, ClampHi = 1 in {
Matt Arsenaulte135c4c2017-09-20 20:53:49 +0000146def V_MAD_MIXHI_F16 : VOP3_VOP3PInst<"v_mad_mixhi_f16", VOP3_Profile<VOP_F16_F16_F16_F16, VOP3_OPSEL>, 1>;
Matt Arsenaultc8f8cda2017-08-30 22:18:40 +0000147}
Tim Corringham4c4d2fe2018-12-10 12:06:10 +0000148} // End FPDPRounding = 1
Matt Arsenault8cbb4882017-09-20 21:01:24 +0000149}
Matt Arsenault9be7b0d2017-02-27 18:49:11 +0000150
Matt Arsenault0084adc2018-04-30 19:08:16 +0000151defm : MadFmaMixPats<fmad, V_MAD_MIX_F32, V_MAD_MIXLO_F16, V_MAD_MIXHI_F16>;
152} // End SubtargetPredicate = HasMadMixInsts
Matt Arsenault76935122017-09-20 20:28:39 +0000153
Matt Arsenault8cbb4882017-09-20 21:01:24 +0000154
Matt Arsenault0084adc2018-04-30 19:08:16 +0000155// Essentially the same as the mad_mix versions
156let SubtargetPredicate = HasFmaMixInsts in {
157let isCommutable = 1 in {
158def V_FMA_MIX_F32 : VOP3_VOP3PInst<"v_fma_mix_f32", VOP3_Profile<VOP_F32_F16_F16_F16, VOP3_OPSEL>>;
Matt Arsenault8cbb4882017-09-20 21:01:24 +0000159
Tim Corringham4c4d2fe2018-12-10 12:06:10 +0000160let FPDPRounding = 1 in {
Matt Arsenault0084adc2018-04-30 19:08:16 +0000161// Clamp modifier is applied after conversion to f16.
162def V_FMA_MIXLO_F16 : VOP3_VOP3PInst<"v_fma_mixlo_f16", VOP3_Profile<VOP_F16_F16_F16_F16, VOP3_OPSEL>, 1>;
Matt Arsenault8cbb4882017-09-20 21:01:24 +0000163
Matt Arsenault0084adc2018-04-30 19:08:16 +0000164let ClampLo = 0, ClampHi = 1 in {
165def V_FMA_MIXHI_F16 : VOP3_VOP3PInst<"v_fma_mixhi_f16", VOP3_Profile<VOP_F16_F16_F16_F16, VOP3_OPSEL>, 1>;
166}
Tim Corringham4c4d2fe2018-12-10 12:06:10 +0000167} // End FPDPRounding = 1
Matt Arsenault0084adc2018-04-30 19:08:16 +0000168}
169
170defm : MadFmaMixPats<fma, V_FMA_MIX_F32, V_FMA_MIXLO_F16, V_FMA_MIXHI_F16>;
171}
172
Farhana Aleen4bc597b2018-10-04 16:57:37 +0000173// Defines patterns that extract signed 4bit from each Idx[0].
174foreach Idx = [[0,28],[4,24],[8,20],[12,16],[16,12],[20,8],[24,4]] in
175 def ExtractSigned4bit_#Idx[0] : PatFrag<(ops node:$src),
176 (sra (shl node:$src, (i32 Idx[1])), (i32 28))>;
Farhana Aleen9250c922018-08-29 16:31:18 +0000177
Farhana Aleen4bc597b2018-10-04 16:57:37 +0000178// Defines code pattern that extracts U(unsigned/signed) 4/8bit from FromBitIndex.
179class Extract<int FromBitIndex, int BitMask, bit U>: PatFrag<
Farhana Aleenf5a28482018-09-18 16:59:48 +0000180 (ops node:$src),
Farhana Aleen4bc597b2018-10-04 16:57:37 +0000181 !if (!or (!and (!eq (BitMask, 255), !eq (FromBitIndex, 24)), !eq (FromBitIndex, 28)), // last element
182 !if (U, (srl node:$src, (i32 FromBitIndex)), (sra node:$src, (i32 FromBitIndex))),
Farhana Aleen9250c922018-08-29 16:31:18 +0000183 !if (!eq (FromBitIndex, 0), // first element
Farhana Aleen4bc597b2018-10-04 16:57:37 +0000184 !if (U, (and node:$src, (i32 BitMask)),
185 !if (!eq (BitMask, 15), (!cast<PatFrag>("ExtractSigned4bit_"#FromBitIndex) node:$src),
186 (sext_inreg node:$src, i8))),
187 !if (U, (and (srl node:$src, (i32 FromBitIndex)), (i32 BitMask)),
188 !if (!eq (BitMask, 15), (!cast<PatFrag>("ExtractSigned4bit_"#FromBitIndex) node:$src),
189 (sext_inreg (srl node:$src, (i32 FromBitIndex)), i8)))))>;
Farhana Aleen9250c922018-08-29 16:31:18 +0000190
Farhana Aleen9250c922018-08-29 16:31:18 +0000191
Farhana Aleen4bc597b2018-10-04 16:57:37 +0000192foreach Type = ["I", "U"] in
193 foreach Index = 0-3 in {
194 // Defines patterns that extract each Index'ed 8bit from an unsigned
195 // 32bit scalar value;
196 def #Type#Index#"_8bit" : Extract<!shl(Index, 3), 255, !if (!eq (Type, "U"), 1, 0)>;
197
198 // Defines multiplication patterns where the multiplication is happening on each
199 // Index'ed 8bit of a 32bit scalar value.
200
201 def Mul#Type#_Elt#Index : PatFrag<
202 (ops node:$src0, node:$src1),
203 (!cast<HasOneUseBinOp>(!if (!eq (Type, "I"), AMDGPUmul_i24_oneuse, AMDGPUmul_u24_oneuse))
204 (!cast<Extract>(#Type#Index#"_8bit") node:$src0),
205 (!cast<Extract>(#Type#Index#"_8bit") node:$src1))>;
206 }
Farhana Aleenf5a28482018-09-18 16:59:48 +0000207
208// Different variants of dot8 patterns cause a huge increase in the compile time.
209// Define non-associative/commutative add/mul to prevent permutation in the dot8
210// pattern.
211def NonACAdd : SDNode<"ISD::ADD" , SDTIntBinOp>;
212def NonACAdd_oneuse : HasOneUseBinOp<NonACAdd>;
213
214def NonACAMDGPUmul_u24 : SDNode<"AMDGPUISD::MUL_U24" , SDTIntBinOp>;
215def NonACAMDGPUmul_u24_oneuse : HasOneUseBinOp<NonACAMDGPUmul_u24>;
216
Farhana Aleen4bc597b2018-10-04 16:57:37 +0000217def NonACAMDGPUmul_i24 : SDNode<"AMDGPUISD::MUL_I24" , SDTIntBinOp>;
218def NonACAMDGPUmul_i24_oneuse : HasOneUseBinOp<NonACAMDGPUmul_i24>;
Farhana Aleenf5a28482018-09-18 16:59:48 +0000219
Farhana Aleen4bc597b2018-10-04 16:57:37 +0000220foreach Type = ["I", "U"] in
221 foreach Index = 0-7 in {
222 // Defines patterns that extract each Index'ed 4bit from an unsigned
223 // 32bit scalar value;
224 def #Type#Index#"_4bit" : Extract<!shl(Index, 2), 15, !if (!eq (Type, "U"), 1, 0)>;
225
226 // Defines multiplication patterns where the multiplication is happening on each
227 // Index'ed 8bit of a 32bit scalar value.
228 def Mul#Type#Index#"_4bit" : PatFrag<
229 (ops node:$src0, node:$src1),
230 (!cast<HasOneUseBinOp>(!if (!eq (Type, "I"), NonACAMDGPUmul_i24_oneuse, NonACAMDGPUmul_u24_oneuse))
231 (!cast<Extract>(#Type#Index#"_4bit") node:$src0),
232 (!cast<Extract>(#Type#Index#"_4bit") node:$src1))>;
233 }
Farhana Aleen9250c922018-08-29 16:31:18 +0000234
Farhana Aleen3528c802018-08-21 16:21:15 +0000235class UDot2Pat<Instruction Inst> : GCNPat <
236 (add (add_oneuse (AMDGPUmul_u24_oneuse (srl i32:$src0, (i32 16)),
237 (srl i32:$src1, (i32 16))), i32:$src2),
238 (AMDGPUmul_u24_oneuse (and i32:$src0, (i32 65535)),
239 (and i32:$src1, (i32 65535)))
240 ),
Stanislav Mekhanoshin0e858b02019-02-09 00:34:21 +0000241 (Inst (i32 8), $src0, (i32 8), $src1, (i32 8), $src2, (i1 0))> {
242 let SubtargetPredicate = !cast<VOP_Pseudo>(Inst).SubtargetPredicate;
243}
Farhana Aleen3528c802018-08-21 16:21:15 +0000244
245class SDot2Pat<Instruction Inst> : GCNPat <
246 (add (add_oneuse (AMDGPUmul_i24_oneuse (sra i32:$src0, (i32 16)),
247 (sra i32:$src1, (i32 16))), i32:$src2),
248 (AMDGPUmul_i24_oneuse (sext_inreg i32:$src0, i16),
249 (sext_inreg i32:$src1, i16))),
Stanislav Mekhanoshin0e858b02019-02-09 00:34:21 +0000250 (Inst (i32 8), $src0, (i32 8), $src1, (i32 8), $src2, (i1 0))> {
251 let SubtargetPredicate = !cast<VOP_Pseudo>(Inst).SubtargetPredicate;
252}
Farhana Aleen3528c802018-08-21 16:21:15 +0000253
Stanislav Mekhanoshin0e858b02019-02-09 00:34:21 +0000254let SubtargetPredicate = HasDot2Insts in {
Matt Arsenault0084adc2018-04-30 19:08:16 +0000255
Konstantin Zhuravlyovbb30ef72018-08-01 01:31:30 +0000256def V_DOT2_F32_F16 : VOP3PInst<"v_dot2_f32_f16", VOP3_Profile<VOP_F32_V2F16_V2F16_F32>>;
257def V_DOT2_I32_I16 : VOP3PInst<"v_dot2_i32_i16", VOP3_Profile<VOP_I32_V2I16_V2I16_I32>>;
258def V_DOT2_U32_U16 : VOP3PInst<"v_dot2_u32_u16", VOP3_Profile<VOP_I32_V2I16_V2I16_I32>>;
Konstantin Zhuravlyovbb30ef72018-08-01 01:31:30 +0000259def V_DOT4_U32_U8 : VOP3PInst<"v_dot4_u32_u8", VOP3_Profile<VOP_I32_I32_I32_I32, VOP3_PACKED>>;
Konstantin Zhuravlyovbb30ef72018-08-01 01:31:30 +0000260def V_DOT8_U32_U4 : VOP3PInst<"v_dot8_u32_u4", VOP3_Profile<VOP_I32_I32_I32_I32, VOP3_PACKED>>;
261
Stanislav Mekhanoshin0e858b02019-02-09 00:34:21 +0000262} // End SubtargetPredicate = HasDot2Insts
263
264let SubtargetPredicate = HasDot1Insts in {
265
266def V_DOT4_I32_I8 : VOP3PInst<"v_dot4_i32_i8", VOP3_Profile<VOP_I32_I32_I32_I32, VOP3_PACKED>>;
267def V_DOT8_I32_I4 : VOP3PInst<"v_dot8_i32_i4", VOP3_Profile<VOP_I32_I32_I32_I32, VOP3_PACKED>>;
268
269} // End SubtargetPredicate = HasDot1Insts
270
Konstantin Zhuravlyovbb30ef72018-08-01 01:31:30 +0000271multiclass DotPats<SDPatternOperator dot_op,
272 VOP3PInst dot_inst> {
Stanislav Mekhanoshin0e858b02019-02-09 00:34:21 +0000273 let SubtargetPredicate = dot_inst.SubtargetPredicate in
Konstantin Zhuravlyovbb30ef72018-08-01 01:31:30 +0000274 def : GCNPat <
275 (dot_op (dot_inst.Pfl.Src0VT (VOP3PMods0 dot_inst.Pfl.Src0VT:$src0, i32:$src0_modifiers)),
276 (dot_inst.Pfl.Src1VT (VOP3PMods dot_inst.Pfl.Src1VT:$src1, i32:$src1_modifiers)),
277 (dot_inst.Pfl.Src2VT (VOP3PMods dot_inst.Pfl.Src2VT:$src2, i32:$src2_modifiers)), i1:$clamp),
278 (dot_inst $src0_modifiers, $src0, $src1_modifiers, $src1, $src2_modifiers, $src2, (as_i1imm $clamp))>;
279}
280
281defm : DotPats<AMDGPUfdot2, V_DOT2_F32_F16>;
282defm : DotPats<int_amdgcn_sdot2, V_DOT2_I32_I16>;
283defm : DotPats<int_amdgcn_udot2, V_DOT2_U32_U16>;
284defm : DotPats<int_amdgcn_sdot4, V_DOT4_I32_I8>;
285defm : DotPats<int_amdgcn_udot4, V_DOT4_U32_U8>;
286defm : DotPats<int_amdgcn_sdot8, V_DOT8_I32_I4>;
287defm : DotPats<int_amdgcn_udot8, V_DOT8_U32_U4>;
Matt Arsenault0084adc2018-04-30 19:08:16 +0000288
Farhana Aleen3528c802018-08-21 16:21:15 +0000289def : UDot2Pat<V_DOT2_U32_U16>;
290def : SDot2Pat<V_DOT2_I32_I16>;
291
Farhana Aleen4bc597b2018-10-04 16:57:37 +0000292foreach Type = ["U", "I"] in
Stanislav Mekhanoshin0e858b02019-02-09 00:34:21 +0000293 let SubtargetPredicate = !cast<VOP_Pseudo>("V_DOT4_"#Type#"32_"#Type#8).SubtargetPredicate in
Farhana Aleen4bc597b2018-10-04 16:57:37 +0000294 def : GCNPat <
295 !cast<dag>(!foldl((i32 i32:$src2), [0, 1, 2, 3], lhs, y,
296 (add_oneuse lhs, (!cast<PatFrag>("Mul"#Type#"_Elt"#y) i32:$src0, i32:$src1)))),
297 (!cast<VOP3PInst>("V_DOT4_"#Type#"32_"#Type#8) (i32 8), $src0, (i32 8), $src1, (i32 8), $src2, (i1 0))>;
Farhana Aleen9250c922018-08-29 16:31:18 +0000298
Farhana Aleen4bc597b2018-10-04 16:57:37 +0000299foreach Type = ["U", "I"] in
Stanislav Mekhanoshin0e858b02019-02-09 00:34:21 +0000300 let SubtargetPredicate = !cast<VOP_Pseudo>("V_DOT8_"#Type#"32_"#Type#4).SubtargetPredicate in
Farhana Aleen4bc597b2018-10-04 16:57:37 +0000301 def : GCNPat <
302 !cast<dag>(!foldl((add_oneuse i32:$src2, (!cast<PatFrag>("Mul"#Type#"0_4bit") i32:$src0, i32:$src1)),
303 [1, 2, 3, 4, 5, 6, 7], lhs, y,
304 (NonACAdd_oneuse lhs, (!cast<PatFrag>("Mul"#Type#y#"_4bit") i32:$src0, i32:$src1)))),
305 (!cast<VOP3PInst>("V_DOT8_"#Type#"32_"#Type#4) (i32 8), $src0, (i32 8), $src1, (i32 8), $src2, (i1 0))>;
Farhana Aleenf5a28482018-09-18 16:59:48 +0000306
Farhana Aleen58537622018-11-01 22:48:19 +0000307// Different variants of dot8 code-gen dag patterns are not generated through table-gen due to a huge increase
308// in the compile time. Directly handle the pattern generated by the FE here.
309foreach Type = ["U", "I"] in
Stanislav Mekhanoshin0e858b02019-02-09 00:34:21 +0000310 let SubtargetPredicate = !cast<VOP_Pseudo>("V_DOT8_"#Type#"32_"#Type#4).SubtargetPredicate in
Farhana Aleen58537622018-11-01 22:48:19 +0000311 def : GCNPat <
312 !cast<dag>(!foldl((add_oneuse i32:$src2, (!cast<PatFrag>("Mul"#Type#"0_4bit") i32:$src0, i32:$src1)),
313 [7, 1, 2, 3, 4, 5, 6], lhs, y,
314 (NonACAdd_oneuse lhs, (!cast<PatFrag>("Mul"#Type#y#"_4bit") i32:$src0, i32:$src1)))),
315 (!cast<VOP3PInst>("V_DOT8_"#Type#"32_"#Type#4) (i32 8), $src0, (i32 8), $src1, (i32 8), $src2, (i1 0))>;
316
Matt Arsenault9be7b0d2017-02-27 18:49:11 +0000317multiclass VOP3P_Real_vi<bits<10> op> {
Nicolai Haehnle4f850ea2018-03-26 13:56:53 +0000318 def _vi : VOP3P_Real<!cast<VOP3_Pseudo>(NAME), SIEncodingFamily.VI>,
319 VOP3Pe <op, !cast<VOP3_Pseudo>(NAME).Pfl> {
Matt Arsenault9be7b0d2017-02-27 18:49:11 +0000320 let AssemblerPredicates = [HasVOP3PInsts];
Stanislav Mekhanoshin51823022019-04-06 09:20:48 +0000321 let DecoderNamespace = "GFX8";
Matt Arsenault9be7b0d2017-02-27 18:49:11 +0000322 }
323}
324
Dmitry Preobrazhensky095ec3da2017-07-18 09:24:10 +0000325defm V_PK_MAD_I16 : VOP3P_Real_vi <0x380>;
Matt Arsenault9be7b0d2017-02-27 18:49:11 +0000326defm V_PK_MUL_LO_U16 : VOP3P_Real_vi <0x381>;
327defm V_PK_ADD_I16 : VOP3P_Real_vi <0x382>;
328defm V_PK_SUB_I16 : VOP3P_Real_vi <0x383>;
329defm V_PK_LSHLREV_B16 : VOP3P_Real_vi <0x384>;
330defm V_PK_LSHRREV_B16 : VOP3P_Real_vi <0x385>;
331defm V_PK_ASHRREV_I16 : VOP3P_Real_vi <0x386>;
332defm V_PK_MAX_I16 : VOP3P_Real_vi <0x387>;
333defm V_PK_MIN_I16 : VOP3P_Real_vi <0x388>;
Dmitry Preobrazhensky095ec3da2017-07-18 09:24:10 +0000334defm V_PK_MAD_U16 : VOP3P_Real_vi <0x389>;
Matt Arsenault9be7b0d2017-02-27 18:49:11 +0000335
336defm V_PK_ADD_U16 : VOP3P_Real_vi <0x38a>;
Dmitry Preobrazhensky095ec3da2017-07-18 09:24:10 +0000337defm V_PK_SUB_U16 : VOP3P_Real_vi <0x38b>;
Matt Arsenault9be7b0d2017-02-27 18:49:11 +0000338defm V_PK_MAX_U16 : VOP3P_Real_vi <0x38c>;
339defm V_PK_MIN_U16 : VOP3P_Real_vi <0x38d>;
340defm V_PK_FMA_F16 : VOP3P_Real_vi <0x38e>;
341defm V_PK_ADD_F16 : VOP3P_Real_vi <0x38f>;
342defm V_PK_MUL_F16 : VOP3P_Real_vi <0x390>;
343defm V_PK_MIN_F16 : VOP3P_Real_vi <0x391>;
344defm V_PK_MAX_F16 : VOP3P_Real_vi <0x392>;
345
Matt Arsenault0084adc2018-04-30 19:08:16 +0000346
347let SubtargetPredicate = HasMadMixInsts in {
Matt Arsenault9be7b0d2017-02-27 18:49:11 +0000348defm V_MAD_MIX_F32 : VOP3P_Real_vi <0x3a0>;
349defm V_MAD_MIXLO_F16 : VOP3P_Real_vi <0x3a1>;
350defm V_MAD_MIXHI_F16 : VOP3P_Real_vi <0x3a2>;
Matt Arsenault0084adc2018-04-30 19:08:16 +0000351}
352
353let SubtargetPredicate = HasFmaMixInsts in {
354let DecoderNamespace = "GFX9_DL" in {
355// The mad_mix instructions were renamed and their behaviors changed,
356// but the opcode stayed the same so we need to put these in a
357// different DecoderNamespace to avoid the ambiguity.
358defm V_FMA_MIX_F32 : VOP3P_Real_vi <0x3a0>;
359defm V_FMA_MIXLO_F16 : VOP3P_Real_vi <0x3a1>;
360defm V_FMA_MIXHI_F16 : VOP3P_Real_vi <0x3a2>;
361}
362}
363
364
Stanislav Mekhanoshin0e858b02019-02-09 00:34:21 +0000365let SubtargetPredicate = HasDot2Insts in {
Matt Arsenault0084adc2018-04-30 19:08:16 +0000366
367defm V_DOT2_F32_F16 : VOP3P_Real_vi <0x3a3>;
368defm V_DOT2_I32_I16 : VOP3P_Real_vi <0x3a6>;
369defm V_DOT2_U32_U16 : VOP3P_Real_vi <0x3a7>;
Matt Arsenault0084adc2018-04-30 19:08:16 +0000370defm V_DOT4_U32_U8 : VOP3P_Real_vi <0x3a9>;
Matt Arsenault0084adc2018-04-30 19:08:16 +0000371defm V_DOT8_U32_U4 : VOP3P_Real_vi <0x3ab>;
372
Stanislav Mekhanoshin0e858b02019-02-09 00:34:21 +0000373} // End SubtargetPredicate = HasDot2Insts
374
375let SubtargetPredicate = HasDot1Insts in {
376
377defm V_DOT4_I32_I8 : VOP3P_Real_vi <0x3a8>;
378defm V_DOT8_I32_I4 : VOP3P_Real_vi <0x3aa>;
379
380} // End SubtargetPredicate = HasDot1Insts
Stanislav Mekhanoshin61beff02019-04-26 17:56:03 +0000381
382//===----------------------------------------------------------------------===//
383// GFX10.
384//===----------------------------------------------------------------------===//
385
386let AssemblerPredicate = isGFX10Plus, DecoderNamespace = "GFX10" in {
387 multiclass VOP3P_Real_gfx10<bits<10> op> {
388 def _gfx10 : VOP3P_Real<!cast<VOP3P_Pseudo>(NAME), SIEncodingFamily.GFX10>,
389 VOP3Pe_gfx10 <op, !cast<VOP3P_Pseudo>(NAME).Pfl>;
390 }
391} // End AssemblerPredicate = isGFX10Plus, DecoderNamespace = "GFX10"
392
393defm V_PK_MAD_I16 : VOP3P_Real_gfx10<0x000>;
394defm V_PK_MUL_LO_U16 : VOP3P_Real_gfx10<0x001>;
395defm V_PK_ADD_I16 : VOP3P_Real_gfx10<0x002>;
396defm V_PK_SUB_I16 : VOP3P_Real_gfx10<0x003>;
397defm V_PK_LSHLREV_B16 : VOP3P_Real_gfx10<0x004>;
398defm V_PK_LSHRREV_B16 : VOP3P_Real_gfx10<0x005>;
399defm V_PK_ASHRREV_I16 : VOP3P_Real_gfx10<0x006>;
400defm V_PK_MAX_I16 : VOP3P_Real_gfx10<0x007>;
401defm V_PK_MIN_I16 : VOP3P_Real_gfx10<0x008>;
402defm V_PK_MAD_U16 : VOP3P_Real_gfx10<0x009>;
403defm V_PK_ADD_U16 : VOP3P_Real_gfx10<0x00a>;
404defm V_PK_SUB_U16 : VOP3P_Real_gfx10<0x00b>;
405defm V_PK_MAX_U16 : VOP3P_Real_gfx10<0x00c>;
406defm V_PK_MIN_U16 : VOP3P_Real_gfx10<0x00d>;
407defm V_PK_FMA_F16 : VOP3P_Real_gfx10<0x00e>;
408defm V_PK_ADD_F16 : VOP3P_Real_gfx10<0x00f>;
409defm V_PK_MUL_F16 : VOP3P_Real_gfx10<0x010>;
410defm V_PK_MIN_F16 : VOP3P_Real_gfx10<0x011>;
411defm V_PK_MAX_F16 : VOP3P_Real_gfx10<0x012>;
412defm V_FMA_MIX_F32 : VOP3P_Real_gfx10<0x020>;
413defm V_FMA_MIXLO_F16 : VOP3P_Real_gfx10<0x021>;
414defm V_FMA_MIXHI_F16 : VOP3P_Real_gfx10<0x022>;
Stanislav Mekhanoshinc43e67b2019-06-14 00:33:31 +0000415
416let SubtargetPredicate = HasDot2Insts in {
417
418defm V_DOT2_F32_F16 : VOP3P_Real_gfx10 <0x013>;
419defm V_DOT2_I32_I16 : VOP3P_Real_gfx10 <0x014>;
420defm V_DOT2_U32_U16 : VOP3P_Real_gfx10 <0x015>;
421defm V_DOT4_U32_U8 : VOP3P_Real_gfx10 <0x017>;
422defm V_DOT8_U32_U4 : VOP3P_Real_gfx10 <0x019>;
423
424} // End SubtargetPredicate = HasDot2Insts
425
426let SubtargetPredicate = HasDot1Insts in {
427
428defm V_DOT4_I32_I8 : VOP3P_Real_gfx10 <0x016>;
429defm V_DOT8_I32_I4 : VOP3P_Real_gfx10 <0x018>;
430
431} // End SubtargetPredicate = HasDot1Insts