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.softwqm. Like @llvm.amdgcn.wqm it is
115 // turned into a copy by WQM pass, but does not seed WQM requirements.
116 def SOFT_WQM : PseudoInstSI <(outs unknown:$vdst), (ins unknown:$src0)>;
118 // Pseudoinstruction for @llvm.amdgcn.wwm. It is turned into a copy post-RA, so
119 // that the @earlyclobber is respected. The @earlyclobber is to make sure that
120 // the instruction that defines $src0 (which is run in WWM) doesn't
121 // accidentally clobber inactive channels of $vdst.
122 let Constraints = "@earlyclobber $vdst" in {
123 def WWM : PseudoInstSI <(outs unknown:$vdst), (ins unknown:$src0)>;
126 } // End let hasSideEffects = 0, mayLoad = 0, mayStore = 0, Uses = [EXEC]
128 def ENTER_WWM : SPseudoInstSI <(outs SReg_1:$sdst), (ins i64imm:$src0)> {
130 let hasSideEffects = 0;
135 def EXIT_WWM : SPseudoInstSI <(outs SReg_1:$sdst), (ins SReg_1:$src0)> {
136 let hasSideEffects = 0;
141 // Invert the exec mask and overwrite the inactive lanes of dst with inactive,
142 // restoring it after we're done.
143 def V_SET_INACTIVE_B32 : VPseudoInstSI <(outs VGPR_32:$vdst),
144 (ins VGPR_32: $src, VSrc_b32:$inactive),
145 [(set i32:$vdst, (int_amdgcn_set_inactive i32:$src, i32:$inactive))]> {
146 let Constraints = "$src = $vdst";
149 def V_SET_INACTIVE_B64 : VPseudoInstSI <(outs VReg_64:$vdst),
150 (ins VReg_64: $src, VSrc_b64:$inactive),
151 [(set i64:$vdst, (int_amdgcn_set_inactive i64:$src, i64:$inactive))]> {
152 let Constraints = "$src = $vdst";
156 let usesCustomInserter = 1, Defs = [SCC] in {
157 def S_ADD_U64_PSEUDO : SPseudoInstSI <
158 (outs SReg_64:$vdst), (ins SSrc_b64:$src0, SSrc_b64:$src1),
159 [(set SReg_64:$vdst, (add i64:$src0, i64:$src1))]
162 def S_SUB_U64_PSEUDO : SPseudoInstSI <
163 (outs SReg_64:$vdst), (ins SSrc_b64:$src0, SSrc_b64:$src1),
164 [(set SReg_64:$vdst, (sub i64:$src0, i64:$src1))]
167 def S_ADD_U64_CO_PSEUDO : SPseudoInstSI <
168 (outs SReg_64:$vdst, VOPDstS64orS32:$sdst), (ins SSrc_b64:$src0, SSrc_b64:$src1)
171 def S_SUB_U64_CO_PSEUDO : SPseudoInstSI <
172 (outs SReg_64:$vdst, VOPDstS64orS32:$sdst), (ins SSrc_b64:$src0, SSrc_b64:$src1)
174 } // End usesCustomInserter = 1, Defs = [SCC]
176 let usesCustomInserter = 1 in {
177 def GET_GROUPSTATICSIZE : SPseudoInstSI <(outs SReg_32:$sdst), (ins),
178 [(set SReg_32:$sdst, (int_amdgcn_groupstaticsize))]>;
179 } // End let usesCustomInserter = 1, SALU = 1
181 // Wrap an instruction by duplicating it, except for setting isTerminator.
182 class WrapTerminatorInst<SOP_Pseudo base_inst> : SPseudoInstSI<
183 base_inst.OutOperandList,
184 base_inst.InOperandList> {
185 let Uses = base_inst.Uses;
186 let Defs = base_inst.Defs;
187 let isTerminator = 1;
188 let isAsCheapAsAMove = base_inst.isAsCheapAsAMove;
189 let hasSideEffects = base_inst.hasSideEffects;
190 let UseNamedOperandTable = base_inst.UseNamedOperandTable;
191 let CodeSize = base_inst.CodeSize;
194 let WaveSizePredicate = isWave64 in {
195 def S_MOV_B64_term : WrapTerminatorInst<S_MOV_B64>;
196 def S_OR_B64_term : WrapTerminatorInst<S_OR_B64>;
197 def S_XOR_B64_term : WrapTerminatorInst<S_XOR_B64>;
198 def S_ANDN2_B64_term : WrapTerminatorInst<S_ANDN2_B64>;
201 let WaveSizePredicate = isWave32 in {
202 def S_MOV_B32_term : WrapTerminatorInst<S_MOV_B32>;
203 def S_XOR_B32_term : WrapTerminatorInst<S_XOR_B32>;
204 def S_OR_B32_term : WrapTerminatorInst<S_OR_B32>;
205 def S_ANDN2_B32_term : WrapTerminatorInst<S_ANDN2_B32>;
208 def WAVE_BARRIER : SPseudoInstSI<(outs), (ins),
209 [(int_amdgcn_wave_barrier)]> {
211 let hasNoSchedulingInfo = 1;
212 let hasSideEffects = 1;
215 let isConvergent = 1;
220 // SI pseudo instructions. These are used by the CFG structurizer pass
221 // and should be lowered to ISA instructions prior to codegen.
223 // Dummy terminator instruction to use after control flow instructions
224 // replaced with exec mask operations.
225 def SI_MASK_BRANCH : VPseudoInstSI <
226 (outs), (ins brtarget:$target)> {
228 let isTerminator = 1;
231 let hasNoSchedulingInfo = 1;
236 let isTerminator = 1 in {
238 let OtherPredicates = [EnableLateCFGStructurize] in {
239 def SI_NON_UNIFORM_BRCOND_PSEUDO : CFPseudoInstSI <
241 (ins SReg_1:$vcc, brtarget:$target),
242 [(brcond i1:$vcc, bb:$target)]> {
247 def SI_IF: CFPseudoInstSI <
248 (outs SReg_1:$dst), (ins SReg_1:$vcc, brtarget:$target),
249 [(set i1:$dst, (AMDGPUif i1:$vcc, bb:$target))], 1, 1> {
250 let Constraints = "";
252 let hasSideEffects = 1;
255 def SI_ELSE : CFPseudoInstSI <
257 (ins SReg_1:$src, brtarget:$target, i1imm:$execfix), [], 1, 1> {
259 let hasSideEffects = 1;
262 def SI_LOOP : CFPseudoInstSI <
263 (outs), (ins SReg_1:$saved, brtarget:$target),
264 [(AMDGPUloop i1:$saved, bb:$target)], 1, 1> {
267 let hasSideEffects = 1;
270 } // End isTerminator = 1
272 def SI_END_CF : CFPseudoInstSI <
273 (outs), (ins SReg_1:$saved), [], 1, 1> {
275 let isAsCheapAsAMove = 1;
276 let isReMaterializable = 1;
277 let hasSideEffects = 1;
278 let mayLoad = 1; // FIXME: Should not need memory flags
282 def SI_IF_BREAK : CFPseudoInstSI <
283 (outs SReg_1:$dst), (ins SReg_1:$vcc, SReg_1:$src), []> {
285 let isAsCheapAsAMove = 1;
286 let isReMaterializable = 1;
289 let Uses = [EXEC] in {
291 multiclass PseudoInstKill <dag ins> {
292 // Even though this pseudo can usually be expanded without an SCC def, we
293 // conservatively assume that it has an SCC def, both because it is sometimes
294 // required in degenerate cases (when V_CMPX cannot be used due to constant
295 // bus limitations) and because it allows us to avoid having to track SCC
296 // liveness across basic blocks.
297 let Defs = [EXEC,VCC,SCC] in
298 def _PSEUDO : PseudoInstSI <(outs), ins> {
299 let isConvergent = 1;
300 let usesCustomInserter = 1;
303 let Defs = [EXEC,VCC,SCC] in
304 def _TERMINATOR : SPseudoInstSI <(outs), ins> {
305 let isTerminator = 1;
309 defm SI_KILL_I1 : PseudoInstKill <(ins SCSrc_i1:$src, i1imm:$killvalue)>;
310 defm SI_KILL_F32_COND_IMM : PseudoInstKill <(ins VSrc_b32:$src0, i32imm:$src1, i32imm:$cond)>;
312 let Defs = [EXEC,VCC] in
313 def SI_ILLEGAL_COPY : SPseudoInstSI <
314 (outs unknown:$dst), (ins unknown:$src),
315 [], " ; illegal copy $src to $dst">;
317 } // End Uses = [EXEC], Defs = [EXEC,VCC]
319 // Branch on undef scc. Used to avoid intermediate copy from
320 // IMPLICIT_DEF to SCC.
321 def SI_BR_UNDEF : SPseudoInstSI <(outs), (ins sopp_brtarget:$simm16)> {
322 let isTerminator = 1;
323 let usesCustomInserter = 1;
327 def SI_PS_LIVE : PseudoInstSI <
328 (outs SReg_1:$dst), (ins),
329 [(set i1:$dst, (int_amdgcn_ps_live))]> {
333 def SI_MASKED_UNREACHABLE : SPseudoInstSI <(outs), (ins),
334 [(int_amdgcn_unreachable)],
335 "; divergent unreachable"> {
337 let hasNoSchedulingInfo = 1;
341 // Used as an isel pseudo to directly emit initialization with an
342 // s_mov_b32 rather than a copy of another initialized
343 // register. MachineCSE skips copies, and we don't want to have to
344 // fold operands before it runs.
345 def SI_INIT_M0 : SPseudoInstSI <(outs), (ins SSrc_b32:$src)> {
347 let usesCustomInserter = 1;
348 let isAsCheapAsAMove = 1;
349 let isReMaterializable = 1;
352 def SI_INIT_EXEC : SPseudoInstSI <
353 (outs), (ins i64imm:$src), []> {
355 let usesCustomInserter = 1;
356 let isAsCheapAsAMove = 1;
357 let WaveSizePredicate = isWave64;
360 def SI_INIT_EXEC_LO : SPseudoInstSI <
361 (outs), (ins i32imm:$src), []> {
362 let Defs = [EXEC_LO];
363 let usesCustomInserter = 1;
364 let isAsCheapAsAMove = 1;
365 let WaveSizePredicate = isWave32;
368 def SI_INIT_EXEC_FROM_INPUT : SPseudoInstSI <
369 (outs), (ins SSrc_b32:$input, i32imm:$shift), []> {
371 let usesCustomInserter = 1;
374 // Return for returning shaders to a shader variant epilog.
375 def SI_RETURN_TO_EPILOG : SPseudoInstSI <
376 (outs), (ins variable_ops), [(AMDGPUreturn_to_epilog)]> {
377 let isTerminator = 1;
380 let hasNoSchedulingInfo = 1;
385 // Return for returning function calls.
386 def SI_RETURN : SPseudoInstSI <
389 let isTerminator = 1;
392 let SchedRW = [WriteBranch];
395 // Return for returning function calls without output register.
397 // This version is only needed so we can fill in the output regiter in
398 // the custom inserter.
399 def SI_CALL_ISEL : SPseudoInstSI <
400 (outs), (ins SSrc_b64:$src0, unknown:$callee),
401 [(AMDGPUcall i64:$src0, tglobaladdr:$callee)]> {
404 let SchedRW = [WriteBranch];
405 let usesCustomInserter = 1;
406 // TODO: Should really base this on the call target
407 let isConvergent = 1;
410 // Wrapper around s_swappc_b64 with extra $callee parameter to track
411 // the called function after regalloc.
412 def SI_CALL : SPseudoInstSI <
413 (outs SReg_64:$dst), (ins SSrc_b64:$src0, unknown:$callee)> {
416 let UseNamedOperandTable = 1;
417 let SchedRW = [WriteBranch];
418 // TODO: Should really base this on the call target
419 let isConvergent = 1;
422 // Tail call handling pseudo
423 def SI_TCRETURN : SPseudoInstSI <(outs),
424 (ins SSrc_b64:$src0, unknown:$callee, i32imm:$fpdiff),
425 [(AMDGPUtc_return i64:$src0, tglobaladdr:$callee, i32:$fpdiff)]> {
428 let isTerminator = 1;
431 let UseNamedOperandTable = 1;
432 let SchedRW = [WriteBranch];
433 // TODO: Should really base this on the call target
434 let isConvergent = 1;
438 def ADJCALLSTACKUP : SPseudoInstSI<
439 (outs), (ins i32imm:$amt0, i32imm:$amt1),
440 [(callseq_start timm:$amt0, timm:$amt1)],
441 "; adjcallstackup $amt0 $amt1"> {
442 let Size = 8; // Worst case. (s_add_u32 + constant)
444 let hasSideEffects = 1;
445 let usesCustomInserter = 1;
446 let SchedRW = [WriteSALU];
450 def ADJCALLSTACKDOWN : SPseudoInstSI<
451 (outs), (ins i32imm:$amt1, i32imm:$amt2),
452 [(callseq_end timm:$amt1, timm:$amt2)],
453 "; adjcallstackdown $amt1"> {
454 let Size = 8; // Worst case. (s_add_u32 + constant)
455 let hasSideEffects = 1;
456 let usesCustomInserter = 1;
457 let SchedRW = [WriteSALU];
461 let Defs = [M0, EXEC, SCC],
462 UseNamedOperandTable = 1 in {
464 class SI_INDIRECT_SRC<RegisterClass rc> : VPseudoInstSI <
465 (outs VGPR_32:$vdst),
466 (ins rc:$src, VS_32:$idx, i32imm:$offset)> {
467 let usesCustomInserter = 1;
470 class SI_INDIRECT_DST<RegisterClass rc> : VPseudoInstSI <
472 (ins rc:$src, VS_32:$idx, i32imm:$offset, VGPR_32:$val)> {
473 let Constraints = "$src = $vdst";
474 let usesCustomInserter = 1;
477 // TODO: We can support indirect SGPR access.
478 def SI_INDIRECT_SRC_V1 : SI_INDIRECT_SRC<VGPR_32>;
479 def SI_INDIRECT_SRC_V2 : SI_INDIRECT_SRC<VReg_64>;
480 def SI_INDIRECT_SRC_V4 : SI_INDIRECT_SRC<VReg_128>;
481 def SI_INDIRECT_SRC_V8 : SI_INDIRECT_SRC<VReg_256>;
482 def SI_INDIRECT_SRC_V16 : SI_INDIRECT_SRC<VReg_512>;
484 def SI_INDIRECT_DST_V1 : SI_INDIRECT_DST<VGPR_32>;
485 def SI_INDIRECT_DST_V2 : SI_INDIRECT_DST<VReg_64>;
486 def SI_INDIRECT_DST_V4 : SI_INDIRECT_DST<VReg_128>;
487 def SI_INDIRECT_DST_V8 : SI_INDIRECT_DST<VReg_256>;
488 def SI_INDIRECT_DST_V16 : SI_INDIRECT_DST<VReg_512>;
490 } // End Uses = [EXEC], Defs = [M0, EXEC]
492 multiclass SI_SPILL_SGPR <RegisterClass sgpr_class> {
493 let UseNamedOperandTable = 1, SGPRSpill = 1, Uses = [EXEC] in {
494 def _SAVE : PseudoInstSI <
496 (ins sgpr_class:$data, i32imm:$addr)> {
501 def _RESTORE : PseudoInstSI <
502 (outs sgpr_class:$data),
503 (ins i32imm:$addr)> {
507 } // End UseNamedOperandTable = 1
510 // You cannot use M0 as the output of v_readlane_b32 instructions or
511 // use it in the sdata operand of SMEM instructions. We still need to
512 // be able to spill the physical register m0, so allow it for
513 // SI_SPILL_32_* instructions.
514 defm SI_SPILL_S32 : SI_SPILL_SGPR <SReg_32>;
515 defm SI_SPILL_S64 : SI_SPILL_SGPR <SReg_64>;
516 defm SI_SPILL_S96 : SI_SPILL_SGPR <SReg_96>;
517 defm SI_SPILL_S128 : SI_SPILL_SGPR <SReg_128>;
518 defm SI_SPILL_S160 : SI_SPILL_SGPR <SReg_160>;
519 defm SI_SPILL_S256 : SI_SPILL_SGPR <SReg_256>;
520 defm SI_SPILL_S512 : SI_SPILL_SGPR <SReg_512>;
521 defm SI_SPILL_S1024 : SI_SPILL_SGPR <SReg_1024>;
523 multiclass SI_SPILL_VGPR <RegisterClass vgpr_class> {
524 let UseNamedOperandTable = 1, VGPRSpill = 1,
525 SchedRW = [WriteVMEM] in {
526 def _SAVE : VPseudoInstSI <
528 (ins vgpr_class:$vdata, i32imm:$vaddr, SReg_128:$srsrc,
529 SReg_32:$soffset, i32imm:$offset)> {
532 // (2 * 4) + (8 * num_subregs) bytes maximum
533 int MaxSize = !add(!shl(!srl(vgpr_class.Size, 5), 3), 8);
534 // Size field is unsigned char and cannot fit more.
535 let Size = !if(!le(MaxSize, 256), MaxSize, 252);
538 def _RESTORE : VPseudoInstSI <
539 (outs vgpr_class:$vdata),
540 (ins i32imm:$vaddr, SReg_128:$srsrc, SReg_32:$soffset,
545 // (2 * 4) + (8 * num_subregs) bytes maximum
546 int MaxSize = !add(!shl(!srl(vgpr_class.Size, 5), 3), 8);
547 // Size field is unsigned char and cannot fit more.
548 let Size = !if(!le(MaxSize, 256), MaxSize, 252);
550 } // End UseNamedOperandTable = 1, VGPRSpill = 1, SchedRW = [WriteVMEM]
553 defm SI_SPILL_V32 : SI_SPILL_VGPR <VGPR_32>;
554 defm SI_SPILL_V64 : SI_SPILL_VGPR <VReg_64>;
555 defm SI_SPILL_V96 : SI_SPILL_VGPR <VReg_96>;
556 defm SI_SPILL_V128 : SI_SPILL_VGPR <VReg_128>;
557 defm SI_SPILL_V160 : SI_SPILL_VGPR <VReg_160>;
558 defm SI_SPILL_V256 : SI_SPILL_VGPR <VReg_256>;
559 defm SI_SPILL_V512 : SI_SPILL_VGPR <VReg_512>;
560 defm SI_SPILL_V1024 : SI_SPILL_VGPR <VReg_1024>;
562 multiclass SI_SPILL_AGPR <RegisterClass vgpr_class> {
563 let UseNamedOperandTable = 1, VGPRSpill = 1,
564 Constraints = "@earlyclobber $tmp",
565 SchedRW = [WriteVMEM] in {
566 def _SAVE : VPseudoInstSI <
568 (ins vgpr_class:$vdata, i32imm:$vaddr, SReg_128:$srsrc,
569 SReg_32:$soffset, i32imm:$offset)> {
572 // (2 * 4) + (16 * num_subregs) bytes maximum
573 int MaxSize = !add(!shl(!srl(vgpr_class.Size, 5), 4), 8);
574 // Size field is unsigned char and cannot fit more.
575 let Size = !if(!le(MaxSize, 256), MaxSize, 252);
578 def _RESTORE : VPseudoInstSI <
579 (outs vgpr_class:$vdata, VGPR_32:$tmp),
580 (ins i32imm:$vaddr, SReg_128:$srsrc, SReg_32:$soffset,
585 // (2 * 4) + (16 * num_subregs) bytes maximum
586 int MaxSize = !add(!shl(!srl(vgpr_class.Size, 5), 4), 8);
587 // Size field is unsigned char and cannot fit more.
588 let Size = !if(!le(MaxSize, 256), MaxSize, 252);
590 } // End UseNamedOperandTable = 1, VGPRSpill = 1, SchedRW = [WriteVMEM]
593 defm SI_SPILL_A32 : SI_SPILL_AGPR <AGPR_32>;
594 defm SI_SPILL_A64 : SI_SPILL_AGPR <AReg_64>;
595 defm SI_SPILL_A128 : SI_SPILL_AGPR <AReg_128>;
596 defm SI_SPILL_A512 : SI_SPILL_AGPR <AReg_512>;
597 defm SI_SPILL_A1024 : SI_SPILL_AGPR <AReg_1024>;
599 def SI_PC_ADD_REL_OFFSET : SPseudoInstSI <
601 (ins si_ga:$ptr_lo, si_ga:$ptr_hi),
603 (i64 (SIpc_add_rel_offset tglobaladdr:$ptr_lo, tglobaladdr:$ptr_hi)))]> {
608 (SIpc_add_rel_offset tglobaladdr:$ptr_lo, 0),
609 (SI_PC_ADD_REL_OFFSET $ptr_lo, (i32 0))
613 (AMDGPUinit_exec i64:$src),
614 (SI_INIT_EXEC (as_i64imm $src))
616 let WaveSizePredicate = isWave64;
620 (AMDGPUinit_exec i64:$src),
621 (SI_INIT_EXEC_LO (as_i32imm $src))
623 let WaveSizePredicate = isWave32;
627 (AMDGPUinit_exec_from_input i32:$input, i32:$shift),
628 (SI_INIT_EXEC_FROM_INPUT (i32 $input), (as_i32imm $shift))
632 (AMDGPUtrap timm:$trapid),
637 (AMDGPUelse i1:$src, bb:$target),
638 (SI_ELSE $src, $target, 0)
642 // -1.0 as i32 (LowerINTRINSIC_VOID converts all other constants to -1.0)
643 (AMDGPUkill (i32 -1082130432)),
644 (SI_KILL_I1_PSEUDO (i1 0), 0)
648 (int_amdgcn_kill i1:$src),
649 (SI_KILL_I1_PSEUDO $src, 0)
653 (int_amdgcn_kill (i1 (not i1:$src))),
654 (SI_KILL_I1_PSEUDO $src, -1)
658 (AMDGPUkill i32:$src),
659 (SI_KILL_F32_COND_IMM_PSEUDO $src, 0, 3) // 3 means SETOGE
663 (int_amdgcn_kill (i1 (setcc f32:$src, InlineFPImm<f32>:$imm, cond:$cond))),
664 (SI_KILL_F32_COND_IMM_PSEUDO $src, (bitcast_fpimm_to_i32 $imm), (cond_as_i32imm $cond))
667 // TODO: we could add more variants for other types of conditionals
670 (i64 (int_amdgcn_icmp i1:$src, (i1 0), (i32 33))),
671 (COPY $src) // Return the SGPRs representing i1 src
675 (i32 (int_amdgcn_icmp i1:$src, (i1 0), (i32 33))),
676 (COPY $src) // Return the SGPRs representing i1 src
679 //===----------------------------------------------------------------------===//
681 //===----------------------------------------------------------------------===//
683 let OtherPredicates = [UnsafeFPMath] in {
685 //def : RcpPat<V_RCP_F64_e32, f64>;
686 //defm : RsqPat<V_RSQ_F64_e32, f64>;
687 //defm : RsqPat<V_RSQ_F32_e32, f32>;
689 def : RsqPat<V_RSQ_F32_e32, f32>;
690 def : RsqPat<V_RSQ_F64_e32, f64>;
692 // Convert (x - floor(x)) to fract(x)
694 (f32 (fsub (f32 (VOP3Mods f32:$x, i32:$mods)),
695 (f32 (ffloor (f32 (VOP3Mods f32:$x, i32:$mods)))))),
696 (V_FRACT_F32_e64 $mods, $x, DSTCLAMP.NONE, DSTOMOD.NONE)
699 // Convert (x + (-floor(x))) to fract(x)
701 (f64 (fadd (f64 (VOP3Mods f64:$x, i32:$mods)),
702 (f64 (fneg (f64 (ffloor (f64 (VOP3Mods f64:$x, i32:$mods)))))))),
703 (V_FRACT_F64_e64 $mods, $x, DSTCLAMP.NONE, DSTOMOD.NONE)
706 } // End OtherPredicates = [UnsafeFPMath]
709 // f16_to_fp patterns
711 (f32 (f16_to_fp i32:$src0)),
712 (V_CVT_F32_F16_e64 SRCMODS.NONE, $src0, DSTCLAMP.NONE, DSTOMOD.NONE)
716 (f32 (f16_to_fp (and_oneuse i32:$src0, 0x7fff))),
717 (V_CVT_F32_F16_e64 SRCMODS.ABS, $src0, DSTCLAMP.NONE, DSTOMOD.NONE)
721 (f32 (f16_to_fp (i32 (srl_oneuse (and_oneuse i32:$src0, 0x7fff0000), (i32 16))))),
722 (V_CVT_F32_F16_e64 SRCMODS.ABS, (i32 (V_LSHRREV_B32_e64 (i32 16), i32:$src0)), DSTCLAMP.NONE, DSTOMOD.NONE)
726 (f32 (f16_to_fp (or_oneuse i32:$src0, 0x8000))),
727 (V_CVT_F32_F16_e64 SRCMODS.NEG_ABS, $src0, DSTCLAMP.NONE, DSTOMOD.NONE)
731 (f32 (f16_to_fp (xor_oneuse i32:$src0, 0x8000))),
732 (V_CVT_F32_F16_e64 SRCMODS.NEG, $src0, DSTCLAMP.NONE, DSTOMOD.NONE)
736 (f64 (fpextend f16:$src)),
737 (V_CVT_F64_F32_e32 (V_CVT_F32_F16_e32 $src))
740 // fp_to_fp16 patterns
742 (i32 (AMDGPUfp_to_f16 (f32 (VOP3Mods f32:$src0, i32:$src0_modifiers)))),
743 (V_CVT_F16_F32_e64 $src0_modifiers, f32:$src0, DSTCLAMP.NONE, DSTOMOD.NONE)
747 (i32 (fp_to_sint f16:$src)),
748 (V_CVT_I32_F32_e32 (V_CVT_F32_F16_e32 $src))
752 (i32 (fp_to_uint f16:$src)),
753 (V_CVT_U32_F32_e32 (V_CVT_F32_F16_e32 $src))
757 (f16 (sint_to_fp i32:$src)),
758 (V_CVT_F16_F32_e32 (V_CVT_F32_I32_e32 $src))
762 (f16 (uint_to_fp i32:$src)),
763 (V_CVT_F16_F32_e32 (V_CVT_F32_U32_e32 $src))
766 //===----------------------------------------------------------------------===//
768 //===----------------------------------------------------------------------===//
770 multiclass FMADPat <ValueType vt, Instruction inst> {
772 (vt (fmad (VOP3NoMods vt:$src0),
773 (VOP3NoMods vt:$src1),
774 (VOP3NoMods vt:$src2))),
775 (inst SRCMODS.NONE, $src0, SRCMODS.NONE, $src1,
776 SRCMODS.NONE, $src2, DSTCLAMP.NONE, DSTOMOD.NONE)
780 defm : FMADPat <f16, V_MAC_F16_e64>;
781 defm : FMADPat <f32, V_MAC_F32_e64>;
783 class FMADModsPat<Instruction inst, SDPatternOperator mad_opr, ValueType Ty>
785 (Ty (mad_opr (VOP3Mods Ty:$src0, i32:$src0_mod),
786 (VOP3Mods Ty:$src1, i32:$src1_mod),
787 (VOP3Mods Ty:$src2, i32:$src2_mod))),
788 (inst $src0_mod, $src0, $src1_mod, $src1,
789 $src2_mod, $src2, DSTCLAMP.NONE, DSTOMOD.NONE)
792 def : FMADModsPat<V_MAD_F32, AMDGPUfmad_ftz, f32>;
793 def : FMADModsPat<V_MAD_F16, AMDGPUfmad_ftz, f16> {
794 let SubtargetPredicate = Has16BitInsts;
797 multiclass SelectPat <ValueType vt> {
799 (vt (select i1:$src0, (VOP3Mods_f32 vt:$src1, i32:$src1_mods),
800 (VOP3Mods_f32 vt:$src2, i32:$src2_mods))),
801 (V_CNDMASK_B32_e64 $src2_mods, $src2, $src1_mods, $src1, $src0)
805 defm : SelectPat <i16>;
806 defm : SelectPat <i32>;
807 defm : SelectPat <f16>;
808 defm : SelectPat <f32>;
810 let AddedComplexity = 1 in {
812 (i32 (add (i32 (getDivergentFrag<ctpop>.ret i32:$popcnt)), i32:$val)),
813 (V_BCNT_U32_B32_e64 $popcnt, $val)
817 (i16 (add (i16 (trunc (getDivergentFrag<ctpop>.ret i32:$popcnt))), i16:$val)),
818 (V_BCNT_U32_B32_e64 $popcnt, $val)
821 /********** ============================================ **********/
822 /********** Extraction, Insertion, Building and Casting **********/
823 /********** ============================================ **********/
825 foreach Index = 0-2 in {
826 def Extract_Element_v2i32_#Index : Extract_Element <
827 i32, v2i32, Index, !cast<SubRegIndex>(sub#Index)
829 def Insert_Element_v2i32_#Index : Insert_Element <
830 i32, v2i32, Index, !cast<SubRegIndex>(sub#Index)
833 def Extract_Element_v2f32_#Index : Extract_Element <
834 f32, v2f32, Index, !cast<SubRegIndex>(sub#Index)
836 def Insert_Element_v2f32_#Index : Insert_Element <
837 f32, v2f32, Index, !cast<SubRegIndex>(sub#Index)
841 foreach Index = 0-2 in {
842 def Extract_Element_v3i32_#Index : Extract_Element <
843 i32, v3i32, Index, !cast<SubRegIndex>(sub#Index)
845 def Insert_Element_v3i32_#Index : Insert_Element <
846 i32, v3i32, Index, !cast<SubRegIndex>(sub#Index)
849 def Extract_Element_v3f32_#Index : Extract_Element <
850 f32, v3f32, Index, !cast<SubRegIndex>(sub#Index)
852 def Insert_Element_v3f32_#Index : Insert_Element <
853 f32, v3f32, Index, !cast<SubRegIndex>(sub#Index)
857 foreach Index = 0-3 in {
858 def Extract_Element_v4i32_#Index : Extract_Element <
859 i32, v4i32, Index, !cast<SubRegIndex>(sub#Index)
861 def Insert_Element_v4i32_#Index : Insert_Element <
862 i32, v4i32, Index, !cast<SubRegIndex>(sub#Index)
865 def Extract_Element_v4f32_#Index : Extract_Element <
866 f32, v4f32, Index, !cast<SubRegIndex>(sub#Index)
868 def Insert_Element_v4f32_#Index : Insert_Element <
869 f32, v4f32, Index, !cast<SubRegIndex>(sub#Index)
873 foreach Index = 0-4 in {
874 def Extract_Element_v5i32_#Index : Extract_Element <
875 i32, v5i32, Index, !cast<SubRegIndex>(sub#Index)
877 def Insert_Element_v5i32_#Index : Insert_Element <
878 i32, v5i32, Index, !cast<SubRegIndex>(sub#Index)
881 def Extract_Element_v5f32_#Index : Extract_Element <
882 f32, v5f32, Index, !cast<SubRegIndex>(sub#Index)
884 def Insert_Element_v5f32_#Index : Insert_Element <
885 f32, v5f32, Index, !cast<SubRegIndex>(sub#Index)
889 foreach Index = 0-7 in {
890 def Extract_Element_v8i32_#Index : Extract_Element <
891 i32, v8i32, Index, !cast<SubRegIndex>(sub#Index)
893 def Insert_Element_v8i32_#Index : Insert_Element <
894 i32, v8i32, Index, !cast<SubRegIndex>(sub#Index)
897 def Extract_Element_v8f32_#Index : Extract_Element <
898 f32, v8f32, Index, !cast<SubRegIndex>(sub#Index)
900 def Insert_Element_v8f32_#Index : Insert_Element <
901 f32, v8f32, Index, !cast<SubRegIndex>(sub#Index)
905 foreach Index = 0-15 in {
906 def Extract_Element_v16i32_#Index : Extract_Element <
907 i32, v16i32, Index, !cast<SubRegIndex>(sub#Index)
909 def Insert_Element_v16i32_#Index : Insert_Element <
910 i32, v16i32, Index, !cast<SubRegIndex>(sub#Index)
913 def Extract_Element_v16f32_#Index : Extract_Element <
914 f32, v16f32, Index, !cast<SubRegIndex>(sub#Index)
916 def Insert_Element_v16f32_#Index : Insert_Element <
917 f32, v16f32, Index, !cast<SubRegIndex>(sub#Index)
923 (extract_subvector v4i16:$vec, (i32 0)),
924 (v2i16 (EXTRACT_SUBREG v4i16:$vec, sub0))
928 (extract_subvector v4i16:$vec, (i32 2)),
929 (v2i16 (EXTRACT_SUBREG v4i16:$vec, sub1))
933 (extract_subvector v4f16:$vec, (i32 0)),
934 (v2f16 (EXTRACT_SUBREG v4f16:$vec, sub0))
938 (extract_subvector v4f16:$vec, (i32 2)),
939 (v2f16 (EXTRACT_SUBREG v4f16:$vec, sub1))
942 foreach Index = 0-31 in {
943 def Extract_Element_v32i32_#Index : Extract_Element <
944 i32, v32i32, Index, !cast<SubRegIndex>(sub#Index)
947 def Insert_Element_v32i32_#Index : Insert_Element <
948 i32, v32i32, Index, !cast<SubRegIndex>(sub#Index)
951 def Extract_Element_v32f32_#Index : Extract_Element <
952 f32, v32f32, Index, !cast<SubRegIndex>(sub#Index)
955 def Insert_Element_v32f32_#Index : Insert_Element <
956 f32, v32f32, Index, !cast<SubRegIndex>(sub#Index)
960 // FIXME: Why do only some of these type combinations for SReg and
963 def : BitConvert <i16, f16, VGPR_32>;
964 def : BitConvert <f16, i16, VGPR_32>;
965 def : BitConvert <i16, f16, SReg_32>;
966 def : BitConvert <f16, i16, SReg_32>;
969 def : BitConvert <i32, f32, VGPR_32>;
970 def : BitConvert <f32, i32, VGPR_32>;
971 def : BitConvert <i32, f32, SReg_32>;
972 def : BitConvert <f32, i32, SReg_32>;
973 def : BitConvert <v2i16, i32, SReg_32>;
974 def : BitConvert <i32, v2i16, SReg_32>;
975 def : BitConvert <v2f16, i32, SReg_32>;
976 def : BitConvert <i32, v2f16, SReg_32>;
977 def : BitConvert <v2i16, v2f16, SReg_32>;
978 def : BitConvert <v2f16, v2i16, SReg_32>;
979 def : BitConvert <v2f16, f32, SReg_32>;
980 def : BitConvert <f32, v2f16, SReg_32>;
981 def : BitConvert <v2i16, f32, SReg_32>;
982 def : BitConvert <f32, v2i16, SReg_32>;
985 def : BitConvert <i64, f64, VReg_64>;
986 def : BitConvert <f64, i64, VReg_64>;
987 def : BitConvert <v2i32, v2f32, VReg_64>;
988 def : BitConvert <v2f32, v2i32, VReg_64>;
989 def : BitConvert <i64, v2i32, VReg_64>;
990 def : BitConvert <v2i32, i64, VReg_64>;
991 def : BitConvert <i64, v2f32, VReg_64>;
992 def : BitConvert <v2f32, i64, VReg_64>;
993 def : BitConvert <f64, v2f32, VReg_64>;
994 def : BitConvert <v2f32, f64, VReg_64>;
995 def : BitConvert <f64, v2i32, VReg_64>;
996 def : BitConvert <v2i32, f64, VReg_64>;
997 def : BitConvert <v4i16, v4f16, VReg_64>;
998 def : BitConvert <v4f16, v4i16, VReg_64>;
1001 def : BitConvert <v2i32, v4f16, VReg_64>;
1002 def : BitConvert <v4f16, v2i32, VReg_64>;
1003 def : BitConvert <v2i32, v4f16, VReg_64>;
1004 def : BitConvert <v2i32, v4i16, VReg_64>;
1005 def : BitConvert <v4i16, v2i32, VReg_64>;
1006 def : BitConvert <v2f32, v4f16, VReg_64>;
1007 def : BitConvert <v4f16, v2f32, VReg_64>;
1008 def : BitConvert <v2f32, v4i16, VReg_64>;
1009 def : BitConvert <v4i16, v2f32, VReg_64>;
1010 def : BitConvert <v4i16, f64, VReg_64>;
1011 def : BitConvert <v4f16, f64, VReg_64>;
1012 def : BitConvert <f64, v4i16, VReg_64>;
1013 def : BitConvert <f64, v4f16, VReg_64>;
1014 def : BitConvert <v4i16, i64, VReg_64>;
1015 def : BitConvert <v4f16, i64, VReg_64>;
1016 def : BitConvert <i64, v4i16, VReg_64>;
1017 def : BitConvert <i64, v4f16, VReg_64>;
1019 def : BitConvert <v4i32, v4f32, VReg_128>;
1020 def : BitConvert <v4f32, v4i32, VReg_128>;
1023 def : BitConvert <v3i32, v3f32, SGPR_96>;
1024 def : BitConvert <v3f32, v3i32, SGPR_96>;
1027 def : BitConvert <v2i64, v4i32, SReg_128>;
1028 def : BitConvert <v4i32, v2i64, SReg_128>;
1029 def : BitConvert <v2f64, v4f32, VReg_128>;
1030 def : BitConvert <v2f64, v4i32, VReg_128>;
1031 def : BitConvert <v4f32, v2f64, VReg_128>;
1032 def : BitConvert <v4i32, v2f64, VReg_128>;
1033 def : BitConvert <v2i64, v2f64, VReg_128>;
1034 def : BitConvert <v2f64, v2i64, VReg_128>;
1037 def : BitConvert <v5i32, v5f32, SGPR_160>;
1038 def : BitConvert <v5f32, v5i32, SGPR_160>;
1041 def : BitConvert <v8i32, v8f32, SReg_256>;
1042 def : BitConvert <v8f32, v8i32, SReg_256>;
1043 def : BitConvert <v8i32, v8f32, VReg_256>;
1044 def : BitConvert <v8f32, v8i32, VReg_256>;
1047 def : BitConvert <v16i32, v16f32, VReg_512>;
1048 def : BitConvert <v16f32, v16i32, VReg_512>;
1051 def : BitConvert <v32i32, v32f32, VReg_1024>;
1052 def : BitConvert <v32f32, v32i32, VReg_1024>;
1054 /********** =================== **********/
1055 /********** Src & Dst modifiers **********/
1056 /********** =================== **********/
1059 // If denormals are not enabled, it only impacts the compare of the
1060 // inputs. The output result is not flushed.
1061 class ClampPat<Instruction inst, ValueType vt> : GCNPat <
1062 (vt (AMDGPUclamp (VOP3Mods vt:$src0, i32:$src0_modifiers))),
1063 (inst i32:$src0_modifiers, vt:$src0,
1064 i32:$src0_modifiers, vt:$src0, DSTCLAMP.ENABLE, DSTOMOD.NONE)
1067 def : ClampPat<V_MAX_F32_e64, f32>;
1068 def : ClampPat<V_MAX_F64, f64>;
1069 def : ClampPat<V_MAX_F16_e64, f16>;
1071 let SubtargetPredicate = HasVOP3PInsts in {
1073 (v2f16 (AMDGPUclamp (VOP3PMods v2f16:$src0, i32:$src0_modifiers))),
1074 (V_PK_MAX_F16 $src0_modifiers, $src0,
1075 $src0_modifiers, $src0, DSTCLAMP.ENABLE)
1079 /********** ================================ **********/
1080 /********** Floating point absolute/negative **********/
1081 /********** ================================ **********/
1083 // Prevent expanding both fneg and fabs.
1086 (fneg (fabs f32:$src)),
1087 (S_OR_B32 $src, (S_MOV_B32(i32 0x80000000))) // Set sign bit
1090 // FIXME: Should use S_OR_B32
1092 (fneg (fabs f64:$src)),
1093 (REG_SEQUENCE VReg_64,
1094 (i32 (EXTRACT_SUBREG f64:$src, sub0)),
1096 (V_OR_B32_e32 (i32 (EXTRACT_SUBREG f64:$src, sub1)),
1097 (V_MOV_B32_e32 (i32 0x80000000))), // Set sign bit.
1103 (S_AND_B32 $src, (S_MOV_B32 (i32 0x7fffffff)))
1108 (V_XOR_B32_e32 $src, (V_MOV_B32_e32 (i32 0x80000000)))
1113 (REG_SEQUENCE VReg_64,
1114 (i32 (EXTRACT_SUBREG f64:$src, sub0)),
1116 (V_AND_B32_e64 (i32 (EXTRACT_SUBREG f64:$src, sub1)),
1117 (V_MOV_B32_e32 (i32 0x7fffffff))), // Set sign bit.
1123 (REG_SEQUENCE VReg_64,
1124 (i32 (EXTRACT_SUBREG f64:$src, sub0)),
1126 (V_XOR_B32_e32 (i32 (EXTRACT_SUBREG f64:$src, sub1)),
1127 (i32 (V_MOV_B32_e32 (i32 0x80000000)))),
1132 (fcopysign f16:$src0, f16:$src1),
1133 (V_BFI_B32 (S_MOV_B32 (i32 0x00007fff)), $src0, $src1)
1137 (fcopysign f32:$src0, f16:$src1),
1138 (V_BFI_B32 (S_MOV_B32 (i32 0x7fffffff)), $src0,
1139 (V_LSHLREV_B32_e64 (i32 16), $src1))
1143 (fcopysign f64:$src0, f16:$src1),
1144 (REG_SEQUENCE SReg_64,
1145 (i32 (EXTRACT_SUBREG $src0, sub0)), sub0,
1146 (V_BFI_B32 (S_MOV_B32 (i32 0x7fffffff)), (i32 (EXTRACT_SUBREG $src0, sub1)),
1147 (V_LSHLREV_B32_e64 (i32 16), $src1)), sub1)
1151 (fcopysign f16:$src0, f32:$src1),
1152 (V_BFI_B32 (S_MOV_B32 (i32 0x00007fff)), $src0,
1153 (V_LSHRREV_B32_e64 (i32 16), $src1))
1157 (fcopysign f16:$src0, f64:$src1),
1158 (V_BFI_B32 (S_MOV_B32 (i32 0x00007fff)), $src0,
1159 (V_LSHRREV_B32_e64 (i32 16), (EXTRACT_SUBREG $src1, sub1)))
1164 (S_XOR_B32 $src, (S_MOV_B32 (i32 0x00008000)))
1169 (S_AND_B32 $src, (S_MOV_B32 (i32 0x00007fff)))
1173 (fneg (fabs f16:$src)),
1174 (S_OR_B32 $src, (S_MOV_B32 (i32 0x00008000))) // Set sign bit
1179 (S_XOR_B32 $src, (S_MOV_B32 (i32 0x80008000)))
1184 (S_AND_B32 $src, (S_MOV_B32 (i32 0x7fff7fff)))
1187 // This is really (fneg (fabs v2f16:$src))
1189 // fabs is not reported as free because there is modifier for it in
1190 // VOP3P instructions, so it is turned into the bit op.
1192 (fneg (v2f16 (bitconvert (and_oneuse i32:$src, 0x7fff7fff)))),
1193 (S_OR_B32 $src, (S_MOV_B32 (i32 0x80008000))) // Set sign bit
1197 (fneg (v2f16 (fabs v2f16:$src))),
1198 (S_OR_B32 $src, (S_MOV_B32 (i32 0x80008000))) // Set sign bit
1201 /********** ================== **********/
1202 /********** Immediate Patterns **********/
1203 /********** ================== **********/
1206 (VGPRImm<(i32 imm)>:$imm),
1207 (V_MOV_B32_e32 imm:$imm)
1211 (VGPRImm<(f32 fpimm)>:$imm),
1212 (V_MOV_B32_e32 (f32 (bitcast_fpimm_to_i32 $imm)))
1217 (S_MOV_B32 imm:$imm)
1221 (VGPRImm<(SIlds tglobaladdr:$ga)>),
1226 (SIlds tglobaladdr:$ga),
1230 // FIXME: Workaround for ordering issue with peephole optimizer where
1231 // a register class copy interferes with immediate folding. Should
1232 // use s_mov_b32, which can be shrunk to s_movk_i32
1234 (VGPRImm<(f16 fpimm)>:$imm),
1235 (V_MOV_B32_e32 (f16 (bitcast_fpimm_to_i32 $imm)))
1240 (S_MOV_B32 (f32 (bitcast_fpimm_to_i32 $imm)))
1245 (S_MOV_B32 (i32 (bitcast_fpimm_to_i32 $imm)))
1249 (i32 frameindex:$fi),
1250 (V_MOV_B32_e32 (i32 (frameindex_to_targetframeindex $fi)))
1254 (i64 InlineImm<i64>:$imm),
1255 (S_MOV_B64 InlineImm<i64>:$imm)
1258 // XXX - Should this use a s_cmp to set SCC?
1260 // Set to sign-extended 64-bit value (true = -1, false = 0)
1263 (S_MOV_B64 (i64 (as_i64imm $imm)))
1265 let WaveSizePredicate = isWave64;
1270 (S_MOV_B32 (i32 (as_i32imm $imm)))
1272 let WaveSizePredicate = isWave32;
1276 (f64 InlineFPImm<f64>:$imm),
1277 (S_MOV_B64 (f64 (bitcast_fpimm_to_i64 InlineFPImm<f64>:$imm)))
1280 /********** ================== **********/
1281 /********** Intrinsic Patterns **********/
1282 /********** ================== **********/
1284 def : POW_Common <V_LOG_F32_e32, V_EXP_F32_e32, V_MUL_LEGACY_F32_e32>;
1287 (i32 (sext i1:$src0)),
1288 (V_CNDMASK_B32_e64 /*src0mod*/(i32 0), /*src0*/(i32 0),
1289 /*src1mod*/(i32 0), /*src1*/(i32 -1), $src0)
1292 class Ext32Pat <SDNode ext> : GCNPat <
1293 (i32 (ext i1:$src0)),
1294 (V_CNDMASK_B32_e64 /*src0mod*/(i32 0), /*src0*/(i32 0),
1295 /*src1mod*/(i32 0), /*src1*/(i32 1), $src0)
1298 def : Ext32Pat <zext>;
1299 def : Ext32Pat <anyext>;
1301 // The multiplication scales from [0,1] to the unsigned integer range
1303 (AMDGPUurecip i32:$src0),
1305 (V_MUL_F32_e32 (i32 CONST.FP_UINT_MAX_PLUS_1),
1306 (V_RCP_IFLAG_F32_e32 (V_CVT_F32_U32_e32 $src0))))
1309 //===----------------------------------------------------------------------===//
1311 //===----------------------------------------------------------------------===//
1313 def : IMad24Pat<V_MAD_I32_I24, 1>;
1314 def : UMad24Pat<V_MAD_U32_U24, 1>;
1316 // FIXME: This should only be done for VALU inputs
1317 defm : BFIPatterns <V_BFI_B32, S_MOV_B32, SReg_64>;
1318 def : ROTRPattern <V_ALIGNBIT_B32>;
1320 def : GCNPat<(i32 (trunc (srl i64:$src0, (and i32:$src1, (i32 31))))),
1321 (V_ALIGNBIT_B32 (i32 (EXTRACT_SUBREG (i64 $src0), sub1)),
1322 (i32 (EXTRACT_SUBREG (i64 $src0), sub0)), $src1)>;
1324 def : GCNPat<(i32 (trunc (srl i64:$src0, (i32 ShiftAmt32Imm:$src1)))),
1325 (V_ALIGNBIT_B32 (i32 (EXTRACT_SUBREG (i64 $src0), sub1)),
1326 (i32 (EXTRACT_SUBREG (i64 $src0), sub0)), $src1)>;
1328 /********** ====================== **********/
1329 /********** Indirect addressing **********/
1330 /********** ====================== **********/
1332 multiclass SI_INDIRECT_Pattern <ValueType vt, ValueType eltvt, string VecSize> {
1333 // Extract with offset
1335 (eltvt (extractelt vt:$src, (MOVRELOffset i32:$idx, (i32 imm:$offset)))),
1336 (!cast<Instruction>("SI_INDIRECT_SRC_"#VecSize) $src, $idx, imm:$offset)
1339 // Insert with offset
1341 (insertelt vt:$src, eltvt:$val, (MOVRELOffset i32:$idx, (i32 imm:$offset))),
1342 (!cast<Instruction>("SI_INDIRECT_DST_"#VecSize) $src, $idx, imm:$offset, $val)
1346 defm : SI_INDIRECT_Pattern <v2f32, f32, "V2">;
1347 defm : SI_INDIRECT_Pattern <v4f32, f32, "V4">;
1348 defm : SI_INDIRECT_Pattern <v8f32, f32, "V8">;
1349 defm : SI_INDIRECT_Pattern <v16f32, f32, "V16">;
1351 defm : SI_INDIRECT_Pattern <v2i32, i32, "V2">;
1352 defm : SI_INDIRECT_Pattern <v4i32, i32, "V4">;
1353 defm : SI_INDIRECT_Pattern <v8i32, i32, "V8">;
1354 defm : SI_INDIRECT_Pattern <v16i32, i32, "V16">;
1356 //===----------------------------------------------------------------------===//
1358 //===----------------------------------------------------------------------===//
1361 (add (sub_oneuse (umax i32:$src0, i32:$src1),
1362 (umin i32:$src0, i32:$src1)),
1364 (V_SAD_U32 $src0, $src1, $src2, (i1 0))
1368 (add (select_oneuse (i1 (setugt i32:$src0, i32:$src1)),
1369 (sub i32:$src0, i32:$src1),
1370 (sub i32:$src1, i32:$src0)),
1372 (V_SAD_U32 $src0, $src1, $src2, (i1 0))
1375 //===----------------------------------------------------------------------===//
1376 // Conversion Patterns
1377 //===----------------------------------------------------------------------===//
1379 def : GCNPat<(i32 (sext_inreg i32:$src, i1)),
1380 (S_BFE_I32 i32:$src, (i32 65536))>; // 0 | 1 << 16
1382 // Handle sext_inreg in i64
1384 (i64 (sext_inreg i64:$src, i1)),
1385 (S_BFE_I64 i64:$src, (i32 0x10000)) // 0 | 1 << 16
1389 (i16 (sext_inreg i16:$src, i1)),
1390 (S_BFE_I32 $src, (i32 0x00010000)) // 0 | 1 << 16
1394 (i16 (sext_inreg i16:$src, i8)),
1395 (S_BFE_I32 $src, (i32 0x80000)) // 0 | 8 << 16
1399 (i64 (sext_inreg i64:$src, i8)),
1400 (S_BFE_I64 i64:$src, (i32 0x80000)) // 0 | 8 << 16
1404 (i64 (sext_inreg i64:$src, i16)),
1405 (S_BFE_I64 i64:$src, (i32 0x100000)) // 0 | 16 << 16
1409 (i64 (sext_inreg i64:$src, i32)),
1410 (S_BFE_I64 i64:$src, (i32 0x200000)) // 0 | 32 << 16
1414 (i64 (zext i32:$src)),
1415 (REG_SEQUENCE SReg_64, $src, sub0, (S_MOV_B32 (i32 0)), sub1)
1419 (i64 (anyext i32:$src)),
1420 (REG_SEQUENCE SReg_64, $src, sub0, (i32 (IMPLICIT_DEF)), sub1)
1423 class ZExt_i64_i1_Pat <SDNode ext> : GCNPat <
1424 (i64 (ext i1:$src)),
1425 (REG_SEQUENCE VReg_64,
1426 (V_CNDMASK_B32_e64 /*src0mod*/(i32 0), /*src0*/(i32 0),
1427 /*src1mod*/(i32 0), /*src1*/(i32 1), $src),
1428 sub0, (S_MOV_B32 (i32 0)), sub1)
1432 def : ZExt_i64_i1_Pat<zext>;
1433 def : ZExt_i64_i1_Pat<anyext>;
1435 // FIXME: We need to use COPY_TO_REGCLASS to work-around the fact that
1436 // REG_SEQUENCE patterns don't support instructions with multiple outputs.
1438 (i64 (sext i32:$src)),
1439 (REG_SEQUENCE SReg_64, $src, sub0,
1440 (i32 (COPY_TO_REGCLASS (S_ASHR_I32 $src, (i32 31)), SReg_32_XM0)), sub1)
1444 (i64 (sext i1:$src)),
1445 (REG_SEQUENCE VReg_64,
1446 (V_CNDMASK_B32_e64 /*src0mod*/(i32 0), /*src0*/(i32 0),
1447 /*src1mod*/(i32 0), /*src1*/(i32 -1), $src), sub0,
1448 (V_CNDMASK_B32_e64 /*src0mod*/(i32 0), /*src0*/(i32 0),
1449 /*src1mod*/(i32 0), /*src1*/(i32 -1), $src), sub1)
1452 class FPToI1Pat<Instruction Inst, int KOne, ValueType kone_type, ValueType vt, SDPatternOperator fp_to_int> : GCNPat <
1453 (i1 (fp_to_int (vt (VOP3Mods vt:$src0, i32:$src0_modifiers)))),
1454 (i1 (Inst 0, (kone_type KOne), $src0_modifiers, $src0, DSTCLAMP.NONE))
1457 def : FPToI1Pat<V_CMP_EQ_F32_e64, CONST.FP32_ONE, i32, f32, fp_to_uint>;
1458 def : FPToI1Pat<V_CMP_EQ_F32_e64, CONST.FP32_NEG_ONE, i32, f32, fp_to_sint>;
1459 def : FPToI1Pat<V_CMP_EQ_F64_e64, CONST.FP64_ONE, i64, f64, fp_to_uint>;
1460 def : FPToI1Pat<V_CMP_EQ_F64_e64, CONST.FP64_NEG_ONE, i64, f64, fp_to_sint>;
1462 // If we need to perform a logical operation on i1 values, we need to
1463 // use vector comparisons since there is only one SCC register. Vector
1464 // comparisons may write to a pair of SGPRs or a single SGPR, so treat
1465 // these as 32 or 64-bit comparisons. When legalizing SGPR copies,
1466 // instructions resulting in the copies from SCC to these instructions
1467 // will be moved to the VALU.
1469 let WaveSizePredicate = isWave64 in {
1471 (i1 (and i1:$src0, i1:$src1)),
1472 (S_AND_B64 $src0, $src1)
1476 (i1 (or i1:$src0, i1:$src1)),
1477 (S_OR_B64 $src0, $src1)
1481 (i1 (xor i1:$src0, i1:$src1)),
1482 (S_XOR_B64 $src0, $src1)
1486 (i1 (add i1:$src0, i1:$src1)),
1487 (S_XOR_B64 $src0, $src1)
1491 (i1 (sub i1:$src0, i1:$src1)),
1492 (S_XOR_B64 $src0, $src1)
1495 let AddedComplexity = 1 in {
1497 (i1 (add i1:$src0, (i1 -1))),
1502 (i1 (sub i1:$src0, (i1 -1))),
1508 let WaveSizePredicate = isWave32 in {
1510 (i1 (and i1:$src0, i1:$src1)),
1511 (S_AND_B32 $src0, $src1)
1515 (i1 (or i1:$src0, i1:$src1)),
1516 (S_OR_B32 $src0, $src1)
1520 (i1 (xor i1:$src0, i1:$src1)),
1521 (S_XOR_B32 $src0, $src1)
1525 (i1 (add i1:$src0, i1:$src1)),
1526 (S_XOR_B32 $src0, $src1)
1530 (i1 (sub i1:$src0, i1:$src1)),
1531 (S_XOR_B32 $src0, $src1)
1534 let AddedComplexity = 1 in {
1536 (i1 (add i1:$src0, (i1 -1))),
1541 (i1 (sub i1:$src0, (i1 -1))),
1548 (f16 (sint_to_fp i1:$src)),
1549 (V_CVT_F16_F32_e32 (
1550 V_CNDMASK_B32_e64 /*src0mod*/(i32 0), /*src0*/(i32 0),
1551 /*src1mod*/(i32 0), /*src1*/(i32 CONST.FP32_NEG_ONE),
1556 (f16 (uint_to_fp i1:$src)),
1557 (V_CVT_F16_F32_e32 (
1558 V_CNDMASK_B32_e64 /*src0mod*/(i32 0), /*src0*/(i32 0),
1559 /*src1mod*/(i32 0), /*src1*/(i32 CONST.FP32_ONE),
1564 (f32 (sint_to_fp i1:$src)),
1565 (V_CNDMASK_B32_e64 /*src0mod*/(i32 0), /*src0*/(i32 0),
1566 /*src1mod*/(i32 0), /*src1*/(i32 CONST.FP32_NEG_ONE),
1571 (f32 (uint_to_fp i1:$src)),
1572 (V_CNDMASK_B32_e64 /*src0mod*/(i32 0), /*src0*/(i32 0),
1573 /*src1mod*/(i32 0), /*src1*/(i32 CONST.FP32_ONE),
1578 (f64 (sint_to_fp i1:$src)),
1579 (V_CVT_F64_I32_e32 (V_CNDMASK_B32_e64 /*src0mod*/(i32 0), /*src0*/(i32 0),
1580 /*src1mod*/(i32 0), /*src1*/(i32 -1),
1585 (f64 (uint_to_fp i1:$src)),
1586 (V_CVT_F64_U32_e32 (V_CNDMASK_B32_e64 /*src0mod*/(i32 0), /*src0*/(i32 0),
1587 /*src1mod*/(i32 0), /*src1*/(i32 1),
1591 //===----------------------------------------------------------------------===//
1592 // Miscellaneous Patterns
1593 //===----------------------------------------------------------------------===//
1595 (i32 (AMDGPUfp16_zext f16:$src)),
1601 (i32 (trunc i64:$a)),
1602 (EXTRACT_SUBREG $a, sub0)
1606 (i1 (trunc i32:$a)),
1607 (V_CMP_EQ_U32_e64 (S_AND_B32 (i32 1), $a), (i32 1))
1611 (i1 (trunc i16:$a)),
1612 (V_CMP_EQ_U32_e64 (S_AND_B32 (i32 1), $a), (i32 1))
1616 (i1 (trunc i64:$a)),
1617 (V_CMP_EQ_U32_e64 (S_AND_B32 (i32 1),
1618 (i32 (EXTRACT_SUBREG $a, sub0))), (i32 1))
1622 (i32 (bswap i32:$a)),
1623 (V_BFI_B32 (S_MOV_B32 (i32 0x00ff00ff)),
1624 (V_ALIGNBIT_B32 $a, $a, (i32 24)),
1625 (V_ALIGNBIT_B32 $a, $a, (i32 8)))
1628 let OtherPredicates = [NoFP16Denormals] in {
1630 (fcanonicalize (f16 (VOP3Mods f16:$src, i32:$src_mods))),
1631 (V_MUL_F16_e64 0, (i32 CONST.FP16_ONE), $src_mods, $src, 0, 0)
1635 (fcanonicalize (f16 (fneg (VOP3Mods f16:$src, i32:$src_mods)))),
1636 (V_MUL_F16_e64 0, (i32 CONST.FP16_NEG_ONE), $src_mods, $src, 0, 0)
1640 (fcanonicalize (v2f16 (VOP3PMods v2f16:$src, i32:$src_mods))),
1641 (V_PK_MUL_F16 0, (i32 CONST.FP16_ONE), $src_mods, $src, DSTCLAMP.NONE)
1645 let OtherPredicates = [FP16Denormals] in {
1647 (fcanonicalize (f16 (VOP3Mods f16:$src, i32:$src_mods))),
1648 (V_MAX_F16_e64 $src_mods, $src, $src_mods, $src, 0, 0)
1651 let SubtargetPredicate = HasVOP3PInsts in {
1653 (fcanonicalize (v2f16 (VOP3PMods v2f16:$src, i32:$src_mods))),
1654 (V_PK_MAX_F16 $src_mods, $src, $src_mods, $src, DSTCLAMP.NONE)
1659 let OtherPredicates = [NoFP32Denormals] in {
1661 (fcanonicalize (f32 (VOP3Mods f32:$src, i32:$src_mods))),
1662 (V_MUL_F32_e64 0, (i32 CONST.FP32_ONE), $src_mods, $src, 0, 0)
1666 (fcanonicalize (f32 (fneg (VOP3Mods f32:$src, i32:$src_mods)))),
1667 (V_MUL_F32_e64 0, (i32 CONST.FP32_NEG_ONE), $src_mods, $src, 0, 0)
1671 let OtherPredicates = [FP32Denormals] in {
1673 (fcanonicalize (f32 (VOP3Mods f32:$src, i32:$src_mods))),
1674 (V_MAX_F32_e64 $src_mods, $src, $src_mods, $src, 0, 0)
1678 let OtherPredicates = [NoFP64Denormals] in {
1680 (fcanonicalize (f64 (VOP3Mods f64:$src, i32:$src_mods))),
1681 (V_MUL_F64 0, CONST.FP64_ONE, $src_mods, $src, 0, 0)
1685 let OtherPredicates = [FP64Denormals] in {
1687 (fcanonicalize (f64 (VOP3Mods f64:$src, i32:$src_mods))),
1688 (V_MAX_F64 $src_mods, $src, $src_mods, $src, 0, 0)
1692 let OtherPredicates = [HasDLInsts] in {
1694 (fma (f32 (VOP3Mods0 f32:$src0, i32:$src0_modifiers, i1:$clamp, i32:$omod)),
1695 (f32 (VOP3Mods f32:$src1, i32:$src1_modifiers)),
1696 (f32 (VOP3NoMods f32:$src2))),
1697 (V_FMAC_F32_e64 $src0_modifiers, $src0, $src1_modifiers, $src1,
1698 SRCMODS.NONE, $src2, $clamp, $omod)
1700 } // End OtherPredicates = [HasDLInsts]
1702 let SubtargetPredicate = isGFX10Plus in
1704 (fma (f16 (VOP3Mods0 f32:$src0, i32:$src0_modifiers, i1:$clamp, i32:$omod)),
1705 (f16 (VOP3Mods f32:$src1, i32:$src1_modifiers)),
1706 (f16 (VOP3NoMods f32:$src2))),
1707 (V_FMAC_F16_e64 $src0_modifiers, $src0, $src1_modifiers, $src1,
1708 SRCMODS.NONE, $src2, $clamp, $omod)
1711 // Allow integer inputs
1712 class ExpPattern<SDPatternOperator node, ValueType vt, Instruction Inst> : GCNPat<
1713 (node (i8 timm:$tgt), (i8 timm:$en), vt:$src0, vt:$src1, vt:$src2, vt:$src3, (i1 timm:$compr), (i1 timm:$vm)),
1714 (Inst i8:$tgt, vt:$src0, vt:$src1, vt:$src2, vt:$src3, i1:$vm, i1:$compr, i8:$en)
1717 def : ExpPattern<AMDGPUexport, i32, EXP>;
1718 def : ExpPattern<AMDGPUexport_done, i32, EXP_DONE>;
1720 // COPY is workaround tablegen bug from multiple outputs
1721 // from S_LSHL_B32's multiple outputs from implicit scc def.
1723 (v2i16 (build_vector (i16 0), i16:$src1)),
1724 (v2i16 (COPY (S_LSHL_B32 i16:$src1, (i16 16))))
1728 (v2i16 (build_vector i16:$src0, (i16 undef))),
1729 (v2i16 (COPY $src0))
1733 (v2f16 (build_vector f16:$src0, (f16 undef))),
1734 (v2f16 (COPY $src0))
1738 (v2i16 (build_vector (i16 undef), i16:$src1)),
1739 (v2i16 (COPY (S_LSHL_B32 $src1, (i32 16))))
1743 (v2f16 (build_vector (f16 undef), f16:$src1)),
1744 (v2f16 (COPY (S_LSHL_B32 $src1, (i32 16))))
1747 let SubtargetPredicate = HasVOP3PInsts in {
1749 (v2i16 (build_vector i16:$src0, i16:$src1)),
1750 (v2i16 (S_PACK_LL_B32_B16 $src0, $src1))
1753 // With multiple uses of the shift, this will duplicate the shift and
1754 // increase register pressure.
1756 (v2i16 (build_vector i16:$src0, (i16 (trunc (srl_oneuse i32:$src1, (i32 16)))))),
1757 (v2i16 (S_PACK_LH_B32_B16 i16:$src0, i32:$src1))
1762 (v2i16 (build_vector (i16 (trunc (srl_oneuse i32:$src0, (i32 16)))),
1763 (i16 (trunc (srl_oneuse i32:$src1, (i32 16)))))),
1764 (v2i16 (S_PACK_HH_B32_B16 $src0, $src1))
1767 // TODO: Should source modifiers be matched to v_pack_b32_f16?
1769 (v2f16 (build_vector f16:$src0, f16:$src1)),
1770 (v2f16 (S_PACK_LL_B32_B16 $src0, $src1))
1773 } // End SubtargetPredicate = HasVOP3PInsts
1777 (v2f16 (scalar_to_vector f16:$src0)),
1782 (v2i16 (scalar_to_vector i16:$src0)),
1787 (v4i16 (scalar_to_vector i16:$src0)),
1788 (INSERT_SUBREG (IMPLICIT_DEF), $src0, sub0)
1792 (v4f16 (scalar_to_vector f16:$src0)),
1793 (INSERT_SUBREG (IMPLICIT_DEF), $src0, sub0)
1796 //===----------------------------------------------------------------------===//
1798 //===----------------------------------------------------------------------===//
1800 let SubtargetPredicate = isGFX6 in {
1802 // V_FRACT is buggy on SI, so the F32 version is never used and (x-floor(x)) is
1803 // used instead. However, SI doesn't have V_FLOOR_F64, so the most efficient
1804 // way to implement it is using V_FRACT_F64.
1805 // The workaround for the V_FRACT bug is:
1806 // fract(x) = isnan(x) ? x : min(V_FRACT(x), 0.99999999999999999)
1808 // Convert floor(x) to (x - fract(x))
1810 (f64 (ffloor (f64 (VOP3Mods f64:$x, i32:$mods)))),
1815 (V_CNDMASK_B64_PSEUDO
1818 (V_FRACT_F64_e64 $mods, $x, DSTCLAMP.NONE, DSTOMOD.NONE),
1820 (V_MOV_B64_PSEUDO 0x3fefffffffffffff),
1821 DSTCLAMP.NONE, DSTOMOD.NONE),
1823 (V_CMP_CLASS_F64_e64 SRCMODS.NONE, $x, (i32 3 /*NaN*/))),
1824 DSTCLAMP.NONE, DSTOMOD.NONE)
1827 } // End SubtargetPredicates = isGFX6
1829 //============================================================================//
1830 // Miscellaneous Optimization Patterns
1831 //============================================================================//
1833 // Undo sub x, c -> add x, -c canonicalization since c is more likely
1834 // an inline immediate than -c.
1835 // TODO: Also do for 64-bit.
1837 (add i32:$src0, (i32 NegSubInlineConst32:$src1)),
1838 (S_SUB_I32 $src0, NegSubInlineConst32:$src1)
1841 // Avoid pointlessly materializing a constant in VGPR.
1842 // FIXME: Should also do this for readlane, but tablegen crashes on
1843 // the ignored src1.
1845 (int_amdgcn_readfirstlane (i32 imm:$src)),
1849 multiclass BFMPatterns <ValueType vt, InstSI BFM, InstSI MOV> {
1851 (vt (shl (vt (add (vt (shl 1, vt:$a)), -1)), vt:$b)),
1856 (vt (add (vt (shl 1, vt:$a)), -1)),
1857 (BFM $a, (MOV (i32 0)))
1861 defm : BFMPatterns <i32, S_BFM_B32, S_MOV_B32>;
1862 // FIXME: defm : BFMPatterns <i64, S_BFM_B64, S_MOV_B64>;
1864 defm : BFEPattern <V_BFE_U32, V_BFE_I32, S_MOV_B32>;
1865 defm : SHA256MaPattern <V_BFI_B32, V_XOR_B32_e64, SReg_64>;
1867 defm : IntMed3Pat<V_MED3_I32, smin, smax, smin_oneuse, smax_oneuse>;
1868 defm : IntMed3Pat<V_MED3_U32, umin, umax, umin_oneuse, umax_oneuse>;
1870 // This matches 16 permutations of
1871 // max(min(x, y), min(max(x, y), z))
1872 class FPMed3Pat<ValueType vt,
1873 //SDPatternOperator max, SDPatternOperator min,
1874 Instruction med3Inst> : GCNPat<
1875 (fmaxnum_like (fminnum_like_oneuse (VOP3Mods_nnan vt:$src0, i32:$src0_mods),
1876 (VOP3Mods_nnan vt:$src1, i32:$src1_mods)),
1877 (fminnum_like_oneuse (fmaxnum_like_oneuse (VOP3Mods_nnan vt:$src0, i32:$src0_mods),
1878 (VOP3Mods_nnan vt:$src1, i32:$src1_mods)),
1879 (vt (VOP3Mods_nnan vt:$src2, i32:$src2_mods)))),
1880 (med3Inst $src0_mods, $src0, $src1_mods, $src1, $src2_mods, $src2, DSTCLAMP.NONE, DSTOMOD.NONE)
1883 class FP16Med3Pat<ValueType vt,
1884 Instruction med3Inst> : GCNPat<
1885 (fmaxnum_like (fminnum_like_oneuse (VOP3Mods_nnan vt:$src0, i32:$src0_mods),
1886 (VOP3Mods_nnan vt:$src1, i32:$src1_mods)),
1887 (fminnum_like_oneuse (fmaxnum_like_oneuse (VOP3Mods_nnan vt:$src0, i32:$src0_mods),
1888 (VOP3Mods_nnan vt:$src1, i32:$src1_mods)),
1889 (vt (VOP3Mods_nnan vt:$src2, i32:$src2_mods)))),
1890 (med3Inst $src0_mods, $src0, $src1_mods, $src1, $src2_mods, $src2, DSTCLAMP.NONE)
1893 multiclass Int16Med3Pat<Instruction med3Inst,
1894 SDPatternOperator min,
1895 SDPatternOperator max,
1896 SDPatternOperator max_oneuse,
1897 SDPatternOperator min_oneuse,
1898 ValueType vt = i16> {
1899 // This matches 16 permutations of
1900 // max(min(x, y), min(max(x, y), z))
1902 (max (min_oneuse vt:$src0, vt:$src1),
1903 (min_oneuse (max_oneuse vt:$src0, vt:$src1), vt:$src2)),
1904 (med3Inst SRCMODS.NONE, $src0, SRCMODS.NONE, $src1, SRCMODS.NONE, $src2, DSTCLAMP.NONE)
1907 // This matches 16 permutations of
1908 // min(max(a, b), max(min(a, b), c))
1910 (min (max_oneuse vt:$src0, vt:$src1),
1911 (max_oneuse (min_oneuse vt:$src0, vt:$src1), vt:$src2)),
1912 (med3Inst SRCMODS.NONE, $src0, SRCMODS.NONE, $src1, SRCMODS.NONE, $src2, DSTCLAMP.NONE)
1916 def : FPMed3Pat<f32, V_MED3_F32>;
1918 let OtherPredicates = [isGFX9Plus] in {
1919 def : FP16Med3Pat<f16, V_MED3_F16>;
1920 defm : Int16Med3Pat<V_MED3_I16, smin, smax, smax_oneuse, smin_oneuse>;
1921 defm : Int16Med3Pat<V_MED3_U16, umin, umax, umax_oneuse, umin_oneuse>;
1922 } // End Predicates = [isGFX9Plus]