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 let hasSideEffects = 0, mayLoad = 0, mayStore = 0, Uses = [EXEC] in {
97 // For use in patterns
98 def V_CNDMASK_B64_PSEUDO : VOP3Common <(outs VReg_64:$vdst),
99 (ins VSrc_b64:$src0, VSrc_b64:$src1, SSrc_b64:$src2), "", []> {
101 let isCodeGenOnly = 1;
102 let usesCustomInserter = 1;
105 // 64-bit vector move instruction. This is mainly used by the
106 // SIFoldOperands pass to enable folding of inline immediates.
107 def V_MOV_B64_PSEUDO : VPseudoInstSI <(outs VReg_64:$vdst),
108 (ins VSrc_b64:$src0)>;
110 // Pseudoinstruction for @llvm.amdgcn.wqm. It is turned into a copy after the
111 // WQM pass processes it.
112 def WQM : PseudoInstSI <(outs unknown:$vdst), (ins unknown:$src0)>;
114 // Pseudoinstruction for @llvm.amdgcn.softwqm. Like @llvm.amdgcn.wqm it is
115 // turned into a copy by WQM pass, but does not seed WQM requirements.
116 def SOFT_WQM : PseudoInstSI <(outs unknown:$vdst), (ins unknown:$src0)>;
118 // Pseudoinstruction for @llvm.amdgcn.wwm. It is turned into a copy post-RA, so
119 // that the @earlyclobber is respected. The @earlyclobber is to make sure that
120 // the instruction that defines $src0 (which is run in WWM) doesn't
121 // accidentally clobber inactive channels of $vdst.
122 let Constraints = "@earlyclobber $vdst" in {
123 def WWM : PseudoInstSI <(outs unknown:$vdst), (ins unknown:$src0)>;
126 } // End let hasSideEffects = 0, mayLoad = 0, mayStore = 0, Uses = [EXEC]
128 def ENTER_WWM : SPseudoInstSI <(outs SReg_1:$sdst), (ins i64imm:$src0)> {
130 let hasSideEffects = 0;
135 def EXIT_WWM : SPseudoInstSI <(outs SReg_1:$sdst), (ins SReg_1:$src0)> {
136 let hasSideEffects = 0;
141 // Invert the exec mask and overwrite the inactive lanes of dst with inactive,
142 // restoring it after we're done.
143 def V_SET_INACTIVE_B32 : VPseudoInstSI <(outs VGPR_32:$vdst),
144 (ins VGPR_32: $src, VSrc_b32:$inactive),
145 [(set i32:$vdst, (int_amdgcn_set_inactive i32:$src, i32:$inactive))]> {
146 let Constraints = "$src = $vdst";
149 def V_SET_INACTIVE_B64 : VPseudoInstSI <(outs VReg_64:$vdst),
150 (ins VReg_64: $src, VSrc_b64:$inactive),
151 [(set i64:$vdst, (int_amdgcn_set_inactive i64:$src, i64:$inactive))]> {
152 let Constraints = "$src = $vdst";
156 let usesCustomInserter = 1, Defs = [SCC] in {
157 def S_ADD_U64_PSEUDO : SPseudoInstSI <
158 (outs SReg_64:$vdst), (ins SSrc_b64:$src0, SSrc_b64:$src1),
159 [(set SReg_64:$vdst, (add i64:$src0, i64:$src1))]
162 def S_SUB_U64_PSEUDO : SPseudoInstSI <
163 (outs SReg_64:$vdst), (ins SSrc_b64:$src0, SSrc_b64:$src1),
164 [(set SReg_64:$vdst, (sub i64:$src0, i64:$src1))]
167 def S_ADD_U64_CO_PSEUDO : SPseudoInstSI <
168 (outs SReg_64:$vdst, VOPDstS64orS32:$sdst), (ins SSrc_b64:$src0, SSrc_b64:$src1)
171 def S_SUB_U64_CO_PSEUDO : SPseudoInstSI <
172 (outs SReg_64:$vdst, VOPDstS64orS32:$sdst), (ins SSrc_b64:$src0, SSrc_b64:$src1)
174 } // End usesCustomInserter = 1, Defs = [SCC]
176 let usesCustomInserter = 1 in {
177 def GET_GROUPSTATICSIZE : SPseudoInstSI <(outs SReg_32:$sdst), (ins),
178 [(set SReg_32:$sdst, (int_amdgcn_groupstaticsize))]>;
179 } // End let usesCustomInserter = 1, SALU = 1
181 // Wrap an instruction by duplicating it, except for setting isTerminator.
182 class WrapTerminatorInst<SOP_Pseudo base_inst> : SPseudoInstSI<
183 base_inst.OutOperandList,
184 base_inst.InOperandList> {
185 let Uses = base_inst.Uses;
186 let Defs = base_inst.Defs;
187 let isTerminator = 1;
188 let isAsCheapAsAMove = base_inst.isAsCheapAsAMove;
189 let hasSideEffects = base_inst.hasSideEffects;
190 let UseNamedOperandTable = base_inst.UseNamedOperandTable;
191 let CodeSize = base_inst.CodeSize;
194 let WaveSizePredicate = isWave64 in {
195 def S_MOV_B64_term : WrapTerminatorInst<S_MOV_B64>;
196 def S_XOR_B64_term : WrapTerminatorInst<S_XOR_B64>;
197 def S_ANDN2_B64_term : WrapTerminatorInst<S_ANDN2_B64>;
200 let WaveSizePredicate = isWave32 in {
201 def S_MOV_B32_term : WrapTerminatorInst<S_MOV_B32>;
202 def S_XOR_B32_term : WrapTerminatorInst<S_XOR_B32>;
203 def S_OR_B32_term : WrapTerminatorInst<S_OR_B32>;
204 def S_ANDN2_B32_term : WrapTerminatorInst<S_ANDN2_B32>;
207 def WAVE_BARRIER : SPseudoInstSI<(outs), (ins),
208 [(int_amdgcn_wave_barrier)]> {
210 let hasNoSchedulingInfo = 1;
211 let hasSideEffects = 1;
214 let isConvergent = 1;
219 // SI pseudo instructions. These are used by the CFG structurizer pass
220 // and should be lowered to ISA instructions prior to codegen.
222 // Dummy terminator instruction to use after control flow instructions
223 // replaced with exec mask operations.
224 def SI_MASK_BRANCH : VPseudoInstSI <
225 (outs), (ins brtarget:$target)> {
227 let isTerminator = 1;
230 let hasNoSchedulingInfo = 1;
235 let isTerminator = 1 in {
237 let OtherPredicates = [EnableLateCFGStructurize] in {
238 def SI_NON_UNIFORM_BRCOND_PSEUDO : CFPseudoInstSI <
240 (ins SReg_1:$vcc, brtarget:$target),
241 [(brcond i1:$vcc, bb:$target)]> {
246 def SI_IF: CFPseudoInstSI <
247 (outs SReg_1:$dst), (ins SReg_1:$vcc, brtarget:$target),
248 [(set i1:$dst, (AMDGPUif i1:$vcc, bb:$target))], 1, 1> {
249 let Constraints = "";
251 let hasSideEffects = 1;
254 def SI_ELSE : CFPseudoInstSI <
256 (ins SReg_1:$src, brtarget:$target, i1imm:$execfix), [], 1, 1> {
258 let hasSideEffects = 1;
261 def SI_LOOP : CFPseudoInstSI <
262 (outs), (ins SReg_1:$saved, brtarget:$target),
263 [(AMDGPUloop i1:$saved, bb:$target)], 1, 1> {
266 let hasSideEffects = 1;
269 } // End isTerminator = 1
271 def SI_END_CF : CFPseudoInstSI <
272 (outs), (ins SReg_1:$saved), [], 1, 1> {
274 let isAsCheapAsAMove = 1;
275 let isReMaterializable = 1;
276 let hasSideEffects = 1;
277 let mayLoad = 1; // FIXME: Should not need memory flags
281 def SI_IF_BREAK : CFPseudoInstSI <
282 (outs SReg_1:$dst), (ins SReg_1:$vcc, SReg_1:$src), []> {
284 let isAsCheapAsAMove = 1;
285 let isReMaterializable = 1;
288 let Uses = [EXEC] in {
290 multiclass PseudoInstKill <dag ins> {
291 // Even though this pseudo can usually be expanded without an SCC def, we
292 // conservatively assume that it has an SCC def, both because it is sometimes
293 // required in degenerate cases (when V_CMPX cannot be used due to constant
294 // bus limitations) and because it allows us to avoid having to track SCC
295 // liveness across basic blocks.
296 let Defs = [EXEC,VCC,SCC] in
297 def _PSEUDO : PseudoInstSI <(outs), ins> {
298 let isConvergent = 1;
299 let usesCustomInserter = 1;
302 let Defs = [EXEC,VCC,SCC] in
303 def _TERMINATOR : SPseudoInstSI <(outs), ins> {
304 let isTerminator = 1;
308 defm SI_KILL_I1 : PseudoInstKill <(ins SCSrc_i1:$src, i1imm:$killvalue)>;
309 defm SI_KILL_F32_COND_IMM : PseudoInstKill <(ins VSrc_b32:$src0, i32imm:$src1, i32imm:$cond)>;
311 let Defs = [EXEC,VCC] in
312 def SI_ILLEGAL_COPY : SPseudoInstSI <
313 (outs unknown:$dst), (ins unknown:$src),
314 [], " ; illegal copy $src to $dst">;
316 } // End Uses = [EXEC], Defs = [EXEC,VCC]
318 // Branch on undef scc. Used to avoid intermediate copy from
319 // IMPLICIT_DEF to SCC.
320 def SI_BR_UNDEF : SPseudoInstSI <(outs), (ins sopp_brtarget:$simm16)> {
321 let isTerminator = 1;
322 let usesCustomInserter = 1;
326 def SI_PS_LIVE : PseudoInstSI <
327 (outs SReg_1:$dst), (ins),
328 [(set i1:$dst, (int_amdgcn_ps_live))]> {
332 def SI_MASKED_UNREACHABLE : SPseudoInstSI <(outs), (ins),
333 [(int_amdgcn_unreachable)],
334 "; divergent unreachable"> {
336 let hasNoSchedulingInfo = 1;
340 // Used as an isel pseudo to directly emit initialization with an
341 // s_mov_b32 rather than a copy of another initialized
342 // register. MachineCSE skips copies, and we don't want to have to
343 // fold operands before it runs.
344 def SI_INIT_M0 : SPseudoInstSI <(outs), (ins SSrc_b32:$src)> {
346 let usesCustomInserter = 1;
347 let isAsCheapAsAMove = 1;
348 let isReMaterializable = 1;
351 def SI_INIT_EXEC : SPseudoInstSI <
352 (outs), (ins i64imm:$src),
353 [(int_amdgcn_init_exec (i64 timm:$src))]> {
355 let usesCustomInserter = 1;
356 let isAsCheapAsAMove = 1;
357 let WaveSizePredicate = isWave64;
360 // FIXME: Intrinsic should be mangled for wave size.
361 def SI_INIT_EXEC_LO : SPseudoInstSI <
362 (outs), (ins i32imm:$src), []> {
363 let Defs = [EXEC_LO];
364 let usesCustomInserter = 1;
365 let isAsCheapAsAMove = 1;
366 let WaveSizePredicate = isWave32;
369 // FIXME: Wave32 version
370 def SI_INIT_EXEC_FROM_INPUT : SPseudoInstSI <
371 (outs), (ins SSrc_b32:$input, i32imm:$shift),
372 [(int_amdgcn_init_exec_from_input i32:$input, (i32 timm:$shift))]> {
374 let usesCustomInserter = 1;
378 (int_amdgcn_init_exec timm:$src),
379 (SI_INIT_EXEC_LO (as_i32imm imm:$src))> {
380 let WaveSizePredicate = isWave32;
383 // Return for returning shaders to a shader variant epilog.
384 def SI_RETURN_TO_EPILOG : SPseudoInstSI <
385 (outs), (ins variable_ops), [(AMDGPUreturn_to_epilog)]> {
386 let isTerminator = 1;
389 let hasNoSchedulingInfo = 1;
394 // Return for returning function calls.
395 def SI_RETURN : SPseudoInstSI <
398 let isTerminator = 1;
401 let SchedRW = [WriteBranch];
404 // Return for returning function calls without output register.
406 // This version is only needed so we can fill in the output regiter in
407 // the custom inserter.
408 def SI_CALL_ISEL : SPseudoInstSI <
409 (outs), (ins SSrc_b64:$src0, unknown:$callee),
410 [(AMDGPUcall i64:$src0, tglobaladdr:$callee)]> {
413 let SchedRW = [WriteBranch];
414 let usesCustomInserter = 1;
415 // TODO: Should really base this on the call target
416 let isConvergent = 1;
419 // Wrapper around s_swappc_b64 with extra $callee parameter to track
420 // the called function after regalloc.
421 def SI_CALL : SPseudoInstSI <
422 (outs SReg_64:$dst), (ins SSrc_b64:$src0, unknown:$callee)> {
425 let UseNamedOperandTable = 1;
426 let SchedRW = [WriteBranch];
427 // TODO: Should really base this on the call target
428 let isConvergent = 1;
431 // Tail call handling pseudo
432 def SI_TCRETURN : SPseudoInstSI <(outs),
433 (ins SSrc_b64:$src0, unknown:$callee, i32imm:$fpdiff),
434 [(AMDGPUtc_return i64:$src0, tglobaladdr:$callee, i32:$fpdiff)]> {
437 let isTerminator = 1;
440 let UseNamedOperandTable = 1;
441 let SchedRW = [WriteBranch];
442 // TODO: Should really base this on the call target
443 let isConvergent = 1;
447 def ADJCALLSTACKUP : SPseudoInstSI<
448 (outs), (ins i32imm:$amt0, i32imm:$amt1),
449 [(callseq_start timm:$amt0, timm:$amt1)],
450 "; adjcallstackup $amt0 $amt1"> {
451 let Size = 8; // Worst case. (s_add_u32 + constant)
453 let hasSideEffects = 1;
454 let usesCustomInserter = 1;
455 let SchedRW = [WriteSALU];
459 def ADJCALLSTACKDOWN : SPseudoInstSI<
460 (outs), (ins i32imm:$amt1, i32imm:$amt2),
461 [(callseq_end timm:$amt1, timm:$amt2)],
462 "; adjcallstackdown $amt1"> {
463 let Size = 8; // Worst case. (s_add_u32 + constant)
464 let hasSideEffects = 1;
465 let usesCustomInserter = 1;
466 let SchedRW = [WriteSALU];
470 let Defs = [M0, EXEC, SCC],
471 UseNamedOperandTable = 1 in {
473 class SI_INDIRECT_SRC<RegisterClass rc> : VPseudoInstSI <
474 (outs VGPR_32:$vdst),
475 (ins rc:$src, VS_32:$idx, i32imm:$offset)> {
476 let usesCustomInserter = 1;
479 class SI_INDIRECT_DST<RegisterClass rc> : VPseudoInstSI <
481 (ins rc:$src, VS_32:$idx, i32imm:$offset, VGPR_32:$val)> {
482 let Constraints = "$src = $vdst";
483 let usesCustomInserter = 1;
486 // TODO: We can support indirect SGPR access.
487 def SI_INDIRECT_SRC_V1 : SI_INDIRECT_SRC<VGPR_32>;
488 def SI_INDIRECT_SRC_V2 : SI_INDIRECT_SRC<VReg_64>;
489 def SI_INDIRECT_SRC_V4 : SI_INDIRECT_SRC<VReg_128>;
490 def SI_INDIRECT_SRC_V8 : SI_INDIRECT_SRC<VReg_256>;
491 def SI_INDIRECT_SRC_V16 : SI_INDIRECT_SRC<VReg_512>;
493 def SI_INDIRECT_DST_V1 : SI_INDIRECT_DST<VGPR_32>;
494 def SI_INDIRECT_DST_V2 : SI_INDIRECT_DST<VReg_64>;
495 def SI_INDIRECT_DST_V4 : SI_INDIRECT_DST<VReg_128>;
496 def SI_INDIRECT_DST_V8 : SI_INDIRECT_DST<VReg_256>;
497 def SI_INDIRECT_DST_V16 : SI_INDIRECT_DST<VReg_512>;
499 } // End Uses = [EXEC], Defs = [M0, EXEC]
501 multiclass SI_SPILL_SGPR <RegisterClass sgpr_class> {
502 let UseNamedOperandTable = 1, SGPRSpill = 1, Uses = [EXEC] in {
503 def _SAVE : PseudoInstSI <
505 (ins sgpr_class:$data, i32imm:$addr)> {
510 def _RESTORE : PseudoInstSI <
511 (outs sgpr_class:$data),
512 (ins i32imm:$addr)> {
516 } // End UseNamedOperandTable = 1
519 // You cannot use M0 as the output of v_readlane_b32 instructions or
520 // use it in the sdata operand of SMEM instructions. We still need to
521 // be able to spill the physical register m0, so allow it for
522 // SI_SPILL_32_* instructions.
523 defm SI_SPILL_S32 : SI_SPILL_SGPR <SReg_32>;
524 defm SI_SPILL_S64 : SI_SPILL_SGPR <SReg_64>;
525 defm SI_SPILL_S96 : SI_SPILL_SGPR <SReg_96>;
526 defm SI_SPILL_S128 : SI_SPILL_SGPR <SReg_128>;
527 defm SI_SPILL_S160 : SI_SPILL_SGPR <SReg_160>;
528 defm SI_SPILL_S256 : SI_SPILL_SGPR <SReg_256>;
529 defm SI_SPILL_S512 : SI_SPILL_SGPR <SReg_512>;
530 defm SI_SPILL_S1024 : SI_SPILL_SGPR <SReg_1024>;
532 multiclass SI_SPILL_VGPR <RegisterClass vgpr_class> {
533 let UseNamedOperandTable = 1, VGPRSpill = 1,
534 SchedRW = [WriteVMEM] in {
535 def _SAVE : VPseudoInstSI <
537 (ins vgpr_class:$vdata, i32imm:$vaddr, SReg_128:$srsrc,
538 SReg_32:$soffset, i32imm:$offset)> {
541 // (2 * 4) + (8 * num_subregs) bytes maximum
542 int MaxSize = !add(!shl(!srl(vgpr_class.Size, 5), 3), 8);
543 // Size field is unsigned char and cannot fit more.
544 let Size = !if(!le(MaxSize, 256), MaxSize, 252);
547 def _RESTORE : VPseudoInstSI <
548 (outs vgpr_class:$vdata),
549 (ins i32imm:$vaddr, SReg_128:$srsrc, SReg_32:$soffset,
554 // (2 * 4) + (8 * num_subregs) bytes maximum
555 int MaxSize = !add(!shl(!srl(vgpr_class.Size, 5), 3), 8);
556 // Size field is unsigned char and cannot fit more.
557 let Size = !if(!le(MaxSize, 256), MaxSize, 252);
559 } // End UseNamedOperandTable = 1, VGPRSpill = 1, SchedRW = [WriteVMEM]
562 defm SI_SPILL_V32 : SI_SPILL_VGPR <VGPR_32>;
563 defm SI_SPILL_V64 : SI_SPILL_VGPR <VReg_64>;
564 defm SI_SPILL_V96 : SI_SPILL_VGPR <VReg_96>;
565 defm SI_SPILL_V128 : SI_SPILL_VGPR <VReg_128>;
566 defm SI_SPILL_V160 : SI_SPILL_VGPR <VReg_160>;
567 defm SI_SPILL_V256 : SI_SPILL_VGPR <VReg_256>;
568 defm SI_SPILL_V512 : SI_SPILL_VGPR <VReg_512>;
569 defm SI_SPILL_V1024 : SI_SPILL_VGPR <VReg_1024>;
571 multiclass SI_SPILL_AGPR <RegisterClass vgpr_class> {
572 let UseNamedOperandTable = 1, VGPRSpill = 1,
573 Constraints = "@earlyclobber $tmp",
574 SchedRW = [WriteVMEM] in {
575 def _SAVE : VPseudoInstSI <
577 (ins vgpr_class:$vdata, i32imm:$vaddr, SReg_128:$srsrc,
578 SReg_32:$soffset, i32imm:$offset)> {
581 // (2 * 4) + (16 * num_subregs) bytes maximum
582 int MaxSize = !add(!shl(!srl(vgpr_class.Size, 5), 4), 8);
583 // Size field is unsigned char and cannot fit more.
584 let Size = !if(!le(MaxSize, 256), MaxSize, 252);
587 def _RESTORE : VPseudoInstSI <
588 (outs vgpr_class:$vdata, VGPR_32:$tmp),
589 (ins i32imm:$vaddr, SReg_128:$srsrc, SReg_32:$soffset,
594 // (2 * 4) + (16 * num_subregs) bytes maximum
595 int MaxSize = !add(!shl(!srl(vgpr_class.Size, 5), 4), 8);
596 // Size field is unsigned char and cannot fit more.
597 let Size = !if(!le(MaxSize, 256), MaxSize, 252);
599 } // End UseNamedOperandTable = 1, VGPRSpill = 1, SchedRW = [WriteVMEM]
602 defm SI_SPILL_A32 : SI_SPILL_AGPR <AGPR_32>;
603 defm SI_SPILL_A64 : SI_SPILL_AGPR <AReg_64>;
604 defm SI_SPILL_A128 : SI_SPILL_AGPR <AReg_128>;
605 defm SI_SPILL_A512 : SI_SPILL_AGPR <AReg_512>;
606 defm SI_SPILL_A1024 : SI_SPILL_AGPR <AReg_1024>;
608 def SI_PC_ADD_REL_OFFSET : SPseudoInstSI <
610 (ins si_ga:$ptr_lo, si_ga:$ptr_hi),
612 (i64 (SIpc_add_rel_offset tglobaladdr:$ptr_lo, tglobaladdr:$ptr_hi)))]> {
617 (SIpc_add_rel_offset tglobaladdr:$ptr_lo, 0),
618 (SI_PC_ADD_REL_OFFSET $ptr_lo, (i32 0))
622 (AMDGPUtrap timm:$trapid),
627 (AMDGPUelse i1:$src, bb:$target),
628 (SI_ELSE $src, $target, 0)
632 // -1.0 as i32 (LowerINTRINSIC_VOID converts all other constants to -1.0)
633 (AMDGPUkill (i32 -1082130432)),
634 (SI_KILL_I1_PSEUDO (i1 0), 0)
638 (int_amdgcn_kill i1:$src),
639 (SI_KILL_I1_PSEUDO $src, 0)
643 (int_amdgcn_kill (i1 (not i1:$src))),
644 (SI_KILL_I1_PSEUDO $src, -1)
648 (AMDGPUkill i32:$src),
649 (SI_KILL_F32_COND_IMM_PSEUDO $src, 0, 3) // 3 means SETOGE
653 (int_amdgcn_kill (i1 (setcc f32:$src, InlineFPImm<f32>:$imm, cond:$cond))),
654 (SI_KILL_F32_COND_IMM_PSEUDO $src, (bitcast_fpimm_to_i32 $imm), (cond_as_i32imm $cond))
657 // TODO: we could add more variants for other types of conditionals
660 (i64 (int_amdgcn_icmp i1:$src, (i1 0), (i32 33))),
661 (COPY $src) // Return the SGPRs representing i1 src
665 (i32 (int_amdgcn_icmp i1:$src, (i1 0), (i32 33))),
666 (COPY $src) // Return the SGPRs representing i1 src
669 //===----------------------------------------------------------------------===//
671 //===----------------------------------------------------------------------===//
673 let OtherPredicates = [UnsafeFPMath] in {
675 //def : RcpPat<V_RCP_F64_e32, f64>;
676 //defm : RsqPat<V_RSQ_F64_e32, f64>;
677 //defm : RsqPat<V_RSQ_F32_e32, f32>;
679 def : RsqPat<V_RSQ_F32_e32, f32>;
680 def : RsqPat<V_RSQ_F64_e32, f64>;
682 // Convert (x - floor(x)) to fract(x)
684 (f32 (fsub (f32 (VOP3Mods f32:$x, i32:$mods)),
685 (f32 (ffloor (f32 (VOP3Mods f32:$x, i32:$mods)))))),
686 (V_FRACT_F32_e64 $mods, $x, DSTCLAMP.NONE, DSTOMOD.NONE)
689 // Convert (x + (-floor(x))) to fract(x)
691 (f64 (fadd (f64 (VOP3Mods f64:$x, i32:$mods)),
692 (f64 (fneg (f64 (ffloor (f64 (VOP3Mods f64:$x, i32:$mods)))))))),
693 (V_FRACT_F64_e64 $mods, $x, DSTCLAMP.NONE, DSTOMOD.NONE)
696 } // End OtherPredicates = [UnsafeFPMath]
699 // f16_to_fp patterns
701 (f32 (f16_to_fp i32:$src0)),
702 (V_CVT_F32_F16_e64 SRCMODS.NONE, $src0, DSTCLAMP.NONE, DSTOMOD.NONE)
706 (f32 (f16_to_fp (and_oneuse i32:$src0, 0x7fff))),
707 (V_CVT_F32_F16_e64 SRCMODS.ABS, $src0, DSTCLAMP.NONE, DSTOMOD.NONE)
711 (f32 (f16_to_fp (i32 (srl_oneuse (and_oneuse i32:$src0, 0x7fff0000), (i32 16))))),
712 (V_CVT_F32_F16_e64 SRCMODS.ABS, (i32 (V_LSHRREV_B32_e64 (i32 16), i32:$src0)), DSTCLAMP.NONE, DSTOMOD.NONE)
716 (f32 (f16_to_fp (or_oneuse i32:$src0, 0x8000))),
717 (V_CVT_F32_F16_e64 SRCMODS.NEG_ABS, $src0, DSTCLAMP.NONE, DSTOMOD.NONE)
721 (f32 (f16_to_fp (xor_oneuse i32:$src0, 0x8000))),
722 (V_CVT_F32_F16_e64 SRCMODS.NEG, $src0, DSTCLAMP.NONE, DSTOMOD.NONE)
726 (f64 (fpextend f16:$src)),
727 (V_CVT_F64_F32_e32 (V_CVT_F32_F16_e32 $src))
730 // fp_to_fp16 patterns
732 (i32 (AMDGPUfp_to_f16 (f32 (VOP3Mods f32:$src0, i32:$src0_modifiers)))),
733 (V_CVT_F16_F32_e64 $src0_modifiers, f32:$src0, DSTCLAMP.NONE, DSTOMOD.NONE)
737 (i32 (fp_to_sint f16:$src)),
738 (V_CVT_I32_F32_e32 (V_CVT_F32_F16_e32 VSrc_b32:$src))
742 (i32 (fp_to_uint f16:$src)),
743 (V_CVT_U32_F32_e32 (V_CVT_F32_F16_e32 VSrc_b32:$src))
747 (f16 (sint_to_fp i32:$src)),
748 (V_CVT_F16_F32_e32 (V_CVT_F32_I32_e32 VSrc_b32:$src))
752 (f16 (uint_to_fp i32:$src)),
753 (V_CVT_F16_F32_e32 (V_CVT_F32_U32_e32 VSrc_b32:$src))
756 //===----------------------------------------------------------------------===//
758 //===----------------------------------------------------------------------===//
760 multiclass FMADPat <ValueType vt, Instruction inst> {
762 (vt (fmad (VOP3NoMods vt:$src0),
763 (VOP3NoMods vt:$src1),
764 (VOP3NoMods vt:$src2))),
765 (inst SRCMODS.NONE, $src0, SRCMODS.NONE, $src1,
766 SRCMODS.NONE, $src2, DSTCLAMP.NONE, DSTOMOD.NONE)
770 defm : FMADPat <f16, V_MAC_F16_e64>;
771 defm : FMADPat <f32, V_MAC_F32_e64>;
773 class FMADModsPat<Instruction inst, SDPatternOperator mad_opr, ValueType Ty>
775 (Ty (mad_opr (VOP3Mods Ty:$src0, i32:$src0_mod),
776 (VOP3Mods Ty:$src1, i32:$src1_mod),
777 (VOP3Mods Ty:$src2, i32:$src2_mod))),
778 (inst $src0_mod, $src0, $src1_mod, $src1,
779 $src2_mod, $src2, DSTCLAMP.NONE, DSTOMOD.NONE)
782 def : FMADModsPat<V_MAD_F32, AMDGPUfmad_ftz, f32>;
783 def : FMADModsPat<V_MAD_F16, AMDGPUfmad_ftz, f16> {
784 let SubtargetPredicate = Has16BitInsts;
787 multiclass SelectPat <ValueType vt> {
789 (vt (select i1:$src0, (VOP3Mods_f32 vt:$src1, i32:$src1_mods),
790 (VOP3Mods_f32 vt:$src2, i32:$src2_mods))),
791 (V_CNDMASK_B32_e64 $src2_mods, $src2, $src1_mods, $src1, $src0)
795 defm : SelectPat <i16>;
796 defm : SelectPat <i32>;
797 defm : SelectPat <f16>;
798 defm : SelectPat <f32>;
800 let AddedComplexity = 1 in {
802 (i32 (add (i32 (getDivergentFrag<ctpop>.ret i32:$popcnt)), i32:$val)),
803 (V_BCNT_U32_B32_e64 $popcnt, $val)
808 (i32 (ctpop i32:$popcnt)),
809 (V_BCNT_U32_B32_e64 VSrc_b32:$popcnt, (i32 0))
813 (i16 (add (i16 (trunc (i32 (getDivergentFrag<ctpop>.ret i32:$popcnt)))), i16:$val)),
814 (V_BCNT_U32_B32_e64 $popcnt, $val)
817 /********** ============================================ **********/
818 /********** Extraction, Insertion, Building and Casting **********/
819 /********** ============================================ **********/
821 foreach Index = 0-2 in {
822 def Extract_Element_v2i32_#Index : Extract_Element <
823 i32, v2i32, Index, !cast<SubRegIndex>(sub#Index)
825 def Insert_Element_v2i32_#Index : Insert_Element <
826 i32, v2i32, Index, !cast<SubRegIndex>(sub#Index)
829 def Extract_Element_v2f32_#Index : Extract_Element <
830 f32, v2f32, Index, !cast<SubRegIndex>(sub#Index)
832 def Insert_Element_v2f32_#Index : Insert_Element <
833 f32, v2f32, Index, !cast<SubRegIndex>(sub#Index)
837 foreach Index = 0-2 in {
838 def Extract_Element_v3i32_#Index : Extract_Element <
839 i32, v3i32, Index, !cast<SubRegIndex>(sub#Index)
841 def Insert_Element_v3i32_#Index : Insert_Element <
842 i32, v3i32, Index, !cast<SubRegIndex>(sub#Index)
845 def Extract_Element_v3f32_#Index : Extract_Element <
846 f32, v3f32, Index, !cast<SubRegIndex>(sub#Index)
848 def Insert_Element_v3f32_#Index : Insert_Element <
849 f32, v3f32, Index, !cast<SubRegIndex>(sub#Index)
853 foreach Index = 0-3 in {
854 def Extract_Element_v4i32_#Index : Extract_Element <
855 i32, v4i32, Index, !cast<SubRegIndex>(sub#Index)
857 def Insert_Element_v4i32_#Index : Insert_Element <
858 i32, v4i32, Index, !cast<SubRegIndex>(sub#Index)
861 def Extract_Element_v4f32_#Index : Extract_Element <
862 f32, v4f32, Index, !cast<SubRegIndex>(sub#Index)
864 def Insert_Element_v4f32_#Index : Insert_Element <
865 f32, v4f32, Index, !cast<SubRegIndex>(sub#Index)
869 foreach Index = 0-4 in {
870 def Extract_Element_v5i32_#Index : Extract_Element <
871 i32, v5i32, Index, !cast<SubRegIndex>(sub#Index)
873 def Insert_Element_v5i32_#Index : Insert_Element <
874 i32, v5i32, Index, !cast<SubRegIndex>(sub#Index)
877 def Extract_Element_v5f32_#Index : Extract_Element <
878 f32, v5f32, Index, !cast<SubRegIndex>(sub#Index)
880 def Insert_Element_v5f32_#Index : Insert_Element <
881 f32, v5f32, Index, !cast<SubRegIndex>(sub#Index)
885 foreach Index = 0-7 in {
886 def Extract_Element_v8i32_#Index : Extract_Element <
887 i32, v8i32, Index, !cast<SubRegIndex>(sub#Index)
889 def Insert_Element_v8i32_#Index : Insert_Element <
890 i32, v8i32, Index, !cast<SubRegIndex>(sub#Index)
893 def Extract_Element_v8f32_#Index : Extract_Element <
894 f32, v8f32, Index, !cast<SubRegIndex>(sub#Index)
896 def Insert_Element_v8f32_#Index : Insert_Element <
897 f32, v8f32, Index, !cast<SubRegIndex>(sub#Index)
901 foreach Index = 0-15 in {
902 def Extract_Element_v16i32_#Index : Extract_Element <
903 i32, v16i32, Index, !cast<SubRegIndex>(sub#Index)
905 def Insert_Element_v16i32_#Index : Insert_Element <
906 i32, v16i32, Index, !cast<SubRegIndex>(sub#Index)
909 def Extract_Element_v16f32_#Index : Extract_Element <
910 f32, v16f32, Index, !cast<SubRegIndex>(sub#Index)
912 def Insert_Element_v16f32_#Index : Insert_Element <
913 f32, v16f32, Index, !cast<SubRegIndex>(sub#Index)
919 (extract_subvector v4i16:$vec, (i32 0)),
920 (v2i16 (EXTRACT_SUBREG v4i16:$vec, sub0))
924 (extract_subvector v4i16:$vec, (i32 2)),
925 (v2i16 (EXTRACT_SUBREG v4i16:$vec, sub1))
929 (extract_subvector v4f16:$vec, (i32 0)),
930 (v2f16 (EXTRACT_SUBREG v4f16:$vec, sub0))
934 (extract_subvector v4f16:$vec, (i32 2)),
935 (v2f16 (EXTRACT_SUBREG v4f16:$vec, sub1))
938 foreach Index = 0-31 in {
939 def Extract_Element_v32i32_#Index : Extract_Element <
940 i32, v32i32, Index, !cast<SubRegIndex>(sub#Index)
943 def Insert_Element_v32i32_#Index : Insert_Element <
944 i32, v32i32, Index, !cast<SubRegIndex>(sub#Index)
947 def Extract_Element_v32f32_#Index : Extract_Element <
948 f32, v32f32, Index, !cast<SubRegIndex>(sub#Index)
951 def Insert_Element_v32f32_#Index : Insert_Element <
952 f32, v32f32, Index, !cast<SubRegIndex>(sub#Index)
956 // FIXME: Why do only some of these type combinations for SReg and
959 def : BitConvert <i16, f16, VGPR_32>;
960 def : BitConvert <f16, i16, VGPR_32>;
961 def : BitConvert <i16, f16, SReg_32>;
962 def : BitConvert <f16, i16, SReg_32>;
965 def : BitConvert <i32, f32, VGPR_32>;
966 def : BitConvert <f32, i32, VGPR_32>;
967 def : BitConvert <i32, f32, SReg_32>;
968 def : BitConvert <f32, i32, SReg_32>;
969 def : BitConvert <v2i16, i32, SReg_32>;
970 def : BitConvert <i32, v2i16, SReg_32>;
971 def : BitConvert <v2f16, i32, SReg_32>;
972 def : BitConvert <i32, v2f16, SReg_32>;
973 def : BitConvert <v2i16, v2f16, SReg_32>;
974 def : BitConvert <v2f16, v2i16, SReg_32>;
975 def : BitConvert <v2f16, f32, SReg_32>;
976 def : BitConvert <f32, v2f16, SReg_32>;
977 def : BitConvert <v2i16, f32, SReg_32>;
978 def : BitConvert <f32, v2i16, SReg_32>;
981 def : BitConvert <i64, f64, VReg_64>;
982 def : BitConvert <f64, i64, VReg_64>;
983 def : BitConvert <v2i32, v2f32, VReg_64>;
984 def : BitConvert <v2f32, v2i32, VReg_64>;
985 def : BitConvert <i64, v2i32, VReg_64>;
986 def : BitConvert <v2i32, i64, VReg_64>;
987 def : BitConvert <i64, v2f32, VReg_64>;
988 def : BitConvert <v2f32, i64, VReg_64>;
989 def : BitConvert <f64, v2f32, VReg_64>;
990 def : BitConvert <v2f32, f64, VReg_64>;
991 def : BitConvert <f64, v2i32, VReg_64>;
992 def : BitConvert <v2i32, f64, VReg_64>;
993 def : BitConvert <v4i16, v4f16, VReg_64>;
994 def : BitConvert <v4f16, v4i16, VReg_64>;
997 def : BitConvert <v2i32, v4f16, VReg_64>;
998 def : BitConvert <v4f16, v2i32, VReg_64>;
999 def : BitConvert <v2i32, v4f16, VReg_64>;
1000 def : BitConvert <v2i32, v4i16, VReg_64>;
1001 def : BitConvert <v4i16, v2i32, VReg_64>;
1002 def : BitConvert <v2f32, v4f16, VReg_64>;
1003 def : BitConvert <v4f16, v2f32, VReg_64>;
1004 def : BitConvert <v2f32, v4i16, VReg_64>;
1005 def : BitConvert <v4i16, v2f32, VReg_64>;
1006 def : BitConvert <v4i16, f64, VReg_64>;
1007 def : BitConvert <v4f16, f64, VReg_64>;
1008 def : BitConvert <f64, v4i16, VReg_64>;
1009 def : BitConvert <f64, v4f16, VReg_64>;
1010 def : BitConvert <v4i16, i64, VReg_64>;
1011 def : BitConvert <v4f16, i64, VReg_64>;
1012 def : BitConvert <i64, v4i16, VReg_64>;
1013 def : BitConvert <i64, v4f16, VReg_64>;
1015 def : BitConvert <v4i32, v4f32, VReg_128>;
1016 def : BitConvert <v4f32, v4i32, VReg_128>;
1019 def : BitConvert <v3i32, v3f32, SGPR_96>;
1020 def : BitConvert <v3f32, v3i32, SGPR_96>;
1023 def : BitConvert <v2i64, v4i32, SReg_128>;
1024 def : BitConvert <v4i32, v2i64, SReg_128>;
1025 def : BitConvert <v2f64, v4f32, VReg_128>;
1026 def : BitConvert <v2f64, v4i32, VReg_128>;
1027 def : BitConvert <v4f32, v2f64, VReg_128>;
1028 def : BitConvert <v4i32, v2f64, VReg_128>;
1029 def : BitConvert <v2i64, v2f64, VReg_128>;
1030 def : BitConvert <v2f64, v2i64, VReg_128>;
1033 def : BitConvert <v5i32, v5f32, SGPR_160>;
1034 def : BitConvert <v5f32, v5i32, SGPR_160>;
1037 def : BitConvert <v8i32, v8f32, SReg_256>;
1038 def : BitConvert <v8f32, v8i32, SReg_256>;
1039 def : BitConvert <v8i32, v8f32, VReg_256>;
1040 def : BitConvert <v8f32, v8i32, VReg_256>;
1043 def : BitConvert <v16i32, v16f32, VReg_512>;
1044 def : BitConvert <v16f32, v16i32, VReg_512>;
1047 def : BitConvert <v32i32, v32f32, VReg_1024>;
1048 def : BitConvert <v32f32, v32i32, VReg_1024>;
1050 /********** =================== **********/
1051 /********** Src & Dst modifiers **********/
1052 /********** =================== **********/
1055 // If denormals are not enabled, it only impacts the compare of the
1056 // inputs. The output result is not flushed.
1057 class ClampPat<Instruction inst, ValueType vt> : GCNPat <
1058 (vt (AMDGPUclamp (VOP3Mods vt:$src0, i32:$src0_modifiers))),
1059 (inst i32:$src0_modifiers, vt:$src0,
1060 i32:$src0_modifiers, vt:$src0, DSTCLAMP.ENABLE, DSTOMOD.NONE)
1063 def : ClampPat<V_MAX_F32_e64, f32>;
1064 def : ClampPat<V_MAX_F64, f64>;
1065 def : ClampPat<V_MAX_F16_e64, f16>;
1067 let SubtargetPredicate = HasVOP3PInsts in {
1069 (v2f16 (AMDGPUclamp (VOP3PMods v2f16:$src0, i32:$src0_modifiers))),
1070 (V_PK_MAX_F16 $src0_modifiers, $src0,
1071 $src0_modifiers, $src0, DSTCLAMP.ENABLE)
1075 /********** ================================ **********/
1076 /********** Floating point absolute/negative **********/
1077 /********** ================================ **********/
1079 // Prevent expanding both fneg and fabs.
1080 // TODO: Add IgnoredBySelectionDAG bit?
1081 let AddedComplexity = 1 in { // Prefer SALU to VALU patterns for DAG
1084 (fneg (fabs (f32 SReg_32:$src))),
1085 (S_OR_B32 SReg_32:$src, (S_MOV_B32 (i32 0x80000000))) // Set sign bit
1089 (fabs (f32 SReg_32:$src)),
1090 (S_AND_B32 SReg_32:$src, (S_MOV_B32 (i32 0x7fffffff)))
1094 (fneg (f32 SReg_32:$src)),
1095 (S_XOR_B32 SReg_32:$src, (S_MOV_B32 (i32 0x80000000)))
1099 (fneg (f16 SReg_32:$src)),
1100 (S_XOR_B32 SReg_32:$src, (S_MOV_B32 (i32 0x00008000)))
1104 (fneg (f16 VGPR_32:$src)),
1105 (V_XOR_B32_e32 (S_MOV_B32 (i32 0x00008000)), VGPR_32:$src)
1109 (fabs (f16 SReg_32:$src)),
1110 (S_AND_B32 SReg_32:$src, (S_MOV_B32 (i32 0x00007fff)))
1114 (fneg (fabs (f16 SReg_32:$src))),
1115 (S_OR_B32 SReg_32:$src, (S_MOV_B32 (i32 0x00008000))) // Set sign bit
1119 (fneg (fabs (f16 VGPR_32:$src))),
1120 (V_OR_B32_e32 (S_MOV_B32 (i32 0x00008000)), VGPR_32:$src) // Set sign bit
1124 (fneg (v2f16 SReg_32:$src)),
1125 (S_XOR_B32 SReg_32:$src, (S_MOV_B32 (i32 0x80008000)))
1129 (fabs (v2f16 SReg_32:$src)),
1130 (S_AND_B32 SReg_32:$src, (S_MOV_B32 (i32 0x7fff7fff)))
1133 // This is really (fneg (fabs v2f16:$src))
1135 // fabs is not reported as free because there is modifier for it in
1136 // VOP3P instructions, so it is turned into the bit op.
1138 (fneg (v2f16 (bitconvert (and_oneuse (i32 SReg_32:$src), 0x7fff7fff)))),
1139 (S_OR_B32 SReg_32:$src, (S_MOV_B32 (i32 0x80008000))) // Set sign bit
1143 (fneg (v2f16 (fabs SReg_32:$src))),
1144 (S_OR_B32 SReg_32:$src, (S_MOV_B32 (i32 0x80008000))) // Set sign bit
1147 // FIXME: The implicit-def of scc from S_[X]OR_B32 is mishandled
1149 // (fneg (f64 SReg_64:$src)),
1150 // (REG_SEQUENCE SReg_64,
1151 // (i32 (EXTRACT_SUBREG SReg_64:$src, sub0)),
1153 // (S_XOR_B32 (i32 (EXTRACT_SUBREG SReg_64:$src, sub1)),
1154 // (i32 (S_MOV_B32 (i32 0x80000000)))),
1159 // (fneg (fabs (f64 SReg_64:$src))),
1160 // (REG_SEQUENCE SReg_64,
1161 // (i32 (EXTRACT_SUBREG SReg_64:$src, sub0)),
1163 // (S_OR_B32 (i32 (EXTRACT_SUBREG SReg_64:$src, sub1)),
1164 // (S_MOV_B32 (i32 0x80000000))), // Set sign bit.
1168 } // End let AddedComplexity = 1
1171 (fabs (f32 VGPR_32:$src)),
1172 (V_AND_B32_e32 (S_MOV_B32 (i32 0x7fffffff)), VGPR_32:$src)
1176 (fneg (f32 VGPR_32:$src)),
1177 (V_XOR_B32_e32 (S_MOV_B32 (i32 0x80000000)), VGPR_32:$src)
1181 (fabs (f16 VGPR_32:$src)),
1182 (V_AND_B32_e32 (S_MOV_B32 (i32 0x00007fff)), VGPR_32:$src)
1186 (fneg (v2f16 VGPR_32:$src)),
1187 (V_XOR_B32_e32 (S_MOV_B32 (i32 0x80008000)), VGPR_32:$src)
1191 (fabs (v2f16 VGPR_32:$src)),
1192 (V_AND_B32_e32 (S_MOV_B32 (i32 0x7fff7fff)), VGPR_32:$src)
1196 (fneg (v2f16 (fabs VGPR_32:$src))),
1197 (V_OR_B32_e32 (S_MOV_B32 (i32 0x80008000)), VGPR_32:$src) // Set sign bit
1201 (fabs (f64 VReg_64:$src)),
1202 (REG_SEQUENCE VReg_64,
1203 (i32 (EXTRACT_SUBREG VReg_64:$src, sub0)),
1205 (V_AND_B32_e64 (i32 (EXTRACT_SUBREG VReg_64:$src, sub1)),
1206 (V_MOV_B32_e32 (i32 0x7fffffff))), // Set sign bit.
1210 // TODO: Use SGPR for constant
1212 (fneg (f64 VReg_64:$src)),
1213 (REG_SEQUENCE VReg_64,
1214 (i32 (EXTRACT_SUBREG VReg_64:$src, sub0)),
1216 (V_XOR_B32_e32 (i32 (EXTRACT_SUBREG VReg_64:$src, sub1)),
1217 (i32 (V_MOV_B32_e32 (i32 0x80000000)))),
1221 // TODO: Use SGPR for constant
1223 (fneg (fabs (f64 VReg_64:$src))),
1224 (REG_SEQUENCE VReg_64,
1225 (i32 (EXTRACT_SUBREG VReg_64:$src, sub0)),
1227 (V_OR_B32_e32 (i32 (EXTRACT_SUBREG VReg_64:$src, sub1)),
1228 (V_MOV_B32_e32 (i32 0x80000000))), // Set sign bit.
1233 (fcopysign f16:$src0, f16:$src1),
1234 (V_BFI_B32 (S_MOV_B32 (i32 0x00007fff)), $src0, $src1)
1238 (fcopysign f32:$src0, f16:$src1),
1239 (V_BFI_B32 (S_MOV_B32 (i32 0x7fffffff)), $src0,
1240 (V_LSHLREV_B32_e64 (i32 16), $src1))
1244 (fcopysign f64:$src0, f16:$src1),
1245 (REG_SEQUENCE SReg_64,
1246 (i32 (EXTRACT_SUBREG $src0, sub0)), sub0,
1247 (V_BFI_B32 (S_MOV_B32 (i32 0x7fffffff)), (i32 (EXTRACT_SUBREG $src0, sub1)),
1248 (V_LSHLREV_B32_e64 (i32 16), $src1)), sub1)
1252 (fcopysign f16:$src0, f32:$src1),
1253 (V_BFI_B32 (S_MOV_B32 (i32 0x00007fff)), $src0,
1254 (V_LSHRREV_B32_e64 (i32 16), $src1))
1258 (fcopysign f16:$src0, f64:$src1),
1259 (V_BFI_B32 (S_MOV_B32 (i32 0x00007fff)), $src0,
1260 (V_LSHRREV_B32_e64 (i32 16), (EXTRACT_SUBREG $src1, sub1)))
1263 /********** ================== **********/
1264 /********** Immediate Patterns **********/
1265 /********** ================== **********/
1268 (VGPRImm<(i32 imm)>:$imm),
1269 (V_MOV_B32_e32 imm:$imm)
1273 (VGPRImm<(f32 fpimm)>:$imm),
1274 (V_MOV_B32_e32 (f32 (bitcast_fpimm_to_i32 $imm)))
1279 (S_MOV_B32 imm:$imm)
1283 (VGPRImm<(SIlds tglobaladdr:$ga)>),
1288 (SIlds tglobaladdr:$ga),
1292 // FIXME: Workaround for ordering issue with peephole optimizer where
1293 // a register class copy interferes with immediate folding. Should
1294 // use s_mov_b32, which can be shrunk to s_movk_i32
1296 (VGPRImm<(f16 fpimm)>:$imm),
1297 (V_MOV_B32_e32 (f16 (bitcast_fpimm_to_i32 $imm)))
1302 (S_MOV_B32 (f32 (bitcast_fpimm_to_i32 $imm)))
1307 (S_MOV_B32 (i32 (bitcast_fpimm_to_i32 $imm)))
1311 (i32 frameindex:$fi),
1312 (V_MOV_B32_e32 (i32 (frameindex_to_targetframeindex $fi)))
1316 (i64 InlineImm<i64>:$imm),
1317 (S_MOV_B64 InlineImm<i64>:$imm)
1320 // XXX - Should this use a s_cmp to set SCC?
1322 // Set to sign-extended 64-bit value (true = -1, false = 0)
1325 (S_MOV_B64 (i64 (as_i64imm $imm)))
1327 let WaveSizePredicate = isWave64;
1332 (S_MOV_B32 (i32 (as_i32imm $imm)))
1334 let WaveSizePredicate = isWave32;
1338 (f64 InlineFPImm<f64>:$imm),
1339 (S_MOV_B64 (f64 (bitcast_fpimm_to_i64 InlineFPImm<f64>:$imm)))
1342 /********** ================== **********/
1343 /********** Intrinsic Patterns **********/
1344 /********** ================== **********/
1346 def : POW_Common <V_LOG_F32_e32, V_EXP_F32_e32, V_MUL_LEGACY_F32_e32>;
1349 (i32 (sext i1:$src0)),
1350 (V_CNDMASK_B32_e64 /*src0mod*/(i32 0), /*src0*/(i32 0),
1351 /*src1mod*/(i32 0), /*src1*/(i32 -1), $src0)
1354 class Ext32Pat <SDNode ext> : GCNPat <
1355 (i32 (ext i1:$src0)),
1356 (V_CNDMASK_B32_e64 /*src0mod*/(i32 0), /*src0*/(i32 0),
1357 /*src1mod*/(i32 0), /*src1*/(i32 1), $src0)
1360 def : Ext32Pat <zext>;
1361 def : Ext32Pat <anyext>;
1363 // The multiplication scales from [0,1] to the unsigned integer range
1365 (AMDGPUurecip i32:$src0),
1367 (V_MUL_F32_e32 (i32 CONST.FP_UINT_MAX_PLUS_1),
1368 (V_RCP_IFLAG_F32_e32 (V_CVT_F32_U32_e32 $src0))))
1371 //===----------------------------------------------------------------------===//
1373 //===----------------------------------------------------------------------===//
1375 def : IMad24Pat<V_MAD_I32_I24, 1>;
1376 def : UMad24Pat<V_MAD_U32_U24, 1>;
1378 // FIXME: This should only be done for VALU inputs
1379 defm : BFIPatterns <V_BFI_B32, S_MOV_B32, SReg_64>;
1380 def : ROTRPattern <V_ALIGNBIT_B32>;
1382 def : GCNPat<(i32 (trunc (srl i64:$src0, (and i32:$src1, (i32 31))))),
1383 (V_ALIGNBIT_B32 (i32 (EXTRACT_SUBREG (i64 $src0), sub1)),
1384 (i32 (EXTRACT_SUBREG (i64 $src0), sub0)), $src1)>;
1386 def : GCNPat<(i32 (trunc (srl i64:$src0, (i32 ShiftAmt32Imm:$src1)))),
1387 (V_ALIGNBIT_B32 (i32 (EXTRACT_SUBREG (i64 $src0), sub1)),
1388 (i32 (EXTRACT_SUBREG (i64 $src0), sub0)), $src1)>;
1390 /********** ====================== **********/
1391 /********** Indirect addressing **********/
1392 /********** ====================== **********/
1394 multiclass SI_INDIRECT_Pattern <ValueType vt, ValueType eltvt, string VecSize> {
1395 // Extract with offset
1397 (eltvt (extractelt vt:$src, (MOVRELOffset i32:$idx, (i32 imm:$offset)))),
1398 (!cast<Instruction>("SI_INDIRECT_SRC_"#VecSize) $src, $idx, imm:$offset)
1401 // Insert with offset
1403 (insertelt vt:$src, eltvt:$val, (MOVRELOffset i32:$idx, (i32 imm:$offset))),
1404 (!cast<Instruction>("SI_INDIRECT_DST_"#VecSize) $src, $idx, imm:$offset, $val)
1408 defm : SI_INDIRECT_Pattern <v2f32, f32, "V2">;
1409 defm : SI_INDIRECT_Pattern <v4f32, f32, "V4">;
1410 defm : SI_INDIRECT_Pattern <v8f32, f32, "V8">;
1411 defm : SI_INDIRECT_Pattern <v16f32, f32, "V16">;
1413 defm : SI_INDIRECT_Pattern <v2i32, i32, "V2">;
1414 defm : SI_INDIRECT_Pattern <v4i32, i32, "V4">;
1415 defm : SI_INDIRECT_Pattern <v8i32, i32, "V8">;
1416 defm : SI_INDIRECT_Pattern <v16i32, i32, "V16">;
1418 //===----------------------------------------------------------------------===//
1420 //===----------------------------------------------------------------------===//
1423 (add (sub_oneuse (umax i32:$src0, i32:$src1),
1424 (umin i32:$src0, i32:$src1)),
1426 (V_SAD_U32 $src0, $src1, $src2, (i1 0))
1430 (add (select_oneuse (i1 (setugt i32:$src0, i32:$src1)),
1431 (sub i32:$src0, i32:$src1),
1432 (sub i32:$src1, i32:$src0)),
1434 (V_SAD_U32 $src0, $src1, $src2, (i1 0))
1437 //===----------------------------------------------------------------------===//
1438 // Conversion Patterns
1439 //===----------------------------------------------------------------------===//
1441 def : GCNPat<(i32 (sext_inreg i32:$src, i1)),
1442 (S_BFE_I32 i32:$src, (i32 65536))>; // 0 | 1 << 16
1444 // Handle sext_inreg in i64
1446 (i64 (sext_inreg i64:$src, i1)),
1447 (S_BFE_I64 i64:$src, (i32 0x10000)) // 0 | 1 << 16
1451 (i16 (sext_inreg i16:$src, i1)),
1452 (S_BFE_I32 $src, (i32 0x00010000)) // 0 | 1 << 16
1456 (i16 (sext_inreg i16:$src, i8)),
1457 (S_BFE_I32 $src, (i32 0x80000)) // 0 | 8 << 16
1461 (i64 (sext_inreg i64:$src, i8)),
1462 (S_BFE_I64 i64:$src, (i32 0x80000)) // 0 | 8 << 16
1466 (i64 (sext_inreg i64:$src, i16)),
1467 (S_BFE_I64 i64:$src, (i32 0x100000)) // 0 | 16 << 16
1471 (i64 (sext_inreg i64:$src, i32)),
1472 (S_BFE_I64 i64:$src, (i32 0x200000)) // 0 | 32 << 16
1476 (i64 (zext i32:$src)),
1477 (REG_SEQUENCE SReg_64, $src, sub0, (S_MOV_B32 (i32 0)), sub1)
1481 (i64 (anyext i32:$src)),
1482 (REG_SEQUENCE SReg_64, $src, sub0, (i32 (IMPLICIT_DEF)), sub1)
1485 class ZExt_i64_i1_Pat <SDNode ext> : GCNPat <
1486 (i64 (ext i1:$src)),
1487 (REG_SEQUENCE VReg_64,
1488 (V_CNDMASK_B32_e64 /*src0mod*/(i32 0), /*src0*/(i32 0),
1489 /*src1mod*/(i32 0), /*src1*/(i32 1), $src),
1490 sub0, (S_MOV_B32 (i32 0)), sub1)
1494 def : ZExt_i64_i1_Pat<zext>;
1495 def : ZExt_i64_i1_Pat<anyext>;
1497 // FIXME: We need to use COPY_TO_REGCLASS to work-around the fact that
1498 // REG_SEQUENCE patterns don't support instructions with multiple outputs.
1500 (i64 (sext i32:$src)),
1501 (REG_SEQUENCE SReg_64, $src, sub0,
1502 (i32 (COPY_TO_REGCLASS (S_ASHR_I32 $src, (i32 31)), SReg_32_XM0)), sub1)
1506 (i64 (sext i1:$src)),
1507 (REG_SEQUENCE VReg_64,
1508 (V_CNDMASK_B32_e64 /*src0mod*/(i32 0), /*src0*/(i32 0),
1509 /*src1mod*/(i32 0), /*src1*/(i32 -1), $src), sub0,
1510 (V_CNDMASK_B32_e64 /*src0mod*/(i32 0), /*src0*/(i32 0),
1511 /*src1mod*/(i32 0), /*src1*/(i32 -1), $src), sub1)
1514 class FPToI1Pat<Instruction Inst, int KOne, ValueType kone_type, ValueType vt, SDPatternOperator fp_to_int> : GCNPat <
1515 (i1 (fp_to_int (vt (VOP3Mods vt:$src0, i32:$src0_modifiers)))),
1516 (i1 (Inst 0, (kone_type KOne), $src0_modifiers, $src0, DSTCLAMP.NONE))
1519 def : FPToI1Pat<V_CMP_EQ_F32_e64, CONST.FP32_ONE, i32, f32, fp_to_uint>;
1520 def : FPToI1Pat<V_CMP_EQ_F32_e64, CONST.FP32_NEG_ONE, i32, f32, fp_to_sint>;
1521 def : FPToI1Pat<V_CMP_EQ_F64_e64, CONST.FP64_ONE, i64, f64, fp_to_uint>;
1522 def : FPToI1Pat<V_CMP_EQ_F64_e64, CONST.FP64_NEG_ONE, i64, f64, fp_to_sint>;
1524 // If we need to perform a logical operation on i1 values, we need to
1525 // use vector comparisons since there is only one SCC register. Vector
1526 // comparisons may write to a pair of SGPRs or a single SGPR, so treat
1527 // these as 32 or 64-bit comparisons. When legalizing SGPR copies,
1528 // instructions resulting in the copies from SCC to these instructions
1529 // will be moved to the VALU.
1531 let WaveSizePredicate = isWave64 in {
1533 (i1 (and i1:$src0, i1:$src1)),
1534 (S_AND_B64 $src0, $src1)
1538 (i1 (or i1:$src0, i1:$src1)),
1539 (S_OR_B64 $src0, $src1)
1543 (i1 (xor i1:$src0, i1:$src1)),
1544 (S_XOR_B64 $src0, $src1)
1548 (i1 (add i1:$src0, i1:$src1)),
1549 (S_XOR_B64 $src0, $src1)
1553 (i1 (sub i1:$src0, i1:$src1)),
1554 (S_XOR_B64 $src0, $src1)
1557 let AddedComplexity = 1 in {
1559 (i1 (add i1:$src0, (i1 -1))),
1564 (i1 (sub i1:$src0, (i1 -1))),
1570 let WaveSizePredicate = isWave32 in {
1572 (i1 (and i1:$src0, i1:$src1)),
1573 (S_AND_B32 $src0, $src1)
1577 (i1 (or i1:$src0, i1:$src1)),
1578 (S_OR_B32 $src0, $src1)
1582 (i1 (xor i1:$src0, i1:$src1)),
1583 (S_XOR_B32 $src0, $src1)
1587 (i1 (add i1:$src0, i1:$src1)),
1588 (S_XOR_B32 $src0, $src1)
1592 (i1 (sub i1:$src0, i1:$src1)),
1593 (S_XOR_B32 $src0, $src1)
1596 let AddedComplexity = 1 in {
1598 (i1 (add i1:$src0, (i1 -1))),
1603 (i1 (sub i1:$src0, (i1 -1))),
1610 (f16 (sint_to_fp i1:$src)),
1611 (V_CVT_F16_F32_e32 (
1612 V_CNDMASK_B32_e64 /*src0mod*/(i32 0), /*src0*/(i32 0),
1613 /*src1mod*/(i32 0), /*src1*/(i32 CONST.FP32_NEG_ONE),
1618 (f16 (uint_to_fp i1:$src)),
1619 (V_CVT_F16_F32_e32 (
1620 V_CNDMASK_B32_e64 /*src0mod*/(i32 0), /*src0*/(i32 0),
1621 /*src1mod*/(i32 0), /*src1*/(i32 CONST.FP32_ONE),
1626 (f32 (sint_to_fp i1:$src)),
1627 (V_CNDMASK_B32_e64 /*src0mod*/(i32 0), /*src0*/(i32 0),
1628 /*src1mod*/(i32 0), /*src1*/(i32 CONST.FP32_NEG_ONE),
1633 (f32 (uint_to_fp i1:$src)),
1634 (V_CNDMASK_B32_e64 /*src0mod*/(i32 0), /*src0*/(i32 0),
1635 /*src1mod*/(i32 0), /*src1*/(i32 CONST.FP32_ONE),
1640 (f64 (sint_to_fp i1:$src)),
1641 (V_CVT_F64_I32_e32 (V_CNDMASK_B32_e64 /*src0mod*/(i32 0), /*src0*/(i32 0),
1642 /*src1mod*/(i32 0), /*src1*/(i32 -1),
1647 (f64 (uint_to_fp i1:$src)),
1648 (V_CVT_F64_U32_e32 (V_CNDMASK_B32_e64 /*src0mod*/(i32 0), /*src0*/(i32 0),
1649 /*src1mod*/(i32 0), /*src1*/(i32 1),
1653 //===----------------------------------------------------------------------===//
1654 // Miscellaneous Patterns
1655 //===----------------------------------------------------------------------===//
1657 (i32 (AMDGPUfp16_zext f16:$src)),
1663 (i32 (trunc i64:$a)),
1664 (EXTRACT_SUBREG $a, sub0)
1668 (i1 (trunc i32:$a)),
1669 (V_CMP_EQ_U32_e64 (S_AND_B32 (i32 1), $a), (i32 1))
1673 (i1 (trunc i16:$a)),
1674 (V_CMP_EQ_U32_e64 (S_AND_B32 (i32 1), $a), (i32 1))
1678 (i1 (trunc i64:$a)),
1679 (V_CMP_EQ_U32_e64 (S_AND_B32 (i32 1),
1680 (i32 (EXTRACT_SUBREG $a, sub0))), (i32 1))
1684 (i32 (bswap i32:$a)),
1685 (V_BFI_B32 (S_MOV_B32 (i32 0x00ff00ff)),
1686 (V_ALIGNBIT_B32 $a, $a, (i32 24)),
1687 (V_ALIGNBIT_B32 $a, $a, (i32 8)))
1690 let OtherPredicates = [NoFP16Denormals] in {
1692 (fcanonicalize (f16 (VOP3Mods f16:$src, i32:$src_mods))),
1693 (V_MUL_F16_e64 0, (i32 CONST.FP16_ONE), $src_mods, $src, 0, 0)
1697 (fcanonicalize (f16 (fneg (VOP3Mods f16:$src, i32:$src_mods)))),
1698 (V_MUL_F16_e64 0, (i32 CONST.FP16_NEG_ONE), $src_mods, $src, 0, 0)
1702 (fcanonicalize (v2f16 (VOP3PMods v2f16:$src, i32:$src_mods))),
1703 (V_PK_MUL_F16 0, (i32 CONST.FP16_ONE), $src_mods, $src, DSTCLAMP.NONE)
1707 let OtherPredicates = [FP16Denormals] in {
1709 (fcanonicalize (f16 (VOP3Mods f16:$src, i32:$src_mods))),
1710 (V_MAX_F16_e64 $src_mods, $src, $src_mods, $src, 0, 0)
1713 let SubtargetPredicate = HasVOP3PInsts in {
1715 (fcanonicalize (v2f16 (VOP3PMods v2f16:$src, i32:$src_mods))),
1716 (V_PK_MAX_F16 $src_mods, $src, $src_mods, $src, DSTCLAMP.NONE)
1721 let OtherPredicates = [NoFP32Denormals] in {
1723 (fcanonicalize (f32 (VOP3Mods f32:$src, i32:$src_mods))),
1724 (V_MUL_F32_e64 0, (i32 CONST.FP32_ONE), $src_mods, $src, 0, 0)
1728 (fcanonicalize (f32 (fneg (VOP3Mods f32:$src, i32:$src_mods)))),
1729 (V_MUL_F32_e64 0, (i32 CONST.FP32_NEG_ONE), $src_mods, $src, 0, 0)
1733 let OtherPredicates = [FP32Denormals] in {
1735 (fcanonicalize (f32 (VOP3Mods f32:$src, i32:$src_mods))),
1736 (V_MAX_F32_e64 $src_mods, $src, $src_mods, $src, 0, 0)
1740 let OtherPredicates = [NoFP64Denormals] in {
1742 (fcanonicalize (f64 (VOP3Mods f64:$src, i32:$src_mods))),
1743 (V_MUL_F64 0, CONST.FP64_ONE, $src_mods, $src, 0, 0)
1747 let OtherPredicates = [FP64Denormals] in {
1749 (fcanonicalize (f64 (VOP3Mods f64:$src, i32:$src_mods))),
1750 (V_MAX_F64 $src_mods, $src, $src_mods, $src, 0, 0)
1754 let OtherPredicates = [HasDLInsts] in {
1756 (fma (f32 (VOP3Mods0 f32:$src0, i32:$src0_modifiers, i1:$clamp, i32:$omod)),
1757 (f32 (VOP3Mods f32:$src1, i32:$src1_modifiers)),
1758 (f32 (VOP3NoMods f32:$src2))),
1759 (V_FMAC_F32_e64 $src0_modifiers, $src0, $src1_modifiers, $src1,
1760 SRCMODS.NONE, $src2, $clamp, $omod)
1762 } // End OtherPredicates = [HasDLInsts]
1764 let SubtargetPredicate = isGFX10Plus in
1766 (fma (f16 (VOP3Mods0 f32:$src0, i32:$src0_modifiers, i1:$clamp, i32:$omod)),
1767 (f16 (VOP3Mods f32:$src1, i32:$src1_modifiers)),
1768 (f16 (VOP3NoMods f32:$src2))),
1769 (V_FMAC_F16_e64 $src0_modifiers, $src0, $src1_modifiers, $src1,
1770 SRCMODS.NONE, $src2, $clamp, $omod)
1773 // Allow integer inputs
1774 class ExpPattern<SDPatternOperator node, ValueType vt, Instruction Inst> : GCNPat<
1775 (node (i8 timm:$tgt), (i8 timm:$en), vt:$src0, vt:$src1, vt:$src2, vt:$src3, (i1 timm:$compr), (i1 timm:$vm)),
1776 (Inst i8:$tgt, vt:$src0, vt:$src1, vt:$src2, vt:$src3, i1:$vm, i1:$compr, i8:$en)
1779 def : ExpPattern<AMDGPUexport, i32, EXP>;
1780 def : ExpPattern<AMDGPUexport_done, i32, EXP_DONE>;
1782 // COPY is workaround tablegen bug from multiple outputs
1783 // from S_LSHL_B32's multiple outputs from implicit scc def.
1785 (v2i16 (build_vector (i16 0), i16:$src1)),
1786 (v2i16 (COPY (S_LSHL_B32 i16:$src1, (i16 16))))
1790 (v2i16 (build_vector i16:$src0, (i16 undef))),
1791 (v2i16 (COPY $src0))
1795 (v2f16 (build_vector f16:$src0, (f16 undef))),
1796 (v2f16 (COPY $src0))
1800 (v2i16 (build_vector (i16 undef), i16:$src1)),
1801 (v2i16 (COPY (S_LSHL_B32 $src1, (i32 16))))
1805 (v2f16 (build_vector (f16 undef), f16:$src1)),
1806 (v2f16 (COPY (S_LSHL_B32 $src1, (i32 16))))
1809 let SubtargetPredicate = HasVOP3PInsts in {
1811 (v2i16 (build_vector i16:$src0, i16:$src1)),
1812 (v2i16 (S_PACK_LL_B32_B16 $src0, $src1))
1815 // With multiple uses of the shift, this will duplicate the shift and
1816 // increase register pressure.
1818 (v2i16 (build_vector i16:$src0, (i16 (trunc (srl_oneuse i32:$src1, (i32 16)))))),
1819 (v2i16 (S_PACK_LH_B32_B16 i16:$src0, i32:$src1))
1824 (v2i16 (build_vector (i16 (trunc (srl_oneuse i32:$src0, (i32 16)))),
1825 (i16 (trunc (srl_oneuse i32:$src1, (i32 16)))))),
1826 (v2i16 (S_PACK_HH_B32_B16 $src0, $src1))
1829 // TODO: Should source modifiers be matched to v_pack_b32_f16?
1831 (v2f16 (build_vector f16:$src0, f16:$src1)),
1832 (v2f16 (S_PACK_LL_B32_B16 $src0, $src1))
1835 } // End SubtargetPredicate = HasVOP3PInsts
1839 (v2f16 (scalar_to_vector f16:$src0)),
1844 (v2i16 (scalar_to_vector i16:$src0)),
1849 (v4i16 (scalar_to_vector i16:$src0)),
1850 (INSERT_SUBREG (IMPLICIT_DEF), $src0, sub0)
1854 (v4f16 (scalar_to_vector f16:$src0)),
1855 (INSERT_SUBREG (IMPLICIT_DEF), $src0, sub0)
1858 //===----------------------------------------------------------------------===//
1860 //===----------------------------------------------------------------------===//
1862 let SubtargetPredicate = isGFX6 in {
1864 // V_FRACT is buggy on SI, so the F32 version is never used and (x-floor(x)) is
1865 // used instead. However, SI doesn't have V_FLOOR_F64, so the most efficient
1866 // way to implement it is using V_FRACT_F64.
1867 // The workaround for the V_FRACT bug is:
1868 // fract(x) = isnan(x) ? x : min(V_FRACT(x), 0.99999999999999999)
1870 // Convert floor(x) to (x - fract(x))
1872 (f64 (ffloor (f64 (VOP3Mods f64:$x, i32:$mods)))),
1877 (V_CNDMASK_B64_PSEUDO
1880 (V_FRACT_F64_e64 $mods, $x, DSTCLAMP.NONE, DSTOMOD.NONE),
1882 (V_MOV_B64_PSEUDO 0x3fefffffffffffff),
1883 DSTCLAMP.NONE, DSTOMOD.NONE),
1885 (V_CMP_CLASS_F64_e64 SRCMODS.NONE, $x, (i32 3 /*NaN*/))),
1886 DSTCLAMP.NONE, DSTOMOD.NONE)
1889 } // End SubtargetPredicates = isGFX6
1891 //============================================================================//
1892 // Miscellaneous Optimization Patterns
1893 //============================================================================//
1895 // Undo sub x, c -> add x, -c canonicalization since c is more likely
1896 // an inline immediate than -c.
1897 // TODO: Also do for 64-bit.
1899 (add i32:$src0, (i32 NegSubInlineConst32:$src1)),
1900 (S_SUB_I32 $src0, NegSubInlineConst32:$src1)
1903 // Avoid pointlessly materializing a constant in VGPR.
1904 // FIXME: Should also do this for readlane, but tablegen crashes on
1905 // the ignored src1.
1907 (int_amdgcn_readfirstlane (i32 imm:$src)),
1911 multiclass BFMPatterns <ValueType vt, InstSI BFM, InstSI MOV> {
1913 (vt (shl (vt (add (vt (shl 1, vt:$a)), -1)), vt:$b)),
1918 (vt (add (vt (shl 1, vt:$a)), -1)),
1919 (BFM $a, (MOV (i32 0)))
1923 defm : BFMPatterns <i32, S_BFM_B32, S_MOV_B32>;
1924 // FIXME: defm : BFMPatterns <i64, S_BFM_B64, S_MOV_B64>;
1926 defm : BFEPattern <V_BFE_U32, V_BFE_I32, S_MOV_B32>;
1927 defm : SHA256MaPattern <V_BFI_B32, V_XOR_B32_e64, SReg_64>;
1929 defm : IntMed3Pat<V_MED3_I32, smin, smax, smin_oneuse, smax_oneuse>;
1930 defm : IntMed3Pat<V_MED3_U32, umin, umax, umin_oneuse, umax_oneuse>;
1932 // This matches 16 permutations of
1933 // max(min(x, y), min(max(x, y), z))
1934 class FPMed3Pat<ValueType vt,
1935 //SDPatternOperator max, SDPatternOperator min,
1936 Instruction med3Inst> : GCNPat<
1937 (fmaxnum_like (fminnum_like_oneuse (VOP3Mods_nnan vt:$src0, i32:$src0_mods),
1938 (VOP3Mods_nnan vt:$src1, i32:$src1_mods)),
1939 (fminnum_like_oneuse (fmaxnum_like_oneuse (VOP3Mods_nnan vt:$src0, i32:$src0_mods),
1940 (VOP3Mods_nnan vt:$src1, i32:$src1_mods)),
1941 (vt (VOP3Mods_nnan vt:$src2, i32:$src2_mods)))),
1942 (med3Inst $src0_mods, $src0, $src1_mods, $src1, $src2_mods, $src2, DSTCLAMP.NONE, DSTOMOD.NONE)
1945 class FP16Med3Pat<ValueType vt,
1946 Instruction med3Inst> : GCNPat<
1947 (fmaxnum_like (fminnum_like_oneuse (VOP3Mods_nnan vt:$src0, i32:$src0_mods),
1948 (VOP3Mods_nnan vt:$src1, i32:$src1_mods)),
1949 (fminnum_like_oneuse (fmaxnum_like_oneuse (VOP3Mods_nnan vt:$src0, i32:$src0_mods),
1950 (VOP3Mods_nnan vt:$src1, i32:$src1_mods)),
1951 (vt (VOP3Mods_nnan vt:$src2, i32:$src2_mods)))),
1952 (med3Inst $src0_mods, $src0, $src1_mods, $src1, $src2_mods, $src2, DSTCLAMP.NONE)
1955 multiclass Int16Med3Pat<Instruction med3Inst,
1956 SDPatternOperator min,
1957 SDPatternOperator max,
1958 SDPatternOperator max_oneuse,
1959 SDPatternOperator min_oneuse,
1960 ValueType vt = i16> {
1961 // This matches 16 permutations of
1962 // max(min(x, y), min(max(x, y), z))
1964 (max (min_oneuse vt:$src0, vt:$src1),
1965 (min_oneuse (max_oneuse vt:$src0, vt:$src1), vt:$src2)),
1966 (med3Inst SRCMODS.NONE, $src0, SRCMODS.NONE, $src1, SRCMODS.NONE, $src2, DSTCLAMP.NONE)
1969 // This matches 16 permutations of
1970 // min(max(a, b), max(min(a, b), c))
1972 (min (max_oneuse vt:$src0, vt:$src1),
1973 (max_oneuse (min_oneuse vt:$src0, vt:$src1), vt:$src2)),
1974 (med3Inst SRCMODS.NONE, $src0, SRCMODS.NONE, $src1, SRCMODS.NONE, $src2, DSTCLAMP.NONE)
1978 def : FPMed3Pat<f32, V_MED3_F32>;
1980 let OtherPredicates = [isGFX9Plus] in {
1981 def : FP16Med3Pat<f16, V_MED3_F16>;
1982 defm : Int16Med3Pat<V_MED3_I16, smin, smax, smax_oneuse, smin_oneuse>;
1983 defm : Int16Med3Pat<V_MED3_U16, umin, umax, umax_oneuse, umin_oneuse>;
1984 } // End Predicates = [isGFX9Plus]
1986 class AMDGPUGenericInstruction : GenericInstruction {
1987 let Namespace = "AMDGPU";
1990 def G_AMDGPU_FFBH_U32 : AMDGPUGenericInstruction {
1991 let OutOperandList = (outs type0:$dst);
1992 let InOperandList = (ins type1:$src);
1993 let hasSideEffects = 0;