xref: /freebsd/contrib/llvm-project/llvm/lib/Target/AMDGPU/SOPInstructions.td (revision 0fca6ea1d4eea4c934cfff25ac9ee8ad6fe95583)
1//===-- SOPInstructions.td - SOP Instruction Definitions ------------------===//
2//
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
6//
7//===----------------------------------------------------------------------===//
8
9def GPRIdxMode : CustomOperand<i32>;
10
11class SOP_Pseudo<string opName, dag outs, dag ins, string asmOps,
12                  list<dag> pattern=[]> :
13    InstSI<outs, ins, "", pattern>,
14    SIMCInstr<opName, SIEncodingFamily.NONE> {
15
16  let isPseudo = 1;
17  let isCodeGenOnly = 1;
18  let Size = 4;
19
20  string Mnemonic = opName;
21  string AsmOperands = asmOps;
22
23  bits<1> has_sdst = 0;
24}
25
26//===----------------------------------------------------------------------===//
27// SOP1 Instructions
28//===----------------------------------------------------------------------===//
29
30class SOP1_Pseudo <string opName, dag outs, dag ins,
31                   string asmOps, list<dag> pattern=[]> :
32  SOP_Pseudo<opName, outs, ins, " " # asmOps, pattern> {
33
34  let mayLoad = 0;
35  let mayStore = 0;
36  let hasSideEffects = 0;
37  let SALU = 1;
38  let SOP1 = 1;
39  let SchedRW = [WriteSALU];
40  let UseNamedOperandTable = 1;
41
42  bits<1> has_src0 = 1;
43  let has_sdst = 1;
44}
45
46class SOP1_Real<bits<8> op, SOP1_Pseudo ps, string real_name = ps.Mnemonic> :
47  InstSI <ps.OutOperandList, ps.InOperandList,
48          real_name # ps.AsmOperands>,
49  Enc32 {
50
51  let SALU = 1;
52  let SOP1 = 1;
53  let isPseudo = 0;
54  let isCodeGenOnly = 0;
55  let Size = 4;
56
57  // copy relevant pseudo op flags
58  let SubtargetPredicate = ps.SubtargetPredicate;
59  let AsmMatchConverter  = ps.AsmMatchConverter;
60  let SchedRW            = ps.SchedRW;
61  let mayLoad            = ps.mayLoad;
62  let mayStore           = ps.mayStore;
63  let isTerminator       = ps.isTerminator;
64  let isReturn           = ps.isReturn;
65  let isCall             = ps.isCall;
66  let isBranch           = ps.isBranch;
67  let isBarrier          = ps.isBarrier;
68  let Uses               = ps.Uses;
69  let Defs               = ps.Defs;
70
71  // encoding
72  bits<7> sdst;
73  bits<8> src0;
74
75  let Inst{7-0} = !if(ps.has_src0, src0, ?);
76  let Inst{15-8} = op;
77  let Inst{22-16} = !if(ps.has_sdst, sdst, ?);
78  let Inst{31-23} = 0x17d; //encoding;
79}
80
81class SOP1_32 <string opName, list<dag> pattern=[], bit tied_in = 0> : SOP1_Pseudo <
82  opName, (outs SReg_32:$sdst),
83  !if(tied_in, (ins SSrc_b32:$src0, SReg_32:$sdst_in),
84               (ins SSrc_b32:$src0)),
85  "$sdst, $src0", pattern> {
86  let Constraints = !if(tied_in, "$sdst = $sdst_in", "");
87}
88
89// Only register input allowed.
90class SOP1_32R <string opName, list<dag> pattern=[]> : SOP1_Pseudo <
91  opName, (outs SReg_32:$sdst), (ins SReg_32:$src0),
92  "$sdst, $src0", pattern>;
93
94// 32-bit input, no output.
95class SOP1_0_32 <string opName, list<dag> pattern = []> : SOP1_Pseudo <
96  opName, (outs), (ins SSrc_b32:$src0),
97  "$src0", pattern> {
98  let has_sdst = 0;
99}
100
101// Special case for movreld where sdst is treated as a use operand.
102class SOP1_32_movreld <string opName, list<dag> pattern=[]> : SOP1_Pseudo <
103  opName, (outs), (ins SReg_32:$sdst, SSrc_b32:$src0),
104  "$sdst, $src0", pattern>;
105
106// Special case for movreld where sdst is treated as a use operand.
107class SOP1_64_movreld <string opName, list<dag> pattern=[]> : SOP1_Pseudo <
108  opName, (outs), (ins SReg_64:$sdst, SSrc_b64:$src0),
109  "$sdst, $src0", pattern
110>;
111
112class SOP1_0_32R <string opName, list<dag> pattern = []> : SOP1_Pseudo <
113  opName, (outs), (ins SReg_32:$src0),
114  "$src0", pattern> {
115  let has_sdst = 0;
116}
117
118class SOP1_64 <string opName, list<dag> pattern=[]> : SOP1_Pseudo <
119  opName, (outs SReg_64:$sdst), (ins SSrc_b64:$src0),
120  "$sdst, $src0", pattern
121>;
122
123// Only register input allowed.
124class SOP1_64R <string opName, list<dag> pattern=[]> : SOP1_Pseudo <
125  opName, (outs SReg_64:$sdst), (ins SReg_64:$src0),
126  "$sdst, $src0", pattern
127>;
128
129// 64-bit input, 32-bit output.
130class SOP1_32_64 <string opName, list<dag> pattern=[]> : SOP1_Pseudo <
131  opName, (outs SReg_32:$sdst), (ins SSrc_b64:$src0),
132  "$sdst, $src0", pattern
133>;
134
135// 32-bit input, 64-bit output.
136class SOP1_64_32 <string opName, list<dag> pattern=[], bit tied_in = 0> : SOP1_Pseudo <
137  opName, (outs SReg_64:$sdst),
138  !if(tied_in, (ins SSrc_b32:$src0, SReg_64:$sdst_in),
139               (ins SSrc_b32:$src0)),
140  "$sdst, $src0", pattern> {
141  let Constraints = !if(tied_in, "$sdst = $sdst_in", "");
142}
143
144// no input, 64-bit output.
145class SOP1_64_0 <string opName, list<dag> pattern=[]> : SOP1_Pseudo <
146  opName, (outs SReg_64:$sdst), (ins), "$sdst", pattern> {
147  let has_src0 = 0;
148}
149
150// 64-bit input, no output
151class SOP1_1 <string opName, list<dag> pattern=[]> : SOP1_Pseudo <
152  opName, (outs), (ins SReg_64:$src0), "$src0", pattern> {
153  let has_sdst = 0;
154}
155
156
157class UniformUnaryFrag<SDPatternOperator Op> : PatFrag <
158  (ops node:$src0),
159  (Op $src0),
160  [{ return !N->isDivergent(); }]> {
161  // This check is unnecessary as it's captured by the result register
162  // bank constraint.
163  //
164  // FIXME: Should add a way for the emitter to recognize this is a
165  // trivially true predicate to eliminate the check.
166  let GISelPredicateCode = [{return true;}];
167}
168
169class UniformBinFrag<SDPatternOperator Op> : PatFrag <
170  (ops node:$src0, node:$src1),
171  (Op $src0, $src1),
172  [{ return !N->isDivergent(); }]> {
173  // This check is unnecessary as it's captured by the result register
174  // bank constraint.
175  //
176  // FIXME: Should add a way for the emitter to recognize this is a
177  // trivially true predicate to eliminate the check.
178  let GISelPredicateCode = [{return true;}];
179}
180
181class UniformTernaryFrag<SDPatternOperator Op> : PatFrag <
182  (ops node:$src0, node:$src1, node:$src2),
183  (Op $src0, $src1, $src2),
184  [{ return !N->isDivergent(); }]> {
185  // This check is unnecessary as it's captured by the result register
186  // bank constraint.
187  //
188  // FIXME: Should add a way for the emitter to recognize this is a
189  // trivially true predicate to eliminate the check.
190  let GISelPredicateCode = [{return true;}];
191}
192
193class DivergentBinFrag<SDPatternOperator Op> : PatFrag <
194  (ops node:$src0, node:$src1),
195  (Op $src0, $src1),
196  [{ return N->isDivergent(); }]> {
197  // This check is unnecessary as it's captured by the result register
198  // bank constraint.
199  //
200  // FIXME: Should add a way for the emitter to recognize this is a
201  // trivially true predicate to eliminate the check.
202  let GISelPredicateCode = [{return true;}];
203}
204
205
206let isMoveImm = 1 in {
207  let isReMaterializable = 1, isAsCheapAsAMove = 1 in {
208    def S_MOV_B32 : SOP1_32 <"s_mov_b32">;
209    def S_MOV_B64 : SOP1_64 <"s_mov_b64">;
210  } // End isReMaterializable = 1
211
212  let Uses = [SCC] in {
213    def S_CMOV_B32 : SOP1_32 <"s_cmov_b32">;
214    def S_CMOV_B64 : SOP1_64 <"s_cmov_b64">;
215  } // End Uses = [SCC]
216} // End isMoveImm = 1
217
218// Variant of S_MOV_B32 used for reading from volatile registers like
219// SRC_POPS_EXITING_WAVE_ID.
220let hasSideEffects = 1 in
221def S_MOV_B32_sideeffects : SOP1_32 <"s_mov_b32">;
222
223let Defs = [SCC] in {
224  def S_NOT_B32 : SOP1_32 <"s_not_b32",
225    [(set i32:$sdst, (UniformUnaryFrag<not> i32:$src0))]
226  >;
227
228  def S_NOT_B64 : SOP1_64 <"s_not_b64",
229    [(set i64:$sdst, (UniformUnaryFrag<not> i64:$src0))]
230  >;
231  def S_WQM_B32 : SOP1_32 <"s_wqm_b32",
232    [(set i32:$sdst, (int_amdgcn_s_wqm i32:$src0))]>;
233  def S_WQM_B64 : SOP1_64 <"s_wqm_b64",
234    [(set i64:$sdst, (int_amdgcn_s_wqm i64:$src0))]>;
235} // End Defs = [SCC]
236
237
238let WaveSizePredicate = isWave32 in {
239def : GCNPat <
240  (int_amdgcn_wqm_vote i1:$src0),
241  (S_WQM_B32 SSrc_b32:$src0)
242>;
243}
244
245let WaveSizePredicate = isWave64 in {
246def : GCNPat <
247  (int_amdgcn_wqm_vote i1:$src0),
248  (S_WQM_B64 SSrc_b64:$src0)
249>;
250}
251
252let isReMaterializable = 1, isAsCheapAsAMove = 1 in {
253def S_BREV_B32 : SOP1_32 <"s_brev_b32",
254  [(set i32:$sdst, (UniformUnaryFrag<bitreverse> i32:$src0))]
255>;
256def S_BREV_B64 : SOP1_64 <"s_brev_b64",
257  [(set i64:$sdst, (UniformUnaryFrag<bitreverse> i64:$src0))]
258>;
259} // End isReMaterializable = 1, isAsCheapAsAMove = 1
260
261let Defs = [SCC] in {
262def S_BCNT0_I32_B32 : SOP1_32 <"s_bcnt0_i32_b32">;
263def S_BCNT0_I32_B64 : SOP1_32_64 <"s_bcnt0_i32_b64">;
264def S_BCNT1_I32_B32 : SOP1_32 <"s_bcnt1_i32_b32",
265  [(set i32:$sdst, (UniformUnaryFrag<ctpop> i32:$src0))]
266>;
267def S_BCNT1_I32_B64 : SOP1_32_64 <"s_bcnt1_i32_b64",
268  [(set i32:$sdst, (UniformUnaryFrag<ctpop> i64:$src0))]
269>;
270} // End Defs = [SCC]
271
272let isReMaterializable = 1 in {
273def S_FF0_I32_B32 : SOP1_32 <"s_ff0_i32_b32">;
274def S_FF0_I32_B64 : SOP1_32_64 <"s_ff0_i32_b64">;
275def S_FF1_I32_B64 : SOP1_32_64 <"s_ff1_i32_b64",
276  [(set i32:$sdst, (UniformUnaryFrag<AMDGPUffbl_b32> i64:$src0))]
277>;
278
279def S_FF1_I32_B32 : SOP1_32 <"s_ff1_i32_b32",
280  [(set i32:$sdst, (UniformUnaryFrag<AMDGPUffbl_b32> i32:$src0))]
281>;
282
283def S_FLBIT_I32_B32 : SOP1_32 <"s_flbit_i32_b32",
284  [(set i32:$sdst, (UniformUnaryFrag<AMDGPUffbh_u32> i32:$src0))]
285>;
286
287def S_FLBIT_I32_B64 : SOP1_32_64 <"s_flbit_i32_b64",
288  [(set i32:$sdst, (UniformUnaryFrag<AMDGPUffbh_u32> i64:$src0))]
289>;
290def S_FLBIT_I32 : SOP1_32 <"s_flbit_i32",
291  [(set i32:$sdst, (UniformUnaryFrag<AMDGPUffbh_i32> i32:$src0))]
292>;
293def S_FLBIT_I32_I64 : SOP1_32_64 <"s_flbit_i32_i64">;
294def S_SEXT_I32_I8 : SOP1_32 <"s_sext_i32_i8",
295  [(set i32:$sdst, (UniformSextInreg<i8> i32:$src0))]
296>;
297def S_SEXT_I32_I16 : SOP1_32 <"s_sext_i32_i16",
298  [(set i32:$sdst, (UniformSextInreg<i16> i32:$src0))]
299>;
300} // End isReMaterializable = 1
301
302def S_BITSET0_B32 : SOP1_32    <"s_bitset0_b32", [], 1>;
303def S_BITSET0_B64 : SOP1_64_32 <"s_bitset0_b64", [], 1>;
304def S_BITSET1_B32 : SOP1_32    <"s_bitset1_b32", [], 1>;
305def S_BITSET1_B64 : SOP1_64_32 <"s_bitset1_b64", [], 1>;
306
307def S_GETPC_B64 : SOP1_64_0  <"s_getpc_b64">;
308// PSEUDO includes a workaround for a hardware anomaly where some ASICs
309// zero-extend the result from 48 bits instead of sign-extending.
310let isReMaterializable = 1 in
311def S_GETPC_B64_pseudo : SOP1_64_0  <"s_getpc_b64",
312  [(set i64:$sdst, (int_amdgcn_s_getpc))]
313>;
314
315let isTerminator = 1, isBarrier = 1, SchedRW = [WriteBranch] in {
316
317let isBranch = 1, isIndirectBranch = 1 in {
318def S_SETPC_B64 : SOP1_1  <"s_setpc_b64">;
319} // End isBranch = 1, isIndirectBranch = 1
320
321let isReturn = 1 in {
322// Define variant marked as return rather than branch.
323def S_SETPC_B64_return : SOP1_1<"">;
324}
325} // End isTerminator = 1, isBarrier = 1
326
327let isCall = 1 in {
328def S_SWAPPC_B64 : SOP1_64 <"s_swappc_b64"
329>;
330}
331
332def S_RFE_B64 : SOP1_1  <"s_rfe_b64">;
333
334let hasSideEffects = 1, Uses = [EXEC], Defs = [EXEC, SCC] in {
335
336def S_AND_SAVEEXEC_B64 : SOP1_64 <"s_and_saveexec_b64">;
337def S_OR_SAVEEXEC_B64 : SOP1_64 <"s_or_saveexec_b64">;
338def S_XOR_SAVEEXEC_B64 : SOP1_64 <"s_xor_saveexec_b64">;
339def S_ANDN2_SAVEEXEC_B64 : SOP1_64 <"s_andn2_saveexec_b64">;
340def S_ORN2_SAVEEXEC_B64 : SOP1_64 <"s_orn2_saveexec_b64">;
341def S_NAND_SAVEEXEC_B64 : SOP1_64 <"s_nand_saveexec_b64">;
342def S_NOR_SAVEEXEC_B64 : SOP1_64 <"s_nor_saveexec_b64">;
343def S_XNOR_SAVEEXEC_B64 : SOP1_64 <"s_xnor_saveexec_b64">;
344
345} // End hasSideEffects = 1, Uses = [EXEC], Defs = [EXEC, SCC]
346
347def S_QUADMASK_B32 : SOP1_32 <"s_quadmask_b32",
348  [(set i32:$sdst, (int_amdgcn_s_quadmask i32:$src0))]>;
349def S_QUADMASK_B64 : SOP1_64 <"s_quadmask_b64",
350  [(set i64:$sdst, (int_amdgcn_s_quadmask i64:$src0))]>;
351
352let Uses = [M0] in {
353def S_MOVRELS_B32 : SOP1_32R <"s_movrels_b32">;
354def S_MOVRELS_B64 : SOP1_64R <"s_movrels_b64">;
355def S_MOVRELD_B32 : SOP1_32_movreld <"s_movreld_b32">;
356def S_MOVRELD_B64 : SOP1_64_movreld <"s_movreld_b64">;
357} // End Uses = [M0]
358
359let SubtargetPredicate = isGFX6GFX7GFX8GFX9 in {
360def S_CBRANCH_JOIN : SOP1_0_32R <"s_cbranch_join">;
361} // End SubtargetPredicate = isGFX6GFX7GFX8GFX9
362
363let Defs = [SCC] in {
364def S_ABS_I32 : SOP1_32 <"s_abs_i32",
365    [(set i32:$sdst, (UniformUnaryFrag<abs> i32:$src0))]
366  >;
367} // End Defs = [SCC]
368
369let SubtargetPredicate = HasVGPRIndexMode in {
370def S_SET_GPR_IDX_IDX : SOP1_0_32<"s_set_gpr_idx_idx"> {
371  let Uses = [M0, MODE];
372  let Defs = [M0, MODE];
373}
374}
375
376let SubtargetPredicate = isGFX9Plus in {
377  let hasSideEffects = 1, Defs = [EXEC, SCC], Uses = [EXEC] in {
378    def S_ANDN1_SAVEEXEC_B64 : SOP1_64<"s_andn1_saveexec_b64">;
379    def S_ORN1_SAVEEXEC_B64  : SOP1_64<"s_orn1_saveexec_b64">;
380    def S_ANDN1_WREXEC_B64   : SOP1_64<"s_andn1_wrexec_b64">;
381    def S_ANDN2_WREXEC_B64   : SOP1_64<"s_andn2_wrexec_b64">;
382  } // End hasSideEffects = 1, Defs = [EXEC, SCC], Uses = [EXEC]
383
384  let isReMaterializable = 1 in
385  def S_BITREPLICATE_B64_B32 : SOP1_64_32<"s_bitreplicate_b64_b32",
386  [(set i64:$sdst, (int_amdgcn_s_bitreplicate i32:$src0))]>;
387} // End SubtargetPredicate = isGFX9Plus
388
389let SubtargetPredicate = isGFX10Plus in {
390  let hasSideEffects = 1, Defs = [EXEC, SCC], Uses = [EXEC] in {
391    def S_AND_SAVEEXEC_B32   : SOP1_32<"s_and_saveexec_b32">;
392    def S_OR_SAVEEXEC_B32    : SOP1_32<"s_or_saveexec_b32">;
393    def S_XOR_SAVEEXEC_B32   : SOP1_32<"s_xor_saveexec_b32">;
394    def S_ANDN2_SAVEEXEC_B32 : SOP1_32<"s_andn2_saveexec_b32">;
395    def S_ORN2_SAVEEXEC_B32  : SOP1_32<"s_orn2_saveexec_b32">;
396    def S_NAND_SAVEEXEC_B32  : SOP1_32<"s_nand_saveexec_b32">;
397    def S_NOR_SAVEEXEC_B32   : SOP1_32<"s_nor_saveexec_b32">;
398    def S_XNOR_SAVEEXEC_B32  : SOP1_32<"s_xnor_saveexec_b32">;
399    def S_ANDN1_SAVEEXEC_B32 : SOP1_32<"s_andn1_saveexec_b32">;
400    def S_ORN1_SAVEEXEC_B32  : SOP1_32<"s_orn1_saveexec_b32">;
401    def S_ANDN1_WREXEC_B32   : SOP1_32<"s_andn1_wrexec_b32">;
402    def S_ANDN2_WREXEC_B32   : SOP1_32<"s_andn2_wrexec_b32">;
403  } // End hasSideEffects = 1, Defs = [EXEC, SCC], Uses = [EXEC]
404
405  let Uses = [M0] in {
406    def S_MOVRELSD_2_B32 : SOP1_32<"s_movrelsd_2_b32">;
407  } // End Uses = [M0]
408} // End SubtargetPredicate = isGFX10Plus
409
410let SubtargetPredicate = isGFX11Plus in {
411  let hasSideEffects = 1 in {
412    // For s_sendmsg_rtn_* the src0 field encodes the message type directly; it
413    // is not an SGPR number.
414    def S_SENDMSG_RTN_B32 : SOP1_Pseudo<
415      "s_sendmsg_rtn_b32", (outs SReg_32:$sdst), (ins SendMsg:$src0),
416      "$sdst, $src0", [(set i32:$sdst, (int_amdgcn_s_sendmsg_rtn timm:$src0))]
417    >;
418    def S_SENDMSG_RTN_B64 : SOP1_Pseudo<
419      "s_sendmsg_rtn_b64", (outs SReg_64:$sdst), (ins SendMsg:$src0),
420      "$sdst, $src0", [(set i64:$sdst, (int_amdgcn_s_sendmsg_rtn timm:$src0))]
421    >;
422  }
423} // End SubtargetPredicate = isGFX11Plus
424
425class SOP1_F32_Inst<string opName, SDPatternOperator Op, ValueType vt0=f32,
426                    ValueType vt1=vt0> :
427  SOP1_32<opName, [(set vt0:$sdst, (UniformUnaryFrag<Op> vt1:$src0))]>;
428
429let SubtargetPredicate = HasSALUFloatInsts, Uses = [MODE],
430    SchedRW = [WriteSFPU], isReMaterializable = 1 in {
431  def S_CVT_F32_I32 : SOP1_F32_Inst<"s_cvt_f32_i32", sint_to_fp, f32, i32>;
432  def S_CVT_F32_U32 : SOP1_F32_Inst<"s_cvt_f32_u32", uint_to_fp, f32, i32>;
433
434  let mayRaiseFPException = 1 in {
435    def S_CVT_I32_F32    : SOP1_F32_Inst<"s_cvt_i32_f32", fp_to_sint, i32, f32>;
436    def S_CVT_U32_F32    : SOP1_F32_Inst<"s_cvt_u32_f32", fp_to_uint, i32, f32>;
437    def S_CVT_F32_F16    : SOP1_F32_Inst<"s_cvt_f32_f16", fpextend, f32, f16>;
438    def S_CVT_HI_F32_F16 : SOP1_32<"s_cvt_hi_f32_f16">;
439
440    def S_CEIL_F32  : SOP1_F32_Inst<"s_ceil_f32", fceil>;
441    def S_FLOOR_F32 : SOP1_F32_Inst<"s_floor_f32", ffloor>;
442    def S_TRUNC_F32 : SOP1_F32_Inst<"s_trunc_f32", ftrunc>;
443    def S_RNDNE_F32 : SOP1_F32_Inst<"s_rndne_f32", froundeven>;
444
445    let FPDPRounding = 1 in
446      def S_CVT_F16_F32 : SOP1_F32_Inst<"s_cvt_f16_f32", fpround, f16, f32>;
447
448    def S_CEIL_F16  : SOP1_F32_Inst<"s_ceil_f16", fceil, f16>;
449    def S_FLOOR_F16 : SOP1_F32_Inst<"s_floor_f16", ffloor, f16>;
450    def S_TRUNC_F16 : SOP1_F32_Inst<"s_trunc_f16", ftrunc, f16>;
451    def S_RNDNE_F16 : SOP1_F32_Inst<"s_rndne_f16", froundeven, f16>;
452  } // End mayRaiseFPException = 1
453} // End SubtargetPredicate = HasSALUFloatInsts, Uses = [MODE]
454  // SchedRW = [WriteSFPU], isReMaterializable = 1
455
456let hasSideEffects = 1 in {
457let has_sdst = 0 in {
458let Uses = [M0] in {
459def S_BARRIER_SIGNAL_M0 : SOP1_Pseudo <"s_barrier_signal m0", (outs), (ins),
460  "", [(int_amdgcn_s_barrier_signal_var M0)]>{
461  let SchedRW = [WriteBarrier];
462  let isConvergent = 1;
463}
464
465def S_BARRIER_SIGNAL_ISFIRST_M0 : SOP1_Pseudo <"s_barrier_signal_isfirst m0", (outs), (ins),
466  "", [(set SCC, (int_amdgcn_s_barrier_signal_isfirst_var M0))]>{
467  let Defs = [SCC];
468  let SchedRW = [WriteBarrier];
469  let isConvergent = 1;
470}
471
472def S_BARRIER_INIT_M0 : SOP1_Pseudo <"s_barrier_init m0", (outs), (ins),
473  "", []>{
474  let SchedRW = [WriteBarrier];
475  let isConvergent = 1;
476}
477
478def S_BARRIER_INIT_IMM : SOP1_Pseudo <"s_barrier_init", (outs),
479  (ins SplitBarrier:$src0), "$src0", []>{
480  let SchedRW = [WriteBarrier];
481  let isConvergent = 1;
482}
483
484def S_BARRIER_JOIN_M0 : SOP1_Pseudo <"s_barrier_join m0", (outs), (ins),
485  "", []>{
486  let SchedRW = [WriteBarrier];
487  let isConvergent = 1;
488}
489
490def S_WAKEUP_BARRIER_M0 : SOP1_Pseudo <"s_wakeup_barrier m0", (outs), (ins),
491  "", []>{
492  let SchedRW = [WriteBarrier];
493  let isConvergent = 1;
494}
495} // End Uses = [M0]
496
497def S_BARRIER_SIGNAL_IMM : SOP1_Pseudo <"s_barrier_signal", (outs),
498  (ins SplitBarrier:$src0), "$src0", [(int_amdgcn_s_barrier_signal timm:$src0)]>{
499  let SchedRW = [WriteBarrier];
500  let isConvergent = 1;
501}
502
503def S_BARRIER_SIGNAL_ISFIRST_IMM : SOP1_Pseudo <"s_barrier_signal_isfirst", (outs),
504  (ins SplitBarrier:$src0), "$src0", [(set SCC, (int_amdgcn_s_barrier_signal_isfirst timm:$src0))]>{
505  let Defs = [SCC];
506  let SchedRW = [WriteBarrier];
507  let isConvergent = 1;
508}
509
510def S_BARRIER_JOIN_IMM : SOP1_Pseudo <"s_barrier_join", (outs),
511  (ins SplitBarrier:$src0), "$src0", []>{
512  let SchedRW = [WriteBarrier];
513  let isConvergent = 1;
514}
515
516def S_WAKEUP_BARRIER_IMM : SOP1_Pseudo <"s_wakeup_barrier", (outs),
517  (ins SplitBarrier:$src0), "$src0", []>{
518  let SchedRW = [WriteBarrier];
519  let isConvergent = 1;
520}
521} // End has_sdst = 0
522
523def S_GET_BARRIER_STATE_IMM : SOP1_Pseudo <"s_get_barrier_state", (outs SSrc_b32:$sdst),
524  (ins SplitBarrier:$src0), "$sdst, $src0", []>{
525  let SchedRW = [WriteBarrier];
526  let isConvergent = 1;
527}
528
529def S_GET_BARRIER_STATE_M0 : SOP1_Pseudo <"s_get_barrier_state $sdst, m0", (outs SSrc_b32:$sdst),
530  (ins), "", []>{
531  let Uses = [M0];
532  let SchedRW = [WriteBarrier];
533  let isConvergent = 1;
534}
535} // End hasSideEffects = 1
536
537//===----------------------------------------------------------------------===//
538// SOP2 Instructions
539//===----------------------------------------------------------------------===//
540
541class SOP2_Pseudo<string opName, dag outs, dag ins,
542                  string asmOps, list<dag> pattern=[]> :
543  SOP_Pseudo<opName, outs, ins, " " # asmOps, pattern> {
544
545  let mayLoad = 0;
546  let mayStore = 0;
547  let hasSideEffects = 0;
548  let SALU = 1;
549  let SOP2 = 1;
550  let SchedRW = [WriteSALU];
551  let UseNamedOperandTable = 1;
552
553  let has_sdst = 1;
554
555  // Pseudo instructions have no encodings, but adding this field here allows
556  // us to do:
557  // let sdst = xxx in {
558  // for multiclasses that include both real and pseudo instructions.
559  // field bits<7> sdst = 0;
560}
561
562class SOP2_Real<SOP_Pseudo ps, string name = ps.Mnemonic> :
563  InstSI <ps.OutOperandList, ps.InOperandList,
564          name # ps.AsmOperands> {
565  let SALU = 1;
566  let SOP2 = 1;
567  let isPseudo = 0;
568  let isCodeGenOnly = 0;
569
570  // copy relevant pseudo op flags
571  let SubtargetPredicate   = ps.SubtargetPredicate;
572  let AsmMatchConverter    = ps.AsmMatchConverter;
573  let UseNamedOperandTable = ps.UseNamedOperandTable;
574  let TSFlags              = ps.TSFlags;
575  let SchedRW              = ps.SchedRW;
576  let mayLoad              = ps.mayLoad;
577  let mayStore             = ps.mayStore;
578  let Constraints          = ps.Constraints;
579  let DisableEncoding      = ps.DisableEncoding;
580  let Uses                 = ps.Uses;
581  let Defs                 = ps.Defs;
582
583  // encoding
584  bits<7> sdst;
585  bits<8> src0;
586  bits<8> src1;
587  bits<32> imm;
588}
589
590class SOP2_Real32<bits<7> op, SOP_Pseudo ps, string name = ps.Mnemonic> :
591  SOP2_Real<ps, name>, Enc32 {
592  let Inst{7-0}   = src0;
593  let Inst{15-8}  = src1;
594  let Inst{22-16} = !if(ps.has_sdst, sdst, ?);
595  let Inst{29-23} = op;
596  let Inst{31-30} = 0x2; // encoding
597}
598
599class SOP2_Real64<bits<7> op, SOP_Pseudo ps, string name = ps.Mnemonic> :
600  SOP2_Real<ps, name>, Enc64 {
601  let Inst{7-0}   = src0;
602  let Inst{15-8}  = src1;
603  let Inst{22-16} = !if(ps.has_sdst, sdst, ?);
604  let Inst{29-23} = op;
605  let Inst{31-30} = 0x2; // encoding
606  let Inst{63-32} = imm;
607}
608
609class SOP2_F16 <string opName, list<dag> pattern=[]> : SOP2_Pseudo <
610  opName, (outs SReg_32:$sdst), (ins SSrc_f16:$src0, SSrc_f16:$src1),
611  "$sdst, $src0, $src1", pattern
612>;
613
614class SOP2_32 <string opName, list<dag> pattern=[]> : SOP2_Pseudo <
615  opName, (outs SReg_32:$sdst), (ins SSrc_b32:$src0, SSrc_b32:$src1),
616  "$sdst, $src0, $src1", pattern
617>;
618
619class SOP2_F32 <string opName, list<dag> pattern=[]> : SOP2_Pseudo <
620  opName, (outs SReg_32:$sdst), (ins SSrc_f32:$src0, SSrc_f32:$src1),
621  "$sdst, $src0, $src1", pattern
622>;
623
624class SOP2_64 <string opName, list<dag> pattern=[]> : SOP2_Pseudo <
625  opName, (outs SReg_64:$sdst), (ins SSrc_b64:$src0, SSrc_b64:$src1),
626  "$sdst, $src0, $src1", pattern
627>;
628
629class SOP2_64_32 <string opName, list<dag> pattern=[]> : SOP2_Pseudo <
630  opName, (outs SReg_64:$sdst), (ins SSrc_b64:$src0, SSrc_b32:$src1),
631  "$sdst, $src0, $src1", pattern
632>;
633
634class SOP2_64_32_32 <string opName, list<dag> pattern=[]> : SOP2_Pseudo <
635  opName, (outs SReg_64:$sdst), (ins SSrc_b32:$src0, SSrc_b32:$src1),
636  "$sdst, $src0, $src1", pattern
637>;
638
639
640let Defs = [SCC] in { // Carry out goes to SCC
641let isCommutable = 1 in {
642def S_ADD_U32 : SOP2_32 <"s_add_u32">;
643def S_ADD_I32 : SOP2_32 <"s_add_i32",
644  [(set i32:$sdst, (UniformBinFrag<add> SSrc_b32:$src0, SSrc_b32:$src1))]
645>;
646} // End isCommutable = 1
647
648def S_SUB_U32 : SOP2_32 <"s_sub_u32">;
649def S_SUB_I32 : SOP2_32 <"s_sub_i32",
650  [(set i32:$sdst, (UniformBinFrag<sub> SSrc_b32:$src0, SSrc_b32:$src1))]
651>;
652
653let Uses = [SCC] in { // Carry in comes from SCC
654let isCommutable = 1 in {
655def S_ADDC_U32 : SOP2_32 <"s_addc_u32",
656  [(set i32:$sdst, (UniformBinFrag<adde> (i32 SSrc_b32:$src0), (i32 SSrc_b32:$src1)))]>;
657} // End isCommutable = 1
658
659def S_SUBB_U32 : SOP2_32 <"s_subb_u32",
660  [(set i32:$sdst, (UniformBinFrag<sube> (i32 SSrc_b32:$src0), (i32 SSrc_b32:$src1)))]>;
661} // End Uses = [SCC]
662
663let isCommutable = 1 in {
664def S_MIN_I32 : SOP2_32 <"s_min_i32",
665  [(set i32:$sdst, (UniformBinFrag<smin> i32:$src0, i32:$src1))]
666>;
667def S_MIN_U32 : SOP2_32 <"s_min_u32",
668  [(set i32:$sdst, (UniformBinFrag<umin> i32:$src0, i32:$src1))]
669>;
670def S_MAX_I32 : SOP2_32 <"s_max_i32",
671  [(set i32:$sdst, (UniformBinFrag<smax> i32:$src0, i32:$src1))]
672>;
673def S_MAX_U32 : SOP2_32 <"s_max_u32",
674  [(set i32:$sdst, (UniformBinFrag<umax> i32:$src0, i32:$src1))]
675>;
676} // End isCommutable = 1
677} // End Defs = [SCC]
678
679let SubtargetPredicate = isGFX12Plus in {
680  def S_ADD_U64 : SOP2_64<"s_add_u64">{
681    let isCommutable = 1;
682  }
683
684  def S_SUB_U64 : SOP2_64<"s_sub_u64">;
685
686  def S_MUL_U64 : SOP2_64 <"s_mul_u64",
687    [(set i64:$sdst, (UniformBinFrag<mul> i64:$src0, i64:$src1))]> {
688    let isCommutable = 1;
689  }
690
691  // The higher 32-bits of the inputs contain the sign extension bits.
692  def S_MUL_I64_I32_PSEUDO : SPseudoInstSI <
693    (outs SReg_64:$sdst), (ins SSrc_b64:$src0, SSrc_b64:$src1)
694  >;
695
696  // The higher 32-bits of the inputs are zero.
697  def S_MUL_U64_U32_PSEUDO : SPseudoInstSI <
698    (outs SReg_64:$sdst), (ins SSrc_b64:$src0, SSrc_b64:$src1)
699  >;
700
701} // End SubtargetPredicate = isGFX12Plus
702
703let Uses = [SCC] in {
704  def S_CSELECT_B32 : SOP2_32 <"s_cselect_b32">;
705  def S_CSELECT_B64 : SOP2_64 <"s_cselect_b64">;
706} // End Uses = [SCC]
707
708let Defs = [SCC] in {
709let isCommutable = 1 in {
710def S_AND_B32 : SOP2_32 <"s_and_b32",
711  [(set i32:$sdst, (UniformBinFrag<and> i32:$src0, i32:$src1))]
712>;
713
714def S_AND_B64 : SOP2_64 <"s_and_b64",
715  [(set i64:$sdst, (UniformBinFrag<and> i64:$src0, i64:$src1))]
716>;
717
718def S_OR_B32 : SOP2_32 <"s_or_b32",
719  [(set i32:$sdst, (UniformBinFrag<or> i32:$src0, i32:$src1))]
720>;
721
722def S_OR_B64 : SOP2_64 <"s_or_b64",
723  [(set i64:$sdst, (UniformBinFrag<or> i64:$src0, i64:$src1))]
724>;
725
726def S_XOR_B32 : SOP2_32 <"s_xor_b32",
727  [(set i32:$sdst, (UniformBinFrag<xor> i32:$src0, i32:$src1))]
728>;
729
730def S_XOR_B64 : SOP2_64 <"s_xor_b64",
731  [(set i64:$sdst, (UniformBinFrag<xor> i64:$src0, i64:$src1))]
732>;
733
734def S_XNOR_B32 : SOP2_32 <"s_xnor_b32",
735  [(set i32:$sdst, (UniformUnaryFrag<not> (xor_oneuse i32:$src0, i32:$src1)))]
736>;
737
738def S_XNOR_B64 : SOP2_64 <"s_xnor_b64",
739  [(set i64:$sdst, (UniformUnaryFrag<not> (xor_oneuse i64:$src0, i64:$src1)))]
740>;
741
742def S_NAND_B32 : SOP2_32 <"s_nand_b32",
743  [(set i32:$sdst, (UniformUnaryFrag<not> (and_oneuse i32:$src0, i32:$src1)))]
744>;
745
746def S_NAND_B64 : SOP2_64 <"s_nand_b64",
747  [(set i64:$sdst, (UniformUnaryFrag<not> (and_oneuse i64:$src0, i64:$src1)))]
748>;
749
750def S_NOR_B32 : SOP2_32 <"s_nor_b32",
751  [(set i32:$sdst, (UniformUnaryFrag<not> (or_oneuse i32:$src0, i32:$src1)))]
752>;
753
754def S_NOR_B64 : SOP2_64 <"s_nor_b64",
755  [(set i64:$sdst, (UniformUnaryFrag<not> (or_oneuse i64:$src0, i64:$src1)))]
756>;
757} // End isCommutable = 1
758
759// There are also separate patterns for types other than i32
760def S_ANDN2_B32 : SOP2_32 <"s_andn2_b32",
761  [(set i32:$sdst, (UniformBinFrag<and> i32:$src0, (not i32:$src1)))]
762>;
763
764def S_ANDN2_B64 : SOP2_64 <"s_andn2_b64",
765  [(set i64:$sdst, (UniformBinFrag<and> i64:$src0, (not i64:$src1)))]
766>;
767
768def S_ORN2_B32 : SOP2_32 <"s_orn2_b32",
769  [(set i32:$sdst, (UniformBinFrag<or> i32:$src0, (not i32:$src1)))]
770>;
771
772def S_ORN2_B64 : SOP2_64 <"s_orn2_b64",
773  [(set i64:$sdst, (UniformBinFrag<or> i64:$src0, (not i64:$src1)))]
774>;
775} // End Defs = [SCC]
776
777// Use added complexity so these patterns are preferred to the VALU patterns.
778let AddedComplexity = 1 in {
779
780let Defs = [SCC] in {
781// TODO: b64 versions require VOP3 change since v_lshlrev_b64 is VOP3
782def S_LSHL_B32 : SOP2_32 <"s_lshl_b32",
783  [(set SReg_32:$sdst, (UniformBinFrag<cshl_32> (i32 SSrc_b32:$src0), (i32 SSrc_b32:$src1)))]
784>;
785def S_LSHL_B64 : SOP2_64_32 <"s_lshl_b64",
786  [(set SReg_64:$sdst, (UniformBinFrag<cshl_64> (i64 SSrc_b64:$src0), (i32 SSrc_b32:$src1)))]
787>;
788def S_LSHR_B32 : SOP2_32 <"s_lshr_b32",
789  [(set SReg_32:$sdst, (UniformBinFrag<csrl_32> (i32 SSrc_b32:$src0), (i32 SSrc_b32:$src1)))]
790>;
791def S_LSHR_B64 : SOP2_64_32 <"s_lshr_b64",
792  [(set SReg_64:$sdst, (UniformBinFrag<csrl_64> (i64 SSrc_b64:$src0), (i32 SSrc_b32:$src1)))]
793>;
794def S_ASHR_I32 : SOP2_32 <"s_ashr_i32",
795  [(set SReg_32:$sdst, (UniformBinFrag<csra_32> (i32 SSrc_b32:$src0), (i32 SSrc_b32:$src1)))]
796>;
797def S_ASHR_I64 : SOP2_64_32 <"s_ashr_i64",
798  [(set SReg_64:$sdst, (UniformBinFrag<csra_64> (i64 SSrc_b64:$src0), (i32 SSrc_b32:$src1)))]
799>;
800} // End Defs = [SCC]
801
802let isReMaterializable = 1 in {
803def S_BFM_B32 : SOP2_32 <"s_bfm_b32",
804  [(set i32:$sdst, (UniformBinFrag<AMDGPUbfm> i32:$src0, i32:$src1))]>;
805def S_BFM_B64 : SOP2_64_32_32 <"s_bfm_b64">;
806
807def S_MUL_I32 : SOP2_32 <"s_mul_i32",
808  [(set i32:$sdst, (UniformBinFrag<mul> i32:$src0, i32:$src1))]> {
809  let isCommutable = 1;
810}
811} // End isReMaterializable = 1
812} // End AddedComplexity = 1
813
814let Defs = [SCC] in {
815def S_BFE_U32 : SOP2_32 <"s_bfe_u32">;
816def S_BFE_I32 : SOP2_32 <"s_bfe_i32">;
817def S_BFE_U64 : SOP2_64_32 <"s_bfe_u64">;
818def S_BFE_I64 : SOP2_64_32 <"s_bfe_i64">;
819} // End Defs = [SCC]
820
821def S_CBRANCH_G_FORK : SOP2_Pseudo <
822  "s_cbranch_g_fork", (outs),
823  (ins SCSrc_b64:$src0, SCSrc_b64:$src1),
824  "$src0, $src1"
825> {
826  let has_sdst = 0;
827  let SubtargetPredicate = isGFX6GFX7GFX8GFX9;
828}
829
830let Defs = [SCC] in {
831def S_ABSDIFF_I32 : SOP2_32 <"s_absdiff_i32">;
832} // End Defs = [SCC]
833
834let SubtargetPredicate = isGFX8GFX9 in {
835  def S_RFE_RESTORE_B64 : SOP2_Pseudo <
836    "s_rfe_restore_b64", (outs),
837    (ins SSrc_b64:$src0, SSrc_b32:$src1),
838    "$src0, $src1"
839  > {
840    let hasSideEffects = 1;
841    let has_sdst = 0;
842  }
843}
844
845let SubtargetPredicate = isGFX9Plus in {
846  let isReMaterializable = 1 in {
847    def S_PACK_LL_B32_B16 : SOP2_32<"s_pack_ll_b32_b16">;
848    def S_PACK_LH_B32_B16 : SOP2_32<"s_pack_lh_b32_b16">;
849    def S_PACK_HH_B32_B16 : SOP2_32<"s_pack_hh_b32_b16">;
850  } // End isReMaterializable = 1
851
852  let Defs = [SCC] in {
853    def S_LSHL1_ADD_U32 : SOP2_32<"s_lshl1_add_u32",
854      [(set i32:$sdst, (shl1_add SSrc_b32:$src0, SSrc_b32:$src1))]
855    >;
856    def S_LSHL2_ADD_U32 : SOP2_32<"s_lshl2_add_u32",
857      [(set i32:$sdst, (shl2_add SSrc_b32:$src0, SSrc_b32:$src1))]
858    >;
859    def S_LSHL3_ADD_U32 : SOP2_32<"s_lshl3_add_u32",
860      [(set i32:$sdst, (shl3_add SSrc_b32:$src0, SSrc_b32:$src1))]
861    >;
862    def S_LSHL4_ADD_U32 : SOP2_32<"s_lshl4_add_u32",
863      [(set i32:$sdst, (shl4_add SSrc_b32:$src0, SSrc_b32:$src1))]
864    >;
865  } // End Defs = [SCC]
866
867  let isCommutable = 1, isReMaterializable = 1 in {
868    def S_MUL_HI_U32 : SOP2_32<"s_mul_hi_u32",
869      [(set i32:$sdst, (UniformBinFrag<mulhu> SSrc_b32:$src0, SSrc_b32:$src1))]>;
870    def S_MUL_HI_I32 : SOP2_32<"s_mul_hi_i32",
871      [(set i32:$sdst, (UniformBinFrag<mulhs> SSrc_b32:$src0, SSrc_b32:$src1))]>;
872  } // End isCommutable = 1, isReMaterializable = 1
873} // End SubtargetPredicate = isGFX9Plus
874
875let SubtargetPredicate = isGFX11Plus in {
876  def S_PACK_HL_B32_B16 : SOP2_32<"s_pack_hl_b32_b16">;
877} // End SubtargetPredicate = isGFX11Plus
878
879class SOP2_F32_Inst<string opName, SDPatternOperator Op, ValueType dstVt=f32> :
880  SOP2_F32<opName,
881    [(set dstVt:$sdst, (UniformBinFrag<Op> SSrc_f32:$src0, SSrc_f32:$src1))]>;
882
883class SOP2_F16_Inst<string opName, SDPatternOperator Op> :
884  SOP2_F16<opName,
885    [(set f16:$sdst, (UniformBinFrag<Op> SSrc_f16:$src0, SSrc_f16:$src1))]>;
886
887let SubtargetPredicate = HasSALUFloatInsts, mayRaiseFPException = 1,
888    Uses = [MODE], SchedRW = [WriteSFPU] in {
889  let isReMaterializable = 1 in {
890    let isCommutable = 1 in {
891      def S_ADD_F32 : SOP2_F32_Inst<"s_add_f32", any_fadd>;
892      def S_MIN_F32 : SOP2_F32_Inst<"s_min_f32", fminnum_like>;
893      def S_MAX_F32 : SOP2_F32_Inst<"s_max_f32", fmaxnum_like>;
894      def S_MUL_F32 : SOP2_F32_Inst<"s_mul_f32", any_fmul>;
895
896      let FixedSize = 1 in
897      def S_FMAAK_F32 : SOP2_Pseudo<
898        "s_fmaak_f32", (outs SReg_32:$sdst),
899        (ins SSrc_f32_Deferred:$src0, SSrc_f32_Deferred:$src1, KImmFP32:$imm),
900        "$sdst, $src0, $src1, $imm"
901      >;
902
903      let FPDPRounding = 1 in {
904        def S_ADD_F16 : SOP2_F16_Inst<"s_add_f16", any_fadd>;
905        def S_MUL_F16 : SOP2_F16_Inst<"s_mul_f16", any_fmul>;
906      } // End FPDPRounding
907
908      def S_MIN_F16 : SOP2_F16_Inst<"s_min_f16", fminnum_like>;
909      def S_MAX_F16 : SOP2_F16_Inst<"s_max_f16", fmaxnum_like>;
910    } // End isCommutable = 1
911
912    let FPDPRounding = 1 in
913      def S_SUB_F16 : SOP2_F16_Inst<"s_sub_f16", any_fsub>;
914
915    def S_SUB_F32            : SOP2_F32_Inst<"s_sub_f32", any_fsub>;
916    def S_CVT_PK_RTZ_F16_F32 : SOP2_F32_Inst<"s_cvt_pk_rtz_f16_f32",
917                                             AMDGPUpkrtz_f16_f32, v2f16>;
918
919    let FixedSize = 1 in
920    def S_FMAMK_F32 : SOP2_Pseudo<
921      "s_fmamk_f32", (outs SReg_32:$sdst),
922      (ins SSrc_f32_Deferred:$src0, KImmFP32:$imm, SSrc_f32_Deferred:$src1),
923      "$sdst, $src0, $imm, $src1"
924    >;
925  } // End isReMaterializable = 1
926
927  let Constraints = "$sdst = $src2", DisableEncoding="$src2",
928      isCommutable = 1, AddedComplexity = 20 in {
929    def S_FMAC_F32 : SOP2_Pseudo<
930      "s_fmac_f32", (outs SReg_32:$sdst),
931      (ins SSrc_f32:$src0, SSrc_f32:$src1, SReg_32:$src2),
932      "$sdst, $src0, $src1",
933      [(set f32:$sdst, (UniformTernaryFrag<any_fma> SSrc_f32:$src0, SSrc_f32:$src1, SReg_32:$src2))]
934    >;
935
936    def S_FMAC_F16 : SOP2_Pseudo<
937      "s_fmac_f16", (outs SReg_32:$sdst),
938      (ins SSrc_f16:$src0, SSrc_f16:$src1, SReg_32:$src2),
939      "$sdst, $src0, $src1",
940      [(set f16:$sdst, (UniformTernaryFrag<any_fma> SSrc_f16:$src0, SSrc_f16:$src1, SReg_32:$src2))]
941    >;
942  } // End Constraints = "$sdst = $src2", DisableEncoding="$src2",
943    // isCommutable = 1, AddedComplexity = 20
944} // End SubtargetPredicate = HasSALUFloatInsts, mayRaiseFPException = 1,
945  // Uses = [MODE], SchedRW = [WriteSFPU]
946
947// On GFX12 MIN/MAX instructions do not read MODE register.
948let SubtargetPredicate = isGFX12Plus, mayRaiseFPException = 1, isCommutable = 1,
949    isReMaterializable = 1, SchedRW = [WriteSFPU] in {
950  def S_MINIMUM_F32 : SOP2_F32_Inst<"s_minimum_f32", fminimum>;
951  def S_MAXIMUM_F32 : SOP2_F32_Inst<"s_maximum_f32", fmaximum>;
952  def S_MINIMUM_F16 : SOP2_F16_Inst<"s_minimum_f16", fminimum>;
953  def S_MAXIMUM_F16 : SOP2_F16_Inst<"s_maximum_f16", fmaximum>;
954}
955
956//===----------------------------------------------------------------------===//
957// SOPK Instructions
958//===----------------------------------------------------------------------===//
959
960class SOPK_Pseudo <string opName, dag outs, dag ins,
961                   string asmOps, list<dag> pattern=[]> :
962  SOP_Pseudo<opName, outs, ins, " " # asmOps, pattern> {
963  let mayLoad = 0;
964  let mayStore = 0;
965  let hasSideEffects = 0;
966  let SALU = 1;
967  let SOPK = 1;
968  let FixedSize = 1;
969  let SchedRW = [WriteSALU];
970  let UseNamedOperandTable = 1;
971
972  let has_sdst = 1;
973}
974
975class SOPK_Real<SOPK_Pseudo ps, string name = ps.Mnemonic> :
976  InstSI <ps.OutOperandList, ps.InOperandList,
977          name # ps.AsmOperands> {
978  let SALU = 1;
979  let SOPK = 1;
980  let isPseudo = 0;
981  let isCodeGenOnly = 0;
982  let UseNamedOperandTable = 1;
983
984  // copy relevant pseudo op flags
985  let SubtargetPredicate = ps.SubtargetPredicate;
986  let AsmMatchConverter  = ps.AsmMatchConverter;
987  let DisableEncoding    = ps.DisableEncoding;
988  let Constraints        = ps.Constraints;
989  let SchedRW            = ps.SchedRW;
990  let mayLoad            = ps.mayLoad;
991  let mayStore           = ps.mayStore;
992  let isBranch           = ps.isBranch;
993  let isCall             = ps.isCall;
994  let isTerminator       = ps.isTerminator;
995  let isReturn           = ps.isReturn;
996  let isBarrier          = ps.isBarrier;
997  let Uses               = ps.Uses;
998  let Defs               = ps.Defs;
999
1000  // encoding
1001  bits<7>  sdst;
1002  bits<16> simm16;
1003  bits<32> imm;
1004}
1005
1006class SOPK_Real32<bits<5> op, SOPK_Pseudo ps, string name = ps.Mnemonic> :
1007  SOPK_Real <ps, name>,
1008  Enc32 {
1009  let Inst{15-0}  = simm16;
1010  let Inst{22-16} = !if(ps.has_sdst, sdst, ?);
1011  let Inst{27-23} = op;
1012  let Inst{31-28} = 0xb; //encoding
1013}
1014
1015class SOPK_Real64<bits<5> op, SOPK_Pseudo ps> :
1016  SOPK_Real<ps>,
1017  Enc64 {
1018  let Inst{15-0}  = simm16;
1019  let Inst{22-16} = !if(ps.has_sdst, sdst, ?);
1020  let Inst{27-23} = op;
1021  let Inst{31-28} = 0xb; //encoding
1022  let Inst{63-32} = imm;
1023}
1024
1025class SOPKInstTable <bit is_sopk, string cmpOp = ""> {
1026  bit IsSOPK = is_sopk;
1027  string BaseCmpOp = cmpOp;
1028}
1029
1030class SOPK_32 <string opName, list<dag> pattern=[]> : SOPK_Pseudo <
1031  opName,
1032  (outs SReg_32:$sdst),
1033  (ins s16imm:$simm16),
1034  "$sdst, $simm16",
1035  pattern>;
1036
1037class SOPK_32_BR <string opName, list<dag> pattern=[]> : SOPK_Pseudo <
1038  opName,
1039  (outs),
1040  (ins SOPPBrTarget:$simm16, SReg_32:$sdst),
1041  "$sdst, $simm16",
1042  pattern> {
1043  let Defs = [EXEC];
1044  let Uses = [EXEC];
1045  let isBranch = 1;
1046  let isTerminator = 1;
1047  let SchedRW = [WriteBranch];
1048}
1049
1050class SOPK_SCC <string opName, string base_op, bit isSignExt> : SOPK_Pseudo <
1051  opName,
1052  (outs),
1053  !if(isSignExt,
1054      (ins SReg_32:$sdst, s16imm:$simm16),
1055      (ins SReg_32:$sdst, u16imm:$simm16)),
1056  "$sdst, $simm16">,
1057  SOPKInstTable<1, base_op>{
1058  let Defs = [SCC];
1059}
1060
1061class SOPK_32TIE <string opName, list<dag> pattern=[]> : SOPK_Pseudo <
1062  opName,
1063  (outs SReg_32:$sdst),
1064  (ins SReg_32:$src0, s16imm:$simm16),
1065  "$sdst, $simm16",
1066  pattern
1067>;
1068
1069let isReMaterializable = 1, isMoveImm = 1 in {
1070def S_MOVK_I32 : SOPK_32 <"s_movk_i32">;
1071} // End isReMaterializable = 1
1072let Uses = [SCC] in {
1073def S_CMOVK_I32 : SOPK_32 <"s_cmovk_i32">;
1074}
1075
1076let isCompare = 1 in {
1077
1078// This instruction is disabled for now until we can figure out how to teach
1079// the instruction selector to correctly use the  S_CMP* vs V_CMP*
1080// instructions.
1081//
1082// When this instruction is enabled the code generator sometimes produces this
1083// invalid sequence:
1084//
1085// SCC = S_CMPK_EQ_I32 SGPR0, imm
1086// VCC = COPY SCC
1087// VGPR0 = V_CNDMASK VCC, VGPR0, VGPR1
1088//
1089// def S_CMPK_EQ_I32 : SOPK_SCC <"s_cmpk_eq_i32",
1090//   [(set i1:$dst, (setcc i32:$src0, imm:$src1, SETEQ))]
1091// >;
1092
1093def S_CMPK_EQ_I32 : SOPK_SCC <"s_cmpk_eq_i32", "s_cmp_eq_i32", 1>;
1094def S_CMPK_LG_I32 : SOPK_SCC <"s_cmpk_lg_i32", "s_cmp_lg_i32", 1>;
1095def S_CMPK_GT_I32 : SOPK_SCC <"s_cmpk_gt_i32", "s_cmp_gt_i32", 1>;
1096def S_CMPK_GE_I32 : SOPK_SCC <"s_cmpk_ge_i32", "s_cmp_ge_i32", 1>;
1097def S_CMPK_LT_I32 : SOPK_SCC <"s_cmpk_lt_i32", "s_cmp_lt_i32", 1>;
1098def S_CMPK_LE_I32 : SOPK_SCC <"s_cmpk_le_i32", "s_cmp_le_i32", 1>;
1099
1100def S_CMPK_EQ_U32 : SOPK_SCC <"s_cmpk_eq_u32", "s_cmp_eq_u32", 0>;
1101def S_CMPK_LG_U32 : SOPK_SCC <"s_cmpk_lg_u32", "s_cmp_lg_u32", 0>;
1102def S_CMPK_GT_U32 : SOPK_SCC <"s_cmpk_gt_u32", "s_cmp_gt_u32", 0>;
1103def S_CMPK_GE_U32 : SOPK_SCC <"s_cmpk_ge_u32", "s_cmp_ge_u32", 0>;
1104def S_CMPK_LT_U32 : SOPK_SCC <"s_cmpk_lt_u32", "s_cmp_lt_u32", 0>;
1105def S_CMPK_LE_U32 : SOPK_SCC <"s_cmpk_le_u32", "s_cmp_le_u32", 0>;
1106} // End isCompare = 1
1107
1108let isCommutable = 1, DisableEncoding = "$src0",
1109    Constraints = "$sdst = $src0" in {
1110  let Defs = [SCC] in
1111    def S_ADDK_I32 : SOPK_32TIE <"s_addk_i32">;
1112  def S_MULK_I32 : SOPK_32TIE <"s_mulk_i32">;
1113}
1114
1115let SubtargetPredicate = isGFX6GFX7GFX8GFX9 in
1116def S_CBRANCH_I_FORK : SOPK_Pseudo <
1117  "s_cbranch_i_fork",
1118  (outs), (ins SReg_64:$sdst, SOPPBrTarget:$simm16),
1119  "$sdst, $simm16"
1120>;
1121
1122// This is hasSideEffects to allow its use in readcyclecounter selection.
1123// FIXME: Need to truncate immediate to 16-bits.
1124// FIXME: Should have separate pseudos for known may read MODE and
1125// only read MODE.
1126def S_GETREG_B32 : SOPK_Pseudo <
1127  "s_getreg_b32",
1128  (outs SReg_32:$sdst), (ins hwreg:$simm16),
1129  "$sdst, $simm16",
1130  [(set i32:$sdst, (int_amdgcn_s_getreg (i32 timm:$simm16)))]> {
1131  let hasSideEffects = 1;
1132  let Uses = [MODE];
1133}
1134
1135let Defs = [MODE], Uses = [MODE] in {
1136
1137// FIXME: Need to truncate immediate to 16-bits.
1138class S_SETREG_B32_Pseudo <list<dag> pattern=[]> : SOPK_Pseudo <
1139  "s_setreg_b32",
1140  (outs), (ins SReg_32:$sdst, hwreg:$simm16),
1141  "$simm16, $sdst",
1142  pattern>;
1143
1144def S_SETREG_B32 : S_SETREG_B32_Pseudo <
1145  [(int_amdgcn_s_setreg (i32 SIMM16bit:$simm16), i32:$sdst)]> {
1146  // Use custom inserter to optimize some cases to
1147  // S_DENORM_MODE/S_ROUND_MODE/S_SETREG_B32_mode.
1148  let usesCustomInserter = 1;
1149  let hasSideEffects = 1;
1150}
1151
1152// Variant of SETREG that is guaranteed to only touch FP bits in the MODE
1153// register, so doesn't have unmodeled side effects.
1154def S_SETREG_B32_mode : S_SETREG_B32_Pseudo {
1155  let hasSideEffects = 0;
1156}
1157
1158// FIXME: Not on SI?
1159//def S_GETREG_REGRD_B32 : SOPK_32 <sopk<0x14, 0x13>, "s_getreg_regrd_b32">;
1160
1161class S_SETREG_IMM32_B32_Pseudo : SOPK_Pseudo <
1162  "s_setreg_imm32_b32",
1163  (outs), (ins i32imm:$imm, hwreg:$simm16),
1164  "$simm16, $imm"> {
1165  let Size = 8; // Unlike every other SOPK instruction.
1166  let has_sdst = 0;
1167}
1168
1169def S_SETREG_IMM32_B32 : S_SETREG_IMM32_B32_Pseudo {
1170  let hasSideEffects = 1;
1171}
1172
1173// Variant of SETREG_IMM32 that is guaranteed to only touch FP bits in the MODE
1174// register, so doesn't have unmodeled side effects.
1175def S_SETREG_IMM32_B32_mode : S_SETREG_IMM32_B32_Pseudo {
1176  let hasSideEffects = 0;
1177}
1178
1179} // End Defs = [MODE], Uses = [MODE]
1180
1181class SOPK_WAITCNT<string opName, list<dag> pat=[]> :
1182    SOPK_Pseudo<
1183        opName,
1184        (outs),
1185        (ins SReg_32:$sdst, s16imm:$simm16),
1186        "$sdst, $simm16",
1187        pat> {
1188  let hasSideEffects = 1;
1189  let mayLoad = 1;
1190  let mayStore = 1;
1191  let has_sdst = 1; // First source takes place of sdst in encoding
1192}
1193
1194let SubtargetPredicate = isGFX9Plus in {
1195  def S_CALL_B64 : SOPK_Pseudo<
1196      "s_call_b64",
1197      (outs SReg_64:$sdst),
1198      (ins SOPPBrTarget:$simm16),
1199      "$sdst, $simm16"> {
1200    let isCall = 1;
1201  }
1202} // End SubtargetPredicate = isGFX9Plus
1203
1204def VersionImm : S16ImmOperand {
1205  let DecoderMethod = "decodeVersionImm";
1206}
1207
1208let SubtargetPredicate = isGFX10Plus in {
1209  def S_VERSION : SOPK_Pseudo<
1210      "s_version",
1211      (outs),
1212      (ins VersionImm:$simm16),
1213      "$simm16"> {
1214    let has_sdst = 0;
1215  }
1216} // End SubtargetPredicate = isGFX10Plus
1217
1218let SubtargetPredicate = isGFX10GFX11 in {
1219  def S_SUBVECTOR_LOOP_BEGIN : SOPK_32_BR<"s_subvector_loop_begin">;
1220  def S_SUBVECTOR_LOOP_END   : SOPK_32_BR<"s_subvector_loop_end">;
1221
1222  def S_WAITCNT_VSCNT   : SOPK_WAITCNT<"s_waitcnt_vscnt">;
1223  def S_WAITCNT_VMCNT   : SOPK_WAITCNT<"s_waitcnt_vmcnt">;
1224  def S_WAITCNT_EXPCNT  : SOPK_WAITCNT<"s_waitcnt_expcnt">;
1225  def S_WAITCNT_LGKMCNT : SOPK_WAITCNT<"s_waitcnt_lgkmcnt">;
1226} // End SubtargetPredicate = isGFX10GFX11
1227
1228//===----------------------------------------------------------------------===//
1229// SOPC Instructions
1230//===----------------------------------------------------------------------===//
1231
1232class SOPC_Pseudo<string opName, dag outs, dag ins,
1233                  string asmOps, list<dag> pattern=[]> :
1234  SOP_Pseudo<opName, outs, ins, " " # asmOps, pattern> {
1235  let mayLoad = 0;
1236  let mayStore = 0;
1237  let hasSideEffects = 0;
1238  let SALU = 1;
1239  let SOPC = 1;
1240  let Defs = [SCC];
1241  let SchedRW = [WriteSALU];
1242  let UseNamedOperandTable = 1;
1243}
1244
1245class SOPC_Real<bits<7> op, SOPC_Pseudo ps> :
1246  InstSI <ps.OutOperandList, ps.InOperandList,
1247          ps.Mnemonic # ps.AsmOperands>,
1248  Enc32 {
1249  let SALU = 1;
1250  let SOPC = 1;
1251  let isPseudo = 0;
1252  let isCodeGenOnly = 0;
1253
1254  // copy relevant pseudo op flags
1255  let SubtargetPredicate   = ps.SubtargetPredicate;
1256  let OtherPredicates      = ps.OtherPredicates;
1257  let AsmMatchConverter    = ps.AsmMatchConverter;
1258  let UseNamedOperandTable = ps.UseNamedOperandTable;
1259  let TSFlags              = ps.TSFlags;
1260  let SchedRW              = ps.SchedRW;
1261  let mayLoad              = ps.mayLoad;
1262  let mayStore             = ps.mayStore;
1263  let Uses                 = ps.Uses;
1264  let Defs                 = ps.Defs;
1265
1266  // encoding
1267  bits<8> src0;
1268  bits<8> src1;
1269
1270  let Inst{7-0} = src0;
1271  let Inst{15-8} = src1;
1272  let Inst{22-16} = op;
1273  let Inst{31-23} = 0x17e;
1274}
1275
1276class SOPC_Base <RegisterOperand rc0, RegisterOperand rc1,
1277                 string opName, list<dag> pattern = []> : SOPC_Pseudo <
1278  opName, (outs), (ins rc0:$src0, rc1:$src1),
1279  "$src0, $src1", pattern > {
1280}
1281
1282class SOPC_Helper <RegisterOperand rc, ValueType vt,
1283                    string opName, SDPatternOperator cond> : SOPC_Base <
1284  rc, rc, opName,
1285  [(set SCC, (UniformTernaryFrag<setcc> vt:$src0, vt:$src1, cond))] > {
1286}
1287
1288class SOPC_CMP_32<string opName,
1289                  SDPatternOperator cond = COND_NULL, string revOp = opName>
1290  : SOPC_Helper<SSrc_b32, i32, opName, cond>,
1291    Commutable_REV<revOp, !eq(revOp, opName)>,
1292    SOPKInstTable<0, opName> {
1293  let isCompare = 1;
1294  let isCommutable = 1;
1295}
1296
1297class SOPC_CMP_F32<string opName,
1298                  SDPatternOperator cond = COND_NULL, string revOp = opName>
1299  : SOPC_Helper<SSrc_b32, f32, opName, cond>,
1300    Commutable_REV<revOp, !eq(revOp, opName)>,
1301    SOPKInstTable<0, opName> {
1302  let isCompare = 1;
1303  let isCommutable = 1;
1304  let mayRaiseFPException = 1;
1305  let Uses = [MODE];
1306  let SchedRW = [WriteSFPU];
1307}
1308
1309class SOPC_CMP_F16<string opName,
1310                  SDPatternOperator cond = COND_NULL, string revOp = opName>
1311  : SOPC_Helper<SSrc_b16, f16, opName, cond>,
1312    Commutable_REV<revOp, !eq(revOp, opName)>,
1313    SOPKInstTable<0, opName> {
1314  let isCompare = 1;
1315  let isCommutable = 1;
1316  let mayRaiseFPException = 1;
1317  let Uses = [MODE];
1318  let SchedRW = [WriteSFPU];
1319}
1320
1321class SOPC_CMP_64<string opName,
1322                  SDPatternOperator cond = COND_NULL, string revOp = opName>
1323  : SOPC_Helper<SSrc_b64, i64, opName, cond>,
1324    Commutable_REV<revOp, !eq(revOp, opName)> {
1325  let isCompare = 1;
1326  let isCommutable = 1;
1327}
1328
1329class SOPC_32<string opName, list<dag> pattern = []>
1330  : SOPC_Base<SSrc_b32, SSrc_b32, opName, pattern>;
1331
1332class SOPC_64_32<string opName, list<dag> pattern = []>
1333  : SOPC_Base<SSrc_b64, SSrc_b32, opName, pattern>;
1334
1335def S_CMP_EQ_I32 : SOPC_CMP_32 <"s_cmp_eq_i32">;
1336def S_CMP_LG_I32 : SOPC_CMP_32 <"s_cmp_lg_i32">;
1337def S_CMP_GT_I32 : SOPC_CMP_32 <"s_cmp_gt_i32", COND_SGT>;
1338def S_CMP_GE_I32 : SOPC_CMP_32 <"s_cmp_ge_i32", COND_SGE>;
1339def S_CMP_LT_I32 : SOPC_CMP_32 <"s_cmp_lt_i32", COND_SLT, "s_cmp_gt_i32">;
1340def S_CMP_LE_I32 : SOPC_CMP_32 <"s_cmp_le_i32", COND_SLE, "s_cmp_ge_i32">;
1341def S_CMP_EQ_U32 : SOPC_CMP_32 <"s_cmp_eq_u32", COND_EQ>;
1342def S_CMP_LG_U32 : SOPC_CMP_32 <"s_cmp_lg_u32", COND_NE>;
1343def S_CMP_GT_U32 : SOPC_CMP_32 <"s_cmp_gt_u32", COND_UGT>;
1344def S_CMP_GE_U32 : SOPC_CMP_32 <"s_cmp_ge_u32", COND_UGE>;
1345def S_CMP_LT_U32 : SOPC_CMP_32 <"s_cmp_lt_u32", COND_ULT, "s_cmp_gt_u32">;
1346def S_CMP_LE_U32 : SOPC_CMP_32 <"s_cmp_le_u32", COND_ULE, "s_cmp_ge_u32">;
1347
1348def S_BITCMP0_B32 : SOPC_32 <"s_bitcmp0_b32">;
1349def S_BITCMP1_B32 : SOPC_32 <"s_bitcmp1_b32">;
1350def S_BITCMP0_B64 : SOPC_64_32 <"s_bitcmp0_b64">;
1351def S_BITCMP1_B64 : SOPC_64_32 <"s_bitcmp1_b64">;
1352let SubtargetPredicate = isGFX6GFX7GFX8GFX9 in
1353def S_SETVSKIP : SOPC_32 <"s_setvskip">;
1354
1355let SubtargetPredicate = isGFX8Plus in {
1356def S_CMP_EQ_U64 : SOPC_CMP_64 <"s_cmp_eq_u64", COND_EQ>;
1357def S_CMP_LG_U64 : SOPC_CMP_64 <"s_cmp_lg_u64", COND_NE>;
1358} // End SubtargetPredicate = isGFX8Plus
1359
1360let SubtargetPredicate = HasVGPRIndexMode in {
1361// Setting the GPR index mode is really writing the fields in the mode
1362// register. We don't want to add mode register uses to every
1363// instruction, and it's too complicated to deal with anyway. This is
1364// modeled just as a side effect.
1365def S_SET_GPR_IDX_ON : SOPC_Pseudo <
1366  "s_set_gpr_idx_on" ,
1367  (outs),
1368  (ins SSrc_b32:$src0, GPRIdxMode:$src1),
1369  "$src0, $src1"> {
1370  let Defs = [M0, MODE]; // No scc def
1371  let Uses = [M0, MODE]; // Other bits of mode, m0 unmodified.
1372  let hasSideEffects = 1; // Sets mode.gpr_idx_en
1373  let FixedSize = 1;
1374}
1375}
1376
1377let SubtargetPredicate = HasSALUFloatInsts in {
1378
1379def S_CMP_LT_F32  : SOPC_CMP_F32<"s_cmp_lt_f32", COND_OLT, "s_cmp_gt_f32">;
1380def S_CMP_EQ_F32  : SOPC_CMP_F32<"s_cmp_eq_f32", COND_OEQ>;
1381def S_CMP_LE_F32  : SOPC_CMP_F32<"s_cmp_le_f32", COND_OLE, "s_cmp_ge_f32">;
1382def S_CMP_GT_F32  : SOPC_CMP_F32<"s_cmp_gt_f32", COND_OGT>;
1383def S_CMP_LG_F32  : SOPC_CMP_F32<"s_cmp_lg_f32", COND_ONE>;
1384def S_CMP_GE_F32  : SOPC_CMP_F32<"s_cmp_ge_f32", COND_OGE>;
1385def S_CMP_O_F32   : SOPC_CMP_F32<"s_cmp_o_f32", COND_O>;
1386def S_CMP_U_F32   : SOPC_CMP_F32<"s_cmp_u_f32", COND_UO>;
1387def S_CMP_NGE_F32 : SOPC_CMP_F32<"s_cmp_nge_f32", COND_ULT, "s_cmp_nle_f32">;
1388def S_CMP_NLG_F32 : SOPC_CMP_F32<"s_cmp_nlg_f32", COND_UEQ>;
1389def S_CMP_NGT_F32 : SOPC_CMP_F32<"s_cmp_ngt_f32", COND_ULE, "s_cmp_nlt_f32">;
1390def S_CMP_NLE_F32 : SOPC_CMP_F32<"s_cmp_nle_f32", COND_UGT>;
1391def S_CMP_NEQ_F32 : SOPC_CMP_F32<"s_cmp_neq_f32", COND_UNE>;
1392def S_CMP_NLT_F32 : SOPC_CMP_F32<"s_cmp_nlt_f32", COND_UGE>;
1393
1394def S_CMP_LT_F16  : SOPC_CMP_F16<"s_cmp_lt_f16", COND_OLT, "s_cmp_gt_f16">;
1395def S_CMP_EQ_F16  : SOPC_CMP_F16<"s_cmp_eq_f16", COND_OEQ>;
1396def S_CMP_LE_F16  : SOPC_CMP_F16<"s_cmp_le_f16", COND_OLE, "s_cmp_ge_f16">;
1397def S_CMP_GT_F16  : SOPC_CMP_F16<"s_cmp_gt_f16", COND_OGT>;
1398def S_CMP_LG_F16  : SOPC_CMP_F16<"s_cmp_lg_f16", COND_ONE>;
1399def S_CMP_GE_F16  : SOPC_CMP_F16<"s_cmp_ge_f16", COND_OGE>;
1400def S_CMP_O_F16   : SOPC_CMP_F16<"s_cmp_o_f16", COND_O>;
1401def S_CMP_U_F16   : SOPC_CMP_F16<"s_cmp_u_f16", COND_UO>;
1402def S_CMP_NGE_F16 : SOPC_CMP_F16<"s_cmp_nge_f16", COND_ULT, "s_cmp_nle_f16">;
1403def S_CMP_NLG_F16 : SOPC_CMP_F16<"s_cmp_nlg_f16", COND_UEQ>;
1404def S_CMP_NGT_F16 : SOPC_CMP_F16<"s_cmp_ngt_f16", COND_ULE, "s_cmp_nlt_f16">;
1405def S_CMP_NLE_F16 : SOPC_CMP_F16<"s_cmp_nle_f16", COND_UGT>;
1406def S_CMP_NEQ_F16 : SOPC_CMP_F16<"s_cmp_neq_f16", COND_UNE>;
1407def S_CMP_NLT_F16 : SOPC_CMP_F16<"s_cmp_nlt_f16", COND_UGE>;
1408
1409} // End SubtargetPredicate = HasSALUFloatInsts
1410
1411//===----------------------------------------------------------------------===//
1412// SOPP Instructions
1413//===----------------------------------------------------------------------===//
1414
1415class SOPP_Pseudo<string opName, dag ins,
1416                  string asmOps = "", list<dag> pattern=[],
1417                  string sep = !if(!empty(asmOps), "", " "),
1418                  string keyName = opName> :
1419  SOP_Pseudo<opName, (outs), ins, sep # asmOps, pattern> {
1420  let mayLoad = 0;
1421  let mayStore = 0;
1422  let hasSideEffects = 0;
1423  let SALU = 1;
1424  let SOPP = 1;
1425  let FixedSize = 1;
1426  let SchedRW = [WriteSALU];
1427  let UseNamedOperandTable = 1;
1428  bits <16> simm16;
1429  bits <1> fixed_imm = 0;
1430  string KeyName = keyName;
1431}
1432
1433class SOPPRelaxTable <bit isRelaxed, string keyName, string gfxip> {
1434  bit IsRelaxed = isRelaxed;
1435  string KeyName = keyName # gfxip;
1436}
1437
1438class SOPP_Real<SOPP_Pseudo ps, string name = ps.Mnemonic> :
1439  InstSI <ps.OutOperandList, ps.InOperandList,
1440          name # ps.AsmOperands> {
1441  let SALU = 1;
1442  let SOPP = 1;
1443  let isPseudo = 0;
1444  let isCodeGenOnly = 0;
1445
1446  // copy relevant pseudo op flags
1447  let SubtargetPredicate   = ps.SubtargetPredicate;
1448  let OtherPredicates      = ps.OtherPredicates;
1449  let AsmMatchConverter    = ps.AsmMatchConverter;
1450  let UseNamedOperandTable = ps.UseNamedOperandTable;
1451  let TSFlags              = ps.TSFlags;
1452  let SchedRW              = ps.SchedRW;
1453  let mayLoad              = ps.mayLoad;
1454  let mayStore             = ps.mayStore;
1455  let isTerminator         = ps.isTerminator;
1456  let isReturn             = ps.isReturn;
1457  let isCall               = ps.isCall;
1458  let isBranch             = ps.isBranch;
1459  let isBarrier            = ps.isBarrier;
1460  let Uses                 = ps.Uses;
1461  let Defs                 = ps.Defs;
1462  bits <16> simm16;
1463}
1464
1465class SOPP_Real_32 <bits<7> op, SOPP_Pseudo ps, string name = ps.Mnemonic> : SOPP_Real<ps, name>,
1466Enc32 {
1467  let Inst{15-0} = !if(ps.fixed_imm, ps.simm16, simm16);
1468  let Inst{22-16} = op;
1469  let Inst{31-23} = 0x17f;
1470}
1471
1472class SOPP_Real_64 <bits<7> op, SOPP_Pseudo ps, string name = ps.Mnemonic> : SOPP_Real<ps, name>,
1473Enc64 {
1474  // encoding
1475  let Inst{15-0} = !if(ps.fixed_imm, ps.simm16, simm16);
1476  let Inst{22-16} = op;
1477  let Inst{31-23} = 0x17f;
1478  //effectively a nop
1479  let Inst{47-32} = 0x0;
1480  let Inst{54-48} = 0x0;
1481  let Inst{63-55} = 0x17f;
1482}
1483
1484multiclass SOPP_With_Relaxation <string opName, dag ins,
1485                  string asmOps, list<dag> pattern=[]> {
1486  def "" : SOPP_Pseudo <opName, ins, asmOps, pattern>;
1487  def _pad_s_nop : SOPP_Pseudo <opName # "_pad_s_nop", ins, asmOps, pattern, " ", opName>;
1488}
1489
1490def S_NOP : SOPP_Pseudo<"s_nop" , (ins i16imm:$simm16), "$simm16",
1491  [(int_amdgcn_s_nop timm:$simm16)]> {
1492  let hasSideEffects = 1;
1493}
1494
1495let isTerminator = 1 in {
1496def S_ENDPGM : SOPP_Pseudo<"s_endpgm", (ins Endpgm:$simm16), "$simm16", [], ""> {
1497  let isBarrier = 1;
1498  let isReturn = 1;
1499  let hasSideEffects = 1;
1500}
1501
1502def S_ENDPGM_SAVED : SOPP_Pseudo<"s_endpgm_saved", (ins)> {
1503  let SubtargetPredicate = isGFX8Plus;
1504  let simm16 = 0;
1505  let fixed_imm = 1;
1506  let isBarrier = 1;
1507  let isReturn = 1;
1508}
1509
1510let SubtargetPredicate = isGFX9GFX10 in {
1511  let isBarrier = 1, isReturn = 1, simm16 = 0, fixed_imm = 1 in {
1512    def S_ENDPGM_ORDERED_PS_DONE :
1513      SOPP_Pseudo<"s_endpgm_ordered_ps_done", (ins)>;
1514  } // End isBarrier = 1, isReturn = 1, simm16 = 0, fixed_imm = 1
1515} // End SubtargetPredicate = isGFX9GFX10
1516
1517let SubtargetPredicate = isGFX10Plus in {
1518  let isBarrier = 1, isReturn = 1, simm16 = 0, fixed_imm = 1 in {
1519    def S_CODE_END :
1520      SOPP_Pseudo<"s_code_end", (ins)>;
1521  } // End isBarrier = 1, isReturn = 1, simm16 = 0, fixed_imm = 1
1522} // End SubtargetPredicate = isGFX10Plus
1523
1524let isBranch = 1, SchedRW = [WriteBranch] in {
1525let isBarrier = 1 in {
1526defm S_BRANCH : SOPP_With_Relaxation<
1527  "s_branch" , (ins SOPPBrTarget:$simm16), "$simm16",
1528  [(br bb:$simm16)]>;
1529}
1530
1531let Uses = [SCC] in {
1532defm S_CBRANCH_SCC0 : SOPP_With_Relaxation<
1533  "s_cbranch_scc0" , (ins SOPPBrTarget:$simm16),
1534  "$simm16"
1535>;
1536defm S_CBRANCH_SCC1 : SOPP_With_Relaxation <
1537  "s_cbranch_scc1" , (ins SOPPBrTarget:$simm16),
1538  "$simm16"
1539>;
1540} // End Uses = [SCC]
1541
1542let Uses = [VCC] in {
1543defm S_CBRANCH_VCCZ : SOPP_With_Relaxation <
1544  "s_cbranch_vccz" , (ins SOPPBrTarget:$simm16),
1545  "$simm16"
1546>;
1547defm S_CBRANCH_VCCNZ : SOPP_With_Relaxation <
1548  "s_cbranch_vccnz" , (ins SOPPBrTarget:$simm16),
1549  "$simm16"
1550>;
1551} // End Uses = [VCC]
1552
1553let Uses = [EXEC] in {
1554defm S_CBRANCH_EXECZ : SOPP_With_Relaxation <
1555  "s_cbranch_execz" , (ins SOPPBrTarget:$simm16),
1556  "$simm16"
1557>;
1558defm S_CBRANCH_EXECNZ : SOPP_With_Relaxation <
1559  "s_cbranch_execnz" , (ins SOPPBrTarget:$simm16),
1560  "$simm16"
1561>;
1562} // End Uses = [EXEC]
1563
1564defm S_CBRANCH_CDBGSYS : SOPP_With_Relaxation <
1565  "s_cbranch_cdbgsys" , (ins SOPPBrTarget:$simm16),
1566  "$simm16"
1567>;
1568
1569defm S_CBRANCH_CDBGSYS_AND_USER : SOPP_With_Relaxation <
1570  "s_cbranch_cdbgsys_and_user" , (ins SOPPBrTarget:$simm16),
1571  "$simm16"
1572>;
1573
1574defm S_CBRANCH_CDBGSYS_OR_USER : SOPP_With_Relaxation <
1575  "s_cbranch_cdbgsys_or_user" , (ins SOPPBrTarget:$simm16),
1576  "$simm16"
1577>;
1578
1579defm S_CBRANCH_CDBGUSER : SOPP_With_Relaxation <
1580  "s_cbranch_cdbguser" , (ins SOPPBrTarget:$simm16),
1581  "$simm16"
1582>;
1583
1584} // End isBranch = 1
1585} // End isTerminator = 1
1586
1587let hasSideEffects = 1 in {
1588def S_BARRIER : SOPP_Pseudo <"s_barrier", (ins), "",
1589  [(int_amdgcn_s_barrier)]> {
1590  let SchedRW = [WriteBarrier];
1591  let simm16 = 0;
1592  let fixed_imm = 1;
1593  let isConvergent = 1;
1594}
1595
1596def S_BARRIER_WAIT : SOPP_Pseudo <"s_barrier_wait", (ins i16imm:$simm16), "$simm16",
1597  [(int_amdgcn_s_barrier_wait timm:$simm16)]> {
1598  let SchedRW = [WriteBarrier];
1599  let isConvergent = 1;
1600}
1601
1602def S_BARRIER_LEAVE : SOPP_Pseudo <"s_barrier_leave", (ins), "",
1603  [(set SCC, (int_amdgcn_s_barrier_leave))]> {
1604  let SchedRW = [WriteBarrier];
1605  let simm16 = 0;
1606  let fixed_imm = 1;
1607  let isConvergent = 1;
1608  let Defs = [SCC];
1609}
1610
1611def S_WAKEUP : SOPP_Pseudo <"s_wakeup", (ins) > {
1612  let SubtargetPredicate = isGFX8Plus;
1613  let simm16 = 0;
1614  let fixed_imm = 1;
1615  let mayLoad = 1;
1616  let mayStore = 1;
1617}
1618
1619def S_WAITCNT : SOPP_Pseudo <"s_waitcnt" , (ins SWaitCnt:$simm16), "$simm16",
1620    [(int_amdgcn_s_waitcnt timm:$simm16)]>;
1621
1622// "_soft" waitcnts are waitcnts that are either relaxed into their non-soft
1623// counterpart, or completely removed.
1624//
1625// These are inserted by SIMemoryLegalizer to resolve memory dependencies
1626// and later optimized by SIInsertWaitcnts
1627// For example, a S_WAITCNT_soft 0 can be completely removed in a function
1628// that doesn't access memory.
1629def S_WAITCNT_soft : SOPP_Pseudo <"s_soft_waitcnt" , (ins SWaitCnt:$simm16), "$simm16">;
1630def S_WAITCNT_VSCNT_soft : SOPK_WAITCNT<"s_soft_waitcnt_vscnt">;
1631let SubtargetPredicate = isGFX12Plus in {
1632  def S_WAIT_LOADCNT_soft : SOPP_Pseudo <"s_soft_wait_loadcnt", (ins s16imm:$simm16), "$simm16">;
1633  def S_WAIT_STORECNT_soft : SOPP_Pseudo <"s_soft_wait_storecnt", (ins s16imm:$simm16), "$simm16">;
1634let OtherPredicates = [HasImageInsts] in {
1635  def S_WAIT_SAMPLECNT_soft : SOPP_Pseudo <"s_soft_wait_samplecnt", (ins s16imm:$simm16), "$simm16">;
1636  def S_WAIT_BVHCNT_soft : SOPP_Pseudo <"s_soft_wait_bvhcnt", (ins s16imm:$simm16), "$simm16">;
1637} // End OtherPredicates = [HasImageInsts].
1638  def S_WAIT_DSCNT_soft : SOPP_Pseudo <"s_soft_wait_dscnt", (ins s16imm:$simm16), "$simm16">;
1639  def S_WAIT_KMCNT_soft : SOPP_Pseudo <"s_soft_wait_kmcnt", (ins s16imm:$simm16), "$simm16">;
1640}
1641
1642def S_SETHALT : SOPP_Pseudo <"s_sethalt" , (ins i32imm:$simm16), "$simm16",
1643    [(int_amdgcn_s_sethalt timm:$simm16)]>;
1644def S_SETKILL : SOPP_Pseudo <"s_setkill" , (ins i16imm:$simm16), "$simm16">;
1645
1646// On SI the documentation says sleep for approximately 64 * low 2
1647// bits, consistent with the reported maximum of 448. On VI the
1648// maximum reported is 960 cycles, so 960 / 64 = 15 max, so is the
1649// maximum really 15 on VI?
1650def S_SLEEP : SOPP_Pseudo <"s_sleep", (ins i32imm:$simm16),
1651  "$simm16", [(int_amdgcn_s_sleep timm:$simm16)]> {
1652}
1653
1654def S_SLEEP_VAR : SOP1_0_32 <"s_sleep_var", [(int_amdgcn_s_sleep_var SSrc_b32:$src0)]> {
1655  let hasSideEffects = 1;
1656}
1657
1658def S_SETPRIO : SOPP_Pseudo <"s_setprio", (ins i16imm:$simm16), "$simm16",
1659  [(int_amdgcn_s_setprio timm:$simm16)]> {
1660}
1661
1662let Uses = [EXEC, M0] in {
1663def S_SENDMSG : SOPP_Pseudo <"s_sendmsg" , (ins SendMsg:$simm16), "$simm16",
1664  [(int_amdgcn_s_sendmsg (i32 timm:$simm16), M0)]> {
1665}
1666
1667def S_SENDMSGHALT : SOPP_Pseudo <"s_sendmsghalt" , (ins SendMsg:$simm16), "$simm16",
1668  [(int_amdgcn_s_sendmsghalt (i32 timm:$simm16), M0)]> {
1669}
1670
1671} // End Uses = [EXEC, M0]
1672
1673def S_TRAP : SOPP_Pseudo <"s_trap" , (ins i16imm:$simm16), "$simm16"> {
1674  let isTrap = 1;
1675}
1676
1677def S_ICACHE_INV : SOPP_Pseudo <"s_icache_inv", (ins)> {
1678  let simm16 = 0;
1679  let fixed_imm = 1;
1680}
1681def S_INCPERFLEVEL : SOPP_Pseudo <"s_incperflevel", (ins i32imm:$simm16), "$simm16",
1682  [(int_amdgcn_s_incperflevel timm:$simm16)]> {
1683}
1684def S_DECPERFLEVEL : SOPP_Pseudo <"s_decperflevel", (ins i32imm:$simm16), "$simm16",
1685  [(int_amdgcn_s_decperflevel timm:$simm16)]> {
1686}
1687
1688let Uses = [M0] in
1689def S_TTRACEDATA : SOPP_Pseudo <"s_ttracedata", (ins), "",
1690                                [(int_amdgcn_s_ttracedata M0)]> {
1691  let simm16 = 0;
1692  let fixed_imm = 1;
1693}
1694
1695let SubtargetPredicate = HasVGPRIndexMode in {
1696def S_SET_GPR_IDX_OFF : SOPP_Pseudo<"s_set_gpr_idx_off", (ins) > {
1697  let simm16 = 0;
1698  let fixed_imm = 1;
1699  let Defs = [MODE];
1700  let Uses = [MODE];
1701}
1702}
1703} // End hasSideEffects
1704
1705let SubtargetPredicate = HasVGPRIndexMode in {
1706def S_SET_GPR_IDX_MODE : SOPP_Pseudo<"s_set_gpr_idx_mode", (ins GPRIdxMode:$simm16),
1707  "$simm16"> {
1708  let Defs = [M0, MODE];
1709  let Uses = [MODE];
1710}
1711}
1712
1713let SubtargetPredicate = isGFX10Plus in {
1714  def S_INST_PREFETCH :
1715    SOPP_Pseudo<"s_inst_prefetch", (ins s16imm:$simm16), "$simm16">;
1716  def S_CLAUSE :
1717    SOPP_Pseudo<"s_clause", (ins s16imm:$simm16), "$simm16">;
1718  def S_WAIT_IDLE :
1719    SOPP_Pseudo <"s_wait_idle", (ins)> {
1720      let simm16 = 0;
1721      let fixed_imm = 1;
1722    }
1723  def S_WAITCNT_DEPCTR :
1724    SOPP_Pseudo <"s_waitcnt_depctr" , (ins DepCtr:$simm16), "$simm16">;
1725
1726  let hasSideEffects = 0, Uses = [MODE], Defs = [MODE] in {
1727    def S_ROUND_MODE :
1728      SOPP_Pseudo<"s_round_mode", (ins s16imm:$simm16), "$simm16">;
1729    def S_DENORM_MODE :
1730      SOPP_Pseudo<"s_denorm_mode", (ins i32imm:$simm16), "$simm16",
1731      [(SIdenorm_mode (i32 timm:$simm16))]>;
1732  }
1733
1734  let hasSideEffects = 1 in
1735  def S_TTRACEDATA_IMM :
1736    SOPP_Pseudo<"s_ttracedata_imm", (ins s16imm:$simm16), "$simm16",
1737                [(int_amdgcn_s_ttracedata_imm timm:$simm16)]>;
1738} // End SubtargetPredicate = isGFX10Plus
1739
1740let SubtargetPredicate = isGFX11Plus in {
1741let OtherPredicates = [HasExportInsts] in
1742  def S_WAIT_EVENT : SOPP_Pseudo<"s_wait_event", (ins s16imm:$simm16),
1743                                 "$simm16"> {
1744                                   let hasSideEffects = 1;
1745                                 }
1746  def S_DELAY_ALU : SOPP_Pseudo<"s_delay_alu", (ins SDelayALU:$simm16),
1747                                "$simm16">;
1748} // End SubtargetPredicate = isGFX11Plus
1749
1750let SubtargetPredicate = HasVGPRSingleUseHintInsts in {
1751  def S_SINGLEUSE_VDST :
1752    SOPP_Pseudo<"s_singleuse_vdst", (ins s16imm:$simm16), "$simm16">;
1753} // End SubtargetPredicate = HasVGPRSingeUseHintInsts
1754
1755let SubtargetPredicate = isGFX12Plus, hasSideEffects = 1 in {
1756  def S_WAIT_LOADCNT :
1757    SOPP_Pseudo<"s_wait_loadcnt", (ins s16imm:$simm16), "$simm16",
1758                [(int_amdgcn_s_wait_loadcnt timm:$simm16)]>;
1759  def S_WAIT_LOADCNT_DSCNT :
1760    SOPP_Pseudo<"s_wait_loadcnt_dscnt", (ins s16imm:$simm16), "$simm16">;
1761  def S_WAIT_STORECNT :
1762    SOPP_Pseudo<"s_wait_storecnt", (ins s16imm:$simm16), "$simm16",
1763                [(int_amdgcn_s_wait_storecnt timm:$simm16)]>;
1764  def S_WAIT_STORECNT_DSCNT :
1765    SOPP_Pseudo<"s_wait_storecnt_dscnt", (ins s16imm:$simm16), "$simm16">;
1766let OtherPredicates = [HasImageInsts] in {
1767  def S_WAIT_SAMPLECNT :
1768    SOPP_Pseudo<"s_wait_samplecnt", (ins s16imm:$simm16), "$simm16",
1769                [(int_amdgcn_s_wait_samplecnt timm:$simm16)]>;
1770  def S_WAIT_BVHCNT :
1771    SOPP_Pseudo<"s_wait_bvhcnt", (ins s16imm:$simm16), "$simm16",
1772                [(int_amdgcn_s_wait_bvhcnt timm:$simm16)]>;
1773} // End OtherPredicates = [HasImageInsts].
1774let OtherPredicates = [HasExportInsts] in
1775  def S_WAIT_EXPCNT :
1776    SOPP_Pseudo<"s_wait_expcnt", (ins s16imm:$simm16), "$simm16",
1777                [(int_amdgcn_s_wait_expcnt timm:$simm16)]>;
1778  def S_WAIT_DSCNT :
1779    SOPP_Pseudo<"s_wait_dscnt", (ins s16imm:$simm16), "$simm16",
1780                [(int_amdgcn_s_wait_dscnt timm:$simm16)]>;
1781  def S_WAIT_KMCNT :
1782    SOPP_Pseudo<"s_wait_kmcnt", (ins s16imm:$simm16), "$simm16",
1783                [(int_amdgcn_s_wait_kmcnt timm:$simm16)]>;
1784} // End SubtargetPredicate = isGFX12Plus, hasSideEffects = 1
1785
1786//===----------------------------------------------------------------------===//
1787// SOP1 Patterns
1788//===----------------------------------------------------------------------===//
1789
1790def : GCNPat <
1791  (AMDGPUendpgm),
1792    (S_ENDPGM (i16 0))
1793>;
1794
1795def : GCNPat <
1796  (int_amdgcn_endpgm),
1797    (S_ENDPGM (i16 0))
1798>;
1799
1800def : GCNPat <
1801  (i64 (UniformUnaryFrag<ctpop> i64:$src)),
1802    (i64 (REG_SEQUENCE SReg_64,
1803     (i32 (COPY_TO_REGCLASS (S_BCNT1_I32_B64 $src), SReg_32)), sub0,
1804     (S_MOV_B32 (i32 0)), sub1))
1805>;
1806
1807def : GCNPat <
1808  (i32 (UniformBinFrag<smax> i32:$x, (i32 (ineg i32:$x)))),
1809  (S_ABS_I32 SReg_32:$x)
1810>;
1811
1812def : GCNPat <
1813  (i16 imm:$imm),
1814  (S_MOV_B32 imm:$imm)
1815>;
1816
1817// Same as a 32-bit inreg
1818def : GCNPat<
1819  (i32 (UniformUnaryFrag<sext> i16:$src)),
1820  (S_SEXT_I32_I16 $src)
1821>;
1822
1823let SubtargetPredicate = isNotGFX12Plus in
1824  def : GCNPat <(int_amdgcn_s_wait_event_export_ready), (S_WAIT_EVENT (i16 0))>;
1825let SubtargetPredicate = isGFX12Plus in
1826  def : GCNPat <(int_amdgcn_s_wait_event_export_ready), (S_WAIT_EVENT (i16 2))>;
1827
1828// The first 10 bits of the mode register are the core FP mode on all
1829// subtargets.
1830//
1831// The high bits include additional fields, intermixed with some
1832// non-floating point environment information. We extract the full
1833// register and clear non-relevant bits.
1834//
1835// EXCP_EN covers floating point exceptions, but also some other
1836// non-FP exceptions.
1837//
1838// Bits 12-18 cover the relevant exception mask on all subtargets.
1839//
1840// FIXME: Bit 18 is int_div0, should this be in the FP environment? I
1841// think the only source is v_rcp_iflag_i32.
1842//
1843// On GFX9+:
1844// Bit 23 is the additional FP16_OVFL mode.
1845//
1846// Bits 19, 20, and 21 cover non-FP exceptions and differ between
1847// gfx9/10/11, so we ignore them here.
1848
1849// TODO: Would it be cheaper to emit multiple s_getreg_b32 calls for
1850// the ranges and combine the results?
1851
1852defvar fp_round_mask = !add(!shl(1, 4), -1);
1853defvar fp_denorm_mask = !shl(!add(!shl(1, 4), -1), 4);
1854defvar dx10_clamp_mask = !shl(1, 8);
1855defvar ieee_mode_mask = !shl(1, 9);
1856
1857// Covers fp_round, fp_denorm, dx10_clamp, and IEEE bit.
1858defvar fpmode_mask =
1859  !or(fp_round_mask, fp_denorm_mask, dx10_clamp_mask, ieee_mode_mask);
1860
1861defvar fp_excp_en_mask = !shl(!add(!shl(1, 7), -1), 12);
1862defvar fp16_ovfl = !shl(1, 23);
1863defvar fpmode_mask_gfx6plus = !or(fpmode_mask, fp_excp_en_mask);
1864defvar fpmode_mask_gfx9plus = !or(fpmode_mask_gfx6plus, fp16_ovfl);
1865
1866class GetFPModePat<int fpmode_mask> : GCNPat<
1867  (i32 get_fpmode),
1868  (S_AND_B32 (i32 fpmode_mask),
1869             (S_GETREG_B32 getHwRegImm<
1870                HWREG.MODE, 0,
1871                !add(!logtwo(fpmode_mask), 1)>.ret))
1872>;
1873
1874// TODO: Might be worth moving to custom lowering so the and is
1875// exposed to demanded bits optimizations. Most users probably only
1876// care about the rounding or denorm mode bits. We also can reduce the
1877// demanded read from the getreg immediate.
1878let SubtargetPredicate = isGFX9Plus in {
1879// Last bit = FP16_OVFL
1880def : GetFPModePat<fpmode_mask_gfx9plus>;
1881}
1882
1883// Last bit = EXCP_EN.int_div0
1884let SubtargetPredicate = isNotGFX9Plus in {
1885def : GetFPModePat<fpmode_mask_gfx6plus>;
1886}
1887
1888let SubtargetPredicate = isGFX9GFX10 in
1889def : GCNPat<
1890  (int_amdgcn_pops_exiting_wave_id),
1891  (S_MOV_B32_sideeffects (i32 SRC_POPS_EXITING_WAVE_ID))
1892>;
1893
1894//===----------------------------------------------------------------------===//
1895// SOP2 Patterns
1896//===----------------------------------------------------------------------===//
1897
1898def UniformSelect : PatFrag<
1899  (ops node:$src0, node:$src1),
1900  (select SCC, $src0, $src1),
1901  [{ return !N->isDivergent(); }]
1902>;
1903
1904let AddedComplexity = 20 in {
1905  def : GCNPat<
1906    (i32 (UniformSelect i32:$src0, i32:$src1)),
1907    (S_CSELECT_B32 SSrc_b32:$src0, SSrc_b32:$src1)
1908  >;
1909
1910  // TODO: The predicate should not be necessary, but enabling this pattern for
1911  // all subtargets generates worse code in some cases.
1912  let OtherPredicates = [HasPseudoScalarTrans] in
1913  def : GCNPat<
1914    (f32 (UniformSelect f32:$src0, f32:$src1)),
1915    (S_CSELECT_B32 SSrc_b32:$src0, SSrc_b32:$src1)
1916  >;
1917}
1918
1919// V_ADD_I32_e32/S_ADD_U32 produces carry in VCC/SCC. For the vector
1920// case, the sgpr-copies pass will fix this to use the vector version.
1921def : GCNPat <
1922  (i32 (addc i32:$src0, i32:$src1)),
1923  (S_ADD_U32 $src0, $src1)
1924>;
1925
1926// FIXME: We need to use COPY_TO_REGCLASS to work-around the fact that
1927// REG_SEQUENCE patterns don't support instructions with multiple
1928// outputs.
1929def : GCNPat<
1930  (i64 (UniformUnaryFrag<zext> i16:$src)),
1931    (REG_SEQUENCE SReg_64,
1932      (i32 (COPY_TO_REGCLASS (S_AND_B32 $src, (S_MOV_B32 (i32 0xffff))), SGPR_32)), sub0,
1933      (S_MOV_B32 (i32 0)), sub1)
1934>;
1935
1936def : GCNPat <
1937  (i64 (UniformUnaryFrag<sext> i16:$src)),
1938    (REG_SEQUENCE SReg_64, (i32 (S_SEXT_I32_I16 $src)), sub0,
1939    (i32 (COPY_TO_REGCLASS (S_ASHR_I32 (i32 (S_SEXT_I32_I16 $src)), (S_MOV_B32 (i32 31))), SGPR_32)), sub1)
1940>;
1941
1942def : GCNPat<
1943  (i32 (UniformUnaryFrag<zext> i16:$src)),
1944  (S_AND_B32 (S_MOV_B32 (i32 0xffff)), $src)
1945>;
1946
1947class ScalarNot2Pat<Instruction inst, SDPatternOperator op, ValueType vt,
1948                    SDPatternOperator notnode = !if(vt.isVector, vnot, not)> : GCNPat<
1949  (UniformBinFrag<op> vt:$src0, (notnode vt:$src1)),
1950  (inst getSOPSrcForVT<vt>.ret:$src0, getSOPSrcForVT<vt>.ret:$src1)
1951>;
1952
1953// Match these for some more types
1954// TODO: i1
1955def : ScalarNot2Pat<S_ANDN2_B32, and, i16>;
1956def : ScalarNot2Pat<S_ANDN2_B32, and, v2i16>;
1957def : ScalarNot2Pat<S_ANDN2_B64, and, v4i16>;
1958def : ScalarNot2Pat<S_ANDN2_B64, and, v2i32>;
1959
1960def : ScalarNot2Pat<S_ORN2_B32, or, i16>;
1961def : ScalarNot2Pat<S_ORN2_B32, or, v2i16>;
1962def : ScalarNot2Pat<S_ORN2_B64, or, v4i16>;
1963def : ScalarNot2Pat<S_ORN2_B64, or, v2i32>;
1964
1965//===----------------------------------------------------------------------===//
1966// Target-specific instruction encodings.
1967//===----------------------------------------------------------------------===//
1968
1969class Select<GFXGen Gen, string opName> : SIMCInstr<opName, Gen.Subtarget> {
1970  Predicate AssemblerPredicate = Gen.AssemblerPredicate;
1971  string DecoderNamespace = Gen.DecoderNamespace;
1972}
1973
1974class Select_vi<string opName> : SIMCInstr<opName, SIEncodingFamily.VI> {
1975  Predicate AssemblerPredicate = isGFX8GFX9;
1976  string DecoderNamespace = "GFX8";
1977}
1978
1979class Select_gfx6_gfx7<string opName> : SIMCInstr<opName, SIEncodingFamily.SI> {
1980  Predicate AssemblerPredicate = isGFX6GFX7;
1981  string DecoderNamespace      = "GFX6GFX7";
1982}
1983
1984//===----------------------------------------------------------------------===//
1985//  SOP1 - GFX11, GFX12
1986//===----------------------------------------------------------------------===//
1987
1988multiclass SOP1_Real_gfx11<bits<8> op, string name = !tolower(NAME)> {
1989  defvar ps = !cast<SOP1_Pseudo>(NAME);
1990  def _gfx11 : SOP1_Real<op, ps, name>,
1991               Select<GFX11Gen, ps.PseudoInstr>;
1992  if !ne(ps.Mnemonic, name) then
1993    def : AMDGPUMnemonicAlias<ps.Mnemonic, name> {
1994      let AssemblerPredicate = isGFX11Only;
1995    }
1996}
1997
1998multiclass SOP1_Real_gfx12<bits<8> op, string name = !tolower(NAME)> {
1999  defvar ps = !cast<SOP1_Pseudo>(NAME);
2000  def _gfx12 : SOP1_Real<op, ps, name>,
2001               Select<GFX12Gen, ps.PseudoInstr>;
2002  if !ne(ps.Mnemonic, name) then
2003    def : AMDGPUMnemonicAlias<ps.Mnemonic, name> {
2004      let AssemblerPredicate = isGFX12Plus;
2005    }
2006}
2007
2008multiclass SOP1_M0_Real_gfx12<bits<8> op> {
2009  def _gfx12 : SOP1_Real<op, !cast<SOP1_Pseudo>(NAME)>,
2010               Select<GFX12Gen, !cast<SOP1_Pseudo>(NAME).PseudoInstr> {
2011    let Inst{7-0} = M0_gfx11plus.HWEncoding{7-0}; // Set Src0 encoding to M0
2012  }
2013}
2014
2015multiclass SOP1_IMM_Real_gfx12<bits<8> op> {
2016  defvar ps = !cast<SOP1_Pseudo>(NAME);
2017  def _gfx12 : SOP1_Real<op, ps>,
2018               Select<GFX12Gen, ps.PseudoInstr>;
2019}
2020
2021multiclass SOP1_Real_gfx11_gfx12<bits<8> op, string name = !tolower(NAME)> :
2022  SOP1_Real_gfx11<op, name>, SOP1_Real_gfx12<op, name>;
2023
2024defm S_MOV_B32                    : SOP1_Real_gfx11_gfx12<0x000>;
2025defm S_MOV_B64                    : SOP1_Real_gfx11_gfx12<0x001>;
2026defm S_CMOV_B32                   : SOP1_Real_gfx11_gfx12<0x002>;
2027defm S_CMOV_B64                   : SOP1_Real_gfx11_gfx12<0x003>;
2028defm S_BREV_B32                   : SOP1_Real_gfx11_gfx12<0x004>;
2029defm S_BREV_B64                   : SOP1_Real_gfx11_gfx12<0x005>;
2030defm S_FF1_I32_B32                : SOP1_Real_gfx11_gfx12<0x008, "s_ctz_i32_b32">;
2031defm S_FF1_I32_B64                : SOP1_Real_gfx11_gfx12<0x009, "s_ctz_i32_b64">;
2032defm S_FLBIT_I32_B32              : SOP1_Real_gfx11_gfx12<0x00a, "s_clz_i32_u32">;
2033defm S_FLBIT_I32_B64              : SOP1_Real_gfx11_gfx12<0x00b, "s_clz_i32_u64">;
2034defm S_FLBIT_I32                  : SOP1_Real_gfx11_gfx12<0x00c, "s_cls_i32">;
2035defm S_FLBIT_I32_I64              : SOP1_Real_gfx11_gfx12<0x00d, "s_cls_i32_i64">;
2036defm S_SEXT_I32_I8                : SOP1_Real_gfx11_gfx12<0x00e>;
2037defm S_SEXT_I32_I16               : SOP1_Real_gfx11_gfx12<0x00f>;
2038defm S_BITSET0_B32                : SOP1_Real_gfx11_gfx12<0x010>;
2039defm S_BITSET0_B64                : SOP1_Real_gfx11_gfx12<0x011>;
2040defm S_BITSET1_B32                : SOP1_Real_gfx11_gfx12<0x012>;
2041defm S_BITSET1_B64                : SOP1_Real_gfx11_gfx12<0x013>;
2042defm S_BITREPLICATE_B64_B32       : SOP1_Real_gfx11_gfx12<0x014>;
2043defm S_ABS_I32                    : SOP1_Real_gfx11_gfx12<0x015>;
2044defm S_BCNT0_I32_B32              : SOP1_Real_gfx11_gfx12<0x016>;
2045defm S_BCNT0_I32_B64              : SOP1_Real_gfx11_gfx12<0x017>;
2046defm S_BCNT1_I32_B32              : SOP1_Real_gfx11_gfx12<0x018>;
2047defm S_BCNT1_I32_B64              : SOP1_Real_gfx11_gfx12<0x019>;
2048defm S_QUADMASK_B32               : SOP1_Real_gfx11_gfx12<0x01a>;
2049defm S_QUADMASK_B64               : SOP1_Real_gfx11_gfx12<0x01b>;
2050defm S_WQM_B32                    : SOP1_Real_gfx11_gfx12<0x01c>;
2051defm S_WQM_B64                    : SOP1_Real_gfx11_gfx12<0x01d>;
2052defm S_NOT_B32                    : SOP1_Real_gfx11_gfx12<0x01e>;
2053defm S_NOT_B64                    : SOP1_Real_gfx11_gfx12<0x01f>;
2054defm S_AND_SAVEEXEC_B32           : SOP1_Real_gfx11_gfx12<0x020>;
2055defm S_AND_SAVEEXEC_B64           : SOP1_Real_gfx11_gfx12<0x021>;
2056defm S_OR_SAVEEXEC_B32            : SOP1_Real_gfx11_gfx12<0x022>;
2057defm S_OR_SAVEEXEC_B64            : SOP1_Real_gfx11_gfx12<0x023>;
2058defm S_XOR_SAVEEXEC_B32           : SOP1_Real_gfx11_gfx12<0x024>;
2059defm S_XOR_SAVEEXEC_B64           : SOP1_Real_gfx11_gfx12<0x025>;
2060defm S_NAND_SAVEEXEC_B32          : SOP1_Real_gfx11_gfx12<0x026>;
2061defm S_NAND_SAVEEXEC_B64          : SOP1_Real_gfx11_gfx12<0x027>;
2062defm S_NOR_SAVEEXEC_B32           : SOP1_Real_gfx11_gfx12<0x028>;
2063defm S_NOR_SAVEEXEC_B64           : SOP1_Real_gfx11_gfx12<0x029>;
2064defm S_XNOR_SAVEEXEC_B32          : SOP1_Real_gfx11_gfx12<0x02a>;
2065defm S_ANDN1_SAVEEXEC_B32         : SOP1_Real_gfx11_gfx12<0x02c, "s_and_not0_saveexec_b32">;
2066defm S_ANDN1_SAVEEXEC_B64         : SOP1_Real_gfx11_gfx12<0x02d, "s_and_not0_saveexec_b64">;
2067defm S_ORN1_SAVEEXEC_B32          : SOP1_Real_gfx11_gfx12<0x02e, "s_or_not0_saveexec_b32">;
2068defm S_ORN1_SAVEEXEC_B64          : SOP1_Real_gfx11_gfx12<0x02f, "s_or_not0_saveexec_b64">;
2069defm S_ANDN2_SAVEEXEC_B32         : SOP1_Real_gfx11_gfx12<0x030, "s_and_not1_saveexec_b32">;
2070defm S_ANDN2_SAVEEXEC_B64         : SOP1_Real_gfx11_gfx12<0x031, "s_and_not1_saveexec_b64">;
2071defm S_ORN2_SAVEEXEC_B32          : SOP1_Real_gfx11_gfx12<0x032, "s_or_not1_saveexec_b32">;
2072defm S_ORN2_SAVEEXEC_B64          : SOP1_Real_gfx11_gfx12<0x033, "s_or_not1_saveexec_b64">;
2073defm S_ANDN1_WREXEC_B32           : SOP1_Real_gfx11_gfx12<0x034, "s_and_not0_wrexec_b32">;
2074defm S_ANDN1_WREXEC_B64           : SOP1_Real_gfx11_gfx12<0x035, "s_and_not0_wrexec_b64">;
2075defm S_ANDN2_WREXEC_B32           : SOP1_Real_gfx11_gfx12<0x036, "s_and_not1_wrexec_b32">;
2076defm S_ANDN2_WREXEC_B64           : SOP1_Real_gfx11_gfx12<0x037, "s_and_not1_wrexec_b64">;
2077defm S_MOVRELS_B32                : SOP1_Real_gfx11_gfx12<0x040>;
2078defm S_MOVRELS_B64                : SOP1_Real_gfx11_gfx12<0x041>;
2079defm S_MOVRELD_B32                : SOP1_Real_gfx11_gfx12<0x042>;
2080defm S_MOVRELD_B64                : SOP1_Real_gfx11_gfx12<0x043>;
2081defm S_MOVRELSD_2_B32             : SOP1_Real_gfx11_gfx12<0x044>;
2082defm S_GETPC_B64                  : SOP1_Real_gfx11_gfx12<0x047>;
2083defm S_SETPC_B64                  : SOP1_Real_gfx11_gfx12<0x048>;
2084defm S_SWAPPC_B64                 : SOP1_Real_gfx11_gfx12<0x049>;
2085defm S_RFE_B64                    : SOP1_Real_gfx11_gfx12<0x04a>;
2086defm S_SENDMSG_RTN_B32            : SOP1_Real_gfx11_gfx12<0x04c>;
2087defm S_SENDMSG_RTN_B64            : SOP1_Real_gfx11_gfx12<0x04d>;
2088defm S_BARRIER_SIGNAL_M0          : SOP1_M0_Real_gfx12<0x04e>;
2089defm S_BARRIER_SIGNAL_ISFIRST_M0  : SOP1_M0_Real_gfx12<0x04f>;
2090defm S_GET_BARRIER_STATE_M0       : SOP1_M0_Real_gfx12<0x050>;
2091defm S_BARRIER_INIT_M0            : SOP1_M0_Real_gfx12<0x051>;
2092defm S_BARRIER_JOIN_M0            : SOP1_M0_Real_gfx12<0x052>;
2093defm S_WAKEUP_BARRIER_M0          : SOP1_M0_Real_gfx12<0x057>;
2094defm S_BARRIER_SIGNAL_IMM         : SOP1_IMM_Real_gfx12<0x04e>;
2095defm S_BARRIER_SIGNAL_ISFIRST_IMM : SOP1_IMM_Real_gfx12<0x04f>;
2096defm S_GET_BARRIER_STATE_IMM      : SOP1_IMM_Real_gfx12<0x050>;
2097defm S_BARRIER_INIT_IMM           : SOP1_IMM_Real_gfx12<0x051>;
2098defm S_BARRIER_JOIN_IMM           : SOP1_IMM_Real_gfx12<0x052>;
2099defm S_WAKEUP_BARRIER_IMM         : SOP1_IMM_Real_gfx12<0x057>;
2100defm S_SLEEP_VAR                  : SOP1_IMM_Real_gfx12<0x058>;
2101
2102//===----------------------------------------------------------------------===//
2103// SOP1 - GFX1150, GFX12
2104//===----------------------------------------------------------------------===//
2105
2106defm S_CEIL_F32          : SOP1_Real_gfx11_gfx12<0x060>;
2107defm S_FLOOR_F32         : SOP1_Real_gfx11_gfx12<0x061>;
2108defm S_TRUNC_F32         : SOP1_Real_gfx11_gfx12<0x062>;
2109defm S_RNDNE_F32         : SOP1_Real_gfx11_gfx12<0x063>;
2110defm S_CVT_F32_I32       : SOP1_Real_gfx11_gfx12<0x064>;
2111defm S_CVT_F32_U32       : SOP1_Real_gfx11_gfx12<0x065>;
2112defm S_CVT_I32_F32       : SOP1_Real_gfx11_gfx12<0x066>;
2113defm S_CVT_U32_F32       : SOP1_Real_gfx11_gfx12<0x067>;
2114defm S_CVT_F16_F32       : SOP1_Real_gfx11_gfx12<0x068>;
2115defm S_CVT_F32_F16       : SOP1_Real_gfx11_gfx12<0x069>;
2116defm S_CVT_HI_F32_F16    : SOP1_Real_gfx11_gfx12<0x06a>;
2117defm S_CEIL_F16          : SOP1_Real_gfx11_gfx12<0x06b>;
2118defm S_FLOOR_F16         : SOP1_Real_gfx11_gfx12<0x06c>;
2119defm S_TRUNC_F16         : SOP1_Real_gfx11_gfx12<0x06d>;
2120defm S_RNDNE_F16         : SOP1_Real_gfx11_gfx12<0x06e>;
2121
2122//===----------------------------------------------------------------------===//
2123// SOP1 - GFX10.
2124//===----------------------------------------------------------------------===//
2125
2126multiclass SOP1_Real_gfx10<bits<8> op> {
2127  defvar ps = !cast<SOP1_Pseudo>(NAME);
2128  def _gfx10 : SOP1_Real<op, ps>,
2129               Select<GFX10Gen, ps.PseudoInstr>;
2130}
2131
2132multiclass SOP1_Real_gfx10_gfx11_gfx12<bits<8> op> :
2133  SOP1_Real_gfx10<op>, SOP1_Real_gfx11_gfx12<op>;
2134
2135defm S_ANDN1_SAVEEXEC_B64   : SOP1_Real_gfx10<0x037>;
2136defm S_ORN1_SAVEEXEC_B64    : SOP1_Real_gfx10<0x038>;
2137defm S_ANDN1_WREXEC_B64     : SOP1_Real_gfx10<0x039>;
2138defm S_ANDN2_WREXEC_B64     : SOP1_Real_gfx10<0x03a>;
2139defm S_BITREPLICATE_B64_B32 : SOP1_Real_gfx10<0x03b>;
2140defm S_AND_SAVEEXEC_B32     : SOP1_Real_gfx10<0x03c>;
2141defm S_OR_SAVEEXEC_B32      : SOP1_Real_gfx10<0x03d>;
2142defm S_XOR_SAVEEXEC_B32     : SOP1_Real_gfx10<0x03e>;
2143defm S_ANDN2_SAVEEXEC_B32   : SOP1_Real_gfx10<0x03f>;
2144defm S_ORN2_SAVEEXEC_B32    : SOP1_Real_gfx10<0x040>;
2145defm S_NAND_SAVEEXEC_B32    : SOP1_Real_gfx10<0x041>;
2146defm S_NOR_SAVEEXEC_B32     : SOP1_Real_gfx10<0x042>;
2147defm S_XNOR_SAVEEXEC_B32    : SOP1_Real_gfx10<0x043>;
2148defm S_ANDN1_SAVEEXEC_B32   : SOP1_Real_gfx10<0x044>;
2149defm S_ORN1_SAVEEXEC_B32    : SOP1_Real_gfx10<0x045>;
2150defm S_ANDN1_WREXEC_B32     : SOP1_Real_gfx10<0x046>;
2151defm S_ANDN2_WREXEC_B32     : SOP1_Real_gfx10<0x047>;
2152defm S_MOVRELSD_2_B32       : SOP1_Real_gfx10<0x049>;
2153
2154//===----------------------------------------------------------------------===//
2155// SOP1 - GFX6, GFX7, GFX10, GFX11.
2156//===----------------------------------------------------------------------===//
2157
2158
2159multiclass SOP1_Real_gfx6_gfx7<bits<8> op> {
2160  defvar ps = !cast<SOP1_Pseudo>(NAME);
2161  def _gfx6_gfx7 : SOP1_Real<op, ps>,
2162                   Select_gfx6_gfx7<ps.PseudoInstr>;
2163}
2164
2165multiclass SOP1_Real_gfx6_gfx7_gfx10<bits<8> op> :
2166  SOP1_Real_gfx6_gfx7<op>, SOP1_Real_gfx10<op>;
2167
2168multiclass SOP1_Real_gfx6_gfx7_gfx10_gfx11_gfx12<bits<8> op> :
2169  SOP1_Real_gfx6_gfx7<op>, SOP1_Real_gfx10_gfx11_gfx12<op>;
2170
2171defm S_CBRANCH_JOIN  : SOP1_Real_gfx6_gfx7<0x032>;
2172
2173defm S_MOV_B32            : SOP1_Real_gfx6_gfx7_gfx10<0x003>;
2174defm S_MOV_B64            : SOP1_Real_gfx6_gfx7_gfx10<0x004>;
2175defm S_CMOV_B32           : SOP1_Real_gfx6_gfx7_gfx10<0x005>;
2176defm S_CMOV_B64           : SOP1_Real_gfx6_gfx7_gfx10<0x006>;
2177defm S_NOT_B32            : SOP1_Real_gfx6_gfx7_gfx10<0x007>;
2178defm S_NOT_B64            : SOP1_Real_gfx6_gfx7_gfx10<0x008>;
2179defm S_WQM_B32            : SOP1_Real_gfx6_gfx7_gfx10<0x009>;
2180defm S_WQM_B64            : SOP1_Real_gfx6_gfx7_gfx10<0x00a>;
2181defm S_BREV_B32           : SOP1_Real_gfx6_gfx7_gfx10<0x00b>;
2182defm S_BREV_B64           : SOP1_Real_gfx6_gfx7_gfx10<0x00c>;
2183defm S_BCNT0_I32_B32      : SOP1_Real_gfx6_gfx7_gfx10<0x00d>;
2184defm S_BCNT0_I32_B64      : SOP1_Real_gfx6_gfx7_gfx10<0x00e>;
2185defm S_BCNT1_I32_B32      : SOP1_Real_gfx6_gfx7_gfx10<0x00f>;
2186defm S_BCNT1_I32_B64      : SOP1_Real_gfx6_gfx7_gfx10<0x010>;
2187defm S_FF0_I32_B32        : SOP1_Real_gfx6_gfx7_gfx10<0x011>;
2188defm S_FF0_I32_B64        : SOP1_Real_gfx6_gfx7_gfx10<0x012>;
2189defm S_FF1_I32_B32        : SOP1_Real_gfx6_gfx7_gfx10<0x013>;
2190defm S_FF1_I32_B64        : SOP1_Real_gfx6_gfx7_gfx10<0x014>;
2191defm S_FLBIT_I32_B32      : SOP1_Real_gfx6_gfx7_gfx10<0x015>;
2192defm S_FLBIT_I32_B64      : SOP1_Real_gfx6_gfx7_gfx10<0x016>;
2193defm S_FLBIT_I32          : SOP1_Real_gfx6_gfx7_gfx10<0x017>;
2194defm S_FLBIT_I32_I64      : SOP1_Real_gfx6_gfx7_gfx10<0x018>;
2195defm S_SEXT_I32_I8        : SOP1_Real_gfx6_gfx7_gfx10<0x019>;
2196defm S_SEXT_I32_I16       : SOP1_Real_gfx6_gfx7_gfx10<0x01a>;
2197defm S_BITSET0_B32        : SOP1_Real_gfx6_gfx7_gfx10<0x01b>;
2198defm S_BITSET0_B64        : SOP1_Real_gfx6_gfx7_gfx10<0x01c>;
2199defm S_BITSET1_B32        : SOP1_Real_gfx6_gfx7_gfx10<0x01d>;
2200defm S_BITSET1_B64        : SOP1_Real_gfx6_gfx7_gfx10<0x01e>;
2201defm S_GETPC_B64          : SOP1_Real_gfx6_gfx7_gfx10<0x01f>;
2202defm S_SETPC_B64          : SOP1_Real_gfx6_gfx7_gfx10<0x020>;
2203defm S_SWAPPC_B64         : SOP1_Real_gfx6_gfx7_gfx10<0x021>;
2204defm S_RFE_B64            : SOP1_Real_gfx6_gfx7_gfx10<0x022>;
2205defm S_AND_SAVEEXEC_B64   : SOP1_Real_gfx6_gfx7_gfx10<0x024>;
2206defm S_OR_SAVEEXEC_B64    : SOP1_Real_gfx6_gfx7_gfx10<0x025>;
2207defm S_XOR_SAVEEXEC_B64   : SOP1_Real_gfx6_gfx7_gfx10<0x026>;
2208defm S_ANDN2_SAVEEXEC_B64 : SOP1_Real_gfx6_gfx7_gfx10<0x027>;
2209defm S_ORN2_SAVEEXEC_B64  : SOP1_Real_gfx6_gfx7_gfx10<0x028>;
2210defm S_NAND_SAVEEXEC_B64  : SOP1_Real_gfx6_gfx7_gfx10<0x029>;
2211defm S_NOR_SAVEEXEC_B64   : SOP1_Real_gfx6_gfx7_gfx10<0x02a>;
2212defm S_XNOR_SAVEEXEC_B64  : SOP1_Real_gfx6_gfx7_gfx10_gfx11_gfx12<0x02b>;
2213defm S_QUADMASK_B32       : SOP1_Real_gfx6_gfx7_gfx10<0x02c>;
2214defm S_QUADMASK_B64       : SOP1_Real_gfx6_gfx7_gfx10<0x02d>;
2215defm S_MOVRELS_B32        : SOP1_Real_gfx6_gfx7_gfx10<0x02e>;
2216defm S_MOVRELS_B64        : SOP1_Real_gfx6_gfx7_gfx10<0x02f>;
2217defm S_MOVRELD_B32        : SOP1_Real_gfx6_gfx7_gfx10<0x030>;
2218defm S_MOVRELD_B64        : SOP1_Real_gfx6_gfx7_gfx10<0x031>;
2219defm S_ABS_I32            : SOP1_Real_gfx6_gfx7_gfx10<0x034>;
2220
2221//===----------------------------------------------------------------------===//
2222// SOP2 - GFX12
2223//===----------------------------------------------------------------------===//
2224
2225multiclass SOP2_Real_gfx12<bits<7> op, string name = !tolower(NAME)> {
2226  defvar ps = !cast<SOP2_Pseudo>(NAME);
2227  def _gfx12 : SOP2_Real32<op, ps, name>,
2228               Select<GFX12Gen, ps.PseudoInstr>;
2229  if !ne(ps.Mnemonic, name) then
2230    def : AMDGPUMnemonicAlias<ps.Mnemonic, name> {
2231      let AssemblerPredicate = isGFX12Plus;
2232    }
2233}
2234
2235defm S_MINIMUM_F32 : SOP2_Real_gfx12<0x04f>;
2236defm S_MAXIMUM_F32 : SOP2_Real_gfx12<0x050>;
2237defm S_MINIMUM_F16 : SOP2_Real_gfx12<0x051>;
2238defm S_MAXIMUM_F16 : SOP2_Real_gfx12<0x052>;
2239
2240//===----------------------------------------------------------------------===//
2241// SOP2 - GFX11, GFX12.
2242//===----------------------------------------------------------------------===//
2243
2244multiclass SOP2_Real_gfx11<bits<7> op, string name = !tolower(NAME)> {
2245  defvar ps = !cast<SOP2_Pseudo>(NAME);
2246  def _gfx11 : SOP2_Real32<op, ps, name>,
2247               Select<GFX11Gen, ps.PseudoInstr>;
2248  if !ne(ps.Mnemonic, name) then
2249    def : AMDGPUMnemonicAlias<ps.Mnemonic, name> {
2250      let AssemblerPredicate = isGFX11Only;
2251    }
2252}
2253
2254multiclass SOP2_Real_gfx11_gfx12<bits<7> op, string name = !tolower(NAME)> :
2255  SOP2_Real_gfx11<op, name>, SOP2_Real_gfx12<op, name>;
2256
2257defm S_ABSDIFF_I32     : SOP2_Real_gfx11_gfx12<0x006>;
2258defm S_LSHL_B32        : SOP2_Real_gfx11_gfx12<0x008>;
2259defm S_LSHL_B64        : SOP2_Real_gfx11_gfx12<0x009>;
2260defm S_LSHR_B32        : SOP2_Real_gfx11_gfx12<0x00a>;
2261defm S_LSHR_B64        : SOP2_Real_gfx11_gfx12<0x00b>;
2262defm S_ASHR_I32        : SOP2_Real_gfx11_gfx12<0x00c>;
2263defm S_ASHR_I64        : SOP2_Real_gfx11_gfx12<0x00d>;
2264defm S_LSHL1_ADD_U32   : SOP2_Real_gfx11_gfx12<0x00e>;
2265defm S_LSHL2_ADD_U32   : SOP2_Real_gfx11_gfx12<0x00f>;
2266defm S_LSHL3_ADD_U32   : SOP2_Real_gfx11_gfx12<0x010>;
2267defm S_LSHL4_ADD_U32   : SOP2_Real_gfx11_gfx12<0x011>;
2268defm S_MIN_I32         : SOP2_Real_gfx11_gfx12<0x012>;
2269defm S_MIN_U32         : SOP2_Real_gfx11_gfx12<0x013>;
2270defm S_MAX_I32         : SOP2_Real_gfx11_gfx12<0x014>;
2271defm S_MAX_U32         : SOP2_Real_gfx11_gfx12<0x015>;
2272defm S_AND_B32         : SOP2_Real_gfx11_gfx12<0x016>;
2273defm S_AND_B64         : SOP2_Real_gfx11_gfx12<0x017>;
2274defm S_OR_B32          : SOP2_Real_gfx11_gfx12<0x018>;
2275defm S_OR_B64          : SOP2_Real_gfx11_gfx12<0x019>;
2276defm S_XOR_B32         : SOP2_Real_gfx11_gfx12<0x01a>;
2277defm S_XOR_B64         : SOP2_Real_gfx11_gfx12<0x01b>;
2278defm S_NAND_B32        : SOP2_Real_gfx11_gfx12<0x01c>;
2279defm S_NAND_B64        : SOP2_Real_gfx11_gfx12<0x01d>;
2280defm S_NOR_B32         : SOP2_Real_gfx11_gfx12<0x01e>;
2281defm S_NOR_B64         : SOP2_Real_gfx11_gfx12<0x01f>;
2282defm S_XNOR_B32        : SOP2_Real_gfx11_gfx12<0x020>;
2283defm S_XNOR_B64        : SOP2_Real_gfx11_gfx12<0x021>;
2284defm S_ANDN2_B32       : SOP2_Real_gfx11_gfx12<0x022, "s_and_not1_b32">;
2285defm S_ANDN2_B64       : SOP2_Real_gfx11_gfx12<0x023, "s_and_not1_b64">;
2286defm S_ORN2_B32        : SOP2_Real_gfx11_gfx12<0x024, "s_or_not1_b32">;
2287defm S_ORN2_B64        : SOP2_Real_gfx11_gfx12<0x025, "s_or_not1_b64">;
2288defm S_BFE_U32         : SOP2_Real_gfx11_gfx12<0x026>;
2289defm S_BFE_I32         : SOP2_Real_gfx11_gfx12<0x027>;
2290defm S_BFE_U64         : SOP2_Real_gfx11_gfx12<0x028>;
2291defm S_BFE_I64         : SOP2_Real_gfx11_gfx12<0x029>;
2292defm S_BFM_B32         : SOP2_Real_gfx11_gfx12<0x02a>;
2293defm S_BFM_B64         : SOP2_Real_gfx11_gfx12<0x02b>;
2294defm S_MUL_I32         : SOP2_Real_gfx11_gfx12<0x02c>;
2295defm S_MUL_HI_U32      : SOP2_Real_gfx11_gfx12<0x02d>;
2296defm S_MUL_HI_I32      : SOP2_Real_gfx11_gfx12<0x02e>;
2297defm S_CSELECT_B32     : SOP2_Real_gfx11_gfx12<0x030>;
2298defm S_CSELECT_B64     : SOP2_Real_gfx11_gfx12<0x031>;
2299defm S_PACK_HL_B32_B16 : SOP2_Real_gfx11_gfx12<0x035>;
2300defm S_ADD_U64         : SOP2_Real_gfx12<0x053, "s_add_nc_u64">;
2301defm S_SUB_U64         : SOP2_Real_gfx12<0x054, "s_sub_nc_u64">;
2302defm S_MUL_U64         : SOP2_Real_gfx12<0x055>;
2303
2304//===----------------------------------------------------------------------===//
2305// SOP2 - GFX1150, GFX12
2306//===----------------------------------------------------------------------===//
2307
2308multiclass SOP2_Real_FMAK_gfx12<bits<7> op> {
2309  def _gfx12 : SOP2_Real64<op, !cast<SOP2_Pseudo>(NAME)>,
2310               Select<GFX12Gen, !cast<SOP2_Pseudo>(NAME).PseudoInstr>;
2311}
2312
2313multiclass SOP2_Real_FMAK_gfx11<bits<7> op> {
2314  def _gfx11 : SOP2_Real64<op, !cast<SOP2_Pseudo>(NAME)>,
2315               Select<GFX11Gen, !cast<SOP2_Pseudo>(NAME).PseudoInstr>;
2316}
2317
2318multiclass SOP2_Real_FMAK_gfx11_gfx12<bits<7> op> :
2319  SOP2_Real_FMAK_gfx11<op>, SOP2_Real_FMAK_gfx12<op>;
2320
2321defm S_ADD_F32            : SOP2_Real_gfx11_gfx12<0x040>;
2322defm S_SUB_F32            : SOP2_Real_gfx11_gfx12<0x041>;
2323defm S_MUL_F32            : SOP2_Real_gfx11_gfx12<0x044>;
2324defm S_FMAAK_F32          : SOP2_Real_FMAK_gfx11_gfx12<0x045>;
2325defm S_FMAMK_F32          : SOP2_Real_FMAK_gfx11_gfx12<0x046>;
2326defm S_FMAC_F32           : SOP2_Real_gfx11_gfx12<0x047>;
2327defm S_CVT_PK_RTZ_F16_F32 : SOP2_Real_gfx11_gfx12<0x048>;
2328defm S_ADD_F16            : SOP2_Real_gfx11_gfx12<0x049>;
2329defm S_SUB_F16            : SOP2_Real_gfx11_gfx12<0x04a>;
2330defm S_MUL_F16            : SOP2_Real_gfx11_gfx12<0x04d>;
2331defm S_FMAC_F16           : SOP2_Real_gfx11_gfx12<0x04e>;
2332
2333//===----------------------------------------------------------------------===//
2334// SOP2 - GFX1150
2335//===----------------------------------------------------------------------===//
2336
2337multiclass SOP2_Real_gfx11_Renamed_gfx12<bits<7> op, string gfx12_name> :
2338  SOP2_Real_gfx11<op>, SOP2_Real_gfx12<op, gfx12_name>;
2339
2340defm S_MIN_F32 : SOP2_Real_gfx11_Renamed_gfx12<0x042, "s_min_num_f32">;
2341defm S_MAX_F32 : SOP2_Real_gfx11_Renamed_gfx12<0x043, "s_max_num_f32">;
2342defm S_MIN_F16 : SOP2_Real_gfx11_Renamed_gfx12<0x04b, "s_min_num_f16">;
2343defm S_MAX_F16 : SOP2_Real_gfx11_Renamed_gfx12<0x04c, "s_max_num_f16">;
2344
2345//===----------------------------------------------------------------------===//
2346// SOP2 - GFX10.
2347//===----------------------------------------------------------------------===//
2348
2349multiclass SOP2_Real_gfx10<bits<7> op> {
2350  defvar ps = !cast<SOP2_Pseudo>(NAME);
2351  def _gfx10 : SOP2_Real32<op, ps>,
2352               Select<GFX10Gen, ps.PseudoInstr>;
2353}
2354
2355multiclass SOP2_Real_gfx10_gfx11_gfx12<bits<7> op> :
2356  SOP2_Real_gfx10<op>, SOP2_Real_gfx11_gfx12<op>;
2357
2358defm S_LSHL1_ADD_U32   : SOP2_Real_gfx10<0x02e>;
2359defm S_LSHL2_ADD_U32   : SOP2_Real_gfx10<0x02f>;
2360defm S_LSHL3_ADD_U32   : SOP2_Real_gfx10<0x030>;
2361defm S_LSHL4_ADD_U32   : SOP2_Real_gfx10<0x031>;
2362defm S_PACK_LL_B32_B16 : SOP2_Real_gfx10_gfx11_gfx12<0x032>;
2363defm S_PACK_LH_B32_B16 : SOP2_Real_gfx10_gfx11_gfx12<0x033>;
2364defm S_PACK_HH_B32_B16 : SOP2_Real_gfx10_gfx11_gfx12<0x034>;
2365defm S_MUL_HI_U32      : SOP2_Real_gfx10<0x035>;
2366defm S_MUL_HI_I32      : SOP2_Real_gfx10<0x036>;
2367
2368//===----------------------------------------------------------------------===//
2369// SOP2 - GFX6, GFX7.
2370//===----------------------------------------------------------------------===//
2371
2372multiclass SOP2_Real_gfx6_gfx7<bits<7> op> {
2373  defvar ps = !cast<SOP2_Pseudo>(NAME);
2374  def _gfx6_gfx7 : SOP2_Real32<op, ps>,
2375                   Select_gfx6_gfx7<ps.PseudoInstr>;
2376}
2377
2378multiclass SOP2_Real_gfx6_gfx7_gfx10<bits<7> op> :
2379  SOP2_Real_gfx6_gfx7<op>, SOP2_Real_gfx10<op>;
2380
2381multiclass SOP2_Real_gfx6_gfx7_gfx10_gfx11_Renamed_gfx12<bits<7> op, string gfx12_name> :
2382  SOP2_Real_gfx6_gfx7<op>, SOP2_Real_gfx10<op>, SOP2_Real_gfx11<op>,
2383  SOP2_Real_gfx12<op, gfx12_name>;
2384
2385defm S_CBRANCH_G_FORK : SOP2_Real_gfx6_gfx7<0x02b>;
2386
2387defm S_ADD_U32     : SOP2_Real_gfx6_gfx7_gfx10_gfx11_Renamed_gfx12<0x000, "s_add_co_u32">;
2388defm S_SUB_U32     : SOP2_Real_gfx6_gfx7_gfx10_gfx11_Renamed_gfx12<0x001, "s_sub_co_u32">;
2389defm S_ADD_I32     : SOP2_Real_gfx6_gfx7_gfx10_gfx11_Renamed_gfx12<0x002, "s_add_co_i32">;
2390defm S_SUB_I32     : SOP2_Real_gfx6_gfx7_gfx10_gfx11_Renamed_gfx12<0x003, "s_sub_co_i32">;
2391defm S_ADDC_U32    : SOP2_Real_gfx6_gfx7_gfx10_gfx11_Renamed_gfx12<0x004, "s_add_co_ci_u32">;
2392defm S_SUBB_U32    : SOP2_Real_gfx6_gfx7_gfx10_gfx11_Renamed_gfx12<0x005, "s_sub_co_ci_u32">;
2393defm S_MIN_I32     : SOP2_Real_gfx6_gfx7_gfx10<0x006>;
2394defm S_MIN_U32     : SOP2_Real_gfx6_gfx7_gfx10<0x007>;
2395defm S_MAX_I32     : SOP2_Real_gfx6_gfx7_gfx10<0x008>;
2396defm S_MAX_U32     : SOP2_Real_gfx6_gfx7_gfx10<0x009>;
2397defm S_CSELECT_B32 : SOP2_Real_gfx6_gfx7_gfx10<0x00a>;
2398defm S_CSELECT_B64 : SOP2_Real_gfx6_gfx7_gfx10<0x00b>;
2399defm S_AND_B32     : SOP2_Real_gfx6_gfx7_gfx10<0x00e>;
2400defm S_AND_B64     : SOP2_Real_gfx6_gfx7_gfx10<0x00f>;
2401defm S_OR_B32      : SOP2_Real_gfx6_gfx7_gfx10<0x010>;
2402defm S_OR_B64      : SOP2_Real_gfx6_gfx7_gfx10<0x011>;
2403defm S_XOR_B32     : SOP2_Real_gfx6_gfx7_gfx10<0x012>;
2404defm S_XOR_B64     : SOP2_Real_gfx6_gfx7_gfx10<0x013>;
2405defm S_ANDN2_B32   : SOP2_Real_gfx6_gfx7_gfx10<0x014>;
2406defm S_ANDN2_B64   : SOP2_Real_gfx6_gfx7_gfx10<0x015>;
2407defm S_ORN2_B32    : SOP2_Real_gfx6_gfx7_gfx10<0x016>;
2408defm S_ORN2_B64    : SOP2_Real_gfx6_gfx7_gfx10<0x017>;
2409defm S_NAND_B32    : SOP2_Real_gfx6_gfx7_gfx10<0x018>;
2410defm S_NAND_B64    : SOP2_Real_gfx6_gfx7_gfx10<0x019>;
2411defm S_NOR_B32     : SOP2_Real_gfx6_gfx7_gfx10<0x01a>;
2412defm S_NOR_B64     : SOP2_Real_gfx6_gfx7_gfx10<0x01b>;
2413defm S_XNOR_B32    : SOP2_Real_gfx6_gfx7_gfx10<0x01c>;
2414defm S_XNOR_B64    : SOP2_Real_gfx6_gfx7_gfx10<0x01d>;
2415defm S_LSHL_B32    : SOP2_Real_gfx6_gfx7_gfx10<0x01e>;
2416defm S_LSHL_B64    : SOP2_Real_gfx6_gfx7_gfx10<0x01f>;
2417defm S_LSHR_B32    : SOP2_Real_gfx6_gfx7_gfx10<0x020>;
2418defm S_LSHR_B64    : SOP2_Real_gfx6_gfx7_gfx10<0x021>;
2419defm S_ASHR_I32    : SOP2_Real_gfx6_gfx7_gfx10<0x022>;
2420defm S_ASHR_I64    : SOP2_Real_gfx6_gfx7_gfx10<0x023>;
2421defm S_BFM_B32     : SOP2_Real_gfx6_gfx7_gfx10<0x024>;
2422defm S_BFM_B64     : SOP2_Real_gfx6_gfx7_gfx10<0x025>;
2423defm S_MUL_I32     : SOP2_Real_gfx6_gfx7_gfx10<0x026>;
2424defm S_BFE_U32     : SOP2_Real_gfx6_gfx7_gfx10<0x027>;
2425defm S_BFE_I32     : SOP2_Real_gfx6_gfx7_gfx10<0x028>;
2426defm S_BFE_U64     : SOP2_Real_gfx6_gfx7_gfx10<0x029>;
2427defm S_BFE_I64     : SOP2_Real_gfx6_gfx7_gfx10<0x02a>;
2428defm S_ABSDIFF_I32 : SOP2_Real_gfx6_gfx7_gfx10<0x02c>;
2429
2430//===----------------------------------------------------------------------===//
2431// SOPK - GFX11, GFX12.
2432//===----------------------------------------------------------------------===//
2433
2434multiclass SOPK_Real32_gfx12<bits<5> op, string name = !tolower(NAME)> {
2435  defvar ps = !cast<SOPK_Pseudo>(NAME);
2436  def _gfx12 : SOPK_Real32<op, ps, name>,
2437               Select<GFX12Gen, ps.PseudoInstr>;
2438  if !ne(ps.Mnemonic, name) then
2439    def : AMDGPUMnemonicAlias<ps.Mnemonic, name> {
2440      let AssemblerPredicate = isGFX12Plus;
2441    }
2442}
2443
2444multiclass SOPK_Real32_gfx11<bits<5> op> {
2445  def _gfx11 : SOPK_Real32<op, !cast<SOPK_Pseudo>(NAME)>,
2446               Select<GFX11Gen, !cast<SOPK_Pseudo>(NAME).PseudoInstr>;
2447}
2448
2449multiclass SOPK_Real64_gfx12<bits<5> op> {
2450  def _gfx12 : SOPK_Real64<op, !cast<SOPK_Pseudo>(NAME)>,
2451               Select<GFX12Gen, !cast<SOPK_Pseudo>(NAME).PseudoInstr>;
2452}
2453
2454multiclass SOPK_Real64_gfx11<bits<5> op> {
2455  def _gfx11 : SOPK_Real64<op, !cast<SOPK_Pseudo>(NAME)>,
2456               Select<GFX11Gen, !cast<SOPK_Pseudo>(NAME).PseudoInstr>;
2457}
2458
2459multiclass SOPK_Real32_gfx11_gfx12<bits<5> op> :
2460  SOPK_Real32_gfx11<op>, SOPK_Real32_gfx12<op>;
2461
2462multiclass SOPK_Real64_gfx11_gfx12<bits<5> op> :
2463  SOPK_Real64_gfx11<op>, SOPK_Real64_gfx12<op>;
2464
2465defm S_GETREG_B32           : SOPK_Real32_gfx11_gfx12<0x011>;
2466defm S_SETREG_B32           : SOPK_Real32_gfx11_gfx12<0x012>;
2467defm S_SETREG_IMM32_B32     : SOPK_Real64_gfx11_gfx12<0x013>;
2468defm S_CALL_B64             : SOPK_Real32_gfx11_gfx12<0x014>;
2469defm S_SUBVECTOR_LOOP_BEGIN : SOPK_Real32_gfx11<0x016>;
2470defm S_SUBVECTOR_LOOP_END   : SOPK_Real32_gfx11<0x017>;
2471defm S_WAITCNT_VSCNT        : SOPK_Real32_gfx11<0x018>;
2472defm S_WAITCNT_VMCNT        : SOPK_Real32_gfx11<0x019>;
2473defm S_WAITCNT_EXPCNT       : SOPK_Real32_gfx11<0x01a>;
2474defm S_WAITCNT_LGKMCNT      : SOPK_Real32_gfx11<0x01b>;
2475
2476//===----------------------------------------------------------------------===//
2477// SOPK - GFX10.
2478//===----------------------------------------------------------------------===//
2479
2480multiclass SOPK_Real32_gfx10<bits<5> op> {
2481  defvar ps = !cast<SOPK_Pseudo>(NAME);
2482  def _gfx10 : SOPK_Real32<op, ps>,
2483               Select<GFX10Gen, ps.PseudoInstr>;
2484}
2485
2486multiclass SOPK_Real64_gfx10<bits<5> op> {
2487  defvar ps = !cast<SOPK_Pseudo>(NAME);
2488  def _gfx10 : SOPK_Real64<op, ps>,
2489               Select<GFX10Gen, ps.PseudoInstr>;
2490}
2491
2492multiclass SOPK_Real32_gfx10_gfx11<bits<5> op> :
2493  SOPK_Real32_gfx10<op>, SOPK_Real32_gfx11<op>;
2494
2495multiclass SOPK_Real32_gfx10_gfx11_gfx12<bits<5> op> :
2496  SOPK_Real32_gfx10<op>, SOPK_Real32_gfx11_gfx12<op>;
2497
2498defm S_VERSION              : SOPK_Real32_gfx10_gfx11_gfx12<0x001>;
2499defm S_CALL_B64             : SOPK_Real32_gfx10<0x016>;
2500defm S_WAITCNT_VSCNT        : SOPK_Real32_gfx10<0x017>;
2501defm S_WAITCNT_VMCNT        : SOPK_Real32_gfx10<0x018>;
2502defm S_WAITCNT_EXPCNT       : SOPK_Real32_gfx10<0x019>;
2503defm S_WAITCNT_LGKMCNT      : SOPK_Real32_gfx10<0x01a>;
2504defm S_SUBVECTOR_LOOP_BEGIN : SOPK_Real32_gfx10<0x01b>;
2505defm S_SUBVECTOR_LOOP_END   : SOPK_Real32_gfx10<0x01c>;
2506
2507//===----------------------------------------------------------------------===//
2508// SOPK - GFX6, GFX7.
2509//===----------------------------------------------------------------------===//
2510
2511multiclass SOPK_Real32_gfx6_gfx7<bits<5> op> {
2512  defvar ps = !cast<SOPK_Pseudo>(NAME);
2513  def _gfx6_gfx7 : SOPK_Real32<op, ps>,
2514                   Select_gfx6_gfx7<ps.PseudoInstr>;
2515}
2516
2517multiclass SOPK_Real64_gfx6_gfx7<bits<5> op> {
2518  defvar ps = !cast<SOPK_Pseudo>(NAME);
2519  def _gfx6_gfx7 : SOPK_Real64<op, ps>,
2520                   Select_gfx6_gfx7<ps.PseudoInstr>;
2521}
2522
2523multiclass SOPK_Real32_gfx6_gfx7_gfx10<bits<5> op> :
2524  SOPK_Real32_gfx6_gfx7<op>, SOPK_Real32_gfx10<op>;
2525
2526multiclass SOPK_Real64_gfx6_gfx7_gfx10<bits<5> op> :
2527  SOPK_Real64_gfx6_gfx7<op>, SOPK_Real64_gfx10<op>;
2528
2529multiclass SOPK_Real32_gfx6_gfx7_gfx10_gfx11<bits<5> op> :
2530  SOPK_Real32_gfx6_gfx7<op>, SOPK_Real32_gfx10_gfx11<op>;
2531
2532multiclass SOPK_Real32_gfx6_gfx7_gfx10_gfx11_gfx12<bits<5> op> :
2533  SOPK_Real32_gfx6_gfx7<op>, SOPK_Real32_gfx10_gfx11_gfx12<op>;
2534
2535multiclass SOPK_Real32_gfx6_gfx7_gfx10_gfx11_Renamed_gfx12<bits<5> op, string gfx12_name> :
2536  SOPK_Real32_gfx6_gfx7<op>, SOPK_Real32_gfx10<op>, SOPK_Real32_gfx11<op>,
2537  SOPK_Real32_gfx12<op, gfx12_name>;
2538
2539defm S_CBRANCH_I_FORK : SOPK_Real32_gfx6_gfx7<0x011>;
2540
2541defm S_MOVK_I32         : SOPK_Real32_gfx6_gfx7_gfx10_gfx11_gfx12<0x000>;
2542defm S_CMOVK_I32        : SOPK_Real32_gfx6_gfx7_gfx10_gfx11_gfx12<0x002>;
2543defm S_CMPK_EQ_I32      : SOPK_Real32_gfx6_gfx7_gfx10_gfx11<0x003>;
2544defm S_CMPK_LG_I32      : SOPK_Real32_gfx6_gfx7_gfx10_gfx11<0x004>;
2545defm S_CMPK_GT_I32      : SOPK_Real32_gfx6_gfx7_gfx10_gfx11<0x005>;
2546defm S_CMPK_GE_I32      : SOPK_Real32_gfx6_gfx7_gfx10_gfx11<0x006>;
2547defm S_CMPK_LT_I32      : SOPK_Real32_gfx6_gfx7_gfx10_gfx11<0x007>;
2548defm S_CMPK_LE_I32      : SOPK_Real32_gfx6_gfx7_gfx10_gfx11<0x008>;
2549defm S_CMPK_EQ_U32      : SOPK_Real32_gfx6_gfx7_gfx10_gfx11<0x009>;
2550defm S_CMPK_LG_U32      : SOPK_Real32_gfx6_gfx7_gfx10_gfx11<0x00a>;
2551defm S_CMPK_GT_U32      : SOPK_Real32_gfx6_gfx7_gfx10_gfx11<0x00b>;
2552defm S_CMPK_GE_U32      : SOPK_Real32_gfx6_gfx7_gfx10_gfx11<0x00c>;
2553defm S_CMPK_LT_U32      : SOPK_Real32_gfx6_gfx7_gfx10_gfx11<0x00d>;
2554defm S_CMPK_LE_U32      : SOPK_Real32_gfx6_gfx7_gfx10_gfx11<0x00e>;
2555defm S_ADDK_I32         : SOPK_Real32_gfx6_gfx7_gfx10_gfx11_Renamed_gfx12<0x00f, "s_addk_co_i32">;
2556defm S_MULK_I32         : SOPK_Real32_gfx6_gfx7_gfx10_gfx11_gfx12<0x010>;
2557defm S_GETREG_B32       : SOPK_Real32_gfx6_gfx7_gfx10<0x012>;
2558defm S_SETREG_B32       : SOPK_Real32_gfx6_gfx7_gfx10<0x013>;
2559defm S_SETREG_IMM32_B32 : SOPK_Real64_gfx6_gfx7_gfx10<0x015>;
2560
2561//===----------------------------------------------------------------------===//
2562// SOPP - GFX12 only.
2563//===----------------------------------------------------------------------===//
2564
2565multiclass SOPP_Real_32_gfx12<bits<7> op, string name = !tolower(NAME)> {
2566  defvar ps = !cast<SOPP_Pseudo>(NAME);
2567  def _gfx12 : SOPP_Real_32<op, ps, name>,
2568               Select<GFX12Gen, ps.PseudoInstr>;
2569  if !ne(ps.Mnemonic, name) then
2570    def : AMDGPUMnemonicAlias<ps.Mnemonic, name> {
2571      let AssemblerPredicate = isGFX12Plus;
2572    }
2573}
2574
2575defm S_BARRIER_WAIT         : SOPP_Real_32_gfx12<0x014>;
2576defm S_BARRIER_LEAVE        : SOPP_Real_32_gfx12<0x015>;
2577defm S_WAIT_LOADCNT         : SOPP_Real_32_gfx12<0x040>;
2578defm S_WAIT_STORECNT        : SOPP_Real_32_gfx12<0x041>;
2579defm S_WAIT_SAMPLECNT       : SOPP_Real_32_gfx12<0x042>;
2580defm S_WAIT_BVHCNT          : SOPP_Real_32_gfx12<0x043>;
2581defm S_WAIT_EXPCNT          : SOPP_Real_32_gfx12<0x044>;
2582defm S_WAIT_DSCNT           : SOPP_Real_32_gfx12<0x046>;
2583defm S_WAIT_KMCNT           : SOPP_Real_32_gfx12<0x047>;
2584defm S_WAIT_LOADCNT_DSCNT   : SOPP_Real_32_gfx12<0x048>;
2585defm S_WAIT_STORECNT_DSCNT  : SOPP_Real_32_gfx12<0x049>;
2586
2587//===----------------------------------------------------------------------===//
2588// SOPP - GFX11, GFX12.
2589//===----------------------------------------------------------------------===//
2590
2591
2592multiclass SOPP_Real_32_gfx11<bits<7> op, string name = !tolower(NAME)> {
2593  defvar ps = !cast<SOPP_Pseudo>(NAME);
2594  def _gfx11 : SOPP_Real_32<op, ps, name>,
2595               Select<GFX11Gen, ps.PseudoInstr>,
2596               SOPPRelaxTable<0, ps.KeyName, "_gfx11">;
2597  if !ne(ps.Mnemonic, name) then
2598    def : AMDGPUMnemonicAlias<ps.Mnemonic, name> {
2599      let AssemblerPredicate = isGFX11Only;
2600    }
2601}
2602
2603multiclass SOPP_Real_64_gfx12<bits<7> op> {
2604  def _gfx12 : SOPP_Real_64<op, !cast<SOPP_Pseudo>(NAME), !cast<SOPP_Pseudo>(NAME).Mnemonic>,
2605               Select<GFX12Gen, !cast<SOPP_Pseudo>(NAME).PseudoInstr>,
2606               SOPPRelaxTable<1, !cast<SOPP_Pseudo>(NAME).KeyName, "_gfx12">;
2607}
2608
2609multiclass SOPP_Real_64_gfx11<bits<7> op> {
2610  def _gfx11 : SOPP_Real_64<op, !cast<SOPP_Pseudo>(NAME), !cast<SOPP_Pseudo>(NAME).Mnemonic>,
2611               Select<GFX11Gen, !cast<SOPP_Pseudo>(NAME).PseudoInstr>,
2612               SOPPRelaxTable<1, !cast<SOPP_Pseudo>(NAME).KeyName, "_gfx11">;
2613}
2614
2615multiclass SOPP_Real_32_gfx11_gfx12<bits<7> op> :
2616  SOPP_Real_32_gfx11<op>, SOPP_Real_32_gfx12<op>;
2617
2618multiclass SOPP_Real_32_gfx11_Renamed_gfx12<bits<7> op, string gfx12_name> :
2619  SOPP_Real_32_gfx11<op>, SOPP_Real_32_gfx12<op, gfx12_name>;
2620
2621multiclass SOPP_Real_With_Relaxation_gfx12<bits<7> op> {
2622  defm "" : SOPP_Real_32_gfx12<op>;
2623  let isCodeGenOnly = 1 in
2624  defm _pad_s_nop : SOPP_Real_64_gfx12<op>;
2625}
2626
2627multiclass SOPP_Real_With_Relaxation_gfx11<bits<7> op> {
2628  defm "" : SOPP_Real_32_gfx11<op>;
2629  let isCodeGenOnly = 1 in
2630  defm _pad_s_nop : SOPP_Real_64_gfx11<op>;
2631}
2632
2633multiclass SOPP_Real_With_Relaxation_gfx11_gfx12<bits<7>op> :
2634  SOPP_Real_With_Relaxation_gfx11<op>, SOPP_Real_With_Relaxation_gfx12<op>;
2635
2636defm S_SETKILL                    : SOPP_Real_32_gfx11_gfx12<0x001>;
2637defm S_SETHALT                    : SOPP_Real_32_gfx11_gfx12<0x002>;
2638defm S_SLEEP                      : SOPP_Real_32_gfx11_gfx12<0x003>;
2639defm S_INST_PREFETCH              : SOPP_Real_32_gfx11<0x004, "s_set_inst_prefetch_distance">;
2640defm S_CLAUSE                     : SOPP_Real_32_gfx11_gfx12<0x005>;
2641defm S_DELAY_ALU                  : SOPP_Real_32_gfx11_gfx12<0x007>;
2642defm S_WAITCNT_DEPCTR             : SOPP_Real_32_gfx11_Renamed_gfx12<0x008, "s_wait_alu">;
2643defm S_WAITCNT                    : SOPP_Real_32_gfx11_gfx12<0x009>;
2644defm S_WAIT_IDLE                  : SOPP_Real_32_gfx11_gfx12<0x00a>;
2645defm S_WAIT_EVENT                 : SOPP_Real_32_gfx11_gfx12<0x00b>;
2646defm S_TRAP                       : SOPP_Real_32_gfx11_gfx12<0x010>;
2647defm S_ROUND_MODE                 : SOPP_Real_32_gfx11_gfx12<0x011>;
2648defm S_DENORM_MODE                : SOPP_Real_32_gfx11_gfx12<0x012>;
2649defm S_BRANCH                     : SOPP_Real_With_Relaxation_gfx11_gfx12<0x020>;
2650defm S_CBRANCH_SCC0               : SOPP_Real_With_Relaxation_gfx11_gfx12<0x021>;
2651defm S_CBRANCH_SCC1               : SOPP_Real_With_Relaxation_gfx11_gfx12<0x022>;
2652defm S_CBRANCH_VCCZ               : SOPP_Real_With_Relaxation_gfx11_gfx12<0x023>;
2653defm S_CBRANCH_VCCNZ              : SOPP_Real_With_Relaxation_gfx11_gfx12<0x024>;
2654defm S_CBRANCH_EXECZ              : SOPP_Real_With_Relaxation_gfx11_gfx12<0x025>;
2655defm S_CBRANCH_EXECNZ             : SOPP_Real_With_Relaxation_gfx11_gfx12<0x026>;
2656defm S_CBRANCH_CDBGSYS            : SOPP_Real_With_Relaxation_gfx11<0x027>;
2657defm S_CBRANCH_CDBGUSER           : SOPP_Real_With_Relaxation_gfx11<0x028>;
2658defm S_CBRANCH_CDBGSYS_OR_USER    : SOPP_Real_With_Relaxation_gfx11<0x029>;
2659defm S_CBRANCH_CDBGSYS_AND_USER   : SOPP_Real_With_Relaxation_gfx11<0x02a>;
2660defm S_ENDPGM                     : SOPP_Real_32_gfx11_gfx12<0x030>;
2661defm S_ENDPGM_SAVED               : SOPP_Real_32_gfx11_gfx12<0x031>;
2662defm S_WAKEUP                     : SOPP_Real_32_gfx11_gfx12<0x034>;
2663defm S_SETPRIO                    : SOPP_Real_32_gfx11_gfx12<0x035>;
2664defm S_SENDMSG                    : SOPP_Real_32_gfx11_gfx12<0x036>;
2665defm S_SENDMSGHALT                : SOPP_Real_32_gfx11_gfx12<0x037>;
2666defm S_INCPERFLEVEL               : SOPP_Real_32_gfx11_gfx12<0x038>;
2667defm S_DECPERFLEVEL               : SOPP_Real_32_gfx11_gfx12<0x039>;
2668defm S_TTRACEDATA                 : SOPP_Real_32_gfx11_gfx12<0x03a>;
2669defm S_TTRACEDATA_IMM             : SOPP_Real_32_gfx11_gfx12<0x03b>;
2670defm S_ICACHE_INV                 : SOPP_Real_32_gfx11_gfx12<0x03c>;
2671
2672defm S_BARRIER                    : SOPP_Real_32_gfx11<0x03d>;
2673
2674//===----------------------------------------------------------------------===//
2675// SOPP - GFX1150, GFX12.
2676//===----------------------------------------------------------------------===//
2677
2678defm S_SINGLEUSE_VDST             : SOPP_Real_32_gfx11_gfx12<0x013>;
2679
2680//===----------------------------------------------------------------------===//
2681// SOPP - GFX6, GFX7, GFX8, GFX9, GFX10
2682//===----------------------------------------------------------------------===//
2683
2684multiclass SOPP_Real_32_gfx6_gfx7<bits<7> op> {
2685  defvar ps = !cast<SOPP_Pseudo>(NAME);
2686  def _gfx6_gfx7 : SOPP_Real_32<op, ps, !cast<SOPP_Pseudo>(NAME).Mnemonic>,
2687                   Select_gfx6_gfx7<ps.PseudoInstr>,
2688                   SOPPRelaxTable<0, ps.KeyName, "_gfx6_gfx7">;
2689}
2690
2691multiclass SOPP_Real_32_gfx8_gfx9<bits<7> op> {
2692  defvar ps = !cast<SOPP_Pseudo>(NAME);
2693  def _vi : SOPP_Real_32<op, ps>,
2694            Select_vi<ps.PseudoInstr>,
2695            SOPPRelaxTable<0, ps.KeyName, "_vi">;
2696}
2697
2698multiclass SOPP_Real_32_gfx10<bits<7> op> {
2699  defvar ps = !cast<SOPP_Pseudo>(NAME);
2700  def _gfx10 : SOPP_Real_32<op, ps>,
2701               Select<GFX10Gen, ps.PseudoInstr>,
2702               SOPPRelaxTable<0, ps.KeyName, "_gfx10">;
2703}
2704
2705multiclass SOPP_Real_32_gfx8_gfx9_gfx10<bits<7> op> :
2706  SOPP_Real_32_gfx8_gfx9<op>, SOPP_Real_32_gfx10<op>;
2707
2708multiclass SOPP_Real_32_gfx6_gfx7_gfx8_gfx9<bits<7> op> :
2709  SOPP_Real_32_gfx6_gfx7<op>, SOPP_Real_32_gfx8_gfx9<op>;
2710
2711multiclass SOPP_Real_32_gfx6_gfx7_gfx8_gfx9_gfx10<bits<7> op> :
2712  SOPP_Real_32_gfx6_gfx7_gfx8_gfx9<op>, SOPP_Real_32_gfx10<op>;
2713
2714multiclass SOPP_Real_32_gfx6_gfx7_gfx8_gfx9_gfx10_gfx11_gfx12<bits<7> op> :
2715  SOPP_Real_32_gfx6_gfx7_gfx8_gfx9_gfx10<op>, SOPP_Real_32_gfx11_gfx12<op>;
2716
2717multiclass SOPP_Real_32_gfx10_gfx11_gfx12<bits<7> op> :
2718  SOPP_Real_32_gfx10<op>, SOPP_Real_32_gfx11_gfx12<op>;
2719
2720//64 bit encodings, for Relaxation
2721multiclass SOPP_Real_64_gfx6_gfx7<bits<7> op> {
2722  defvar ps = !cast<SOPP_Pseudo>(NAME);
2723  def _gfx6_gfx7 : SOPP_Real_64<op, ps>,
2724                   Select_gfx6_gfx7<ps.PseudoInstr>,
2725                   SOPPRelaxTable<1, ps.KeyName, "_gfx6_gfx7">;
2726}
2727
2728multiclass SOPP_Real_64_gfx8_gfx9<bits<7> op> {
2729  defvar ps = !cast<SOPP_Pseudo>(NAME);
2730  def _vi : SOPP_Real_64<op, ps>,
2731            Select_vi<ps.PseudoInstr>,
2732            SOPPRelaxTable<1, ps.KeyName, "_vi">;
2733}
2734
2735multiclass SOPP_Real_64_gfx10<bits<7> op> {
2736  defvar ps = !cast<SOPP_Pseudo>(NAME);
2737  def _gfx10 : SOPP_Real_64<op, ps>,
2738               Select<GFX10Gen, ps.PseudoInstr>,
2739               SOPPRelaxTable<1, ps.KeyName, "_gfx10">;
2740}
2741
2742multiclass SOPP_Real_64_gfx6_gfx7_gfx8_gfx9<bits<7> op> :
2743  SOPP_Real_64_gfx6_gfx7<op>, SOPP_Real_64_gfx8_gfx9<op>;
2744
2745multiclass SOPP_Real_64_gfx6_gfx7_gfx8_gfx9_gfx10<bits<7> op> :
2746  SOPP_Real_64_gfx6_gfx7_gfx8_gfx9<op>, SOPP_Real_64_gfx10<op>;
2747
2748//relaxation for insts with no operands not implemented
2749multiclass SOPP_Real_With_Relaxation_gfx6_gfx7_gfx8_gfx9_gfx10<bits<7> op> {
2750  defm "" : SOPP_Real_32_gfx6_gfx7_gfx8_gfx9_gfx10<op>;
2751  let isCodeGenOnly = 1 in
2752  defm _pad_s_nop : SOPP_Real_64_gfx6_gfx7_gfx8_gfx9_gfx10<op>;
2753}
2754
2755defm S_NOP                      : SOPP_Real_32_gfx6_gfx7_gfx8_gfx9_gfx10_gfx11_gfx12<0x000>;
2756defm S_ENDPGM                   : SOPP_Real_32_gfx6_gfx7_gfx8_gfx9_gfx10<0x001>;
2757defm S_WAKEUP                   : SOPP_Real_32_gfx8_gfx9_gfx10<0x003>;
2758defm S_BARRIER                  : SOPP_Real_32_gfx6_gfx7_gfx8_gfx9_gfx10<0x00a>;
2759defm S_WAITCNT                  : SOPP_Real_32_gfx6_gfx7_gfx8_gfx9_gfx10<0x00c>;
2760defm S_SETHALT                  : SOPP_Real_32_gfx6_gfx7_gfx8_gfx9_gfx10<0x00d>;
2761defm S_SETKILL                  : SOPP_Real_32_gfx6_gfx7_gfx8_gfx9_gfx10<0x00b>;
2762defm S_SLEEP                    : SOPP_Real_32_gfx6_gfx7_gfx8_gfx9_gfx10<0x00e>;
2763defm S_SETPRIO                  : SOPP_Real_32_gfx6_gfx7_gfx8_gfx9_gfx10<0x00f>;
2764defm S_SENDMSG                  : SOPP_Real_32_gfx6_gfx7_gfx8_gfx9_gfx10<0x010>;
2765defm S_SENDMSGHALT              : SOPP_Real_32_gfx6_gfx7_gfx8_gfx9_gfx10<0x011>;
2766defm S_TRAP                     : SOPP_Real_32_gfx6_gfx7_gfx8_gfx9_gfx10<0x012>;
2767defm S_ICACHE_INV               : SOPP_Real_32_gfx6_gfx7_gfx8_gfx9_gfx10<0x013>;
2768defm S_INCPERFLEVEL             : SOPP_Real_32_gfx6_gfx7_gfx8_gfx9_gfx10<0x014>;
2769defm S_DECPERFLEVEL             : SOPP_Real_32_gfx6_gfx7_gfx8_gfx9_gfx10<0x015>;
2770defm S_TTRACEDATA               : SOPP_Real_32_gfx6_gfx7_gfx8_gfx9_gfx10<0x016>;
2771defm S_ENDPGM_SAVED             : SOPP_Real_32_gfx6_gfx7_gfx8_gfx9_gfx10<0x01B>;
2772defm S_SET_GPR_IDX_OFF          : SOPP_Real_32_gfx8_gfx9<0x01c>;
2773defm S_SET_GPR_IDX_MODE         : SOPP_Real_32_gfx8_gfx9<0x01d>;
2774defm S_ENDPGM_ORDERED_PS_DONE   : SOPP_Real_32_gfx8_gfx9_gfx10<0x01e>;
2775defm S_CODE_END                 : SOPP_Real_32_gfx10_gfx11_gfx12<0x01f>;
2776defm S_INST_PREFETCH            : SOPP_Real_32_gfx10<0x020>;
2777defm S_CLAUSE                   : SOPP_Real_32_gfx10<0x021>;
2778defm S_WAIT_IDLE                : SOPP_Real_32_gfx10<0x022>;
2779defm S_WAITCNT_DEPCTR           : SOPP_Real_32_gfx10<0x023>;
2780defm S_ROUND_MODE               : SOPP_Real_32_gfx10<0x024>;
2781defm S_DENORM_MODE              : SOPP_Real_32_gfx10<0x025>;
2782defm S_TTRACEDATA_IMM           : SOPP_Real_32_gfx10<0x028>;
2783
2784let isBranch = 1 in {
2785defm S_BRANCH                   : SOPP_Real_With_Relaxation_gfx6_gfx7_gfx8_gfx9_gfx10<0x002>;
2786defm S_CBRANCH_SCC0             : SOPP_Real_With_Relaxation_gfx6_gfx7_gfx8_gfx9_gfx10<0x004>;
2787defm S_CBRANCH_SCC1             : SOPP_Real_With_Relaxation_gfx6_gfx7_gfx8_gfx9_gfx10<0x005>;
2788defm S_CBRANCH_VCCZ             : SOPP_Real_With_Relaxation_gfx6_gfx7_gfx8_gfx9_gfx10<0x006>;
2789defm S_CBRANCH_VCCNZ            : SOPP_Real_With_Relaxation_gfx6_gfx7_gfx8_gfx9_gfx10<0x007>;
2790defm S_CBRANCH_EXECZ            : SOPP_Real_With_Relaxation_gfx6_gfx7_gfx8_gfx9_gfx10<0x008>;
2791defm S_CBRANCH_EXECNZ           : SOPP_Real_With_Relaxation_gfx6_gfx7_gfx8_gfx9_gfx10<0x009>;
2792defm S_CBRANCH_CDBGSYS          : SOPP_Real_With_Relaxation_gfx6_gfx7_gfx8_gfx9_gfx10<0x017>;
2793defm S_CBRANCH_CDBGUSER         : SOPP_Real_With_Relaxation_gfx6_gfx7_gfx8_gfx9_gfx10<0x018>;
2794defm S_CBRANCH_CDBGSYS_OR_USER  : SOPP_Real_With_Relaxation_gfx6_gfx7_gfx8_gfx9_gfx10<0x019>;
2795defm S_CBRANCH_CDBGSYS_AND_USER : SOPP_Real_With_Relaxation_gfx6_gfx7_gfx8_gfx9_gfx10<0x01A>;
2796}
2797
2798//===----------------------------------------------------------------------===//
2799// SOPC - GFX11, GFX12.
2800//===----------------------------------------------------------------------===//
2801
2802multiclass SOPC_Real_gfx12<bits<7> op> {
2803  def _gfx12 : SOPC_Real<op, !cast<SOPC_Pseudo>(NAME)>,
2804               Select<GFX12Gen, !cast<SOPC_Pseudo>(NAME).PseudoInstr>;
2805}
2806
2807multiclass SOPC_Real_gfx11<bits<7> op> {
2808  def _gfx11 : SOPC_Real<op, !cast<SOPC_Pseudo>(NAME)>,
2809               Select<GFX11Gen, !cast<SOPC_Pseudo>(NAME).PseudoInstr>;
2810}
2811
2812multiclass SOPC_Real_gfx11_gfx12<bits<7> op> :
2813  SOPC_Real_gfx11<op>, SOPC_Real_gfx12<op>;
2814
2815defm S_CMP_EQ_U64 : SOPC_Real_gfx11_gfx12<0x10>;
2816defm S_CMP_LG_U64 : SOPC_Real_gfx11_gfx12<0x11>;
2817
2818//===----------------------------------------------------------------------===//
2819// SOPC - GFX1150, GFX12
2820//===----------------------------------------------------------------------===//
2821
2822defm S_CMP_LT_F32  : SOPC_Real_gfx11_gfx12<0x41>;
2823defm S_CMP_EQ_F32  : SOPC_Real_gfx11_gfx12<0x42>;
2824defm S_CMP_LE_F32  : SOPC_Real_gfx11_gfx12<0x43>;
2825defm S_CMP_GT_F32  : SOPC_Real_gfx11_gfx12<0x44>;
2826defm S_CMP_LG_F32  : SOPC_Real_gfx11_gfx12<0x45>;
2827defm S_CMP_GE_F32  : SOPC_Real_gfx11_gfx12<0x46>;
2828defm S_CMP_O_F32   : SOPC_Real_gfx11_gfx12<0x47>;
2829defm S_CMP_U_F32   : SOPC_Real_gfx11_gfx12<0x48>;
2830defm S_CMP_NGE_F32 : SOPC_Real_gfx11_gfx12<0x49>;
2831defm S_CMP_NLG_F32 : SOPC_Real_gfx11_gfx12<0x4a>;
2832defm S_CMP_NGT_F32 : SOPC_Real_gfx11_gfx12<0x4b>;
2833defm S_CMP_NLE_F32 : SOPC_Real_gfx11_gfx12<0x4c>;
2834defm S_CMP_NEQ_F32 : SOPC_Real_gfx11_gfx12<0x4d>;
2835defm S_CMP_NLT_F32 : SOPC_Real_gfx11_gfx12<0x4e>;
2836
2837defm S_CMP_LT_F16  : SOPC_Real_gfx11_gfx12<0x51>;
2838defm S_CMP_EQ_F16  : SOPC_Real_gfx11_gfx12<0x52>;
2839defm S_CMP_LE_F16  : SOPC_Real_gfx11_gfx12<0x53>;
2840defm S_CMP_GT_F16  : SOPC_Real_gfx11_gfx12<0x54>;
2841defm S_CMP_LG_F16  : SOPC_Real_gfx11_gfx12<0x55>;
2842defm S_CMP_GE_F16  : SOPC_Real_gfx11_gfx12<0x56>;
2843defm S_CMP_O_F16   : SOPC_Real_gfx11_gfx12<0x57>;
2844defm S_CMP_U_F16   : SOPC_Real_gfx11_gfx12<0x58>;
2845defm S_CMP_NGE_F16 : SOPC_Real_gfx11_gfx12<0x59>;
2846defm S_CMP_NLG_F16 : SOPC_Real_gfx11_gfx12<0x5a>;
2847defm S_CMP_NGT_F16 : SOPC_Real_gfx11_gfx12<0x5b>;
2848defm S_CMP_NLE_F16 : SOPC_Real_gfx11_gfx12<0x5c>;
2849defm S_CMP_NEQ_F16 : SOPC_Real_gfx11_gfx12<0x5d>;
2850defm S_CMP_NLT_F16 : SOPC_Real_gfx11_gfx12<0x5e>;
2851
2852//===----------------------------------------------------------------------===//
2853// SOPC - GFX6, GFX7, GFX8, GFX9, GFX10
2854//===----------------------------------------------------------------------===//
2855
2856multiclass SOPC_Real_gfx6_gfx7<bits<7> op> {
2857  defvar ps = !cast<SOPC_Pseudo>(NAME);
2858  def _gfx6_gfx7 : SOPC_Real<op, ps>,
2859                   Select_gfx6_gfx7<ps.PseudoInstr>;
2860}
2861
2862multiclass SOPC_Real_gfx8_gfx9<bits<7> op> {
2863  defvar ps = !cast<SOPC_Pseudo>(NAME);
2864  def _vi : SOPC_Real<op, ps>,
2865            Select_vi<ps.PseudoInstr>;
2866}
2867
2868multiclass SOPC_Real_gfx10<bits<7> op> {
2869  defvar ps = !cast<SOPC_Pseudo>(NAME);
2870  def _gfx10 : SOPC_Real<op, ps>,
2871               Select<GFX10Gen, ps.PseudoInstr>;
2872}
2873
2874multiclass SOPC_Real_gfx8_gfx9_gfx10<bits<7> op> :
2875  SOPC_Real_gfx8_gfx9<op>, SOPC_Real_gfx10<op>;
2876
2877multiclass SOPC_Real_gfx6_gfx7_gfx8_gfx9<bits<7> op> :
2878  SOPC_Real_gfx6_gfx7<op>, SOPC_Real_gfx8_gfx9<op>;
2879
2880multiclass SOPC_Real_gfx6_gfx7_gfx8_gfx9_gfx10_gfx11_gfx12<bits<7> op> :
2881  SOPC_Real_gfx6_gfx7_gfx8_gfx9<op>, SOPC_Real_gfx10<op>, SOPC_Real_gfx11<op>,
2882  SOPC_Real_gfx12<op>;
2883
2884defm S_CMP_EQ_I32     : SOPC_Real_gfx6_gfx7_gfx8_gfx9_gfx10_gfx11_gfx12<0x00>;
2885defm S_CMP_LG_I32     : SOPC_Real_gfx6_gfx7_gfx8_gfx9_gfx10_gfx11_gfx12<0x01>;
2886defm S_CMP_GT_I32     : SOPC_Real_gfx6_gfx7_gfx8_gfx9_gfx10_gfx11_gfx12<0x02>;
2887defm S_CMP_GE_I32     : SOPC_Real_gfx6_gfx7_gfx8_gfx9_gfx10_gfx11_gfx12<0x03>;
2888defm S_CMP_LT_I32     : SOPC_Real_gfx6_gfx7_gfx8_gfx9_gfx10_gfx11_gfx12<0x04>;
2889defm S_CMP_LE_I32     : SOPC_Real_gfx6_gfx7_gfx8_gfx9_gfx10_gfx11_gfx12<0x05>;
2890defm S_CMP_EQ_U32     : SOPC_Real_gfx6_gfx7_gfx8_gfx9_gfx10_gfx11_gfx12<0x06>;
2891defm S_CMP_LG_U32     : SOPC_Real_gfx6_gfx7_gfx8_gfx9_gfx10_gfx11_gfx12<0x07>;
2892defm S_CMP_GT_U32     : SOPC_Real_gfx6_gfx7_gfx8_gfx9_gfx10_gfx11_gfx12<0x08>;
2893defm S_CMP_GE_U32     : SOPC_Real_gfx6_gfx7_gfx8_gfx9_gfx10_gfx11_gfx12<0x09>;
2894defm S_CMP_LT_U32     : SOPC_Real_gfx6_gfx7_gfx8_gfx9_gfx10_gfx11_gfx12<0x0a>;
2895defm S_CMP_LE_U32     : SOPC_Real_gfx6_gfx7_gfx8_gfx9_gfx10_gfx11_gfx12<0x0b>;
2896defm S_BITCMP0_B32    : SOPC_Real_gfx6_gfx7_gfx8_gfx9_gfx10_gfx11_gfx12<0x0c>;
2897defm S_BITCMP1_B32    : SOPC_Real_gfx6_gfx7_gfx8_gfx9_gfx10_gfx11_gfx12<0x0d>;
2898defm S_BITCMP0_B64    : SOPC_Real_gfx6_gfx7_gfx8_gfx9_gfx10_gfx11_gfx12<0x0e>;
2899defm S_BITCMP1_B64    : SOPC_Real_gfx6_gfx7_gfx8_gfx9_gfx10_gfx11_gfx12<0x0f>;
2900defm S_SETVSKIP       : SOPC_Real_gfx6_gfx7_gfx8_gfx9<0x10>;
2901defm S_SET_GPR_IDX_ON : SOPC_Real_gfx8_gfx9<0x11>;
2902defm S_CMP_EQ_U64     : SOPC_Real_gfx8_gfx9_gfx10<0x12>;
2903defm S_CMP_LG_U64     : SOPC_Real_gfx8_gfx9_gfx10<0x13>;
2904
2905//===----------------------------------------------------------------------===//
2906// GFX8 (VI), GFX9.
2907//===----------------------------------------------------------------------===//
2908
2909class SOP1_Real_vi<bits<8> op, SOP1_Pseudo ps> :
2910  SOP1_Real<op, ps>,
2911  Select_vi<ps.PseudoInstr>;
2912
2913class SOP2_Real_vi<bits<7> op, SOP2_Pseudo ps> :
2914  SOP2_Real32<op, ps>,
2915  Select_vi<ps.PseudoInstr>;
2916
2917class SOPK_Real_vi<bits<5> op, SOPK_Pseudo ps> :
2918  SOPK_Real32<op, ps>,
2919  Select_vi<ps.PseudoInstr>;
2920
2921def S_MOV_B32_vi           : SOP1_Real_vi <0x00, S_MOV_B32>;
2922def S_MOV_B64_vi           : SOP1_Real_vi <0x01, S_MOV_B64>;
2923def S_CMOV_B32_vi          : SOP1_Real_vi <0x02, S_CMOV_B32>;
2924def S_CMOV_B64_vi          : SOP1_Real_vi <0x03, S_CMOV_B64>;
2925def S_NOT_B32_vi           : SOP1_Real_vi <0x04, S_NOT_B32>;
2926def S_NOT_B64_vi           : SOP1_Real_vi <0x05, S_NOT_B64>;
2927def S_WQM_B32_vi           : SOP1_Real_vi <0x06, S_WQM_B32>;
2928def S_WQM_B64_vi           : SOP1_Real_vi <0x07, S_WQM_B64>;
2929def S_BREV_B32_vi          : SOP1_Real_vi <0x08, S_BREV_B32>;
2930def S_BREV_B64_vi          : SOP1_Real_vi <0x09, S_BREV_B64>;
2931def S_BCNT0_I32_B32_vi     : SOP1_Real_vi <0x0a, S_BCNT0_I32_B32>;
2932def S_BCNT0_I32_B64_vi     : SOP1_Real_vi <0x0b, S_BCNT0_I32_B64>;
2933def S_BCNT1_I32_B32_vi     : SOP1_Real_vi <0x0c, S_BCNT1_I32_B32>;
2934def S_BCNT1_I32_B64_vi     : SOP1_Real_vi <0x0d, S_BCNT1_I32_B64>;
2935def S_FF0_I32_B32_vi       : SOP1_Real_vi <0x0e, S_FF0_I32_B32>;
2936def S_FF0_I32_B64_vi       : SOP1_Real_vi <0x0f, S_FF0_I32_B64>;
2937def S_FF1_I32_B32_vi       : SOP1_Real_vi <0x10, S_FF1_I32_B32>;
2938def S_FF1_I32_B64_vi       : SOP1_Real_vi <0x11, S_FF1_I32_B64>;
2939def S_FLBIT_I32_B32_vi     : SOP1_Real_vi <0x12, S_FLBIT_I32_B32>;
2940def S_FLBIT_I32_B64_vi     : SOP1_Real_vi <0x13, S_FLBIT_I32_B64>;
2941def S_FLBIT_I32_vi         : SOP1_Real_vi <0x14, S_FLBIT_I32>;
2942def S_FLBIT_I32_I64_vi     : SOP1_Real_vi <0x15, S_FLBIT_I32_I64>;
2943def S_SEXT_I32_I8_vi       : SOP1_Real_vi <0x16, S_SEXT_I32_I8>;
2944def S_SEXT_I32_I16_vi      : SOP1_Real_vi <0x17, S_SEXT_I32_I16>;
2945def S_BITSET0_B32_vi       : SOP1_Real_vi <0x18, S_BITSET0_B32>;
2946def S_BITSET0_B64_vi       : SOP1_Real_vi <0x19, S_BITSET0_B64>;
2947def S_BITSET1_B32_vi       : SOP1_Real_vi <0x1a, S_BITSET1_B32>;
2948def S_BITSET1_B64_vi       : SOP1_Real_vi <0x1b, S_BITSET1_B64>;
2949def S_GETPC_B64_vi         : SOP1_Real_vi <0x1c, S_GETPC_B64>;
2950def S_SETPC_B64_vi         : SOP1_Real_vi <0x1d, S_SETPC_B64>;
2951def S_SWAPPC_B64_vi        : SOP1_Real_vi <0x1e, S_SWAPPC_B64>;
2952def S_RFE_B64_vi           : SOP1_Real_vi <0x1f, S_RFE_B64>;
2953def S_AND_SAVEEXEC_B64_vi  : SOP1_Real_vi <0x20, S_AND_SAVEEXEC_B64>;
2954def S_OR_SAVEEXEC_B64_vi   : SOP1_Real_vi <0x21, S_OR_SAVEEXEC_B64>;
2955def S_XOR_SAVEEXEC_B64_vi  : SOP1_Real_vi <0x22, S_XOR_SAVEEXEC_B64>;
2956def S_ANDN2_SAVEEXEC_B64_vi: SOP1_Real_vi <0x23, S_ANDN2_SAVEEXEC_B64>;
2957def S_ORN2_SAVEEXEC_B64_vi : SOP1_Real_vi <0x24, S_ORN2_SAVEEXEC_B64>;
2958def S_NAND_SAVEEXEC_B64_vi : SOP1_Real_vi <0x25, S_NAND_SAVEEXEC_B64>;
2959def S_NOR_SAVEEXEC_B64_vi  : SOP1_Real_vi <0x26, S_NOR_SAVEEXEC_B64>;
2960def S_XNOR_SAVEEXEC_B64_vi : SOP1_Real_vi <0x27, S_XNOR_SAVEEXEC_B64>;
2961def S_QUADMASK_B32_vi      : SOP1_Real_vi <0x28, S_QUADMASK_B32>;
2962def S_QUADMASK_B64_vi      : SOP1_Real_vi <0x29, S_QUADMASK_B64>;
2963def S_MOVRELS_B32_vi       : SOP1_Real_vi <0x2a, S_MOVRELS_B32>;
2964def S_MOVRELS_B64_vi       : SOP1_Real_vi <0x2b, S_MOVRELS_B64>;
2965def S_MOVRELD_B32_vi       : SOP1_Real_vi <0x2c, S_MOVRELD_B32>;
2966def S_MOVRELD_B64_vi       : SOP1_Real_vi <0x2d, S_MOVRELD_B64>;
2967def S_CBRANCH_JOIN_vi      : SOP1_Real_vi <0x2e, S_CBRANCH_JOIN>;
2968def S_ABS_I32_vi           : SOP1_Real_vi <0x30, S_ABS_I32>;
2969def S_SET_GPR_IDX_IDX_vi   : SOP1_Real_vi <0x32, S_SET_GPR_IDX_IDX>;
2970
2971def S_ADD_U32_vi           : SOP2_Real_vi <0x00, S_ADD_U32>;
2972def S_ADD_I32_vi           : SOP2_Real_vi <0x02, S_ADD_I32>;
2973def S_SUB_U32_vi           : SOP2_Real_vi <0x01, S_SUB_U32>;
2974def S_SUB_I32_vi           : SOP2_Real_vi <0x03, S_SUB_I32>;
2975def S_ADDC_U32_vi          : SOP2_Real_vi <0x04, S_ADDC_U32>;
2976def S_SUBB_U32_vi          : SOP2_Real_vi <0x05, S_SUBB_U32>;
2977def S_MIN_I32_vi           : SOP2_Real_vi <0x06, S_MIN_I32>;
2978def S_MIN_U32_vi           : SOP2_Real_vi <0x07, S_MIN_U32>;
2979def S_MAX_I32_vi           : SOP2_Real_vi <0x08, S_MAX_I32>;
2980def S_MAX_U32_vi           : SOP2_Real_vi <0x09, S_MAX_U32>;
2981def S_CSELECT_B32_vi       : SOP2_Real_vi <0x0a, S_CSELECT_B32>;
2982def S_CSELECT_B64_vi       : SOP2_Real_vi <0x0b, S_CSELECT_B64>;
2983def S_AND_B32_vi           : SOP2_Real_vi <0x0c, S_AND_B32>;
2984def S_AND_B64_vi           : SOP2_Real_vi <0x0d, S_AND_B64>;
2985def S_OR_B32_vi            : SOP2_Real_vi <0x0e, S_OR_B32>;
2986def S_OR_B64_vi            : SOP2_Real_vi <0x0f, S_OR_B64>;
2987def S_XOR_B32_vi           : SOP2_Real_vi <0x10, S_XOR_B32>;
2988def S_XOR_B64_vi           : SOP2_Real_vi <0x11, S_XOR_B64>;
2989def S_ANDN2_B32_vi         : SOP2_Real_vi <0x12, S_ANDN2_B32>;
2990def S_ANDN2_B64_vi         : SOP2_Real_vi <0x13, S_ANDN2_B64>;
2991def S_ORN2_B32_vi          : SOP2_Real_vi <0x14, S_ORN2_B32>;
2992def S_ORN2_B64_vi          : SOP2_Real_vi <0x15, S_ORN2_B64>;
2993def S_NAND_B32_vi          : SOP2_Real_vi <0x16, S_NAND_B32>;
2994def S_NAND_B64_vi          : SOP2_Real_vi <0x17, S_NAND_B64>;
2995def S_NOR_B32_vi           : SOP2_Real_vi <0x18, S_NOR_B32>;
2996def S_NOR_B64_vi           : SOP2_Real_vi <0x19, S_NOR_B64>;
2997def S_XNOR_B32_vi          : SOP2_Real_vi <0x1a, S_XNOR_B32>;
2998def S_XNOR_B64_vi          : SOP2_Real_vi <0x1b, S_XNOR_B64>;
2999def S_LSHL_B32_vi          : SOP2_Real_vi <0x1c, S_LSHL_B32>;
3000def S_LSHL_B64_vi          : SOP2_Real_vi <0x1d, S_LSHL_B64>;
3001def S_LSHR_B32_vi          : SOP2_Real_vi <0x1e, S_LSHR_B32>;
3002def S_LSHR_B64_vi          : SOP2_Real_vi <0x1f, S_LSHR_B64>;
3003def S_ASHR_I32_vi          : SOP2_Real_vi <0x20, S_ASHR_I32>;
3004def S_ASHR_I64_vi          : SOP2_Real_vi <0x21, S_ASHR_I64>;
3005def S_BFM_B32_vi           : SOP2_Real_vi <0x22, S_BFM_B32>;
3006def S_BFM_B64_vi           : SOP2_Real_vi <0x23, S_BFM_B64>;
3007def S_MUL_I32_vi           : SOP2_Real_vi <0x24, S_MUL_I32>;
3008def S_BFE_U32_vi           : SOP2_Real_vi <0x25, S_BFE_U32>;
3009def S_BFE_I32_vi           : SOP2_Real_vi <0x26, S_BFE_I32>;
3010def S_BFE_U64_vi           : SOP2_Real_vi <0x27, S_BFE_U64>;
3011def S_BFE_I64_vi           : SOP2_Real_vi <0x28, S_BFE_I64>;
3012def S_CBRANCH_G_FORK_vi    : SOP2_Real_vi <0x29, S_CBRANCH_G_FORK>;
3013def S_ABSDIFF_I32_vi       : SOP2_Real_vi <0x2a, S_ABSDIFF_I32>;
3014def S_PACK_LL_B32_B16_vi   : SOP2_Real_vi <0x32, S_PACK_LL_B32_B16>;
3015def S_PACK_LH_B32_B16_vi   : SOP2_Real_vi <0x33, S_PACK_LH_B32_B16>;
3016def S_PACK_HH_B32_B16_vi   : SOP2_Real_vi <0x34, S_PACK_HH_B32_B16>;
3017def S_RFE_RESTORE_B64_vi   : SOP2_Real_vi <0x2b, S_RFE_RESTORE_B64>;
3018
3019def S_MOVK_I32_vi          : SOPK_Real_vi <0x00, S_MOVK_I32>;
3020def S_CMOVK_I32_vi         : SOPK_Real_vi <0x01, S_CMOVK_I32>;
3021def S_CMPK_EQ_I32_vi       : SOPK_Real_vi <0x02, S_CMPK_EQ_I32>;
3022def S_CMPK_LG_I32_vi       : SOPK_Real_vi <0x03, S_CMPK_LG_I32>;
3023def S_CMPK_GT_I32_vi       : SOPK_Real_vi <0x04, S_CMPK_GT_I32>;
3024def S_CMPK_GE_I32_vi       : SOPK_Real_vi <0x05, S_CMPK_GE_I32>;
3025def S_CMPK_LT_I32_vi       : SOPK_Real_vi <0x06, S_CMPK_LT_I32>;
3026def S_CMPK_LE_I32_vi       : SOPK_Real_vi <0x07, S_CMPK_LE_I32>;
3027def S_CMPK_EQ_U32_vi       : SOPK_Real_vi <0x08, S_CMPK_EQ_U32>;
3028def S_CMPK_LG_U32_vi       : SOPK_Real_vi <0x09, S_CMPK_LG_U32>;
3029def S_CMPK_GT_U32_vi       : SOPK_Real_vi <0x0A, S_CMPK_GT_U32>;
3030def S_CMPK_GE_U32_vi       : SOPK_Real_vi <0x0B, S_CMPK_GE_U32>;
3031def S_CMPK_LT_U32_vi       : SOPK_Real_vi <0x0C, S_CMPK_LT_U32>;
3032def S_CMPK_LE_U32_vi       : SOPK_Real_vi <0x0D, S_CMPK_LE_U32>;
3033def S_ADDK_I32_vi          : SOPK_Real_vi <0x0E, S_ADDK_I32>;
3034def S_MULK_I32_vi          : SOPK_Real_vi <0x0F, S_MULK_I32>;
3035def S_CBRANCH_I_FORK_vi    : SOPK_Real_vi <0x10, S_CBRANCH_I_FORK>;
3036def S_GETREG_B32_vi        : SOPK_Real_vi <0x11, S_GETREG_B32>;
3037def S_SETREG_B32_vi        : SOPK_Real_vi <0x12, S_SETREG_B32>;
3038//def S_GETREG_REGRD_B32_vi  : SOPK_Real_vi <0x13, S_GETREG_REGRD_B32>; // see pseudo for comments
3039def S_SETREG_IMM32_B32_vi  : SOPK_Real64<0x14, S_SETREG_IMM32_B32>,
3040                             Select_vi<S_SETREG_IMM32_B32.PseudoInstr>;
3041
3042def S_CALL_B64_vi          : SOPK_Real_vi <0x15, S_CALL_B64>;
3043
3044//===----------------------------------------------------------------------===//
3045// SOP1 - GFX9.
3046//===----------------------------------------------------------------------===//
3047
3048def S_ANDN1_SAVEEXEC_B64_vi   : SOP1_Real_vi<0x33, S_ANDN1_SAVEEXEC_B64>;
3049def S_ORN1_SAVEEXEC_B64_vi    : SOP1_Real_vi<0x34, S_ORN1_SAVEEXEC_B64>;
3050def S_ANDN1_WREXEC_B64_vi     : SOP1_Real_vi<0x35, S_ANDN1_WREXEC_B64>;
3051def S_ANDN2_WREXEC_B64_vi     : SOP1_Real_vi<0x36, S_ANDN2_WREXEC_B64>;
3052def S_BITREPLICATE_B64_B32_vi : SOP1_Real_vi<0x37, S_BITREPLICATE_B64_B32>;
3053
3054//===----------------------------------------------------------------------===//
3055// SOP2 - GFX9.
3056//===----------------------------------------------------------------------===//
3057
3058def S_LSHL1_ADD_U32_vi   : SOP2_Real_vi<0x2e, S_LSHL1_ADD_U32>;
3059def S_LSHL2_ADD_U32_vi   : SOP2_Real_vi<0x2f, S_LSHL2_ADD_U32>;
3060def S_LSHL3_ADD_U32_vi   : SOP2_Real_vi<0x30, S_LSHL3_ADD_U32>;
3061def S_LSHL4_ADD_U32_vi   : SOP2_Real_vi<0x31, S_LSHL4_ADD_U32>;
3062def S_MUL_HI_U32_vi      : SOP2_Real_vi<0x2c, S_MUL_HI_U32>;
3063def S_MUL_HI_I32_vi      : SOP2_Real_vi<0x2d, S_MUL_HI_I32>;
3064