1 //===-- SIInstructions.td - SI Instruction Defintions ---------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
9 // This file was originally auto-generated from a GPU register header file and
10 // all the instruction definitions were originally commented out. Instructions
11 // that are not yet supported remain commented out.
12 //===----------------------------------------------------------------------===//
14 class GCNPat<dag pattern, dag result> : Pat<pattern, result>, GCNPredicateControl {
15 let SubtargetPredicate = isGCN;
18 include "VOPInstructions.td"
19 include "SOPInstructions.td"
20 include "SMInstructions.td"
21 include "FLATInstructions.td"
22 include "BUFInstructions.td"
24 //===----------------------------------------------------------------------===//
26 //===----------------------------------------------------------------------===//
28 defm EXP : EXP_m<0, AMDGPUexport>;
29 defm EXP_DONE : EXP_m<1, AMDGPUexport_done>;
31 //===----------------------------------------------------------------------===//
32 // VINTRP Instructions
33 //===----------------------------------------------------------------------===//
35 // Used to inject printing of "_e32" suffix for VI (there are "_e64" variants for VI)
36 def VINTRPDst : VINTRPDstOperand <VGPR_32>;
38 let Uses = [M0, EXEC] in {
40 // FIXME: Specify SchedRW for VINTRP insturctions.
42 multiclass V_INTERP_P1_F32_m : VINTRP_m <
44 (outs VINTRPDst:$vdst),
45 (ins VGPR_32:$vsrc, Attr:$attr, AttrChan:$attrchan),
46 "v_interp_p1_f32$vdst, $vsrc, $attr$attrchan",
47 [(set f32:$vdst, (AMDGPUinterp_p1 f32:$vsrc, (i32 imm:$attrchan),
51 let OtherPredicates = [has32BankLDS] in {
53 defm V_INTERP_P1_F32 : V_INTERP_P1_F32_m;
55 } // End OtherPredicates = [has32BankLDS]
57 let OtherPredicates = [has16BankLDS], Constraints = "@earlyclobber $vdst", isAsmParserOnly=1 in {
59 defm V_INTERP_P1_F32_16bank : V_INTERP_P1_F32_m;
61 } // End OtherPredicates = [has32BankLDS], Constraints = "@earlyclobber $vdst", isAsmParserOnly=1
63 let DisableEncoding = "$src0", Constraints = "$src0 = $vdst" in {
65 defm V_INTERP_P2_F32 : VINTRP_m <
67 (outs VINTRPDst:$vdst),
68 (ins VGPR_32:$src0, VGPR_32:$vsrc, Attr:$attr, AttrChan:$attrchan),
69 "v_interp_p2_f32$vdst, $vsrc, $attr$attrchan",
70 [(set f32:$vdst, (AMDGPUinterp_p2 f32:$src0, f32:$vsrc, (i32 imm:$attrchan),
73 } // End DisableEncoding = "$src0", Constraints = "$src0 = $vdst"
75 defm V_INTERP_MOV_F32 : VINTRP_m <
77 (outs VINTRPDst:$vdst),
78 (ins InterpSlot:$vsrc, Attr:$attr, AttrChan:$attrchan),
79 "v_interp_mov_f32$vdst, $vsrc, $attr$attrchan",
80 [(set f32:$vdst, (AMDGPUinterp_mov (i32 imm:$vsrc), (i32 imm:$attrchan),
83 } // End Uses = [M0, EXEC]
85 //===----------------------------------------------------------------------===//
86 // Pseudo Instructions
87 //===----------------------------------------------------------------------===//
88 def ATOMIC_FENCE : SPseudoInstSI<
89 (outs), (ins i32imm:$ordering, i32imm:$scope),
90 [(atomic_fence (i32 imm:$ordering), (i32 imm:$scope))],
91 "ATOMIC_FENCE $ordering, $scope"> {
92 let hasSideEffects = 1;
96 let hasSideEffects = 0, mayLoad = 0, mayStore = 0, Uses = [EXEC] in {
98 // For use in patterns
99 def V_CNDMASK_B64_PSEUDO : VOP3Common <(outs VReg_64:$vdst),
100 (ins VSrc_b64:$src0, VSrc_b64:$src1, SSrc_b64:$src2), "", []> {
102 let isCodeGenOnly = 1;
103 let usesCustomInserter = 1;
106 // 64-bit vector move instruction. This is mainly used by the
107 // SIFoldOperands pass to enable folding of inline immediates.
108 def V_MOV_B64_PSEUDO : VPseudoInstSI <(outs VReg_64:$vdst),
109 (ins VSrc_b64:$src0)>;
111 // Pseudoinstruction for @llvm.amdgcn.wqm. It is turned into a copy after the
112 // WQM pass processes it.
113 def WQM : PseudoInstSI <(outs unknown:$vdst), (ins unknown:$src0)>;
115 // Pseudoinstruction for @llvm.amdgcn.wwm. It is turned into a copy post-RA, so
116 // that the @earlyclobber is respected. The @earlyclobber is to make sure that
117 // the instruction that defines $src0 (which is run in WWM) doesn't
118 // accidentally clobber inactive channels of $vdst.
119 let Constraints = "@earlyclobber $vdst" in {
120 def WWM : PseudoInstSI <(outs unknown:$vdst), (ins unknown:$src0)>;
123 } // End let hasSideEffects = 0, mayLoad = 0, mayStore = 0, Uses = [EXEC]
125 def EXIT_WWM : SPseudoInstSI <(outs SReg_64:$sdst), (ins SReg_64:$src0)> {
126 let hasSideEffects = 0;
131 // Invert the exec mask and overwrite the inactive lanes of dst with inactive,
132 // restoring it after we're done.
133 def V_SET_INACTIVE_B32 : VPseudoInstSI <(outs VGPR_32:$vdst),
134 (ins VGPR_32: $src, VSrc_b32:$inactive),
135 [(set i32:$vdst, (int_amdgcn_set_inactive i32:$src, i32:$inactive))]> {
136 let Constraints = "$src = $vdst";
139 def V_SET_INACTIVE_B64 : VPseudoInstSI <(outs VReg_64:$vdst),
140 (ins VReg_64: $src, VSrc_b64:$inactive),
141 [(set i64:$vdst, (int_amdgcn_set_inactive i64:$src, i64:$inactive))]> {
142 let Constraints = "$src = $vdst";
146 let usesCustomInserter = 1, Defs = [SCC] in {
147 def S_ADD_U64_PSEUDO : SPseudoInstSI <
148 (outs SReg_64:$vdst), (ins SSrc_b64:$src0, SSrc_b64:$src1),
149 [(set SReg_64:$vdst, (add i64:$src0, i64:$src1))]
152 def S_SUB_U64_PSEUDO : SPseudoInstSI <
153 (outs SReg_64:$vdst), (ins SSrc_b64:$src0, SSrc_b64:$src1),
154 [(set SReg_64:$vdst, (sub i64:$src0, i64:$src1))]
157 def S_ADD_U64_CO_PSEUDO : SPseudoInstSI <
158 (outs SReg_64:$vdst, VOPDstS64:$sdst), (ins SSrc_b64:$src0, SSrc_b64:$src1)
161 def S_SUB_U64_CO_PSEUDO : SPseudoInstSI <
162 (outs SReg_64:$vdst, VOPDstS64:$sdst), (ins SSrc_b64:$src0, SSrc_b64:$src1)
165 } // End usesCustomInserter = 1, Defs = [SCC]
167 let usesCustomInserter = 1 in {
168 def GET_GROUPSTATICSIZE : SPseudoInstSI <(outs SReg_32:$sdst), (ins),
169 [(set SReg_32:$sdst, (int_amdgcn_groupstaticsize))]>;
170 } // End let usesCustomInserter = 1, SALU = 1
172 def S_MOV_B64_term : SPseudoInstSI<(outs SReg_64:$dst),
173 (ins SSrc_b64:$src0)> {
174 let isAsCheapAsAMove = 1;
175 let isTerminator = 1;
178 def S_XOR_B64_term : SPseudoInstSI<(outs SReg_64:$dst),
179 (ins SSrc_b64:$src0, SSrc_b64:$src1)> {
180 let isAsCheapAsAMove = 1;
181 let isTerminator = 1;
185 def S_ANDN2_B64_term : SPseudoInstSI<(outs SReg_64:$dst),
186 (ins SSrc_b64:$src0, SSrc_b64:$src1)> {
187 let isAsCheapAsAMove = 1;
188 let isTerminator = 1;
191 def WAVE_BARRIER : SPseudoInstSI<(outs), (ins),
192 [(int_amdgcn_wave_barrier)]> {
194 let hasNoSchedulingInfo = 1;
195 let hasSideEffects = 1;
199 let isConvergent = 1;
204 // SI pseudo instructions. These are used by the CFG structurizer pass
205 // and should be lowered to ISA instructions prior to codegen.
207 // Dummy terminator instruction to use after control flow instructions
208 // replaced with exec mask operations.
209 def SI_MASK_BRANCH : VPseudoInstSI <
210 (outs), (ins brtarget:$target)> {
212 let isTerminator = 1;
215 let hasNoSchedulingInfo = 1;
220 let isTerminator = 1 in {
222 let OtherPredicates = [EnableLateCFGStructurize] in {
223 def SI_NON_UNIFORM_BRCOND_PSEUDO : CFPseudoInstSI <
225 (ins SReg_64:$vcc, brtarget:$target),
226 [(brcond i1:$vcc, bb:$target)]> {
231 def SI_IF: CFPseudoInstSI <
232 (outs SReg_64:$dst), (ins SReg_64:$vcc, brtarget:$target),
233 [(set i64:$dst, (AMDGPUif i1:$vcc, bb:$target))], 1, 1> {
234 let Constraints = "";
236 let hasSideEffects = 1;
239 def SI_ELSE : CFPseudoInstSI <
241 (ins SReg_64:$src, brtarget:$target, i1imm:$execfix), [], 1, 1> {
243 let hasSideEffects = 1;
246 def SI_LOOP : CFPseudoInstSI <
247 (outs), (ins SReg_64:$saved, brtarget:$target),
248 [(AMDGPUloop i64:$saved, bb:$target)], 1, 1> {
251 let hasSideEffects = 1;
254 } // End isTerminator = 1
256 def SI_END_CF : CFPseudoInstSI <
257 (outs), (ins SReg_64:$saved),
258 [(int_amdgcn_end_cf i64:$saved)], 1, 1> {
260 let isAsCheapAsAMove = 1;
261 let isReMaterializable = 1;
262 let hasSideEffects = 1;
263 let mayLoad = 1; // FIXME: Should not need memory flags
267 def SI_BREAK : CFPseudoInstSI <
268 (outs SReg_64:$dst), (ins SReg_64:$src),
269 [(set i64:$dst, (int_amdgcn_break i64:$src))], 1> {
271 let isAsCheapAsAMove = 1;
272 let isReMaterializable = 1;
275 def SI_IF_BREAK : CFPseudoInstSI <
276 (outs SReg_64:$dst), (ins SReg_64:$vcc, SReg_64:$src),
277 [(set i64:$dst, (int_amdgcn_if_break i1:$vcc, i64:$src))]> {
279 let isAsCheapAsAMove = 1;
280 let isReMaterializable = 1;
283 def SI_ELSE_BREAK : CFPseudoInstSI <
284 (outs SReg_64:$dst), (ins SReg_64:$src0, SReg_64:$src1),
285 [(set i64:$dst, (int_amdgcn_else_break i64:$src0, i64:$src1))]> {
287 let isAsCheapAsAMove = 1;
288 let isReMaterializable = 1;
291 let Uses = [EXEC] in {
293 multiclass PseudoInstKill <dag ins> {
294 // Even though this pseudo can usually be expanded without an SCC def, we
295 // conservatively assume that it has an SCC def, both because it is sometimes
296 // required in degenerate cases (when V_CMPX cannot be used due to constant
297 // bus limitations) and because it allows us to avoid having to track SCC
298 // liveness across basic blocks.
299 let Defs = [EXEC,VCC,SCC] in
300 def _PSEUDO : PseudoInstSI <(outs), ins> {
301 let isConvergent = 1;
302 let usesCustomInserter = 1;
305 let Defs = [EXEC,VCC,SCC] in
306 def _TERMINATOR : SPseudoInstSI <(outs), ins> {
307 let isTerminator = 1;
311 defm SI_KILL_I1 : PseudoInstKill <(ins SSrc_b64:$src, i1imm:$killvalue)>;
312 defm SI_KILL_F32_COND_IMM : PseudoInstKill <(ins VSrc_b32:$src0, i32imm:$src1, i32imm:$cond)>;
314 let Defs = [EXEC,VCC] in
315 def SI_ILLEGAL_COPY : SPseudoInstSI <
316 (outs unknown:$dst), (ins unknown:$src),
317 [], " ; illegal copy $src to $dst">;
319 } // End Uses = [EXEC], Defs = [EXEC,VCC]
321 // Branch on undef scc. Used to avoid intermediate copy from
322 // IMPLICIT_DEF to SCC.
323 def SI_BR_UNDEF : SPseudoInstSI <(outs), (ins sopp_brtarget:$simm16)> {
324 let isTerminator = 1;
325 let usesCustomInserter = 1;
328 def SI_PS_LIVE : PseudoInstSI <
329 (outs SReg_64:$dst), (ins),
330 [(set i1:$dst, (int_amdgcn_ps_live))]> {
334 def SI_MASKED_UNREACHABLE : SPseudoInstSI <(outs), (ins),
335 [(int_amdgcn_unreachable)],
336 "; divergent unreachable"> {
338 let hasNoSchedulingInfo = 1;
342 // Used as an isel pseudo to directly emit initialization with an
343 // s_mov_b32 rather than a copy of another initialized
344 // register. MachineCSE skips copies, and we don't want to have to
345 // fold operands before it runs.
346 def SI_INIT_M0 : SPseudoInstSI <(outs), (ins SSrc_b32:$src)> {
348 let usesCustomInserter = 1;
349 let isAsCheapAsAMove = 1;
350 let isReMaterializable = 1;
353 def SI_INIT_EXEC : SPseudoInstSI <
354 (outs), (ins i64imm:$src), []> {
356 let usesCustomInserter = 1;
357 let isAsCheapAsAMove = 1;
360 def SI_INIT_EXEC_FROM_INPUT : SPseudoInstSI <
361 (outs), (ins SSrc_b32:$input, i32imm:$shift), []> {
363 let usesCustomInserter = 1;
366 // Return for returning shaders to a shader variant epilog.
367 def SI_RETURN_TO_EPILOG : SPseudoInstSI <
368 (outs), (ins variable_ops), [(AMDGPUreturn_to_epilog)]> {
369 let isTerminator = 1;
372 let hasNoSchedulingInfo = 1;
377 // Return for returning function calls.
378 def SI_RETURN : SPseudoInstSI <
381 let isTerminator = 1;
384 let SchedRW = [WriteBranch];
387 // Return for returning function calls without output register.
389 // This version is only needed so we can fill in the output regiter in
390 // the custom inserter.
391 def SI_CALL_ISEL : SPseudoInstSI <
392 (outs), (ins SSrc_b64:$src0), [(AMDGPUcall i64:$src0)]> {
395 let SchedRW = [WriteBranch];
396 let usesCustomInserter = 1;
399 // Wrapper around s_swappc_b64 with extra $callee parameter to track
400 // the called function after regalloc.
401 def SI_CALL : SPseudoInstSI <
402 (outs SReg_64:$dst), (ins SSrc_b64:$src0, unknown:$callee)> {
405 let UseNamedOperandTable = 1;
406 let SchedRW = [WriteBranch];
409 // Tail call handling pseudo
410 def SI_TCRETURN_ISEL : SPseudoInstSI<(outs),
411 (ins SSrc_b64:$src0, i32imm:$fpdiff),
412 [(AMDGPUtc_return i64:$src0, i32:$fpdiff)]> {
414 let isTerminator = 1;
417 let SchedRW = [WriteBranch];
418 let usesCustomInserter = 1;
421 def SI_TCRETURN : SPseudoInstSI <
423 (ins SSrc_b64:$src0, unknown:$callee, i32imm:$fpdiff)> {
426 let isTerminator = 1;
429 let UseNamedOperandTable = 1;
430 let SchedRW = [WriteBranch];
434 def ADJCALLSTACKUP : SPseudoInstSI<
435 (outs), (ins i32imm:$amt0, i32imm:$amt1),
436 [(callseq_start timm:$amt0, timm:$amt1)],
437 "; adjcallstackup $amt0 $amt1"> {
438 let Size = 8; // Worst case. (s_add_u32 + constant)
440 let hasSideEffects = 1;
441 let usesCustomInserter = 1;
444 def ADJCALLSTACKDOWN : SPseudoInstSI<
445 (outs), (ins i32imm:$amt1, i32imm:$amt2),
446 [(callseq_end timm:$amt1, timm:$amt2)],
447 "; adjcallstackdown $amt1"> {
448 let Size = 8; // Worst case. (s_add_u32 + constant)
449 let hasSideEffects = 1;
450 let usesCustomInserter = 1;
453 let Defs = [M0, EXEC, SCC],
454 UseNamedOperandTable = 1 in {
456 class SI_INDIRECT_SRC<RegisterClass rc> : VPseudoInstSI <
457 (outs VGPR_32:$vdst),
458 (ins rc:$src, VS_32:$idx, i32imm:$offset)> {
459 let usesCustomInserter = 1;
462 class SI_INDIRECT_DST<RegisterClass rc> : VPseudoInstSI <
464 (ins rc:$src, VS_32:$idx, i32imm:$offset, VGPR_32:$val)> {
465 let Constraints = "$src = $vdst";
466 let usesCustomInserter = 1;
469 // TODO: We can support indirect SGPR access.
470 def SI_INDIRECT_SRC_V1 : SI_INDIRECT_SRC<VGPR_32>;
471 def SI_INDIRECT_SRC_V2 : SI_INDIRECT_SRC<VReg_64>;
472 def SI_INDIRECT_SRC_V4 : SI_INDIRECT_SRC<VReg_128>;
473 def SI_INDIRECT_SRC_V8 : SI_INDIRECT_SRC<VReg_256>;
474 def SI_INDIRECT_SRC_V16 : SI_INDIRECT_SRC<VReg_512>;
476 def SI_INDIRECT_DST_V1 : SI_INDIRECT_DST<VGPR_32>;
477 def SI_INDIRECT_DST_V2 : SI_INDIRECT_DST<VReg_64>;
478 def SI_INDIRECT_DST_V4 : SI_INDIRECT_DST<VReg_128>;
479 def SI_INDIRECT_DST_V8 : SI_INDIRECT_DST<VReg_256>;
480 def SI_INDIRECT_DST_V16 : SI_INDIRECT_DST<VReg_512>;
482 } // End Uses = [EXEC], Defs = [M0, EXEC]
484 multiclass SI_SPILL_SGPR <RegisterClass sgpr_class> {
485 let UseNamedOperandTable = 1, SGPRSpill = 1, Uses = [EXEC] in {
486 def _SAVE : PseudoInstSI <
488 (ins sgpr_class:$data, i32imm:$addr)> {
493 def _RESTORE : PseudoInstSI <
494 (outs sgpr_class:$data),
495 (ins i32imm:$addr)> {
499 } // End UseNamedOperandTable = 1
502 // You cannot use M0 as the output of v_readlane_b32 instructions or
503 // use it in the sdata operand of SMEM instructions. We still need to
504 // be able to spill the physical register m0, so allow it for
505 // SI_SPILL_32_* instructions.
506 defm SI_SPILL_S32 : SI_SPILL_SGPR <SReg_32>;
507 defm SI_SPILL_S64 : SI_SPILL_SGPR <SReg_64>;
508 defm SI_SPILL_S128 : SI_SPILL_SGPR <SReg_128>;
509 defm SI_SPILL_S256 : SI_SPILL_SGPR <SReg_256>;
510 defm SI_SPILL_S512 : SI_SPILL_SGPR <SReg_512>;
512 multiclass SI_SPILL_VGPR <RegisterClass vgpr_class> {
513 let UseNamedOperandTable = 1, VGPRSpill = 1,
514 SchedRW = [WriteVMEM] in {
515 def _SAVE : VPseudoInstSI <
517 (ins vgpr_class:$vdata, i32imm:$vaddr, SReg_128:$srsrc,
518 SReg_32:$soffset, i32imm:$offset)> {
521 // (2 * 4) + (8 * num_subregs) bytes maximum
522 let Size = !add(!shl(!srl(vgpr_class.Size, 5), 3), 8);
525 def _RESTORE : VPseudoInstSI <
526 (outs vgpr_class:$vdata),
527 (ins i32imm:$vaddr, SReg_128:$srsrc, SReg_32:$soffset,
532 // (2 * 4) + (8 * num_subregs) bytes maximum
533 let Size = !add(!shl(!srl(vgpr_class.Size, 5), 3), 8);
535 } // End UseNamedOperandTable = 1, VGPRSpill = 1, SchedRW = [WriteVMEM]
538 defm SI_SPILL_V32 : SI_SPILL_VGPR <VGPR_32>;
539 defm SI_SPILL_V64 : SI_SPILL_VGPR <VReg_64>;
540 defm SI_SPILL_V96 : SI_SPILL_VGPR <VReg_96>;
541 defm SI_SPILL_V128 : SI_SPILL_VGPR <VReg_128>;
542 defm SI_SPILL_V256 : SI_SPILL_VGPR <VReg_256>;
543 defm SI_SPILL_V512 : SI_SPILL_VGPR <VReg_512>;
545 def SI_PC_ADD_REL_OFFSET : SPseudoInstSI <
547 (ins si_ga:$ptr_lo, si_ga:$ptr_hi),
549 (i64 (SIpc_add_rel_offset (tglobaladdr:$ptr_lo), (tglobaladdr:$ptr_hi))))]> {
554 (AMDGPUinit_exec i64:$src),
555 (SI_INIT_EXEC (as_i64imm $src))
559 (AMDGPUinit_exec_from_input i32:$input, i32:$shift),
560 (SI_INIT_EXEC_FROM_INPUT (i32 $input), (as_i32imm $shift))
564 (AMDGPUtrap timm:$trapid),
569 (AMDGPUelse i64:$src, bb:$target),
570 (SI_ELSE $src, $target, 0)
574 // -1.0 as i32 (LowerINTRINSIC_VOID converts all other constants to -1.0)
575 (AMDGPUkill (i32 -1082130432)),
576 (SI_KILL_I1_PSEUDO (i1 0), 0)
580 (int_amdgcn_kill i1:$src),
581 (SI_KILL_I1_PSEUDO $src, 0)
585 (int_amdgcn_kill (i1 (not i1:$src))),
586 (SI_KILL_I1_PSEUDO $src, -1)
590 (AMDGPUkill i32:$src),
591 (SI_KILL_F32_COND_IMM_PSEUDO $src, 0, 3) // 3 means SETOGE
595 (int_amdgcn_kill (i1 (setcc f32:$src, InlineFPImm<f32>:$imm, cond:$cond))),
596 (SI_KILL_F32_COND_IMM_PSEUDO $src, (bitcast_fpimm_to_i32 $imm), (cond_as_i32imm $cond))
598 // TODO: we could add more variants for other types of conditionals
600 //===----------------------------------------------------------------------===//
602 //===----------------------------------------------------------------------===//
604 let SubtargetPredicate = isGCN, OtherPredicates = [UnsafeFPMath] in {
606 //def : RcpPat<V_RCP_F64_e32, f64>;
607 //defm : RsqPat<V_RSQ_F64_e32, f64>;
608 //defm : RsqPat<V_RSQ_F32_e32, f32>;
610 def : RsqPat<V_RSQ_F32_e32, f32>;
611 def : RsqPat<V_RSQ_F64_e32, f64>;
613 // Convert (x - floor(x)) to fract(x)
615 (f32 (fsub (f32 (VOP3Mods f32:$x, i32:$mods)),
616 (f32 (ffloor (f32 (VOP3Mods f32:$x, i32:$mods)))))),
617 (V_FRACT_F32_e64 $mods, $x, DSTCLAMP.NONE, DSTOMOD.NONE)
620 // Convert (x + (-floor(x))) to fract(x)
622 (f64 (fadd (f64 (VOP3Mods f64:$x, i32:$mods)),
623 (f64 (fneg (f64 (ffloor (f64 (VOP3Mods f64:$x, i32:$mods)))))))),
624 (V_FRACT_F64_e64 $mods, $x, DSTCLAMP.NONE, DSTOMOD.NONE)
627 } // End SubtargetPredicate = isGCN, OtherPredicates = [UnsafeFPMath]
630 // f16_to_fp patterns
632 (f32 (f16_to_fp i32:$src0)),
633 (V_CVT_F32_F16_e64 SRCMODS.NONE, $src0, DSTCLAMP.NONE, DSTOMOD.NONE)
637 (f32 (f16_to_fp (and_oneuse i32:$src0, 0x7fff))),
638 (V_CVT_F32_F16_e64 SRCMODS.ABS, $src0, DSTCLAMP.NONE, DSTOMOD.NONE)
642 (f32 (f16_to_fp (i32 (srl_oneuse (and_oneuse i32:$src0, 0x7fff0000), (i32 16))))),
643 (V_CVT_F32_F16_e64 SRCMODS.ABS, (i32 (V_LSHRREV_B32_e64 (i32 16), i32:$src0)), DSTCLAMP.NONE, DSTOMOD.NONE)
647 (f32 (f16_to_fp (or_oneuse i32:$src0, 0x8000))),
648 (V_CVT_F32_F16_e64 SRCMODS.NEG_ABS, $src0, DSTCLAMP.NONE, DSTOMOD.NONE)
652 (f32 (f16_to_fp (xor_oneuse i32:$src0, 0x8000))),
653 (V_CVT_F32_F16_e64 SRCMODS.NEG, $src0, DSTCLAMP.NONE, DSTOMOD.NONE)
657 (f64 (fpextend f16:$src)),
658 (V_CVT_F64_F32_e32 (V_CVT_F32_F16_e32 $src))
661 // fp_to_fp16 patterns
663 (i32 (AMDGPUfp_to_f16 (f32 (VOP3Mods f32:$src0, i32:$src0_modifiers)))),
664 (V_CVT_F16_F32_e64 $src0_modifiers, f32:$src0, DSTCLAMP.NONE, DSTOMOD.NONE)
668 (i32 (fp_to_sint f16:$src)),
669 (V_CVT_I32_F32_e32 (V_CVT_F32_F16_e32 $src))
673 (i32 (fp_to_uint f16:$src)),
674 (V_CVT_U32_F32_e32 (V_CVT_F32_F16_e32 $src))
678 (f16 (sint_to_fp i32:$src)),
679 (V_CVT_F16_F32_e32 (V_CVT_F32_I32_e32 $src))
683 (f16 (uint_to_fp i32:$src)),
684 (V_CVT_F16_F32_e32 (V_CVT_F32_U32_e32 $src))
687 //===----------------------------------------------------------------------===//
689 //===----------------------------------------------------------------------===//
691 multiclass FMADPat <ValueType vt, Instruction inst> {
693 (vt (fmad (VOP3NoMods vt:$src0),
694 (VOP3NoMods vt:$src1),
695 (VOP3NoMods vt:$src2))),
696 (inst SRCMODS.NONE, $src0, SRCMODS.NONE, $src1,
697 SRCMODS.NONE, $src2, DSTCLAMP.NONE, DSTOMOD.NONE)
701 defm : FMADPat <f16, V_MAC_F16_e64>;
702 defm : FMADPat <f32, V_MAC_F32_e64>;
704 class FMADModsPat<Instruction inst, SDPatternOperator mad_opr, ValueType Ty>
706 (Ty (mad_opr (VOP3Mods Ty:$src0, i32:$src0_mod),
707 (VOP3Mods Ty:$src1, i32:$src1_mod),
708 (VOP3Mods Ty:$src2, i32:$src2_mod))),
709 (inst $src0_mod, $src0, $src1_mod, $src1,
710 $src2_mod, $src2, DSTCLAMP.NONE, DSTOMOD.NONE)
713 def : FMADModsPat<V_MAD_F32, AMDGPUfmad_ftz, f32>;
714 def : FMADModsPat<V_MAD_F16, AMDGPUfmad_ftz, f16> {
715 let SubtargetPredicate = Has16BitInsts;
718 multiclass SelectPat <ValueType vt, Instruction inst> {
720 (vt (select i1:$src0, vt:$src1, vt:$src2)),
721 (inst $src2, $src1, $src0)
725 defm : SelectPat <i16, V_CNDMASK_B32_e64>;
726 defm : SelectPat <i32, V_CNDMASK_B32_e64>;
727 defm : SelectPat <f16, V_CNDMASK_B32_e64>;
728 defm : SelectPat <f32, V_CNDMASK_B32_e64>;
731 (i32 (add (i32 (ctpop i32:$popcnt)), i32:$val)),
732 (V_BCNT_U32_B32_e64 $popcnt, $val)
735 (i16 (add (i16 (trunc (ctpop i32:$popcnt))), i16:$val)),
736 (V_BCNT_U32_B32_e64 $popcnt, $val)
739 /********** ============================================ **********/
740 /********** Extraction, Insertion, Building and Casting **********/
741 /********** ============================================ **********/
743 foreach Index = 0-2 in {
744 def Extract_Element_v2i32_#Index : Extract_Element <
745 i32, v2i32, Index, !cast<SubRegIndex>(sub#Index)
747 def Insert_Element_v2i32_#Index : Insert_Element <
748 i32, v2i32, Index, !cast<SubRegIndex>(sub#Index)
751 def Extract_Element_v2f32_#Index : Extract_Element <
752 f32, v2f32, Index, !cast<SubRegIndex>(sub#Index)
754 def Insert_Element_v2f32_#Index : Insert_Element <
755 f32, v2f32, Index, !cast<SubRegIndex>(sub#Index)
759 foreach Index = 0-3 in {
760 def Extract_Element_v4i32_#Index : Extract_Element <
761 i32, v4i32, Index, !cast<SubRegIndex>(sub#Index)
763 def Insert_Element_v4i32_#Index : Insert_Element <
764 i32, v4i32, Index, !cast<SubRegIndex>(sub#Index)
767 def Extract_Element_v4f32_#Index : Extract_Element <
768 f32, v4f32, Index, !cast<SubRegIndex>(sub#Index)
770 def Insert_Element_v4f32_#Index : Insert_Element <
771 f32, v4f32, Index, !cast<SubRegIndex>(sub#Index)
775 foreach Index = 0-7 in {
776 def Extract_Element_v8i32_#Index : Extract_Element <
777 i32, v8i32, Index, !cast<SubRegIndex>(sub#Index)
779 def Insert_Element_v8i32_#Index : Insert_Element <
780 i32, v8i32, Index, !cast<SubRegIndex>(sub#Index)
783 def Extract_Element_v8f32_#Index : Extract_Element <
784 f32, v8f32, Index, !cast<SubRegIndex>(sub#Index)
786 def Insert_Element_v8f32_#Index : Insert_Element <
787 f32, v8f32, Index, !cast<SubRegIndex>(sub#Index)
791 foreach Index = 0-15 in {
792 def Extract_Element_v16i32_#Index : Extract_Element <
793 i32, v16i32, Index, !cast<SubRegIndex>(sub#Index)
795 def Insert_Element_v16i32_#Index : Insert_Element <
796 i32, v16i32, Index, !cast<SubRegIndex>(sub#Index)
799 def Extract_Element_v16f32_#Index : Extract_Element <
800 f32, v16f32, Index, !cast<SubRegIndex>(sub#Index)
802 def Insert_Element_v16f32_#Index : Insert_Element <
803 f32, v16f32, Index, !cast<SubRegIndex>(sub#Index)
809 (extract_subvector v4i16:$vec, (i32 0)),
810 (v2i16 (EXTRACT_SUBREG v4i16:$vec, sub0))
814 (extract_subvector v4i16:$vec, (i32 2)),
815 (v2i16 (EXTRACT_SUBREG v4i16:$vec, sub1))
819 (extract_subvector v4f16:$vec, (i32 0)),
820 (v2f16 (EXTRACT_SUBREG v4f16:$vec, sub0))
824 (extract_subvector v4f16:$vec, (i32 2)),
825 (v2f16 (EXTRACT_SUBREG v4f16:$vec, sub1))
828 let SubtargetPredicate = isGCN in {
830 // FIXME: Why do only some of these type combinations for SReg and
833 def : BitConvert <i16, f16, VGPR_32>;
834 def : BitConvert <f16, i16, VGPR_32>;
835 def : BitConvert <i16, f16, SReg_32>;
836 def : BitConvert <f16, i16, SReg_32>;
839 def : BitConvert <i32, f32, VGPR_32>;
840 def : BitConvert <f32, i32, VGPR_32>;
841 def : BitConvert <i32, f32, SReg_32>;
842 def : BitConvert <f32, i32, SReg_32>;
843 def : BitConvert <v2i16, i32, SReg_32>;
844 def : BitConvert <i32, v2i16, SReg_32>;
845 def : BitConvert <v2f16, i32, SReg_32>;
846 def : BitConvert <i32, v2f16, SReg_32>;
847 def : BitConvert <v2i16, v2f16, SReg_32>;
848 def : BitConvert <v2f16, v2i16, SReg_32>;
849 def : BitConvert <v2f16, f32, SReg_32>;
850 def : BitConvert <f32, v2f16, SReg_32>;
851 def : BitConvert <v2i16, f32, SReg_32>;
852 def : BitConvert <f32, v2i16, SReg_32>;
855 def : BitConvert <i64, f64, VReg_64>;
856 def : BitConvert <f64, i64, VReg_64>;
857 def : BitConvert <v2i32, v2f32, VReg_64>;
858 def : BitConvert <v2f32, v2i32, VReg_64>;
859 def : BitConvert <i64, v2i32, VReg_64>;
860 def : BitConvert <v2i32, i64, VReg_64>;
861 def : BitConvert <i64, v2f32, VReg_64>;
862 def : BitConvert <v2f32, i64, VReg_64>;
863 def : BitConvert <f64, v2f32, VReg_64>;
864 def : BitConvert <v2f32, f64, VReg_64>;
865 def : BitConvert <f64, v2i32, VReg_64>;
866 def : BitConvert <v2i32, f64, VReg_64>;
869 def : BitConvert <v2i32, v4f16, VReg_64>;
870 def : BitConvert <v4f16, v2i32, VReg_64>;
871 def : BitConvert <v2i32, v4f16, VReg_64>;
872 def : BitConvert <v2i32, v4i16, VReg_64>;
873 def : BitConvert <v4i16, v2i32, VReg_64>;
874 def : BitConvert <v2f32, v4f16, VReg_64>;
875 def : BitConvert <v4f16, v2f32, VReg_64>;
876 def : BitConvert <v2f32, v4i16, VReg_64>;
877 def : BitConvert <v4i16, v2f32, VReg_64>;
878 def : BitConvert <v4i16, f64, VReg_64>;
879 def : BitConvert <v4f16, f64, VReg_64>;
880 def : BitConvert <f64, v4i16, VReg_64>;
881 def : BitConvert <f64, v4f16, VReg_64>;
882 def : BitConvert <v4i16, i64, VReg_64>;
883 def : BitConvert <v4f16, i64, VReg_64>;
884 def : BitConvert <i64, v4i16, VReg_64>;
885 def : BitConvert <i64, v4f16, VReg_64>;
887 def : BitConvert <v4i32, v4f32, VReg_128>;
888 def : BitConvert <v4f32, v4i32, VReg_128>;
891 def : BitConvert <v2i64, v4i32, SReg_128>;
892 def : BitConvert <v4i32, v2i64, SReg_128>;
893 def : BitConvert <v2f64, v4f32, VReg_128>;
894 def : BitConvert <v2f64, v4i32, VReg_128>;
895 def : BitConvert <v4f32, v2f64, VReg_128>;
896 def : BitConvert <v4i32, v2f64, VReg_128>;
897 def : BitConvert <v2i64, v2f64, VReg_128>;
898 def : BitConvert <v2f64, v2i64, VReg_128>;
901 def : BitConvert <v8i32, v8f32, SReg_256>;
902 def : BitConvert <v8f32, v8i32, SReg_256>;
903 def : BitConvert <v8i32, v8f32, VReg_256>;
904 def : BitConvert <v8f32, v8i32, VReg_256>;
907 def : BitConvert <v16i32, v16f32, VReg_512>;
908 def : BitConvert <v16f32, v16i32, VReg_512>;
910 } // End SubtargetPredicate = isGCN
912 /********** =================== **********/
913 /********** Src & Dst modifiers **********/
914 /********** =================== **********/
917 // If denormals are not enabled, it only impacts the compare of the
918 // inputs. The output result is not flushed.
919 class ClampPat<Instruction inst, ValueType vt> : GCNPat <
920 (vt (AMDGPUclamp (VOP3Mods vt:$src0, i32:$src0_modifiers))),
921 (inst i32:$src0_modifiers, vt:$src0,
922 i32:$src0_modifiers, vt:$src0, DSTCLAMP.ENABLE, DSTOMOD.NONE)
925 def : ClampPat<V_MAX_F32_e64, f32>;
926 def : ClampPat<V_MAX_F64, f64>;
927 def : ClampPat<V_MAX_F16_e64, f16>;
929 let SubtargetPredicate = HasVOP3PInsts in {
931 (v2f16 (AMDGPUclamp (VOP3PMods v2f16:$src0, i32:$src0_modifiers))),
932 (V_PK_MAX_F16 $src0_modifiers, $src0,
933 $src0_modifiers, $src0, DSTCLAMP.ENABLE)
937 /********** ================================ **********/
938 /********** Floating point absolute/negative **********/
939 /********** ================================ **********/
941 // Prevent expanding both fneg and fabs.
944 (fneg (fabs f32:$src)),
945 (S_OR_B32 $src, (S_MOV_B32(i32 0x80000000))) // Set sign bit
948 // FIXME: Should use S_OR_B32
950 (fneg (fabs f64:$src)),
951 (REG_SEQUENCE VReg_64,
952 (i32 (EXTRACT_SUBREG f64:$src, sub0)),
954 (V_OR_B32_e32 (i32 (EXTRACT_SUBREG f64:$src, sub1)),
955 (V_MOV_B32_e32 (i32 0x80000000))), // Set sign bit.
961 (S_AND_B32 $src, (S_MOV_B32 (i32 0x7fffffff)))
966 (V_XOR_B32_e32 $src, (V_MOV_B32_e32 (i32 0x80000000)))
971 (REG_SEQUENCE VReg_64,
972 (i32 (EXTRACT_SUBREG f64:$src, sub0)),
974 (V_AND_B32_e64 (i32 (EXTRACT_SUBREG f64:$src, sub1)),
975 (V_MOV_B32_e32 (i32 0x7fffffff))), // Set sign bit.
981 (REG_SEQUENCE VReg_64,
982 (i32 (EXTRACT_SUBREG f64:$src, sub0)),
984 (V_XOR_B32_e32 (i32 (EXTRACT_SUBREG f64:$src, sub1)),
985 (i32 (V_MOV_B32_e32 (i32 0x80000000)))),
990 (fcopysign f16:$src0, f16:$src1),
991 (V_BFI_B32 (S_MOV_B32 (i32 0x00007fff)), $src0, $src1)
995 (fcopysign f32:$src0, f16:$src1),
996 (V_BFI_B32 (S_MOV_B32 (i32 0x7fffffff)), $src0,
997 (V_LSHLREV_B32_e64 (i32 16), $src1))
1001 (fcopysign f64:$src0, f16:$src1),
1002 (REG_SEQUENCE SReg_64,
1003 (i32 (EXTRACT_SUBREG $src0, sub0)), sub0,
1004 (V_BFI_B32 (S_MOV_B32 (i32 0x7fffffff)), (i32 (EXTRACT_SUBREG $src0, sub1)),
1005 (V_LSHLREV_B32_e64 (i32 16), $src1)), sub1)
1009 (fcopysign f16:$src0, f32:$src1),
1010 (V_BFI_B32 (S_MOV_B32 (i32 0x00007fff)), $src0,
1011 (V_LSHRREV_B32_e64 (i32 16), $src1))
1015 (fcopysign f16:$src0, f64:$src1),
1016 (V_BFI_B32 (S_MOV_B32 (i32 0x00007fff)), $src0,
1017 (V_LSHRREV_B32_e64 (i32 16), (EXTRACT_SUBREG $src1, sub1)))
1022 (S_XOR_B32 $src, (S_MOV_B32 (i32 0x00008000)))
1027 (S_AND_B32 $src, (S_MOV_B32 (i32 0x00007fff)))
1031 (fneg (fabs f16:$src)),
1032 (S_OR_B32 $src, (S_MOV_B32 (i32 0x00008000))) // Set sign bit
1037 (S_XOR_B32 $src, (S_MOV_B32 (i32 0x80008000)))
1042 (S_AND_B32 $src, (S_MOV_B32 (i32 0x7fff7fff)))
1045 // This is really (fneg (fabs v2f16:$src))
1047 // fabs is not reported as free because there is modifier for it in
1048 // VOP3P instructions, so it is turned into the bit op.
1050 (fneg (v2f16 (bitconvert (and_oneuse i32:$src, 0x7fff7fff)))),
1051 (S_OR_B32 $src, (S_MOV_B32 (i32 0x80008000))) // Set sign bit
1055 (fneg (v2f16 (fabs v2f16:$src))),
1056 (S_OR_B32 $src, (S_MOV_B32 (i32 0x80008000))) // Set sign bit
1059 /********** ================== **********/
1060 /********** Immediate Patterns **********/
1061 /********** ================== **********/
1064 (VGPRImm<(i32 imm)>:$imm),
1065 (V_MOV_B32_e32 imm:$imm)
1069 (VGPRImm<(f32 fpimm)>:$imm),
1070 (V_MOV_B32_e32 (f32 (bitcast_fpimm_to_i32 $imm)))
1075 (S_MOV_B32 imm:$imm)
1078 // FIXME: Workaround for ordering issue with peephole optimizer where
1079 // a register class copy interferes with immediate folding. Should
1080 // use s_mov_b32, which can be shrunk to s_movk_i32
1082 (VGPRImm<(f16 fpimm)>:$imm),
1083 (V_MOV_B32_e32 (f16 (bitcast_fpimm_to_i32 $imm)))
1088 (S_MOV_B32 (f32 (bitcast_fpimm_to_i32 $imm)))
1093 (S_MOV_B32 (i32 (bitcast_fpimm_to_i32 $imm)))
1097 (i32 frameindex:$fi),
1098 (V_MOV_B32_e32 (i32 (frameindex_to_targetframeindex $fi)))
1102 (i64 InlineImm<i64>:$imm),
1103 (S_MOV_B64 InlineImm<i64>:$imm)
1106 // XXX - Should this use a s_cmp to set SCC?
1108 // Set to sign-extended 64-bit value (true = -1, false = 0)
1111 (S_MOV_B64 (i64 (as_i64imm $imm)))
1115 (f64 InlineFPImm<f64>:$imm),
1116 (S_MOV_B64 (f64 (bitcast_fpimm_to_i64 InlineFPImm<f64>:$imm)))
1119 /********** ================== **********/
1120 /********** Intrinsic Patterns **********/
1121 /********** ================== **********/
1123 let SubtargetPredicate = isGCN in {
1124 def : POW_Common <V_LOG_F32_e32, V_EXP_F32_e32, V_MUL_LEGACY_F32_e32>;
1128 (i32 (sext i1:$src0)),
1129 (V_CNDMASK_B32_e64 (i32 0), (i32 -1), $src0)
1132 class Ext32Pat <SDNode ext> : GCNPat <
1133 (i32 (ext i1:$src0)),
1134 (V_CNDMASK_B32_e64 (i32 0), (i32 1), $src0)
1137 def : Ext32Pat <zext>;
1138 def : Ext32Pat <anyext>;
1140 // The multiplication scales from [0,1] to the unsigned integer range
1142 (AMDGPUurecip i32:$src0),
1144 (V_MUL_F32_e32 (i32 CONST.FP_UINT_MAX_PLUS_1),
1145 (V_RCP_IFLAG_F32_e32 (V_CVT_F32_U32_e32 $src0))))
1148 //===----------------------------------------------------------------------===//
1150 //===----------------------------------------------------------------------===//
1152 let SubtargetPredicate = isGCN in {
1154 def : IMad24Pat<V_MAD_I32_I24, 1>;
1155 def : UMad24Pat<V_MAD_U32_U24, 1>;
1157 // FIXME: This should only be done for VALU inputs
1158 defm : BFIPatterns <V_BFI_B32, S_MOV_B32, SReg_64>;
1159 def : ROTRPattern <V_ALIGNBIT_B32>;
1163 def : GCNPat<(i32 (trunc (srl i64:$src0, (and i32:$src1, (i32 31))))),
1164 (V_ALIGNBIT_B32 (i32 (EXTRACT_SUBREG (i64 $src0), sub1)),
1165 (i32 (EXTRACT_SUBREG (i64 $src0), sub0)), $src1)>;
1167 def : GCNPat<(i32 (trunc (srl i64:$src0, (i32 ShiftAmt32Imm:$src1)))),
1168 (V_ALIGNBIT_B32 (i32 (EXTRACT_SUBREG (i64 $src0), sub1)),
1169 (i32 (EXTRACT_SUBREG (i64 $src0), sub0)), $src1)>;
1171 /********** ====================== **********/
1172 /********** Indirect addressing **********/
1173 /********** ====================== **********/
1175 multiclass SI_INDIRECT_Pattern <ValueType vt, ValueType eltvt, string VecSize> {
1176 // Extract with offset
1178 (eltvt (extractelt vt:$src, (MOVRELOffset i32:$idx, (i32 imm:$offset)))),
1179 (!cast<Instruction>("SI_INDIRECT_SRC_"#VecSize) $src, $idx, imm:$offset)
1182 // Insert with offset
1184 (insertelt vt:$src, eltvt:$val, (MOVRELOffset i32:$idx, (i32 imm:$offset))),
1185 (!cast<Instruction>("SI_INDIRECT_DST_"#VecSize) $src, $idx, imm:$offset, $val)
1189 defm : SI_INDIRECT_Pattern <v2f32, f32, "V2">;
1190 defm : SI_INDIRECT_Pattern <v4f32, f32, "V4">;
1191 defm : SI_INDIRECT_Pattern <v8f32, f32, "V8">;
1192 defm : SI_INDIRECT_Pattern <v16f32, f32, "V16">;
1194 defm : SI_INDIRECT_Pattern <v2i32, i32, "V2">;
1195 defm : SI_INDIRECT_Pattern <v4i32, i32, "V4">;
1196 defm : SI_INDIRECT_Pattern <v8i32, i32, "V8">;
1197 defm : SI_INDIRECT_Pattern <v16i32, i32, "V16">;
1199 //===----------------------------------------------------------------------===//
1201 //===----------------------------------------------------------------------===//
1204 (add (sub_oneuse (umax i32:$src0, i32:$src1),
1205 (umin i32:$src0, i32:$src1)),
1207 (V_SAD_U32 $src0, $src1, $src2, (i1 0))
1211 (add (select_oneuse (i1 (setugt i32:$src0, i32:$src1)),
1212 (sub i32:$src0, i32:$src1),
1213 (sub i32:$src1, i32:$src0)),
1215 (V_SAD_U32 $src0, $src1, $src2, (i1 0))
1218 //===----------------------------------------------------------------------===//
1219 // Conversion Patterns
1220 //===----------------------------------------------------------------------===//
1222 def : GCNPat<(i32 (sext_inreg i32:$src, i1)),
1223 (S_BFE_I32 i32:$src, (i32 65536))>; // 0 | 1 << 16
1225 // Handle sext_inreg in i64
1227 (i64 (sext_inreg i64:$src, i1)),
1228 (S_BFE_I64 i64:$src, (i32 0x10000)) // 0 | 1 << 16
1232 (i16 (sext_inreg i16:$src, i1)),
1233 (S_BFE_I32 $src, (i32 0x00010000)) // 0 | 1 << 16
1237 (i16 (sext_inreg i16:$src, i8)),
1238 (S_BFE_I32 $src, (i32 0x80000)) // 0 | 8 << 16
1242 (i64 (sext_inreg i64:$src, i8)),
1243 (S_BFE_I64 i64:$src, (i32 0x80000)) // 0 | 8 << 16
1247 (i64 (sext_inreg i64:$src, i16)),
1248 (S_BFE_I64 i64:$src, (i32 0x100000)) // 0 | 16 << 16
1252 (i64 (sext_inreg i64:$src, i32)),
1253 (S_BFE_I64 i64:$src, (i32 0x200000)) // 0 | 32 << 16
1257 (i64 (zext i32:$src)),
1258 (REG_SEQUENCE SReg_64, $src, sub0, (S_MOV_B32 (i32 0)), sub1)
1262 (i64 (anyext i32:$src)),
1263 (REG_SEQUENCE SReg_64, $src, sub0, (i32 (IMPLICIT_DEF)), sub1)
1266 class ZExt_i64_i1_Pat <SDNode ext> : GCNPat <
1267 (i64 (ext i1:$src)),
1268 (REG_SEQUENCE VReg_64,
1269 (V_CNDMASK_B32_e64 (i32 0), (i32 1), $src), sub0,
1270 (S_MOV_B32 (i32 0)), sub1)
1274 def : ZExt_i64_i1_Pat<zext>;
1275 def : ZExt_i64_i1_Pat<anyext>;
1277 // FIXME: We need to use COPY_TO_REGCLASS to work-around the fact that
1278 // REG_SEQUENCE patterns don't support instructions with multiple outputs.
1280 (i64 (sext i32:$src)),
1281 (REG_SEQUENCE SReg_64, $src, sub0,
1282 (i32 (COPY_TO_REGCLASS (S_ASHR_I32 $src, (i32 31)), SReg_32_XM0)), sub1)
1286 (i64 (sext i1:$src)),
1287 (REG_SEQUENCE VReg_64,
1288 (V_CNDMASK_B32_e64 (i32 0), (i32 -1), $src), sub0,
1289 (V_CNDMASK_B32_e64 (i32 0), (i32 -1), $src), sub1)
1292 class FPToI1Pat<Instruction Inst, int KOne, ValueType kone_type, ValueType vt, SDPatternOperator fp_to_int> : GCNPat <
1293 (i1 (fp_to_int (vt (VOP3Mods vt:$src0, i32:$src0_modifiers)))),
1294 (i1 (Inst 0, (kone_type KOne), $src0_modifiers, $src0, DSTCLAMP.NONE))
1297 def : FPToI1Pat<V_CMP_EQ_F32_e64, CONST.FP32_ONE, i32, f32, fp_to_uint>;
1298 def : FPToI1Pat<V_CMP_EQ_F32_e64, CONST.FP32_NEG_ONE, i32, f32, fp_to_sint>;
1299 def : FPToI1Pat<V_CMP_EQ_F64_e64, CONST.FP64_ONE, i64, f64, fp_to_uint>;
1300 def : FPToI1Pat<V_CMP_EQ_F64_e64, CONST.FP64_NEG_ONE, i64, f64, fp_to_sint>;
1302 // If we need to perform a logical operation on i1 values, we need to
1303 // use vector comparisons since there is only one SCC register. Vector
1304 // comparisons still write to a pair of SGPRs, so treat these as
1305 // 64-bit comparisons. When legalizing SGPR copies, instructions
1306 // resulting in the copies from SCC to these instructions will be
1307 // moved to the VALU.
1309 (i1 (and i1:$src0, i1:$src1)),
1310 (S_AND_B64 $src0, $src1)
1314 (i1 (or i1:$src0, i1:$src1)),
1315 (S_OR_B64 $src0, $src1)
1319 (i1 (xor i1:$src0, i1:$src1)),
1320 (S_XOR_B64 $src0, $src1)
1324 (f32 (sint_to_fp i1:$src)),
1325 (V_CNDMASK_B32_e64 (i32 0), (i32 CONST.FP32_NEG_ONE), $src)
1329 (f32 (uint_to_fp i1:$src)),
1330 (V_CNDMASK_B32_e64 (i32 0), (i32 CONST.FP32_ONE), $src)
1334 (f64 (sint_to_fp i1:$src)),
1335 (V_CVT_F64_I32_e32 (V_CNDMASK_B32_e64 (i32 0), (i32 -1), $src))
1339 (f64 (uint_to_fp i1:$src)),
1340 (V_CVT_F64_U32_e32 (V_CNDMASK_B32_e64 (i32 0), (i32 1), $src))
1343 //===----------------------------------------------------------------------===//
1344 // Miscellaneous Patterns
1345 //===----------------------------------------------------------------------===//
1347 (i32 (AMDGPUfp16_zext f16:$src)),
1353 (i32 (trunc i64:$a)),
1354 (EXTRACT_SUBREG $a, sub0)
1358 (i1 (trunc i32:$a)),
1359 (V_CMP_EQ_U32_e64 (S_AND_B32 (i32 1), $a), (i32 1))
1363 (i1 (trunc i16:$a)),
1364 (V_CMP_EQ_U32_e64 (S_AND_B32 (i32 1), $a), (i32 1))
1368 (i1 (trunc i64:$a)),
1369 (V_CMP_EQ_U32_e64 (S_AND_B32 (i32 1),
1370 (i32 (EXTRACT_SUBREG $a, sub0))), (i32 1))
1374 (i32 (bswap i32:$a)),
1375 (V_BFI_B32 (S_MOV_B32 (i32 0x00ff00ff)),
1376 (V_ALIGNBIT_B32 $a, $a, (i32 24)),
1377 (V_ALIGNBIT_B32 $a, $a, (i32 8)))
1380 let OtherPredicates = [NoFP16Denormals] in {
1382 (fcanonicalize (f16 (VOP3Mods f16:$src, i32:$src_mods))),
1383 (V_MUL_F16_e64 0, (i32 CONST.FP16_ONE), $src_mods, $src, 0, 0)
1387 (fcanonicalize (f16 (fneg (VOP3Mods f16:$src, i32:$src_mods)))),
1388 (V_MUL_F16_e64 0, (i32 CONST.FP16_NEG_ONE), $src_mods, $src, 0, 0)
1392 (fcanonicalize (v2f16 (VOP3PMods v2f16:$src, i32:$src_mods))),
1393 (V_PK_MUL_F16 0, (i32 CONST.V2FP16_ONE), $src_mods, $src, DSTCLAMP.NONE)
1397 let OtherPredicates = [FP16Denormals] in {
1399 (fcanonicalize (f16 (VOP3Mods f16:$src, i32:$src_mods))),
1400 (V_MAX_F16_e64 $src_mods, $src, $src_mods, $src, 0, 0)
1403 let SubtargetPredicate = HasVOP3PInsts in {
1405 (fcanonicalize (v2f16 (VOP3PMods v2f16:$src, i32:$src_mods))),
1406 (V_PK_MAX_F16 $src_mods, $src, $src_mods, $src, DSTCLAMP.NONE)
1411 let OtherPredicates = [NoFP32Denormals] in {
1413 (fcanonicalize (f32 (VOP3Mods f32:$src, i32:$src_mods))),
1414 (V_MUL_F32_e64 0, (i32 CONST.FP32_ONE), $src_mods, $src, 0, 0)
1418 (fcanonicalize (f32 (fneg (VOP3Mods f32:$src, i32:$src_mods)))),
1419 (V_MUL_F32_e64 0, (i32 CONST.FP32_NEG_ONE), $src_mods, $src, 0, 0)
1423 let OtherPredicates = [FP32Denormals] in {
1425 (fcanonicalize (f32 (VOP3Mods f32:$src, i32:$src_mods))),
1426 (V_MAX_F32_e64 $src_mods, $src, $src_mods, $src, 0, 0)
1430 let OtherPredicates = [NoFP64Denormals] in {
1432 (fcanonicalize (f64 (VOP3Mods f64:$src, i32:$src_mods))),
1433 (V_MUL_F64 0, CONST.FP64_ONE, $src_mods, $src, 0, 0)
1437 let OtherPredicates = [FP64Denormals] in {
1439 (fcanonicalize (f64 (VOP3Mods f64:$src, i32:$src_mods))),
1440 (V_MAX_F64 $src_mods, $src, $src_mods, $src, 0, 0)
1444 let OtherPredicates = [HasDLInsts] in {
1446 (fma (f32 (VOP3Mods0 f32:$src0, i32:$src0_modifiers, i1:$clamp, i32:$omod)),
1447 (f32 (VOP3Mods f32:$src1, i32:$src1_modifiers)),
1448 (f32 (VOP3NoMods f32:$src2))),
1449 (V_FMAC_F32_e64 $src0_modifiers, $src0, $src1_modifiers, $src1,
1450 SRCMODS.NONE, $src2, $clamp, $omod)
1452 } // End OtherPredicates = [HasDLInsts]
1455 // Allow integer inputs
1456 class ExpPattern<SDPatternOperator node, ValueType vt, Instruction Inst> : GCNPat<
1457 (node (i8 timm:$tgt), (i8 timm:$en), vt:$src0, vt:$src1, vt:$src2, vt:$src3, (i1 timm:$compr), (i1 timm:$vm)),
1458 (Inst i8:$tgt, vt:$src0, vt:$src1, vt:$src2, vt:$src3, i1:$vm, i1:$compr, i8:$en)
1461 def : ExpPattern<AMDGPUexport, i32, EXP>;
1462 def : ExpPattern<AMDGPUexport_done, i32, EXP_DONE>;
1464 // COPY is workaround tablegen bug from multiple outputs
1465 // from S_LSHL_B32's multiple outputs from implicit scc def.
1467 (v2i16 (build_vector (i16 0), i16:$src1)),
1468 (v2i16 (COPY (S_LSHL_B32 i16:$src1, (i16 16))))
1472 (v2i16 (build_vector i16:$src0, (i16 undef))),
1473 (v2i16 (COPY $src0))
1477 (v2f16 (build_vector f16:$src0, (f16 undef))),
1478 (v2f16 (COPY $src0))
1482 (v2i16 (build_vector (i16 undef), i16:$src1)),
1483 (v2i16 (COPY (S_LSHL_B32 $src1, (i32 16))))
1487 (v2f16 (build_vector (f16 undef), f16:$src1)),
1488 (v2f16 (COPY (S_LSHL_B32 $src1, (i32 16))))
1491 let SubtargetPredicate = HasVOP3PInsts in {
1493 (v2i16 (build_vector i16:$src0, i16:$src1)),
1494 (v2i16 (S_PACK_LL_B32_B16 $src0, $src1))
1497 // With multiple uses of the shift, this will duplicate the shift and
1498 // increase register pressure.
1500 (v2i16 (build_vector i16:$src0, (i16 (trunc (srl_oneuse i32:$src1, (i32 16)))))),
1501 (v2i16 (S_PACK_LH_B32_B16 i16:$src0, i32:$src1))
1506 (v2i16 (build_vector (i16 (trunc (srl_oneuse i32:$src0, (i32 16)))),
1507 (i16 (trunc (srl_oneuse i32:$src1, (i32 16)))))),
1508 (v2i16 (S_PACK_HH_B32_B16 $src0, $src1))
1511 // TODO: Should source modifiers be matched to v_pack_b32_f16?
1513 (v2f16 (build_vector f16:$src0, f16:$src1)),
1514 (v2f16 (S_PACK_LL_B32_B16 $src0, $src1))
1517 } // End SubtargetPredicate = HasVOP3PInsts
1521 // (v2f16 (scalar_to_vector f16:$src0)),
1526 // (v2i16 (scalar_to_vector i16:$src0)),
1531 (v4i16 (scalar_to_vector i16:$src0)),
1532 (INSERT_SUBREG (IMPLICIT_DEF), $src0, sub0)
1536 (v4f16 (scalar_to_vector f16:$src0)),
1537 (INSERT_SUBREG (IMPLICIT_DEF), $src0, sub0)
1540 //===----------------------------------------------------------------------===//
1542 //===----------------------------------------------------------------------===//
1544 let SubtargetPredicate = isSI in {
1546 // V_FRACT is buggy on SI, so the F32 version is never used and (x-floor(x)) is
1547 // used instead. However, SI doesn't have V_FLOOR_F64, so the most efficient
1548 // way to implement it is using V_FRACT_F64.
1549 // The workaround for the V_FRACT bug is:
1550 // fract(x) = isnan(x) ? x : min(V_FRACT(x), 0.99999999999999999)
1552 // Convert floor(x) to (x - fract(x))
1554 (f64 (ffloor (f64 (VOP3Mods f64:$x, i32:$mods)))),
1559 (V_CNDMASK_B64_PSEUDO
1562 (V_FRACT_F64_e64 $mods, $x, DSTCLAMP.NONE, DSTOMOD.NONE),
1564 (V_MOV_B64_PSEUDO 0x3fefffffffffffff),
1565 DSTCLAMP.NONE, DSTOMOD.NONE),
1567 (V_CMP_CLASS_F64_e64 SRCMODS.NONE, $x, (i32 3 /*NaN*/))),
1568 DSTCLAMP.NONE, DSTOMOD.NONE)
1571 } // End SubtargetPredicates = isSI
1573 //============================================================================//
1574 // Miscellaneous Optimization Patterns
1575 //============================================================================//
1577 // Undo sub x, c -> add x, -c canonicalization since c is more likely
1578 // an inline immediate than -c.
1579 // TODO: Also do for 64-bit.
1581 (add i32:$src0, (i32 NegSubInlineConst32:$src1)),
1582 (S_SUB_I32 $src0, NegSubInlineConst32:$src1)
1586 multiclass BFMPatterns <ValueType vt, InstSI BFM, InstSI MOV> {
1588 (vt (shl (vt (add (vt (shl 1, vt:$a)), -1)), vt:$b)),
1593 (vt (add (vt (shl 1, vt:$a)), -1)),
1594 (BFM $a, (MOV (i32 0)))
1598 let SubtargetPredicate = isGCN in {
1600 defm : BFMPatterns <i32, S_BFM_B32, S_MOV_B32>;
1601 // FIXME: defm : BFMPatterns <i64, S_BFM_B64, S_MOV_B64>;
1603 defm : BFEPattern <V_BFE_U32, V_BFE_I32, S_MOV_B32>;
1604 defm : SHA256MaPattern <V_BFI_B32, V_XOR_B32_e64, SReg_64>;
1606 def : IntMed3Pat<V_MED3_I32, smax, smax_oneuse, smin_oneuse>;
1607 def : IntMed3Pat<V_MED3_U32, umax, umax_oneuse, umin_oneuse>;
1611 // This matches 16 permutations of
1612 // max(min(x, y), min(max(x, y), z))
1613 class FPMed3Pat<ValueType vt,
1614 Instruction med3Inst> : GCNPat<
1615 (fmaxnum (fminnum_oneuse (VOP3Mods_nnan vt:$src0, i32:$src0_mods),
1616 (VOP3Mods_nnan vt:$src1, i32:$src1_mods)),
1617 (fminnum_oneuse (fmaxnum_oneuse (VOP3Mods_nnan vt:$src0, i32:$src0_mods),
1618 (VOP3Mods_nnan vt:$src1, i32:$src1_mods)),
1619 (vt (VOP3Mods_nnan vt:$src2, i32:$src2_mods)))),
1620 (med3Inst $src0_mods, $src0, $src1_mods, $src1, $src2_mods, $src2, DSTCLAMP.NONE, DSTOMOD.NONE)
1623 class FP16Med3Pat<ValueType vt,
1624 Instruction med3Inst> : GCNPat<
1625 (fmaxnum (fminnum_oneuse (VOP3Mods_nnan vt:$src0, i32:$src0_mods),
1626 (VOP3Mods_nnan vt:$src1, i32:$src1_mods)),
1627 (fminnum_oneuse (fmaxnum_oneuse (VOP3Mods_nnan vt:$src0, i32:$src0_mods),
1628 (VOP3Mods_nnan vt:$src1, i32:$src1_mods)),
1629 (vt (VOP3Mods_nnan vt:$src2, i32:$src2_mods)))),
1630 (med3Inst $src0_mods, $src0, $src1_mods, $src1, $src2_mods, $src2, DSTCLAMP.NONE)
1633 class Int16Med3Pat<Instruction med3Inst,
1634 SDPatternOperator max,
1635 SDPatternOperator max_oneuse,
1636 SDPatternOperator min_oneuse,
1637 ValueType vt = i32> : GCNPat<
1638 (max (min_oneuse vt:$src0, vt:$src1),
1639 (min_oneuse (max_oneuse vt:$src0, vt:$src1), vt:$src2)),
1640 (med3Inst SRCMODS.NONE, $src0, SRCMODS.NONE, $src1, SRCMODS.NONE, $src2, DSTCLAMP.NONE)
1643 def : FPMed3Pat<f32, V_MED3_F32>;
1645 let OtherPredicates = [isGFX9] in {
1646 def : FP16Med3Pat<f16, V_MED3_F16>;
1647 def : Int16Med3Pat<V_MED3_I16, smax, smax_oneuse, smin_oneuse, i16>;
1648 def : Int16Med3Pat<V_MED3_U16, umax, umax_oneuse, umin_oneuse, i16>;
1649 } // End Predicates = [isGFX9]