1 //===-- SIInstructions.td - SI Instruction Definitions --------------------===//
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"
22 include "EXPInstructions.td"
24 //===----------------------------------------------------------------------===//
25 // VINTRP Instructions
26 //===----------------------------------------------------------------------===//
28 // Used to inject printing of "_e32" suffix for VI (there are "_e64" variants for VI)
29 def VINTRPDst : VINTRPDstOperand <VGPR_32>;
31 let Uses = [MODE, M0, EXEC] in {
33 // FIXME: Specify SchedRW for VINTRP instructions.
35 multiclass V_INTERP_P1_F32_m : VINTRP_m <
37 (outs VINTRPDst:$vdst),
38 (ins VGPR_32:$vsrc, Attr:$attr, AttrChan:$attrchan),
39 "v_interp_p1_f32$vdst, $vsrc, $attr$attrchan",
40 [(set f32:$vdst, (int_amdgcn_interp_p1 f32:$vsrc,
41 (i32 timm:$attrchan), (i32 timm:$attr), M0))]
44 let OtherPredicates = [has32BankLDS, isNotGFX90APlus] in {
46 defm V_INTERP_P1_F32 : V_INTERP_P1_F32_m;
48 } // End OtherPredicates = [has32BankLDS, isNotGFX90APlus]
50 let OtherPredicates = [has16BankLDS, isNotGFX90APlus],
51 Constraints = "@earlyclobber $vdst", isAsmParserOnly=1 in {
53 defm V_INTERP_P1_F32_16bank : V_INTERP_P1_F32_m;
55 } // End OtherPredicates = [has32BankLDS, isNotGFX90APlus],
56 // Constraints = "@earlyclobber $vdst", isAsmParserOnly=1
58 let OtherPredicates = [isNotGFX90APlus] in {
59 let DisableEncoding = "$src0", Constraints = "$src0 = $vdst" in {
61 defm V_INTERP_P2_F32 : VINTRP_m <
63 (outs VINTRPDst:$vdst),
64 (ins VGPR_32:$src0, VGPR_32:$vsrc, Attr:$attr, AttrChan:$attrchan),
65 "v_interp_p2_f32$vdst, $vsrc, $attr$attrchan",
66 [(set f32:$vdst, (int_amdgcn_interp_p2 f32:$src0, f32:$vsrc,
67 (i32 timm:$attrchan), (i32 timm:$attr), M0))]>;
69 } // End DisableEncoding = "$src0", Constraints = "$src0 = $vdst"
71 defm V_INTERP_MOV_F32 : VINTRP_m <
73 (outs VINTRPDst:$vdst),
74 (ins InterpSlot:$vsrc, Attr:$attr, AttrChan:$attrchan),
75 "v_interp_mov_f32$vdst, $vsrc, $attr$attrchan",
76 [(set f32:$vdst, (int_amdgcn_interp_mov (i32 timm:$vsrc),
77 (i32 timm:$attrchan), (i32 timm:$attr), M0))]>;
79 } // End OtherPredicates = [isNotGFX90APlus]
81 } // End Uses = [MODE, M0, EXEC]
83 //===----------------------------------------------------------------------===//
84 // Pseudo Instructions
85 //===----------------------------------------------------------------------===//
86 def ATOMIC_FENCE : SPseudoInstSI<
87 (outs), (ins i32imm:$ordering, i32imm:$scope),
88 [(atomic_fence (i32 timm:$ordering), (i32 timm:$scope))],
89 "ATOMIC_FENCE $ordering, $scope"> {
90 let hasSideEffects = 1;
94 let hasSideEffects = 0, mayLoad = 0, mayStore = 0, Uses = [EXEC] in {
96 // For use in patterns
97 def V_CNDMASK_B64_PSEUDO : VOP3Common <(outs VReg_64:$vdst),
98 (ins VSrc_b64:$src0, VSrc_b64:$src1, SSrc_b64:$src2), "", []> {
100 let isCodeGenOnly = 1;
101 let usesCustomInserter = 1;
104 // 64-bit vector move instruction. This is mainly used by the
105 // SIFoldOperands pass to enable folding of inline immediates.
106 def V_MOV_B64_PSEUDO : VPseudoInstSI <(outs VReg_64:$vdst),
107 (ins VSrc_b64:$src0)> {
108 let isReMaterializable = 1;
109 let isAsCheapAsAMove = 1;
111 let SchedRW = [Write64Bit];
112 let Size = 16; // Needs maximum 2 v_mov_b32 instructions 8 byte long each.
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> {
117 let Size = 16; // Requires two 8-byte v_mov_b32_dpp to complete.
120 // 64-bit scalar move immediate instruction. This is used to avoid subregs
121 // initialization and allow rematerialization.
122 def S_MOV_B64_IMM_PSEUDO : SPseudoInstSI <(outs SReg_64:$sdst),
123 (ins i64imm:$src0)> {
124 let isReMaterializable = 1;
125 let isAsCheapAsAMove = 1;
127 let SchedRW = [WriteSALU, Write64Bit];
128 let Size = 16; // Needs maximum 2 s_mov_b32 instructions 8 byte long each.
132 // Pseudoinstruction for @llvm.amdgcn.wqm. It is turned into a copy after the
133 // WQM pass processes it.
134 def WQM : PseudoInstSI <(outs unknown:$vdst), (ins unknown:$src0)>;
136 // Pseudoinstruction for @llvm.amdgcn.softwqm. Like @llvm.amdgcn.wqm it is
137 // turned into a copy by WQM pass, but does not seed WQM requirements.
138 def SOFT_WQM : PseudoInstSI <(outs unknown:$vdst), (ins unknown:$src0)>;
140 // Pseudoinstruction for @llvm.amdgcn.strict.wwm. It is turned into a copy post-RA, so
141 // that the @earlyclobber is respected. The @earlyclobber is to make sure that
142 // the instruction that defines $src0 (which is run in Whole Wave Mode) doesn't
143 // accidentally clobber inactive channels of $vdst.
144 let Constraints = "@earlyclobber $vdst" in {
145 def STRICT_WWM : PseudoInstSI <(outs unknown:$vdst), (ins unknown:$src0)>;
146 def STRICT_WQM : PseudoInstSI <(outs unknown:$vdst), (ins unknown:$src0)>;
149 } // End let hasSideEffects = 0, mayLoad = 0, mayStore = 0, Uses = [EXEC]
151 def ENTER_STRICT_WWM : SPseudoInstSI <(outs SReg_1:$sdst), (ins i64imm:$src0)> {
153 let Defs = [EXEC, SCC];
154 let hasSideEffects = 0;
159 def EXIT_STRICT_WWM : SPseudoInstSI <(outs SReg_1:$sdst), (ins SReg_1:$src0)> {
160 let hasSideEffects = 0;
165 def ENTER_STRICT_WQM : SPseudoInstSI <(outs SReg_1:$sdst), (ins i64imm:$src0)> {
167 let Defs = [EXEC, SCC];
168 let hasSideEffects = 0;
173 def EXIT_STRICT_WQM : SPseudoInstSI <(outs SReg_1:$sdst), (ins SReg_1:$src0)> {
174 let hasSideEffects = 0;
179 // Invert the exec mask and overwrite the inactive lanes of dst with inactive,
180 // restoring it after we're done.
181 let Defs = [SCC] in {
182 def V_SET_INACTIVE_B32 : VPseudoInstSI <(outs VGPR_32:$vdst),
183 (ins VGPR_32: $src, VSrc_b32:$inactive),
184 [(set i32:$vdst, (int_amdgcn_set_inactive i32:$src, i32:$inactive))]> {
185 let Constraints = "$src = $vdst";
188 def V_SET_INACTIVE_B64 : VPseudoInstSI <(outs VReg_64:$vdst),
189 (ins VReg_64: $src, VSrc_b64:$inactive),
190 [(set i64:$vdst, (int_amdgcn_set_inactive i64:$src, i64:$inactive))]> {
191 let Constraints = "$src = $vdst";
193 } // End Defs = [SCC]
195 let usesCustomInserter = 1, Defs = [VCC, EXEC] in {
196 def V_ADD_U64_PSEUDO : VPseudoInstSI <
197 (outs VReg_64:$vdst), (ins VSrc_b64:$src0, VSrc_b64:$src1),
198 [(set VReg_64:$vdst, (getDivergentFrag<add>.ret i64:$src0, i64:$src1))]
201 def V_SUB_U64_PSEUDO : VPseudoInstSI <
202 (outs VReg_64:$vdst), (ins VSrc_b64:$src0, VSrc_b64:$src1),
203 [(set VReg_64:$vdst, (getDivergentFrag<sub>.ret i64:$src0, i64:$src1))]
205 } // End usesCustomInserter = 1, Defs = [VCC, EXEC]
207 let usesCustomInserter = 1, Defs = [SCC] in {
208 def S_ADD_U64_PSEUDO : SPseudoInstSI <
209 (outs SReg_64:$sdst), (ins SSrc_b64:$src0, SSrc_b64:$src1),
210 [(set SReg_64:$sdst, (UniformBinFrag<add> i64:$src0, i64:$src1))]
213 def S_SUB_U64_PSEUDO : SPseudoInstSI <
214 (outs SReg_64:$sdst), (ins SSrc_b64:$src0, SSrc_b64:$src1),
215 [(set SReg_64:$sdst, (UniformBinFrag<sub> i64:$src0, i64:$src1))]
218 def S_ADD_U64_CO_PSEUDO : SPseudoInstSI <
219 (outs SReg_64:$vdst, VOPDstS64orS32:$sdst), (ins SSrc_b64:$src0, SSrc_b64:$src1)
222 def S_SUB_U64_CO_PSEUDO : SPseudoInstSI <
223 (outs SReg_64:$vdst, VOPDstS64orS32:$sdst), (ins SSrc_b64:$src0, SSrc_b64:$src1)
226 def S_ADD_CO_PSEUDO : SPseudoInstSI <
227 (outs SReg_32:$sdst, SSrc_i1:$scc_out), (ins SSrc_b32:$src0, SSrc_b32:$src1, SSrc_i1:$scc_in)
230 def S_SUB_CO_PSEUDO : SPseudoInstSI <
231 (outs SReg_32:$sdst, SSrc_i1:$scc_out), (ins SSrc_b32:$src0, SSrc_b32:$src1, SSrc_i1:$scc_in)
234 def S_UADDO_PSEUDO : SPseudoInstSI <
235 (outs SReg_32:$sdst, SSrc_i1:$scc_out), (ins SSrc_b32:$src0, SSrc_b32:$src1)
238 def S_USUBO_PSEUDO : SPseudoInstSI <
239 (outs SReg_32:$sdst, SSrc_i1:$scc_out), (ins SSrc_b32:$src0, SSrc_b32:$src1)
242 } // End usesCustomInserter = 1, Defs = [SCC]
244 let usesCustomInserter = 1 in {
245 def GET_GROUPSTATICSIZE : SPseudoInstSI <(outs SReg_32:$sdst), (ins),
246 [(set SReg_32:$sdst, (int_amdgcn_groupstaticsize))]>;
247 } // End let usesCustomInserter = 1, SALU = 1
249 // Wrap an instruction by duplicating it, except for setting isTerminator.
250 class WrapTerminatorInst<SOP_Pseudo base_inst> : SPseudoInstSI<
251 base_inst.OutOperandList,
252 base_inst.InOperandList> {
253 let Uses = base_inst.Uses;
254 let Defs = base_inst.Defs;
255 let isTerminator = 1;
256 let isAsCheapAsAMove = base_inst.isAsCheapAsAMove;
257 let hasSideEffects = base_inst.hasSideEffects;
258 let UseNamedOperandTable = base_inst.UseNamedOperandTable;
259 let CodeSize = base_inst.CodeSize;
260 let SchedRW = base_inst.SchedRW;
263 let WaveSizePredicate = isWave64 in {
264 def S_MOV_B64_term : WrapTerminatorInst<S_MOV_B64>;
265 def S_XOR_B64_term : WrapTerminatorInst<S_XOR_B64>;
266 def S_OR_B64_term : WrapTerminatorInst<S_OR_B64>;
267 def S_ANDN2_B64_term : WrapTerminatorInst<S_ANDN2_B64>;
268 def S_AND_B64_term : WrapTerminatorInst<S_AND_B64>;
271 let WaveSizePredicate = isWave32 in {
272 def S_MOV_B32_term : WrapTerminatorInst<S_MOV_B32>;
273 def S_XOR_B32_term : WrapTerminatorInst<S_XOR_B32>;
274 def S_OR_B32_term : WrapTerminatorInst<S_OR_B32>;
275 def S_ANDN2_B32_term : WrapTerminatorInst<S_ANDN2_B32>;
276 def S_AND_B32_term : WrapTerminatorInst<S_AND_B32>;
280 def WAVE_BARRIER : SPseudoInstSI<(outs), (ins),
281 [(int_amdgcn_wave_barrier)]> {
283 let hasNoSchedulingInfo = 1;
284 let hasSideEffects = 1;
287 let isConvergent = 1;
292 // SI pseudo instructions. These are used by the CFG structurizer pass
293 // and should be lowered to ISA instructions prior to codegen.
295 let isTerminator = 1 in {
297 let OtherPredicates = [EnableLateCFGStructurize] in {
298 def SI_NON_UNIFORM_BRCOND_PSEUDO : CFPseudoInstSI <
300 (ins SReg_1:$vcc, brtarget:$target),
301 [(brcond i1:$vcc, bb:$target)]> {
306 def SI_IF: CFPseudoInstSI <
307 (outs SReg_1:$dst), (ins SReg_1:$vcc, brtarget:$target),
308 [(set i1:$dst, (AMDGPUif i1:$vcc, bb:$target))], 1, 1> {
309 let Constraints = "";
311 let hasSideEffects = 1;
314 def SI_ELSE : CFPseudoInstSI <
316 (ins SReg_1:$src, brtarget:$target), [], 1, 1> {
318 let hasSideEffects = 1;
321 def SI_WATERFALL_LOOP : CFPseudoInstSI <
323 (ins brtarget:$target), [], 1> {
329 def SI_LOOP : CFPseudoInstSI <
330 (outs), (ins SReg_1:$saved, brtarget:$target),
331 [(AMDGPUloop i1:$saved, bb:$target)], 1, 1> {
334 let hasSideEffects = 1;
337 } // End isTerminator = 1
339 def SI_END_CF : CFPseudoInstSI <
340 (outs), (ins SReg_1:$saved), [], 1, 1> {
342 let isAsCheapAsAMove = 1;
343 let isReMaterializable = 1;
344 let hasSideEffects = 1;
345 let mayLoad = 1; // FIXME: Should not need memory flags
349 def SI_IF_BREAK : CFPseudoInstSI <
350 (outs SReg_1:$dst), (ins SReg_1:$vcc, SReg_1:$src), []> {
352 let isAsCheapAsAMove = 1;
353 let isReMaterializable = 1;
356 // Branch to the early termination block of the shader if SCC is 0.
357 // This uses SCC from a previous SALU operation, i.e. the update of
358 // a mask of live lanes after a kill/demote operation.
359 // Only valid in pixel shaders.
360 def SI_EARLY_TERMINATE_SCC0 : SPseudoInstSI <(outs), (ins)> {
361 let Uses = [EXEC,SCC];
364 let Uses = [EXEC] in {
366 multiclass PseudoInstKill <dag ins> {
367 // Even though this pseudo can usually be expanded without an SCC def, we
368 // conservatively assume that it has an SCC def, both because it is sometimes
369 // required in degenerate cases (when V_CMPX cannot be used due to constant
370 // bus limitations) and because it allows us to avoid having to track SCC
371 // liveness across basic blocks.
372 let Defs = [EXEC,SCC] in
373 def _PSEUDO : PseudoInstSI <(outs), ins> {
374 let isConvergent = 1;
375 let usesCustomInserter = 1;
378 let Defs = [EXEC,SCC] in
379 def _TERMINATOR : SPseudoInstSI <(outs), ins> {
380 let isTerminator = 1;
384 defm SI_KILL_I1 : PseudoInstKill <(ins SCSrc_i1:$src, i1imm:$killvalue)>;
386 defm SI_KILL_F32_COND_IMM : PseudoInstKill <(ins VSrc_b32:$src0, i32imm:$src1, i32imm:$cond)>;
388 let Defs = [EXEC,VCC] in
389 def SI_ILLEGAL_COPY : SPseudoInstSI <
390 (outs unknown:$dst), (ins unknown:$src),
391 [], " ; illegal copy $src to $dst">;
393 } // End Uses = [EXEC], Defs = [EXEC,VCC]
395 // Branch on undef scc. Used to avoid intermediate copy from
396 // IMPLICIT_DEF to SCC.
397 def SI_BR_UNDEF : SPseudoInstSI <(outs), (ins sopp_brtarget:$simm16)> {
398 let isTerminator = 1;
399 let usesCustomInserter = 1;
403 def SI_PS_LIVE : PseudoInstSI <
404 (outs SReg_1:$dst), (ins),
405 [(set i1:$dst, (int_amdgcn_ps_live))]> {
409 let Uses = [EXEC] in {
410 def SI_LIVE_MASK : PseudoInstSI <
411 (outs SReg_1:$dst), (ins),
412 [(set i1:$dst, (int_amdgcn_live_mask))]> {
415 let Defs = [EXEC,SCC] in {
416 // Demote: Turn a pixel shader thread into a helper lane.
417 def SI_DEMOTE_I1 : SPseudoInstSI <(outs), (ins SCSrc_i1:$src, i1imm:$killvalue)>;
418 } // End Defs = [EXEC,SCC]
419 } // End Uses = [EXEC]
421 def SI_MASKED_UNREACHABLE : SPseudoInstSI <(outs), (ins),
422 [(int_amdgcn_unreachable)],
423 "; divergent unreachable"> {
425 let hasNoSchedulingInfo = 1;
429 // Used as an isel pseudo to directly emit initialization with an
430 // s_mov_b32 rather than a copy of another initialized
431 // register. MachineCSE skips copies, and we don't want to have to
432 // fold operands before it runs.
433 def SI_INIT_M0 : SPseudoInstSI <(outs), (ins SSrc_b32:$src)> {
435 let usesCustomInserter = 1;
436 let isAsCheapAsAMove = 1;
437 let isReMaterializable = 1;
440 def SI_INIT_EXEC : SPseudoInstSI <
441 (outs), (ins i64imm:$src),
442 [(int_amdgcn_init_exec (i64 timm:$src))]> {
444 let isAsCheapAsAMove = 1;
447 def SI_INIT_EXEC_FROM_INPUT : SPseudoInstSI <
448 (outs), (ins SSrc_b32:$input, i32imm:$shift),
449 [(int_amdgcn_init_exec_from_input i32:$input, (i32 timm:$shift))]> {
453 // Return for returning shaders to a shader variant epilog.
454 def SI_RETURN_TO_EPILOG : SPseudoInstSI <
455 (outs), (ins variable_ops), [(AMDGPUreturn_to_epilog)]> {
456 let isTerminator = 1;
459 let hasNoSchedulingInfo = 1;
464 // Return for returning function calls.
465 def SI_RETURN : SPseudoInstSI <
468 let isTerminator = 1;
471 let SchedRW = [WriteBranch];
474 // Return for returning function calls without output register.
476 // This version is only needed so we can fill in the output register
477 // in the custom inserter.
478 def SI_CALL_ISEL : SPseudoInstSI <
479 (outs), (ins SSrc_b64:$src0, unknown:$callee),
480 [(AMDGPUcall i64:$src0, tglobaladdr:$callee)]> {
483 let SchedRW = [WriteBranch];
484 let usesCustomInserter = 1;
485 // TODO: Should really base this on the call target
486 let isConvergent = 1;
490 (AMDGPUcall i64:$src0, (i64 0)),
491 (SI_CALL_ISEL $src0, (i64 0))
494 // Wrapper around s_swappc_b64 with extra $callee parameter to track
495 // the called function after regalloc.
496 def SI_CALL : SPseudoInstSI <
497 (outs SReg_64:$dst), (ins SSrc_b64:$src0, unknown:$callee)> {
500 let UseNamedOperandTable = 1;
501 let SchedRW = [WriteBranch];
502 // TODO: Should really base this on the call target
503 let isConvergent = 1;
506 // Tail call handling pseudo
507 def SI_TCRETURN : SPseudoInstSI <(outs),
508 (ins SReg_64:$src0, unknown:$callee, i32imm:$fpdiff),
509 [(AMDGPUtc_return i64:$src0, tglobaladdr:$callee, i32:$fpdiff)]> {
512 let isTerminator = 1;
515 let UseNamedOperandTable = 1;
516 let SchedRW = [WriteBranch];
517 // TODO: Should really base this on the call target
518 let isConvergent = 1;
521 // Handle selecting indirect tail calls
523 (AMDGPUtc_return i64:$src0, (i64 0), (i32 timm:$fpdiff)),
524 (SI_TCRETURN SReg_64:$src0, (i64 0), i32imm:$fpdiff)
527 def ADJCALLSTACKUP : SPseudoInstSI<
528 (outs), (ins i32imm:$amt0, i32imm:$amt1),
529 [(callseq_start timm:$amt0, timm:$amt1)],
530 "; adjcallstackup $amt0 $amt1"> {
531 let Size = 8; // Worst case. (s_add_u32 + constant)
533 let hasSideEffects = 1;
534 let usesCustomInserter = 1;
535 let SchedRW = [WriteSALU];
539 def ADJCALLSTACKDOWN : SPseudoInstSI<
540 (outs), (ins i32imm:$amt1, i32imm:$amt2),
541 [(callseq_end timm:$amt1, timm:$amt2)],
542 "; adjcallstackdown $amt1"> {
543 let Size = 8; // Worst case. (s_add_u32 + constant)
544 let hasSideEffects = 1;
545 let usesCustomInserter = 1;
546 let SchedRW = [WriteSALU];
550 let Defs = [M0, EXEC, SCC],
551 UseNamedOperandTable = 1 in {
553 // SI_INDIRECT_SRC/DST are only used by legacy SelectionDAG indirect
554 // addressing implementation.
555 class SI_INDIRECT_SRC<RegisterClass rc> : VPseudoInstSI <
556 (outs VGPR_32:$vdst),
557 (ins rc:$src, VS_32:$idx, i32imm:$offset)> {
558 let usesCustomInserter = 1;
561 class SI_INDIRECT_DST<RegisterClass rc> : VPseudoInstSI <
563 (ins rc:$src, VS_32:$idx, i32imm:$offset, VGPR_32:$val)> {
564 let Constraints = "$src = $vdst";
565 let usesCustomInserter = 1;
568 def SI_INDIRECT_SRC_V1 : SI_INDIRECT_SRC<VGPR_32>;
569 def SI_INDIRECT_SRC_V2 : SI_INDIRECT_SRC<VReg_64>;
570 def SI_INDIRECT_SRC_V4 : SI_INDIRECT_SRC<VReg_128>;
571 def SI_INDIRECT_SRC_V8 : SI_INDIRECT_SRC<VReg_256>;
572 def SI_INDIRECT_SRC_V16 : SI_INDIRECT_SRC<VReg_512>;
573 def SI_INDIRECT_SRC_V32 : SI_INDIRECT_SRC<VReg_1024>;
575 def SI_INDIRECT_DST_V1 : SI_INDIRECT_DST<VGPR_32>;
576 def SI_INDIRECT_DST_V2 : SI_INDIRECT_DST<VReg_64>;
577 def SI_INDIRECT_DST_V4 : SI_INDIRECT_DST<VReg_128>;
578 def SI_INDIRECT_DST_V8 : SI_INDIRECT_DST<VReg_256>;
579 def SI_INDIRECT_DST_V16 : SI_INDIRECT_DST<VReg_512>;
580 def SI_INDIRECT_DST_V32 : SI_INDIRECT_DST<VReg_1024>;
582 } // End Uses = [EXEC], Defs = [M0, EXEC]
584 // This is a pseudo variant of the v_movreld_b32 instruction in which the
585 // vector operand appears only twice, once as def and once as use. Using this
586 // pseudo avoids problems with the Two Address instructions pass.
587 class INDIRECT_REG_WRITE_MOVREL_pseudo<RegisterClass rc,
588 RegisterOperand val_ty> : PseudoInstSI <
589 (outs rc:$vdst), (ins rc:$vsrc, val_ty:$val, i32imm:$subreg)> {
590 let Constraints = "$vsrc = $vdst";
594 class V_INDIRECT_REG_WRITE_MOVREL_B32_pseudo<RegisterClass rc> :
595 INDIRECT_REG_WRITE_MOVREL_pseudo<rc, VSrc_b32> {
598 let Uses = [M0, EXEC];
601 class S_INDIRECT_REG_WRITE_MOVREL_pseudo<RegisterClass rc,
602 RegisterOperand val_ty> :
603 INDIRECT_REG_WRITE_MOVREL_pseudo<rc, val_ty> {
609 class S_INDIRECT_REG_WRITE_MOVREL_B32_pseudo<RegisterClass rc> :
610 S_INDIRECT_REG_WRITE_MOVREL_pseudo<rc, SSrc_b32>;
611 class S_INDIRECT_REG_WRITE_MOVREL_B64_pseudo<RegisterClass rc> :
612 S_INDIRECT_REG_WRITE_MOVREL_pseudo<rc, SSrc_b64>;
614 def V_INDIRECT_REG_WRITE_MOVREL_B32_V1 : V_INDIRECT_REG_WRITE_MOVREL_B32_pseudo<VGPR_32>;
615 def V_INDIRECT_REG_WRITE_MOVREL_B32_V2 : V_INDIRECT_REG_WRITE_MOVREL_B32_pseudo<VReg_64>;
616 def V_INDIRECT_REG_WRITE_MOVREL_B32_V3 : V_INDIRECT_REG_WRITE_MOVREL_B32_pseudo<VReg_96>;
617 def V_INDIRECT_REG_WRITE_MOVREL_B32_V4 : V_INDIRECT_REG_WRITE_MOVREL_B32_pseudo<VReg_128>;
618 def V_INDIRECT_REG_WRITE_MOVREL_B32_V5 : V_INDIRECT_REG_WRITE_MOVREL_B32_pseudo<VReg_160>;
619 def V_INDIRECT_REG_WRITE_MOVREL_B32_V8 : V_INDIRECT_REG_WRITE_MOVREL_B32_pseudo<VReg_256>;
620 def V_INDIRECT_REG_WRITE_MOVREL_B32_V16 : V_INDIRECT_REG_WRITE_MOVREL_B32_pseudo<VReg_512>;
621 def V_INDIRECT_REG_WRITE_MOVREL_B32_V32 : V_INDIRECT_REG_WRITE_MOVREL_B32_pseudo<VReg_1024>;
623 def S_INDIRECT_REG_WRITE_MOVREL_B32_V1 : S_INDIRECT_REG_WRITE_MOVREL_B32_pseudo<SReg_32>;
624 def S_INDIRECT_REG_WRITE_MOVREL_B32_V2 : S_INDIRECT_REG_WRITE_MOVREL_B32_pseudo<SReg_64>;
625 def S_INDIRECT_REG_WRITE_MOVREL_B32_V3 : S_INDIRECT_REG_WRITE_MOVREL_B32_pseudo<SReg_96>;
626 def S_INDIRECT_REG_WRITE_MOVREL_B32_V4 : S_INDIRECT_REG_WRITE_MOVREL_B32_pseudo<SReg_128>;
627 def S_INDIRECT_REG_WRITE_MOVREL_B32_V5 : S_INDIRECT_REG_WRITE_MOVREL_B32_pseudo<SReg_160>;
628 def S_INDIRECT_REG_WRITE_MOVREL_B32_V8 : S_INDIRECT_REG_WRITE_MOVREL_B32_pseudo<SReg_256>;
629 def S_INDIRECT_REG_WRITE_MOVREL_B32_V16 : S_INDIRECT_REG_WRITE_MOVREL_B32_pseudo<SReg_512>;
630 def S_INDIRECT_REG_WRITE_MOVREL_B32_V32 : S_INDIRECT_REG_WRITE_MOVREL_B32_pseudo<SReg_1024>;
632 def S_INDIRECT_REG_WRITE_MOVREL_B64_V1 : S_INDIRECT_REG_WRITE_MOVREL_B64_pseudo<SReg_64>;
633 def S_INDIRECT_REG_WRITE_MOVREL_B64_V2 : S_INDIRECT_REG_WRITE_MOVREL_B64_pseudo<SReg_128>;
634 def S_INDIRECT_REG_WRITE_MOVREL_B64_V4 : S_INDIRECT_REG_WRITE_MOVREL_B64_pseudo<SReg_256>;
635 def S_INDIRECT_REG_WRITE_MOVREL_B64_V8 : S_INDIRECT_REG_WRITE_MOVREL_B64_pseudo<SReg_512>;
636 def S_INDIRECT_REG_WRITE_MOVREL_B64_V16 : S_INDIRECT_REG_WRITE_MOVREL_B64_pseudo<SReg_1024>;
638 // These variants of V_INDIRECT_REG_READ/WRITE use VGPR indexing. By using these
639 // pseudos we avoid spills or copies being inserted within indirect sequences
640 // that switch the VGPR indexing mode. Spills to accvgprs could be effected by
641 // this mode switching.
643 class V_INDIRECT_REG_WRITE_GPR_IDX_pseudo<RegisterClass rc> : PseudoInstSI <
644 (outs rc:$vdst), (ins rc:$vsrc, VSrc_b32:$val, SSrc_b32:$idx, i32imm:$subreg)> {
645 let Constraints = "$vsrc = $vdst";
647 let Uses = [M0, EXEC];
651 def V_INDIRECT_REG_WRITE_GPR_IDX_B32_V1 : V_INDIRECT_REG_WRITE_GPR_IDX_pseudo<VGPR_32>;
652 def V_INDIRECT_REG_WRITE_GPR_IDX_B32_V2 : V_INDIRECT_REG_WRITE_GPR_IDX_pseudo<VReg_64>;
653 def V_INDIRECT_REG_WRITE_GPR_IDX_B32_V3 : V_INDIRECT_REG_WRITE_GPR_IDX_pseudo<VReg_96>;
654 def V_INDIRECT_REG_WRITE_GPR_IDX_B32_V4 : V_INDIRECT_REG_WRITE_GPR_IDX_pseudo<VReg_128>;
655 def V_INDIRECT_REG_WRITE_GPR_IDX_B32_V5 : V_INDIRECT_REG_WRITE_GPR_IDX_pseudo<VReg_160>;
656 def V_INDIRECT_REG_WRITE_GPR_IDX_B32_V8 : V_INDIRECT_REG_WRITE_GPR_IDX_pseudo<VReg_256>;
657 def V_INDIRECT_REG_WRITE_GPR_IDX_B32_V16 : V_INDIRECT_REG_WRITE_GPR_IDX_pseudo<VReg_512>;
658 def V_INDIRECT_REG_WRITE_GPR_IDX_B32_V32 : V_INDIRECT_REG_WRITE_GPR_IDX_pseudo<VReg_1024>;
660 class V_INDIRECT_REG_READ_GPR_IDX_pseudo<RegisterClass rc> : PseudoInstSI <
661 (outs VGPR_32:$vdst), (ins rc:$vsrc, SSrc_b32:$idx, i32imm:$subreg)> {
663 let Uses = [M0, EXEC];
667 def V_INDIRECT_REG_READ_GPR_IDX_B32_V1 : V_INDIRECT_REG_READ_GPR_IDX_pseudo<VGPR_32>;
668 def V_INDIRECT_REG_READ_GPR_IDX_B32_V2 : V_INDIRECT_REG_READ_GPR_IDX_pseudo<VReg_64>;
669 def V_INDIRECT_REG_READ_GPR_IDX_B32_V3 : V_INDIRECT_REG_READ_GPR_IDX_pseudo<VReg_96>;
670 def V_INDIRECT_REG_READ_GPR_IDX_B32_V4 : V_INDIRECT_REG_READ_GPR_IDX_pseudo<VReg_128>;
671 def V_INDIRECT_REG_READ_GPR_IDX_B32_V5 : V_INDIRECT_REG_READ_GPR_IDX_pseudo<VReg_160>;
672 def V_INDIRECT_REG_READ_GPR_IDX_B32_V8 : V_INDIRECT_REG_READ_GPR_IDX_pseudo<VReg_256>;
673 def V_INDIRECT_REG_READ_GPR_IDX_B32_V16 : V_INDIRECT_REG_READ_GPR_IDX_pseudo<VReg_512>;
674 def V_INDIRECT_REG_READ_GPR_IDX_B32_V32 : V_INDIRECT_REG_READ_GPR_IDX_pseudo<VReg_1024>;
676 multiclass SI_SPILL_SGPR <RegisterClass sgpr_class> {
677 let UseNamedOperandTable = 1, SGPRSpill = 1, Uses = [EXEC] in {
678 def _SAVE : PseudoInstSI <
680 (ins sgpr_class:$data, i32imm:$addr)> {
685 def _RESTORE : PseudoInstSI <
686 (outs sgpr_class:$data),
687 (ins i32imm:$addr)> {
691 } // End UseNamedOperandTable = 1
694 // You cannot use M0 as the output of v_readlane_b32 instructions or
695 // use it in the sdata operand of SMEM instructions. We still need to
696 // be able to spill the physical register m0, so allow it for
697 // SI_SPILL_32_* instructions.
698 defm SI_SPILL_S32 : SI_SPILL_SGPR <SReg_32>;
699 defm SI_SPILL_S64 : SI_SPILL_SGPR <SReg_64>;
700 defm SI_SPILL_S96 : SI_SPILL_SGPR <SReg_96>;
701 defm SI_SPILL_S128 : SI_SPILL_SGPR <SReg_128>;
702 defm SI_SPILL_S160 : SI_SPILL_SGPR <SReg_160>;
703 defm SI_SPILL_S192 : SI_SPILL_SGPR <SReg_192>;
704 defm SI_SPILL_S224 : SI_SPILL_SGPR <SReg_224>;
705 defm SI_SPILL_S256 : SI_SPILL_SGPR <SReg_256>;
706 defm SI_SPILL_S512 : SI_SPILL_SGPR <SReg_512>;
707 defm SI_SPILL_S1024 : SI_SPILL_SGPR <SReg_1024>;
709 // VGPR or AGPR spill instructions. In case of AGPR spilling a temp register
710 // needs to be used and an extra instruction to move between VGPR and AGPR.
711 // UsesTmp adds to the total size of an expanded spill in this case.
712 multiclass SI_SPILL_VGPR <RegisterClass vgpr_class, bit UsesTmp = 0> {
713 let UseNamedOperandTable = 1, VGPRSpill = 1,
714 SchedRW = [WriteVMEM] in {
715 def _SAVE : VPseudoInstSI <
717 (ins vgpr_class:$vdata, i32imm:$vaddr,
718 SReg_32:$soffset, i32imm:$offset)> {
721 // (2 * 4) + (8 * num_subregs) bytes maximum
722 int MaxSize = !add(!shl(!srl(vgpr_class.Size, 5), !add(UsesTmp, 3)), 8);
723 // Size field is unsigned char and cannot fit more.
724 let Size = !if(!le(MaxSize, 256), MaxSize, 252);
727 def _RESTORE : VPseudoInstSI <
728 (outs vgpr_class:$vdata),
730 SReg_32:$soffset, i32imm:$offset)> {
734 // (2 * 4) + (8 * num_subregs) bytes maximum
735 int MaxSize = !add(!shl(!srl(vgpr_class.Size, 5), !add(UsesTmp, 3)), 8);
736 // Size field is unsigned char and cannot fit more.
737 let Size = !if(!le(MaxSize, 256), MaxSize, 252);
739 } // End UseNamedOperandTable = 1, VGPRSpill = 1, SchedRW = [WriteVMEM]
742 defm SI_SPILL_V32 : SI_SPILL_VGPR <VGPR_32>;
743 defm SI_SPILL_V64 : SI_SPILL_VGPR <VReg_64>;
744 defm SI_SPILL_V96 : SI_SPILL_VGPR <VReg_96>;
745 defm SI_SPILL_V128 : SI_SPILL_VGPR <VReg_128>;
746 defm SI_SPILL_V160 : SI_SPILL_VGPR <VReg_160>;
747 defm SI_SPILL_V192 : SI_SPILL_VGPR <VReg_192>;
748 defm SI_SPILL_V224 : SI_SPILL_VGPR <VReg_224>;
749 defm SI_SPILL_V256 : SI_SPILL_VGPR <VReg_256>;
750 defm SI_SPILL_V512 : SI_SPILL_VGPR <VReg_512>;
751 defm SI_SPILL_V1024 : SI_SPILL_VGPR <VReg_1024>;
753 defm SI_SPILL_A32 : SI_SPILL_VGPR <AGPR_32, 1>;
754 defm SI_SPILL_A64 : SI_SPILL_VGPR <AReg_64, 1>;
755 defm SI_SPILL_A96 : SI_SPILL_VGPR <AReg_96, 1>;
756 defm SI_SPILL_A128 : SI_SPILL_VGPR <AReg_128, 1>;
757 defm SI_SPILL_A160 : SI_SPILL_VGPR <AReg_160, 1>;
758 defm SI_SPILL_A192 : SI_SPILL_VGPR <AReg_192, 1>;
759 defm SI_SPILL_A224 : SI_SPILL_VGPR <AReg_224, 1>;
760 defm SI_SPILL_A256 : SI_SPILL_VGPR <AReg_256, 1>;
761 defm SI_SPILL_A512 : SI_SPILL_VGPR <AReg_512, 1>;
762 defm SI_SPILL_A1024 : SI_SPILL_VGPR <AReg_1024, 1>;
764 def SI_PC_ADD_REL_OFFSET : SPseudoInstSI <
766 (ins si_ga:$ptr_lo, si_ga:$ptr_hi),
768 (i64 (SIpc_add_rel_offset tglobaladdr:$ptr_lo, tglobaladdr:$ptr_hi)))]> {
773 (SIpc_add_rel_offset tglobaladdr:$ptr_lo, 0),
774 (SI_PC_ADD_REL_OFFSET $ptr_lo, (i32 0))
778 (AMDGPUtrap timm:$trapid),
783 (AMDGPUelse i1:$src, bb:$target),
784 (SI_ELSE $src, $target)
788 (int_amdgcn_kill i1:$src),
789 (SI_KILL_I1_PSEUDO SCSrc_i1:$src, 0)
793 (int_amdgcn_kill (i1 (not i1:$src))),
794 (SI_KILL_I1_PSEUDO SCSrc_i1:$src, -1)
798 (int_amdgcn_kill (i1 (setcc f32:$src, InlineImmFP32:$imm, cond:$cond))),
799 (SI_KILL_F32_COND_IMM_PSEUDO VSrc_b32:$src, (bitcast_fpimm_to_i32 $imm), (cond_as_i32imm $cond))
803 (int_amdgcn_wqm_demote i1:$src),
804 (SI_DEMOTE_I1 SCSrc_i1:$src, 0)
808 (int_amdgcn_wqm_demote (i1 (not i1:$src))),
809 (SI_DEMOTE_I1 SCSrc_i1:$src, -1)
812 // TODO: we could add more variants for other types of conditionals
815 (i64 (int_amdgcn_icmp i1:$src, (i1 0), (i32 33))),
816 (COPY $src) // Return the SGPRs representing i1 src
820 (i32 (int_amdgcn_icmp i1:$src, (i1 0), (i32 33))),
821 (COPY $src) // Return the SGPRs representing i1 src
824 //===----------------------------------------------------------------------===//
826 //===----------------------------------------------------------------------===//
828 let OtherPredicates = [UnsafeFPMath] in {
830 //defm : RsqPat<V_RSQ_F32_e32, f32>;
832 def : RsqPat<V_RSQ_F32_e32, f32>;
834 // Convert (x - floor(x)) to fract(x)
836 (f32 (fsub (f32 (VOP3Mods f32:$x, i32:$mods)),
837 (f32 (ffloor (f32 (VOP3Mods f32:$x, i32:$mods)))))),
838 (V_FRACT_F32_e64 $mods, $x)
841 // Convert (x + (-floor(x))) to fract(x)
843 (f64 (fadd (f64 (VOP3Mods f64:$x, i32:$mods)),
844 (f64 (fneg (f64 (ffloor (f64 (VOP3Mods f64:$x, i32:$mods)))))))),
845 (V_FRACT_F64_e64 $mods, $x)
848 } // End OtherPredicates = [UnsafeFPMath]
851 // f16_to_fp patterns
853 (f32 (f16_to_fp i32:$src0)),
854 (V_CVT_F32_F16_e64 SRCMODS.NONE, $src0)
858 (f32 (f16_to_fp (and_oneuse i32:$src0, 0x7fff))),
859 (V_CVT_F32_F16_e64 SRCMODS.ABS, $src0)
863 (f32 (f16_to_fp (i32 (srl_oneuse (and_oneuse i32:$src0, 0x7fff0000), (i32 16))))),
864 (V_CVT_F32_F16_e64 SRCMODS.ABS, (i32 (V_LSHRREV_B32_e64 (i32 16), i32:$src0)))
868 (f32 (f16_to_fp (or_oneuse i32:$src0, 0x8000))),
869 (V_CVT_F32_F16_e64 SRCMODS.NEG_ABS, $src0)
873 (f32 (f16_to_fp (xor_oneuse i32:$src0, 0x8000))),
874 (V_CVT_F32_F16_e64 SRCMODS.NEG, $src0)
878 (f64 (fpextend f16:$src)),
879 (V_CVT_F64_F32_e32 (V_CVT_F32_F16_e32 $src))
882 // fp_to_fp16 patterns
884 (i32 (AMDGPUfp_to_f16 (f32 (VOP3Mods f32:$src0, i32:$src0_modifiers)))),
885 (V_CVT_F16_F32_e64 $src0_modifiers, f32:$src0)
889 (i32 (fp_to_sint f16:$src)),
890 (V_CVT_I32_F32_e32 (V_CVT_F32_F16_e32 VSrc_b32:$src))
894 (i32 (fp_to_uint f16:$src)),
895 (V_CVT_U32_F32_e32 (V_CVT_F32_F16_e32 VSrc_b32:$src))
899 (f16 (sint_to_fp i32:$src)),
900 (V_CVT_F16_F32_e32 (V_CVT_F32_I32_e32 VSrc_b32:$src))
904 (f16 (uint_to_fp i32:$src)),
905 (V_CVT_F16_F32_e32 (V_CVT_F32_U32_e32 VSrc_b32:$src))
908 //===----------------------------------------------------------------------===//
910 //===----------------------------------------------------------------------===//
912 // NoMods pattern used for mac. If there are any source modifiers then it's
913 // better to select mad instead of mac.
914 class FMADPat <ValueType vt, Instruction inst, SDPatternOperator node>
915 : GCNPat <(vt (node (vt (VOP3NoMods vt:$src0)),
916 (vt (VOP3NoMods vt:$src1)),
917 (vt (VOP3NoMods vt:$src2)))),
918 (inst SRCMODS.NONE, $src0, SRCMODS.NONE, $src1,
919 SRCMODS.NONE, $src2, DSTCLAMP.NONE, DSTOMOD.NONE)
922 // Prefer mac form when there are no modifiers.
923 let AddedComplexity = 9 in {
924 let OtherPredicates = [HasMadMacF32Insts] in {
925 def : FMADPat <f32, V_MAC_F32_e64, fmad>;
926 def : FMADPat <f32, V_MAC_F32_e64, AMDGPUfmad_ftz>;
927 } // OtherPredicates = [HasMadMacF32Insts]
929 // Don't allow source modifiers. If there are any source modifiers then it's
930 // better to select mad instead of mac.
931 let SubtargetPredicate = isGFX6GFX7GFX10,
932 OtherPredicates = [HasMadMacF32Insts, NoFP32Denormals] in
934 (f32 (fadd (AMDGPUfmul_legacy (VOP3NoMods f32:$src0),
935 (VOP3NoMods f32:$src1)),
936 (VOP3NoMods f32:$src2))),
937 (V_MAC_LEGACY_F32_e64 SRCMODS.NONE, $src0, SRCMODS.NONE, $src1,
938 SRCMODS.NONE, $src2, DSTCLAMP.NONE, DSTOMOD.NONE)
941 // Don't allow source modifiers. If there are any source modifiers then it's
942 // better to select fma instead of fmac.
943 let SubtargetPredicate = HasFmaLegacy32 in
945 (f32 (int_amdgcn_fma_legacy (VOP3NoMods f32:$src0),
946 (VOP3NoMods f32:$src1),
947 (VOP3NoMods f32:$src2))),
948 (V_FMAC_LEGACY_F32_e64 SRCMODS.NONE, $src0, SRCMODS.NONE, $src1,
949 SRCMODS.NONE, $src2, DSTCLAMP.NONE, DSTOMOD.NONE)
952 let SubtargetPredicate = Has16BitInsts in {
953 def : FMADPat <f16, V_MAC_F16_e64, fmad>;
954 def : FMADPat <f16, V_MAC_F16_e64, AMDGPUfmad_ftz>;
955 } // SubtargetPredicate = Has16BitInsts
956 } // AddedComplexity = 9
958 class FMADModsPat<ValueType Ty, Instruction inst, SDPatternOperator mad_opr>
960 (Ty (mad_opr (Ty (VOP3Mods Ty:$src0, i32:$src0_mod)),
961 (Ty (VOP3Mods Ty:$src1, i32:$src1_mod)),
962 (Ty (VOP3Mods Ty:$src2, i32:$src2_mod)))),
963 (inst $src0_mod, $src0, $src1_mod, $src1,
964 $src2_mod, $src2, DSTCLAMP.NONE, DSTOMOD.NONE)
967 let OtherPredicates = [HasMadMacF32Insts] in
968 def : FMADModsPat<f32, V_MAD_F32_e64, AMDGPUfmad_ftz>;
970 let OtherPredicates = [HasMadMacF32Insts, NoFP32Denormals] in
972 (f32 (fadd (AMDGPUfmul_legacy (VOP3Mods f32:$src0, i32:$src0_mod),
973 (VOP3Mods f32:$src1, i32:$src1_mod)),
974 (VOP3Mods f32:$src2, i32:$src2_mod))),
975 (V_MAD_LEGACY_F32_e64 $src0_mod, $src0, $src1_mod, $src1,
976 $src2_mod, $src2, DSTCLAMP.NONE, DSTOMOD.NONE)
979 let SubtargetPredicate = Has16BitInsts in
980 def : FMADModsPat<f16, V_MAD_F16_e64, AMDGPUfmad_ftz>;
982 class VOPSelectModsPat <ValueType vt> : GCNPat <
983 (vt (select i1:$src0, (VOP3Mods vt:$src1, i32:$src1_mods),
984 (VOP3Mods vt:$src2, i32:$src2_mods))),
985 (V_CNDMASK_B32_e64 FP32InputMods:$src2_mods, VSrc_b32:$src2,
986 FP32InputMods:$src1_mods, VSrc_b32:$src1, SSrc_i1:$src0)
989 class VOPSelectPat <ValueType vt> : GCNPat <
990 (vt (select i1:$src0, vt:$src1, vt:$src2)),
991 (V_CNDMASK_B32_e64 0, VSrc_b32:$src2, 0, VSrc_b32:$src1, SSrc_i1:$src0)
994 def : VOPSelectModsPat <i32>;
995 def : VOPSelectModsPat <f32>;
996 def : VOPSelectPat <f16>;
997 def : VOPSelectPat <i16>;
999 let AddedComplexity = 1 in {
1001 (i32 (add (i32 (getDivergentFrag<ctpop>.ret i32:$popcnt)), i32:$val)),
1002 (V_BCNT_U32_B32_e64 $popcnt, $val)
1007 (i32 (ctpop i32:$popcnt)),
1008 (V_BCNT_U32_B32_e64 VSrc_b32:$popcnt, (i32 0))
1012 (i16 (add (i16 (trunc (i32 (getDivergentFrag<ctpop>.ret i32:$popcnt)))), i16:$val)),
1013 (V_BCNT_U32_B32_e64 $popcnt, $val)
1016 /********** ============================================ **********/
1017 /********** Extraction, Insertion, Building and Casting **********/
1018 /********** ============================================ **********/
1020 // Special case for 2 element vectors. REQ_SEQUENCE produces better code
1021 // than an INSERT_SUBREG.
1022 multiclass Insert_Element_V2<RegisterClass RC, ValueType elem_type, ValueType vec_type> {
1024 (insertelt vec_type:$vec, elem_type:$elem, 0),
1025 (REG_SEQUENCE RC, $elem, sub0, (elem_type (EXTRACT_SUBREG $vec, sub1)), sub1)
1029 (insertelt vec_type:$vec, elem_type:$elem, 1),
1030 (REG_SEQUENCE RC, (elem_type (EXTRACT_SUBREG $vec, sub0)), sub0, $elem, sub1)
1034 foreach Index = 0-1 in {
1035 def Extract_Element_v2i32_#Index : Extract_Element <
1036 i32, v2i32, Index, !cast<SubRegIndex>(sub#Index)
1039 def Extract_Element_v2f32_#Index : Extract_Element <
1040 f32, v2f32, Index, !cast<SubRegIndex>(sub#Index)
1044 defm : Insert_Element_V2 <SReg_64, i32, v2i32>;
1045 defm : Insert_Element_V2 <SReg_64, f32, v2f32>;
1047 foreach Index = 0-2 in {
1048 def Extract_Element_v3i32_#Index : Extract_Element <
1049 i32, v3i32, Index, !cast<SubRegIndex>(sub#Index)
1051 def Insert_Element_v3i32_#Index : Insert_Element <
1052 i32, v3i32, Index, !cast<SubRegIndex>(sub#Index)
1055 def Extract_Element_v3f32_#Index : Extract_Element <
1056 f32, v3f32, Index, !cast<SubRegIndex>(sub#Index)
1058 def Insert_Element_v3f32_#Index : Insert_Element <
1059 f32, v3f32, Index, !cast<SubRegIndex>(sub#Index)
1063 foreach Index = 0-3 in {
1064 def Extract_Element_v4i32_#Index : Extract_Element <
1065 i32, v4i32, Index, !cast<SubRegIndex>(sub#Index)
1067 def Insert_Element_v4i32_#Index : Insert_Element <
1068 i32, v4i32, Index, !cast<SubRegIndex>(sub#Index)
1071 def Extract_Element_v4f32_#Index : Extract_Element <
1072 f32, v4f32, Index, !cast<SubRegIndex>(sub#Index)
1074 def Insert_Element_v4f32_#Index : Insert_Element <
1075 f32, v4f32, Index, !cast<SubRegIndex>(sub#Index)
1079 foreach Index = 0-4 in {
1080 def Extract_Element_v5i32_#Index : Extract_Element <
1081 i32, v5i32, Index, !cast<SubRegIndex>(sub#Index)
1083 def Insert_Element_v5i32_#Index : Insert_Element <
1084 i32, v5i32, Index, !cast<SubRegIndex>(sub#Index)
1087 def Extract_Element_v5f32_#Index : Extract_Element <
1088 f32, v5f32, Index, !cast<SubRegIndex>(sub#Index)
1090 def Insert_Element_v5f32_#Index : Insert_Element <
1091 f32, v5f32, Index, !cast<SubRegIndex>(sub#Index)
1095 foreach Index = 0-5 in {
1096 def Extract_Element_v6i32_#Index : Extract_Element <
1097 i32, v6i32, Index, !cast<SubRegIndex>(sub#Index)
1099 def Insert_Element_v6i32_#Index : Insert_Element <
1100 i32, v6i32, Index, !cast<SubRegIndex>(sub#Index)
1103 def Extract_Element_v6f32_#Index : Extract_Element <
1104 f32, v6f32, Index, !cast<SubRegIndex>(sub#Index)
1106 def Insert_Element_v6f32_#Index : Insert_Element <
1107 f32, v6f32, Index, !cast<SubRegIndex>(sub#Index)
1111 foreach Index = 0-6 in {
1112 def Extract_Element_v7i32_#Index : Extract_Element <
1113 i32, v7i32, Index, !cast<SubRegIndex>(sub#Index)
1115 def Insert_Element_v7i32_#Index : Insert_Element <
1116 i32, v7i32, Index, !cast<SubRegIndex>(sub#Index)
1119 def Extract_Element_v7f32_#Index : Extract_Element <
1120 f32, v7f32, Index, !cast<SubRegIndex>(sub#Index)
1122 def Insert_Element_v7f32_#Index : Insert_Element <
1123 f32, v7f32, Index, !cast<SubRegIndex>(sub#Index)
1127 foreach Index = 0-7 in {
1128 def Extract_Element_v8i32_#Index : Extract_Element <
1129 i32, v8i32, Index, !cast<SubRegIndex>(sub#Index)
1131 def Insert_Element_v8i32_#Index : Insert_Element <
1132 i32, v8i32, Index, !cast<SubRegIndex>(sub#Index)
1135 def Extract_Element_v8f32_#Index : Extract_Element <
1136 f32, v8f32, Index, !cast<SubRegIndex>(sub#Index)
1138 def Insert_Element_v8f32_#Index : Insert_Element <
1139 f32, v8f32, Index, !cast<SubRegIndex>(sub#Index)
1143 foreach Index = 0-15 in {
1144 def Extract_Element_v16i32_#Index : Extract_Element <
1145 i32, v16i32, Index, !cast<SubRegIndex>(sub#Index)
1147 def Insert_Element_v16i32_#Index : Insert_Element <
1148 i32, v16i32, Index, !cast<SubRegIndex>(sub#Index)
1151 def Extract_Element_v16f32_#Index : Extract_Element <
1152 f32, v16f32, Index, !cast<SubRegIndex>(sub#Index)
1154 def Insert_Element_v16f32_#Index : Insert_Element <
1155 f32, v16f32, Index, !cast<SubRegIndex>(sub#Index)
1161 (extract_subvector v4i16:$vec, (i32 0)),
1162 (v2i16 (EXTRACT_SUBREG v4i16:$vec, sub0))
1166 (extract_subvector v4i16:$vec, (i32 2)),
1167 (v2i16 (EXTRACT_SUBREG v4i16:$vec, sub1))
1171 (extract_subvector v4f16:$vec, (i32 0)),
1172 (v2f16 (EXTRACT_SUBREG v4f16:$vec, sub0))
1176 (extract_subvector v4f16:$vec, (i32 2)),
1177 (v2f16 (EXTRACT_SUBREG v4f16:$vec, sub1))
1180 foreach Index = 0-31 in {
1181 def Extract_Element_v32i32_#Index : Extract_Element <
1182 i32, v32i32, Index, !cast<SubRegIndex>(sub#Index)
1185 def Insert_Element_v32i32_#Index : Insert_Element <
1186 i32, v32i32, Index, !cast<SubRegIndex>(sub#Index)
1189 def Extract_Element_v32f32_#Index : Extract_Element <
1190 f32, v32f32, Index, !cast<SubRegIndex>(sub#Index)
1193 def Insert_Element_v32f32_#Index : Insert_Element <
1194 f32, v32f32, Index, !cast<SubRegIndex>(sub#Index)
1198 // FIXME: Why do only some of these type combinations for SReg and
1201 def : BitConvert <i16, f16, VGPR_32>;
1202 def : BitConvert <f16, i16, VGPR_32>;
1203 def : BitConvert <i16, f16, SReg_32>;
1204 def : BitConvert <f16, i16, SReg_32>;
1207 def : BitConvert <i32, f32, VGPR_32>;
1208 def : BitConvert <f32, i32, VGPR_32>;
1209 def : BitConvert <i32, f32, SReg_32>;
1210 def : BitConvert <f32, i32, SReg_32>;
1211 def : BitConvert <v2i16, i32, SReg_32>;
1212 def : BitConvert <i32, v2i16, SReg_32>;
1213 def : BitConvert <v2f16, i32, SReg_32>;
1214 def : BitConvert <i32, v2f16, SReg_32>;
1215 def : BitConvert <v2i16, v2f16, SReg_32>;
1216 def : BitConvert <v2f16, v2i16, SReg_32>;
1217 def : BitConvert <v2f16, f32, SReg_32>;
1218 def : BitConvert <f32, v2f16, SReg_32>;
1219 def : BitConvert <v2i16, f32, SReg_32>;
1220 def : BitConvert <f32, v2i16, SReg_32>;
1223 def : BitConvert <i64, f64, VReg_64>;
1224 def : BitConvert <f64, i64, VReg_64>;
1225 def : BitConvert <v2i32, v2f32, VReg_64>;
1226 def : BitConvert <v2f32, v2i32, VReg_64>;
1227 def : BitConvert <i64, v2i32, VReg_64>;
1228 def : BitConvert <v2i32, i64, VReg_64>;
1229 def : BitConvert <i64, v2f32, VReg_64>;
1230 def : BitConvert <v2f32, i64, VReg_64>;
1231 def : BitConvert <f64, v2f32, VReg_64>;
1232 def : BitConvert <v2f32, f64, VReg_64>;
1233 def : BitConvert <f64, v2i32, VReg_64>;
1234 def : BitConvert <v2i32, f64, VReg_64>;
1235 def : BitConvert <v4i16, v4f16, VReg_64>;
1236 def : BitConvert <v4f16, v4i16, VReg_64>;
1239 def : BitConvert <v2i32, v4f16, VReg_64>;
1240 def : BitConvert <v4f16, v2i32, VReg_64>;
1241 def : BitConvert <v2i32, v4f16, VReg_64>;
1242 def : BitConvert <v2i32, v4i16, VReg_64>;
1243 def : BitConvert <v4i16, v2i32, VReg_64>;
1244 def : BitConvert <v2f32, v4f16, VReg_64>;
1245 def : BitConvert <v4f16, v2f32, VReg_64>;
1246 def : BitConvert <v2f32, v4i16, VReg_64>;
1247 def : BitConvert <v4i16, v2f32, VReg_64>;
1248 def : BitConvert <v4i16, f64, VReg_64>;
1249 def : BitConvert <v4f16, f64, VReg_64>;
1250 def : BitConvert <f64, v4i16, VReg_64>;
1251 def : BitConvert <f64, v4f16, VReg_64>;
1252 def : BitConvert <v4i16, i64, VReg_64>;
1253 def : BitConvert <v4f16, i64, VReg_64>;
1254 def : BitConvert <i64, v4i16, VReg_64>;
1255 def : BitConvert <i64, v4f16, VReg_64>;
1257 def : BitConvert <v4i32, v4f32, VReg_128>;
1258 def : BitConvert <v4f32, v4i32, VReg_128>;
1261 def : BitConvert <v3i32, v3f32, SGPR_96>;
1262 def : BitConvert <v3f32, v3i32, SGPR_96>;
1265 def : BitConvert <v2i64, v4i32, SReg_128>;
1266 def : BitConvert <v4i32, v2i64, SReg_128>;
1267 def : BitConvert <v2f64, v4f32, VReg_128>;
1268 def : BitConvert <v2f64, v4i32, VReg_128>;
1269 def : BitConvert <v4f32, v2f64, VReg_128>;
1270 def : BitConvert <v4i32, v2f64, VReg_128>;
1271 def : BitConvert <v2i64, v2f64, VReg_128>;
1272 def : BitConvert <v2f64, v2i64, VReg_128>;
1273 def : BitConvert <v4f32, v2i64, VReg_128>;
1274 def : BitConvert <v2i64, v4f32, VReg_128>;
1277 def : BitConvert <v5i32, v5f32, SReg_160>;
1278 def : BitConvert <v5f32, v5i32, SReg_160>;
1279 def : BitConvert <v5i32, v5f32, VReg_160>;
1280 def : BitConvert <v5f32, v5i32, VReg_160>;
1283 def : BitConvert <v6i32, v6f32, SReg_192>;
1284 def : BitConvert <v6f32, v6i32, SReg_192>;
1285 def : BitConvert <v6i32, v6f32, VReg_192>;
1286 def : BitConvert <v6f32, v6i32, VReg_192>;
1287 def : BitConvert <v3i64, v3f64, VReg_192>;
1288 def : BitConvert <v3f64, v3i64, VReg_192>;
1289 def : BitConvert <v3i64, v6i32, VReg_192>;
1290 def : BitConvert <v3i64, v6f32, VReg_192>;
1291 def : BitConvert <v3f64, v6i32, VReg_192>;
1292 def : BitConvert <v3f64, v6f32, VReg_192>;
1293 def : BitConvert <v6i32, v3i64, VReg_192>;
1294 def : BitConvert <v6f32, v3i64, VReg_192>;
1295 def : BitConvert <v6i32, v3f64, VReg_192>;
1296 def : BitConvert <v6f32, v3f64, VReg_192>;
1299 def : BitConvert <v7i32, v7f32, SReg_224>;
1300 def : BitConvert <v7f32, v7i32, SReg_224>;
1301 def : BitConvert <v7i32, v7f32, VReg_224>;
1302 def : BitConvert <v7f32, v7i32, VReg_224>;
1305 def : BitConvert <v8i32, v8f32, SReg_256>;
1306 def : BitConvert <v8f32, v8i32, SReg_256>;
1307 def : BitConvert <v8i32, v8f32, VReg_256>;
1308 def : BitConvert <v8f32, v8i32, VReg_256>;
1309 def : BitConvert <v4i64, v4f64, VReg_256>;
1310 def : BitConvert <v4f64, v4i64, VReg_256>;
1311 def : BitConvert <v4i64, v8i32, VReg_256>;
1312 def : BitConvert <v4i64, v8f32, VReg_256>;
1313 def : BitConvert <v4f64, v8i32, VReg_256>;
1314 def : BitConvert <v4f64, v8f32, VReg_256>;
1315 def : BitConvert <v8i32, v4i64, VReg_256>;
1316 def : BitConvert <v8f32, v4i64, VReg_256>;
1317 def : BitConvert <v8i32, v4f64, VReg_256>;
1318 def : BitConvert <v8f32, v4f64, VReg_256>;
1322 def : BitConvert <v16i32, v16f32, VReg_512>;
1323 def : BitConvert <v16f32, v16i32, VReg_512>;
1324 def : BitConvert <v8i64, v8f64, VReg_512>;
1325 def : BitConvert <v8f64, v8i64, VReg_512>;
1326 def : BitConvert <v8i64, v16i32, VReg_512>;
1327 def : BitConvert <v8f64, v16i32, VReg_512>;
1328 def : BitConvert <v16i32, v8i64, VReg_512>;
1329 def : BitConvert <v16i32, v8f64, VReg_512>;
1330 def : BitConvert <v8i64, v16f32, VReg_512>;
1331 def : BitConvert <v8f64, v16f32, VReg_512>;
1332 def : BitConvert <v16f32, v8i64, VReg_512>;
1333 def : BitConvert <v16f32, v8f64, VReg_512>;
1336 def : BitConvert <v32i32, v32f32, VReg_1024>;
1337 def : BitConvert <v32f32, v32i32, VReg_1024>;
1338 def : BitConvert <v16i64, v16f64, VReg_1024>;
1339 def : BitConvert <v16f64, v16i64, VReg_1024>;
1340 def : BitConvert <v16i64, v32i32, VReg_1024>;
1341 def : BitConvert <v32i32, v16i64, VReg_1024>;
1342 def : BitConvert <v16f64, v32f32, VReg_1024>;
1343 def : BitConvert <v32f32, v16f64, VReg_1024>;
1344 def : BitConvert <v16i64, v32f32, VReg_1024>;
1345 def : BitConvert <v32i32, v16f64, VReg_1024>;
1346 def : BitConvert <v16f64, v32i32, VReg_1024>;
1347 def : BitConvert <v32f32, v16i64, VReg_1024>;
1350 /********** =================== **********/
1351 /********** Src & Dst modifiers **********/
1352 /********** =================== **********/
1355 // If denormals are not enabled, it only impacts the compare of the
1356 // inputs. The output result is not flushed.
1357 class ClampPat<Instruction inst, ValueType vt> : GCNPat <
1358 (vt (AMDGPUclamp (VOP3Mods vt:$src0, i32:$src0_modifiers))),
1359 (inst i32:$src0_modifiers, vt:$src0,
1360 i32:$src0_modifiers, vt:$src0, DSTCLAMP.ENABLE, DSTOMOD.NONE)
1363 def : ClampPat<V_MAX_F32_e64, f32>;
1364 def : ClampPat<V_MAX_F64_e64, f64>;
1365 def : ClampPat<V_MAX_F16_e64, f16>;
1367 let SubtargetPredicate = HasVOP3PInsts in {
1369 (v2f16 (AMDGPUclamp (VOP3PMods v2f16:$src0, i32:$src0_modifiers))),
1370 (V_PK_MAX_F16 $src0_modifiers, $src0,
1371 $src0_modifiers, $src0, DSTCLAMP.ENABLE)
1375 /********** ================================ **********/
1376 /********** Floating point absolute/negative **********/
1377 /********** ================================ **********/
1379 // Prevent expanding both fneg and fabs.
1380 // TODO: Add IgnoredBySelectionDAG bit?
1381 let AddedComplexity = 1 in { // Prefer SALU to VALU patterns for DAG
1384 (fneg (fabs (f32 SReg_32:$src))),
1385 (S_OR_B32 SReg_32:$src, (S_MOV_B32 (i32 0x80000000))) // Set sign bit
1389 (fabs (f32 SReg_32:$src)),
1390 (S_AND_B32 SReg_32:$src, (S_MOV_B32 (i32 0x7fffffff)))
1394 (fneg (f32 SReg_32:$src)),
1395 (S_XOR_B32 SReg_32:$src, (S_MOV_B32 (i32 0x80000000)))
1399 (fneg (f16 SReg_32:$src)),
1400 (S_XOR_B32 SReg_32:$src, (S_MOV_B32 (i32 0x00008000)))
1404 (fneg (f16 VGPR_32:$src)),
1405 (V_XOR_B32_e32 (S_MOV_B32 (i32 0x00008000)), VGPR_32:$src)
1409 (fabs (f16 SReg_32:$src)),
1410 (S_AND_B32 SReg_32:$src, (S_MOV_B32 (i32 0x00007fff)))
1414 (fneg (fabs (f16 SReg_32:$src))),
1415 (S_OR_B32 SReg_32:$src, (S_MOV_B32 (i32 0x00008000))) // Set sign bit
1419 (fneg (fabs (f16 VGPR_32:$src))),
1420 (V_OR_B32_e32 (S_MOV_B32 (i32 0x00008000)), VGPR_32:$src) // Set sign bit
1424 (fneg (v2f16 SReg_32:$src)),
1425 (S_XOR_B32 SReg_32:$src, (S_MOV_B32 (i32 0x80008000)))
1429 (fabs (v2f16 SReg_32:$src)),
1430 (S_AND_B32 SReg_32:$src, (S_MOV_B32 (i32 0x7fff7fff)))
1433 // This is really (fneg (fabs v2f16:$src))
1435 // fabs is not reported as free because there is modifier for it in
1436 // VOP3P instructions, so it is turned into the bit op.
1438 (fneg (v2f16 (bitconvert (and_oneuse (i32 SReg_32:$src), 0x7fff7fff)))),
1439 (S_OR_B32 SReg_32:$src, (S_MOV_B32 (i32 0x80008000))) // Set sign bit
1443 (fneg (v2f16 (fabs SReg_32:$src))),
1444 (S_OR_B32 SReg_32:$src, (S_MOV_B32 (i32 0x80008000))) // Set sign bit
1447 // FIXME: The implicit-def of scc from S_[X]OR/AND_B32 is mishandled
1449 // (fneg (f64 SReg_64:$src)),
1450 // (REG_SEQUENCE SReg_64,
1451 // (i32 (EXTRACT_SUBREG SReg_64:$src, sub0)),
1453 // (S_XOR_B32 (i32 (EXTRACT_SUBREG SReg_64:$src, sub1)),
1454 // (i32 (S_MOV_B32 (i32 0x80000000)))),
1459 // (fneg (fabs (f64 SReg_64:$src))),
1460 // (REG_SEQUENCE SReg_64,
1461 // (i32 (EXTRACT_SUBREG SReg_64:$src, sub0)),
1463 // (S_OR_B32 (i32 (EXTRACT_SUBREG SReg_64:$src, sub1)),
1464 // (S_MOV_B32 (i32 0x80000000))), // Set sign bit.
1468 // FIXME: Use S_BITSET0_B32/B64?
1470 // (fabs (f64 SReg_64:$src)),
1471 // (REG_SEQUENCE SReg_64,
1472 // (i32 (EXTRACT_SUBREG SReg_64:$src, sub0)),
1474 // (S_AND_B32 (i32 (EXTRACT_SUBREG SReg_64:$src, sub1)),
1475 // (i32 (S_MOV_B32 (i32 0x7fffffff)))),
1479 // COPY_TO_REGCLASS is needed to avoid using SCC from S_XOR_B32 instead
1480 // of the real value.
1482 (fneg (v2f32 SReg_64:$src)),
1483 (v2f32 (REG_SEQUENCE SReg_64,
1484 (f32 (COPY_TO_REGCLASS (S_XOR_B32 (i32 (EXTRACT_SUBREG $src, sub0)),
1485 (i32 (S_MOV_B32 (i32 0x80000000)))),
1487 (f32 (COPY_TO_REGCLASS (S_XOR_B32 (i32 (EXTRACT_SUBREG $src, sub1)),
1488 (i32 (S_MOV_B32 (i32 0x80000000)))),
1492 } // End let AddedComplexity = 1
1495 (fabs (f32 VGPR_32:$src)),
1496 (V_AND_B32_e32 (S_MOV_B32 (i32 0x7fffffff)), VGPR_32:$src)
1500 (fneg (f32 VGPR_32:$src)),
1501 (V_XOR_B32_e32 (S_MOV_B32 (i32 0x80000000)), VGPR_32:$src)
1505 (fabs (f16 VGPR_32:$src)),
1506 (V_AND_B32_e32 (S_MOV_B32 (i32 0x00007fff)), VGPR_32:$src)
1510 (fneg (v2f16 VGPR_32:$src)),
1511 (V_XOR_B32_e32 (S_MOV_B32 (i32 0x80008000)), VGPR_32:$src)
1515 (fabs (v2f16 VGPR_32:$src)),
1516 (V_AND_B32_e32 (S_MOV_B32 (i32 0x7fff7fff)), VGPR_32:$src)
1520 (fneg (v2f16 (fabs VGPR_32:$src))),
1521 (V_OR_B32_e32 (S_MOV_B32 (i32 0x80008000)), VGPR_32:$src) // Set sign bit
1525 (fabs (f64 VReg_64:$src)),
1526 (REG_SEQUENCE VReg_64,
1527 (i32 (EXTRACT_SUBREG VReg_64:$src, sub0)),
1529 (V_AND_B32_e64 (i32 (EXTRACT_SUBREG VReg_64:$src, sub1)),
1530 (V_MOV_B32_e32 (i32 0x7fffffff))), // Set sign bit.
1534 // TODO: Use SGPR for constant
1536 (fneg (f64 VReg_64:$src)),
1537 (REG_SEQUENCE VReg_64,
1538 (i32 (EXTRACT_SUBREG VReg_64:$src, sub0)),
1540 (V_XOR_B32_e32 (i32 (EXTRACT_SUBREG VReg_64:$src, sub1)),
1541 (i32 (V_MOV_B32_e32 (i32 0x80000000)))),
1545 // TODO: Use SGPR for constant
1547 (fneg (fabs (f64 VReg_64:$src))),
1548 (REG_SEQUENCE VReg_64,
1549 (i32 (EXTRACT_SUBREG VReg_64:$src, sub0)),
1551 (V_OR_B32_e32 (i32 (EXTRACT_SUBREG VReg_64:$src, sub1)),
1552 (V_MOV_B32_e32 (i32 0x80000000))), // Set sign bit.
1557 (getDivergentFrag<fneg>.ret (v2f32 VReg_64:$src)),
1558 (V_PK_ADD_F32 11 /* OP_SEL_1 | NEG_LO | HEG_HI */, VReg_64:$src,
1559 11 /* OP_SEL_1 | NEG_LO | HEG_HI */, 0,
1562 let SubtargetPredicate = HasPackedFP32Ops;
1566 (fcopysign f16:$src0, f16:$src1),
1567 (V_BFI_B32_e64 (S_MOV_B32 (i32 0x00007fff)), $src0, $src1)
1571 (fcopysign f32:$src0, f16:$src1),
1572 (V_BFI_B32_e64 (S_MOV_B32 (i32 0x7fffffff)), $src0,
1573 (V_LSHLREV_B32_e64 (i32 16), $src1))
1577 (fcopysign f64:$src0, f16:$src1),
1578 (REG_SEQUENCE SReg_64,
1579 (i32 (EXTRACT_SUBREG $src0, sub0)), sub0,
1580 (V_BFI_B32_e64 (S_MOV_B32 (i32 0x7fffffff)), (i32 (EXTRACT_SUBREG $src0, sub1)),
1581 (V_LSHLREV_B32_e64 (i32 16), $src1)), sub1)
1585 (fcopysign f16:$src0, f32:$src1),
1586 (V_BFI_B32_e64 (S_MOV_B32 (i32 0x00007fff)), $src0,
1587 (V_LSHRREV_B32_e64 (i32 16), $src1))
1591 (fcopysign f16:$src0, f64:$src1),
1592 (V_BFI_B32_e64 (S_MOV_B32 (i32 0x00007fff)), $src0,
1593 (V_LSHRREV_B32_e64 (i32 16), (EXTRACT_SUBREG $src1, sub1)))
1596 /********** ================== **********/
1597 /********** Immediate Patterns **********/
1598 /********** ================== **********/
1601 (VGPRImm<(i32 imm)>:$imm),
1602 (V_MOV_B32_e32 imm:$imm)
1606 (VGPRImm<(f32 fpimm)>:$imm),
1607 (V_MOV_B32_e32 (f32 (bitcast_fpimm_to_i32 $imm)))
1612 (S_MOV_B32 imm:$imm)
1616 (VGPRImm<(SIlds tglobaladdr:$ga)>),
1621 (SIlds tglobaladdr:$ga),
1625 // FIXME: Workaround for ordering issue with peephole optimizer where
1626 // a register class copy interferes with immediate folding. Should
1627 // use s_mov_b32, which can be shrunk to s_movk_i32
1629 (VGPRImm<(f16 fpimm)>:$imm),
1630 (V_MOV_B32_e32 (f16 (bitcast_fpimm_to_i32 $imm)))
1635 (S_MOV_B32 (f32 (bitcast_fpimm_to_i32 $imm)))
1640 (S_MOV_B32 (i32 (bitcast_fpimm_to_i32 $imm)))
1644 (p5 frameindex:$fi),
1645 (V_MOV_B32_e32 (p5 (frameindex_to_targetframeindex $fi)))
1649 (p5 frameindex:$fi),
1650 (S_MOV_B32 (p5 (frameindex_to_targetframeindex $fi)))
1654 (i64 InlineImm64:$imm),
1655 (S_MOV_B64 InlineImm64:$imm)
1658 // XXX - Should this use a s_cmp to set SCC?
1660 // Set to sign-extended 64-bit value (true = -1, false = 0)
1663 (S_MOV_B64 (i64 (as_i64imm $imm)))
1665 let WaveSizePredicate = isWave64;
1670 (S_MOV_B32 (i32 (as_i32imm $imm)))
1672 let WaveSizePredicate = isWave32;
1676 (f64 InlineImmFP64:$imm),
1677 (S_MOV_B64 (f64 (bitcast_fpimm_to_i64 InlineImmFP64:$imm)))
1680 /********** ================== **********/
1681 /********** Intrinsic Patterns **********/
1682 /********** ================== **********/
1684 let OtherPredicates = [isNotGFX90APlus] in
1685 // FIXME: Should use _e64 and select source modifiers.
1686 def : POW_Common <V_LOG_F32_e32, V_EXP_F32_e32, V_MUL_LEGACY_F32_e32>;
1688 let OtherPredicates = [isGFX90APlus] in
1690 (fpow f32:$src0, f32:$src1),
1691 (V_EXP_F32_e32 (V_MUL_LEGACY_F32_e64 0, f32:$src1, SRCMODS.NONE, (V_LOG_F32_e32 f32:$src0), 0, 0))
1695 (i32 (sext i1:$src0)),
1696 (V_CNDMASK_B32_e64 /*src0mod*/(i32 0), /*src0*/(i32 0),
1697 /*src1mod*/(i32 0), /*src1*/(i32 -1), $src0)
1700 class Ext32Pat <SDNode ext> : GCNPat <
1701 (i32 (ext i1:$src0)),
1702 (V_CNDMASK_B32_e64 /*src0mod*/(i32 0), /*src0*/(i32 0),
1703 /*src1mod*/(i32 0), /*src1*/(i32 1), $src0)
1706 def : Ext32Pat <zext>;
1707 def : Ext32Pat <anyext>;
1709 // The multiplication scales from [0,1) to the unsigned integer range,
1710 // rounding down a bit to avoid unwanted overflow.
1712 (AMDGPUurecip i32:$src0),
1714 (V_MUL_F32_e32 (i32 CONST.FP_4294966784),
1715 (V_RCP_IFLAG_F32_e32 (V_CVT_F32_U32_e32 $src0))))
1718 //===----------------------------------------------------------------------===//
1720 //===----------------------------------------------------------------------===//
1722 def : IMad24Pat<V_MAD_I32_I24_e64, 1>;
1723 def : UMad24Pat<V_MAD_U32_U24_e64, 1>;
1727 def BFIImm32 : PatFrag<
1728 (ops node:$x, node:$y, node:$z),
1729 (i32 (DivergentBinFrag<or> (and node:$y, node:$x), (and node:$z, imm))),
1731 auto *X = dyn_cast<ConstantSDNode>(N->getOperand(0)->getOperand(1));
1732 auto *NotX = dyn_cast<ConstantSDNode>(N->getOperand(1)->getOperand(1));
1734 ~(unsigned)X->getZExtValue() == (unsigned)NotX->getZExtValue();
1738 // Definition from ISA doc:
1739 // (y & x) | (z & ~x)
1741 (DivergentBinFrag<or> (and i32:$y, i32:$x), (and i32:$z, (not i32:$x))),
1742 (V_BFI_B32_e64 $x, $y, $z)
1745 // (y & C) | (z & ~C)
1747 (BFIImm32 i32:$x, i32:$y, i32:$z),
1748 (V_BFI_B32_e64 $x, $y, $z)
1753 (DivergentBinFrag<or> (and i64:$y, i64:$x), (and i64:$z, (not i64:$x))),
1754 (REG_SEQUENCE SReg_64,
1755 (V_BFI_B32_e64 (i32 (EXTRACT_SUBREG SReg_64:$x, sub0)),
1756 (i32 (EXTRACT_SUBREG SReg_64:$y, sub0)),
1757 (i32 (EXTRACT_SUBREG SReg_64:$z, sub0))), sub0,
1758 (V_BFI_B32_e64 (i32 (EXTRACT_SUBREG SReg_64:$x, sub1)),
1759 (i32 (EXTRACT_SUBREG SReg_64:$y, sub1)),
1760 (i32 (EXTRACT_SUBREG SReg_64:$z, sub1))), sub1)
1763 // SHA-256 Ch function
1764 // z ^ (x & (y ^ z))
1766 (DivergentBinFrag<xor> i32:$z, (and i32:$x, (xor i32:$y, i32:$z))),
1767 (V_BFI_B32_e64 $x, $y, $z)
1772 (DivergentBinFrag<xor> i64:$z, (and i64:$x, (xor i64:$y, i64:$z))),
1773 (REG_SEQUENCE SReg_64,
1774 (V_BFI_B32_e64 (i32 (EXTRACT_SUBREG SReg_64:$x, sub0)),
1775 (i32 (EXTRACT_SUBREG SReg_64:$y, sub0)),
1776 (i32 (EXTRACT_SUBREG SReg_64:$z, sub0))), sub0,
1777 (V_BFI_B32_e64 (i32 (EXTRACT_SUBREG SReg_64:$x, sub1)),
1778 (i32 (EXTRACT_SUBREG SReg_64:$y, sub1)),
1779 (i32 (EXTRACT_SUBREG SReg_64:$z, sub1))), sub1)
1783 (fcopysign f32:$src0, f32:$src1),
1784 (V_BFI_B32_e64 (S_MOV_B32 (i32 0x7fffffff)), $src0, $src1)
1788 (fcopysign f32:$src0, f64:$src1),
1789 (V_BFI_B32_e64 (S_MOV_B32 (i32 0x7fffffff)), $src0,
1790 (i32 (EXTRACT_SUBREG SReg_64:$src1, sub1)))
1794 (fcopysign f64:$src0, f64:$src1),
1795 (REG_SEQUENCE SReg_64,
1796 (i32 (EXTRACT_SUBREG $src0, sub0)), sub0,
1797 (V_BFI_B32_e64 (S_MOV_B32 (i32 0x7fffffff)),
1798 (i32 (EXTRACT_SUBREG SReg_64:$src0, sub1)),
1799 (i32 (EXTRACT_SUBREG SReg_64:$src1, sub1))), sub1)
1803 (fcopysign f64:$src0, f32:$src1),
1804 (REG_SEQUENCE SReg_64,
1805 (i32 (EXTRACT_SUBREG $src0, sub0)), sub0,
1806 (V_BFI_B32_e64 (S_MOV_B32 (i32 0x7fffffff)),
1807 (i32 (EXTRACT_SUBREG SReg_64:$src0, sub1)),
1811 def : ROTRPattern <V_ALIGNBIT_B32_e64>;
1813 def : GCNPat<(i32 (trunc (srl i64:$src0, (and i32:$src1, (i32 31))))),
1814 (V_ALIGNBIT_B32_e64 (i32 (EXTRACT_SUBREG (i64 $src0), sub1)),
1815 (i32 (EXTRACT_SUBREG (i64 $src0), sub0)), $src1)>;
1817 def : GCNPat<(i32 (trunc (srl i64:$src0, (i32 ShiftAmt32Imm:$src1)))),
1818 (V_ALIGNBIT_B32_e64 (i32 (EXTRACT_SUBREG (i64 $src0), sub1)),
1819 (i32 (EXTRACT_SUBREG (i64 $src0), sub0)), $src1)>;
1821 /********** ====================== **********/
1822 /********** Indirect addressing **********/
1823 /********** ====================== **********/
1825 multiclass SI_INDIRECT_Pattern <ValueType vt, ValueType eltvt, string VecSize> {
1826 // Extract with offset
1828 (eltvt (extractelt vt:$src, (MOVRELOffset i32:$idx, (i32 imm:$offset)))),
1829 (!cast<Instruction>("SI_INDIRECT_SRC_"#VecSize) $src, $idx, imm:$offset)
1832 // Insert with offset
1834 (insertelt vt:$src, eltvt:$val, (MOVRELOffset i32:$idx, (i32 imm:$offset))),
1835 (!cast<Instruction>("SI_INDIRECT_DST_"#VecSize) $src, $idx, imm:$offset, $val)
1839 defm : SI_INDIRECT_Pattern <v2f32, f32, "V2">;
1840 defm : SI_INDIRECT_Pattern <v4f32, f32, "V4">;
1841 defm : SI_INDIRECT_Pattern <v8f32, f32, "V8">;
1842 defm : SI_INDIRECT_Pattern <v16f32, f32, "V16">;
1843 defm : SI_INDIRECT_Pattern <v32f32, f32, "V32">;
1845 defm : SI_INDIRECT_Pattern <v2i32, i32, "V2">;
1846 defm : SI_INDIRECT_Pattern <v4i32, i32, "V4">;
1847 defm : SI_INDIRECT_Pattern <v8i32, i32, "V8">;
1848 defm : SI_INDIRECT_Pattern <v16i32, i32, "V16">;
1849 defm : SI_INDIRECT_Pattern <v32i32, i32, "V32">;
1851 //===----------------------------------------------------------------------===//
1853 //===----------------------------------------------------------------------===//
1856 (add (sub_oneuse (umax i32:$src0, i32:$src1),
1857 (umin i32:$src0, i32:$src1)),
1859 (V_SAD_U32_e64 $src0, $src1, $src2, (i1 0))
1863 (add (select_oneuse (i1 (setugt i32:$src0, i32:$src1)),
1864 (sub i32:$src0, i32:$src1),
1865 (sub i32:$src1, i32:$src0)),
1867 (V_SAD_U32_e64 $src0, $src1, $src2, (i1 0))
1870 //===----------------------------------------------------------------------===//
1871 // Conversion Patterns
1872 //===----------------------------------------------------------------------===//
1874 def : GCNPat<(i32 (sext_inreg i32:$src, i1)),
1875 (S_BFE_I32 i32:$src, (i32 65536))>; // 0 | 1 << 16
1877 // Handle sext_inreg in i64
1879 (i64 (sext_inreg i64:$src, i1)),
1880 (S_BFE_I64 i64:$src, (i32 0x10000)) // 0 | 1 << 16
1884 (i16 (sext_inreg i16:$src, i1)),
1885 (S_BFE_I32 $src, (i32 0x00010000)) // 0 | 1 << 16
1889 (i16 (sext_inreg i16:$src, i8)),
1890 (S_BFE_I32 $src, (i32 0x80000)) // 0 | 8 << 16
1894 (i64 (sext_inreg i64:$src, i8)),
1895 (S_BFE_I64 i64:$src, (i32 0x80000)) // 0 | 8 << 16
1899 (i64 (sext_inreg i64:$src, i16)),
1900 (S_BFE_I64 i64:$src, (i32 0x100000)) // 0 | 16 << 16
1904 (i64 (sext_inreg i64:$src, i32)),
1905 (S_BFE_I64 i64:$src, (i32 0x200000)) // 0 | 32 << 16
1909 (i64 (zext i32:$src)),
1910 (REG_SEQUENCE SReg_64, $src, sub0, (S_MOV_B32 (i32 0)), sub1)
1914 (i64 (anyext i32:$src)),
1915 (REG_SEQUENCE SReg_64, $src, sub0, (i32 (IMPLICIT_DEF)), sub1)
1918 class ZExt_i64_i1_Pat <SDNode ext> : GCNPat <
1919 (i64 (ext i1:$src)),
1920 (REG_SEQUENCE VReg_64,
1921 (V_CNDMASK_B32_e64 /*src0mod*/(i32 0), /*src0*/(i32 0),
1922 /*src1mod*/(i32 0), /*src1*/(i32 1), $src),
1923 sub0, (S_MOV_B32 (i32 0)), sub1)
1927 def : ZExt_i64_i1_Pat<zext>;
1928 def : ZExt_i64_i1_Pat<anyext>;
1930 // FIXME: We need to use COPY_TO_REGCLASS to work-around the fact that
1931 // REG_SEQUENCE patterns don't support instructions with multiple outputs.
1933 (i64 (sext i32:$src)),
1934 (REG_SEQUENCE SReg_64, $src, sub0,
1935 (i32 (COPY_TO_REGCLASS (S_ASHR_I32 $src, (i32 31)), SReg_32_XM0)), sub1)
1939 (i64 (sext i1:$src)),
1940 (REG_SEQUENCE VReg_64,
1941 (V_CNDMASK_B32_e64 /*src0mod*/(i32 0), /*src0*/(i32 0),
1942 /*src1mod*/(i32 0), /*src1*/(i32 -1), $src), sub0,
1943 (V_CNDMASK_B32_e64 /*src0mod*/(i32 0), /*src0*/(i32 0),
1944 /*src1mod*/(i32 0), /*src1*/(i32 -1), $src), sub1)
1947 class FPToI1Pat<Instruction Inst, int KOne, ValueType kone_type, ValueType vt, SDPatternOperator fp_to_int> : GCNPat <
1948 (i1 (fp_to_int (vt (VOP3Mods vt:$src0, i32:$src0_modifiers)))),
1949 (i1 (Inst 0, (kone_type KOne), $src0_modifiers, $src0, DSTCLAMP.NONE))
1952 def : FPToI1Pat<V_CMP_EQ_F16_e64, CONST.FP16_ONE, i16, f16, fp_to_uint>;
1953 def : FPToI1Pat<V_CMP_EQ_F16_e64, CONST.FP16_NEG_ONE, i16, f16, fp_to_sint>;
1954 def : FPToI1Pat<V_CMP_EQ_F32_e64, CONST.FP32_ONE, i32, f32, fp_to_uint>;
1955 def : FPToI1Pat<V_CMP_EQ_F32_e64, CONST.FP32_NEG_ONE, i32, f32, fp_to_sint>;
1956 def : FPToI1Pat<V_CMP_EQ_F64_e64, CONST.FP64_ONE, i64, f64, fp_to_uint>;
1957 def : FPToI1Pat<V_CMP_EQ_F64_e64, CONST.FP64_NEG_ONE, i64, f64, fp_to_sint>;
1959 // If we need to perform a logical operation on i1 values, we need to
1960 // use vector comparisons since there is only one SCC register. Vector
1961 // comparisons may write to a pair of SGPRs or a single SGPR, so treat
1962 // these as 32 or 64-bit comparisons. When legalizing SGPR copies,
1963 // instructions resulting in the copies from SCC to these instructions
1964 // will be moved to the VALU.
1966 let WaveSizePredicate = isWave64 in {
1968 (i1 (and i1:$src0, i1:$src1)),
1969 (S_AND_B64 $src0, $src1)
1973 (i1 (or i1:$src0, i1:$src1)),
1974 (S_OR_B64 $src0, $src1)
1978 (i1 (xor i1:$src0, i1:$src1)),
1979 (S_XOR_B64 $src0, $src1)
1983 (i1 (add i1:$src0, i1:$src1)),
1984 (S_XOR_B64 $src0, $src1)
1988 (i1 (sub i1:$src0, i1:$src1)),
1989 (S_XOR_B64 $src0, $src1)
1992 let AddedComplexity = 1 in {
1994 (i1 (add i1:$src0, (i1 -1))),
1999 (i1 (sub i1:$src0, (i1 -1))),
2005 let WaveSizePredicate = isWave32 in {
2007 (i1 (and i1:$src0, i1:$src1)),
2008 (S_AND_B32 $src0, $src1)
2012 (i1 (or i1:$src0, i1:$src1)),
2013 (S_OR_B32 $src0, $src1)
2017 (i1 (xor i1:$src0, i1:$src1)),
2018 (S_XOR_B32 $src0, $src1)
2022 (i1 (add i1:$src0, i1:$src1)),
2023 (S_XOR_B32 $src0, $src1)
2027 (i1 (sub i1:$src0, i1:$src1)),
2028 (S_XOR_B32 $src0, $src1)
2031 let AddedComplexity = 1 in {
2033 (i1 (add i1:$src0, (i1 -1))),
2038 (i1 (sub i1:$src0, (i1 -1))),
2045 (f16 (sint_to_fp i1:$src)),
2046 (V_CVT_F16_F32_e32 (
2047 V_CNDMASK_B32_e64 /*src0mod*/(i32 0), /*src0*/(i32 0),
2048 /*src1mod*/(i32 0), /*src1*/(i32 CONST.FP32_NEG_ONE),
2053 (f16 (uint_to_fp i1:$src)),
2054 (V_CVT_F16_F32_e32 (
2055 V_CNDMASK_B32_e64 /*src0mod*/(i32 0), /*src0*/(i32 0),
2056 /*src1mod*/(i32 0), /*src1*/(i32 CONST.FP32_ONE),
2061 (f32 (sint_to_fp i1:$src)),
2062 (V_CNDMASK_B32_e64 /*src0mod*/(i32 0), /*src0*/(i32 0),
2063 /*src1mod*/(i32 0), /*src1*/(i32 CONST.FP32_NEG_ONE),
2068 (f32 (uint_to_fp i1:$src)),
2069 (V_CNDMASK_B32_e64 /*src0mod*/(i32 0), /*src0*/(i32 0),
2070 /*src1mod*/(i32 0), /*src1*/(i32 CONST.FP32_ONE),
2075 (f64 (sint_to_fp i1:$src)),
2076 (V_CVT_F64_I32_e32 (V_CNDMASK_B32_e64 /*src0mod*/(i32 0), /*src0*/(i32 0),
2077 /*src1mod*/(i32 0), /*src1*/(i32 -1),
2082 (f64 (uint_to_fp i1:$src)),
2083 (V_CVT_F64_U32_e32 (V_CNDMASK_B32_e64 /*src0mod*/(i32 0), /*src0*/(i32 0),
2084 /*src1mod*/(i32 0), /*src1*/(i32 1),
2088 //===----------------------------------------------------------------------===//
2089 // Miscellaneous Patterns
2090 //===----------------------------------------------------------------------===//
2092 // Eliminate a zero extension from an fp16 operation if it already
2093 // zeros the high bits of the 32-bit register.
2095 // This is complicated on gfx9+. Some instructions maintain the legacy
2096 // zeroing behavior, but others preserve the high bits. Some have a
2097 // control bit to change the behavior. We can't simply say with
2098 // certainty what the source behavior is without more context on how
2099 // the src is lowered. e.g. fptrunc + fma may be lowered to a
2100 // v_fma_mix* instruction which does not zero, or may not.
2102 (i32 (zext (i16 (bitconvert fp16_zeros_high_16bits:$src)))),
2103 (COPY VSrc_b16:$src)>;
2106 (i32 (trunc i64:$a)),
2107 (EXTRACT_SUBREG $a, sub0)
2111 (i1 (trunc i32:$a)),
2112 (V_CMP_EQ_U32_e64 (S_AND_B32 (i32 1), $a), (i32 1))
2116 (i1 (trunc i16:$a)),
2117 (V_CMP_EQ_U32_e64 (S_AND_B32 (i32 1), $a), (i32 1))
2121 (i1 (trunc i64:$a)),
2122 (V_CMP_EQ_U32_e64 (S_AND_B32 (i32 1),
2123 (i32 (EXTRACT_SUBREG $a, sub0))), (i32 1))
2127 (i32 (bswap i32:$a)),
2128 (V_BFI_B32_e64 (S_MOV_B32 (i32 0x00ff00ff)),
2129 (V_ALIGNBIT_B32_e64 VSrc_b32:$a, VSrc_b32:$a, (i32 24)),
2130 (V_ALIGNBIT_B32_e64 VSrc_b32:$a, VSrc_b32:$a, (i32 8)))
2133 // FIXME: This should have been narrowed to i32 during legalization.
2134 // This pattern should also be skipped for GlobalISel
2136 (i64 (bswap i64:$a)),
2137 (REG_SEQUENCE VReg_64,
2138 (V_BFI_B32_e64 (S_MOV_B32 (i32 0x00ff00ff)),
2139 (V_ALIGNBIT_B32_e64 (i32 (EXTRACT_SUBREG VReg_64:$a, sub1)),
2140 (i32 (EXTRACT_SUBREG VReg_64:$a, sub1)),
2142 (V_ALIGNBIT_B32_e64 (i32 (EXTRACT_SUBREG VReg_64:$a, sub1)),
2143 (i32 (EXTRACT_SUBREG VReg_64:$a, sub1)),
2146 (V_BFI_B32_e64 (S_MOV_B32 (i32 0x00ff00ff)),
2147 (V_ALIGNBIT_B32_e64 (i32 (EXTRACT_SUBREG VReg_64:$a, sub0)),
2148 (i32 (EXTRACT_SUBREG VReg_64:$a, sub0)),
2150 (V_ALIGNBIT_B32_e64 (i32 (EXTRACT_SUBREG VReg_64:$a, sub0)),
2151 (i32 (EXTRACT_SUBREG VReg_64:$a, sub0)),
2156 // FIXME: The AddedComplexity should not be needed, but in GlobalISel
2157 // the BFI pattern ends up taking precedence without it.
2158 let SubtargetPredicate = isGFX8Plus, AddedComplexity = 1 in {
2159 // Magic number: 3 | (2 << 8) | (1 << 16) | (0 << 24)
2161 // My reading of the manual suggests we should be using src0 for the
2162 // register value, but this is what seems to work.
2164 (i32 (bswap i32:$a)),
2165 (V_PERM_B32_e64 (i32 0), VSrc_b32:$a, (S_MOV_B32 (i32 0x00010203)))
2168 // FIXME: This should have been narrowed to i32 during legalization.
2169 // This pattern should also be skipped for GlobalISel
2171 (i64 (bswap i64:$a)),
2172 (REG_SEQUENCE VReg_64,
2173 (V_PERM_B32_e64 (i32 0), (EXTRACT_SUBREG VReg_64:$a, sub1),
2174 (S_MOV_B32 (i32 0x00010203))),
2176 (V_PERM_B32_e64 (i32 0), (EXTRACT_SUBREG VReg_64:$a, sub0),
2177 (S_MOV_B32 (i32 0x00010203))),
2181 // Magic number: 1 | (0 << 8) | (12 << 16) | (12 << 24)
2184 (i16 (bswap i16:$a)),
2185 (V_PERM_B32_e64 (i32 0), VSrc_b32:$a, (S_MOV_B32 (i32 0x0c0c0001)))
2189 (i32 (zext (bswap i16:$a))),
2190 (V_PERM_B32_e64 (i32 0), VSrc_b32:$a, (S_MOV_B32 (i32 0x0c0c0001)))
2193 // Magic number: 1 | (0 << 8) | (3 << 16) | (2 << 24)
2195 (v2i16 (bswap v2i16:$a)),
2196 (V_PERM_B32_e64 (i32 0), VSrc_b32:$a, (S_MOV_B32 (i32 0x02030001)))
2202 // Prefer selecting to max when legal, but using mul is always valid.
2203 let AddedComplexity = -5 in {
2205 (fcanonicalize (f16 (VOP3Mods f16:$src, i32:$src_mods))),
2206 (V_MUL_F16_e64 0, (i32 CONST.FP16_ONE), $src_mods, $src)
2210 (fcanonicalize (f16 (fneg (VOP3Mods f16:$src, i32:$src_mods)))),
2211 (V_MUL_F16_e64 0, (i32 CONST.FP16_NEG_ONE), $src_mods, $src)
2215 (fcanonicalize (v2f16 (VOP3PMods v2f16:$src, i32:$src_mods))),
2216 (V_PK_MUL_F16 0, (i32 CONST.FP16_ONE), $src_mods, $src, DSTCLAMP.NONE)
2220 (fcanonicalize (f32 (VOP3Mods f32:$src, i32:$src_mods))),
2221 (V_MUL_F32_e64 0, (i32 CONST.FP32_ONE), $src_mods, $src)
2225 (fcanonicalize (f32 (fneg (VOP3Mods f32:$src, i32:$src_mods)))),
2226 (V_MUL_F32_e64 0, (i32 CONST.FP32_NEG_ONE), $src_mods, $src)
2229 // TODO: Handle fneg like other types.
2231 (fcanonicalize (f64 (VOP3Mods f64:$src, i32:$src_mods))),
2232 (V_MUL_F64_e64 0, CONST.FP64_ONE, $src_mods, $src)
2234 } // End AddedComplexity = -5
2236 multiclass SelectCanonicalizeAsMax<
2237 list<Predicate> f32_preds = [],
2238 list<Predicate> f64_preds = [],
2239 list<Predicate> f16_preds = []> {
2241 (fcanonicalize (f32 (VOP3Mods f32:$src, i32:$src_mods))),
2242 (V_MAX_F32_e64 $src_mods, $src, $src_mods, $src)> {
2243 let OtherPredicates = f32_preds;
2247 (fcanonicalize (f64 (VOP3Mods f64:$src, i32:$src_mods))),
2248 (V_MAX_F64_e64 $src_mods, $src, $src_mods, $src)> {
2249 let OtherPredicates = f64_preds;
2253 (fcanonicalize (f16 (VOP3Mods f16:$src, i32:$src_mods))),
2254 (V_MAX_F16_e64 $src_mods, $src, $src_mods, $src, 0, 0)> {
2255 // FIXME: Should have 16-bit inst subtarget predicate
2256 let OtherPredicates = f16_preds;
2260 (fcanonicalize (v2f16 (VOP3PMods v2f16:$src, i32:$src_mods))),
2261 (V_PK_MAX_F16 $src_mods, $src, $src_mods, $src, DSTCLAMP.NONE)> {
2262 // FIXME: Should have VOP3P subtarget predicate
2263 let OtherPredicates = f16_preds;
2267 // On pre-gfx9 targets, v_max_*/v_min_* did not respect the denormal
2268 // mode, and would never flush. For f64, it's faster to do implement
2269 // this with a max. For f16/f32 it's a wash, but prefer max when
2272 // FIXME: Lowering f32/f16 with max is worse since we can use a
2273 // smaller encoding if the input is fneg'd. It also adds an extra
2275 let SubtargetPredicate = HasMinMaxDenormModes in {
2276 defm : SelectCanonicalizeAsMax<[], [], []>;
2277 } // End SubtargetPredicate = HasMinMaxDenormModes
2279 let SubtargetPredicate = NotHasMinMaxDenormModes in {
2280 // Use the max lowering if we don't need to flush.
2282 // FIXME: We don't do use this for f32 as a workaround for the
2283 // library being compiled with the default ieee mode, but
2284 // potentially being called from flushing kernels. Really we should
2285 // not be mixing code expecting different default FP modes, but mul
2286 // works in any FP environment.
2287 defm : SelectCanonicalizeAsMax<[FalsePredicate], [FP64Denormals], [FP16Denormals]>;
2288 } // End SubtargetPredicate = NotHasMinMaxDenormModes
2291 let OtherPredicates = [HasDLInsts] in {
2293 (fma (f32 (VOP3Mods f32:$src0, i32:$src0_modifiers)),
2294 (f32 (VOP3Mods f32:$src1, i32:$src1_modifiers)),
2295 (f32 (VOP3NoMods f32:$src2))),
2296 (V_FMAC_F32_e64 $src0_modifiers, $src0, $src1_modifiers, $src1,
2297 SRCMODS.NONE, $src2)
2299 } // End OtherPredicates = [HasDLInsts]
2301 let SubtargetPredicate = isGFX10Plus in
2303 (fma (f16 (VOP3Mods f32:$src0, i32:$src0_modifiers)),
2304 (f16 (VOP3Mods f32:$src1, i32:$src1_modifiers)),
2305 (f16 (VOP3NoMods f32:$src2))),
2306 (V_FMAC_F16_e64 $src0_modifiers, $src0, $src1_modifiers, $src1,
2307 SRCMODS.NONE, $src2)
2310 let SubtargetPredicate = isGFX90APlus in
2312 (fma (f64 (VOP3Mods0 f64:$src0, i32:$src0_modifiers, i1:$clamp, i32:$omod)),
2313 (f64 (VOP3Mods f64:$src1, i32:$src1_modifiers)),
2314 (f64 (VOP3NoMods f64:$src2))),
2315 (V_FMAC_F64_e64 $src0_modifiers, $src0, $src1_modifiers, $src1,
2316 SRCMODS.NONE, $src2, $clamp, $omod)
2319 // COPY is workaround tablegen bug from multiple outputs
2320 // from S_LSHL_B32's multiple outputs from implicit scc def.
2322 (v2i16 (build_vector (i16 0), (i16 SReg_32:$src1))),
2323 (S_LSHL_B32 SReg_32:$src1, (i16 16))
2327 (v2i16 (build_vector (i16 SReg_32:$src1), (i16 0))),
2328 (S_AND_B32 (S_MOV_B32 (i32 0xffff)), SReg_32:$src1)
2332 (v2f16 (build_vector (f16 SReg_32:$src1), (f16 FP_ZERO))),
2333 (S_AND_B32 (S_MOV_B32 (i32 0xffff)), SReg_32:$src1)
2337 (v2i16 (build_vector (i16 SReg_32:$src0), (i16 undef))),
2338 (COPY_TO_REGCLASS SReg_32:$src0, SReg_32)
2342 (v2i16 (build_vector (i16 VGPR_32:$src0), (i16 undef))),
2343 (COPY_TO_REGCLASS VGPR_32:$src0, VGPR_32)
2347 (v2f16 (build_vector f16:$src0, (f16 undef))),
2352 (v2i16 (build_vector (i16 undef), (i16 SReg_32:$src1))),
2353 (S_LSHL_B32 SReg_32:$src1, (i32 16))
2357 (v2f16 (build_vector (f16 undef), (f16 SReg_32:$src1))),
2358 (S_LSHL_B32 SReg_32:$src1, (i32 16))
2361 let SubtargetPredicate = HasVOP3PInsts in {
2363 (v2i16 (build_vector (i16 SReg_32:$src0), (i16 SReg_32:$src1))),
2364 (S_PACK_LL_B32_B16 SReg_32:$src0, SReg_32:$src1)
2367 // With multiple uses of the shift, this will duplicate the shift and
2368 // increase register pressure.
2370 (v2i16 (build_vector (i16 SReg_32:$src0), (i16 (trunc (srl_oneuse SReg_32:$src1, (i32 16)))))),
2371 (v2i16 (S_PACK_LH_B32_B16 SReg_32:$src0, SReg_32:$src1))
2376 (v2i16 (build_vector (i16 (trunc (srl_oneuse SReg_32:$src0, (i32 16)))),
2377 (i16 (trunc (srl_oneuse SReg_32:$src1, (i32 16)))))),
2378 (S_PACK_HH_B32_B16 SReg_32:$src0, SReg_32:$src1)
2381 // TODO: Should source modifiers be matched to v_pack_b32_f16?
2383 (v2f16 (build_vector (f16 SReg_32:$src0), (f16 SReg_32:$src1))),
2384 (S_PACK_LL_B32_B16 SReg_32:$src0, SReg_32:$src1)
2388 (v2f16 (is_canonicalized<build_vector> (f16 (VOP3Mods (f16 VGPR_32:$src0), i32:$src0_mods)),
2389 (f16 (VOP3Mods (f16 VGPR_32:$src1), i32:$src1_mods)))),
2390 (V_PACK_B32_F16_e64 $src0_mods, VGPR_32:$src0, $src1_mods, VGPR_32:$src1)
2392 } // End SubtargetPredicate = HasVOP3PInsts
2395 (v2f16 (scalar_to_vector f16:$src0)),
2400 (v2i16 (scalar_to_vector i16:$src0)),
2405 (v4i16 (scalar_to_vector i16:$src0)),
2406 (INSERT_SUBREG (IMPLICIT_DEF), $src0, sub0)
2410 (v4f16 (scalar_to_vector f16:$src0)),
2411 (INSERT_SUBREG (IMPLICIT_DEF), $src0, sub0)
2415 (i64 (int_amdgcn_mov_dpp i64:$src, timm:$dpp_ctrl, timm:$row_mask,
2416 timm:$bank_mask, timm:$bound_ctrl)),
2417 (V_MOV_B64_DPP_PSEUDO VReg_64_Align2:$src, VReg_64_Align2:$src,
2418 (as_i32timm $dpp_ctrl), (as_i32timm $row_mask),
2419 (as_i32timm $bank_mask),
2420 (as_i1timm $bound_ctrl))
2424 (i64 (int_amdgcn_update_dpp i64:$old, i64:$src, timm:$dpp_ctrl, timm:$row_mask,
2425 timm:$bank_mask, timm:$bound_ctrl)),
2426 (V_MOV_B64_DPP_PSEUDO VReg_64_Align2:$old, VReg_64_Align2:$src, (as_i32timm $dpp_ctrl),
2427 (as_i32timm $row_mask), (as_i32timm $bank_mask),
2428 (as_i1timm $bound_ctrl))
2431 //===----------------------------------------------------------------------===//
2433 //===----------------------------------------------------------------------===//
2435 let SubtargetPredicate = isGFX6 in {
2437 // V_FRACT is buggy on SI, so the F32 version is never used and (x-floor(x)) is
2438 // used instead. However, SI doesn't have V_FLOOR_F64, so the most efficient
2439 // way to implement it is using V_FRACT_F64.
2440 // The workaround for the V_FRACT bug is:
2441 // fract(x) = isnan(x) ? x : min(V_FRACT(x), 0.99999999999999999)
2443 // Convert floor(x) to (x - fract(x))
2445 // Don't bother handling this for GlobalISel, it's handled during
2448 // FIXME: DAG should also custom lower this.
2450 (f64 (ffloor (f64 (VOP3Mods f64:$x, i32:$mods)))),
2455 (V_CNDMASK_B64_PSEUDO
2458 (V_FRACT_F64_e64 $mods, $x),
2460 (V_MOV_B64_PSEUDO 0x3fefffffffffffff)),
2462 (V_CMP_CLASS_F64_e64 SRCMODS.NONE, $x, (i32 3 /*NaN*/))))
2465 } // End SubtargetPredicates = isGFX6
2467 //============================================================================//
2468 // Miscellaneous Optimization Patterns
2469 //============================================================================//
2471 // Undo sub x, c -> add x, -c canonicalization since c is more likely
2472 // an inline immediate than -c.
2473 // TODO: Also do for 64-bit.
2475 (add i32:$src0, (i32 NegSubInlineConst32:$src1)),
2476 (S_SUB_I32 SReg_32:$src0, NegSubInlineConst32:$src1)
2480 (add i32:$src0, (i32 NegSubInlineConst32:$src1)),
2481 (V_SUB_U32_e64 VS_32:$src0, NegSubInlineConst32:$src1)> {
2482 let SubtargetPredicate = HasAddNoCarryInsts;
2486 (add i32:$src0, (i32 NegSubInlineConst32:$src1)),
2487 (V_SUB_CO_U32_e64 VS_32:$src0, NegSubInlineConst32:$src1)> {
2488 let SubtargetPredicate = NotHasAddNoCarryInsts;
2492 // Avoid pointlessly materializing a constant in VGPR.
2493 // FIXME: Should also do this for readlane, but tablegen crashes on
2494 // the ignored src1.
2496 (int_amdgcn_readfirstlane (i32 imm:$src)),
2497 (S_MOV_B32 SReg_32:$src)
2500 multiclass BFMPatterns <ValueType vt, InstSI BFM, InstSI MOV> {
2502 (vt (shl (vt (add (vt (shl 1, vt:$a)), -1)), vt:$b)),
2507 (vt (add (vt (shl 1, vt:$a)), -1)),
2508 (BFM $a, (MOV (i32 0)))
2512 defm : BFMPatterns <i32, S_BFM_B32, S_MOV_B32>;
2513 // FIXME: defm : BFMPatterns <i64, S_BFM_B64, S_MOV_B64>;
2515 // Bitfield extract patterns
2517 def IMMZeroBasedBitfieldMask : ImmLeaf <i32, [{
2518 return isMask_32(Imm);
2521 def IMMPopCount : SDNodeXForm<imm, [{
2522 return CurDAG->getTargetConstant(countPopulation(N->getZExtValue()), SDLoc(N),
2527 (DivergentBinFrag<and> (i32 (srl i32:$src, i32:$rshift)),
2528 IMMZeroBasedBitfieldMask:$mask),
2529 (V_BFE_U32_e64 $src, $rshift, (i32 (IMMPopCount $mask)))
2532 // x & ((1 << y) - 1)
2534 (DivergentBinFrag<and> i32:$src, (add_oneuse (shl_oneuse 1, i32:$width), -1)),
2535 (V_BFE_U32_e64 $src, (i32 0), $width)
2540 (DivergentBinFrag<and> i32:$src,
2541 (xor_oneuse (shl_oneuse -1, i32:$width), -1)),
2542 (V_BFE_U32_e64 $src, (i32 0), $width)
2545 // x & (-1 >> (bitwidth - y))
2547 (DivergentBinFrag<and> i32:$src, (srl_oneuse -1, (sub 32, i32:$width))),
2548 (V_BFE_U32_e64 $src, (i32 0), $width)
2551 // x << (bitwidth - y) >> (bitwidth - y)
2553 (DivergentBinFrag<srl> (shl_oneuse i32:$src, (sub 32, i32:$width)),
2554 (sub 32, i32:$width)),
2555 (V_BFE_U32_e64 $src, (i32 0), $width)
2559 (DivergentBinFrag<sra> (shl_oneuse i32:$src, (sub 32, i32:$width)),
2560 (sub 32, i32:$width)),
2561 (V_BFE_I32_e64 $src, (i32 0), $width)
2564 // SHA-256 Ma patterns
2566 // ((x & z) | (y & (x | z))) -> BFI (XOR x, y), z, y
2568 (DivergentBinFrag<or> (and i32:$x, i32:$z),
2569 (and i32:$y, (or i32:$x, i32:$z))),
2570 (V_BFI_B32_e64 (V_XOR_B32_e64 i32:$x, i32:$y), i32:$z, i32:$y)
2574 (DivergentBinFrag<or> (and i64:$x, i64:$z),
2575 (and i64:$y, (or i64:$x, i64:$z))),
2576 (REG_SEQUENCE SReg_64,
2577 (V_BFI_B32_e64 (V_XOR_B32_e64 (i32 (EXTRACT_SUBREG SReg_64:$x, sub0)),
2578 (i32 (EXTRACT_SUBREG SReg_64:$y, sub0))),
2579 (i32 (EXTRACT_SUBREG SReg_64:$z, sub0)),
2580 (i32 (EXTRACT_SUBREG SReg_64:$y, sub0))), sub0,
2581 (V_BFI_B32_e64 (V_XOR_B32_e64 (i32 (EXTRACT_SUBREG SReg_64:$x, sub1)),
2582 (i32 (EXTRACT_SUBREG SReg_64:$y, sub1))),
2583 (i32 (EXTRACT_SUBREG SReg_64:$z, sub1)),
2584 (i32 (EXTRACT_SUBREG SReg_64:$y, sub1))), sub1)
2587 multiclass IntMed3Pat<Instruction med3Inst,
2588 SDPatternOperator min,
2589 SDPatternOperator max,
2590 SDPatternOperator min_oneuse,
2591 SDPatternOperator max_oneuse> {
2593 // This matches 16 permutations of
2594 // min(max(a, b), max(min(a, b), c))
2596 (min (max_oneuse i32:$src0, i32:$src1),
2597 (max_oneuse (min_oneuse i32:$src0, i32:$src1), i32:$src2)),
2598 (med3Inst VSrc_b32:$src0, VSrc_b32:$src1, VSrc_b32:$src2)
2601 // This matches 16 permutations of
2602 // max(min(x, y), min(max(x, y), z))
2604 (max (min_oneuse i32:$src0, i32:$src1),
2605 (min_oneuse (max_oneuse i32:$src0, i32:$src1), i32:$src2)),
2606 (med3Inst VSrc_b32:$src0, VSrc_b32:$src1, VSrc_b32:$src2)
2610 defm : IntMed3Pat<V_MED3_I32_e64, smin, smax, smin_oneuse, smax_oneuse>;
2611 defm : IntMed3Pat<V_MED3_U32_e64, umin, umax, umin_oneuse, umax_oneuse>;
2613 // This matches 16 permutations of
2614 // max(min(x, y), min(max(x, y), z))
2615 class FPMed3Pat<ValueType vt,
2616 //SDPatternOperator max, SDPatternOperator min,
2617 Instruction med3Inst> : GCNPat<
2618 (fmaxnum_like (fminnum_like_oneuse (VOP3Mods_nnan vt:$src0, i32:$src0_mods),
2619 (VOP3Mods_nnan vt:$src1, i32:$src1_mods)),
2620 (fminnum_like_oneuse (fmaxnum_like_oneuse (VOP3Mods_nnan vt:$src0, i32:$src0_mods),
2621 (VOP3Mods_nnan vt:$src1, i32:$src1_mods)),
2622 (vt (VOP3Mods_nnan vt:$src2, i32:$src2_mods)))),
2623 (med3Inst $src0_mods, $src0, $src1_mods, $src1, $src2_mods, $src2, DSTCLAMP.NONE, DSTOMOD.NONE)
2626 class FP16Med3Pat<ValueType vt,
2627 Instruction med3Inst> : GCNPat<
2628 (fmaxnum_like (fminnum_like_oneuse (VOP3Mods_nnan vt:$src0, i32:$src0_mods),
2629 (VOP3Mods_nnan vt:$src1, i32:$src1_mods)),
2630 (fminnum_like_oneuse (fmaxnum_like_oneuse (VOP3Mods_nnan vt:$src0, i32:$src0_mods),
2631 (VOP3Mods_nnan vt:$src1, i32:$src1_mods)),
2632 (vt (VOP3Mods_nnan vt:$src2, i32:$src2_mods)))),
2633 (med3Inst $src0_mods, $src0, $src1_mods, $src1, $src2_mods, $src2, DSTCLAMP.NONE)
2636 multiclass Int16Med3Pat<Instruction med3Inst,
2637 SDPatternOperator min,
2638 SDPatternOperator max,
2639 SDPatternOperator max_oneuse,
2640 SDPatternOperator min_oneuse> {
2641 // This matches 16 permutations of
2642 // max(min(x, y), min(max(x, y), z))
2644 (max (min_oneuse i16:$src0, i16:$src1),
2645 (min_oneuse (max_oneuse i16:$src0, i16:$src1), i16:$src2)),
2646 (med3Inst SRCMODS.NONE, VSrc_b16:$src0, SRCMODS.NONE, VSrc_b16:$src1, SRCMODS.NONE, VSrc_b16:$src2, DSTCLAMP.NONE)
2649 // This matches 16 permutations of
2650 // min(max(a, b), max(min(a, b), c))
2652 (min (max_oneuse i16:$src0, i16:$src1),
2653 (max_oneuse (min_oneuse i16:$src0, i16:$src1), i16:$src2)),
2654 (med3Inst SRCMODS.NONE, VSrc_b16:$src0, SRCMODS.NONE, VSrc_b16:$src1, SRCMODS.NONE, VSrc_b16:$src2, DSTCLAMP.NONE)
2658 def : FPMed3Pat<f32, V_MED3_F32_e64>;
2660 let OtherPredicates = [isGFX9Plus] in {
2661 def : FP16Med3Pat<f16, V_MED3_F16_e64>;
2662 defm : Int16Med3Pat<V_MED3_I16_e64, smin, smax, smax_oneuse, smin_oneuse>;
2663 defm : Int16Med3Pat<V_MED3_U16_e64, umin, umax, umax_oneuse, umin_oneuse>;
2664 } // End Predicates = [isGFX9Plus]
2666 class AMDGPUGenericInstruction : GenericInstruction {
2667 let Namespace = "AMDGPU";
2670 // Returns -1 if the input is zero.
2671 def G_AMDGPU_FFBH_U32 : AMDGPUGenericInstruction {
2672 let OutOperandList = (outs type0:$dst);
2673 let InOperandList = (ins type1:$src);
2674 let hasSideEffects = 0;
2677 // Returns -1 if the input is zero.
2678 def G_AMDGPU_FFBL_B32 : AMDGPUGenericInstruction {
2679 let OutOperandList = (outs type0:$dst);
2680 let InOperandList = (ins type1:$src);
2681 let hasSideEffects = 0;
2684 def G_AMDGPU_RCP_IFLAG : AMDGPUGenericInstruction {
2685 let OutOperandList = (outs type0:$dst);
2686 let InOperandList = (ins type1:$src);
2687 let hasSideEffects = 0;
2690 class BufferLoadGenericInstruction : AMDGPUGenericInstruction {
2691 let OutOperandList = (outs type0:$dst);
2692 let InOperandList = (ins type1:$rsrc, type2:$vindex, type2:$voffset,
2693 type2:$soffset, untyped_imm_0:$offset,
2694 untyped_imm_0:$cachepolicy, untyped_imm_0:$idxen);
2695 let hasSideEffects = 0;
2699 class TBufferLoadGenericInstruction : AMDGPUGenericInstruction {
2700 let OutOperandList = (outs type0:$dst);
2701 let InOperandList = (ins type1:$rsrc, type2:$vindex, type2:$voffset,
2702 type2:$soffset, untyped_imm_0:$offset, untyped_imm_0:$format,
2703 untyped_imm_0:$cachepolicy, untyped_imm_0:$idxen);
2704 let hasSideEffects = 0;
2708 def G_AMDGPU_BUFFER_LOAD_UBYTE : BufferLoadGenericInstruction;
2709 def G_AMDGPU_BUFFER_LOAD_SBYTE : BufferLoadGenericInstruction;
2710 def G_AMDGPU_BUFFER_LOAD_USHORT : BufferLoadGenericInstruction;
2711 def G_AMDGPU_BUFFER_LOAD_SSHORT : BufferLoadGenericInstruction;
2712 def G_AMDGPU_BUFFER_LOAD : BufferLoadGenericInstruction;
2713 def G_AMDGPU_BUFFER_LOAD_FORMAT : BufferLoadGenericInstruction;
2714 def G_AMDGPU_BUFFER_LOAD_FORMAT_D16 : BufferLoadGenericInstruction;
2715 def G_AMDGPU_TBUFFER_LOAD_FORMAT : TBufferLoadGenericInstruction;
2716 def G_AMDGPU_TBUFFER_LOAD_FORMAT_D16 : TBufferLoadGenericInstruction;
2718 class BufferStoreGenericInstruction : AMDGPUGenericInstruction {
2719 let OutOperandList = (outs);
2720 let InOperandList = (ins type0:$vdata, type1:$rsrc, type2:$vindex, type2:$voffset,
2721 type2:$soffset, untyped_imm_0:$offset,
2722 untyped_imm_0:$cachepolicy, untyped_imm_0:$idxen);
2723 let hasSideEffects = 0;
2727 class TBufferStoreGenericInstruction : AMDGPUGenericInstruction {
2728 let OutOperandList = (outs);
2729 let InOperandList = (ins type0:$vdata, type1:$rsrc, type2:$vindex, type2:$voffset,
2730 type2:$soffset, untyped_imm_0:$offset,
2731 untyped_imm_0:$format,
2732 untyped_imm_0:$cachepolicy, untyped_imm_0:$idxen);
2733 let hasSideEffects = 0;
2737 def G_AMDGPU_BUFFER_STORE : BufferStoreGenericInstruction;
2738 def G_AMDGPU_BUFFER_STORE_BYTE : BufferStoreGenericInstruction;
2739 def G_AMDGPU_BUFFER_STORE_SHORT : BufferStoreGenericInstruction;
2740 def G_AMDGPU_BUFFER_STORE_FORMAT : BufferStoreGenericInstruction;
2741 def G_AMDGPU_BUFFER_STORE_FORMAT_D16 : BufferStoreGenericInstruction;
2742 def G_AMDGPU_TBUFFER_STORE_FORMAT : TBufferStoreGenericInstruction;
2743 def G_AMDGPU_TBUFFER_STORE_FORMAT_D16 : TBufferStoreGenericInstruction;
2745 def G_AMDGPU_FMIN_LEGACY : AMDGPUGenericInstruction {
2746 let OutOperandList = (outs type0:$dst);
2747 let InOperandList = (ins type0:$src0, type0:$src1);
2748 let hasSideEffects = 0;
2751 def G_AMDGPU_FMAX_LEGACY : AMDGPUGenericInstruction {
2752 let OutOperandList = (outs type0:$dst);
2753 let InOperandList = (ins type0:$src0, type0:$src1);
2754 let hasSideEffects = 0;
2757 foreach N = 0-3 in {
2758 def G_AMDGPU_CVT_F32_UBYTE#N : AMDGPUGenericInstruction {
2759 let OutOperandList = (outs type0:$dst);
2760 let InOperandList = (ins type0:$src0);
2761 let hasSideEffects = 0;
2765 def G_AMDGPU_CVT_PK_I16_I32 : AMDGPUGenericInstruction {
2766 let OutOperandList = (outs type0:$dst);
2767 let InOperandList = (ins type0:$src0, type0:$src1);
2768 let hasSideEffects = 0;
2771 def G_AMDGPU_SMED3 : AMDGPUGenericInstruction {
2772 let OutOperandList = (outs type0:$dst);
2773 let InOperandList = (ins type0:$src0, type0:$src1, type0:$src2);
2774 let hasSideEffects = 0;
2777 def G_AMDGPU_UMED3 : AMDGPUGenericInstruction {
2778 let OutOperandList = (outs type0:$dst);
2779 let InOperandList = (ins type0:$src0, type0:$src1, type0:$src2);
2780 let hasSideEffects = 0;
2783 // Atomic cmpxchg. $cmpval ad $newval are packed in a single vector
2784 // operand Expects a MachineMemOperand in addition to explicit
2786 def G_AMDGPU_ATOMIC_CMPXCHG : AMDGPUGenericInstruction {
2787 let OutOperandList = (outs type0:$oldval);
2788 let InOperandList = (ins ptype1:$addr, type0:$cmpval_newval);
2789 let hasSideEffects = 0;
2794 let Namespace = "AMDGPU" in {
2795 def G_AMDGPU_ATOMIC_INC : G_ATOMICRMW_OP;
2796 def G_AMDGPU_ATOMIC_DEC : G_ATOMICRMW_OP;
2797 def G_AMDGPU_ATOMIC_FMIN : G_ATOMICRMW_OP;
2798 def G_AMDGPU_ATOMIC_FMAX : G_ATOMICRMW_OP;
2801 class BufferAtomicGenericInstruction<bit NoRtn = 0> : AMDGPUGenericInstruction {
2802 let OutOperandList = !if(NoRtn, (outs), (outs type0:$dst));
2803 let InOperandList = (ins type0:$vdata, type1:$rsrc, type2:$vindex, type2:$voffset,
2804 type2:$soffset, untyped_imm_0:$offset,
2805 untyped_imm_0:$cachepolicy, untyped_imm_0:$idxen);
2806 let hasSideEffects = 0;
2811 def G_AMDGPU_BUFFER_ATOMIC_SWAP : BufferAtomicGenericInstruction;
2812 def G_AMDGPU_BUFFER_ATOMIC_ADD : BufferAtomicGenericInstruction;
2813 def G_AMDGPU_BUFFER_ATOMIC_SUB : BufferAtomicGenericInstruction;
2814 def G_AMDGPU_BUFFER_ATOMIC_SMIN : BufferAtomicGenericInstruction;
2815 def G_AMDGPU_BUFFER_ATOMIC_UMIN : BufferAtomicGenericInstruction;
2816 def G_AMDGPU_BUFFER_ATOMIC_SMAX : BufferAtomicGenericInstruction;
2817 def G_AMDGPU_BUFFER_ATOMIC_UMAX : BufferAtomicGenericInstruction;
2818 def G_AMDGPU_BUFFER_ATOMIC_AND : BufferAtomicGenericInstruction;
2819 def G_AMDGPU_BUFFER_ATOMIC_OR : BufferAtomicGenericInstruction;
2820 def G_AMDGPU_BUFFER_ATOMIC_XOR : BufferAtomicGenericInstruction;
2821 def G_AMDGPU_BUFFER_ATOMIC_INC : BufferAtomicGenericInstruction;
2822 def G_AMDGPU_BUFFER_ATOMIC_DEC : BufferAtomicGenericInstruction;
2823 def G_AMDGPU_BUFFER_ATOMIC_FADD : BufferAtomicGenericInstruction;
2824 def G_AMDGPU_BUFFER_ATOMIC_FMIN : BufferAtomicGenericInstruction;
2825 def G_AMDGPU_BUFFER_ATOMIC_FMAX : BufferAtomicGenericInstruction;
2827 def G_AMDGPU_BUFFER_ATOMIC_CMPSWAP : AMDGPUGenericInstruction {
2828 let OutOperandList = (outs type0:$dst);
2829 let InOperandList = (ins type0:$vdata, type0:$cmp, type1:$rsrc, type2:$vindex,
2830 type2:$voffset, type2:$soffset, untyped_imm_0:$offset,
2831 untyped_imm_0:$cachepolicy, untyped_imm_0:$idxen);
2832 let hasSideEffects = 0;
2837 // Wrapper around llvm.amdgcn.s.buffer.load. This is mostly needed as
2838 // a workaround for the intrinsic being defined as readnone, but
2839 // really needs a memory operand.
2840 def G_AMDGPU_S_BUFFER_LOAD : AMDGPUGenericInstruction {
2841 let OutOperandList = (outs type0:$dst);
2842 let InOperandList = (ins type1:$rsrc, type2:$offset, untyped_imm_0:$cachepolicy);
2843 let hasSideEffects = 0;
2848 // This is equivalent to the G_INTRINSIC*, but the operands may have
2849 // been legalized depending on the subtarget requirements.
2850 def G_AMDGPU_INTRIN_IMAGE_LOAD : AMDGPUGenericInstruction {
2851 let OutOperandList = (outs type0:$dst);
2852 let InOperandList = (ins unknown:$intrin, variable_ops);
2853 let hasSideEffects = 0;
2856 // FIXME: Use separate opcode for atomics.
2860 // This is equivalent to the G_INTRINSIC*, but the operands may have
2861 // been legalized depending on the subtarget requirements.
2862 def G_AMDGPU_INTRIN_IMAGE_STORE : AMDGPUGenericInstruction {
2863 let OutOperandList = (outs);
2864 let InOperandList = (ins unknown:$intrin, variable_ops);
2865 let hasSideEffects = 0;
2869 def G_AMDGPU_INTRIN_BVH_INTERSECT_RAY : AMDGPUGenericInstruction {
2870 let OutOperandList = (outs type0:$dst);
2871 let InOperandList = (ins unknown:$intrin, variable_ops);
2872 let hasSideEffects = 0;