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_XOR_B64_term : WrapTerminatorInst<S_XOR_B64>;
197 def S_ANDN2_B64_term : WrapTerminatorInst<S_ANDN2_B64>;
200 let WaveSizePredicate = isWave32 in {
201 def S_MOV_B32_term : WrapTerminatorInst<S_MOV_B32>;
202 def S_XOR_B32_term : WrapTerminatorInst<S_XOR_B32>;
203 def S_OR_B32_term : WrapTerminatorInst<S_OR_B32>;
204 def S_ANDN2_B32_term : WrapTerminatorInst<S_ANDN2_B32>;
207 def WAVE_BARRIER : SPseudoInstSI<(outs), (ins),
208 [(int_amdgcn_wave_barrier)]> {
210 let hasNoSchedulingInfo = 1;
211 let hasSideEffects = 1;
214 let isConvergent = 1;
219 // SI pseudo instructions. These are used by the CFG structurizer pass
220 // and should be lowered to ISA instructions prior to codegen.
222 // Dummy terminator instruction to use after control flow instructions
223 // replaced with exec mask operations.
224 def SI_MASK_BRANCH : VPseudoInstSI <
225 (outs), (ins brtarget:$target)> {
227 let isTerminator = 1;
230 let hasNoSchedulingInfo = 1;
235 let isTerminator = 1 in {
237 let OtherPredicates = [EnableLateCFGStructurize] in {
238 def SI_NON_UNIFORM_BRCOND_PSEUDO : CFPseudoInstSI <
240 (ins SReg_1:$vcc, brtarget:$target),
241 [(brcond i1:$vcc, bb:$target)]> {
246 def SI_IF: CFPseudoInstSI <
247 (outs SReg_1:$dst), (ins SReg_1:$vcc, brtarget:$target),
248 [(set i1:$dst, (AMDGPUif i1:$vcc, bb:$target))], 1, 1> {
249 let Constraints = "";
251 let hasSideEffects = 1;
254 def SI_ELSE : CFPseudoInstSI <
256 (ins SReg_1:$src, brtarget:$target, i1imm:$execfix), [], 1, 1> {
258 let hasSideEffects = 1;
261 def SI_LOOP : CFPseudoInstSI <
262 (outs), (ins SReg_1:$saved, brtarget:$target),
263 [(AMDGPUloop i1:$saved, bb:$target)], 1, 1> {
266 let hasSideEffects = 1;
269 } // End isTerminator = 1
271 def SI_END_CF : CFPseudoInstSI <
272 (outs), (ins SReg_1:$saved), [], 1, 1> {
274 let isAsCheapAsAMove = 1;
275 let isReMaterializable = 1;
276 let hasSideEffects = 1;
277 let mayLoad = 1; // FIXME: Should not need memory flags
281 def SI_IF_BREAK : CFPseudoInstSI <
282 (outs SReg_1:$dst), (ins SReg_1:$vcc, SReg_1:$src), []> {
284 let isAsCheapAsAMove = 1;
285 let isReMaterializable = 1;
288 let Uses = [EXEC] in {
290 multiclass PseudoInstKill <dag ins> {
291 // Even though this pseudo can usually be expanded without an SCC def, we
292 // conservatively assume that it has an SCC def, both because it is sometimes
293 // required in degenerate cases (when V_CMPX cannot be used due to constant
294 // bus limitations) and because it allows us to avoid having to track SCC
295 // liveness across basic blocks.
296 let Defs = [EXEC,VCC,SCC] in
297 def _PSEUDO : PseudoInstSI <(outs), ins> {
298 let isConvergent = 1;
299 let usesCustomInserter = 1;
302 let Defs = [EXEC,VCC,SCC] in
303 def _TERMINATOR : SPseudoInstSI <(outs), ins> {
304 let isTerminator = 1;
308 defm SI_KILL_I1 : PseudoInstKill <(ins SCSrc_i1:$src, i1imm:$killvalue)>;
309 defm SI_KILL_F32_COND_IMM : PseudoInstKill <(ins VSrc_b32:$src0, i32imm:$src1, i32imm:$cond)>;
311 let Defs = [EXEC,VCC] in
312 def SI_ILLEGAL_COPY : SPseudoInstSI <
313 (outs unknown:$dst), (ins unknown:$src),
314 [], " ; illegal copy $src to $dst">;
316 } // End Uses = [EXEC], Defs = [EXEC,VCC]
318 // Branch on undef scc. Used to avoid intermediate copy from
319 // IMPLICIT_DEF to SCC.
320 def SI_BR_UNDEF : SPseudoInstSI <(outs), (ins sopp_brtarget:$simm16)> {
321 let isTerminator = 1;
322 let usesCustomInserter = 1;
326 def SI_PS_LIVE : PseudoInstSI <
327 (outs SReg_1:$dst), (ins),
328 [(set i1:$dst, (int_amdgcn_ps_live))]> {
332 def SI_MASKED_UNREACHABLE : SPseudoInstSI <(outs), (ins),
333 [(int_amdgcn_unreachable)],
334 "; divergent unreachable"> {
336 let hasNoSchedulingInfo = 1;
340 // Used as an isel pseudo to directly emit initialization with an
341 // s_mov_b32 rather than a copy of another initialized
342 // register. MachineCSE skips copies, and we don't want to have to
343 // fold operands before it runs.
344 def SI_INIT_M0 : SPseudoInstSI <(outs), (ins SSrc_b32:$src)> {
346 let usesCustomInserter = 1;
347 let isAsCheapAsAMove = 1;
348 let isReMaterializable = 1;
351 def SI_INIT_EXEC : SPseudoInstSI <
352 (outs), (ins i64imm:$src), []> {
354 let usesCustomInserter = 1;
355 let isAsCheapAsAMove = 1;
356 let WaveSizePredicate = isWave64;
359 def SI_INIT_EXEC_LO : SPseudoInstSI <
360 (outs), (ins i32imm:$src), []> {
361 let Defs = [EXEC_LO];
362 let usesCustomInserter = 1;
363 let isAsCheapAsAMove = 1;
364 let WaveSizePredicate = isWave32;
367 def SI_INIT_EXEC_FROM_INPUT : SPseudoInstSI <
368 (outs), (ins SSrc_b32:$input, i32imm:$shift), []> {
370 let usesCustomInserter = 1;
373 // Return for returning shaders to a shader variant epilog.
374 def SI_RETURN_TO_EPILOG : SPseudoInstSI <
375 (outs), (ins variable_ops), [(AMDGPUreturn_to_epilog)]> {
376 let isTerminator = 1;
379 let hasNoSchedulingInfo = 1;
384 // Return for returning function calls.
385 def SI_RETURN : SPseudoInstSI <
388 let isTerminator = 1;
391 let SchedRW = [WriteBranch];
394 // Return for returning function calls without output register.
396 // This version is only needed so we can fill in the output regiter in
397 // the custom inserter.
398 def SI_CALL_ISEL : SPseudoInstSI <
399 (outs), (ins SSrc_b64:$src0, unknown:$callee),
400 [(AMDGPUcall i64:$src0, tglobaladdr:$callee)]> {
403 let SchedRW = [WriteBranch];
404 let usesCustomInserter = 1;
405 // TODO: Should really base this on the call target
406 let isConvergent = 1;
409 // Wrapper around s_swappc_b64 with extra $callee parameter to track
410 // the called function after regalloc.
411 def SI_CALL : SPseudoInstSI <
412 (outs SReg_64:$dst), (ins SSrc_b64:$src0, unknown:$callee)> {
415 let UseNamedOperandTable = 1;
416 let SchedRW = [WriteBranch];
417 // TODO: Should really base this on the call target
418 let isConvergent = 1;
421 // Tail call handling pseudo
422 def SI_TCRETURN : SPseudoInstSI <(outs),
423 (ins SSrc_b64:$src0, unknown:$callee, i32imm:$fpdiff),
424 [(AMDGPUtc_return i64:$src0, tglobaladdr:$callee, i32:$fpdiff)]> {
427 let isTerminator = 1;
430 let UseNamedOperandTable = 1;
431 let SchedRW = [WriteBranch];
432 // TODO: Should really base this on the call target
433 let isConvergent = 1;
437 def ADJCALLSTACKUP : SPseudoInstSI<
438 (outs), (ins i32imm:$amt0, i32imm:$amt1),
439 [(callseq_start timm:$amt0, timm:$amt1)],
440 "; adjcallstackup $amt0 $amt1"> {
441 let Size = 8; // Worst case. (s_add_u32 + constant)
443 let hasSideEffects = 1;
444 let usesCustomInserter = 1;
445 let SchedRW = [WriteSALU];
449 def ADJCALLSTACKDOWN : SPseudoInstSI<
450 (outs), (ins i32imm:$amt1, i32imm:$amt2),
451 [(callseq_end timm:$amt1, timm:$amt2)],
452 "; adjcallstackdown $amt1"> {
453 let Size = 8; // Worst case. (s_add_u32 + constant)
454 let hasSideEffects = 1;
455 let usesCustomInserter = 1;
456 let SchedRW = [WriteSALU];
460 let Defs = [M0, EXEC, SCC],
461 UseNamedOperandTable = 1 in {
463 class SI_INDIRECT_SRC<RegisterClass rc> : VPseudoInstSI <
464 (outs VGPR_32:$vdst),
465 (ins rc:$src, VS_32:$idx, i32imm:$offset)> {
466 let usesCustomInserter = 1;
469 class SI_INDIRECT_DST<RegisterClass rc> : VPseudoInstSI <
471 (ins rc:$src, VS_32:$idx, i32imm:$offset, VGPR_32:$val)> {
472 let Constraints = "$src = $vdst";
473 let usesCustomInserter = 1;
476 // TODO: We can support indirect SGPR access.
477 def SI_INDIRECT_SRC_V1 : SI_INDIRECT_SRC<VGPR_32>;
478 def SI_INDIRECT_SRC_V2 : SI_INDIRECT_SRC<VReg_64>;
479 def SI_INDIRECT_SRC_V4 : SI_INDIRECT_SRC<VReg_128>;
480 def SI_INDIRECT_SRC_V8 : SI_INDIRECT_SRC<VReg_256>;
481 def SI_INDIRECT_SRC_V16 : SI_INDIRECT_SRC<VReg_512>;
483 def SI_INDIRECT_DST_V1 : SI_INDIRECT_DST<VGPR_32>;
484 def SI_INDIRECT_DST_V2 : SI_INDIRECT_DST<VReg_64>;
485 def SI_INDIRECT_DST_V4 : SI_INDIRECT_DST<VReg_128>;
486 def SI_INDIRECT_DST_V8 : SI_INDIRECT_DST<VReg_256>;
487 def SI_INDIRECT_DST_V16 : SI_INDIRECT_DST<VReg_512>;
489 } // End Uses = [EXEC], Defs = [M0, EXEC]
491 multiclass SI_SPILL_SGPR <RegisterClass sgpr_class> {
492 let UseNamedOperandTable = 1, SGPRSpill = 1, Uses = [EXEC] in {
493 def _SAVE : PseudoInstSI <
495 (ins sgpr_class:$data, i32imm:$addr)> {
500 def _RESTORE : PseudoInstSI <
501 (outs sgpr_class:$data),
502 (ins i32imm:$addr)> {
506 } // End UseNamedOperandTable = 1
509 // You cannot use M0 as the output of v_readlane_b32 instructions or
510 // use it in the sdata operand of SMEM instructions. We still need to
511 // be able to spill the physical register m0, so allow it for
512 // SI_SPILL_32_* instructions.
513 defm SI_SPILL_S32 : SI_SPILL_SGPR <SReg_32>;
514 defm SI_SPILL_S64 : SI_SPILL_SGPR <SReg_64>;
515 defm SI_SPILL_S96 : SI_SPILL_SGPR <SReg_96>;
516 defm SI_SPILL_S128 : SI_SPILL_SGPR <SReg_128>;
517 defm SI_SPILL_S160 : SI_SPILL_SGPR <SReg_160>;
518 defm SI_SPILL_S256 : SI_SPILL_SGPR <SReg_256>;
519 defm SI_SPILL_S512 : SI_SPILL_SGPR <SReg_512>;
520 defm SI_SPILL_S1024 : SI_SPILL_SGPR <SReg_1024>;
522 multiclass SI_SPILL_VGPR <RegisterClass vgpr_class> {
523 let UseNamedOperandTable = 1, VGPRSpill = 1,
524 SchedRW = [WriteVMEM] in {
525 def _SAVE : VPseudoInstSI <
527 (ins vgpr_class:$vdata, i32imm:$vaddr, SReg_128:$srsrc,
528 SReg_32:$soffset, i32imm:$offset)> {
531 // (2 * 4) + (8 * num_subregs) bytes maximum
532 int MaxSize = !add(!shl(!srl(vgpr_class.Size, 5), 3), 8);
533 // Size field is unsigned char and cannot fit more.
534 let Size = !if(!le(MaxSize, 256), MaxSize, 252);
537 def _RESTORE : VPseudoInstSI <
538 (outs vgpr_class:$vdata),
539 (ins i32imm:$vaddr, SReg_128:$srsrc, SReg_32:$soffset,
544 // (2 * 4) + (8 * num_subregs) bytes maximum
545 int MaxSize = !add(!shl(!srl(vgpr_class.Size, 5), 3), 8);
546 // Size field is unsigned char and cannot fit more.
547 let Size = !if(!le(MaxSize, 256), MaxSize, 252);
549 } // End UseNamedOperandTable = 1, VGPRSpill = 1, SchedRW = [WriteVMEM]
552 defm SI_SPILL_V32 : SI_SPILL_VGPR <VGPR_32>;
553 defm SI_SPILL_V64 : SI_SPILL_VGPR <VReg_64>;
554 defm SI_SPILL_V96 : SI_SPILL_VGPR <VReg_96>;
555 defm SI_SPILL_V128 : SI_SPILL_VGPR <VReg_128>;
556 defm SI_SPILL_V160 : SI_SPILL_VGPR <VReg_160>;
557 defm SI_SPILL_V256 : SI_SPILL_VGPR <VReg_256>;
558 defm SI_SPILL_V512 : SI_SPILL_VGPR <VReg_512>;
559 defm SI_SPILL_V1024 : SI_SPILL_VGPR <VReg_1024>;
561 multiclass SI_SPILL_AGPR <RegisterClass vgpr_class> {
562 let UseNamedOperandTable = 1, VGPRSpill = 1,
563 Constraints = "@earlyclobber $tmp",
564 SchedRW = [WriteVMEM] in {
565 def _SAVE : VPseudoInstSI <
567 (ins vgpr_class:$vdata, i32imm:$vaddr, SReg_128:$srsrc,
568 SReg_32:$soffset, i32imm:$offset)> {
571 // (2 * 4) + (16 * num_subregs) bytes maximum
572 int MaxSize = !add(!shl(!srl(vgpr_class.Size, 5), 4), 8);
573 // Size field is unsigned char and cannot fit more.
574 let Size = !if(!le(MaxSize, 256), MaxSize, 252);
577 def _RESTORE : VPseudoInstSI <
578 (outs vgpr_class:$vdata, VGPR_32:$tmp),
579 (ins i32imm:$vaddr, SReg_128:$srsrc, SReg_32:$soffset,
584 // (2 * 4) + (16 * num_subregs) bytes maximum
585 int MaxSize = !add(!shl(!srl(vgpr_class.Size, 5), 4), 8);
586 // Size field is unsigned char and cannot fit more.
587 let Size = !if(!le(MaxSize, 256), MaxSize, 252);
589 } // End UseNamedOperandTable = 1, VGPRSpill = 1, SchedRW = [WriteVMEM]
592 defm SI_SPILL_A32 : SI_SPILL_AGPR <AGPR_32>;
593 defm SI_SPILL_A64 : SI_SPILL_AGPR <AReg_64>;
594 defm SI_SPILL_A128 : SI_SPILL_AGPR <AReg_128>;
595 defm SI_SPILL_A512 : SI_SPILL_AGPR <AReg_512>;
596 defm SI_SPILL_A1024 : SI_SPILL_AGPR <AReg_1024>;
598 def SI_PC_ADD_REL_OFFSET : SPseudoInstSI <
600 (ins si_ga:$ptr_lo, si_ga:$ptr_hi),
602 (i64 (SIpc_add_rel_offset tglobaladdr:$ptr_lo, tglobaladdr:$ptr_hi)))]> {
607 (SIpc_add_rel_offset tglobaladdr:$ptr_lo, 0),
608 (SI_PC_ADD_REL_OFFSET $ptr_lo, (i32 0))
612 (AMDGPUinit_exec i64:$src),
613 (SI_INIT_EXEC (as_i64imm $src))
615 let WaveSizePredicate = isWave64;
619 (AMDGPUinit_exec i64:$src),
620 (SI_INIT_EXEC_LO (as_i32imm $src))
622 let WaveSizePredicate = isWave32;
626 (AMDGPUinit_exec_from_input i32:$input, i32:$shift),
627 (SI_INIT_EXEC_FROM_INPUT (i32 $input), (as_i32imm $shift))
631 (AMDGPUtrap timm:$trapid),
636 (AMDGPUelse i1:$src, bb:$target),
637 (SI_ELSE $src, $target, 0)
641 // -1.0 as i32 (LowerINTRINSIC_VOID converts all other constants to -1.0)
642 (AMDGPUkill (i32 -1082130432)),
643 (SI_KILL_I1_PSEUDO (i1 0), 0)
647 (int_amdgcn_kill i1:$src),
648 (SI_KILL_I1_PSEUDO $src, 0)
652 (int_amdgcn_kill (i1 (not i1:$src))),
653 (SI_KILL_I1_PSEUDO $src, -1)
657 (AMDGPUkill i32:$src),
658 (SI_KILL_F32_COND_IMM_PSEUDO $src, 0, 3) // 3 means SETOGE
662 (int_amdgcn_kill (i1 (setcc f32:$src, InlineFPImm<f32>:$imm, cond:$cond))),
663 (SI_KILL_F32_COND_IMM_PSEUDO $src, (bitcast_fpimm_to_i32 $imm), (cond_as_i32imm $cond))
666 // TODO: we could add more variants for other types of conditionals
669 (i64 (int_amdgcn_icmp i1:$src, (i1 0), (i32 33))),
670 (COPY $src) // Return the SGPRs representing i1 src
674 (i32 (int_amdgcn_icmp i1:$src, (i1 0), (i32 33))),
675 (COPY $src) // Return the SGPRs representing i1 src
678 //===----------------------------------------------------------------------===//
680 //===----------------------------------------------------------------------===//
682 let OtherPredicates = [UnsafeFPMath] in {
684 //def : RcpPat<V_RCP_F64_e32, f64>;
685 //defm : RsqPat<V_RSQ_F64_e32, f64>;
686 //defm : RsqPat<V_RSQ_F32_e32, f32>;
688 def : RsqPat<V_RSQ_F32_e32, f32>;
689 def : RsqPat<V_RSQ_F64_e32, f64>;
691 // Convert (x - floor(x)) to fract(x)
693 (f32 (fsub (f32 (VOP3Mods f32:$x, i32:$mods)),
694 (f32 (ffloor (f32 (VOP3Mods f32:$x, i32:$mods)))))),
695 (V_FRACT_F32_e64 $mods, $x, DSTCLAMP.NONE, DSTOMOD.NONE)
698 // Convert (x + (-floor(x))) to fract(x)
700 (f64 (fadd (f64 (VOP3Mods f64:$x, i32:$mods)),
701 (f64 (fneg (f64 (ffloor (f64 (VOP3Mods f64:$x, i32:$mods)))))))),
702 (V_FRACT_F64_e64 $mods, $x, DSTCLAMP.NONE, DSTOMOD.NONE)
705 } // End OtherPredicates = [UnsafeFPMath]
708 // f16_to_fp patterns
710 (f32 (f16_to_fp i32:$src0)),
711 (V_CVT_F32_F16_e64 SRCMODS.NONE, $src0, DSTCLAMP.NONE, DSTOMOD.NONE)
715 (f32 (f16_to_fp (and_oneuse i32:$src0, 0x7fff))),
716 (V_CVT_F32_F16_e64 SRCMODS.ABS, $src0, DSTCLAMP.NONE, DSTOMOD.NONE)
720 (f32 (f16_to_fp (i32 (srl_oneuse (and_oneuse i32:$src0, 0x7fff0000), (i32 16))))),
721 (V_CVT_F32_F16_e64 SRCMODS.ABS, (i32 (V_LSHRREV_B32_e64 (i32 16), i32:$src0)), DSTCLAMP.NONE, DSTOMOD.NONE)
725 (f32 (f16_to_fp (or_oneuse i32:$src0, 0x8000))),
726 (V_CVT_F32_F16_e64 SRCMODS.NEG_ABS, $src0, DSTCLAMP.NONE, DSTOMOD.NONE)
730 (f32 (f16_to_fp (xor_oneuse i32:$src0, 0x8000))),
731 (V_CVT_F32_F16_e64 SRCMODS.NEG, $src0, DSTCLAMP.NONE, DSTOMOD.NONE)
735 (f64 (fpextend f16:$src)),
736 (V_CVT_F64_F32_e32 (V_CVT_F32_F16_e32 $src))
739 // fp_to_fp16 patterns
741 (i32 (AMDGPUfp_to_f16 (f32 (VOP3Mods f32:$src0, i32:$src0_modifiers)))),
742 (V_CVT_F16_F32_e64 $src0_modifiers, f32:$src0, DSTCLAMP.NONE, DSTOMOD.NONE)
746 (i32 (fp_to_sint f16:$src)),
747 (V_CVT_I32_F32_e32 (V_CVT_F32_F16_e32 $src))
751 (i32 (fp_to_uint f16:$src)),
752 (V_CVT_U32_F32_e32 (V_CVT_F32_F16_e32 $src))
756 (f16 (sint_to_fp i32:$src)),
757 (V_CVT_F16_F32_e32 (V_CVT_F32_I32_e32 $src))
761 (f16 (uint_to_fp i32:$src)),
762 (V_CVT_F16_F32_e32 (V_CVT_F32_U32_e32 $src))
765 //===----------------------------------------------------------------------===//
767 //===----------------------------------------------------------------------===//
769 multiclass FMADPat <ValueType vt, Instruction inst> {
771 (vt (fmad (VOP3NoMods vt:$src0),
772 (VOP3NoMods vt:$src1),
773 (VOP3NoMods vt:$src2))),
774 (inst SRCMODS.NONE, $src0, SRCMODS.NONE, $src1,
775 SRCMODS.NONE, $src2, DSTCLAMP.NONE, DSTOMOD.NONE)
779 defm : FMADPat <f16, V_MAC_F16_e64>;
780 defm : FMADPat <f32, V_MAC_F32_e64>;
782 class FMADModsPat<Instruction inst, SDPatternOperator mad_opr, ValueType Ty>
784 (Ty (mad_opr (VOP3Mods Ty:$src0, i32:$src0_mod),
785 (VOP3Mods Ty:$src1, i32:$src1_mod),
786 (VOP3Mods Ty:$src2, i32:$src2_mod))),
787 (inst $src0_mod, $src0, $src1_mod, $src1,
788 $src2_mod, $src2, DSTCLAMP.NONE, DSTOMOD.NONE)
791 def : FMADModsPat<V_MAD_F32, AMDGPUfmad_ftz, f32>;
792 def : FMADModsPat<V_MAD_F16, AMDGPUfmad_ftz, f16> {
793 let SubtargetPredicate = Has16BitInsts;
796 multiclass SelectPat <ValueType vt> {
798 (vt (select i1:$src0, (VOP3Mods_f32 vt:$src1, i32:$src1_mods),
799 (VOP3Mods_f32 vt:$src2, i32:$src2_mods))),
800 (V_CNDMASK_B32_e64 $src2_mods, $src2, $src1_mods, $src1, $src0)
804 defm : SelectPat <i16>;
805 defm : SelectPat <i32>;
806 defm : SelectPat <f16>;
807 defm : SelectPat <f32>;
809 let AddedComplexity = 1 in {
811 (i32 (add (i32 (getDivergentFrag<ctpop>.ret i32:$popcnt)), i32:$val)),
812 (V_BCNT_U32_B32_e64 $popcnt, $val)
816 (i16 (add (i16 (trunc (getDivergentFrag<ctpop>.ret i32:$popcnt))), i16:$val)),
817 (V_BCNT_U32_B32_e64 $popcnt, $val)
820 /********** ============================================ **********/
821 /********** Extraction, Insertion, Building and Casting **********/
822 /********** ============================================ **********/
824 foreach Index = 0-2 in {
825 def Extract_Element_v2i32_#Index : Extract_Element <
826 i32, v2i32, Index, !cast<SubRegIndex>(sub#Index)
828 def Insert_Element_v2i32_#Index : Insert_Element <
829 i32, v2i32, Index, !cast<SubRegIndex>(sub#Index)
832 def Extract_Element_v2f32_#Index : Extract_Element <
833 f32, v2f32, Index, !cast<SubRegIndex>(sub#Index)
835 def Insert_Element_v2f32_#Index : Insert_Element <
836 f32, v2f32, Index, !cast<SubRegIndex>(sub#Index)
840 foreach Index = 0-2 in {
841 def Extract_Element_v3i32_#Index : Extract_Element <
842 i32, v3i32, Index, !cast<SubRegIndex>(sub#Index)
844 def Insert_Element_v3i32_#Index : Insert_Element <
845 i32, v3i32, Index, !cast<SubRegIndex>(sub#Index)
848 def Extract_Element_v3f32_#Index : Extract_Element <
849 f32, v3f32, Index, !cast<SubRegIndex>(sub#Index)
851 def Insert_Element_v3f32_#Index : Insert_Element <
852 f32, v3f32, Index, !cast<SubRegIndex>(sub#Index)
856 foreach Index = 0-3 in {
857 def Extract_Element_v4i32_#Index : Extract_Element <
858 i32, v4i32, Index, !cast<SubRegIndex>(sub#Index)
860 def Insert_Element_v4i32_#Index : Insert_Element <
861 i32, v4i32, Index, !cast<SubRegIndex>(sub#Index)
864 def Extract_Element_v4f32_#Index : Extract_Element <
865 f32, v4f32, Index, !cast<SubRegIndex>(sub#Index)
867 def Insert_Element_v4f32_#Index : Insert_Element <
868 f32, v4f32, Index, !cast<SubRegIndex>(sub#Index)
872 foreach Index = 0-4 in {
873 def Extract_Element_v5i32_#Index : Extract_Element <
874 i32, v5i32, Index, !cast<SubRegIndex>(sub#Index)
876 def Insert_Element_v5i32_#Index : Insert_Element <
877 i32, v5i32, Index, !cast<SubRegIndex>(sub#Index)
880 def Extract_Element_v5f32_#Index : Extract_Element <
881 f32, v5f32, Index, !cast<SubRegIndex>(sub#Index)
883 def Insert_Element_v5f32_#Index : Insert_Element <
884 f32, v5f32, Index, !cast<SubRegIndex>(sub#Index)
888 foreach Index = 0-7 in {
889 def Extract_Element_v8i32_#Index : Extract_Element <
890 i32, v8i32, Index, !cast<SubRegIndex>(sub#Index)
892 def Insert_Element_v8i32_#Index : Insert_Element <
893 i32, v8i32, Index, !cast<SubRegIndex>(sub#Index)
896 def Extract_Element_v8f32_#Index : Extract_Element <
897 f32, v8f32, Index, !cast<SubRegIndex>(sub#Index)
899 def Insert_Element_v8f32_#Index : Insert_Element <
900 f32, v8f32, Index, !cast<SubRegIndex>(sub#Index)
904 foreach Index = 0-15 in {
905 def Extract_Element_v16i32_#Index : Extract_Element <
906 i32, v16i32, Index, !cast<SubRegIndex>(sub#Index)
908 def Insert_Element_v16i32_#Index : Insert_Element <
909 i32, v16i32, Index, !cast<SubRegIndex>(sub#Index)
912 def Extract_Element_v16f32_#Index : Extract_Element <
913 f32, v16f32, Index, !cast<SubRegIndex>(sub#Index)
915 def Insert_Element_v16f32_#Index : Insert_Element <
916 f32, v16f32, Index, !cast<SubRegIndex>(sub#Index)
922 (extract_subvector v4i16:$vec, (i32 0)),
923 (v2i16 (EXTRACT_SUBREG v4i16:$vec, sub0))
927 (extract_subvector v4i16:$vec, (i32 2)),
928 (v2i16 (EXTRACT_SUBREG v4i16:$vec, sub1))
932 (extract_subvector v4f16:$vec, (i32 0)),
933 (v2f16 (EXTRACT_SUBREG v4f16:$vec, sub0))
937 (extract_subvector v4f16:$vec, (i32 2)),
938 (v2f16 (EXTRACT_SUBREG v4f16:$vec, sub1))
941 foreach Index = 0-31 in {
942 def Extract_Element_v32i32_#Index : Extract_Element <
943 i32, v32i32, Index, !cast<SubRegIndex>(sub#Index)
946 def Insert_Element_v32i32_#Index : Insert_Element <
947 i32, v32i32, Index, !cast<SubRegIndex>(sub#Index)
950 def Extract_Element_v32f32_#Index : Extract_Element <
951 f32, v32f32, Index, !cast<SubRegIndex>(sub#Index)
954 def Insert_Element_v32f32_#Index : Insert_Element <
955 f32, v32f32, Index, !cast<SubRegIndex>(sub#Index)
959 // FIXME: Why do only some of these type combinations for SReg and
962 def : BitConvert <i16, f16, VGPR_32>;
963 def : BitConvert <f16, i16, VGPR_32>;
964 def : BitConvert <i16, f16, SReg_32>;
965 def : BitConvert <f16, i16, SReg_32>;
968 def : BitConvert <i32, f32, VGPR_32>;
969 def : BitConvert <f32, i32, VGPR_32>;
970 def : BitConvert <i32, f32, SReg_32>;
971 def : BitConvert <f32, i32, SReg_32>;
972 def : BitConvert <v2i16, i32, SReg_32>;
973 def : BitConvert <i32, v2i16, SReg_32>;
974 def : BitConvert <v2f16, i32, SReg_32>;
975 def : BitConvert <i32, v2f16, SReg_32>;
976 def : BitConvert <v2i16, v2f16, SReg_32>;
977 def : BitConvert <v2f16, v2i16, SReg_32>;
978 def : BitConvert <v2f16, f32, SReg_32>;
979 def : BitConvert <f32, v2f16, SReg_32>;
980 def : BitConvert <v2i16, f32, SReg_32>;
981 def : BitConvert <f32, v2i16, SReg_32>;
984 def : BitConvert <i64, f64, VReg_64>;
985 def : BitConvert <f64, i64, VReg_64>;
986 def : BitConvert <v2i32, v2f32, VReg_64>;
987 def : BitConvert <v2f32, v2i32, VReg_64>;
988 def : BitConvert <i64, v2i32, VReg_64>;
989 def : BitConvert <v2i32, i64, VReg_64>;
990 def : BitConvert <i64, v2f32, VReg_64>;
991 def : BitConvert <v2f32, i64, VReg_64>;
992 def : BitConvert <f64, v2f32, VReg_64>;
993 def : BitConvert <v2f32, f64, VReg_64>;
994 def : BitConvert <f64, v2i32, VReg_64>;
995 def : BitConvert <v2i32, f64, VReg_64>;
996 def : BitConvert <v4i16, v4f16, VReg_64>;
997 def : BitConvert <v4f16, v4i16, VReg_64>;
1000 def : BitConvert <v2i32, v4f16, VReg_64>;
1001 def : BitConvert <v4f16, v2i32, VReg_64>;
1002 def : BitConvert <v2i32, v4f16, VReg_64>;
1003 def : BitConvert <v2i32, v4i16, VReg_64>;
1004 def : BitConvert <v4i16, v2i32, VReg_64>;
1005 def : BitConvert <v2f32, v4f16, VReg_64>;
1006 def : BitConvert <v4f16, v2f32, VReg_64>;
1007 def : BitConvert <v2f32, v4i16, VReg_64>;
1008 def : BitConvert <v4i16, v2f32, VReg_64>;
1009 def : BitConvert <v4i16, f64, VReg_64>;
1010 def : BitConvert <v4f16, f64, VReg_64>;
1011 def : BitConvert <f64, v4i16, VReg_64>;
1012 def : BitConvert <f64, v4f16, VReg_64>;
1013 def : BitConvert <v4i16, i64, VReg_64>;
1014 def : BitConvert <v4f16, i64, VReg_64>;
1015 def : BitConvert <i64, v4i16, VReg_64>;
1016 def : BitConvert <i64, v4f16, VReg_64>;
1018 def : BitConvert <v4i32, v4f32, VReg_128>;
1019 def : BitConvert <v4f32, v4i32, VReg_128>;
1022 def : BitConvert <v3i32, v3f32, SGPR_96>;
1023 def : BitConvert <v3f32, v3i32, SGPR_96>;
1026 def : BitConvert <v2i64, v4i32, SReg_128>;
1027 def : BitConvert <v4i32, v2i64, SReg_128>;
1028 def : BitConvert <v2f64, v4f32, VReg_128>;
1029 def : BitConvert <v2f64, v4i32, VReg_128>;
1030 def : BitConvert <v4f32, v2f64, VReg_128>;
1031 def : BitConvert <v4i32, v2f64, VReg_128>;
1032 def : BitConvert <v2i64, v2f64, VReg_128>;
1033 def : BitConvert <v2f64, v2i64, VReg_128>;
1036 def : BitConvert <v5i32, v5f32, SGPR_160>;
1037 def : BitConvert <v5f32, v5i32, SGPR_160>;
1040 def : BitConvert <v8i32, v8f32, SReg_256>;
1041 def : BitConvert <v8f32, v8i32, SReg_256>;
1042 def : BitConvert <v8i32, v8f32, VReg_256>;
1043 def : BitConvert <v8f32, v8i32, VReg_256>;
1046 def : BitConvert <v16i32, v16f32, VReg_512>;
1047 def : BitConvert <v16f32, v16i32, VReg_512>;
1050 def : BitConvert <v32i32, v32f32, VReg_1024>;
1051 def : BitConvert <v32f32, v32i32, VReg_1024>;
1053 /********** =================== **********/
1054 /********** Src & Dst modifiers **********/
1055 /********** =================== **********/
1058 // If denormals are not enabled, it only impacts the compare of the
1059 // inputs. The output result is not flushed.
1060 class ClampPat<Instruction inst, ValueType vt> : GCNPat <
1061 (vt (AMDGPUclamp (VOP3Mods vt:$src0, i32:$src0_modifiers))),
1062 (inst i32:$src0_modifiers, vt:$src0,
1063 i32:$src0_modifiers, vt:$src0, DSTCLAMP.ENABLE, DSTOMOD.NONE)
1066 def : ClampPat<V_MAX_F32_e64, f32>;
1067 def : ClampPat<V_MAX_F64, f64>;
1068 def : ClampPat<V_MAX_F16_e64, f16>;
1070 let SubtargetPredicate = HasVOP3PInsts in {
1072 (v2f16 (AMDGPUclamp (VOP3PMods v2f16:$src0, i32:$src0_modifiers))),
1073 (V_PK_MAX_F16 $src0_modifiers, $src0,
1074 $src0_modifiers, $src0, DSTCLAMP.ENABLE)
1078 /********** ================================ **********/
1079 /********** Floating point absolute/negative **********/
1080 /********** ================================ **********/
1082 // Prevent expanding both fneg and fabs.
1085 (fneg (fabs f32:$src)),
1086 (S_OR_B32 $src, (S_MOV_B32(i32 0x80000000))) // Set sign bit
1089 // FIXME: Should use S_OR_B32
1091 (fneg (fabs f64:$src)),
1092 (REG_SEQUENCE VReg_64,
1093 (i32 (EXTRACT_SUBREG f64:$src, sub0)),
1095 (V_OR_B32_e32 (i32 (EXTRACT_SUBREG f64:$src, sub1)),
1096 (V_MOV_B32_e32 (i32 0x80000000))), // Set sign bit.
1102 (S_AND_B32 $src, (S_MOV_B32 (i32 0x7fffffff)))
1107 (V_XOR_B32_e32 $src, (V_MOV_B32_e32 (i32 0x80000000)))
1112 (REG_SEQUENCE VReg_64,
1113 (i32 (EXTRACT_SUBREG f64:$src, sub0)),
1115 (V_AND_B32_e64 (i32 (EXTRACT_SUBREG f64:$src, sub1)),
1116 (V_MOV_B32_e32 (i32 0x7fffffff))), // Set sign bit.
1122 (REG_SEQUENCE VReg_64,
1123 (i32 (EXTRACT_SUBREG f64:$src, sub0)),
1125 (V_XOR_B32_e32 (i32 (EXTRACT_SUBREG f64:$src, sub1)),
1126 (i32 (V_MOV_B32_e32 (i32 0x80000000)))),
1131 (fcopysign f16:$src0, f16:$src1),
1132 (V_BFI_B32 (S_MOV_B32 (i32 0x00007fff)), $src0, $src1)
1136 (fcopysign f32:$src0, f16:$src1),
1137 (V_BFI_B32 (S_MOV_B32 (i32 0x7fffffff)), $src0,
1138 (V_LSHLREV_B32_e64 (i32 16), $src1))
1142 (fcopysign f64:$src0, f16:$src1),
1143 (REG_SEQUENCE SReg_64,
1144 (i32 (EXTRACT_SUBREG $src0, sub0)), sub0,
1145 (V_BFI_B32 (S_MOV_B32 (i32 0x7fffffff)), (i32 (EXTRACT_SUBREG $src0, sub1)),
1146 (V_LSHLREV_B32_e64 (i32 16), $src1)), sub1)
1150 (fcopysign f16:$src0, f32:$src1),
1151 (V_BFI_B32 (S_MOV_B32 (i32 0x00007fff)), $src0,
1152 (V_LSHRREV_B32_e64 (i32 16), $src1))
1156 (fcopysign f16:$src0, f64:$src1),
1157 (V_BFI_B32 (S_MOV_B32 (i32 0x00007fff)), $src0,
1158 (V_LSHRREV_B32_e64 (i32 16), (EXTRACT_SUBREG $src1, sub1)))
1163 (S_XOR_B32 $src, (S_MOV_B32 (i32 0x00008000)))
1168 (S_AND_B32 $src, (S_MOV_B32 (i32 0x00007fff)))
1172 (fneg (fabs f16:$src)),
1173 (S_OR_B32 $src, (S_MOV_B32 (i32 0x00008000))) // Set sign bit
1178 (S_XOR_B32 $src, (S_MOV_B32 (i32 0x80008000)))
1183 (S_AND_B32 $src, (S_MOV_B32 (i32 0x7fff7fff)))
1186 // This is really (fneg (fabs v2f16:$src))
1188 // fabs is not reported as free because there is modifier for it in
1189 // VOP3P instructions, so it is turned into the bit op.
1191 (fneg (v2f16 (bitconvert (and_oneuse i32:$src, 0x7fff7fff)))),
1192 (S_OR_B32 $src, (S_MOV_B32 (i32 0x80008000))) // Set sign bit
1196 (fneg (v2f16 (fabs v2f16:$src))),
1197 (S_OR_B32 $src, (S_MOV_B32 (i32 0x80008000))) // Set sign bit
1200 /********** ================== **********/
1201 /********** Immediate Patterns **********/
1202 /********** ================== **********/
1205 (VGPRImm<(i32 imm)>:$imm),
1206 (V_MOV_B32_e32 imm:$imm)
1210 (VGPRImm<(f32 fpimm)>:$imm),
1211 (V_MOV_B32_e32 (f32 (bitcast_fpimm_to_i32 $imm)))
1216 (S_MOV_B32 imm:$imm)
1220 (VGPRImm<(SIlds tglobaladdr:$ga)>),
1225 (SIlds tglobaladdr:$ga),
1229 // FIXME: Workaround for ordering issue with peephole optimizer where
1230 // a register class copy interferes with immediate folding. Should
1231 // use s_mov_b32, which can be shrunk to s_movk_i32
1233 (VGPRImm<(f16 fpimm)>:$imm),
1234 (V_MOV_B32_e32 (f16 (bitcast_fpimm_to_i32 $imm)))
1239 (S_MOV_B32 (f32 (bitcast_fpimm_to_i32 $imm)))
1244 (S_MOV_B32 (i32 (bitcast_fpimm_to_i32 $imm)))
1248 (i32 frameindex:$fi),
1249 (V_MOV_B32_e32 (i32 (frameindex_to_targetframeindex $fi)))
1253 (i64 InlineImm<i64>:$imm),
1254 (S_MOV_B64 InlineImm<i64>:$imm)
1257 // XXX - Should this use a s_cmp to set SCC?
1259 // Set to sign-extended 64-bit value (true = -1, false = 0)
1262 (S_MOV_B64 (i64 (as_i64imm $imm)))
1264 let WaveSizePredicate = isWave64;
1269 (S_MOV_B32 (i32 (as_i32imm $imm)))
1271 let WaveSizePredicate = isWave32;
1275 (f64 InlineFPImm<f64>:$imm),
1276 (S_MOV_B64 (f64 (bitcast_fpimm_to_i64 InlineFPImm<f64>:$imm)))
1279 /********** ================== **********/
1280 /********** Intrinsic Patterns **********/
1281 /********** ================== **********/
1283 def : POW_Common <V_LOG_F32_e32, V_EXP_F32_e32, V_MUL_LEGACY_F32_e32>;
1286 (i32 (sext i1:$src0)),
1287 (V_CNDMASK_B32_e64 /*src0mod*/(i32 0), /*src0*/(i32 0),
1288 /*src1mod*/(i32 0), /*src1*/(i32 -1), $src0)
1291 class Ext32Pat <SDNode ext> : GCNPat <
1292 (i32 (ext i1:$src0)),
1293 (V_CNDMASK_B32_e64 /*src0mod*/(i32 0), /*src0*/(i32 0),
1294 /*src1mod*/(i32 0), /*src1*/(i32 1), $src0)
1297 def : Ext32Pat <zext>;
1298 def : Ext32Pat <anyext>;
1300 // The multiplication scales from [0,1] to the unsigned integer range
1302 (AMDGPUurecip i32:$src0),
1304 (V_MUL_F32_e32 (i32 CONST.FP_UINT_MAX_PLUS_1),
1305 (V_RCP_IFLAG_F32_e32 (V_CVT_F32_U32_e32 $src0))))
1308 //===----------------------------------------------------------------------===//
1310 //===----------------------------------------------------------------------===//
1312 def : IMad24Pat<V_MAD_I32_I24, 1>;
1313 def : UMad24Pat<V_MAD_U32_U24, 1>;
1315 // FIXME: This should only be done for VALU inputs
1316 defm : BFIPatterns <V_BFI_B32, S_MOV_B32, SReg_64>;
1317 def : ROTRPattern <V_ALIGNBIT_B32>;
1319 def : GCNPat<(i32 (trunc (srl i64:$src0, (and i32:$src1, (i32 31))))),
1320 (V_ALIGNBIT_B32 (i32 (EXTRACT_SUBREG (i64 $src0), sub1)),
1321 (i32 (EXTRACT_SUBREG (i64 $src0), sub0)), $src1)>;
1323 def : GCNPat<(i32 (trunc (srl i64:$src0, (i32 ShiftAmt32Imm:$src1)))),
1324 (V_ALIGNBIT_B32 (i32 (EXTRACT_SUBREG (i64 $src0), sub1)),
1325 (i32 (EXTRACT_SUBREG (i64 $src0), sub0)), $src1)>;
1327 /********** ====================== **********/
1328 /********** Indirect addressing **********/
1329 /********** ====================== **********/
1331 multiclass SI_INDIRECT_Pattern <ValueType vt, ValueType eltvt, string VecSize> {
1332 // Extract with offset
1334 (eltvt (extractelt vt:$src, (MOVRELOffset i32:$idx, (i32 imm:$offset)))),
1335 (!cast<Instruction>("SI_INDIRECT_SRC_"#VecSize) $src, $idx, imm:$offset)
1338 // Insert with offset
1340 (insertelt vt:$src, eltvt:$val, (MOVRELOffset i32:$idx, (i32 imm:$offset))),
1341 (!cast<Instruction>("SI_INDIRECT_DST_"#VecSize) $src, $idx, imm:$offset, $val)
1345 defm : SI_INDIRECT_Pattern <v2f32, f32, "V2">;
1346 defm : SI_INDIRECT_Pattern <v4f32, f32, "V4">;
1347 defm : SI_INDIRECT_Pattern <v8f32, f32, "V8">;
1348 defm : SI_INDIRECT_Pattern <v16f32, f32, "V16">;
1350 defm : SI_INDIRECT_Pattern <v2i32, i32, "V2">;
1351 defm : SI_INDIRECT_Pattern <v4i32, i32, "V4">;
1352 defm : SI_INDIRECT_Pattern <v8i32, i32, "V8">;
1353 defm : SI_INDIRECT_Pattern <v16i32, i32, "V16">;
1355 //===----------------------------------------------------------------------===//
1357 //===----------------------------------------------------------------------===//
1360 (add (sub_oneuse (umax i32:$src0, i32:$src1),
1361 (umin i32:$src0, i32:$src1)),
1363 (V_SAD_U32 $src0, $src1, $src2, (i1 0))
1367 (add (select_oneuse (i1 (setugt i32:$src0, i32:$src1)),
1368 (sub i32:$src0, i32:$src1),
1369 (sub i32:$src1, i32:$src0)),
1371 (V_SAD_U32 $src0, $src1, $src2, (i1 0))
1374 //===----------------------------------------------------------------------===//
1375 // Conversion Patterns
1376 //===----------------------------------------------------------------------===//
1378 def : GCNPat<(i32 (sext_inreg i32:$src, i1)),
1379 (S_BFE_I32 i32:$src, (i32 65536))>; // 0 | 1 << 16
1381 // Handle sext_inreg in i64
1383 (i64 (sext_inreg i64:$src, i1)),
1384 (S_BFE_I64 i64:$src, (i32 0x10000)) // 0 | 1 << 16
1388 (i16 (sext_inreg i16:$src, i1)),
1389 (S_BFE_I32 $src, (i32 0x00010000)) // 0 | 1 << 16
1393 (i16 (sext_inreg i16:$src, i8)),
1394 (S_BFE_I32 $src, (i32 0x80000)) // 0 | 8 << 16
1398 (i64 (sext_inreg i64:$src, i8)),
1399 (S_BFE_I64 i64:$src, (i32 0x80000)) // 0 | 8 << 16
1403 (i64 (sext_inreg i64:$src, i16)),
1404 (S_BFE_I64 i64:$src, (i32 0x100000)) // 0 | 16 << 16
1408 (i64 (sext_inreg i64:$src, i32)),
1409 (S_BFE_I64 i64:$src, (i32 0x200000)) // 0 | 32 << 16
1413 (i64 (zext i32:$src)),
1414 (REG_SEQUENCE SReg_64, $src, sub0, (S_MOV_B32 (i32 0)), sub1)
1418 (i64 (anyext i32:$src)),
1419 (REG_SEQUENCE SReg_64, $src, sub0, (i32 (IMPLICIT_DEF)), sub1)
1422 class ZExt_i64_i1_Pat <SDNode ext> : GCNPat <
1423 (i64 (ext i1:$src)),
1424 (REG_SEQUENCE VReg_64,
1425 (V_CNDMASK_B32_e64 /*src0mod*/(i32 0), /*src0*/(i32 0),
1426 /*src1mod*/(i32 0), /*src1*/(i32 1), $src),
1427 sub0, (S_MOV_B32 (i32 0)), sub1)
1431 def : ZExt_i64_i1_Pat<zext>;
1432 def : ZExt_i64_i1_Pat<anyext>;
1434 // FIXME: We need to use COPY_TO_REGCLASS to work-around the fact that
1435 // REG_SEQUENCE patterns don't support instructions with multiple outputs.
1437 (i64 (sext i32:$src)),
1438 (REG_SEQUENCE SReg_64, $src, sub0,
1439 (i32 (COPY_TO_REGCLASS (S_ASHR_I32 $src, (i32 31)), SReg_32_XM0)), sub1)
1443 (i64 (sext i1:$src)),
1444 (REG_SEQUENCE VReg_64,
1445 (V_CNDMASK_B32_e64 /*src0mod*/(i32 0), /*src0*/(i32 0),
1446 /*src1mod*/(i32 0), /*src1*/(i32 -1), $src), sub0,
1447 (V_CNDMASK_B32_e64 /*src0mod*/(i32 0), /*src0*/(i32 0),
1448 /*src1mod*/(i32 0), /*src1*/(i32 -1), $src), sub1)
1451 class FPToI1Pat<Instruction Inst, int KOne, ValueType kone_type, ValueType vt, SDPatternOperator fp_to_int> : GCNPat <
1452 (i1 (fp_to_int (vt (VOP3Mods vt:$src0, i32:$src0_modifiers)))),
1453 (i1 (Inst 0, (kone_type KOne), $src0_modifiers, $src0, DSTCLAMP.NONE))
1456 def : FPToI1Pat<V_CMP_EQ_F32_e64, CONST.FP32_ONE, i32, f32, fp_to_uint>;
1457 def : FPToI1Pat<V_CMP_EQ_F32_e64, CONST.FP32_NEG_ONE, i32, f32, fp_to_sint>;
1458 def : FPToI1Pat<V_CMP_EQ_F64_e64, CONST.FP64_ONE, i64, f64, fp_to_uint>;
1459 def : FPToI1Pat<V_CMP_EQ_F64_e64, CONST.FP64_NEG_ONE, i64, f64, fp_to_sint>;
1461 // If we need to perform a logical operation on i1 values, we need to
1462 // use vector comparisons since there is only one SCC register. Vector
1463 // comparisons may write to a pair of SGPRs or a single SGPR, so treat
1464 // these as 32 or 64-bit comparisons. When legalizing SGPR copies,
1465 // instructions resulting in the copies from SCC to these instructions
1466 // will be moved to the VALU.
1468 let WaveSizePredicate = isWave64 in {
1470 (i1 (and i1:$src0, i1:$src1)),
1471 (S_AND_B64 $src0, $src1)
1475 (i1 (or i1:$src0, i1:$src1)),
1476 (S_OR_B64 $src0, $src1)
1480 (i1 (xor i1:$src0, i1:$src1)),
1481 (S_XOR_B64 $src0, $src1)
1485 (i1 (add i1:$src0, i1:$src1)),
1486 (S_XOR_B64 $src0, $src1)
1490 (i1 (sub i1:$src0, i1:$src1)),
1491 (S_XOR_B64 $src0, $src1)
1494 let AddedComplexity = 1 in {
1496 (i1 (add i1:$src0, (i1 -1))),
1501 (i1 (sub i1:$src0, (i1 -1))),
1507 let WaveSizePredicate = isWave32 in {
1509 (i1 (and i1:$src0, i1:$src1)),
1510 (S_AND_B32 $src0, $src1)
1514 (i1 (or i1:$src0, i1:$src1)),
1515 (S_OR_B32 $src0, $src1)
1519 (i1 (xor i1:$src0, i1:$src1)),
1520 (S_XOR_B32 $src0, $src1)
1524 (i1 (add i1:$src0, i1:$src1)),
1525 (S_XOR_B32 $src0, $src1)
1529 (i1 (sub i1:$src0, i1:$src1)),
1530 (S_XOR_B32 $src0, $src1)
1533 let AddedComplexity = 1 in {
1535 (i1 (add i1:$src0, (i1 -1))),
1540 (i1 (sub i1:$src0, (i1 -1))),
1547 (f16 (sint_to_fp i1:$src)),
1548 (V_CVT_F16_F32_e32 (
1549 V_CNDMASK_B32_e64 /*src0mod*/(i32 0), /*src0*/(i32 0),
1550 /*src1mod*/(i32 0), /*src1*/(i32 CONST.FP32_NEG_ONE),
1555 (f16 (uint_to_fp i1:$src)),
1556 (V_CVT_F16_F32_e32 (
1557 V_CNDMASK_B32_e64 /*src0mod*/(i32 0), /*src0*/(i32 0),
1558 /*src1mod*/(i32 0), /*src1*/(i32 CONST.FP32_ONE),
1563 (f32 (sint_to_fp i1:$src)),
1564 (V_CNDMASK_B32_e64 /*src0mod*/(i32 0), /*src0*/(i32 0),
1565 /*src1mod*/(i32 0), /*src1*/(i32 CONST.FP32_NEG_ONE),
1570 (f32 (uint_to_fp i1:$src)),
1571 (V_CNDMASK_B32_e64 /*src0mod*/(i32 0), /*src0*/(i32 0),
1572 /*src1mod*/(i32 0), /*src1*/(i32 CONST.FP32_ONE),
1577 (f64 (sint_to_fp i1:$src)),
1578 (V_CVT_F64_I32_e32 (V_CNDMASK_B32_e64 /*src0mod*/(i32 0), /*src0*/(i32 0),
1579 /*src1mod*/(i32 0), /*src1*/(i32 -1),
1584 (f64 (uint_to_fp i1:$src)),
1585 (V_CVT_F64_U32_e32 (V_CNDMASK_B32_e64 /*src0mod*/(i32 0), /*src0*/(i32 0),
1586 /*src1mod*/(i32 0), /*src1*/(i32 1),
1590 //===----------------------------------------------------------------------===//
1591 // Miscellaneous Patterns
1592 //===----------------------------------------------------------------------===//
1594 (i32 (AMDGPUfp16_zext f16:$src)),
1600 (i32 (trunc i64:$a)),
1601 (EXTRACT_SUBREG $a, sub0)
1605 (i1 (trunc i32:$a)),
1606 (V_CMP_EQ_U32_e64 (S_AND_B32 (i32 1), $a), (i32 1))
1610 (i1 (trunc i16:$a)),
1611 (V_CMP_EQ_U32_e64 (S_AND_B32 (i32 1), $a), (i32 1))
1615 (i1 (trunc i64:$a)),
1616 (V_CMP_EQ_U32_e64 (S_AND_B32 (i32 1),
1617 (i32 (EXTRACT_SUBREG $a, sub0))), (i32 1))
1621 (i32 (bswap i32:$a)),
1622 (V_BFI_B32 (S_MOV_B32 (i32 0x00ff00ff)),
1623 (V_ALIGNBIT_B32 $a, $a, (i32 24)),
1624 (V_ALIGNBIT_B32 $a, $a, (i32 8)))
1627 let OtherPredicates = [NoFP16Denormals] in {
1629 (fcanonicalize (f16 (VOP3Mods f16:$src, i32:$src_mods))),
1630 (V_MUL_F16_e64 0, (i32 CONST.FP16_ONE), $src_mods, $src, 0, 0)
1634 (fcanonicalize (f16 (fneg (VOP3Mods f16:$src, i32:$src_mods)))),
1635 (V_MUL_F16_e64 0, (i32 CONST.FP16_NEG_ONE), $src_mods, $src, 0, 0)
1639 (fcanonicalize (v2f16 (VOP3PMods v2f16:$src, i32:$src_mods))),
1640 (V_PK_MUL_F16 0, (i32 CONST.FP16_ONE), $src_mods, $src, DSTCLAMP.NONE)
1644 let OtherPredicates = [FP16Denormals] in {
1646 (fcanonicalize (f16 (VOP3Mods f16:$src, i32:$src_mods))),
1647 (V_MAX_F16_e64 $src_mods, $src, $src_mods, $src, 0, 0)
1650 let SubtargetPredicate = HasVOP3PInsts in {
1652 (fcanonicalize (v2f16 (VOP3PMods v2f16:$src, i32:$src_mods))),
1653 (V_PK_MAX_F16 $src_mods, $src, $src_mods, $src, DSTCLAMP.NONE)
1658 let OtherPredicates = [NoFP32Denormals] in {
1660 (fcanonicalize (f32 (VOP3Mods f32:$src, i32:$src_mods))),
1661 (V_MUL_F32_e64 0, (i32 CONST.FP32_ONE), $src_mods, $src, 0, 0)
1665 (fcanonicalize (f32 (fneg (VOP3Mods f32:$src, i32:$src_mods)))),
1666 (V_MUL_F32_e64 0, (i32 CONST.FP32_NEG_ONE), $src_mods, $src, 0, 0)
1670 let OtherPredicates = [FP32Denormals] in {
1672 (fcanonicalize (f32 (VOP3Mods f32:$src, i32:$src_mods))),
1673 (V_MAX_F32_e64 $src_mods, $src, $src_mods, $src, 0, 0)
1677 let OtherPredicates = [NoFP64Denormals] in {
1679 (fcanonicalize (f64 (VOP3Mods f64:$src, i32:$src_mods))),
1680 (V_MUL_F64 0, CONST.FP64_ONE, $src_mods, $src, 0, 0)
1684 let OtherPredicates = [FP64Denormals] in {
1686 (fcanonicalize (f64 (VOP3Mods f64:$src, i32:$src_mods))),
1687 (V_MAX_F64 $src_mods, $src, $src_mods, $src, 0, 0)
1691 let OtherPredicates = [HasDLInsts] in {
1693 (fma (f32 (VOP3Mods0 f32:$src0, i32:$src0_modifiers, i1:$clamp, i32:$omod)),
1694 (f32 (VOP3Mods f32:$src1, i32:$src1_modifiers)),
1695 (f32 (VOP3NoMods f32:$src2))),
1696 (V_FMAC_F32_e64 $src0_modifiers, $src0, $src1_modifiers, $src1,
1697 SRCMODS.NONE, $src2, $clamp, $omod)
1699 } // End OtherPredicates = [HasDLInsts]
1701 let SubtargetPredicate = isGFX10Plus in
1703 (fma (f16 (VOP3Mods0 f32:$src0, i32:$src0_modifiers, i1:$clamp, i32:$omod)),
1704 (f16 (VOP3Mods f32:$src1, i32:$src1_modifiers)),
1705 (f16 (VOP3NoMods f32:$src2))),
1706 (V_FMAC_F16_e64 $src0_modifiers, $src0, $src1_modifiers, $src1,
1707 SRCMODS.NONE, $src2, $clamp, $omod)
1710 // Allow integer inputs
1711 class ExpPattern<SDPatternOperator node, ValueType vt, Instruction Inst> : GCNPat<
1712 (node (i8 timm:$tgt), (i8 timm:$en), vt:$src0, vt:$src1, vt:$src2, vt:$src3, (i1 timm:$compr), (i1 timm:$vm)),
1713 (Inst i8:$tgt, vt:$src0, vt:$src1, vt:$src2, vt:$src3, i1:$vm, i1:$compr, i8:$en)
1716 def : ExpPattern<AMDGPUexport, i32, EXP>;
1717 def : ExpPattern<AMDGPUexport_done, i32, EXP_DONE>;
1719 // COPY is workaround tablegen bug from multiple outputs
1720 // from S_LSHL_B32's multiple outputs from implicit scc def.
1722 (v2i16 (build_vector (i16 0), i16:$src1)),
1723 (v2i16 (COPY (S_LSHL_B32 i16:$src1, (i16 16))))
1727 (v2i16 (build_vector i16:$src0, (i16 undef))),
1728 (v2i16 (COPY $src0))
1732 (v2f16 (build_vector f16:$src0, (f16 undef))),
1733 (v2f16 (COPY $src0))
1737 (v2i16 (build_vector (i16 undef), i16:$src1)),
1738 (v2i16 (COPY (S_LSHL_B32 $src1, (i32 16))))
1742 (v2f16 (build_vector (f16 undef), f16:$src1)),
1743 (v2f16 (COPY (S_LSHL_B32 $src1, (i32 16))))
1746 let SubtargetPredicate = HasVOP3PInsts in {
1748 (v2i16 (build_vector i16:$src0, i16:$src1)),
1749 (v2i16 (S_PACK_LL_B32_B16 $src0, $src1))
1752 // With multiple uses of the shift, this will duplicate the shift and
1753 // increase register pressure.
1755 (v2i16 (build_vector i16:$src0, (i16 (trunc (srl_oneuse i32:$src1, (i32 16)))))),
1756 (v2i16 (S_PACK_LH_B32_B16 i16:$src0, i32:$src1))
1761 (v2i16 (build_vector (i16 (trunc (srl_oneuse i32:$src0, (i32 16)))),
1762 (i16 (trunc (srl_oneuse i32:$src1, (i32 16)))))),
1763 (v2i16 (S_PACK_HH_B32_B16 $src0, $src1))
1766 // TODO: Should source modifiers be matched to v_pack_b32_f16?
1768 (v2f16 (build_vector f16:$src0, f16:$src1)),
1769 (v2f16 (S_PACK_LL_B32_B16 $src0, $src1))
1772 } // End SubtargetPredicate = HasVOP3PInsts
1776 (v2f16 (scalar_to_vector f16:$src0)),
1781 (v2i16 (scalar_to_vector i16:$src0)),
1786 (v4i16 (scalar_to_vector i16:$src0)),
1787 (INSERT_SUBREG (IMPLICIT_DEF), $src0, sub0)
1791 (v4f16 (scalar_to_vector f16:$src0)),
1792 (INSERT_SUBREG (IMPLICIT_DEF), $src0, sub0)
1795 //===----------------------------------------------------------------------===//
1797 //===----------------------------------------------------------------------===//
1799 let SubtargetPredicate = isGFX6 in {
1801 // V_FRACT is buggy on SI, so the F32 version is never used and (x-floor(x)) is
1802 // used instead. However, SI doesn't have V_FLOOR_F64, so the most efficient
1803 // way to implement it is using V_FRACT_F64.
1804 // The workaround for the V_FRACT bug is:
1805 // fract(x) = isnan(x) ? x : min(V_FRACT(x), 0.99999999999999999)
1807 // Convert floor(x) to (x - fract(x))
1809 (f64 (ffloor (f64 (VOP3Mods f64:$x, i32:$mods)))),
1814 (V_CNDMASK_B64_PSEUDO
1817 (V_FRACT_F64_e64 $mods, $x, DSTCLAMP.NONE, DSTOMOD.NONE),
1819 (V_MOV_B64_PSEUDO 0x3fefffffffffffff),
1820 DSTCLAMP.NONE, DSTOMOD.NONE),
1822 (V_CMP_CLASS_F64_e64 SRCMODS.NONE, $x, (i32 3 /*NaN*/))),
1823 DSTCLAMP.NONE, DSTOMOD.NONE)
1826 } // End SubtargetPredicates = isGFX6
1828 //============================================================================//
1829 // Miscellaneous Optimization Patterns
1830 //============================================================================//
1832 // Undo sub x, c -> add x, -c canonicalization since c is more likely
1833 // an inline immediate than -c.
1834 // TODO: Also do for 64-bit.
1836 (add i32:$src0, (i32 NegSubInlineConst32:$src1)),
1837 (S_SUB_I32 $src0, NegSubInlineConst32:$src1)
1840 // Avoid pointlessly materializing a constant in VGPR.
1841 // FIXME: Should also do this for readlane, but tablegen crashes on
1842 // the ignored src1.
1844 (int_amdgcn_readfirstlane (i32 imm:$src)),
1848 multiclass BFMPatterns <ValueType vt, InstSI BFM, InstSI MOV> {
1850 (vt (shl (vt (add (vt (shl 1, vt:$a)), -1)), vt:$b)),
1855 (vt (add (vt (shl 1, vt:$a)), -1)),
1856 (BFM $a, (MOV (i32 0)))
1860 defm : BFMPatterns <i32, S_BFM_B32, S_MOV_B32>;
1861 // FIXME: defm : BFMPatterns <i64, S_BFM_B64, S_MOV_B64>;
1863 defm : BFEPattern <V_BFE_U32, V_BFE_I32, S_MOV_B32>;
1864 defm : SHA256MaPattern <V_BFI_B32, V_XOR_B32_e64, SReg_64>;
1866 defm : IntMed3Pat<V_MED3_I32, smin, smax, smin_oneuse, smax_oneuse>;
1867 defm : IntMed3Pat<V_MED3_U32, umin, umax, umin_oneuse, umax_oneuse>;
1869 // This matches 16 permutations of
1870 // max(min(x, y), min(max(x, y), z))
1871 class FPMed3Pat<ValueType vt,
1872 //SDPatternOperator max, SDPatternOperator min,
1873 Instruction med3Inst> : GCNPat<
1874 (fmaxnum_like (fminnum_like_oneuse (VOP3Mods_nnan vt:$src0, i32:$src0_mods),
1875 (VOP3Mods_nnan vt:$src1, i32:$src1_mods)),
1876 (fminnum_like_oneuse (fmaxnum_like_oneuse (VOP3Mods_nnan vt:$src0, i32:$src0_mods),
1877 (VOP3Mods_nnan vt:$src1, i32:$src1_mods)),
1878 (vt (VOP3Mods_nnan vt:$src2, i32:$src2_mods)))),
1879 (med3Inst $src0_mods, $src0, $src1_mods, $src1, $src2_mods, $src2, DSTCLAMP.NONE, DSTOMOD.NONE)
1882 class FP16Med3Pat<ValueType vt,
1883 Instruction med3Inst> : GCNPat<
1884 (fmaxnum_like (fminnum_like_oneuse (VOP3Mods_nnan vt:$src0, i32:$src0_mods),
1885 (VOP3Mods_nnan vt:$src1, i32:$src1_mods)),
1886 (fminnum_like_oneuse (fmaxnum_like_oneuse (VOP3Mods_nnan vt:$src0, i32:$src0_mods),
1887 (VOP3Mods_nnan vt:$src1, i32:$src1_mods)),
1888 (vt (VOP3Mods_nnan vt:$src2, i32:$src2_mods)))),
1889 (med3Inst $src0_mods, $src0, $src1_mods, $src1, $src2_mods, $src2, DSTCLAMP.NONE)
1892 multiclass Int16Med3Pat<Instruction med3Inst,
1893 SDPatternOperator min,
1894 SDPatternOperator max,
1895 SDPatternOperator max_oneuse,
1896 SDPatternOperator min_oneuse,
1897 ValueType vt = i16> {
1898 // This matches 16 permutations of
1899 // max(min(x, y), min(max(x, y), z))
1901 (max (min_oneuse vt:$src0, vt:$src1),
1902 (min_oneuse (max_oneuse vt:$src0, vt:$src1), vt:$src2)),
1903 (med3Inst SRCMODS.NONE, $src0, SRCMODS.NONE, $src1, SRCMODS.NONE, $src2, DSTCLAMP.NONE)
1906 // This matches 16 permutations of
1907 // min(max(a, b), max(min(a, b), c))
1909 (min (max_oneuse vt:$src0, vt:$src1),
1910 (max_oneuse (min_oneuse vt:$src0, vt:$src1), vt:$src2)),
1911 (med3Inst SRCMODS.NONE, $src0, SRCMODS.NONE, $src1, SRCMODS.NONE, $src2, DSTCLAMP.NONE)
1915 def : FPMed3Pat<f32, V_MED3_F32>;
1917 let OtherPredicates = [isGFX9Plus] in {
1918 def : FP16Med3Pat<f16, V_MED3_F16>;
1919 defm : Int16Med3Pat<V_MED3_I16, smin, smax, smax_oneuse, smin_oneuse>;
1920 defm : Int16Med3Pat<V_MED3_U16, umin, umax, umax_oneuse, umin_oneuse>;
1921 } // End Predicates = [isGFX9Plus]