1 //===-- SIInstructions.td - SI Instruction Defintions ---------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
8 // This file was originally auto-generated from a GPU register header file and
9 // all the instruction definitions were originally commented out. Instructions
10 // that are not yet supported remain commented out.
11 //===----------------------------------------------------------------------===//
13 class GCNPat<dag pattern, dag result> : Pat<pattern, result>, GCNPredicateControl {
17 include "SOPInstructions.td"
18 include "VOPInstructions.td"
19 include "SMInstructions.td"
20 include "FLATInstructions.td"
21 include "BUFInstructions.td"
23 //===----------------------------------------------------------------------===//
25 //===----------------------------------------------------------------------===//
27 defm EXP : EXP_m<0, AMDGPUexport>;
28 defm EXP_DONE : EXP_m<1, AMDGPUexport_done>;
30 //===----------------------------------------------------------------------===//
31 // VINTRP Instructions
32 //===----------------------------------------------------------------------===//
34 // Used to inject printing of "_e32" suffix for VI (there are "_e64" variants for VI)
35 def VINTRPDst : VINTRPDstOperand <VGPR_32>;
37 let Uses = [M0, EXEC] in {
39 // FIXME: Specify SchedRW for VINTRP insturctions.
41 multiclass V_INTERP_P1_F32_m : VINTRP_m <
43 (outs VINTRPDst:$vdst),
44 (ins VGPR_32:$vsrc, Attr:$attr, AttrChan:$attrchan),
45 "v_interp_p1_f32$vdst, $vsrc, $attr$attrchan",
46 [(set f32:$vdst, (AMDGPUinterp_p1 f32:$vsrc, (i32 imm:$attrchan),
50 let OtherPredicates = [has32BankLDS] in {
52 defm V_INTERP_P1_F32 : V_INTERP_P1_F32_m;
54 } // End OtherPredicates = [has32BankLDS]
56 let OtherPredicates = [has16BankLDS], Constraints = "@earlyclobber $vdst", isAsmParserOnly=1 in {
58 defm V_INTERP_P1_F32_16bank : V_INTERP_P1_F32_m;
60 } // End OtherPredicates = [has32BankLDS], Constraints = "@earlyclobber $vdst", isAsmParserOnly=1
62 let DisableEncoding = "$src0", Constraints = "$src0 = $vdst" in {
64 defm V_INTERP_P2_F32 : VINTRP_m <
66 (outs VINTRPDst:$vdst),
67 (ins VGPR_32:$src0, VGPR_32:$vsrc, Attr:$attr, AttrChan:$attrchan),
68 "v_interp_p2_f32$vdst, $vsrc, $attr$attrchan",
69 [(set f32:$vdst, (AMDGPUinterp_p2 f32:$src0, f32:$vsrc, (i32 imm:$attrchan),
72 } // End DisableEncoding = "$src0", Constraints = "$src0 = $vdst"
74 defm V_INTERP_MOV_F32 : VINTRP_m <
76 (outs VINTRPDst:$vdst),
77 (ins InterpSlot:$vsrc, Attr:$attr, AttrChan:$attrchan),
78 "v_interp_mov_f32$vdst, $vsrc, $attr$attrchan",
79 [(set f32:$vdst, (AMDGPUinterp_mov (i32 imm:$vsrc), (i32 imm:$attrchan),
82 } // End Uses = [M0, EXEC]
84 //===----------------------------------------------------------------------===//
85 // Pseudo Instructions
86 //===----------------------------------------------------------------------===//
87 def ATOMIC_FENCE : SPseudoInstSI<
88 (outs), (ins i32imm:$ordering, i32imm:$scope),
89 [(atomic_fence (i32 imm:$ordering), (i32 imm:$scope))],
90 "ATOMIC_FENCE $ordering, $scope"> {
91 let hasSideEffects = 1;
95 let hasSideEffects = 0, mayLoad = 0, mayStore = 0, Uses = [EXEC] in {
97 // For use in patterns
98 def V_CNDMASK_B64_PSEUDO : VOP3Common <(outs VReg_64:$vdst),
99 (ins VSrc_b64:$src0, VSrc_b64:$src1, SSrc_b64:$src2), "", []> {
101 let isCodeGenOnly = 1;
102 let usesCustomInserter = 1;
105 // 64-bit vector move instruction. This is mainly used by the
106 // SIFoldOperands pass to enable folding of inline immediates.
107 def V_MOV_B64_PSEUDO : VPseudoInstSI <(outs VReg_64:$vdst),
108 (ins VSrc_b64:$src0)>;
110 // Pseudoinstruction for @llvm.amdgcn.wqm. It is turned into a copy after the
111 // WQM pass processes it.
112 def WQM : PseudoInstSI <(outs unknown:$vdst), (ins unknown:$src0)>;
114 // Pseudoinstruction for @llvm.amdgcn.wwm. It is turned into a copy post-RA, so
115 // that the @earlyclobber is respected. The @earlyclobber is to make sure that
116 // the instruction that defines $src0 (which is run in WWM) doesn't
117 // accidentally clobber inactive channels of $vdst.
118 let Constraints = "@earlyclobber $vdst" in {
119 def WWM : PseudoInstSI <(outs unknown:$vdst), (ins unknown:$src0)>;
122 } // End let hasSideEffects = 0, mayLoad = 0, mayStore = 0, Uses = [EXEC]
124 def ENTER_WWM : SPseudoInstSI <(outs SReg_1:$sdst), (ins i64imm:$src0)> {
126 let hasSideEffects = 0;
131 def EXIT_WWM : SPseudoInstSI <(outs SReg_1:$sdst), (ins SReg_1:$src0)> {
132 let hasSideEffects = 0;
137 // Invert the exec mask and overwrite the inactive lanes of dst with inactive,
138 // restoring it after we're done.
139 def V_SET_INACTIVE_B32 : VPseudoInstSI <(outs VGPR_32:$vdst),
140 (ins VGPR_32: $src, VSrc_b32:$inactive),
141 [(set i32:$vdst, (int_amdgcn_set_inactive i32:$src, i32:$inactive))]> {
142 let Constraints = "$src = $vdst";
145 def V_SET_INACTIVE_B64 : VPseudoInstSI <(outs VReg_64:$vdst),
146 (ins VReg_64: $src, VSrc_b64:$inactive),
147 [(set i64:$vdst, (int_amdgcn_set_inactive i64:$src, i64:$inactive))]> {
148 let Constraints = "$src = $vdst";
152 let usesCustomInserter = 1, Defs = [SCC] in {
153 def S_ADD_U64_PSEUDO : SPseudoInstSI <
154 (outs SReg_64:$vdst), (ins SSrc_b64:$src0, SSrc_b64:$src1),
155 [(set SReg_64:$vdst, (add i64:$src0, i64:$src1))]
158 def S_SUB_U64_PSEUDO : SPseudoInstSI <
159 (outs SReg_64:$vdst), (ins SSrc_b64:$src0, SSrc_b64:$src1),
160 [(set SReg_64:$vdst, (sub i64:$src0, i64:$src1))]
163 def S_ADD_U64_CO_PSEUDO : SPseudoInstSI <
164 (outs SReg_64:$vdst, VOPDstS64orS32:$sdst), (ins SSrc_b64:$src0, SSrc_b64:$src1)
167 def S_SUB_U64_CO_PSEUDO : SPseudoInstSI <
168 (outs SReg_64:$vdst, VOPDstS64orS32:$sdst), (ins SSrc_b64:$src0, SSrc_b64:$src1)
170 } // End usesCustomInserter = 1, Defs = [SCC]
172 let usesCustomInserter = 1 in {
173 def GET_GROUPSTATICSIZE : SPseudoInstSI <(outs SReg_32:$sdst), (ins),
174 [(set SReg_32:$sdst, (int_amdgcn_groupstaticsize))]>;
175 } // End let usesCustomInserter = 1, SALU = 1
177 // Wrap an instruction by duplicating it, except for setting isTerminator.
178 class WrapTerminatorInst<SOP_Pseudo base_inst> : SPseudoInstSI<
179 base_inst.OutOperandList,
180 base_inst.InOperandList> {
181 let Uses = base_inst.Uses;
182 let Defs = base_inst.Defs;
183 let isTerminator = 1;
184 let isAsCheapAsAMove = base_inst.isAsCheapAsAMove;
185 let hasSideEffects = base_inst.hasSideEffects;
186 let UseNamedOperandTable = base_inst.UseNamedOperandTable;
187 let CodeSize = base_inst.CodeSize;
190 let WaveSizePredicate = isWave64 in {
191 def S_MOV_B64_term : WrapTerminatorInst<S_MOV_B64>;
192 def S_XOR_B64_term : WrapTerminatorInst<S_XOR_B64>;
193 def S_ANDN2_B64_term : WrapTerminatorInst<S_ANDN2_B64>;
196 let WaveSizePredicate = isWave32 in {
197 def S_MOV_B32_term : WrapTerminatorInst<S_MOV_B32>;
198 def S_XOR_B32_term : WrapTerminatorInst<S_XOR_B32>;
199 def S_OR_B32_term : WrapTerminatorInst<S_OR_B32>;
200 def S_ANDN2_B32_term : WrapTerminatorInst<S_ANDN2_B32>;
203 def WAVE_BARRIER : SPseudoInstSI<(outs), (ins),
204 [(int_amdgcn_wave_barrier)]> {
206 let hasNoSchedulingInfo = 1;
207 let hasSideEffects = 1;
210 let isConvergent = 1;
215 // SI pseudo instructions. These are used by the CFG structurizer pass
216 // and should be lowered to ISA instructions prior to codegen.
218 // Dummy terminator instruction to use after control flow instructions
219 // replaced with exec mask operations.
220 def SI_MASK_BRANCH : VPseudoInstSI <
221 (outs), (ins brtarget:$target)> {
223 let isTerminator = 1;
226 let hasNoSchedulingInfo = 1;
231 let isTerminator = 1 in {
233 let OtherPredicates = [EnableLateCFGStructurize] in {
234 def SI_NON_UNIFORM_BRCOND_PSEUDO : CFPseudoInstSI <
236 (ins SReg_1:$vcc, brtarget:$target),
237 [(brcond i1:$vcc, bb:$target)]> {
242 def SI_IF: CFPseudoInstSI <
243 (outs SReg_1:$dst), (ins SReg_1:$vcc, brtarget:$target),
244 [(set i1:$dst, (AMDGPUif i1:$vcc, bb:$target))], 1, 1> {
245 let Constraints = "";
247 let hasSideEffects = 1;
250 def SI_ELSE : CFPseudoInstSI <
252 (ins SReg_1:$src, brtarget:$target, i1imm:$execfix), [], 1, 1> {
254 let hasSideEffects = 1;
257 def SI_LOOP : CFPseudoInstSI <
258 (outs), (ins SReg_1:$saved, brtarget:$target),
259 [(AMDGPUloop i1:$saved, bb:$target)], 1, 1> {
262 let hasSideEffects = 1;
265 } // End isTerminator = 1
267 def SI_END_CF : CFPseudoInstSI <
268 (outs), (ins SReg_1:$saved), [], 1, 1> {
270 let isAsCheapAsAMove = 1;
271 let isReMaterializable = 1;
272 let hasSideEffects = 1;
273 let mayLoad = 1; // FIXME: Should not need memory flags
277 def SI_IF_BREAK : CFPseudoInstSI <
278 (outs SReg_1:$dst), (ins SReg_1:$vcc, SReg_1:$src), []> {
280 let isAsCheapAsAMove = 1;
281 let isReMaterializable = 1;
284 let Uses = [EXEC] in {
286 multiclass PseudoInstKill <dag ins> {
287 // Even though this pseudo can usually be expanded without an SCC def, we
288 // conservatively assume that it has an SCC def, both because it is sometimes
289 // required in degenerate cases (when V_CMPX cannot be used due to constant
290 // bus limitations) and because it allows us to avoid having to track SCC
291 // liveness across basic blocks.
292 let Defs = [EXEC,VCC,SCC] in
293 def _PSEUDO : PseudoInstSI <(outs), ins> {
294 let isConvergent = 1;
295 let usesCustomInserter = 1;
298 let Defs = [EXEC,VCC,SCC] in
299 def _TERMINATOR : SPseudoInstSI <(outs), ins> {
300 let isTerminator = 1;
304 defm SI_KILL_I1 : PseudoInstKill <(ins SCSrc_i1:$src, i1imm:$killvalue)>;
305 defm SI_KILL_F32_COND_IMM : PseudoInstKill <(ins VSrc_b32:$src0, i32imm:$src1, i32imm:$cond)>;
307 let Defs = [EXEC,VCC] in
308 def SI_ILLEGAL_COPY : SPseudoInstSI <
309 (outs unknown:$dst), (ins unknown:$src),
310 [], " ; illegal copy $src to $dst">;
312 } // End Uses = [EXEC], Defs = [EXEC,VCC]
314 // Branch on undef scc. Used to avoid intermediate copy from
315 // IMPLICIT_DEF to SCC.
316 def SI_BR_UNDEF : SPseudoInstSI <(outs), (ins sopp_brtarget:$simm16)> {
317 let isTerminator = 1;
318 let usesCustomInserter = 1;
322 def SI_PS_LIVE : PseudoInstSI <
323 (outs SReg_1:$dst), (ins),
324 [(set i1:$dst, (int_amdgcn_ps_live))]> {
328 def SI_MASKED_UNREACHABLE : SPseudoInstSI <(outs), (ins),
329 [(int_amdgcn_unreachable)],
330 "; divergent unreachable"> {
332 let hasNoSchedulingInfo = 1;
336 // Used as an isel pseudo to directly emit initialization with an
337 // s_mov_b32 rather than a copy of another initialized
338 // register. MachineCSE skips copies, and we don't want to have to
339 // fold operands before it runs.
340 def SI_INIT_M0 : SPseudoInstSI <(outs), (ins SSrc_b32:$src)> {
342 let usesCustomInserter = 1;
343 let isAsCheapAsAMove = 1;
344 let isReMaterializable = 1;
347 def SI_INIT_EXEC : SPseudoInstSI <
348 (outs), (ins i64imm:$src), []> {
350 let usesCustomInserter = 1;
351 let isAsCheapAsAMove = 1;
352 let WaveSizePredicate = isWave64;
355 def SI_INIT_EXEC_LO : SPseudoInstSI <
356 (outs), (ins i32imm:$src), []> {
357 let Defs = [EXEC_LO];
358 let usesCustomInserter = 1;
359 let isAsCheapAsAMove = 1;
360 let WaveSizePredicate = isWave32;
363 def SI_INIT_EXEC_FROM_INPUT : SPseudoInstSI <
364 (outs), (ins SSrc_b32:$input, i32imm:$shift), []> {
366 let usesCustomInserter = 1;
369 // Return for returning shaders to a shader variant epilog.
370 def SI_RETURN_TO_EPILOG : SPseudoInstSI <
371 (outs), (ins variable_ops), [(AMDGPUreturn_to_epilog)]> {
372 let isTerminator = 1;
375 let hasNoSchedulingInfo = 1;
380 // Return for returning function calls.
381 def SI_RETURN : SPseudoInstSI <
384 let isTerminator = 1;
387 let SchedRW = [WriteBranch];
390 // Return for returning function calls without output register.
392 // This version is only needed so we can fill in the output regiter in
393 // the custom inserter.
394 def SI_CALL_ISEL : SPseudoInstSI <
395 (outs), (ins SSrc_b64:$src0, unknown:$callee),
396 [(AMDGPUcall i64:$src0, tglobaladdr:$callee)]> {
399 let SchedRW = [WriteBranch];
400 let usesCustomInserter = 1;
401 // TODO: Should really base this on the call target
402 let isConvergent = 1;
405 // Wrapper around s_swappc_b64 with extra $callee parameter to track
406 // the called function after regalloc.
407 def SI_CALL : SPseudoInstSI <
408 (outs SReg_64:$dst), (ins SSrc_b64:$src0, unknown:$callee)> {
411 let UseNamedOperandTable = 1;
412 let SchedRW = [WriteBranch];
413 // TODO: Should really base this on the call target
414 let isConvergent = 1;
417 // Tail call handling pseudo
418 def SI_TCRETURN : SPseudoInstSI <(outs),
419 (ins SSrc_b64:$src0, unknown:$callee, i32imm:$fpdiff),
420 [(AMDGPUtc_return i64:$src0, tglobaladdr:$callee, i32:$fpdiff)]> {
423 let isTerminator = 1;
426 let UseNamedOperandTable = 1;
427 let SchedRW = [WriteBranch];
428 // TODO: Should really base this on the call target
429 let isConvergent = 1;
433 def ADJCALLSTACKUP : SPseudoInstSI<
434 (outs), (ins i32imm:$amt0, i32imm:$amt1),
435 [(callseq_start timm:$amt0, timm:$amt1)],
436 "; adjcallstackup $amt0 $amt1"> {
437 let Size = 8; // Worst case. (s_add_u32 + constant)
439 let hasSideEffects = 1;
440 let usesCustomInserter = 1;
441 let SchedRW = [WriteSALU];
445 def ADJCALLSTACKDOWN : SPseudoInstSI<
446 (outs), (ins i32imm:$amt1, i32imm:$amt2),
447 [(callseq_end timm:$amt1, timm:$amt2)],
448 "; adjcallstackdown $amt1"> {
449 let Size = 8; // Worst case. (s_add_u32 + constant)
450 let hasSideEffects = 1;
451 let usesCustomInserter = 1;
452 let SchedRW = [WriteSALU];
456 let Defs = [M0, EXEC, SCC],
457 UseNamedOperandTable = 1 in {
459 class SI_INDIRECT_SRC<RegisterClass rc> : VPseudoInstSI <
460 (outs VGPR_32:$vdst),
461 (ins rc:$src, VS_32:$idx, i32imm:$offset)> {
462 let usesCustomInserter = 1;
465 class SI_INDIRECT_DST<RegisterClass rc> : VPseudoInstSI <
467 (ins rc:$src, VS_32:$idx, i32imm:$offset, VGPR_32:$val)> {
468 let Constraints = "$src = $vdst";
469 let usesCustomInserter = 1;
472 // TODO: We can support indirect SGPR access.
473 def SI_INDIRECT_SRC_V1 : SI_INDIRECT_SRC<VGPR_32>;
474 def SI_INDIRECT_SRC_V2 : SI_INDIRECT_SRC<VReg_64>;
475 def SI_INDIRECT_SRC_V4 : SI_INDIRECT_SRC<VReg_128>;
476 def SI_INDIRECT_SRC_V8 : SI_INDIRECT_SRC<VReg_256>;
477 def SI_INDIRECT_SRC_V16 : SI_INDIRECT_SRC<VReg_512>;
479 def SI_INDIRECT_DST_V1 : SI_INDIRECT_DST<VGPR_32>;
480 def SI_INDIRECT_DST_V2 : SI_INDIRECT_DST<VReg_64>;
481 def SI_INDIRECT_DST_V4 : SI_INDIRECT_DST<VReg_128>;
482 def SI_INDIRECT_DST_V8 : SI_INDIRECT_DST<VReg_256>;
483 def SI_INDIRECT_DST_V16 : SI_INDIRECT_DST<VReg_512>;
485 } // End Uses = [EXEC], Defs = [M0, EXEC]
487 multiclass SI_SPILL_SGPR <RegisterClass sgpr_class> {
488 let UseNamedOperandTable = 1, SGPRSpill = 1, Uses = [EXEC] in {
489 def _SAVE : PseudoInstSI <
491 (ins sgpr_class:$data, i32imm:$addr)> {
496 def _RESTORE : PseudoInstSI <
497 (outs sgpr_class:$data),
498 (ins i32imm:$addr)> {
502 } // End UseNamedOperandTable = 1
505 // You cannot use M0 as the output of v_readlane_b32 instructions or
506 // use it in the sdata operand of SMEM instructions. We still need to
507 // be able to spill the physical register m0, so allow it for
508 // SI_SPILL_32_* instructions.
509 defm SI_SPILL_S32 : SI_SPILL_SGPR <SReg_32>;
510 defm SI_SPILL_S64 : SI_SPILL_SGPR <SReg_64>;
511 defm SI_SPILL_S96 : SI_SPILL_SGPR <SReg_96>;
512 defm SI_SPILL_S128 : SI_SPILL_SGPR <SReg_128>;
513 defm SI_SPILL_S160 : SI_SPILL_SGPR <SReg_160>;
514 defm SI_SPILL_S256 : SI_SPILL_SGPR <SReg_256>;
515 defm SI_SPILL_S512 : SI_SPILL_SGPR <SReg_512>;
516 defm SI_SPILL_S1024 : SI_SPILL_SGPR <SReg_1024>;
518 multiclass SI_SPILL_VGPR <RegisterClass vgpr_class> {
519 let UseNamedOperandTable = 1, VGPRSpill = 1,
520 SchedRW = [WriteVMEM] in {
521 def _SAVE : VPseudoInstSI <
523 (ins vgpr_class:$vdata, i32imm:$vaddr, SReg_128:$srsrc,
524 SReg_32:$soffset, i32imm:$offset)> {
527 // (2 * 4) + (8 * num_subregs) bytes maximum
528 int MaxSize = !add(!shl(!srl(vgpr_class.Size, 5), 3), 8);
529 // Size field is unsigned char and cannot fit more.
530 let Size = !if(!le(MaxSize, 256), MaxSize, 252);
533 def _RESTORE : VPseudoInstSI <
534 (outs vgpr_class:$vdata),
535 (ins i32imm:$vaddr, SReg_128:$srsrc, SReg_32:$soffset,
540 // (2 * 4) + (8 * num_subregs) bytes maximum
541 int MaxSize = !add(!shl(!srl(vgpr_class.Size, 5), 3), 8);
542 // Size field is unsigned char and cannot fit more.
543 let Size = !if(!le(MaxSize, 256), MaxSize, 252);
545 } // End UseNamedOperandTable = 1, VGPRSpill = 1, SchedRW = [WriteVMEM]
548 defm SI_SPILL_V32 : SI_SPILL_VGPR <VGPR_32>;
549 defm SI_SPILL_V64 : SI_SPILL_VGPR <VReg_64>;
550 defm SI_SPILL_V96 : SI_SPILL_VGPR <VReg_96>;
551 defm SI_SPILL_V128 : SI_SPILL_VGPR <VReg_128>;
552 defm SI_SPILL_V160 : SI_SPILL_VGPR <VReg_160>;
553 defm SI_SPILL_V256 : SI_SPILL_VGPR <VReg_256>;
554 defm SI_SPILL_V512 : SI_SPILL_VGPR <VReg_512>;
555 defm SI_SPILL_V1024 : SI_SPILL_VGPR <VReg_1024>;
557 multiclass SI_SPILL_AGPR <RegisterClass vgpr_class> {
558 let UseNamedOperandTable = 1, VGPRSpill = 1,
559 Constraints = "@earlyclobber $tmp",
560 SchedRW = [WriteVMEM] in {
561 def _SAVE : VPseudoInstSI <
563 (ins vgpr_class:$vdata, i32imm:$vaddr, SReg_128:$srsrc,
564 SReg_32:$soffset, i32imm:$offset)> {
567 // (2 * 4) + (16 * num_subregs) bytes maximum
568 int MaxSize = !add(!shl(!srl(vgpr_class.Size, 5), 4), 8);
569 // Size field is unsigned char and cannot fit more.
570 let Size = !if(!le(MaxSize, 256), MaxSize, 252);
573 def _RESTORE : VPseudoInstSI <
574 (outs vgpr_class:$vdata, VGPR_32:$tmp),
575 (ins i32imm:$vaddr, SReg_128:$srsrc, SReg_32:$soffset,
580 // (2 * 4) + (16 * num_subregs) bytes maximum
581 int MaxSize = !add(!shl(!srl(vgpr_class.Size, 5), 4), 8);
582 // Size field is unsigned char and cannot fit more.
583 let Size = !if(!le(MaxSize, 256), MaxSize, 252);
585 } // End UseNamedOperandTable = 1, VGPRSpill = 1, SchedRW = [WriteVMEM]
588 defm SI_SPILL_A32 : SI_SPILL_AGPR <AGPR_32>;
589 defm SI_SPILL_A64 : SI_SPILL_AGPR <AReg_64>;
590 defm SI_SPILL_A128 : SI_SPILL_AGPR <AReg_128>;
591 defm SI_SPILL_A512 : SI_SPILL_AGPR <AReg_512>;
592 defm SI_SPILL_A1024 : SI_SPILL_AGPR <AReg_1024>;
594 def SI_PC_ADD_REL_OFFSET : SPseudoInstSI <
596 (ins si_ga:$ptr_lo, si_ga:$ptr_hi),
598 (i64 (SIpc_add_rel_offset tglobaladdr:$ptr_lo, tglobaladdr:$ptr_hi)))]> {
603 (SIpc_add_rel_offset tglobaladdr:$ptr_lo, 0),
604 (SI_PC_ADD_REL_OFFSET $ptr_lo, (i32 0))
608 (AMDGPUinit_exec i64:$src),
609 (SI_INIT_EXEC (as_i64imm $src))
611 let WaveSizePredicate = isWave64;
615 (AMDGPUinit_exec i64:$src),
616 (SI_INIT_EXEC_LO (as_i32imm $src))
618 let WaveSizePredicate = isWave32;
622 (AMDGPUinit_exec_from_input i32:$input, i32:$shift),
623 (SI_INIT_EXEC_FROM_INPUT (i32 $input), (as_i32imm $shift))
627 (AMDGPUtrap timm:$trapid),
632 (AMDGPUelse i1:$src, bb:$target),
633 (SI_ELSE $src, $target, 0)
637 // -1.0 as i32 (LowerINTRINSIC_VOID converts all other constants to -1.0)
638 (AMDGPUkill (i32 -1082130432)),
639 (SI_KILL_I1_PSEUDO (i1 0), 0)
643 (int_amdgcn_kill i1:$src),
644 (SI_KILL_I1_PSEUDO $src, 0)
648 (int_amdgcn_kill (i1 (not i1:$src))),
649 (SI_KILL_I1_PSEUDO $src, -1)
653 (AMDGPUkill i32:$src),
654 (SI_KILL_F32_COND_IMM_PSEUDO $src, 0, 3) // 3 means SETOGE
658 (int_amdgcn_kill (i1 (setcc f32:$src, InlineFPImm<f32>:$imm, cond:$cond))),
659 (SI_KILL_F32_COND_IMM_PSEUDO $src, (bitcast_fpimm_to_i32 $imm), (cond_as_i32imm $cond))
662 // TODO: we could add more variants for other types of conditionals
665 (i64 (int_amdgcn_icmp i1:$src, (i1 0), (i32 33))),
666 (COPY $src) // Return the SGPRs representing i1 src
670 (i32 (int_amdgcn_icmp i1:$src, (i1 0), (i32 33))),
671 (COPY $src) // Return the SGPRs representing i1 src
674 //===----------------------------------------------------------------------===//
676 //===----------------------------------------------------------------------===//
678 let OtherPredicates = [UnsafeFPMath] in {
680 //def : RcpPat<V_RCP_F64_e32, f64>;
681 //defm : RsqPat<V_RSQ_F64_e32, f64>;
682 //defm : RsqPat<V_RSQ_F32_e32, f32>;
684 def : RsqPat<V_RSQ_F32_e32, f32>;
685 def : RsqPat<V_RSQ_F64_e32, f64>;
687 // Convert (x - floor(x)) to fract(x)
689 (f32 (fsub (f32 (VOP3Mods f32:$x, i32:$mods)),
690 (f32 (ffloor (f32 (VOP3Mods f32:$x, i32:$mods)))))),
691 (V_FRACT_F32_e64 $mods, $x, DSTCLAMP.NONE, DSTOMOD.NONE)
694 // Convert (x + (-floor(x))) to fract(x)
696 (f64 (fadd (f64 (VOP3Mods f64:$x, i32:$mods)),
697 (f64 (fneg (f64 (ffloor (f64 (VOP3Mods f64:$x, i32:$mods)))))))),
698 (V_FRACT_F64_e64 $mods, $x, DSTCLAMP.NONE, DSTOMOD.NONE)
701 } // End OtherPredicates = [UnsafeFPMath]
704 // f16_to_fp patterns
706 (f32 (f16_to_fp i32:$src0)),
707 (V_CVT_F32_F16_e64 SRCMODS.NONE, $src0, DSTCLAMP.NONE, DSTOMOD.NONE)
711 (f32 (f16_to_fp (and_oneuse i32:$src0, 0x7fff))),
712 (V_CVT_F32_F16_e64 SRCMODS.ABS, $src0, DSTCLAMP.NONE, DSTOMOD.NONE)
716 (f32 (f16_to_fp (i32 (srl_oneuse (and_oneuse i32:$src0, 0x7fff0000), (i32 16))))),
717 (V_CVT_F32_F16_e64 SRCMODS.ABS, (i32 (V_LSHRREV_B32_e64 (i32 16), i32:$src0)), DSTCLAMP.NONE, DSTOMOD.NONE)
721 (f32 (f16_to_fp (or_oneuse i32:$src0, 0x8000))),
722 (V_CVT_F32_F16_e64 SRCMODS.NEG_ABS, $src0, DSTCLAMP.NONE, DSTOMOD.NONE)
726 (f32 (f16_to_fp (xor_oneuse i32:$src0, 0x8000))),
727 (V_CVT_F32_F16_e64 SRCMODS.NEG, $src0, DSTCLAMP.NONE, DSTOMOD.NONE)
731 (f64 (fpextend f16:$src)),
732 (V_CVT_F64_F32_e32 (V_CVT_F32_F16_e32 $src))
735 // fp_to_fp16 patterns
737 (i32 (AMDGPUfp_to_f16 (f32 (VOP3Mods f32:$src0, i32:$src0_modifiers)))),
738 (V_CVT_F16_F32_e64 $src0_modifiers, f32:$src0, DSTCLAMP.NONE, DSTOMOD.NONE)
742 (i32 (fp_to_sint f16:$src)),
743 (V_CVT_I32_F32_e32 (V_CVT_F32_F16_e32 $src))
747 (i32 (fp_to_uint f16:$src)),
748 (V_CVT_U32_F32_e32 (V_CVT_F32_F16_e32 $src))
752 (f16 (sint_to_fp i32:$src)),
753 (V_CVT_F16_F32_e32 (V_CVT_F32_I32_e32 $src))
757 (f16 (uint_to_fp i32:$src)),
758 (V_CVT_F16_F32_e32 (V_CVT_F32_U32_e32 $src))
761 //===----------------------------------------------------------------------===//
763 //===----------------------------------------------------------------------===//
765 multiclass FMADPat <ValueType vt, Instruction inst> {
767 (vt (fmad (VOP3NoMods vt:$src0),
768 (VOP3NoMods vt:$src1),
769 (VOP3NoMods vt:$src2))),
770 (inst SRCMODS.NONE, $src0, SRCMODS.NONE, $src1,
771 SRCMODS.NONE, $src2, DSTCLAMP.NONE, DSTOMOD.NONE)
775 defm : FMADPat <f16, V_MAC_F16_e64>;
776 defm : FMADPat <f32, V_MAC_F32_e64>;
778 class FMADModsPat<Instruction inst, SDPatternOperator mad_opr, ValueType Ty>
780 (Ty (mad_opr (VOP3Mods Ty:$src0, i32:$src0_mod),
781 (VOP3Mods Ty:$src1, i32:$src1_mod),
782 (VOP3Mods Ty:$src2, i32:$src2_mod))),
783 (inst $src0_mod, $src0, $src1_mod, $src1,
784 $src2_mod, $src2, DSTCLAMP.NONE, DSTOMOD.NONE)
787 def : FMADModsPat<V_MAD_F32, AMDGPUfmad_ftz, f32>;
788 def : FMADModsPat<V_MAD_F16, AMDGPUfmad_ftz, f16> {
789 let SubtargetPredicate = Has16BitInsts;
792 multiclass SelectPat <ValueType vt> {
794 (vt (select i1:$src0, (VOP3Mods_f32 vt:$src1, i32:$src1_mods),
795 (VOP3Mods_f32 vt:$src2, i32:$src2_mods))),
796 (V_CNDMASK_B32_e64 $src2_mods, $src2, $src1_mods, $src1, $src0)
800 defm : SelectPat <i16>;
801 defm : SelectPat <i32>;
802 defm : SelectPat <f16>;
803 defm : SelectPat <f32>;
805 let AddedComplexity = 1 in {
807 (i32 (add (i32 (getDivergentFrag<ctpop>.ret i32:$popcnt)), i32:$val)),
808 (V_BCNT_U32_B32_e64 $popcnt, $val)
812 (i16 (add (i16 (trunc (getDivergentFrag<ctpop>.ret i32:$popcnt))), i16:$val)),
813 (V_BCNT_U32_B32_e64 $popcnt, $val)
816 /********** ============================================ **********/
817 /********** Extraction, Insertion, Building and Casting **********/
818 /********** ============================================ **********/
820 foreach Index = 0-2 in {
821 def Extract_Element_v2i32_#Index : Extract_Element <
822 i32, v2i32, Index, !cast<SubRegIndex>(sub#Index)
824 def Insert_Element_v2i32_#Index : Insert_Element <
825 i32, v2i32, Index, !cast<SubRegIndex>(sub#Index)
828 def Extract_Element_v2f32_#Index : Extract_Element <
829 f32, v2f32, Index, !cast<SubRegIndex>(sub#Index)
831 def Insert_Element_v2f32_#Index : Insert_Element <
832 f32, v2f32, Index, !cast<SubRegIndex>(sub#Index)
836 foreach Index = 0-2 in {
837 def Extract_Element_v3i32_#Index : Extract_Element <
838 i32, v3i32, Index, !cast<SubRegIndex>(sub#Index)
840 def Insert_Element_v3i32_#Index : Insert_Element <
841 i32, v3i32, Index, !cast<SubRegIndex>(sub#Index)
844 def Extract_Element_v3f32_#Index : Extract_Element <
845 f32, v3f32, Index, !cast<SubRegIndex>(sub#Index)
847 def Insert_Element_v3f32_#Index : Insert_Element <
848 f32, v3f32, Index, !cast<SubRegIndex>(sub#Index)
852 foreach Index = 0-3 in {
853 def Extract_Element_v4i32_#Index : Extract_Element <
854 i32, v4i32, Index, !cast<SubRegIndex>(sub#Index)
856 def Insert_Element_v4i32_#Index : Insert_Element <
857 i32, v4i32, Index, !cast<SubRegIndex>(sub#Index)
860 def Extract_Element_v4f32_#Index : Extract_Element <
861 f32, v4f32, Index, !cast<SubRegIndex>(sub#Index)
863 def Insert_Element_v4f32_#Index : Insert_Element <
864 f32, v4f32, Index, !cast<SubRegIndex>(sub#Index)
868 foreach Index = 0-4 in {
869 def Extract_Element_v5i32_#Index : Extract_Element <
870 i32, v5i32, Index, !cast<SubRegIndex>(sub#Index)
872 def Insert_Element_v5i32_#Index : Insert_Element <
873 i32, v5i32, Index, !cast<SubRegIndex>(sub#Index)
876 def Extract_Element_v5f32_#Index : Extract_Element <
877 f32, v5f32, Index, !cast<SubRegIndex>(sub#Index)
879 def Insert_Element_v5f32_#Index : Insert_Element <
880 f32, v5f32, Index, !cast<SubRegIndex>(sub#Index)
884 foreach Index = 0-7 in {
885 def Extract_Element_v8i32_#Index : Extract_Element <
886 i32, v8i32, Index, !cast<SubRegIndex>(sub#Index)
888 def Insert_Element_v8i32_#Index : Insert_Element <
889 i32, v8i32, Index, !cast<SubRegIndex>(sub#Index)
892 def Extract_Element_v8f32_#Index : Extract_Element <
893 f32, v8f32, Index, !cast<SubRegIndex>(sub#Index)
895 def Insert_Element_v8f32_#Index : Insert_Element <
896 f32, v8f32, Index, !cast<SubRegIndex>(sub#Index)
900 foreach Index = 0-15 in {
901 def Extract_Element_v16i32_#Index : Extract_Element <
902 i32, v16i32, Index, !cast<SubRegIndex>(sub#Index)
904 def Insert_Element_v16i32_#Index : Insert_Element <
905 i32, v16i32, Index, !cast<SubRegIndex>(sub#Index)
908 def Extract_Element_v16f32_#Index : Extract_Element <
909 f32, v16f32, Index, !cast<SubRegIndex>(sub#Index)
911 def Insert_Element_v16f32_#Index : Insert_Element <
912 f32, v16f32, Index, !cast<SubRegIndex>(sub#Index)
918 (extract_subvector v4i16:$vec, (i32 0)),
919 (v2i16 (EXTRACT_SUBREG v4i16:$vec, sub0))
923 (extract_subvector v4i16:$vec, (i32 2)),
924 (v2i16 (EXTRACT_SUBREG v4i16:$vec, sub1))
928 (extract_subvector v4f16:$vec, (i32 0)),
929 (v2f16 (EXTRACT_SUBREG v4f16:$vec, sub0))
933 (extract_subvector v4f16:$vec, (i32 2)),
934 (v2f16 (EXTRACT_SUBREG v4f16:$vec, sub1))
937 foreach Index = 0-31 in {
938 def Extract_Element_v32i32_#Index : Extract_Element <
939 i32, v32i32, Index, !cast<SubRegIndex>(sub#Index)
942 def Insert_Element_v32i32_#Index : Insert_Element <
943 i32, v32i32, Index, !cast<SubRegIndex>(sub#Index)
946 def Extract_Element_v32f32_#Index : Extract_Element <
947 f32, v32f32, Index, !cast<SubRegIndex>(sub#Index)
950 def Insert_Element_v32f32_#Index : Insert_Element <
951 f32, v32f32, Index, !cast<SubRegIndex>(sub#Index)
955 // FIXME: Why do only some of these type combinations for SReg and
958 def : BitConvert <i16, f16, VGPR_32>;
959 def : BitConvert <f16, i16, VGPR_32>;
960 def : BitConvert <i16, f16, SReg_32>;
961 def : BitConvert <f16, i16, SReg_32>;
964 def : BitConvert <i32, f32, VGPR_32>;
965 def : BitConvert <f32, i32, VGPR_32>;
966 def : BitConvert <i32, f32, SReg_32>;
967 def : BitConvert <f32, i32, SReg_32>;
968 def : BitConvert <v2i16, i32, SReg_32>;
969 def : BitConvert <i32, v2i16, SReg_32>;
970 def : BitConvert <v2f16, i32, SReg_32>;
971 def : BitConvert <i32, v2f16, SReg_32>;
972 def : BitConvert <v2i16, v2f16, SReg_32>;
973 def : BitConvert <v2f16, v2i16, SReg_32>;
974 def : BitConvert <v2f16, f32, SReg_32>;
975 def : BitConvert <f32, v2f16, SReg_32>;
976 def : BitConvert <v2i16, f32, SReg_32>;
977 def : BitConvert <f32, v2i16, SReg_32>;
980 def : BitConvert <i64, f64, VReg_64>;
981 def : BitConvert <f64, i64, VReg_64>;
982 def : BitConvert <v2i32, v2f32, VReg_64>;
983 def : BitConvert <v2f32, v2i32, VReg_64>;
984 def : BitConvert <i64, v2i32, VReg_64>;
985 def : BitConvert <v2i32, i64, VReg_64>;
986 def : BitConvert <i64, v2f32, VReg_64>;
987 def : BitConvert <v2f32, i64, VReg_64>;
988 def : BitConvert <f64, v2f32, VReg_64>;
989 def : BitConvert <v2f32, f64, VReg_64>;
990 def : BitConvert <f64, v2i32, VReg_64>;
991 def : BitConvert <v2i32, f64, VReg_64>;
992 def : BitConvert <v4i16, v4f16, VReg_64>;
993 def : BitConvert <v4f16, v4i16, VReg_64>;
996 def : BitConvert <v2i32, v4f16, VReg_64>;
997 def : BitConvert <v4f16, v2i32, VReg_64>;
998 def : BitConvert <v2i32, v4f16, VReg_64>;
999 def : BitConvert <v2i32, v4i16, VReg_64>;
1000 def : BitConvert <v4i16, v2i32, VReg_64>;
1001 def : BitConvert <v2f32, v4f16, VReg_64>;
1002 def : BitConvert <v4f16, v2f32, VReg_64>;
1003 def : BitConvert <v2f32, v4i16, VReg_64>;
1004 def : BitConvert <v4i16, v2f32, VReg_64>;
1005 def : BitConvert <v4i16, f64, VReg_64>;
1006 def : BitConvert <v4f16, f64, VReg_64>;
1007 def : BitConvert <f64, v4i16, VReg_64>;
1008 def : BitConvert <f64, v4f16, VReg_64>;
1009 def : BitConvert <v4i16, i64, VReg_64>;
1010 def : BitConvert <v4f16, i64, VReg_64>;
1011 def : BitConvert <i64, v4i16, VReg_64>;
1012 def : BitConvert <i64, v4f16, VReg_64>;
1014 def : BitConvert <v4i32, v4f32, VReg_128>;
1015 def : BitConvert <v4f32, v4i32, VReg_128>;
1018 def : BitConvert <v3i32, v3f32, SGPR_96>;
1019 def : BitConvert <v3f32, v3i32, SGPR_96>;
1022 def : BitConvert <v2i64, v4i32, SReg_128>;
1023 def : BitConvert <v4i32, v2i64, SReg_128>;
1024 def : BitConvert <v2f64, v4f32, VReg_128>;
1025 def : BitConvert <v2f64, v4i32, VReg_128>;
1026 def : BitConvert <v4f32, v2f64, VReg_128>;
1027 def : BitConvert <v4i32, v2f64, VReg_128>;
1028 def : BitConvert <v2i64, v2f64, VReg_128>;
1029 def : BitConvert <v2f64, v2i64, VReg_128>;
1032 def : BitConvert <v5i32, v5f32, SGPR_160>;
1033 def : BitConvert <v5f32, v5i32, SGPR_160>;
1036 def : BitConvert <v8i32, v8f32, SReg_256>;
1037 def : BitConvert <v8f32, v8i32, SReg_256>;
1038 def : BitConvert <v8i32, v8f32, VReg_256>;
1039 def : BitConvert <v8f32, v8i32, VReg_256>;
1042 def : BitConvert <v16i32, v16f32, VReg_512>;
1043 def : BitConvert <v16f32, v16i32, VReg_512>;
1046 def : BitConvert <v32i32, v32f32, VReg_1024>;
1047 def : BitConvert <v32f32, v32i32, VReg_1024>;
1049 /********** =================== **********/
1050 /********** Src & Dst modifiers **********/
1051 /********** =================== **********/
1054 // If denormals are not enabled, it only impacts the compare of the
1055 // inputs. The output result is not flushed.
1056 class ClampPat<Instruction inst, ValueType vt> : GCNPat <
1057 (vt (AMDGPUclamp (VOP3Mods vt:$src0, i32:$src0_modifiers))),
1058 (inst i32:$src0_modifiers, vt:$src0,
1059 i32:$src0_modifiers, vt:$src0, DSTCLAMP.ENABLE, DSTOMOD.NONE)
1062 def : ClampPat<V_MAX_F32_e64, f32>;
1063 def : ClampPat<V_MAX_F64, f64>;
1064 def : ClampPat<V_MAX_F16_e64, f16>;
1066 let SubtargetPredicate = HasVOP3PInsts in {
1068 (v2f16 (AMDGPUclamp (VOP3PMods v2f16:$src0, i32:$src0_modifiers))),
1069 (V_PK_MAX_F16 $src0_modifiers, $src0,
1070 $src0_modifiers, $src0, DSTCLAMP.ENABLE)
1074 /********** ================================ **********/
1075 /********** Floating point absolute/negative **********/
1076 /********** ================================ **********/
1078 // Prevent expanding both fneg and fabs.
1081 (fneg (fabs f32:$src)),
1082 (S_OR_B32 $src, (S_MOV_B32(i32 0x80000000))) // Set sign bit
1085 // FIXME: Should use S_OR_B32
1087 (fneg (fabs f64:$src)),
1088 (REG_SEQUENCE VReg_64,
1089 (i32 (EXTRACT_SUBREG f64:$src, sub0)),
1091 (V_OR_B32_e32 (i32 (EXTRACT_SUBREG f64:$src, sub1)),
1092 (V_MOV_B32_e32 (i32 0x80000000))), // Set sign bit.
1098 (S_AND_B32 $src, (S_MOV_B32 (i32 0x7fffffff)))
1103 (V_XOR_B32_e32 $src, (V_MOV_B32_e32 (i32 0x80000000)))
1108 (REG_SEQUENCE VReg_64,
1109 (i32 (EXTRACT_SUBREG f64:$src, sub0)),
1111 (V_AND_B32_e64 (i32 (EXTRACT_SUBREG f64:$src, sub1)),
1112 (V_MOV_B32_e32 (i32 0x7fffffff))), // Set sign bit.
1118 (REG_SEQUENCE VReg_64,
1119 (i32 (EXTRACT_SUBREG f64:$src, sub0)),
1121 (V_XOR_B32_e32 (i32 (EXTRACT_SUBREG f64:$src, sub1)),
1122 (i32 (V_MOV_B32_e32 (i32 0x80000000)))),
1127 (fcopysign f16:$src0, f16:$src1),
1128 (V_BFI_B32 (S_MOV_B32 (i32 0x00007fff)), $src0, $src1)
1132 (fcopysign f32:$src0, f16:$src1),
1133 (V_BFI_B32 (S_MOV_B32 (i32 0x7fffffff)), $src0,
1134 (V_LSHLREV_B32_e64 (i32 16), $src1))
1138 (fcopysign f64:$src0, f16:$src1),
1139 (REG_SEQUENCE SReg_64,
1140 (i32 (EXTRACT_SUBREG $src0, sub0)), sub0,
1141 (V_BFI_B32 (S_MOV_B32 (i32 0x7fffffff)), (i32 (EXTRACT_SUBREG $src0, sub1)),
1142 (V_LSHLREV_B32_e64 (i32 16), $src1)), sub1)
1146 (fcopysign f16:$src0, f32:$src1),
1147 (V_BFI_B32 (S_MOV_B32 (i32 0x00007fff)), $src0,
1148 (V_LSHRREV_B32_e64 (i32 16), $src1))
1152 (fcopysign f16:$src0, f64:$src1),
1153 (V_BFI_B32 (S_MOV_B32 (i32 0x00007fff)), $src0,
1154 (V_LSHRREV_B32_e64 (i32 16), (EXTRACT_SUBREG $src1, sub1)))
1159 (S_XOR_B32 $src, (S_MOV_B32 (i32 0x00008000)))
1164 (S_AND_B32 $src, (S_MOV_B32 (i32 0x00007fff)))
1168 (fneg (fabs f16:$src)),
1169 (S_OR_B32 $src, (S_MOV_B32 (i32 0x00008000))) // Set sign bit
1174 (S_XOR_B32 $src, (S_MOV_B32 (i32 0x80008000)))
1179 (S_AND_B32 $src, (S_MOV_B32 (i32 0x7fff7fff)))
1182 // This is really (fneg (fabs v2f16:$src))
1184 // fabs is not reported as free because there is modifier for it in
1185 // VOP3P instructions, so it is turned into the bit op.
1187 (fneg (v2f16 (bitconvert (and_oneuse i32:$src, 0x7fff7fff)))),
1188 (S_OR_B32 $src, (S_MOV_B32 (i32 0x80008000))) // Set sign bit
1192 (fneg (v2f16 (fabs v2f16:$src))),
1193 (S_OR_B32 $src, (S_MOV_B32 (i32 0x80008000))) // Set sign bit
1196 /********** ================== **********/
1197 /********** Immediate Patterns **********/
1198 /********** ================== **********/
1201 (VGPRImm<(i32 imm)>:$imm),
1202 (V_MOV_B32_e32 imm:$imm)
1206 (VGPRImm<(f32 fpimm)>:$imm),
1207 (V_MOV_B32_e32 (f32 (bitcast_fpimm_to_i32 $imm)))
1212 (S_MOV_B32 imm:$imm)
1216 (VGPRImm<(SIlds tglobaladdr:$ga)>),
1221 (SIlds tglobaladdr:$ga),
1225 // FIXME: Workaround for ordering issue with peephole optimizer where
1226 // a register class copy interferes with immediate folding. Should
1227 // use s_mov_b32, which can be shrunk to s_movk_i32
1229 (VGPRImm<(f16 fpimm)>:$imm),
1230 (V_MOV_B32_e32 (f16 (bitcast_fpimm_to_i32 $imm)))
1235 (S_MOV_B32 (f32 (bitcast_fpimm_to_i32 $imm)))
1240 (S_MOV_B32 (i32 (bitcast_fpimm_to_i32 $imm)))
1244 (i32 frameindex:$fi),
1245 (V_MOV_B32_e32 (i32 (frameindex_to_targetframeindex $fi)))
1249 (i64 InlineImm<i64>:$imm),
1250 (S_MOV_B64 InlineImm<i64>:$imm)
1253 // XXX - Should this use a s_cmp to set SCC?
1255 // Set to sign-extended 64-bit value (true = -1, false = 0)
1258 (S_MOV_B64 (i64 (as_i64imm $imm)))
1260 let WaveSizePredicate = isWave64;
1265 (S_MOV_B32 (i32 (as_i32imm $imm)))
1267 let WaveSizePredicate = isWave32;
1271 (f64 InlineFPImm<f64>:$imm),
1272 (S_MOV_B64 (f64 (bitcast_fpimm_to_i64 InlineFPImm<f64>:$imm)))
1275 /********** ================== **********/
1276 /********** Intrinsic Patterns **********/
1277 /********** ================== **********/
1279 def : POW_Common <V_LOG_F32_e32, V_EXP_F32_e32, V_MUL_LEGACY_F32_e32>;
1282 (i32 (sext i1:$src0)),
1283 (V_CNDMASK_B32_e64 /*src0mod*/(i32 0), /*src0*/(i32 0),
1284 /*src1mod*/(i32 0), /*src1*/(i32 -1), $src0)
1287 class Ext32Pat <SDNode ext> : GCNPat <
1288 (i32 (ext i1:$src0)),
1289 (V_CNDMASK_B32_e64 /*src0mod*/(i32 0), /*src0*/(i32 0),
1290 /*src1mod*/(i32 0), /*src1*/(i32 1), $src0)
1293 def : Ext32Pat <zext>;
1294 def : Ext32Pat <anyext>;
1296 // The multiplication scales from [0,1] to the unsigned integer range
1298 (AMDGPUurecip i32:$src0),
1300 (V_MUL_F32_e32 (i32 CONST.FP_UINT_MAX_PLUS_1),
1301 (V_RCP_IFLAG_F32_e32 (V_CVT_F32_U32_e32 $src0))))
1304 //===----------------------------------------------------------------------===//
1306 //===----------------------------------------------------------------------===//
1308 def : IMad24Pat<V_MAD_I32_I24, 1>;
1309 def : UMad24Pat<V_MAD_U32_U24, 1>;
1311 // FIXME: This should only be done for VALU inputs
1312 defm : BFIPatterns <V_BFI_B32, S_MOV_B32, SReg_64>;
1313 def : ROTRPattern <V_ALIGNBIT_B32>;
1315 def : GCNPat<(i32 (trunc (srl i64:$src0, (and i32:$src1, (i32 31))))),
1316 (V_ALIGNBIT_B32 (i32 (EXTRACT_SUBREG (i64 $src0), sub1)),
1317 (i32 (EXTRACT_SUBREG (i64 $src0), sub0)), $src1)>;
1319 def : GCNPat<(i32 (trunc (srl i64:$src0, (i32 ShiftAmt32Imm:$src1)))),
1320 (V_ALIGNBIT_B32 (i32 (EXTRACT_SUBREG (i64 $src0), sub1)),
1321 (i32 (EXTRACT_SUBREG (i64 $src0), sub0)), $src1)>;
1323 /********** ====================== **********/
1324 /********** Indirect addressing **********/
1325 /********** ====================== **********/
1327 multiclass SI_INDIRECT_Pattern <ValueType vt, ValueType eltvt, string VecSize> {
1328 // Extract with offset
1330 (eltvt (extractelt vt:$src, (MOVRELOffset i32:$idx, (i32 imm:$offset)))),
1331 (!cast<Instruction>("SI_INDIRECT_SRC_"#VecSize) $src, $idx, imm:$offset)
1334 // Insert with offset
1336 (insertelt vt:$src, eltvt:$val, (MOVRELOffset i32:$idx, (i32 imm:$offset))),
1337 (!cast<Instruction>("SI_INDIRECT_DST_"#VecSize) $src, $idx, imm:$offset, $val)
1341 defm : SI_INDIRECT_Pattern <v2f32, f32, "V2">;
1342 defm : SI_INDIRECT_Pattern <v4f32, f32, "V4">;
1343 defm : SI_INDIRECT_Pattern <v8f32, f32, "V8">;
1344 defm : SI_INDIRECT_Pattern <v16f32, f32, "V16">;
1346 defm : SI_INDIRECT_Pattern <v2i32, i32, "V2">;
1347 defm : SI_INDIRECT_Pattern <v4i32, i32, "V4">;
1348 defm : SI_INDIRECT_Pattern <v8i32, i32, "V8">;
1349 defm : SI_INDIRECT_Pattern <v16i32, i32, "V16">;
1351 //===----------------------------------------------------------------------===//
1353 //===----------------------------------------------------------------------===//
1356 (add (sub_oneuse (umax i32:$src0, i32:$src1),
1357 (umin i32:$src0, i32:$src1)),
1359 (V_SAD_U32 $src0, $src1, $src2, (i1 0))
1363 (add (select_oneuse (i1 (setugt i32:$src0, i32:$src1)),
1364 (sub i32:$src0, i32:$src1),
1365 (sub i32:$src1, i32:$src0)),
1367 (V_SAD_U32 $src0, $src1, $src2, (i1 0))
1370 //===----------------------------------------------------------------------===//
1371 // Conversion Patterns
1372 //===----------------------------------------------------------------------===//
1374 def : GCNPat<(i32 (sext_inreg i32:$src, i1)),
1375 (S_BFE_I32 i32:$src, (i32 65536))>; // 0 | 1 << 16
1377 // Handle sext_inreg in i64
1379 (i64 (sext_inreg i64:$src, i1)),
1380 (S_BFE_I64 i64:$src, (i32 0x10000)) // 0 | 1 << 16
1384 (i16 (sext_inreg i16:$src, i1)),
1385 (S_BFE_I32 $src, (i32 0x00010000)) // 0 | 1 << 16
1389 (i16 (sext_inreg i16:$src, i8)),
1390 (S_BFE_I32 $src, (i32 0x80000)) // 0 | 8 << 16
1394 (i64 (sext_inreg i64:$src, i8)),
1395 (S_BFE_I64 i64:$src, (i32 0x80000)) // 0 | 8 << 16
1399 (i64 (sext_inreg i64:$src, i16)),
1400 (S_BFE_I64 i64:$src, (i32 0x100000)) // 0 | 16 << 16
1404 (i64 (sext_inreg i64:$src, i32)),
1405 (S_BFE_I64 i64:$src, (i32 0x200000)) // 0 | 32 << 16
1409 (i64 (zext i32:$src)),
1410 (REG_SEQUENCE SReg_64, $src, sub0, (S_MOV_B32 (i32 0)), sub1)
1414 (i64 (anyext i32:$src)),
1415 (REG_SEQUENCE SReg_64, $src, sub0, (i32 (IMPLICIT_DEF)), sub1)
1418 class ZExt_i64_i1_Pat <SDNode ext> : GCNPat <
1419 (i64 (ext i1:$src)),
1420 (REG_SEQUENCE VReg_64,
1421 (V_CNDMASK_B32_e64 /*src0mod*/(i32 0), /*src0*/(i32 0),
1422 /*src1mod*/(i32 0), /*src1*/(i32 1), $src),
1423 sub0, (S_MOV_B32 (i32 0)), sub1)
1427 def : ZExt_i64_i1_Pat<zext>;
1428 def : ZExt_i64_i1_Pat<anyext>;
1430 // FIXME: We need to use COPY_TO_REGCLASS to work-around the fact that
1431 // REG_SEQUENCE patterns don't support instructions with multiple outputs.
1433 (i64 (sext i32:$src)),
1434 (REG_SEQUENCE SReg_64, $src, sub0,
1435 (i32 (COPY_TO_REGCLASS (S_ASHR_I32 $src, (i32 31)), SReg_32_XM0)), sub1)
1439 (i64 (sext i1:$src)),
1440 (REG_SEQUENCE VReg_64,
1441 (V_CNDMASK_B32_e64 /*src0mod*/(i32 0), /*src0*/(i32 0),
1442 /*src1mod*/(i32 0), /*src1*/(i32 -1), $src), sub0,
1443 (V_CNDMASK_B32_e64 /*src0mod*/(i32 0), /*src0*/(i32 0),
1444 /*src1mod*/(i32 0), /*src1*/(i32 -1), $src), sub1)
1447 class FPToI1Pat<Instruction Inst, int KOne, ValueType kone_type, ValueType vt, SDPatternOperator fp_to_int> : GCNPat <
1448 (i1 (fp_to_int (vt (VOP3Mods vt:$src0, i32:$src0_modifiers)))),
1449 (i1 (Inst 0, (kone_type KOne), $src0_modifiers, $src0, DSTCLAMP.NONE))
1452 def : FPToI1Pat<V_CMP_EQ_F32_e64, CONST.FP32_ONE, i32, f32, fp_to_uint>;
1453 def : FPToI1Pat<V_CMP_EQ_F32_e64, CONST.FP32_NEG_ONE, i32, f32, fp_to_sint>;
1454 def : FPToI1Pat<V_CMP_EQ_F64_e64, CONST.FP64_ONE, i64, f64, fp_to_uint>;
1455 def : FPToI1Pat<V_CMP_EQ_F64_e64, CONST.FP64_NEG_ONE, i64, f64, fp_to_sint>;
1457 // If we need to perform a logical operation on i1 values, we need to
1458 // use vector comparisons since there is only one SCC register. Vector
1459 // comparisons may write to a pair of SGPRs or a single SGPR, so treat
1460 // these as 32 or 64-bit comparisons. When legalizing SGPR copies,
1461 // instructions resulting in the copies from SCC to these instructions
1462 // will be moved to the VALU.
1464 let WaveSizePredicate = isWave64 in {
1466 (i1 (and i1:$src0, i1:$src1)),
1467 (S_AND_B64 $src0, $src1)
1471 (i1 (or i1:$src0, i1:$src1)),
1472 (S_OR_B64 $src0, $src1)
1476 (i1 (xor i1:$src0, i1:$src1)),
1477 (S_XOR_B64 $src0, $src1)
1481 (i1 (add i1:$src0, i1:$src1)),
1482 (S_XOR_B64 $src0, $src1)
1486 (i1 (sub i1:$src0, i1:$src1)),
1487 (S_XOR_B64 $src0, $src1)
1490 let AddedComplexity = 1 in {
1492 (i1 (add i1:$src0, (i1 -1))),
1497 (i1 (sub i1:$src0, (i1 -1))),
1503 let WaveSizePredicate = isWave32 in {
1505 (i1 (and i1:$src0, i1:$src1)),
1506 (S_AND_B32 $src0, $src1)
1510 (i1 (or i1:$src0, i1:$src1)),
1511 (S_OR_B32 $src0, $src1)
1515 (i1 (xor i1:$src0, i1:$src1)),
1516 (S_XOR_B32 $src0, $src1)
1520 (i1 (add i1:$src0, i1:$src1)),
1521 (S_XOR_B32 $src0, $src1)
1525 (i1 (sub i1:$src0, i1:$src1)),
1526 (S_XOR_B32 $src0, $src1)
1529 let AddedComplexity = 1 in {
1531 (i1 (add i1:$src0, (i1 -1))),
1536 (i1 (sub i1:$src0, (i1 -1))),
1543 (f16 (sint_to_fp i1:$src)),
1544 (V_CVT_F16_F32_e32 (
1545 V_CNDMASK_B32_e64 /*src0mod*/(i32 0), /*src0*/(i32 0),
1546 /*src1mod*/(i32 0), /*src1*/(i32 CONST.FP32_NEG_ONE),
1551 (f16 (uint_to_fp i1:$src)),
1552 (V_CVT_F16_F32_e32 (
1553 V_CNDMASK_B32_e64 /*src0mod*/(i32 0), /*src0*/(i32 0),
1554 /*src1mod*/(i32 0), /*src1*/(i32 CONST.FP32_ONE),
1559 (f32 (sint_to_fp i1:$src)),
1560 (V_CNDMASK_B32_e64 /*src0mod*/(i32 0), /*src0*/(i32 0),
1561 /*src1mod*/(i32 0), /*src1*/(i32 CONST.FP32_NEG_ONE),
1566 (f32 (uint_to_fp i1:$src)),
1567 (V_CNDMASK_B32_e64 /*src0mod*/(i32 0), /*src0*/(i32 0),
1568 /*src1mod*/(i32 0), /*src1*/(i32 CONST.FP32_ONE),
1573 (f64 (sint_to_fp i1:$src)),
1574 (V_CVT_F64_I32_e32 (V_CNDMASK_B32_e64 /*src0mod*/(i32 0), /*src0*/(i32 0),
1575 /*src1mod*/(i32 0), /*src1*/(i32 -1),
1580 (f64 (uint_to_fp i1:$src)),
1581 (V_CVT_F64_U32_e32 (V_CNDMASK_B32_e64 /*src0mod*/(i32 0), /*src0*/(i32 0),
1582 /*src1mod*/(i32 0), /*src1*/(i32 1),
1586 //===----------------------------------------------------------------------===//
1587 // Miscellaneous Patterns
1588 //===----------------------------------------------------------------------===//
1590 (i32 (AMDGPUfp16_zext f16:$src)),
1596 (i32 (trunc i64:$a)),
1597 (EXTRACT_SUBREG $a, sub0)
1601 (i1 (trunc i32:$a)),
1602 (V_CMP_EQ_U32_e64 (S_AND_B32 (i32 1), $a), (i32 1))
1606 (i1 (trunc i16:$a)),
1607 (V_CMP_EQ_U32_e64 (S_AND_B32 (i32 1), $a), (i32 1))
1611 (i1 (trunc i64:$a)),
1612 (V_CMP_EQ_U32_e64 (S_AND_B32 (i32 1),
1613 (i32 (EXTRACT_SUBREG $a, sub0))), (i32 1))
1617 (i32 (bswap i32:$a)),
1618 (V_BFI_B32 (S_MOV_B32 (i32 0x00ff00ff)),
1619 (V_ALIGNBIT_B32 $a, $a, (i32 24)),
1620 (V_ALIGNBIT_B32 $a, $a, (i32 8)))
1623 let OtherPredicates = [NoFP16Denormals] in {
1625 (fcanonicalize (f16 (VOP3Mods f16:$src, i32:$src_mods))),
1626 (V_MUL_F16_e64 0, (i32 CONST.FP16_ONE), $src_mods, $src, 0, 0)
1630 (fcanonicalize (f16 (fneg (VOP3Mods f16:$src, i32:$src_mods)))),
1631 (V_MUL_F16_e64 0, (i32 CONST.FP16_NEG_ONE), $src_mods, $src, 0, 0)
1635 (fcanonicalize (v2f16 (VOP3PMods v2f16:$src, i32:$src_mods))),
1636 (V_PK_MUL_F16 0, (i32 CONST.FP16_ONE), $src_mods, $src, DSTCLAMP.NONE)
1640 let OtherPredicates = [FP16Denormals] in {
1642 (fcanonicalize (f16 (VOP3Mods f16:$src, i32:$src_mods))),
1643 (V_MAX_F16_e64 $src_mods, $src, $src_mods, $src, 0, 0)
1646 let SubtargetPredicate = HasVOP3PInsts in {
1648 (fcanonicalize (v2f16 (VOP3PMods v2f16:$src, i32:$src_mods))),
1649 (V_PK_MAX_F16 $src_mods, $src, $src_mods, $src, DSTCLAMP.NONE)
1654 let OtherPredicates = [NoFP32Denormals] in {
1656 (fcanonicalize (f32 (VOP3Mods f32:$src, i32:$src_mods))),
1657 (V_MUL_F32_e64 0, (i32 CONST.FP32_ONE), $src_mods, $src, 0, 0)
1661 (fcanonicalize (f32 (fneg (VOP3Mods f32:$src, i32:$src_mods)))),
1662 (V_MUL_F32_e64 0, (i32 CONST.FP32_NEG_ONE), $src_mods, $src, 0, 0)
1666 let OtherPredicates = [FP32Denormals] in {
1668 (fcanonicalize (f32 (VOP3Mods f32:$src, i32:$src_mods))),
1669 (V_MAX_F32_e64 $src_mods, $src, $src_mods, $src, 0, 0)
1673 let OtherPredicates = [NoFP64Denormals] in {
1675 (fcanonicalize (f64 (VOP3Mods f64:$src, i32:$src_mods))),
1676 (V_MUL_F64 0, CONST.FP64_ONE, $src_mods, $src, 0, 0)
1680 let OtherPredicates = [FP64Denormals] in {
1682 (fcanonicalize (f64 (VOP3Mods f64:$src, i32:$src_mods))),
1683 (V_MAX_F64 $src_mods, $src, $src_mods, $src, 0, 0)
1687 let OtherPredicates = [HasDLInsts] in {
1689 (fma (f32 (VOP3Mods0 f32:$src0, i32:$src0_modifiers, i1:$clamp, i32:$omod)),
1690 (f32 (VOP3Mods f32:$src1, i32:$src1_modifiers)),
1691 (f32 (VOP3NoMods f32:$src2))),
1692 (V_FMAC_F32_e64 $src0_modifiers, $src0, $src1_modifiers, $src1,
1693 SRCMODS.NONE, $src2, $clamp, $omod)
1695 } // End OtherPredicates = [HasDLInsts]
1697 let SubtargetPredicate = isGFX10Plus in
1699 (fma (f16 (VOP3Mods0 f32:$src0, i32:$src0_modifiers, i1:$clamp, i32:$omod)),
1700 (f16 (VOP3Mods f32:$src1, i32:$src1_modifiers)),
1701 (f16 (VOP3NoMods f32:$src2))),
1702 (V_FMAC_F16_e64 $src0_modifiers, $src0, $src1_modifiers, $src1,
1703 SRCMODS.NONE, $src2, $clamp, $omod)
1706 // Allow integer inputs
1707 class ExpPattern<SDPatternOperator node, ValueType vt, Instruction Inst> : GCNPat<
1708 (node (i8 timm:$tgt), (i8 timm:$en), vt:$src0, vt:$src1, vt:$src2, vt:$src3, (i1 timm:$compr), (i1 timm:$vm)),
1709 (Inst i8:$tgt, vt:$src0, vt:$src1, vt:$src2, vt:$src3, i1:$vm, i1:$compr, i8:$en)
1712 def : ExpPattern<AMDGPUexport, i32, EXP>;
1713 def : ExpPattern<AMDGPUexport_done, i32, EXP_DONE>;
1715 // COPY is workaround tablegen bug from multiple outputs
1716 // from S_LSHL_B32's multiple outputs from implicit scc def.
1718 (v2i16 (build_vector (i16 0), i16:$src1)),
1719 (v2i16 (COPY (S_LSHL_B32 i16:$src1, (i16 16))))
1723 (v2i16 (build_vector i16:$src0, (i16 undef))),
1724 (v2i16 (COPY $src0))
1728 (v2f16 (build_vector f16:$src0, (f16 undef))),
1729 (v2f16 (COPY $src0))
1733 (v2i16 (build_vector (i16 undef), i16:$src1)),
1734 (v2i16 (COPY (S_LSHL_B32 $src1, (i32 16))))
1738 (v2f16 (build_vector (f16 undef), f16:$src1)),
1739 (v2f16 (COPY (S_LSHL_B32 $src1, (i32 16))))
1742 let SubtargetPredicate = HasVOP3PInsts in {
1744 (v2i16 (build_vector i16:$src0, i16:$src1)),
1745 (v2i16 (S_PACK_LL_B32_B16 $src0, $src1))
1748 // With multiple uses of the shift, this will duplicate the shift and
1749 // increase register pressure.
1751 (v2i16 (build_vector i16:$src0, (i16 (trunc (srl_oneuse i32:$src1, (i32 16)))))),
1752 (v2i16 (S_PACK_LH_B32_B16 i16:$src0, i32:$src1))
1757 (v2i16 (build_vector (i16 (trunc (srl_oneuse i32:$src0, (i32 16)))),
1758 (i16 (trunc (srl_oneuse i32:$src1, (i32 16)))))),
1759 (v2i16 (S_PACK_HH_B32_B16 $src0, $src1))
1762 // TODO: Should source modifiers be matched to v_pack_b32_f16?
1764 (v2f16 (build_vector f16:$src0, f16:$src1)),
1765 (v2f16 (S_PACK_LL_B32_B16 $src0, $src1))
1768 } // End SubtargetPredicate = HasVOP3PInsts
1772 (v2f16 (scalar_to_vector f16:$src0)),
1777 (v2i16 (scalar_to_vector i16:$src0)),
1782 (v4i16 (scalar_to_vector i16:$src0)),
1783 (INSERT_SUBREG (IMPLICIT_DEF), $src0, sub0)
1787 (v4f16 (scalar_to_vector f16:$src0)),
1788 (INSERT_SUBREG (IMPLICIT_DEF), $src0, sub0)
1791 //===----------------------------------------------------------------------===//
1793 //===----------------------------------------------------------------------===//
1795 let SubtargetPredicate = isGFX6 in {
1797 // V_FRACT is buggy on SI, so the F32 version is never used and (x-floor(x)) is
1798 // used instead. However, SI doesn't have V_FLOOR_F64, so the most efficient
1799 // way to implement it is using V_FRACT_F64.
1800 // The workaround for the V_FRACT bug is:
1801 // fract(x) = isnan(x) ? x : min(V_FRACT(x), 0.99999999999999999)
1803 // Convert floor(x) to (x - fract(x))
1805 (f64 (ffloor (f64 (VOP3Mods f64:$x, i32:$mods)))),
1810 (V_CNDMASK_B64_PSEUDO
1813 (V_FRACT_F64_e64 $mods, $x, DSTCLAMP.NONE, DSTOMOD.NONE),
1815 (V_MOV_B64_PSEUDO 0x3fefffffffffffff),
1816 DSTCLAMP.NONE, DSTOMOD.NONE),
1818 (V_CMP_CLASS_F64_e64 SRCMODS.NONE, $x, (i32 3 /*NaN*/))),
1819 DSTCLAMP.NONE, DSTOMOD.NONE)
1822 } // End SubtargetPredicates = isGFX6
1824 //============================================================================//
1825 // Miscellaneous Optimization Patterns
1826 //============================================================================//
1828 // Undo sub x, c -> add x, -c canonicalization since c is more likely
1829 // an inline immediate than -c.
1830 // TODO: Also do for 64-bit.
1832 (add i32:$src0, (i32 NegSubInlineConst32:$src1)),
1833 (S_SUB_I32 $src0, NegSubInlineConst32:$src1)
1836 // Avoid pointlessly materializing a constant in VGPR.
1837 // FIXME: Should also do this for readlane, but tablegen crashes on
1838 // the ignored src1.
1840 (int_amdgcn_readfirstlane (i32 imm:$src)),
1844 multiclass BFMPatterns <ValueType vt, InstSI BFM, InstSI MOV> {
1846 (vt (shl (vt (add (vt (shl 1, vt:$a)), -1)), vt:$b)),
1851 (vt (add (vt (shl 1, vt:$a)), -1)),
1852 (BFM $a, (MOV (i32 0)))
1856 defm : BFMPatterns <i32, S_BFM_B32, S_MOV_B32>;
1857 // FIXME: defm : BFMPatterns <i64, S_BFM_B64, S_MOV_B64>;
1859 defm : BFEPattern <V_BFE_U32, V_BFE_I32, S_MOV_B32>;
1860 defm : SHA256MaPattern <V_BFI_B32, V_XOR_B32_e64, SReg_64>;
1862 defm : IntMed3Pat<V_MED3_I32, smin, smax, smin_oneuse, smax_oneuse>;
1863 defm : IntMed3Pat<V_MED3_U32, umin, umax, umin_oneuse, umax_oneuse>;
1865 // This matches 16 permutations of
1866 // max(min(x, y), min(max(x, y), z))
1867 class FPMed3Pat<ValueType vt,
1868 //SDPatternOperator max, SDPatternOperator min,
1869 Instruction med3Inst> : GCNPat<
1870 (fmaxnum_like (fminnum_like_oneuse (VOP3Mods_nnan vt:$src0, i32:$src0_mods),
1871 (VOP3Mods_nnan vt:$src1, i32:$src1_mods)),
1872 (fminnum_like_oneuse (fmaxnum_like_oneuse (VOP3Mods_nnan vt:$src0, i32:$src0_mods),
1873 (VOP3Mods_nnan vt:$src1, i32:$src1_mods)),
1874 (vt (VOP3Mods_nnan vt:$src2, i32:$src2_mods)))),
1875 (med3Inst $src0_mods, $src0, $src1_mods, $src1, $src2_mods, $src2, DSTCLAMP.NONE, DSTOMOD.NONE)
1878 class FP16Med3Pat<ValueType vt,
1879 Instruction med3Inst> : GCNPat<
1880 (fmaxnum_like (fminnum_like_oneuse (VOP3Mods_nnan vt:$src0, i32:$src0_mods),
1881 (VOP3Mods_nnan vt:$src1, i32:$src1_mods)),
1882 (fminnum_like_oneuse (fmaxnum_like_oneuse (VOP3Mods_nnan vt:$src0, i32:$src0_mods),
1883 (VOP3Mods_nnan vt:$src1, i32:$src1_mods)),
1884 (vt (VOP3Mods_nnan vt:$src2, i32:$src2_mods)))),
1885 (med3Inst $src0_mods, $src0, $src1_mods, $src1, $src2_mods, $src2, DSTCLAMP.NONE)
1888 multiclass Int16Med3Pat<Instruction med3Inst,
1889 SDPatternOperator min,
1890 SDPatternOperator max,
1891 SDPatternOperator max_oneuse,
1892 SDPatternOperator min_oneuse,
1893 ValueType vt = i16> {
1894 // This matches 16 permutations of
1895 // max(min(x, y), min(max(x, y), z))
1897 (max (min_oneuse vt:$src0, vt:$src1),
1898 (min_oneuse (max_oneuse vt:$src0, vt:$src1), vt:$src2)),
1899 (med3Inst SRCMODS.NONE, $src0, SRCMODS.NONE, $src1, SRCMODS.NONE, $src2, DSTCLAMP.NONE)
1902 // This matches 16 permutations of
1903 // min(max(a, b), max(min(a, b), c))
1905 (min (max_oneuse vt:$src0, vt:$src1),
1906 (max_oneuse (min_oneuse vt:$src0, vt:$src1), vt:$src2)),
1907 (med3Inst SRCMODS.NONE, $src0, SRCMODS.NONE, $src1, SRCMODS.NONE, $src2, DSTCLAMP.NONE)
1911 def : FPMed3Pat<f32, V_MED3_F32>;
1913 let OtherPredicates = [isGFX9Plus] in {
1914 def : FP16Med3Pat<f16, V_MED3_F16>;
1915 defm : Int16Med3Pat<V_MED3_I16, smin, smax, smax_oneuse, smin_oneuse>;
1916 defm : Int16Med3Pat<V_MED3_U16, umin, umax, umax_oneuse, umin_oneuse>;
1917 } // End Predicates = [isGFX9Plus]