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, SALU = 1 in {
168 def GET_GROUPSTATICSIZE : PseudoInstSI <(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 : PseudoInstSI<(outs SReg_64:$dst),
173 (ins SSrc_b64:$src0)> {
175 let isAsCheapAsAMove = 1;
176 let isTerminator = 1;
179 def S_XOR_B64_term : PseudoInstSI<(outs SReg_64:$dst),
180 (ins SSrc_b64:$src0, SSrc_b64:$src1)> {
182 let isAsCheapAsAMove = 1;
183 let isTerminator = 1;
187 def S_ANDN2_B64_term : PseudoInstSI<(outs SReg_64:$dst),
188 (ins SSrc_b64:$src0, SSrc_b64:$src1)> {
190 let isAsCheapAsAMove = 1;
191 let isTerminator = 1;
194 def WAVE_BARRIER : SPseudoInstSI<(outs), (ins),
195 [(int_amdgcn_wave_barrier)]> {
197 let hasNoSchedulingInfo = 1;
198 let hasSideEffects = 1;
202 let isConvergent = 1;
207 // SI pseudo instructions. These are used by the CFG structurizer pass
208 // and should be lowered to ISA instructions prior to codegen.
210 // Dummy terminator instruction to use after control flow instructions
211 // replaced with exec mask operations.
212 def SI_MASK_BRANCH : VPseudoInstSI <
213 (outs), (ins brtarget:$target)> {
215 let isTerminator = 1;
218 let hasNoSchedulingInfo = 1;
223 let isTerminator = 1 in {
225 let OtherPredicates = [EnableLateCFGStructurize] in {
226 def SI_NON_UNIFORM_BRCOND_PSEUDO : CFPseudoInstSI <
228 (ins SReg_64:$vcc, brtarget:$target),
229 [(brcond i1:$vcc, bb:$target)]> {
234 def SI_IF: CFPseudoInstSI <
235 (outs SReg_64:$dst), (ins SReg_64:$vcc, brtarget:$target),
236 [(set i64:$dst, (AMDGPUif i1:$vcc, bb:$target))], 1, 1> {
237 let Constraints = "";
239 let hasSideEffects = 1;
242 def SI_ELSE : CFPseudoInstSI <
244 (ins SReg_64:$src, brtarget:$target, i1imm:$execfix), [], 1, 1> {
246 let hasSideEffects = 1;
249 def SI_LOOP : CFPseudoInstSI <
250 (outs), (ins SReg_64:$saved, brtarget:$target),
251 [(AMDGPUloop i64:$saved, bb:$target)], 1, 1> {
254 let hasSideEffects = 1;
257 } // End isTerminator = 1
259 def SI_END_CF : CFPseudoInstSI <
260 (outs), (ins SReg_64:$saved),
261 [(int_amdgcn_end_cf i64:$saved)], 1, 1> {
263 let isAsCheapAsAMove = 1;
264 let isReMaterializable = 1;
265 let hasSideEffects = 1;
266 let mayLoad = 1; // FIXME: Should not need memory flags
270 def SI_BREAK : CFPseudoInstSI <
271 (outs SReg_64:$dst), (ins SReg_64:$src),
272 [(set i64:$dst, (int_amdgcn_break i64:$src))], 1> {
274 let isAsCheapAsAMove = 1;
275 let isReMaterializable = 1;
278 def SI_IF_BREAK : CFPseudoInstSI <
279 (outs SReg_64:$dst), (ins SReg_64:$vcc, SReg_64:$src),
280 [(set i64:$dst, (int_amdgcn_if_break i1:$vcc, i64:$src))]> {
282 let isAsCheapAsAMove = 1;
283 let isReMaterializable = 1;
286 def SI_ELSE_BREAK : CFPseudoInstSI <
287 (outs SReg_64:$dst), (ins SReg_64:$src0, SReg_64:$src1),
288 [(set i64:$dst, (int_amdgcn_else_break i64:$src0, i64:$src1))]> {
290 let isAsCheapAsAMove = 1;
291 let isReMaterializable = 1;
294 let Uses = [EXEC] in {
296 multiclass PseudoInstKill <dag ins> {
297 // Even though this pseudo can usually be expanded without an SCC def, we
298 // conservatively assume that it has an SCC def, both because it is sometimes
299 // required in degenerate cases (when V_CMPX cannot be used due to constant
300 // bus limitations) and because it allows us to avoid having to track SCC
301 // liveness across basic blocks.
302 let Defs = [EXEC,VCC,SCC] in
303 def _PSEUDO : PseudoInstSI <(outs), ins> {
304 let isConvergent = 1;
305 let usesCustomInserter = 1;
308 let Defs = [EXEC,VCC,SCC] in
309 def _TERMINATOR : SPseudoInstSI <(outs), ins> {
310 let isTerminator = 1;
314 defm SI_KILL_I1 : PseudoInstKill <(ins SSrc_b64:$src, i1imm:$killvalue)>;
315 defm SI_KILL_F32_COND_IMM : PseudoInstKill <(ins VSrc_b32:$src0, i32imm:$src1, i32imm:$cond)>;
317 let Defs = [EXEC,VCC] in
318 def SI_ILLEGAL_COPY : SPseudoInstSI <
319 (outs unknown:$dst), (ins unknown:$src),
320 [], " ; illegal copy $src to $dst">;
322 } // End Uses = [EXEC], Defs = [EXEC,VCC]
324 // Branch on undef scc. Used to avoid intermediate copy from
325 // IMPLICIT_DEF to SCC.
326 def SI_BR_UNDEF : SPseudoInstSI <(outs), (ins sopp_brtarget:$simm16)> {
327 let isTerminator = 1;
328 let usesCustomInserter = 1;
331 def SI_PS_LIVE : PseudoInstSI <
332 (outs SReg_64:$dst), (ins),
333 [(set i1:$dst, (int_amdgcn_ps_live))]> {
337 def SI_MASKED_UNREACHABLE : SPseudoInstSI <(outs), (ins),
338 [(int_amdgcn_unreachable)],
339 "; divergent unreachable"> {
341 let hasNoSchedulingInfo = 1;
345 // Used as an isel pseudo to directly emit initialization with an
346 // s_mov_b32 rather than a copy of another initialized
347 // register. MachineCSE skips copies, and we don't want to have to
348 // fold operands before it runs.
349 def SI_INIT_M0 : SPseudoInstSI <(outs), (ins SSrc_b32:$src)> {
351 let usesCustomInserter = 1;
352 let isAsCheapAsAMove = 1;
353 let isReMaterializable = 1;
356 def SI_INIT_EXEC : SPseudoInstSI <
357 (outs), (ins i64imm:$src), []> {
359 let usesCustomInserter = 1;
360 let isAsCheapAsAMove = 1;
363 def SI_INIT_EXEC_FROM_INPUT : SPseudoInstSI <
364 (outs), (ins SSrc_b32:$input, i32imm:$shift), []> {
366 let usesCustomInserter = 1;
369 // Return for returning shaders to a shader variant epilog.
370 def SI_RETURN_TO_EPILOG : SPseudoInstSI <
371 (outs), (ins variable_ops), [(AMDGPUreturn_to_epilog)]> {
372 let isTerminator = 1;
375 let hasNoSchedulingInfo = 1;
380 // Return for returning function calls.
381 def SI_RETURN : SPseudoInstSI <
384 let isTerminator = 1;
387 let SchedRW = [WriteBranch];
390 // Return for returning function calls without output register.
392 // This version is only needed so we can fill in the output regiter in
393 // the custom inserter.
394 def SI_CALL_ISEL : SPseudoInstSI <
395 (outs), (ins SSrc_b64:$src0), [(AMDGPUcall i64:$src0)]> {
398 let SchedRW = [WriteBranch];
399 let usesCustomInserter = 1;
402 // Wrapper around s_swappc_b64 with extra $callee parameter to track
403 // the called function after regalloc.
404 def SI_CALL : SPseudoInstSI <
405 (outs SReg_64:$dst), (ins SSrc_b64:$src0, unknown:$callee)> {
408 let UseNamedOperandTable = 1;
409 let SchedRW = [WriteBranch];
412 // Tail call handling pseudo
413 def SI_TCRETURN_ISEL : SPseudoInstSI<(outs),
414 (ins SSrc_b64:$src0, i32imm:$fpdiff),
415 [(AMDGPUtc_return i64:$src0, i32:$fpdiff)]> {
417 let isTerminator = 1;
420 let SchedRW = [WriteBranch];
421 let usesCustomInserter = 1;
424 def SI_TCRETURN : SPseudoInstSI <
426 (ins SSrc_b64:$src0, unknown:$callee, i32imm:$fpdiff)> {
429 let isTerminator = 1;
432 let UseNamedOperandTable = 1;
433 let SchedRW = [WriteBranch];
437 def ADJCALLSTACKUP : SPseudoInstSI<
438 (outs), (ins i32imm:$amt0, i32imm:$amt1),
439 [(callseq_start timm:$amt0, timm:$amt1)],
440 "; adjcallstackup $amt0 $amt1"> {
441 let Size = 8; // Worst case. (s_add_u32 + constant)
443 let hasSideEffects = 1;
444 let usesCustomInserter = 1;
447 def ADJCALLSTACKDOWN : SPseudoInstSI<
448 (outs), (ins i32imm:$amt1, i32imm:$amt2),
449 [(callseq_end timm:$amt1, timm:$amt2)],
450 "; adjcallstackdown $amt1"> {
451 let Size = 8; // Worst case. (s_add_u32 + constant)
452 let hasSideEffects = 1;
453 let usesCustomInserter = 1;
456 let Defs = [M0, EXEC, SCC],
457 UseNamedOperandTable = 1 in {
459 class SI_INDIRECT_SRC<RegisterClass rc> : VPseudoInstSI <
460 (outs VGPR_32:$vdst),
461 (ins rc:$src, VS_32:$idx, i32imm:$offset)> {
462 let usesCustomInserter = 1;
465 class SI_INDIRECT_DST<RegisterClass rc> : VPseudoInstSI <
467 (ins rc:$src, VS_32:$idx, i32imm:$offset, VGPR_32:$val)> {
468 let Constraints = "$src = $vdst";
469 let usesCustomInserter = 1;
472 // TODO: We can support indirect SGPR access.
473 def SI_INDIRECT_SRC_V1 : SI_INDIRECT_SRC<VGPR_32>;
474 def SI_INDIRECT_SRC_V2 : SI_INDIRECT_SRC<VReg_64>;
475 def SI_INDIRECT_SRC_V4 : SI_INDIRECT_SRC<VReg_128>;
476 def SI_INDIRECT_SRC_V8 : SI_INDIRECT_SRC<VReg_256>;
477 def SI_INDIRECT_SRC_V16 : SI_INDIRECT_SRC<VReg_512>;
479 def SI_INDIRECT_DST_V1 : SI_INDIRECT_DST<VGPR_32>;
480 def SI_INDIRECT_DST_V2 : SI_INDIRECT_DST<VReg_64>;
481 def SI_INDIRECT_DST_V4 : SI_INDIRECT_DST<VReg_128>;
482 def SI_INDIRECT_DST_V8 : SI_INDIRECT_DST<VReg_256>;
483 def SI_INDIRECT_DST_V16 : SI_INDIRECT_DST<VReg_512>;
485 } // End Uses = [EXEC], Defs = [M0, EXEC]
487 multiclass SI_SPILL_SGPR <RegisterClass sgpr_class> {
488 let UseNamedOperandTable = 1, SGPRSpill = 1, Uses = [EXEC] in {
489 def _SAVE : PseudoInstSI <
491 (ins sgpr_class:$data, i32imm:$addr)> {
496 def _RESTORE : PseudoInstSI <
497 (outs sgpr_class:$data),
498 (ins i32imm:$addr)> {
502 } // End UseNamedOperandTable = 1
505 // You cannot use M0 as the output of v_readlane_b32 instructions or
506 // use it in the sdata operand of SMEM instructions. We still need to
507 // be able to spill the physical register m0, so allow it for
508 // SI_SPILL_32_* instructions.
509 defm SI_SPILL_S32 : SI_SPILL_SGPR <SReg_32>;
510 defm SI_SPILL_S64 : SI_SPILL_SGPR <SReg_64>;
511 defm SI_SPILL_S128 : SI_SPILL_SGPR <SReg_128>;
512 defm SI_SPILL_S256 : SI_SPILL_SGPR <SReg_256>;
513 defm SI_SPILL_S512 : SI_SPILL_SGPR <SReg_512>;
515 multiclass SI_SPILL_VGPR <RegisterClass vgpr_class> {
516 let UseNamedOperandTable = 1, VGPRSpill = 1,
517 SchedRW = [WriteVMEM] in {
518 def _SAVE : VPseudoInstSI <
520 (ins vgpr_class:$vdata, i32imm:$vaddr, SReg_128:$srsrc,
521 SReg_32:$soffset, i32imm:$offset)> {
524 // (2 * 4) + (8 * num_subregs) bytes maximum
525 let Size = !add(!shl(!srl(vgpr_class.Size, 5), 3), 8);
528 def _RESTORE : VPseudoInstSI <
529 (outs vgpr_class:$vdata),
530 (ins i32imm:$vaddr, SReg_128:$srsrc, SReg_32:$soffset,
535 // (2 * 4) + (8 * num_subregs) bytes maximum
536 let Size = !add(!shl(!srl(vgpr_class.Size, 5), 3), 8);
538 } // End UseNamedOperandTable = 1, VGPRSpill = 1, SchedRW = [WriteVMEM]
541 defm SI_SPILL_V32 : SI_SPILL_VGPR <VGPR_32>;
542 defm SI_SPILL_V64 : SI_SPILL_VGPR <VReg_64>;
543 defm SI_SPILL_V96 : SI_SPILL_VGPR <VReg_96>;
544 defm SI_SPILL_V128 : SI_SPILL_VGPR <VReg_128>;
545 defm SI_SPILL_V256 : SI_SPILL_VGPR <VReg_256>;
546 defm SI_SPILL_V512 : SI_SPILL_VGPR <VReg_512>;
548 def SI_PC_ADD_REL_OFFSET : SPseudoInstSI <
550 (ins si_ga:$ptr_lo, si_ga:$ptr_hi),
552 (i64 (SIpc_add_rel_offset (tglobaladdr:$ptr_lo), (tglobaladdr:$ptr_hi))))]> {
557 (AMDGPUinit_exec i64:$src),
558 (SI_INIT_EXEC (as_i64imm $src))
562 (AMDGPUinit_exec_from_input i32:$input, i32:$shift),
563 (SI_INIT_EXEC_FROM_INPUT (i32 $input), (as_i32imm $shift))
567 (AMDGPUtrap timm:$trapid),
572 (AMDGPUelse i64:$src, bb:$target),
573 (SI_ELSE $src, $target, 0)
577 // -1.0 as i32 (LowerINTRINSIC_VOID converts all other constants to -1.0)
578 (AMDGPUkill (i32 -1082130432)),
579 (SI_KILL_I1_PSEUDO (i1 0), 0)
583 (int_amdgcn_kill i1:$src),
584 (SI_KILL_I1_PSEUDO $src, 0)
588 (int_amdgcn_kill (i1 (not i1:$src))),
589 (SI_KILL_I1_PSEUDO $src, -1)
593 (AMDGPUkill i32:$src),
594 (SI_KILL_F32_COND_IMM_PSEUDO $src, 0, 3) // 3 means SETOGE
598 (int_amdgcn_kill (i1 (setcc f32:$src, InlineFPImm<f32>:$imm, cond:$cond))),
599 (SI_KILL_F32_COND_IMM_PSEUDO $src, (bitcast_fpimm_to_i32 $imm), (cond_as_i32imm $cond))
601 // TODO: we could add more variants for other types of conditionals
603 //===----------------------------------------------------------------------===//
605 //===----------------------------------------------------------------------===//
607 let SubtargetPredicate = isGCN, OtherPredicates = [UnsafeFPMath] in {
609 //def : RcpPat<V_RCP_F64_e32, f64>;
610 //defm : RsqPat<V_RSQ_F64_e32, f64>;
611 //defm : RsqPat<V_RSQ_F32_e32, f32>;
613 def : RsqPat<V_RSQ_F32_e32, f32>;
614 def : RsqPat<V_RSQ_F64_e32, f64>;
616 // Convert (x - floor(x)) to fract(x)
618 (f32 (fsub (f32 (VOP3Mods f32:$x, i32:$mods)),
619 (f32 (ffloor (f32 (VOP3Mods f32:$x, i32:$mods)))))),
620 (V_FRACT_F32_e64 $mods, $x, DSTCLAMP.NONE, DSTOMOD.NONE)
623 // Convert (x + (-floor(x))) to fract(x)
625 (f64 (fadd (f64 (VOP3Mods f64:$x, i32:$mods)),
626 (f64 (fneg (f64 (ffloor (f64 (VOP3Mods f64:$x, i32:$mods)))))))),
627 (V_FRACT_F64_e64 $mods, $x, DSTCLAMP.NONE, DSTOMOD.NONE)
630 } // End SubtargetPredicate = isGCN, OtherPredicates = [UnsafeFPMath]
633 // f16_to_fp patterns
635 (f32 (f16_to_fp i32:$src0)),
636 (V_CVT_F32_F16_e64 SRCMODS.NONE, $src0, DSTCLAMP.NONE, DSTOMOD.NONE)
640 (f32 (f16_to_fp (and_oneuse i32:$src0, 0x7fff))),
641 (V_CVT_F32_F16_e64 SRCMODS.ABS, $src0, DSTCLAMP.NONE, DSTOMOD.NONE)
645 (f32 (f16_to_fp (i32 (srl_oneuse (and_oneuse i32:$src0, 0x7fff0000), (i32 16))))),
646 (V_CVT_F32_F16_e64 SRCMODS.ABS, (i32 (V_LSHRREV_B32_e64 (i32 16), i32:$src0)), DSTCLAMP.NONE, DSTOMOD.NONE)
650 (f32 (f16_to_fp (or_oneuse i32:$src0, 0x8000))),
651 (V_CVT_F32_F16_e64 SRCMODS.NEG_ABS, $src0, DSTCLAMP.NONE, DSTOMOD.NONE)
655 (f32 (f16_to_fp (xor_oneuse i32:$src0, 0x8000))),
656 (V_CVT_F32_F16_e64 SRCMODS.NEG, $src0, DSTCLAMP.NONE, DSTOMOD.NONE)
660 (f64 (fpextend f16:$src)),
661 (V_CVT_F64_F32_e32 (V_CVT_F32_F16_e32 $src))
664 // fp_to_fp16 patterns
666 (i32 (AMDGPUfp_to_f16 (f32 (VOP3Mods f32:$src0, i32:$src0_modifiers)))),
667 (V_CVT_F16_F32_e64 $src0_modifiers, f32:$src0, DSTCLAMP.NONE, DSTOMOD.NONE)
671 (i32 (fp_to_sint f16:$src)),
672 (V_CVT_I32_F32_e32 (V_CVT_F32_F16_e32 $src))
676 (i32 (fp_to_uint f16:$src)),
677 (V_CVT_U32_F32_e32 (V_CVT_F32_F16_e32 $src))
681 (f16 (sint_to_fp i32:$src)),
682 (V_CVT_F16_F32_e32 (V_CVT_F32_I32_e32 $src))
686 (f16 (uint_to_fp i32:$src)),
687 (V_CVT_F16_F32_e32 (V_CVT_F32_U32_e32 $src))
690 //===----------------------------------------------------------------------===//
692 //===----------------------------------------------------------------------===//
694 multiclass FMADPat <ValueType vt, Instruction inst> {
696 (vt (fmad (VOP3NoMods vt:$src0),
697 (VOP3NoMods vt:$src1),
698 (VOP3NoMods vt:$src2))),
699 (inst SRCMODS.NONE, $src0, SRCMODS.NONE, $src1,
700 SRCMODS.NONE, $src2, DSTCLAMP.NONE, DSTOMOD.NONE)
704 defm : FMADPat <f16, V_MAC_F16_e64>;
705 defm : FMADPat <f32, V_MAC_F32_e64>;
707 class FMADModsPat<Instruction inst, SDPatternOperator mad_opr, ValueType Ty>
709 (Ty (mad_opr (VOP3Mods Ty:$src0, i32:$src0_mod),
710 (VOP3Mods Ty:$src1, i32:$src1_mod),
711 (VOP3Mods Ty:$src2, i32:$src2_mod))),
712 (inst $src0_mod, $src0, $src1_mod, $src1,
713 $src2_mod, $src2, DSTCLAMP.NONE, DSTOMOD.NONE)
716 def : FMADModsPat<V_MAD_F32, AMDGPUfmad_ftz, f32>;
717 def : FMADModsPat<V_MAD_F16, AMDGPUfmad_ftz, f16> {
718 let SubtargetPredicate = Has16BitInsts;
721 multiclass SelectPat <ValueType vt, Instruction inst> {
723 (vt (select i1:$src0, vt:$src1, vt:$src2)),
724 (inst $src2, $src1, $src0)
728 defm : SelectPat <i16, V_CNDMASK_B32_e64>;
729 defm : SelectPat <i32, V_CNDMASK_B32_e64>;
730 defm : SelectPat <f16, V_CNDMASK_B32_e64>;
731 defm : SelectPat <f32, V_CNDMASK_B32_e64>;
734 (i32 (add (i32 (ctpop i32:$popcnt)), i32:$val)),
735 (V_BCNT_U32_B32_e64 $popcnt, $val)
738 (i16 (add (i16 (trunc (ctpop i32:$popcnt))), i16:$val)),
739 (V_BCNT_U32_B32_e64 $popcnt, $val)
742 /********** ============================================ **********/
743 /********** Extraction, Insertion, Building and Casting **********/
744 /********** ============================================ **********/
746 foreach Index = 0-2 in {
747 def Extract_Element_v2i32_#Index : Extract_Element <
748 i32, v2i32, Index, !cast<SubRegIndex>(sub#Index)
750 def Insert_Element_v2i32_#Index : Insert_Element <
751 i32, v2i32, Index, !cast<SubRegIndex>(sub#Index)
754 def Extract_Element_v2f32_#Index : Extract_Element <
755 f32, v2f32, Index, !cast<SubRegIndex>(sub#Index)
757 def Insert_Element_v2f32_#Index : Insert_Element <
758 f32, v2f32, Index, !cast<SubRegIndex>(sub#Index)
762 foreach Index = 0-3 in {
763 def Extract_Element_v4i32_#Index : Extract_Element <
764 i32, v4i32, Index, !cast<SubRegIndex>(sub#Index)
766 def Insert_Element_v4i32_#Index : Insert_Element <
767 i32, v4i32, Index, !cast<SubRegIndex>(sub#Index)
770 def Extract_Element_v4f32_#Index : Extract_Element <
771 f32, v4f32, Index, !cast<SubRegIndex>(sub#Index)
773 def Insert_Element_v4f32_#Index : Insert_Element <
774 f32, v4f32, Index, !cast<SubRegIndex>(sub#Index)
778 foreach Index = 0-7 in {
779 def Extract_Element_v8i32_#Index : Extract_Element <
780 i32, v8i32, Index, !cast<SubRegIndex>(sub#Index)
782 def Insert_Element_v8i32_#Index : Insert_Element <
783 i32, v8i32, Index, !cast<SubRegIndex>(sub#Index)
786 def Extract_Element_v8f32_#Index : Extract_Element <
787 f32, v8f32, Index, !cast<SubRegIndex>(sub#Index)
789 def Insert_Element_v8f32_#Index : Insert_Element <
790 f32, v8f32, Index, !cast<SubRegIndex>(sub#Index)
794 foreach Index = 0-15 in {
795 def Extract_Element_v16i32_#Index : Extract_Element <
796 i32, v16i32, Index, !cast<SubRegIndex>(sub#Index)
798 def Insert_Element_v16i32_#Index : Insert_Element <
799 i32, v16i32, Index, !cast<SubRegIndex>(sub#Index)
802 def Extract_Element_v16f32_#Index : Extract_Element <
803 f32, v16f32, Index, !cast<SubRegIndex>(sub#Index)
805 def Insert_Element_v16f32_#Index : Insert_Element <
806 f32, v16f32, Index, !cast<SubRegIndex>(sub#Index)
812 (extract_subvector v4i16:$vec, (i32 0)),
813 (v2i16 (EXTRACT_SUBREG v4i16:$vec, sub0))
817 (extract_subvector v4i16:$vec, (i32 2)),
818 (v2i16 (EXTRACT_SUBREG v4i16:$vec, sub1))
822 (extract_subvector v4f16:$vec, (i32 0)),
823 (v2f16 (EXTRACT_SUBREG v4f16:$vec, sub0))
827 (extract_subvector v4f16:$vec, (i32 2)),
828 (v2f16 (EXTRACT_SUBREG v4f16:$vec, sub1))
831 let SubtargetPredicate = isGCN in {
833 // FIXME: Why do only some of these type combinations for SReg and
836 def : BitConvert <i16, f16, VGPR_32>;
837 def : BitConvert <f16, i16, VGPR_32>;
838 def : BitConvert <i16, f16, SReg_32>;
839 def : BitConvert <f16, i16, SReg_32>;
842 def : BitConvert <i32, f32, VGPR_32>;
843 def : BitConvert <f32, i32, VGPR_32>;
844 def : BitConvert <i32, f32, SReg_32>;
845 def : BitConvert <f32, i32, SReg_32>;
846 def : BitConvert <v2i16, i32, SReg_32>;
847 def : BitConvert <i32, v2i16, SReg_32>;
848 def : BitConvert <v2f16, i32, SReg_32>;
849 def : BitConvert <i32, v2f16, SReg_32>;
850 def : BitConvert <v2i16, v2f16, SReg_32>;
851 def : BitConvert <v2f16, v2i16, SReg_32>;
852 def : BitConvert <v2f16, f32, SReg_32>;
853 def : BitConvert <f32, v2f16, SReg_32>;
854 def : BitConvert <v2i16, f32, SReg_32>;
855 def : BitConvert <f32, v2i16, SReg_32>;
858 def : BitConvert <i64, f64, VReg_64>;
859 def : BitConvert <f64, i64, VReg_64>;
860 def : BitConvert <v2i32, v2f32, VReg_64>;
861 def : BitConvert <v2f32, v2i32, VReg_64>;
862 def : BitConvert <i64, v2i32, VReg_64>;
863 def : BitConvert <v2i32, i64, VReg_64>;
864 def : BitConvert <i64, v2f32, VReg_64>;
865 def : BitConvert <v2f32, i64, VReg_64>;
866 def : BitConvert <f64, v2f32, VReg_64>;
867 def : BitConvert <v2f32, f64, VReg_64>;
868 def : BitConvert <f64, v2i32, VReg_64>;
869 def : BitConvert <v2i32, f64, VReg_64>;
872 def : BitConvert <v2i32, v4f16, VReg_64>;
873 def : BitConvert <v4f16, v2i32, VReg_64>;
874 def : BitConvert <v2i32, v4f16, VReg_64>;
875 def : BitConvert <v2i32, v4i16, VReg_64>;
876 def : BitConvert <v4i16, v2i32, VReg_64>;
877 def : BitConvert <v2f32, v4f16, VReg_64>;
878 def : BitConvert <v4f16, v2f32, VReg_64>;
879 def : BitConvert <v2f32, v4i16, VReg_64>;
880 def : BitConvert <v4i16, v2f32, VReg_64>;
881 def : BitConvert <v4i16, f64, VReg_64>;
882 def : BitConvert <v4f16, f64, VReg_64>;
883 def : BitConvert <f64, v4i16, VReg_64>;
884 def : BitConvert <f64, v4f16, VReg_64>;
885 def : BitConvert <v4i16, i64, VReg_64>;
886 def : BitConvert <v4f16, i64, VReg_64>;
887 def : BitConvert <i64, v4i16, VReg_64>;
888 def : BitConvert <i64, v4f16, VReg_64>;
890 def : BitConvert <v4i32, v4f32, VReg_128>;
891 def : BitConvert <v4f32, v4i32, VReg_128>;
894 def : BitConvert <v2i64, v4i32, SReg_128>;
895 def : BitConvert <v4i32, v2i64, SReg_128>;
896 def : BitConvert <v2f64, v4f32, VReg_128>;
897 def : BitConvert <v2f64, v4i32, VReg_128>;
898 def : BitConvert <v4f32, v2f64, VReg_128>;
899 def : BitConvert <v4i32, v2f64, VReg_128>;
900 def : BitConvert <v2i64, v2f64, VReg_128>;
901 def : BitConvert <v2f64, v2i64, VReg_128>;
904 def : BitConvert <v8i32, v8f32, SReg_256>;
905 def : BitConvert <v8f32, v8i32, SReg_256>;
906 def : BitConvert <v8i32, v8f32, VReg_256>;
907 def : BitConvert <v8f32, v8i32, VReg_256>;
910 def : BitConvert <v16i32, v16f32, VReg_512>;
911 def : BitConvert <v16f32, v16i32, VReg_512>;
913 } // End SubtargetPredicate = isGCN
915 /********** =================== **********/
916 /********** Src & Dst modifiers **********/
917 /********** =================== **********/
920 // If denormals are not enabled, it only impacts the compare of the
921 // inputs. The output result is not flushed.
922 class ClampPat<Instruction inst, ValueType vt> : GCNPat <
923 (vt (AMDGPUclamp (VOP3Mods vt:$src0, i32:$src0_modifiers))),
924 (inst i32:$src0_modifiers, vt:$src0,
925 i32:$src0_modifiers, vt:$src0, DSTCLAMP.ENABLE, DSTOMOD.NONE)
928 def : ClampPat<V_MAX_F32_e64, f32>;
929 def : ClampPat<V_MAX_F64, f64>;
930 def : ClampPat<V_MAX_F16_e64, f16>;
932 let SubtargetPredicate = HasVOP3PInsts in {
934 (v2f16 (AMDGPUclamp (VOP3PMods v2f16:$src0, i32:$src0_modifiers))),
935 (V_PK_MAX_F16 $src0_modifiers, $src0,
936 $src0_modifiers, $src0, DSTCLAMP.ENABLE)
940 /********** ================================ **********/
941 /********** Floating point absolute/negative **********/
942 /********** ================================ **********/
944 // Prevent expanding both fneg and fabs.
947 (fneg (fabs f32:$src)),
948 (S_OR_B32 $src, (S_MOV_B32(i32 0x80000000))) // Set sign bit
951 // FIXME: Should use S_OR_B32
953 (fneg (fabs f64:$src)),
954 (REG_SEQUENCE VReg_64,
955 (i32 (EXTRACT_SUBREG f64:$src, sub0)),
957 (V_OR_B32_e32 (i32 (EXTRACT_SUBREG f64:$src, sub1)),
958 (V_MOV_B32_e32 (i32 0x80000000))), // Set sign bit.
964 (S_AND_B32 $src, (S_MOV_B32 (i32 0x7fffffff)))
969 (V_XOR_B32_e32 $src, (V_MOV_B32_e32 (i32 0x80000000)))
974 (REG_SEQUENCE VReg_64,
975 (i32 (EXTRACT_SUBREG f64:$src, sub0)),
977 (V_AND_B32_e64 (i32 (EXTRACT_SUBREG f64:$src, sub1)),
978 (V_MOV_B32_e32 (i32 0x7fffffff))), // Set sign bit.
984 (REG_SEQUENCE VReg_64,
985 (i32 (EXTRACT_SUBREG f64:$src, sub0)),
987 (V_XOR_B32_e32 (i32 (EXTRACT_SUBREG f64:$src, sub1)),
988 (i32 (V_MOV_B32_e32 (i32 0x80000000)))),
993 (fcopysign f16:$src0, f16:$src1),
994 (V_BFI_B32 (S_MOV_B32 (i32 0x00007fff)), $src0, $src1)
998 (fcopysign f32:$src0, f16:$src1),
999 (V_BFI_B32 (S_MOV_B32 (i32 0x7fffffff)), $src0,
1000 (V_LSHLREV_B32_e64 (i32 16), $src1))
1004 (fcopysign f64:$src0, f16:$src1),
1005 (REG_SEQUENCE SReg_64,
1006 (i32 (EXTRACT_SUBREG $src0, sub0)), sub0,
1007 (V_BFI_B32 (S_MOV_B32 (i32 0x7fffffff)), (i32 (EXTRACT_SUBREG $src0, sub1)),
1008 (V_LSHLREV_B32_e64 (i32 16), $src1)), sub1)
1012 (fcopysign f16:$src0, f32:$src1),
1013 (V_BFI_B32 (S_MOV_B32 (i32 0x00007fff)), $src0,
1014 (V_LSHRREV_B32_e64 (i32 16), $src1))
1018 (fcopysign f16:$src0, f64:$src1),
1019 (V_BFI_B32 (S_MOV_B32 (i32 0x00007fff)), $src0,
1020 (V_LSHRREV_B32_e64 (i32 16), (EXTRACT_SUBREG $src1, sub1)))
1025 (S_XOR_B32 $src, (S_MOV_B32 (i32 0x00008000)))
1030 (S_AND_B32 $src, (S_MOV_B32 (i32 0x00007fff)))
1034 (fneg (fabs f16:$src)),
1035 (S_OR_B32 $src, (S_MOV_B32 (i32 0x00008000))) // Set sign bit
1040 (S_XOR_B32 $src, (S_MOV_B32 (i32 0x80008000)))
1045 (S_AND_B32 $src, (S_MOV_B32 (i32 0x7fff7fff)))
1048 // This is really (fneg (fabs v2f16:$src))
1050 // fabs is not reported as free because there is modifier for it in
1051 // VOP3P instructions, so it is turned into the bit op.
1053 (fneg (v2f16 (bitconvert (and_oneuse i32:$src, 0x7fff7fff)))),
1054 (S_OR_B32 $src, (S_MOV_B32 (i32 0x80008000))) // Set sign bit
1058 (fneg (v2f16 (fabs v2f16:$src))),
1059 (S_OR_B32 $src, (S_MOV_B32 (i32 0x80008000))) // Set sign bit
1062 /********** ================== **********/
1063 /********** Immediate Patterns **********/
1064 /********** ================== **********/
1067 (VGPRImm<(i32 imm)>:$imm),
1068 (V_MOV_B32_e32 imm:$imm)
1072 (VGPRImm<(f32 fpimm)>:$imm),
1073 (V_MOV_B32_e32 (f32 (bitcast_fpimm_to_i32 $imm)))
1078 (S_MOV_B32 imm:$imm)
1081 // FIXME: Workaround for ordering issue with peephole optimizer where
1082 // a register class copy interferes with immediate folding. Should
1083 // use s_mov_b32, which can be shrunk to s_movk_i32
1085 (VGPRImm<(f16 fpimm)>:$imm),
1086 (V_MOV_B32_e32 (f16 (bitcast_fpimm_to_i32 $imm)))
1091 (S_MOV_B32 (f32 (bitcast_fpimm_to_i32 $imm)))
1096 (S_MOV_B32 (i32 (bitcast_fpimm_to_i32 $imm)))
1100 (i32 frameindex:$fi),
1101 (V_MOV_B32_e32 (i32 (frameindex_to_targetframeindex $fi)))
1105 (i64 InlineImm<i64>:$imm),
1106 (S_MOV_B64 InlineImm<i64>:$imm)
1109 // XXX - Should this use a s_cmp to set SCC?
1111 // Set to sign-extended 64-bit value (true = -1, false = 0)
1114 (S_MOV_B64 (i64 (as_i64imm $imm)))
1118 (f64 InlineFPImm<f64>:$imm),
1119 (S_MOV_B64 (f64 (bitcast_fpimm_to_i64 InlineFPImm<f64>:$imm)))
1122 /********** ================== **********/
1123 /********** Intrinsic Patterns **********/
1124 /********** ================== **********/
1126 let SubtargetPredicate = isGCN in {
1127 def : POW_Common <V_LOG_F32_e32, V_EXP_F32_e32, V_MUL_LEGACY_F32_e32>;
1131 (i32 (sext i1:$src0)),
1132 (V_CNDMASK_B32_e64 (i32 0), (i32 -1), $src0)
1135 class Ext32Pat <SDNode ext> : GCNPat <
1136 (i32 (ext i1:$src0)),
1137 (V_CNDMASK_B32_e64 (i32 0), (i32 1), $src0)
1140 def : Ext32Pat <zext>;
1141 def : Ext32Pat <anyext>;
1143 // The multiplication scales from [0,1] to the unsigned integer range
1145 (AMDGPUurecip i32:$src0),
1147 (V_MUL_F32_e32 (i32 CONST.FP_UINT_MAX_PLUS_1),
1148 (V_RCP_IFLAG_F32_e32 (V_CVT_F32_U32_e32 $src0))))
1151 //===----------------------------------------------------------------------===//
1153 //===----------------------------------------------------------------------===//
1155 let SubtargetPredicate = isGCN in {
1157 def : IMad24Pat<V_MAD_I32_I24, 1>;
1158 def : UMad24Pat<V_MAD_U32_U24, 1>;
1160 // FIXME: This should only be done for VALU inputs
1161 defm : BFIPatterns <V_BFI_B32, S_MOV_B32, SReg_64>;
1162 def : ROTRPattern <V_ALIGNBIT_B32>;
1166 def : GCNPat<(i32 (trunc (srl i64:$src0, (and i32:$src1, (i32 31))))),
1167 (V_ALIGNBIT_B32 (i32 (EXTRACT_SUBREG (i64 $src0), sub1)),
1168 (i32 (EXTRACT_SUBREG (i64 $src0), sub0)), $src1)>;
1170 def : GCNPat<(i32 (trunc (srl i64:$src0, (i32 ShiftAmt32Imm:$src1)))),
1171 (V_ALIGNBIT_B32 (i32 (EXTRACT_SUBREG (i64 $src0), sub1)),
1172 (i32 (EXTRACT_SUBREG (i64 $src0), sub0)), $src1)>;
1174 /********** ====================== **********/
1175 /********** Indirect addressing **********/
1176 /********** ====================== **********/
1178 multiclass SI_INDIRECT_Pattern <ValueType vt, ValueType eltvt, string VecSize> {
1179 // Extract with offset
1181 (eltvt (extractelt vt:$src, (MOVRELOffset i32:$idx, (i32 imm:$offset)))),
1182 (!cast<Instruction>("SI_INDIRECT_SRC_"#VecSize) $src, $idx, imm:$offset)
1185 // Insert with offset
1187 (insertelt vt:$src, eltvt:$val, (MOVRELOffset i32:$idx, (i32 imm:$offset))),
1188 (!cast<Instruction>("SI_INDIRECT_DST_"#VecSize) $src, $idx, imm:$offset, $val)
1192 defm : SI_INDIRECT_Pattern <v2f32, f32, "V2">;
1193 defm : SI_INDIRECT_Pattern <v4f32, f32, "V4">;
1194 defm : SI_INDIRECT_Pattern <v8f32, f32, "V8">;
1195 defm : SI_INDIRECT_Pattern <v16f32, f32, "V16">;
1197 defm : SI_INDIRECT_Pattern <v2i32, i32, "V2">;
1198 defm : SI_INDIRECT_Pattern <v4i32, i32, "V4">;
1199 defm : SI_INDIRECT_Pattern <v8i32, i32, "V8">;
1200 defm : SI_INDIRECT_Pattern <v16i32, i32, "V16">;
1202 //===----------------------------------------------------------------------===//
1204 //===----------------------------------------------------------------------===//
1207 (add (sub_oneuse (umax i32:$src0, i32:$src1),
1208 (umin i32:$src0, i32:$src1)),
1210 (V_SAD_U32 $src0, $src1, $src2, (i1 0))
1214 (add (select_oneuse (i1 (setugt i32:$src0, i32:$src1)),
1215 (sub i32:$src0, i32:$src1),
1216 (sub i32:$src1, i32:$src0)),
1218 (V_SAD_U32 $src0, $src1, $src2, (i1 0))
1221 //===----------------------------------------------------------------------===//
1222 // Conversion Patterns
1223 //===----------------------------------------------------------------------===//
1225 def : GCNPat<(i32 (sext_inreg i32:$src, i1)),
1226 (S_BFE_I32 i32:$src, (i32 65536))>; // 0 | 1 << 16
1228 // Handle sext_inreg in i64
1230 (i64 (sext_inreg i64:$src, i1)),
1231 (S_BFE_I64 i64:$src, (i32 0x10000)) // 0 | 1 << 16
1235 (i16 (sext_inreg i16:$src, i1)),
1236 (S_BFE_I32 $src, (i32 0x00010000)) // 0 | 1 << 16
1240 (i16 (sext_inreg i16:$src, i8)),
1241 (S_BFE_I32 $src, (i32 0x80000)) // 0 | 8 << 16
1245 (i64 (sext_inreg i64:$src, i8)),
1246 (S_BFE_I64 i64:$src, (i32 0x80000)) // 0 | 8 << 16
1250 (i64 (sext_inreg i64:$src, i16)),
1251 (S_BFE_I64 i64:$src, (i32 0x100000)) // 0 | 16 << 16
1255 (i64 (sext_inreg i64:$src, i32)),
1256 (S_BFE_I64 i64:$src, (i32 0x200000)) // 0 | 32 << 16
1260 (i64 (zext i32:$src)),
1261 (REG_SEQUENCE SReg_64, $src, sub0, (S_MOV_B32 (i32 0)), sub1)
1265 (i64 (anyext i32:$src)),
1266 (REG_SEQUENCE SReg_64, $src, sub0, (i32 (IMPLICIT_DEF)), sub1)
1269 class ZExt_i64_i1_Pat <SDNode ext> : GCNPat <
1270 (i64 (ext i1:$src)),
1271 (REG_SEQUENCE VReg_64,
1272 (V_CNDMASK_B32_e64 (i32 0), (i32 1), $src), sub0,
1273 (S_MOV_B32 (i32 0)), sub1)
1277 def : ZExt_i64_i1_Pat<zext>;
1278 def : ZExt_i64_i1_Pat<anyext>;
1280 // FIXME: We need to use COPY_TO_REGCLASS to work-around the fact that
1281 // REG_SEQUENCE patterns don't support instructions with multiple outputs.
1283 (i64 (sext i32:$src)),
1284 (REG_SEQUENCE SReg_64, $src, sub0,
1285 (i32 (COPY_TO_REGCLASS (S_ASHR_I32 $src, (i32 31)), SReg_32_XM0)), sub1)
1289 (i64 (sext i1:$src)),
1290 (REG_SEQUENCE VReg_64,
1291 (V_CNDMASK_B32_e64 (i32 0), (i32 -1), $src), sub0,
1292 (V_CNDMASK_B32_e64 (i32 0), (i32 -1), $src), sub1)
1295 class FPToI1Pat<Instruction Inst, int KOne, ValueType kone_type, ValueType vt, SDPatternOperator fp_to_int> : GCNPat <
1296 (i1 (fp_to_int (vt (VOP3Mods vt:$src0, i32:$src0_modifiers)))),
1297 (i1 (Inst 0, (kone_type KOne), $src0_modifiers, $src0, DSTCLAMP.NONE))
1300 def : FPToI1Pat<V_CMP_EQ_F32_e64, CONST.FP32_ONE, i32, f32, fp_to_uint>;
1301 def : FPToI1Pat<V_CMP_EQ_F32_e64, CONST.FP32_NEG_ONE, i32, f32, fp_to_sint>;
1302 def : FPToI1Pat<V_CMP_EQ_F64_e64, CONST.FP64_ONE, i64, f64, fp_to_uint>;
1303 def : FPToI1Pat<V_CMP_EQ_F64_e64, CONST.FP64_NEG_ONE, i64, f64, fp_to_sint>;
1305 // If we need to perform a logical operation on i1 values, we need to
1306 // use vector comparisons since there is only one SCC register. Vector
1307 // comparisons still write to a pair of SGPRs, so treat these as
1308 // 64-bit comparisons. When legalizing SGPR copies, instructions
1309 // resulting in the copies from SCC to these instructions will be
1310 // moved to the VALU.
1312 (i1 (and i1:$src0, i1:$src1)),
1313 (S_AND_B64 $src0, $src1)
1317 (i1 (or i1:$src0, i1:$src1)),
1318 (S_OR_B64 $src0, $src1)
1322 (i1 (xor i1:$src0, i1:$src1)),
1323 (S_XOR_B64 $src0, $src1)
1327 (f32 (sint_to_fp i1:$src)),
1328 (V_CNDMASK_B32_e64 (i32 0), (i32 CONST.FP32_NEG_ONE), $src)
1332 (f32 (uint_to_fp i1:$src)),
1333 (V_CNDMASK_B32_e64 (i32 0), (i32 CONST.FP32_ONE), $src)
1337 (f64 (sint_to_fp i1:$src)),
1338 (V_CVT_F64_I32_e32 (V_CNDMASK_B32_e64 (i32 0), (i32 -1), $src))
1342 (f64 (uint_to_fp i1:$src)),
1343 (V_CVT_F64_U32_e32 (V_CNDMASK_B32_e64 (i32 0), (i32 1), $src))
1346 //===----------------------------------------------------------------------===//
1347 // Miscellaneous Patterns
1348 //===----------------------------------------------------------------------===//
1350 (i32 (AMDGPUfp16_zext f16:$src)),
1356 (i32 (trunc i64:$a)),
1357 (EXTRACT_SUBREG $a, sub0)
1361 (i1 (trunc i32:$a)),
1362 (V_CMP_EQ_U32_e64 (S_AND_B32 (i32 1), $a), (i32 1))
1366 (i1 (trunc i16:$a)),
1367 (V_CMP_EQ_U32_e64 (S_AND_B32 (i32 1), $a), (i32 1))
1371 (i1 (trunc i64:$a)),
1372 (V_CMP_EQ_U32_e64 (S_AND_B32 (i32 1),
1373 (i32 (EXTRACT_SUBREG $a, sub0))), (i32 1))
1377 (i32 (bswap i32:$a)),
1378 (V_BFI_B32 (S_MOV_B32 (i32 0x00ff00ff)),
1379 (V_ALIGNBIT_B32 $a, $a, (i32 24)),
1380 (V_ALIGNBIT_B32 $a, $a, (i32 8)))
1383 let OtherPredicates = [NoFP16Denormals] in {
1385 (fcanonicalize (f16 (VOP3Mods f16:$src, i32:$src_mods))),
1386 (V_MUL_F16_e64 0, (i32 CONST.FP16_ONE), $src_mods, $src, 0, 0)
1390 (fcanonicalize (f16 (fneg (VOP3Mods f16:$src, i32:$src_mods)))),
1391 (V_MUL_F16_e64 0, (i32 CONST.FP16_NEG_ONE), $src_mods, $src, 0, 0)
1395 (fcanonicalize (v2f16 (VOP3PMods v2f16:$src, i32:$src_mods))),
1396 (V_PK_MUL_F16 0, (i32 CONST.V2FP16_ONE), $src_mods, $src, DSTCLAMP.NONE)
1400 let OtherPredicates = [FP16Denormals] in {
1402 (fcanonicalize (f16 (VOP3Mods f16:$src, i32:$src_mods))),
1403 (V_MAX_F16_e64 $src_mods, $src, $src_mods, $src, 0, 0)
1406 let SubtargetPredicate = HasVOP3PInsts in {
1408 (fcanonicalize (v2f16 (VOP3PMods v2f16:$src, i32:$src_mods))),
1409 (V_PK_MAX_F16 $src_mods, $src, $src_mods, $src, DSTCLAMP.NONE)
1414 let OtherPredicates = [NoFP32Denormals] in {
1416 (fcanonicalize (f32 (VOP3Mods f32:$src, i32:$src_mods))),
1417 (V_MUL_F32_e64 0, (i32 CONST.FP32_ONE), $src_mods, $src, 0, 0)
1421 (fcanonicalize (f32 (fneg (VOP3Mods f32:$src, i32:$src_mods)))),
1422 (V_MUL_F32_e64 0, (i32 CONST.FP32_NEG_ONE), $src_mods, $src, 0, 0)
1426 let OtherPredicates = [FP32Denormals] in {
1428 (fcanonicalize (f32 (VOP3Mods f32:$src, i32:$src_mods))),
1429 (V_MAX_F32_e64 $src_mods, $src, $src_mods, $src, 0, 0)
1433 let OtherPredicates = [NoFP64Denormals] in {
1435 (fcanonicalize (f64 (VOP3Mods f64:$src, i32:$src_mods))),
1436 (V_MUL_F64 0, CONST.FP64_ONE, $src_mods, $src, 0, 0)
1440 let OtherPredicates = [FP64Denormals] in {
1442 (fcanonicalize (f64 (VOP3Mods f64:$src, i32:$src_mods))),
1443 (V_MAX_F64 $src_mods, $src, $src_mods, $src, 0, 0)
1447 let OtherPredicates = [HasDLInsts] in {
1449 (fma (f32 (VOP3Mods0 f32:$src0, i32:$src0_modifiers, i1:$clamp, i32:$omod)),
1450 (f32 (VOP3Mods f32:$src1, i32:$src1_modifiers)),
1451 (f32 (VOP3NoMods f32:$src2))),
1452 (V_FMAC_F32_e64 $src0_modifiers, $src0, $src1_modifiers, $src1,
1453 SRCMODS.NONE, $src2, $clamp, $omod)
1455 } // End OtherPredicates = [HasDLInsts]
1458 // Allow integer inputs
1459 class ExpPattern<SDPatternOperator node, ValueType vt, Instruction Inst> : GCNPat<
1460 (node (i8 timm:$tgt), (i8 timm:$en), vt:$src0, vt:$src1, vt:$src2, vt:$src3, (i1 timm:$compr), (i1 timm:$vm)),
1461 (Inst i8:$tgt, vt:$src0, vt:$src1, vt:$src2, vt:$src3, i1:$vm, i1:$compr, i8:$en)
1464 def : ExpPattern<AMDGPUexport, i32, EXP>;
1465 def : ExpPattern<AMDGPUexport_done, i32, EXP_DONE>;
1467 // COPY_TO_REGCLASS is workaround tablegen bug from multiple outputs
1468 // from S_LSHL_B32's multiple outputs from implicit scc def.
1470 (v2i16 (build_vector (i16 0), i16:$src1)),
1471 (v2i16 (COPY_TO_REGCLASS (S_LSHL_B32 i16:$src1, (i16 16)), SReg_32_XM0))
1475 let SubtargetPredicate = HasVOP3PInsts in {
1477 (v2i16 (build_vector i16:$src0, i16:$src1)),
1478 (v2i16 (S_PACK_LL_B32_B16 $src0, $src1))
1481 // With multiple uses of the shift, this will duplicate the shift and
1482 // increase register pressure.
1484 (v2i16 (build_vector i16:$src0, (i16 (trunc (srl_oneuse i32:$src1, (i32 16)))))),
1485 (v2i16 (S_PACK_LH_B32_B16 i16:$src0, i32:$src1))
1490 (v2i16 (build_vector (i16 (trunc (srl_oneuse i32:$src0, (i32 16)))),
1491 (i16 (trunc (srl_oneuse i32:$src1, (i32 16)))))),
1492 (v2i16 (S_PACK_HH_B32_B16 $src0, $src1))
1495 // TODO: Should source modifiers be matched to v_pack_b32_f16?
1497 (v2f16 (build_vector f16:$src0, f16:$src1)),
1498 (v2f16 (S_PACK_LL_B32_B16 $src0, $src1))
1501 } // End SubtargetPredicate = HasVOP3PInsts
1505 // (v2f16 (scalar_to_vector f16:$src0)),
1510 // (v2i16 (scalar_to_vector i16:$src0)),
1515 (v4i16 (scalar_to_vector i16:$src0)),
1516 (INSERT_SUBREG (IMPLICIT_DEF), $src0, sub0)
1520 (v4f16 (scalar_to_vector f16:$src0)),
1521 (INSERT_SUBREG (IMPLICIT_DEF), $src0, sub0)
1524 //===----------------------------------------------------------------------===//
1526 //===----------------------------------------------------------------------===//
1528 let SubtargetPredicate = isSI in {
1530 // V_FRACT is buggy on SI, so the F32 version is never used and (x-floor(x)) is
1531 // used instead. However, SI doesn't have V_FLOOR_F64, so the most efficient
1532 // way to implement it is using V_FRACT_F64.
1533 // The workaround for the V_FRACT bug is:
1534 // fract(x) = isnan(x) ? x : min(V_FRACT(x), 0.99999999999999999)
1536 // Convert floor(x) to (x - fract(x))
1538 (f64 (ffloor (f64 (VOP3Mods f64:$x, i32:$mods)))),
1543 (V_CNDMASK_B64_PSEUDO
1546 (V_FRACT_F64_e64 $mods, $x, DSTCLAMP.NONE, DSTOMOD.NONE),
1548 (V_MOV_B64_PSEUDO 0x3fefffffffffffff),
1549 DSTCLAMP.NONE, DSTOMOD.NONE),
1551 (V_CMP_CLASS_F64_e64 SRCMODS.NONE, $x, (i32 3 /*NaN*/))),
1552 DSTCLAMP.NONE, DSTOMOD.NONE)
1555 } // End SubtargetPredicates = isSI
1557 //============================================================================//
1558 // Miscellaneous Optimization Patterns
1559 //============================================================================//
1561 // Undo sub x, c -> add x, -c canonicalization since c is more likely
1562 // an inline immediate than -c.
1563 // TODO: Also do for 64-bit.
1565 (add i32:$src0, (i32 NegSubInlineConst32:$src1)),
1566 (S_SUB_I32 $src0, NegSubInlineConst32:$src1)
1570 multiclass BFMPatterns <ValueType vt, InstSI BFM, InstSI MOV> {
1572 (vt (shl (vt (add (vt (shl 1, vt:$a)), -1)), vt:$b)),
1577 (vt (add (vt (shl 1, vt:$a)), -1)),
1578 (BFM $a, (MOV (i32 0)))
1582 let SubtargetPredicate = isGCN in {
1584 defm : BFMPatterns <i32, S_BFM_B32, S_MOV_B32>;
1585 // FIXME: defm : BFMPatterns <i64, S_BFM_B64, S_MOV_B64>;
1587 defm : BFEPattern <V_BFE_U32, V_BFE_I32, S_MOV_B32>;
1588 defm : SHA256MaPattern <V_BFI_B32, V_XOR_B32_e64, SReg_64>;
1590 def : IntMed3Pat<V_MED3_I32, smax, smax_oneuse, smin_oneuse>;
1591 def : IntMed3Pat<V_MED3_U32, umax, umax_oneuse, umin_oneuse>;
1595 // This matches 16 permutations of
1596 // max(min(x, y), min(max(x, y), z))
1597 class FPMed3Pat<ValueType vt,
1598 Instruction med3Inst> : GCNPat<
1599 (fmaxnum (fminnum_oneuse (VOP3Mods_nnan vt:$src0, i32:$src0_mods),
1600 (VOP3Mods_nnan vt:$src1, i32:$src1_mods)),
1601 (fminnum_oneuse (fmaxnum_oneuse (VOP3Mods_nnan vt:$src0, i32:$src0_mods),
1602 (VOP3Mods_nnan vt:$src1, i32:$src1_mods)),
1603 (vt (VOP3Mods_nnan vt:$src2, i32:$src2_mods)))),
1604 (med3Inst $src0_mods, $src0, $src1_mods, $src1, $src2_mods, $src2, DSTCLAMP.NONE, DSTOMOD.NONE)
1607 class FP16Med3Pat<ValueType vt,
1608 Instruction med3Inst> : GCNPat<
1609 (fmaxnum (fminnum_oneuse (VOP3Mods_nnan vt:$src0, i32:$src0_mods),
1610 (VOP3Mods_nnan vt:$src1, i32:$src1_mods)),
1611 (fminnum_oneuse (fmaxnum_oneuse (VOP3Mods_nnan vt:$src0, i32:$src0_mods),
1612 (VOP3Mods_nnan vt:$src1, i32:$src1_mods)),
1613 (vt (VOP3Mods_nnan vt:$src2, i32:$src2_mods)))),
1614 (med3Inst $src0_mods, $src0, $src1_mods, $src1, $src2_mods, $src2, DSTCLAMP.NONE)
1617 class Int16Med3Pat<Instruction med3Inst,
1618 SDPatternOperator max,
1619 SDPatternOperator max_oneuse,
1620 SDPatternOperator min_oneuse,
1621 ValueType vt = i32> : GCNPat<
1622 (max (min_oneuse vt:$src0, vt:$src1),
1623 (min_oneuse (max_oneuse vt:$src0, vt:$src1), vt:$src2)),
1624 (med3Inst SRCMODS.NONE, $src0, SRCMODS.NONE, $src1, SRCMODS.NONE, $src2, DSTCLAMP.NONE)
1627 def : FPMed3Pat<f32, V_MED3_F32>;
1629 let OtherPredicates = [isGFX9] in {
1630 def : FP16Med3Pat<f16, V_MED3_F16>;
1631 def : Int16Med3Pat<V_MED3_I16, smax, smax_oneuse, smin_oneuse, i16>;
1632 def : Int16Med3Pat<V_MED3_U16, umax, umax_oneuse, umin_oneuse, i16>;
1633 } // End Predicates = [isGFX9]