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 timm:$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 timm:$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 timm:$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 def VOP_I64_I64_DPP : VOPProfile <[i64, i64, untyped, untyped]> {
100 let hasSideEffects = 0, mayLoad = 0, mayStore = 0, Uses = [EXEC] in {
102 // For use in patterns
103 def V_CNDMASK_B64_PSEUDO : VOP3Common <(outs VReg_64:$vdst),
104 (ins VSrc_b64:$src0, VSrc_b64:$src1, SSrc_b64:$src2), "", []> {
106 let isCodeGenOnly = 1;
107 let usesCustomInserter = 1;
110 // 64-bit vector move instruction. This is mainly used by the
111 // SIFoldOperands pass to enable folding of inline immediates.
112 def V_MOV_B64_PSEUDO : VPseudoInstSI <(outs VReg_64:$vdst),
113 (ins VSrc_b64:$src0)>;
115 // 64-bit vector move with dpp. Expanded post-RA.
116 def V_MOV_B64_DPP_PSEUDO : VOP_DPP_Pseudo <"v_mov_b64_dpp", VOP_I64_I64_DPP> {
117 let Size = 16; // Requires two 8-byte v_mov_b32_dpp to complete.
120 // Pseudoinstruction for @llvm.amdgcn.wqm. It is turned into a copy after the
121 // WQM pass processes it.
122 def WQM : PseudoInstSI <(outs unknown:$vdst), (ins unknown:$src0)>;
124 // Pseudoinstruction for @llvm.amdgcn.softwqm. Like @llvm.amdgcn.wqm it is
125 // turned into a copy by WQM pass, but does not seed WQM requirements.
126 def SOFT_WQM : PseudoInstSI <(outs unknown:$vdst), (ins unknown:$src0)>;
128 // Pseudoinstruction for @llvm.amdgcn.wwm. It is turned into a copy post-RA, so
129 // that the @earlyclobber is respected. The @earlyclobber is to make sure that
130 // the instruction that defines $src0 (which is run in WWM) doesn't
131 // accidentally clobber inactive channels of $vdst.
132 let Constraints = "@earlyclobber $vdst" in {
133 def WWM : PseudoInstSI <(outs unknown:$vdst), (ins unknown:$src0)>;
136 } // End let hasSideEffects = 0, mayLoad = 0, mayStore = 0, Uses = [EXEC]
138 def ENTER_WWM : SPseudoInstSI <(outs SReg_1:$sdst), (ins i64imm:$src0)> {
140 let hasSideEffects = 0;
145 def EXIT_WWM : SPseudoInstSI <(outs SReg_1:$sdst), (ins SReg_1:$src0)> {
146 let hasSideEffects = 0;
151 // Invert the exec mask and overwrite the inactive lanes of dst with inactive,
152 // restoring it after we're done.
153 def V_SET_INACTIVE_B32 : VPseudoInstSI <(outs VGPR_32:$vdst),
154 (ins VGPR_32: $src, VSrc_b32:$inactive),
155 [(set i32:$vdst, (int_amdgcn_set_inactive i32:$src, i32:$inactive))]> {
156 let Constraints = "$src = $vdst";
159 def V_SET_INACTIVE_B64 : VPseudoInstSI <(outs VReg_64:$vdst),
160 (ins VReg_64: $src, VSrc_b64:$inactive),
161 [(set i64:$vdst, (int_amdgcn_set_inactive i64:$src, i64:$inactive))]> {
162 let Constraints = "$src = $vdst";
166 let usesCustomInserter = 1, Defs = [SCC] in {
167 def S_ADD_U64_PSEUDO : SPseudoInstSI <
168 (outs SReg_64:$vdst), (ins SSrc_b64:$src0, SSrc_b64:$src1),
169 [(set SReg_64:$vdst, (add i64:$src0, i64:$src1))]
172 def S_SUB_U64_PSEUDO : SPseudoInstSI <
173 (outs SReg_64:$vdst), (ins SSrc_b64:$src0, SSrc_b64:$src1),
174 [(set SReg_64:$vdst, (sub i64:$src0, i64:$src1))]
177 def S_ADD_U64_CO_PSEUDO : SPseudoInstSI <
178 (outs SReg_64:$vdst, VOPDstS64orS32:$sdst), (ins SSrc_b64:$src0, SSrc_b64:$src1)
181 def S_SUB_U64_CO_PSEUDO : SPseudoInstSI <
182 (outs SReg_64:$vdst, VOPDstS64orS32:$sdst), (ins SSrc_b64:$src0, SSrc_b64:$src1)
184 } // End usesCustomInserter = 1, Defs = [SCC]
186 let usesCustomInserter = 1 in {
187 def GET_GROUPSTATICSIZE : SPseudoInstSI <(outs SReg_32:$sdst), (ins),
188 [(set SReg_32:$sdst, (int_amdgcn_groupstaticsize))]>;
189 } // End let usesCustomInserter = 1, SALU = 1
191 // Wrap an instruction by duplicating it, except for setting isTerminator.
192 class WrapTerminatorInst<SOP_Pseudo base_inst> : SPseudoInstSI<
193 base_inst.OutOperandList,
194 base_inst.InOperandList> {
195 let Uses = base_inst.Uses;
196 let Defs = base_inst.Defs;
197 let isTerminator = 1;
198 let isAsCheapAsAMove = base_inst.isAsCheapAsAMove;
199 let hasSideEffects = base_inst.hasSideEffects;
200 let UseNamedOperandTable = base_inst.UseNamedOperandTable;
201 let CodeSize = base_inst.CodeSize;
204 let WaveSizePredicate = isWave64 in {
205 def S_MOV_B64_term : WrapTerminatorInst<S_MOV_B64>;
206 def S_XOR_B64_term : WrapTerminatorInst<S_XOR_B64>;
207 def S_ANDN2_B64_term : WrapTerminatorInst<S_ANDN2_B64>;
210 let WaveSizePredicate = isWave32 in {
211 def S_MOV_B32_term : WrapTerminatorInst<S_MOV_B32>;
212 def S_XOR_B32_term : WrapTerminatorInst<S_XOR_B32>;
213 def S_OR_B32_term : WrapTerminatorInst<S_OR_B32>;
214 def S_ANDN2_B32_term : WrapTerminatorInst<S_ANDN2_B32>;
217 def WAVE_BARRIER : SPseudoInstSI<(outs), (ins),
218 [(int_amdgcn_wave_barrier)]> {
220 let hasNoSchedulingInfo = 1;
221 let hasSideEffects = 1;
224 let isConvergent = 1;
229 // SI pseudo instructions. These are used by the CFG structurizer pass
230 // and should be lowered to ISA instructions prior to codegen.
232 // Dummy terminator instruction to use after control flow instructions
233 // replaced with exec mask operations.
234 def SI_MASK_BRANCH : VPseudoInstSI <
235 (outs), (ins brtarget:$target)> {
237 let isTerminator = 1;
240 let hasNoSchedulingInfo = 1;
245 let isTerminator = 1 in {
247 let OtherPredicates = [EnableLateCFGStructurize] in {
248 def SI_NON_UNIFORM_BRCOND_PSEUDO : CFPseudoInstSI <
250 (ins SReg_1:$vcc, brtarget:$target),
251 [(brcond i1:$vcc, bb:$target)]> {
256 def SI_IF: CFPseudoInstSI <
257 (outs SReg_1:$dst), (ins SReg_1:$vcc, brtarget:$target),
258 [(set i1:$dst, (AMDGPUif i1:$vcc, bb:$target))], 1, 1> {
259 let Constraints = "";
261 let hasSideEffects = 1;
264 def SI_ELSE : CFPseudoInstSI <
266 (ins SReg_1:$src, brtarget:$target, i1imm:$execfix), [], 1, 1> {
268 let hasSideEffects = 1;
271 def SI_LOOP : CFPseudoInstSI <
272 (outs), (ins SReg_1:$saved, brtarget:$target),
273 [(AMDGPUloop i1:$saved, bb:$target)], 1, 1> {
276 let hasSideEffects = 1;
279 } // End isTerminator = 1
281 def SI_END_CF : CFPseudoInstSI <
282 (outs), (ins SReg_1:$saved), [], 1, 1> {
284 let isAsCheapAsAMove = 1;
285 let isReMaterializable = 1;
286 let hasSideEffects = 1;
287 let mayLoad = 1; // FIXME: Should not need memory flags
291 def SI_IF_BREAK : CFPseudoInstSI <
292 (outs SReg_1:$dst), (ins SReg_1:$vcc, SReg_1:$src), []> {
294 let isAsCheapAsAMove = 1;
295 let isReMaterializable = 1;
298 let Uses = [EXEC] in {
300 multiclass PseudoInstKill <dag ins> {
301 // Even though this pseudo can usually be expanded without an SCC def, we
302 // conservatively assume that it has an SCC def, both because it is sometimes
303 // required in degenerate cases (when V_CMPX cannot be used due to constant
304 // bus limitations) and because it allows us to avoid having to track SCC
305 // liveness across basic blocks.
306 let Defs = [EXEC,VCC,SCC] in
307 def _PSEUDO : PseudoInstSI <(outs), ins> {
308 let isConvergent = 1;
309 let usesCustomInserter = 1;
312 let Defs = [EXEC,VCC,SCC] in
313 def _TERMINATOR : SPseudoInstSI <(outs), ins> {
314 let isTerminator = 1;
318 defm SI_KILL_I1 : PseudoInstKill <(ins SCSrc_i1:$src, i1imm:$killvalue)>;
319 defm SI_KILL_F32_COND_IMM : PseudoInstKill <(ins VSrc_b32:$src0, i32imm:$src1, i32imm:$cond)>;
321 let Defs = [EXEC,VCC] in
322 def SI_ILLEGAL_COPY : SPseudoInstSI <
323 (outs unknown:$dst), (ins unknown:$src),
324 [], " ; illegal copy $src to $dst">;
326 } // End Uses = [EXEC], Defs = [EXEC,VCC]
328 // Branch on undef scc. Used to avoid intermediate copy from
329 // IMPLICIT_DEF to SCC.
330 def SI_BR_UNDEF : SPseudoInstSI <(outs), (ins sopp_brtarget:$simm16)> {
331 let isTerminator = 1;
332 let usesCustomInserter = 1;
336 def SI_PS_LIVE : PseudoInstSI <
337 (outs SReg_1:$dst), (ins),
338 [(set i1:$dst, (int_amdgcn_ps_live))]> {
342 def SI_MASKED_UNREACHABLE : SPseudoInstSI <(outs), (ins),
343 [(int_amdgcn_unreachable)],
344 "; divergent unreachable"> {
346 let hasNoSchedulingInfo = 1;
350 // Used as an isel pseudo to directly emit initialization with an
351 // s_mov_b32 rather than a copy of another initialized
352 // register. MachineCSE skips copies, and we don't want to have to
353 // fold operands before it runs.
354 def SI_INIT_M0 : SPseudoInstSI <(outs), (ins SSrc_b32:$src)> {
356 let usesCustomInserter = 1;
357 let isAsCheapAsAMove = 1;
358 let isReMaterializable = 1;
361 def SI_INIT_EXEC : SPseudoInstSI <
362 (outs), (ins i64imm:$src),
363 [(int_amdgcn_init_exec (i64 timm:$src))]> {
365 let usesCustomInserter = 1;
366 let isAsCheapAsAMove = 1;
367 let WaveSizePredicate = isWave64;
370 // FIXME: Intrinsic should be mangled for wave size.
371 def SI_INIT_EXEC_LO : SPseudoInstSI <
372 (outs), (ins i32imm:$src), []> {
373 let Defs = [EXEC_LO];
374 let usesCustomInserter = 1;
375 let isAsCheapAsAMove = 1;
376 let WaveSizePredicate = isWave32;
379 // FIXME: Wave32 version
380 def SI_INIT_EXEC_FROM_INPUT : SPseudoInstSI <
381 (outs), (ins SSrc_b32:$input, i32imm:$shift),
382 [(int_amdgcn_init_exec_from_input i32:$input, (i32 timm:$shift))]> {
384 let usesCustomInserter = 1;
388 (int_amdgcn_init_exec timm:$src),
389 (SI_INIT_EXEC_LO (as_i32imm imm:$src))> {
390 let WaveSizePredicate = isWave32;
393 // Return for returning shaders to a shader variant epilog.
394 def SI_RETURN_TO_EPILOG : SPseudoInstSI <
395 (outs), (ins variable_ops), [(AMDGPUreturn_to_epilog)]> {
396 let isTerminator = 1;
399 let hasNoSchedulingInfo = 1;
404 // Return for returning function calls.
405 def SI_RETURN : SPseudoInstSI <
408 let isTerminator = 1;
411 let SchedRW = [WriteBranch];
414 // Return for returning function calls without output register.
416 // This version is only needed so we can fill in the output regiter in
417 // the custom inserter.
418 def SI_CALL_ISEL : SPseudoInstSI <
419 (outs), (ins SSrc_b64:$src0, unknown:$callee),
420 [(AMDGPUcall i64:$src0, tglobaladdr:$callee)]> {
423 let SchedRW = [WriteBranch];
424 let usesCustomInserter = 1;
425 // TODO: Should really base this on the call target
426 let isConvergent = 1;
429 // Wrapper around s_swappc_b64 with extra $callee parameter to track
430 // the called function after regalloc.
431 def SI_CALL : SPseudoInstSI <
432 (outs SReg_64:$dst), (ins SSrc_b64:$src0, unknown:$callee)> {
435 let UseNamedOperandTable = 1;
436 let SchedRW = [WriteBranch];
437 // TODO: Should really base this on the call target
438 let isConvergent = 1;
441 // Tail call handling pseudo
442 def SI_TCRETURN : SPseudoInstSI <(outs),
443 (ins SSrc_b64:$src0, unknown:$callee, i32imm:$fpdiff),
444 [(AMDGPUtc_return i64:$src0, tglobaladdr:$callee, i32:$fpdiff)]> {
447 let isTerminator = 1;
450 let UseNamedOperandTable = 1;
451 let SchedRW = [WriteBranch];
452 // TODO: Should really base this on the call target
453 let isConvergent = 1;
457 def ADJCALLSTACKUP : SPseudoInstSI<
458 (outs), (ins i32imm:$amt0, i32imm:$amt1),
459 [(callseq_start timm:$amt0, timm:$amt1)],
460 "; adjcallstackup $amt0 $amt1"> {
461 let Size = 8; // Worst case. (s_add_u32 + constant)
463 let hasSideEffects = 1;
464 let usesCustomInserter = 1;
465 let SchedRW = [WriteSALU];
469 def ADJCALLSTACKDOWN : SPseudoInstSI<
470 (outs), (ins i32imm:$amt1, i32imm:$amt2),
471 [(callseq_end timm:$amt1, timm:$amt2)],
472 "; adjcallstackdown $amt1"> {
473 let Size = 8; // Worst case. (s_add_u32 + constant)
474 let hasSideEffects = 1;
475 let usesCustomInserter = 1;
476 let SchedRW = [WriteSALU];
480 let Defs = [M0, EXEC, SCC],
481 UseNamedOperandTable = 1 in {
483 class SI_INDIRECT_SRC<RegisterClass rc> : VPseudoInstSI <
484 (outs VGPR_32:$vdst),
485 (ins rc:$src, VS_32:$idx, i32imm:$offset)> {
486 let usesCustomInserter = 1;
489 class SI_INDIRECT_DST<RegisterClass rc> : VPseudoInstSI <
491 (ins rc:$src, VS_32:$idx, i32imm:$offset, VGPR_32:$val)> {
492 let Constraints = "$src = $vdst";
493 let usesCustomInserter = 1;
496 // TODO: We can support indirect SGPR access.
497 def SI_INDIRECT_SRC_V1 : SI_INDIRECT_SRC<VGPR_32>;
498 def SI_INDIRECT_SRC_V2 : SI_INDIRECT_SRC<VReg_64>;
499 def SI_INDIRECT_SRC_V4 : SI_INDIRECT_SRC<VReg_128>;
500 def SI_INDIRECT_SRC_V8 : SI_INDIRECT_SRC<VReg_256>;
501 def SI_INDIRECT_SRC_V16 : SI_INDIRECT_SRC<VReg_512>;
503 def SI_INDIRECT_DST_V1 : SI_INDIRECT_DST<VGPR_32>;
504 def SI_INDIRECT_DST_V2 : SI_INDIRECT_DST<VReg_64>;
505 def SI_INDIRECT_DST_V4 : SI_INDIRECT_DST<VReg_128>;
506 def SI_INDIRECT_DST_V8 : SI_INDIRECT_DST<VReg_256>;
507 def SI_INDIRECT_DST_V16 : SI_INDIRECT_DST<VReg_512>;
509 } // End Uses = [EXEC], Defs = [M0, EXEC]
511 multiclass SI_SPILL_SGPR <RegisterClass sgpr_class> {
512 let UseNamedOperandTable = 1, SGPRSpill = 1, Uses = [EXEC] in {
513 def _SAVE : PseudoInstSI <
515 (ins sgpr_class:$data, i32imm:$addr)> {
520 def _RESTORE : PseudoInstSI <
521 (outs sgpr_class:$data),
522 (ins i32imm:$addr)> {
526 } // End UseNamedOperandTable = 1
529 // You cannot use M0 as the output of v_readlane_b32 instructions or
530 // use it in the sdata operand of SMEM instructions. We still need to
531 // be able to spill the physical register m0, so allow it for
532 // SI_SPILL_32_* instructions.
533 defm SI_SPILL_S32 : SI_SPILL_SGPR <SReg_32>;
534 defm SI_SPILL_S64 : SI_SPILL_SGPR <SReg_64>;
535 defm SI_SPILL_S96 : SI_SPILL_SGPR <SReg_96>;
536 defm SI_SPILL_S128 : SI_SPILL_SGPR <SReg_128>;
537 defm SI_SPILL_S160 : SI_SPILL_SGPR <SReg_160>;
538 defm SI_SPILL_S256 : SI_SPILL_SGPR <SReg_256>;
539 defm SI_SPILL_S512 : SI_SPILL_SGPR <SReg_512>;
540 defm SI_SPILL_S1024 : SI_SPILL_SGPR <SReg_1024>;
542 multiclass SI_SPILL_VGPR <RegisterClass vgpr_class> {
543 let UseNamedOperandTable = 1, VGPRSpill = 1,
544 SchedRW = [WriteVMEM] in {
545 def _SAVE : VPseudoInstSI <
547 (ins vgpr_class:$vdata, i32imm:$vaddr, SReg_128:$srsrc,
548 SReg_32:$soffset, i32imm:$offset)> {
551 // (2 * 4) + (8 * num_subregs) bytes maximum
552 int MaxSize = !add(!shl(!srl(vgpr_class.Size, 5), 3), 8);
553 // Size field is unsigned char and cannot fit more.
554 let Size = !if(!le(MaxSize, 256), MaxSize, 252);
557 def _RESTORE : VPseudoInstSI <
558 (outs vgpr_class:$vdata),
559 (ins i32imm:$vaddr, SReg_128:$srsrc, SReg_32:$soffset,
564 // (2 * 4) + (8 * num_subregs) bytes maximum
565 int MaxSize = !add(!shl(!srl(vgpr_class.Size, 5), 3), 8);
566 // Size field is unsigned char and cannot fit more.
567 let Size = !if(!le(MaxSize, 256), MaxSize, 252);
569 } // End UseNamedOperandTable = 1, VGPRSpill = 1, SchedRW = [WriteVMEM]
572 defm SI_SPILL_V32 : SI_SPILL_VGPR <VGPR_32>;
573 defm SI_SPILL_V64 : SI_SPILL_VGPR <VReg_64>;
574 defm SI_SPILL_V96 : SI_SPILL_VGPR <VReg_96>;
575 defm SI_SPILL_V128 : SI_SPILL_VGPR <VReg_128>;
576 defm SI_SPILL_V160 : SI_SPILL_VGPR <VReg_160>;
577 defm SI_SPILL_V256 : SI_SPILL_VGPR <VReg_256>;
578 defm SI_SPILL_V512 : SI_SPILL_VGPR <VReg_512>;
579 defm SI_SPILL_V1024 : SI_SPILL_VGPR <VReg_1024>;
581 multiclass SI_SPILL_AGPR <RegisterClass vgpr_class> {
582 let UseNamedOperandTable = 1, VGPRSpill = 1,
583 Constraints = "@earlyclobber $tmp",
584 SchedRW = [WriteVMEM] in {
585 def _SAVE : VPseudoInstSI <
587 (ins vgpr_class:$vdata, i32imm:$vaddr, SReg_128:$srsrc,
588 SReg_32:$soffset, i32imm:$offset)> {
591 // (2 * 4) + (16 * num_subregs) bytes maximum
592 int MaxSize = !add(!shl(!srl(vgpr_class.Size, 5), 4), 8);
593 // Size field is unsigned char and cannot fit more.
594 let Size = !if(!le(MaxSize, 256), MaxSize, 252);
597 def _RESTORE : VPseudoInstSI <
598 (outs vgpr_class:$vdata, VGPR_32:$tmp),
599 (ins i32imm:$vaddr, SReg_128:$srsrc, SReg_32:$soffset,
604 // (2 * 4) + (16 * num_subregs) bytes maximum
605 int MaxSize = !add(!shl(!srl(vgpr_class.Size, 5), 4), 8);
606 // Size field is unsigned char and cannot fit more.
607 let Size = !if(!le(MaxSize, 256), MaxSize, 252);
609 } // End UseNamedOperandTable = 1, VGPRSpill = 1, SchedRW = [WriteVMEM]
612 defm SI_SPILL_A32 : SI_SPILL_AGPR <AGPR_32>;
613 defm SI_SPILL_A64 : SI_SPILL_AGPR <AReg_64>;
614 defm SI_SPILL_A128 : SI_SPILL_AGPR <AReg_128>;
615 defm SI_SPILL_A512 : SI_SPILL_AGPR <AReg_512>;
616 defm SI_SPILL_A1024 : SI_SPILL_AGPR <AReg_1024>;
618 def SI_PC_ADD_REL_OFFSET : SPseudoInstSI <
620 (ins si_ga:$ptr_lo, si_ga:$ptr_hi),
622 (i64 (SIpc_add_rel_offset tglobaladdr:$ptr_lo, tglobaladdr:$ptr_hi)))]> {
627 (SIpc_add_rel_offset tglobaladdr:$ptr_lo, 0),
628 (SI_PC_ADD_REL_OFFSET $ptr_lo, (i32 0))
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 VSrc_b32:$src))
752 (i32 (fp_to_uint f16:$src)),
753 (V_CVT_U32_F32_e32 (V_CVT_F32_F16_e32 VSrc_b32:$src))
757 (f16 (sint_to_fp i32:$src)),
758 (V_CVT_F16_F32_e32 (V_CVT_F32_I32_e32 VSrc_b32:$src))
762 (f16 (uint_to_fp i32:$src)),
763 (V_CVT_F16_F32_e32 (V_CVT_F32_U32_e32 VSrc_b32:$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)
818 (i32 (ctpop i32:$popcnt)),
819 (V_BCNT_U32_B32_e64 VSrc_b32:$popcnt, (i32 0))
823 (i16 (add (i16 (trunc (i32 (getDivergentFrag<ctpop>.ret i32:$popcnt)))), i16:$val)),
824 (V_BCNT_U32_B32_e64 $popcnt, $val)
827 /********** ============================================ **********/
828 /********** Extraction, Insertion, Building and Casting **********/
829 /********** ============================================ **********/
831 foreach Index = 0-2 in {
832 def Extract_Element_v2i32_#Index : Extract_Element <
833 i32, v2i32, Index, !cast<SubRegIndex>(sub#Index)
835 def Insert_Element_v2i32_#Index : Insert_Element <
836 i32, v2i32, Index, !cast<SubRegIndex>(sub#Index)
839 def Extract_Element_v2f32_#Index : Extract_Element <
840 f32, v2f32, Index, !cast<SubRegIndex>(sub#Index)
842 def Insert_Element_v2f32_#Index : Insert_Element <
843 f32, v2f32, Index, !cast<SubRegIndex>(sub#Index)
847 foreach Index = 0-2 in {
848 def Extract_Element_v3i32_#Index : Extract_Element <
849 i32, v3i32, Index, !cast<SubRegIndex>(sub#Index)
851 def Insert_Element_v3i32_#Index : Insert_Element <
852 i32, v3i32, Index, !cast<SubRegIndex>(sub#Index)
855 def Extract_Element_v3f32_#Index : Extract_Element <
856 f32, v3f32, Index, !cast<SubRegIndex>(sub#Index)
858 def Insert_Element_v3f32_#Index : Insert_Element <
859 f32, v3f32, Index, !cast<SubRegIndex>(sub#Index)
863 foreach Index = 0-3 in {
864 def Extract_Element_v4i32_#Index : Extract_Element <
865 i32, v4i32, Index, !cast<SubRegIndex>(sub#Index)
867 def Insert_Element_v4i32_#Index : Insert_Element <
868 i32, v4i32, Index, !cast<SubRegIndex>(sub#Index)
871 def Extract_Element_v4f32_#Index : Extract_Element <
872 f32, v4f32, Index, !cast<SubRegIndex>(sub#Index)
874 def Insert_Element_v4f32_#Index : Insert_Element <
875 f32, v4f32, Index, !cast<SubRegIndex>(sub#Index)
879 foreach Index = 0-4 in {
880 def Extract_Element_v5i32_#Index : Extract_Element <
881 i32, v5i32, Index, !cast<SubRegIndex>(sub#Index)
883 def Insert_Element_v5i32_#Index : Insert_Element <
884 i32, v5i32, Index, !cast<SubRegIndex>(sub#Index)
887 def Extract_Element_v5f32_#Index : Extract_Element <
888 f32, v5f32, Index, !cast<SubRegIndex>(sub#Index)
890 def Insert_Element_v5f32_#Index : Insert_Element <
891 f32, v5f32, Index, !cast<SubRegIndex>(sub#Index)
895 foreach Index = 0-7 in {
896 def Extract_Element_v8i32_#Index : Extract_Element <
897 i32, v8i32, Index, !cast<SubRegIndex>(sub#Index)
899 def Insert_Element_v8i32_#Index : Insert_Element <
900 i32, v8i32, Index, !cast<SubRegIndex>(sub#Index)
903 def Extract_Element_v8f32_#Index : Extract_Element <
904 f32, v8f32, Index, !cast<SubRegIndex>(sub#Index)
906 def Insert_Element_v8f32_#Index : Insert_Element <
907 f32, v8f32, Index, !cast<SubRegIndex>(sub#Index)
911 foreach Index = 0-15 in {
912 def Extract_Element_v16i32_#Index : Extract_Element <
913 i32, v16i32, Index, !cast<SubRegIndex>(sub#Index)
915 def Insert_Element_v16i32_#Index : Insert_Element <
916 i32, v16i32, Index, !cast<SubRegIndex>(sub#Index)
919 def Extract_Element_v16f32_#Index : Extract_Element <
920 f32, v16f32, Index, !cast<SubRegIndex>(sub#Index)
922 def Insert_Element_v16f32_#Index : Insert_Element <
923 f32, v16f32, Index, !cast<SubRegIndex>(sub#Index)
929 (extract_subvector v4i16:$vec, (i32 0)),
930 (v2i16 (EXTRACT_SUBREG v4i16:$vec, sub0))
934 (extract_subvector v4i16:$vec, (i32 2)),
935 (v2i16 (EXTRACT_SUBREG v4i16:$vec, sub1))
939 (extract_subvector v4f16:$vec, (i32 0)),
940 (v2f16 (EXTRACT_SUBREG v4f16:$vec, sub0))
944 (extract_subvector v4f16:$vec, (i32 2)),
945 (v2f16 (EXTRACT_SUBREG v4f16:$vec, sub1))
948 foreach Index = 0-31 in {
949 def Extract_Element_v32i32_#Index : Extract_Element <
950 i32, v32i32, Index, !cast<SubRegIndex>(sub#Index)
953 def Insert_Element_v32i32_#Index : Insert_Element <
954 i32, v32i32, Index, !cast<SubRegIndex>(sub#Index)
957 def Extract_Element_v32f32_#Index : Extract_Element <
958 f32, v32f32, Index, !cast<SubRegIndex>(sub#Index)
961 def Insert_Element_v32f32_#Index : Insert_Element <
962 f32, v32f32, Index, !cast<SubRegIndex>(sub#Index)
966 // FIXME: Why do only some of these type combinations for SReg and
969 def : BitConvert <i16, f16, VGPR_32>;
970 def : BitConvert <f16, i16, VGPR_32>;
971 def : BitConvert <i16, f16, SReg_32>;
972 def : BitConvert <f16, i16, SReg_32>;
975 def : BitConvert <i32, f32, VGPR_32>;
976 def : BitConvert <f32, i32, VGPR_32>;
977 def : BitConvert <i32, f32, SReg_32>;
978 def : BitConvert <f32, i32, SReg_32>;
979 def : BitConvert <v2i16, i32, SReg_32>;
980 def : BitConvert <i32, v2i16, SReg_32>;
981 def : BitConvert <v2f16, i32, SReg_32>;
982 def : BitConvert <i32, v2f16, SReg_32>;
983 def : BitConvert <v2i16, v2f16, SReg_32>;
984 def : BitConvert <v2f16, v2i16, SReg_32>;
985 def : BitConvert <v2f16, f32, SReg_32>;
986 def : BitConvert <f32, v2f16, SReg_32>;
987 def : BitConvert <v2i16, f32, SReg_32>;
988 def : BitConvert <f32, v2i16, SReg_32>;
991 def : BitConvert <i64, f64, VReg_64>;
992 def : BitConvert <f64, i64, VReg_64>;
993 def : BitConvert <v2i32, v2f32, VReg_64>;
994 def : BitConvert <v2f32, v2i32, VReg_64>;
995 def : BitConvert <i64, v2i32, VReg_64>;
996 def : BitConvert <v2i32, i64, VReg_64>;
997 def : BitConvert <i64, v2f32, VReg_64>;
998 def : BitConvert <v2f32, i64, VReg_64>;
999 def : BitConvert <f64, v2f32, VReg_64>;
1000 def : BitConvert <v2f32, f64, VReg_64>;
1001 def : BitConvert <f64, v2i32, VReg_64>;
1002 def : BitConvert <v2i32, f64, VReg_64>;
1003 def : BitConvert <v4i16, v4f16, VReg_64>;
1004 def : BitConvert <v4f16, v4i16, VReg_64>;
1007 def : BitConvert <v2i32, v4f16, VReg_64>;
1008 def : BitConvert <v4f16, v2i32, VReg_64>;
1009 def : BitConvert <v2i32, v4f16, VReg_64>;
1010 def : BitConvert <v2i32, v4i16, VReg_64>;
1011 def : BitConvert <v4i16, v2i32, VReg_64>;
1012 def : BitConvert <v2f32, v4f16, VReg_64>;
1013 def : BitConvert <v4f16, v2f32, VReg_64>;
1014 def : BitConvert <v2f32, v4i16, VReg_64>;
1015 def : BitConvert <v4i16, v2f32, VReg_64>;
1016 def : BitConvert <v4i16, f64, VReg_64>;
1017 def : BitConvert <v4f16, f64, VReg_64>;
1018 def : BitConvert <f64, v4i16, VReg_64>;
1019 def : BitConvert <f64, v4f16, VReg_64>;
1020 def : BitConvert <v4i16, i64, VReg_64>;
1021 def : BitConvert <v4f16, i64, VReg_64>;
1022 def : BitConvert <i64, v4i16, VReg_64>;
1023 def : BitConvert <i64, v4f16, VReg_64>;
1025 def : BitConvert <v4i32, v4f32, VReg_128>;
1026 def : BitConvert <v4f32, v4i32, VReg_128>;
1029 def : BitConvert <v3i32, v3f32, SGPR_96>;
1030 def : BitConvert <v3f32, v3i32, SGPR_96>;
1033 def : BitConvert <v2i64, v4i32, SReg_128>;
1034 def : BitConvert <v4i32, v2i64, SReg_128>;
1035 def : BitConvert <v2f64, v4f32, VReg_128>;
1036 def : BitConvert <v2f64, v4i32, VReg_128>;
1037 def : BitConvert <v4f32, v2f64, VReg_128>;
1038 def : BitConvert <v4i32, v2f64, VReg_128>;
1039 def : BitConvert <v2i64, v2f64, VReg_128>;
1040 def : BitConvert <v2f64, v2i64, VReg_128>;
1043 def : BitConvert <v5i32, v5f32, SGPR_160>;
1044 def : BitConvert <v5f32, v5i32, SGPR_160>;
1047 def : BitConvert <v8i32, v8f32, SReg_256>;
1048 def : BitConvert <v8f32, v8i32, SReg_256>;
1049 def : BitConvert <v8i32, v8f32, VReg_256>;
1050 def : BitConvert <v8f32, v8i32, VReg_256>;
1053 def : BitConvert <v16i32, v16f32, VReg_512>;
1054 def : BitConvert <v16f32, v16i32, VReg_512>;
1057 def : BitConvert <v32i32, v32f32, VReg_1024>;
1058 def : BitConvert <v32f32, v32i32, VReg_1024>;
1060 /********** =================== **********/
1061 /********** Src & Dst modifiers **********/
1062 /********** =================== **********/
1065 // If denormals are not enabled, it only impacts the compare of the
1066 // inputs. The output result is not flushed.
1067 class ClampPat<Instruction inst, ValueType vt> : GCNPat <
1068 (vt (AMDGPUclamp (VOP3Mods vt:$src0, i32:$src0_modifiers))),
1069 (inst i32:$src0_modifiers, vt:$src0,
1070 i32:$src0_modifiers, vt:$src0, DSTCLAMP.ENABLE, DSTOMOD.NONE)
1073 def : ClampPat<V_MAX_F32_e64, f32>;
1074 def : ClampPat<V_MAX_F64, f64>;
1075 def : ClampPat<V_MAX_F16_e64, f16>;
1077 let SubtargetPredicate = HasVOP3PInsts in {
1079 (v2f16 (AMDGPUclamp (VOP3PMods v2f16:$src0, i32:$src0_modifiers))),
1080 (V_PK_MAX_F16 $src0_modifiers, $src0,
1081 $src0_modifiers, $src0, DSTCLAMP.ENABLE)
1085 /********** ================================ **********/
1086 /********** Floating point absolute/negative **********/
1087 /********** ================================ **********/
1089 // Prevent expanding both fneg and fabs.
1090 // TODO: Add IgnoredBySelectionDAG bit?
1091 let AddedComplexity = 1 in { // Prefer SALU to VALU patterns for DAG
1094 (fneg (fabs (f32 SReg_32:$src))),
1095 (S_OR_B32 SReg_32:$src, (S_MOV_B32 (i32 0x80000000))) // Set sign bit
1099 (fabs (f32 SReg_32:$src)),
1100 (S_AND_B32 SReg_32:$src, (S_MOV_B32 (i32 0x7fffffff)))
1104 (fneg (f32 SReg_32:$src)),
1105 (S_XOR_B32 SReg_32:$src, (S_MOV_B32 (i32 0x80000000)))
1109 (fneg (f16 SReg_32:$src)),
1110 (S_XOR_B32 SReg_32:$src, (S_MOV_B32 (i32 0x00008000)))
1114 (fneg (f16 VGPR_32:$src)),
1115 (V_XOR_B32_e32 (S_MOV_B32 (i32 0x00008000)), VGPR_32:$src)
1119 (fabs (f16 SReg_32:$src)),
1120 (S_AND_B32 SReg_32:$src, (S_MOV_B32 (i32 0x00007fff)))
1124 (fneg (fabs (f16 SReg_32:$src))),
1125 (S_OR_B32 SReg_32:$src, (S_MOV_B32 (i32 0x00008000))) // Set sign bit
1129 (fneg (fabs (f16 VGPR_32:$src))),
1130 (V_OR_B32_e32 (S_MOV_B32 (i32 0x00008000)), VGPR_32:$src) // Set sign bit
1134 (fneg (v2f16 SReg_32:$src)),
1135 (S_XOR_B32 SReg_32:$src, (S_MOV_B32 (i32 0x80008000)))
1139 (fabs (v2f16 SReg_32:$src)),
1140 (S_AND_B32 SReg_32:$src, (S_MOV_B32 (i32 0x7fff7fff)))
1143 // This is really (fneg (fabs v2f16:$src))
1145 // fabs is not reported as free because there is modifier for it in
1146 // VOP3P instructions, so it is turned into the bit op.
1148 (fneg (v2f16 (bitconvert (and_oneuse (i32 SReg_32:$src), 0x7fff7fff)))),
1149 (S_OR_B32 SReg_32:$src, (S_MOV_B32 (i32 0x80008000))) // Set sign bit
1153 (fneg (v2f16 (fabs SReg_32:$src))),
1154 (S_OR_B32 SReg_32:$src, (S_MOV_B32 (i32 0x80008000))) // Set sign bit
1157 // FIXME: The implicit-def of scc from S_[X]OR_B32 is mishandled
1159 // (fneg (f64 SReg_64:$src)),
1160 // (REG_SEQUENCE SReg_64,
1161 // (i32 (EXTRACT_SUBREG SReg_64:$src, sub0)),
1163 // (S_XOR_B32 (i32 (EXTRACT_SUBREG SReg_64:$src, sub1)),
1164 // (i32 (S_MOV_B32 (i32 0x80000000)))),
1169 // (fneg (fabs (f64 SReg_64:$src))),
1170 // (REG_SEQUENCE SReg_64,
1171 // (i32 (EXTRACT_SUBREG SReg_64:$src, sub0)),
1173 // (S_OR_B32 (i32 (EXTRACT_SUBREG SReg_64:$src, sub1)),
1174 // (S_MOV_B32 (i32 0x80000000))), // Set sign bit.
1178 } // End let AddedComplexity = 1
1181 (fabs (f32 VGPR_32:$src)),
1182 (V_AND_B32_e32 (S_MOV_B32 (i32 0x7fffffff)), VGPR_32:$src)
1186 (fneg (f32 VGPR_32:$src)),
1187 (V_XOR_B32_e32 (S_MOV_B32 (i32 0x80000000)), VGPR_32:$src)
1191 (fabs (f16 VGPR_32:$src)),
1192 (V_AND_B32_e32 (S_MOV_B32 (i32 0x00007fff)), VGPR_32:$src)
1196 (fneg (v2f16 VGPR_32:$src)),
1197 (V_XOR_B32_e32 (S_MOV_B32 (i32 0x80008000)), VGPR_32:$src)
1201 (fabs (v2f16 VGPR_32:$src)),
1202 (V_AND_B32_e32 (S_MOV_B32 (i32 0x7fff7fff)), VGPR_32:$src)
1206 (fneg (v2f16 (fabs VGPR_32:$src))),
1207 (V_OR_B32_e32 (S_MOV_B32 (i32 0x80008000)), VGPR_32:$src) // Set sign bit
1211 (fabs (f64 VReg_64:$src)),
1212 (REG_SEQUENCE VReg_64,
1213 (i32 (EXTRACT_SUBREG VReg_64:$src, sub0)),
1215 (V_AND_B32_e64 (i32 (EXTRACT_SUBREG VReg_64:$src, sub1)),
1216 (V_MOV_B32_e32 (i32 0x7fffffff))), // Set sign bit.
1220 // TODO: Use SGPR for constant
1222 (fneg (f64 VReg_64:$src)),
1223 (REG_SEQUENCE VReg_64,
1224 (i32 (EXTRACT_SUBREG VReg_64:$src, sub0)),
1226 (V_XOR_B32_e32 (i32 (EXTRACT_SUBREG VReg_64:$src, sub1)),
1227 (i32 (V_MOV_B32_e32 (i32 0x80000000)))),
1231 // TODO: Use SGPR for constant
1233 (fneg (fabs (f64 VReg_64:$src))),
1234 (REG_SEQUENCE VReg_64,
1235 (i32 (EXTRACT_SUBREG VReg_64:$src, sub0)),
1237 (V_OR_B32_e32 (i32 (EXTRACT_SUBREG VReg_64:$src, sub1)),
1238 (V_MOV_B32_e32 (i32 0x80000000))), // Set sign bit.
1243 (fcopysign f16:$src0, f16:$src1),
1244 (V_BFI_B32 (S_MOV_B32 (i32 0x00007fff)), $src0, $src1)
1248 (fcopysign f32:$src0, f16:$src1),
1249 (V_BFI_B32 (S_MOV_B32 (i32 0x7fffffff)), $src0,
1250 (V_LSHLREV_B32_e64 (i32 16), $src1))
1254 (fcopysign f64:$src0, f16:$src1),
1255 (REG_SEQUENCE SReg_64,
1256 (i32 (EXTRACT_SUBREG $src0, sub0)), sub0,
1257 (V_BFI_B32 (S_MOV_B32 (i32 0x7fffffff)), (i32 (EXTRACT_SUBREG $src0, sub1)),
1258 (V_LSHLREV_B32_e64 (i32 16), $src1)), sub1)
1262 (fcopysign f16:$src0, f32:$src1),
1263 (V_BFI_B32 (S_MOV_B32 (i32 0x00007fff)), $src0,
1264 (V_LSHRREV_B32_e64 (i32 16), $src1))
1268 (fcopysign f16:$src0, f64:$src1),
1269 (V_BFI_B32 (S_MOV_B32 (i32 0x00007fff)), $src0,
1270 (V_LSHRREV_B32_e64 (i32 16), (EXTRACT_SUBREG $src1, sub1)))
1273 /********** ================== **********/
1274 /********** Immediate Patterns **********/
1275 /********** ================== **********/
1278 (VGPRImm<(i32 imm)>:$imm),
1279 (V_MOV_B32_e32 imm:$imm)
1283 (VGPRImm<(f32 fpimm)>:$imm),
1284 (V_MOV_B32_e32 (f32 (bitcast_fpimm_to_i32 $imm)))
1289 (S_MOV_B32 imm:$imm)
1293 (VGPRImm<(SIlds tglobaladdr:$ga)>),
1298 (SIlds tglobaladdr:$ga),
1302 // FIXME: Workaround for ordering issue with peephole optimizer where
1303 // a register class copy interferes with immediate folding. Should
1304 // use s_mov_b32, which can be shrunk to s_movk_i32
1306 (VGPRImm<(f16 fpimm)>:$imm),
1307 (V_MOV_B32_e32 (f16 (bitcast_fpimm_to_i32 $imm)))
1312 (S_MOV_B32 (f32 (bitcast_fpimm_to_i32 $imm)))
1317 (S_MOV_B32 (i32 (bitcast_fpimm_to_i32 $imm)))
1321 (i32 frameindex:$fi),
1322 (V_MOV_B32_e32 (i32 (frameindex_to_targetframeindex $fi)))
1326 (i64 InlineImm<i64>:$imm),
1327 (S_MOV_B64 InlineImm<i64>:$imm)
1330 // XXX - Should this use a s_cmp to set SCC?
1332 // Set to sign-extended 64-bit value (true = -1, false = 0)
1335 (S_MOV_B64 (i64 (as_i64imm $imm)))
1337 let WaveSizePredicate = isWave64;
1342 (S_MOV_B32 (i32 (as_i32imm $imm)))
1344 let WaveSizePredicate = isWave32;
1348 (f64 InlineFPImm<f64>:$imm),
1349 (S_MOV_B64 (f64 (bitcast_fpimm_to_i64 InlineFPImm<f64>:$imm)))
1352 /********** ================== **********/
1353 /********** Intrinsic Patterns **********/
1354 /********** ================== **********/
1356 def : POW_Common <V_LOG_F32_e32, V_EXP_F32_e32, V_MUL_LEGACY_F32_e32>;
1359 (i32 (sext i1:$src0)),
1360 (V_CNDMASK_B32_e64 /*src0mod*/(i32 0), /*src0*/(i32 0),
1361 /*src1mod*/(i32 0), /*src1*/(i32 -1), $src0)
1364 class Ext32Pat <SDNode ext> : GCNPat <
1365 (i32 (ext i1:$src0)),
1366 (V_CNDMASK_B32_e64 /*src0mod*/(i32 0), /*src0*/(i32 0),
1367 /*src1mod*/(i32 0), /*src1*/(i32 1), $src0)
1370 def : Ext32Pat <zext>;
1371 def : Ext32Pat <anyext>;
1373 // The multiplication scales from [0,1] to the unsigned integer range
1375 (AMDGPUurecip i32:$src0),
1377 (V_MUL_F32_e32 (i32 CONST.FP_UINT_MAX_PLUS_1),
1378 (V_RCP_IFLAG_F32_e32 (V_CVT_F32_U32_e32 $src0))))
1381 //===----------------------------------------------------------------------===//
1383 //===----------------------------------------------------------------------===//
1385 def : IMad24Pat<V_MAD_I32_I24, 1>;
1386 def : UMad24Pat<V_MAD_U32_U24, 1>;
1388 // FIXME: This should only be done for VALU inputs
1389 defm : BFIPatterns <V_BFI_B32, S_MOV_B32, SReg_64>;
1390 def : ROTRPattern <V_ALIGNBIT_B32>;
1392 def : GCNPat<(i32 (trunc (srl i64:$src0, (and i32:$src1, (i32 31))))),
1393 (V_ALIGNBIT_B32 (i32 (EXTRACT_SUBREG (i64 $src0), sub1)),
1394 (i32 (EXTRACT_SUBREG (i64 $src0), sub0)), $src1)>;
1396 def : GCNPat<(i32 (trunc (srl i64:$src0, (i32 ShiftAmt32Imm:$src1)))),
1397 (V_ALIGNBIT_B32 (i32 (EXTRACT_SUBREG (i64 $src0), sub1)),
1398 (i32 (EXTRACT_SUBREG (i64 $src0), sub0)), $src1)>;
1400 /********** ====================== **********/
1401 /********** Indirect addressing **********/
1402 /********** ====================== **********/
1404 multiclass SI_INDIRECT_Pattern <ValueType vt, ValueType eltvt, string VecSize> {
1405 // Extract with offset
1407 (eltvt (extractelt vt:$src, (MOVRELOffset i32:$idx, (i32 imm:$offset)))),
1408 (!cast<Instruction>("SI_INDIRECT_SRC_"#VecSize) $src, $idx, imm:$offset)
1411 // Insert with offset
1413 (insertelt vt:$src, eltvt:$val, (MOVRELOffset i32:$idx, (i32 imm:$offset))),
1414 (!cast<Instruction>("SI_INDIRECT_DST_"#VecSize) $src, $idx, imm:$offset, $val)
1418 defm : SI_INDIRECT_Pattern <v2f32, f32, "V2">;
1419 defm : SI_INDIRECT_Pattern <v4f32, f32, "V4">;
1420 defm : SI_INDIRECT_Pattern <v8f32, f32, "V8">;
1421 defm : SI_INDIRECT_Pattern <v16f32, f32, "V16">;
1423 defm : SI_INDIRECT_Pattern <v2i32, i32, "V2">;
1424 defm : SI_INDIRECT_Pattern <v4i32, i32, "V4">;
1425 defm : SI_INDIRECT_Pattern <v8i32, i32, "V8">;
1426 defm : SI_INDIRECT_Pattern <v16i32, i32, "V16">;
1428 //===----------------------------------------------------------------------===//
1430 //===----------------------------------------------------------------------===//
1433 (add (sub_oneuse (umax i32:$src0, i32:$src1),
1434 (umin i32:$src0, i32:$src1)),
1436 (V_SAD_U32 $src0, $src1, $src2, (i1 0))
1440 (add (select_oneuse (i1 (setugt i32:$src0, i32:$src1)),
1441 (sub i32:$src0, i32:$src1),
1442 (sub i32:$src1, i32:$src0)),
1444 (V_SAD_U32 $src0, $src1, $src2, (i1 0))
1447 //===----------------------------------------------------------------------===//
1448 // Conversion Patterns
1449 //===----------------------------------------------------------------------===//
1451 def : GCNPat<(i32 (sext_inreg i32:$src, i1)),
1452 (S_BFE_I32 i32:$src, (i32 65536))>; // 0 | 1 << 16
1454 // Handle sext_inreg in i64
1456 (i64 (sext_inreg i64:$src, i1)),
1457 (S_BFE_I64 i64:$src, (i32 0x10000)) // 0 | 1 << 16
1461 (i16 (sext_inreg i16:$src, i1)),
1462 (S_BFE_I32 $src, (i32 0x00010000)) // 0 | 1 << 16
1466 (i16 (sext_inreg i16:$src, i8)),
1467 (S_BFE_I32 $src, (i32 0x80000)) // 0 | 8 << 16
1471 (i64 (sext_inreg i64:$src, i8)),
1472 (S_BFE_I64 i64:$src, (i32 0x80000)) // 0 | 8 << 16
1476 (i64 (sext_inreg i64:$src, i16)),
1477 (S_BFE_I64 i64:$src, (i32 0x100000)) // 0 | 16 << 16
1481 (i64 (sext_inreg i64:$src, i32)),
1482 (S_BFE_I64 i64:$src, (i32 0x200000)) // 0 | 32 << 16
1486 (i64 (zext i32:$src)),
1487 (REG_SEQUENCE SReg_64, $src, sub0, (S_MOV_B32 (i32 0)), sub1)
1491 (i64 (anyext i32:$src)),
1492 (REG_SEQUENCE SReg_64, $src, sub0, (i32 (IMPLICIT_DEF)), sub1)
1495 class ZExt_i64_i1_Pat <SDNode ext> : GCNPat <
1496 (i64 (ext i1:$src)),
1497 (REG_SEQUENCE VReg_64,
1498 (V_CNDMASK_B32_e64 /*src0mod*/(i32 0), /*src0*/(i32 0),
1499 /*src1mod*/(i32 0), /*src1*/(i32 1), $src),
1500 sub0, (S_MOV_B32 (i32 0)), sub1)
1504 def : ZExt_i64_i1_Pat<zext>;
1505 def : ZExt_i64_i1_Pat<anyext>;
1507 // FIXME: We need to use COPY_TO_REGCLASS to work-around the fact that
1508 // REG_SEQUENCE patterns don't support instructions with multiple outputs.
1510 (i64 (sext i32:$src)),
1511 (REG_SEQUENCE SReg_64, $src, sub0,
1512 (i32 (COPY_TO_REGCLASS (S_ASHR_I32 $src, (i32 31)), SReg_32_XM0)), sub1)
1516 (i64 (sext i1:$src)),
1517 (REG_SEQUENCE VReg_64,
1518 (V_CNDMASK_B32_e64 /*src0mod*/(i32 0), /*src0*/(i32 0),
1519 /*src1mod*/(i32 0), /*src1*/(i32 -1), $src), sub0,
1520 (V_CNDMASK_B32_e64 /*src0mod*/(i32 0), /*src0*/(i32 0),
1521 /*src1mod*/(i32 0), /*src1*/(i32 -1), $src), sub1)
1524 class FPToI1Pat<Instruction Inst, int KOne, ValueType kone_type, ValueType vt, SDPatternOperator fp_to_int> : GCNPat <
1525 (i1 (fp_to_int (vt (VOP3Mods vt:$src0, i32:$src0_modifiers)))),
1526 (i1 (Inst 0, (kone_type KOne), $src0_modifiers, $src0, DSTCLAMP.NONE))
1529 def : FPToI1Pat<V_CMP_EQ_F32_e64, CONST.FP32_ONE, i32, f32, fp_to_uint>;
1530 def : FPToI1Pat<V_CMP_EQ_F32_e64, CONST.FP32_NEG_ONE, i32, f32, fp_to_sint>;
1531 def : FPToI1Pat<V_CMP_EQ_F64_e64, CONST.FP64_ONE, i64, f64, fp_to_uint>;
1532 def : FPToI1Pat<V_CMP_EQ_F64_e64, CONST.FP64_NEG_ONE, i64, f64, fp_to_sint>;
1534 // If we need to perform a logical operation on i1 values, we need to
1535 // use vector comparisons since there is only one SCC register. Vector
1536 // comparisons may write to a pair of SGPRs or a single SGPR, so treat
1537 // these as 32 or 64-bit comparisons. When legalizing SGPR copies,
1538 // instructions resulting in the copies from SCC to these instructions
1539 // will be moved to the VALU.
1541 let WaveSizePredicate = isWave64 in {
1543 (i1 (and i1:$src0, i1:$src1)),
1544 (S_AND_B64 $src0, $src1)
1548 (i1 (or i1:$src0, i1:$src1)),
1549 (S_OR_B64 $src0, $src1)
1553 (i1 (xor i1:$src0, i1:$src1)),
1554 (S_XOR_B64 $src0, $src1)
1558 (i1 (add i1:$src0, i1:$src1)),
1559 (S_XOR_B64 $src0, $src1)
1563 (i1 (sub i1:$src0, i1:$src1)),
1564 (S_XOR_B64 $src0, $src1)
1567 let AddedComplexity = 1 in {
1569 (i1 (add i1:$src0, (i1 -1))),
1574 (i1 (sub i1:$src0, (i1 -1))),
1580 let WaveSizePredicate = isWave32 in {
1582 (i1 (and i1:$src0, i1:$src1)),
1583 (S_AND_B32 $src0, $src1)
1587 (i1 (or i1:$src0, i1:$src1)),
1588 (S_OR_B32 $src0, $src1)
1592 (i1 (xor i1:$src0, i1:$src1)),
1593 (S_XOR_B32 $src0, $src1)
1597 (i1 (add i1:$src0, i1:$src1)),
1598 (S_XOR_B32 $src0, $src1)
1602 (i1 (sub i1:$src0, i1:$src1)),
1603 (S_XOR_B32 $src0, $src1)
1606 let AddedComplexity = 1 in {
1608 (i1 (add i1:$src0, (i1 -1))),
1613 (i1 (sub i1:$src0, (i1 -1))),
1620 (f16 (sint_to_fp i1:$src)),
1621 (V_CVT_F16_F32_e32 (
1622 V_CNDMASK_B32_e64 /*src0mod*/(i32 0), /*src0*/(i32 0),
1623 /*src1mod*/(i32 0), /*src1*/(i32 CONST.FP32_NEG_ONE),
1628 (f16 (uint_to_fp i1:$src)),
1629 (V_CVT_F16_F32_e32 (
1630 V_CNDMASK_B32_e64 /*src0mod*/(i32 0), /*src0*/(i32 0),
1631 /*src1mod*/(i32 0), /*src1*/(i32 CONST.FP32_ONE),
1636 (f32 (sint_to_fp i1:$src)),
1637 (V_CNDMASK_B32_e64 /*src0mod*/(i32 0), /*src0*/(i32 0),
1638 /*src1mod*/(i32 0), /*src1*/(i32 CONST.FP32_NEG_ONE),
1643 (f32 (uint_to_fp i1:$src)),
1644 (V_CNDMASK_B32_e64 /*src0mod*/(i32 0), /*src0*/(i32 0),
1645 /*src1mod*/(i32 0), /*src1*/(i32 CONST.FP32_ONE),
1650 (f64 (sint_to_fp i1:$src)),
1651 (V_CVT_F64_I32_e32 (V_CNDMASK_B32_e64 /*src0mod*/(i32 0), /*src0*/(i32 0),
1652 /*src1mod*/(i32 0), /*src1*/(i32 -1),
1657 (f64 (uint_to_fp i1:$src)),
1658 (V_CVT_F64_U32_e32 (V_CNDMASK_B32_e64 /*src0mod*/(i32 0), /*src0*/(i32 0),
1659 /*src1mod*/(i32 0), /*src1*/(i32 1),
1663 //===----------------------------------------------------------------------===//
1664 // Miscellaneous Patterns
1665 //===----------------------------------------------------------------------===//
1667 (i32 (AMDGPUfp16_zext f16:$src)),
1673 (i32 (trunc i64:$a)),
1674 (EXTRACT_SUBREG $a, sub0)
1678 (i1 (trunc i32:$a)),
1679 (V_CMP_EQ_U32_e64 (S_AND_B32 (i32 1), $a), (i32 1))
1683 (i1 (trunc i16:$a)),
1684 (V_CMP_EQ_U32_e64 (S_AND_B32 (i32 1), $a), (i32 1))
1688 (i1 (trunc i64:$a)),
1689 (V_CMP_EQ_U32_e64 (S_AND_B32 (i32 1),
1690 (i32 (EXTRACT_SUBREG $a, sub0))), (i32 1))
1694 (i32 (bswap i32:$a)),
1695 (V_BFI_B32 (S_MOV_B32 (i32 0x00ff00ff)),
1696 (V_ALIGNBIT_B32 $a, $a, (i32 24)),
1697 (V_ALIGNBIT_B32 $a, $a, (i32 8)))
1700 let OtherPredicates = [NoFP16Denormals] in {
1702 (fcanonicalize (f16 (VOP3Mods f16:$src, i32:$src_mods))),
1703 (V_MUL_F16_e64 0, (i32 CONST.FP16_ONE), $src_mods, $src, 0, 0)
1707 (fcanonicalize (f16 (fneg (VOP3Mods f16:$src, i32:$src_mods)))),
1708 (V_MUL_F16_e64 0, (i32 CONST.FP16_NEG_ONE), $src_mods, $src, 0, 0)
1712 (fcanonicalize (v2f16 (VOP3PMods v2f16:$src, i32:$src_mods))),
1713 (V_PK_MUL_F16 0, (i32 CONST.FP16_ONE), $src_mods, $src, DSTCLAMP.NONE)
1717 let OtherPredicates = [FP16Denormals] in {
1719 (fcanonicalize (f16 (VOP3Mods f16:$src, i32:$src_mods))),
1720 (V_MAX_F16_e64 $src_mods, $src, $src_mods, $src, 0, 0)
1723 let SubtargetPredicate = HasVOP3PInsts in {
1725 (fcanonicalize (v2f16 (VOP3PMods v2f16:$src, i32:$src_mods))),
1726 (V_PK_MAX_F16 $src_mods, $src, $src_mods, $src, DSTCLAMP.NONE)
1731 let OtherPredicates = [NoFP32Denormals] in {
1733 (fcanonicalize (f32 (VOP3Mods f32:$src, i32:$src_mods))),
1734 (V_MUL_F32_e64 0, (i32 CONST.FP32_ONE), $src_mods, $src, 0, 0)
1738 (fcanonicalize (f32 (fneg (VOP3Mods f32:$src, i32:$src_mods)))),
1739 (V_MUL_F32_e64 0, (i32 CONST.FP32_NEG_ONE), $src_mods, $src, 0, 0)
1743 let OtherPredicates = [FP32Denormals] in {
1745 (fcanonicalize (f32 (VOP3Mods f32:$src, i32:$src_mods))),
1746 (V_MAX_F32_e64 $src_mods, $src, $src_mods, $src, 0, 0)
1750 let OtherPredicates = [NoFP64Denormals] in {
1752 (fcanonicalize (f64 (VOP3Mods f64:$src, i32:$src_mods))),
1753 (V_MUL_F64 0, CONST.FP64_ONE, $src_mods, $src, 0, 0)
1757 let OtherPredicates = [FP64Denormals] in {
1759 (fcanonicalize (f64 (VOP3Mods f64:$src, i32:$src_mods))),
1760 (V_MAX_F64 $src_mods, $src, $src_mods, $src, 0, 0)
1764 let OtherPredicates = [HasDLInsts] in {
1766 (fma (f32 (VOP3Mods0 f32:$src0, i32:$src0_modifiers, i1:$clamp, i32:$omod)),
1767 (f32 (VOP3Mods f32:$src1, i32:$src1_modifiers)),
1768 (f32 (VOP3NoMods f32:$src2))),
1769 (V_FMAC_F32_e64 $src0_modifiers, $src0, $src1_modifiers, $src1,
1770 SRCMODS.NONE, $src2, $clamp, $omod)
1772 } // End OtherPredicates = [HasDLInsts]
1774 let SubtargetPredicate = isGFX10Plus in
1776 (fma (f16 (VOP3Mods0 f32:$src0, i32:$src0_modifiers, i1:$clamp, i32:$omod)),
1777 (f16 (VOP3Mods f32:$src1, i32:$src1_modifiers)),
1778 (f16 (VOP3NoMods f32:$src2))),
1779 (V_FMAC_F16_e64 $src0_modifiers, $src0, $src1_modifiers, $src1,
1780 SRCMODS.NONE, $src2, $clamp, $omod)
1783 // Allow integer inputs
1784 class ExpPattern<SDPatternOperator node, ValueType vt, Instruction Inst> : GCNPat<
1785 (node (i8 timm:$tgt), (i8 timm:$en), vt:$src0, vt:$src1, vt:$src2, vt:$src3, (i1 timm:$compr), (i1 timm:$vm)),
1786 (Inst i8:$tgt, vt:$src0, vt:$src1, vt:$src2, vt:$src3, i1:$vm, i1:$compr, i8:$en)
1789 def : ExpPattern<AMDGPUexport, i32, EXP>;
1790 def : ExpPattern<AMDGPUexport_done, i32, EXP_DONE>;
1792 // COPY is workaround tablegen bug from multiple outputs
1793 // from S_LSHL_B32's multiple outputs from implicit scc def.
1795 (v2i16 (build_vector (i16 0), i16:$src1)),
1796 (v2i16 (COPY (S_LSHL_B32 i16:$src1, (i16 16))))
1800 (v2i16 (build_vector i16:$src0, (i16 undef))),
1801 (v2i16 (COPY $src0))
1805 (v2f16 (build_vector f16:$src0, (f16 undef))),
1806 (v2f16 (COPY $src0))
1810 (v2i16 (build_vector (i16 undef), i16:$src1)),
1811 (v2i16 (COPY (S_LSHL_B32 $src1, (i32 16))))
1815 (v2f16 (build_vector (f16 undef), f16:$src1)),
1816 (v2f16 (COPY (S_LSHL_B32 $src1, (i32 16))))
1819 let SubtargetPredicate = HasVOP3PInsts in {
1821 (v2i16 (build_vector i16:$src0, i16:$src1)),
1822 (v2i16 (S_PACK_LL_B32_B16 $src0, $src1))
1825 // With multiple uses of the shift, this will duplicate the shift and
1826 // increase register pressure.
1828 (v2i16 (build_vector i16:$src0, (i16 (trunc (srl_oneuse i32:$src1, (i32 16)))))),
1829 (v2i16 (S_PACK_LH_B32_B16 i16:$src0, i32:$src1))
1834 (v2i16 (build_vector (i16 (trunc (srl_oneuse i32:$src0, (i32 16)))),
1835 (i16 (trunc (srl_oneuse i32:$src1, (i32 16)))))),
1836 (v2i16 (S_PACK_HH_B32_B16 $src0, $src1))
1839 // TODO: Should source modifiers be matched to v_pack_b32_f16?
1841 (v2f16 (build_vector f16:$src0, f16:$src1)),
1842 (v2f16 (S_PACK_LL_B32_B16 $src0, $src1))
1845 } // End SubtargetPredicate = HasVOP3PInsts
1849 (v2f16 (scalar_to_vector f16:$src0)),
1854 (v2i16 (scalar_to_vector i16:$src0)),
1859 (v4i16 (scalar_to_vector i16:$src0)),
1860 (INSERT_SUBREG (IMPLICIT_DEF), $src0, sub0)
1864 (v4f16 (scalar_to_vector f16:$src0)),
1865 (INSERT_SUBREG (IMPLICIT_DEF), $src0, sub0)
1869 (i64 (int_amdgcn_mov_dpp i64:$src, timm:$dpp_ctrl, timm:$row_mask, timm:$bank_mask,
1871 (V_MOV_B64_DPP_PSEUDO $src, $src, (as_i32imm $dpp_ctrl),
1872 (as_i32imm $row_mask), (as_i32imm $bank_mask),
1873 (as_i1imm $bound_ctrl))
1877 (i64 (int_amdgcn_update_dpp i64:$old, i64:$src, timm:$dpp_ctrl, timm:$row_mask,
1878 timm:$bank_mask, timm:$bound_ctrl)),
1879 (V_MOV_B64_DPP_PSEUDO $old, $src, (as_i32imm $dpp_ctrl),
1880 (as_i32imm $row_mask), (as_i32imm $bank_mask),
1881 (as_i1imm $bound_ctrl))
1884 //===----------------------------------------------------------------------===//
1886 //===----------------------------------------------------------------------===//
1888 let SubtargetPredicate = isGFX6 in {
1890 // V_FRACT is buggy on SI, so the F32 version is never used and (x-floor(x)) is
1891 // used instead. However, SI doesn't have V_FLOOR_F64, so the most efficient
1892 // way to implement it is using V_FRACT_F64.
1893 // The workaround for the V_FRACT bug is:
1894 // fract(x) = isnan(x) ? x : min(V_FRACT(x), 0.99999999999999999)
1896 // Convert floor(x) to (x - fract(x))
1898 (f64 (ffloor (f64 (VOP3Mods f64:$x, i32:$mods)))),
1903 (V_CNDMASK_B64_PSEUDO
1906 (V_FRACT_F64_e64 $mods, $x, DSTCLAMP.NONE, DSTOMOD.NONE),
1908 (V_MOV_B64_PSEUDO 0x3fefffffffffffff),
1909 DSTCLAMP.NONE, DSTOMOD.NONE),
1911 (V_CMP_CLASS_F64_e64 SRCMODS.NONE, $x, (i32 3 /*NaN*/))),
1912 DSTCLAMP.NONE, DSTOMOD.NONE)
1915 } // End SubtargetPredicates = isGFX6
1917 //============================================================================//
1918 // Miscellaneous Optimization Patterns
1919 //============================================================================//
1921 // Undo sub x, c -> add x, -c canonicalization since c is more likely
1922 // an inline immediate than -c.
1923 // TODO: Also do for 64-bit.
1925 (add i32:$src0, (i32 NegSubInlineConst32:$src1)),
1926 (S_SUB_I32 $src0, NegSubInlineConst32:$src1)
1929 // Avoid pointlessly materializing a constant in VGPR.
1930 // FIXME: Should also do this for readlane, but tablegen crashes on
1931 // the ignored src1.
1933 (int_amdgcn_readfirstlane (i32 imm:$src)),
1937 multiclass BFMPatterns <ValueType vt, InstSI BFM, InstSI MOV> {
1939 (vt (shl (vt (add (vt (shl 1, vt:$a)), -1)), vt:$b)),
1944 (vt (add (vt (shl 1, vt:$a)), -1)),
1945 (BFM $a, (MOV (i32 0)))
1949 defm : BFMPatterns <i32, S_BFM_B32, S_MOV_B32>;
1950 // FIXME: defm : BFMPatterns <i64, S_BFM_B64, S_MOV_B64>;
1952 defm : BFEPattern <V_BFE_U32, V_BFE_I32, S_MOV_B32>;
1953 defm : SHA256MaPattern <V_BFI_B32, V_XOR_B32_e64, SReg_64>;
1955 defm : IntMed3Pat<V_MED3_I32, smin, smax, smin_oneuse, smax_oneuse>;
1956 defm : IntMed3Pat<V_MED3_U32, umin, umax, umin_oneuse, umax_oneuse>;
1958 // This matches 16 permutations of
1959 // max(min(x, y), min(max(x, y), z))
1960 class FPMed3Pat<ValueType vt,
1961 //SDPatternOperator max, SDPatternOperator min,
1962 Instruction med3Inst> : GCNPat<
1963 (fmaxnum_like (fminnum_like_oneuse (VOP3Mods_nnan vt:$src0, i32:$src0_mods),
1964 (VOP3Mods_nnan vt:$src1, i32:$src1_mods)),
1965 (fminnum_like_oneuse (fmaxnum_like_oneuse (VOP3Mods_nnan vt:$src0, i32:$src0_mods),
1966 (VOP3Mods_nnan vt:$src1, i32:$src1_mods)),
1967 (vt (VOP3Mods_nnan vt:$src2, i32:$src2_mods)))),
1968 (med3Inst $src0_mods, $src0, $src1_mods, $src1, $src2_mods, $src2, DSTCLAMP.NONE, DSTOMOD.NONE)
1971 class FP16Med3Pat<ValueType vt,
1972 Instruction med3Inst> : GCNPat<
1973 (fmaxnum_like (fminnum_like_oneuse (VOP3Mods_nnan vt:$src0, i32:$src0_mods),
1974 (VOP3Mods_nnan vt:$src1, i32:$src1_mods)),
1975 (fminnum_like_oneuse (fmaxnum_like_oneuse (VOP3Mods_nnan vt:$src0, i32:$src0_mods),
1976 (VOP3Mods_nnan vt:$src1, i32:$src1_mods)),
1977 (vt (VOP3Mods_nnan vt:$src2, i32:$src2_mods)))),
1978 (med3Inst $src0_mods, $src0, $src1_mods, $src1, $src2_mods, $src2, DSTCLAMP.NONE)
1981 multiclass Int16Med3Pat<Instruction med3Inst,
1982 SDPatternOperator min,
1983 SDPatternOperator max,
1984 SDPatternOperator max_oneuse,
1985 SDPatternOperator min_oneuse,
1986 ValueType vt = i16> {
1987 // This matches 16 permutations of
1988 // max(min(x, y), min(max(x, y), z))
1990 (max (min_oneuse vt:$src0, vt:$src1),
1991 (min_oneuse (max_oneuse vt:$src0, vt:$src1), vt:$src2)),
1992 (med3Inst SRCMODS.NONE, $src0, SRCMODS.NONE, $src1, SRCMODS.NONE, $src2, DSTCLAMP.NONE)
1995 // This matches 16 permutations of
1996 // min(max(a, b), max(min(a, b), c))
1998 (min (max_oneuse vt:$src0, vt:$src1),
1999 (max_oneuse (min_oneuse vt:$src0, vt:$src1), vt:$src2)),
2000 (med3Inst SRCMODS.NONE, $src0, SRCMODS.NONE, $src1, SRCMODS.NONE, $src2, DSTCLAMP.NONE)
2004 def : FPMed3Pat<f32, V_MED3_F32>;
2006 let OtherPredicates = [isGFX9Plus] in {
2007 def : FP16Med3Pat<f16, V_MED3_F16>;
2008 defm : Int16Med3Pat<V_MED3_I16, smin, smax, smax_oneuse, smin_oneuse>;
2009 defm : Int16Med3Pat<V_MED3_U16, umin, umax, umax_oneuse, umin_oneuse>;
2010 } // End Predicates = [isGFX9Plus]
2012 class AMDGPUGenericInstruction : GenericInstruction {
2013 let Namespace = "AMDGPU";
2016 def G_AMDGPU_FFBH_U32 : AMDGPUGenericInstruction {
2017 let OutOperandList = (outs type0:$dst);
2018 let InOperandList = (ins type1:$src);
2019 let hasSideEffects = 0;