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 "SOPInstructions.td"
19 include "VOPInstructions.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_IF_BREAK : CFPseudoInstSI <
268 (outs SReg_64:$dst), (ins SReg_64:$vcc, SReg_64:$src),
269 [(set i64:$dst, (int_amdgcn_if_break i1:$vcc, i64:$src))]> {
271 let isAsCheapAsAMove = 1;
272 let isReMaterializable = 1;
275 let Uses = [EXEC] in {
277 multiclass PseudoInstKill <dag ins> {
278 // Even though this pseudo can usually be expanded without an SCC def, we
279 // conservatively assume that it has an SCC def, both because it is sometimes
280 // required in degenerate cases (when V_CMPX cannot be used due to constant
281 // bus limitations) and because it allows us to avoid having to track SCC
282 // liveness across basic blocks.
283 let Defs = [EXEC,VCC,SCC] in
284 def _PSEUDO : PseudoInstSI <(outs), ins> {
285 let isConvergent = 1;
286 let usesCustomInserter = 1;
289 let Defs = [EXEC,VCC,SCC] in
290 def _TERMINATOR : SPseudoInstSI <(outs), ins> {
291 let isTerminator = 1;
295 defm SI_KILL_I1 : PseudoInstKill <(ins SSrc_b64:$src, i1imm:$killvalue)>;
296 defm SI_KILL_F32_COND_IMM : PseudoInstKill <(ins VSrc_b32:$src0, i32imm:$src1, i32imm:$cond)>;
298 let Defs = [EXEC,VCC] in
299 def SI_ILLEGAL_COPY : SPseudoInstSI <
300 (outs unknown:$dst), (ins unknown:$src),
301 [], " ; illegal copy $src to $dst">;
303 } // End Uses = [EXEC], Defs = [EXEC,VCC]
305 // Branch on undef scc. Used to avoid intermediate copy from
306 // IMPLICIT_DEF to SCC.
307 def SI_BR_UNDEF : SPseudoInstSI <(outs), (ins sopp_brtarget:$simm16)> {
308 let isTerminator = 1;
309 let usesCustomInserter = 1;
313 def SI_PS_LIVE : PseudoInstSI <
314 (outs SReg_64:$dst), (ins),
315 [(set i1:$dst, (int_amdgcn_ps_live))]> {
319 def SI_MASKED_UNREACHABLE : SPseudoInstSI <(outs), (ins),
320 [(int_amdgcn_unreachable)],
321 "; divergent unreachable"> {
323 let hasNoSchedulingInfo = 1;
327 // Used as an isel pseudo to directly emit initialization with an
328 // s_mov_b32 rather than a copy of another initialized
329 // register. MachineCSE skips copies, and we don't want to have to
330 // fold operands before it runs.
331 def SI_INIT_M0 : SPseudoInstSI <(outs), (ins SSrc_b32:$src)> {
333 let usesCustomInserter = 1;
334 let isAsCheapAsAMove = 1;
335 let isReMaterializable = 1;
338 def SI_INIT_EXEC : SPseudoInstSI <
339 (outs), (ins i64imm:$src), []> {
341 let usesCustomInserter = 1;
342 let isAsCheapAsAMove = 1;
345 def SI_INIT_EXEC_FROM_INPUT : SPseudoInstSI <
346 (outs), (ins SSrc_b32:$input, i32imm:$shift), []> {
348 let usesCustomInserter = 1;
351 // Return for returning shaders to a shader variant epilog.
352 def SI_RETURN_TO_EPILOG : SPseudoInstSI <
353 (outs), (ins variable_ops), [(AMDGPUreturn_to_epilog)]> {
354 let isTerminator = 1;
357 let hasNoSchedulingInfo = 1;
362 // Return for returning function calls.
363 def SI_RETURN : SPseudoInstSI <
366 let isTerminator = 1;
369 let SchedRW = [WriteBranch];
372 // Return for returning function calls without output register.
374 // This version is only needed so we can fill in the output regiter in
375 // the custom inserter.
376 def SI_CALL_ISEL : SPseudoInstSI <
377 (outs), (ins SSrc_b64:$src0), [(AMDGPUcall i64:$src0)]> {
380 let SchedRW = [WriteBranch];
381 let usesCustomInserter = 1;
384 // Wrapper around s_swappc_b64 with extra $callee parameter to track
385 // the called function after regalloc.
386 def SI_CALL : SPseudoInstSI <
387 (outs SReg_64:$dst), (ins SSrc_b64:$src0, unknown:$callee)> {
390 let UseNamedOperandTable = 1;
391 let SchedRW = [WriteBranch];
394 // Tail call handling pseudo
395 def SI_TCRETURN_ISEL : SPseudoInstSI<(outs),
396 (ins SSrc_b64:$src0, i32imm:$fpdiff),
397 [(AMDGPUtc_return i64:$src0, i32:$fpdiff)]> {
399 let isTerminator = 1;
402 let SchedRW = [WriteBranch];
403 let usesCustomInserter = 1;
406 def SI_TCRETURN : SPseudoInstSI <
408 (ins SSrc_b64:$src0, unknown:$callee, i32imm:$fpdiff)> {
411 let isTerminator = 1;
414 let UseNamedOperandTable = 1;
415 let SchedRW = [WriteBranch];
419 def ADJCALLSTACKUP : SPseudoInstSI<
420 (outs), (ins i32imm:$amt0, i32imm:$amt1),
421 [(callseq_start timm:$amt0, timm:$amt1)],
422 "; adjcallstackup $amt0 $amt1"> {
423 let Size = 8; // Worst case. (s_add_u32 + constant)
425 let hasSideEffects = 1;
426 let usesCustomInserter = 1;
429 def ADJCALLSTACKDOWN : SPseudoInstSI<
430 (outs), (ins i32imm:$amt1, i32imm:$amt2),
431 [(callseq_end timm:$amt1, timm:$amt2)],
432 "; adjcallstackdown $amt1"> {
433 let Size = 8; // Worst case. (s_add_u32 + constant)
434 let hasSideEffects = 1;
435 let usesCustomInserter = 1;
438 let Defs = [M0, EXEC, SCC],
439 UseNamedOperandTable = 1 in {
441 class SI_INDIRECT_SRC<RegisterClass rc> : VPseudoInstSI <
442 (outs VGPR_32:$vdst),
443 (ins rc:$src, VS_32:$idx, i32imm:$offset)> {
444 let usesCustomInserter = 1;
447 class SI_INDIRECT_DST<RegisterClass rc> : VPseudoInstSI <
449 (ins rc:$src, VS_32:$idx, i32imm:$offset, VGPR_32:$val)> {
450 let Constraints = "$src = $vdst";
451 let usesCustomInserter = 1;
454 // TODO: We can support indirect SGPR access.
455 def SI_INDIRECT_SRC_V1 : SI_INDIRECT_SRC<VGPR_32>;
456 def SI_INDIRECT_SRC_V2 : SI_INDIRECT_SRC<VReg_64>;
457 def SI_INDIRECT_SRC_V4 : SI_INDIRECT_SRC<VReg_128>;
458 def SI_INDIRECT_SRC_V8 : SI_INDIRECT_SRC<VReg_256>;
459 def SI_INDIRECT_SRC_V16 : SI_INDIRECT_SRC<VReg_512>;
461 def SI_INDIRECT_DST_V1 : SI_INDIRECT_DST<VGPR_32>;
462 def SI_INDIRECT_DST_V2 : SI_INDIRECT_DST<VReg_64>;
463 def SI_INDIRECT_DST_V4 : SI_INDIRECT_DST<VReg_128>;
464 def SI_INDIRECT_DST_V8 : SI_INDIRECT_DST<VReg_256>;
465 def SI_INDIRECT_DST_V16 : SI_INDIRECT_DST<VReg_512>;
467 } // End Uses = [EXEC], Defs = [M0, EXEC]
469 multiclass SI_SPILL_SGPR <RegisterClass sgpr_class> {
470 let UseNamedOperandTable = 1, SGPRSpill = 1, Uses = [EXEC] in {
471 def _SAVE : PseudoInstSI <
473 (ins sgpr_class:$data, i32imm:$addr)> {
478 def _RESTORE : PseudoInstSI <
479 (outs sgpr_class:$data),
480 (ins i32imm:$addr)> {
484 } // End UseNamedOperandTable = 1
487 // You cannot use M0 as the output of v_readlane_b32 instructions or
488 // use it in the sdata operand of SMEM instructions. We still need to
489 // be able to spill the physical register m0, so allow it for
490 // SI_SPILL_32_* instructions.
491 defm SI_SPILL_S32 : SI_SPILL_SGPR <SReg_32>;
492 defm SI_SPILL_S64 : SI_SPILL_SGPR <SReg_64>;
493 defm SI_SPILL_S128 : SI_SPILL_SGPR <SReg_128>;
494 defm SI_SPILL_S256 : SI_SPILL_SGPR <SReg_256>;
495 defm SI_SPILL_S512 : SI_SPILL_SGPR <SReg_512>;
497 multiclass SI_SPILL_VGPR <RegisterClass vgpr_class> {
498 let UseNamedOperandTable = 1, VGPRSpill = 1,
499 SchedRW = [WriteVMEM] in {
500 def _SAVE : VPseudoInstSI <
502 (ins vgpr_class:$vdata, i32imm:$vaddr, SReg_128:$srsrc,
503 SReg_32:$soffset, i32imm:$offset)> {
506 // (2 * 4) + (8 * num_subregs) bytes maximum
507 let Size = !add(!shl(!srl(vgpr_class.Size, 5), 3), 8);
510 def _RESTORE : VPseudoInstSI <
511 (outs vgpr_class:$vdata),
512 (ins i32imm:$vaddr, SReg_128:$srsrc, SReg_32:$soffset,
517 // (2 * 4) + (8 * num_subregs) bytes maximum
518 let Size = !add(!shl(!srl(vgpr_class.Size, 5), 3), 8);
520 } // End UseNamedOperandTable = 1, VGPRSpill = 1, SchedRW = [WriteVMEM]
523 defm SI_SPILL_V32 : SI_SPILL_VGPR <VGPR_32>;
524 defm SI_SPILL_V64 : SI_SPILL_VGPR <VReg_64>;
525 defm SI_SPILL_V96 : SI_SPILL_VGPR <VReg_96>;
526 defm SI_SPILL_V128 : SI_SPILL_VGPR <VReg_128>;
527 defm SI_SPILL_V256 : SI_SPILL_VGPR <VReg_256>;
528 defm SI_SPILL_V512 : SI_SPILL_VGPR <VReg_512>;
530 def SI_PC_ADD_REL_OFFSET : SPseudoInstSI <
532 (ins si_ga:$ptr_lo, si_ga:$ptr_hi),
534 (i64 (SIpc_add_rel_offset (tglobaladdr:$ptr_lo), (tglobaladdr:$ptr_hi))))]> {
539 (AMDGPUinit_exec i64:$src),
540 (SI_INIT_EXEC (as_i64imm $src))
544 (AMDGPUinit_exec_from_input i32:$input, i32:$shift),
545 (SI_INIT_EXEC_FROM_INPUT (i32 $input), (as_i32imm $shift))
549 (AMDGPUtrap timm:$trapid),
554 (AMDGPUelse i64:$src, bb:$target),
555 (SI_ELSE $src, $target, 0)
559 // -1.0 as i32 (LowerINTRINSIC_VOID converts all other constants to -1.0)
560 (AMDGPUkill (i32 -1082130432)),
561 (SI_KILL_I1_PSEUDO (i1 0), 0)
565 (int_amdgcn_kill i1:$src),
566 (SI_KILL_I1_PSEUDO $src, 0)
570 (int_amdgcn_kill (i1 (not i1:$src))),
571 (SI_KILL_I1_PSEUDO $src, -1)
575 (AMDGPUkill i32:$src),
576 (SI_KILL_F32_COND_IMM_PSEUDO $src, 0, 3) // 3 means SETOGE
580 (int_amdgcn_kill (i1 (setcc f32:$src, InlineFPImm<f32>:$imm, cond:$cond))),
581 (SI_KILL_F32_COND_IMM_PSEUDO $src, (bitcast_fpimm_to_i32 $imm), (cond_as_i32imm $cond))
584 // TODO: we could add more variants for other types of conditionals
587 (int_amdgcn_icmp i1:$src, (i1 0), (i32 33)),
588 (COPY $src) // Return the SGPRs representing i1 src
591 //===----------------------------------------------------------------------===//
593 //===----------------------------------------------------------------------===//
595 let SubtargetPredicate = isGCN, OtherPredicates = [UnsafeFPMath] in {
597 //def : RcpPat<V_RCP_F64_e32, f64>;
598 //defm : RsqPat<V_RSQ_F64_e32, f64>;
599 //defm : RsqPat<V_RSQ_F32_e32, f32>;
601 def : RsqPat<V_RSQ_F32_e32, f32>;
602 def : RsqPat<V_RSQ_F64_e32, f64>;
604 // Convert (x - floor(x)) to fract(x)
606 (f32 (fsub (f32 (VOP3Mods f32:$x, i32:$mods)),
607 (f32 (ffloor (f32 (VOP3Mods f32:$x, i32:$mods)))))),
608 (V_FRACT_F32_e64 $mods, $x, DSTCLAMP.NONE, DSTOMOD.NONE)
611 // Convert (x + (-floor(x))) to fract(x)
613 (f64 (fadd (f64 (VOP3Mods f64:$x, i32:$mods)),
614 (f64 (fneg (f64 (ffloor (f64 (VOP3Mods f64:$x, i32:$mods)))))))),
615 (V_FRACT_F64_e64 $mods, $x, DSTCLAMP.NONE, DSTOMOD.NONE)
618 } // End SubtargetPredicate = isGCN, OtherPredicates = [UnsafeFPMath]
621 // f16_to_fp patterns
623 (f32 (f16_to_fp i32:$src0)),
624 (V_CVT_F32_F16_e64 SRCMODS.NONE, $src0, DSTCLAMP.NONE, DSTOMOD.NONE)
628 (f32 (f16_to_fp (and_oneuse i32:$src0, 0x7fff))),
629 (V_CVT_F32_F16_e64 SRCMODS.ABS, $src0, DSTCLAMP.NONE, DSTOMOD.NONE)
633 (f32 (f16_to_fp (i32 (srl_oneuse (and_oneuse i32:$src0, 0x7fff0000), (i32 16))))),
634 (V_CVT_F32_F16_e64 SRCMODS.ABS, (i32 (V_LSHRREV_B32_e64 (i32 16), i32:$src0)), DSTCLAMP.NONE, DSTOMOD.NONE)
638 (f32 (f16_to_fp (or_oneuse i32:$src0, 0x8000))),
639 (V_CVT_F32_F16_e64 SRCMODS.NEG_ABS, $src0, DSTCLAMP.NONE, DSTOMOD.NONE)
643 (f32 (f16_to_fp (xor_oneuse i32:$src0, 0x8000))),
644 (V_CVT_F32_F16_e64 SRCMODS.NEG, $src0, DSTCLAMP.NONE, DSTOMOD.NONE)
648 (f64 (fpextend f16:$src)),
649 (V_CVT_F64_F32_e32 (V_CVT_F32_F16_e32 $src))
652 // fp_to_fp16 patterns
654 (i32 (AMDGPUfp_to_f16 (f32 (VOP3Mods f32:$src0, i32:$src0_modifiers)))),
655 (V_CVT_F16_F32_e64 $src0_modifiers, f32:$src0, DSTCLAMP.NONE, DSTOMOD.NONE)
659 (i32 (fp_to_sint f16:$src)),
660 (V_CVT_I32_F32_e32 (V_CVT_F32_F16_e32 $src))
664 (i32 (fp_to_uint f16:$src)),
665 (V_CVT_U32_F32_e32 (V_CVT_F32_F16_e32 $src))
669 (f16 (sint_to_fp i32:$src)),
670 (V_CVT_F16_F32_e32 (V_CVT_F32_I32_e32 $src))
674 (f16 (uint_to_fp i32:$src)),
675 (V_CVT_F16_F32_e32 (V_CVT_F32_U32_e32 $src))
678 //===----------------------------------------------------------------------===//
680 //===----------------------------------------------------------------------===//
682 multiclass FMADPat <ValueType vt, Instruction inst> {
684 (vt (fmad (VOP3NoMods vt:$src0),
685 (VOP3NoMods vt:$src1),
686 (VOP3NoMods vt:$src2))),
687 (inst SRCMODS.NONE, $src0, SRCMODS.NONE, $src1,
688 SRCMODS.NONE, $src2, DSTCLAMP.NONE, DSTOMOD.NONE)
692 defm : FMADPat <f16, V_MAC_F16_e64>;
693 defm : FMADPat <f32, V_MAC_F32_e64>;
695 class FMADModsPat<Instruction inst, SDPatternOperator mad_opr, ValueType Ty>
697 (Ty (mad_opr (VOP3Mods Ty:$src0, i32:$src0_mod),
698 (VOP3Mods Ty:$src1, i32:$src1_mod),
699 (VOP3Mods Ty:$src2, i32:$src2_mod))),
700 (inst $src0_mod, $src0, $src1_mod, $src1,
701 $src2_mod, $src2, DSTCLAMP.NONE, DSTOMOD.NONE)
704 def : FMADModsPat<V_MAD_F32, AMDGPUfmad_ftz, f32>;
705 def : FMADModsPat<V_MAD_F16, AMDGPUfmad_ftz, f16> {
706 let SubtargetPredicate = Has16BitInsts;
709 multiclass SelectPat <ValueType vt, Instruction inst> {
711 (vt (select i1:$src0, vt:$src1, vt:$src2)),
712 (inst $src2, $src1, $src0)
716 defm : SelectPat <i16, V_CNDMASK_B32_e64>;
717 defm : SelectPat <i32, V_CNDMASK_B32_e64>;
718 defm : SelectPat <f16, V_CNDMASK_B32_e64>;
719 defm : SelectPat <f32, V_CNDMASK_B32_e64>;
721 let AddedComplexity = 1 in {
723 (i32 (add (i32 (getDivergentFrag<ctpop>.ret i32:$popcnt)), i32:$val)),
724 (V_BCNT_U32_B32_e64 $popcnt, $val)
728 (i16 (add (i16 (trunc (getDivergentFrag<ctpop>.ret i32:$popcnt))), i16:$val)),
729 (V_BCNT_U32_B32_e64 $popcnt, $val)
732 /********** ============================================ **********/
733 /********** Extraction, Insertion, Building and Casting **********/
734 /********** ============================================ **********/
736 foreach Index = 0-2 in {
737 def Extract_Element_v2i32_#Index : Extract_Element <
738 i32, v2i32, Index, !cast<SubRegIndex>(sub#Index)
740 def Insert_Element_v2i32_#Index : Insert_Element <
741 i32, v2i32, Index, !cast<SubRegIndex>(sub#Index)
744 def Extract_Element_v2f32_#Index : Extract_Element <
745 f32, v2f32, Index, !cast<SubRegIndex>(sub#Index)
747 def Insert_Element_v2f32_#Index : Insert_Element <
748 f32, v2f32, Index, !cast<SubRegIndex>(sub#Index)
752 foreach Index = 0-3 in {
753 def Extract_Element_v4i32_#Index : Extract_Element <
754 i32, v4i32, Index, !cast<SubRegIndex>(sub#Index)
756 def Insert_Element_v4i32_#Index : Insert_Element <
757 i32, v4i32, Index, !cast<SubRegIndex>(sub#Index)
760 def Extract_Element_v4f32_#Index : Extract_Element <
761 f32, v4f32, Index, !cast<SubRegIndex>(sub#Index)
763 def Insert_Element_v4f32_#Index : Insert_Element <
764 f32, v4f32, Index, !cast<SubRegIndex>(sub#Index)
768 foreach Index = 0-7 in {
769 def Extract_Element_v8i32_#Index : Extract_Element <
770 i32, v8i32, Index, !cast<SubRegIndex>(sub#Index)
772 def Insert_Element_v8i32_#Index : Insert_Element <
773 i32, v8i32, Index, !cast<SubRegIndex>(sub#Index)
776 def Extract_Element_v8f32_#Index : Extract_Element <
777 f32, v8f32, Index, !cast<SubRegIndex>(sub#Index)
779 def Insert_Element_v8f32_#Index : Insert_Element <
780 f32, v8f32, Index, !cast<SubRegIndex>(sub#Index)
784 foreach Index = 0-15 in {
785 def Extract_Element_v16i32_#Index : Extract_Element <
786 i32, v16i32, Index, !cast<SubRegIndex>(sub#Index)
788 def Insert_Element_v16i32_#Index : Insert_Element <
789 i32, v16i32, Index, !cast<SubRegIndex>(sub#Index)
792 def Extract_Element_v16f32_#Index : Extract_Element <
793 f32, v16f32, Index, !cast<SubRegIndex>(sub#Index)
795 def Insert_Element_v16f32_#Index : Insert_Element <
796 f32, v16f32, Index, !cast<SubRegIndex>(sub#Index)
802 (extract_subvector v4i16:$vec, (i32 0)),
803 (v2i16 (EXTRACT_SUBREG v4i16:$vec, sub0))
807 (extract_subvector v4i16:$vec, (i32 2)),
808 (v2i16 (EXTRACT_SUBREG v4i16:$vec, sub1))
812 (extract_subvector v4f16:$vec, (i32 0)),
813 (v2f16 (EXTRACT_SUBREG v4f16:$vec, sub0))
817 (extract_subvector v4f16:$vec, (i32 2)),
818 (v2f16 (EXTRACT_SUBREG v4f16:$vec, sub1))
821 let SubtargetPredicate = isGCN in {
823 // FIXME: Why do only some of these type combinations for SReg and
826 def : BitConvert <i16, f16, VGPR_32>;
827 def : BitConvert <f16, i16, VGPR_32>;
828 def : BitConvert <i16, f16, SReg_32>;
829 def : BitConvert <f16, i16, SReg_32>;
832 def : BitConvert <i32, f32, VGPR_32>;
833 def : BitConvert <f32, i32, VGPR_32>;
834 def : BitConvert <i32, f32, SReg_32>;
835 def : BitConvert <f32, i32, SReg_32>;
836 def : BitConvert <v2i16, i32, SReg_32>;
837 def : BitConvert <i32, v2i16, SReg_32>;
838 def : BitConvert <v2f16, i32, SReg_32>;
839 def : BitConvert <i32, v2f16, SReg_32>;
840 def : BitConvert <v2i16, v2f16, SReg_32>;
841 def : BitConvert <v2f16, v2i16, SReg_32>;
842 def : BitConvert <v2f16, f32, SReg_32>;
843 def : BitConvert <f32, v2f16, SReg_32>;
844 def : BitConvert <v2i16, f32, SReg_32>;
845 def : BitConvert <f32, v2i16, SReg_32>;
848 def : BitConvert <i64, f64, VReg_64>;
849 def : BitConvert <f64, i64, VReg_64>;
850 def : BitConvert <v2i32, v2f32, VReg_64>;
851 def : BitConvert <v2f32, v2i32, VReg_64>;
852 def : BitConvert <i64, v2i32, VReg_64>;
853 def : BitConvert <v2i32, i64, VReg_64>;
854 def : BitConvert <i64, v2f32, VReg_64>;
855 def : BitConvert <v2f32, i64, VReg_64>;
856 def : BitConvert <f64, v2f32, VReg_64>;
857 def : BitConvert <v2f32, f64, VReg_64>;
858 def : BitConvert <f64, v2i32, VReg_64>;
859 def : BitConvert <v2i32, f64, VReg_64>;
860 def : BitConvert <v4i16, v4f16, VReg_64>;
861 def : BitConvert <v4f16, v4i16, VReg_64>;
864 def : BitConvert <v2i32, v4f16, VReg_64>;
865 def : BitConvert <v4f16, v2i32, VReg_64>;
866 def : BitConvert <v2i32, v4f16, VReg_64>;
867 def : BitConvert <v2i32, v4i16, VReg_64>;
868 def : BitConvert <v4i16, v2i32, VReg_64>;
869 def : BitConvert <v2f32, v4f16, VReg_64>;
870 def : BitConvert <v4f16, v2f32, VReg_64>;
871 def : BitConvert <v2f32, v4i16, VReg_64>;
872 def : BitConvert <v4i16, v2f32, VReg_64>;
873 def : BitConvert <v4i16, f64, VReg_64>;
874 def : BitConvert <v4f16, f64, VReg_64>;
875 def : BitConvert <f64, v4i16, VReg_64>;
876 def : BitConvert <f64, v4f16, VReg_64>;
877 def : BitConvert <v4i16, i64, VReg_64>;
878 def : BitConvert <v4f16, i64, VReg_64>;
879 def : BitConvert <i64, v4i16, VReg_64>;
880 def : BitConvert <i64, v4f16, VReg_64>;
882 def : BitConvert <v4i32, v4f32, VReg_128>;
883 def : BitConvert <v4f32, v4i32, VReg_128>;
886 def : BitConvert <v2i64, v4i32, SReg_128>;
887 def : BitConvert <v4i32, v2i64, SReg_128>;
888 def : BitConvert <v2f64, v4f32, VReg_128>;
889 def : BitConvert <v2f64, v4i32, VReg_128>;
890 def : BitConvert <v4f32, v2f64, VReg_128>;
891 def : BitConvert <v4i32, v2f64, VReg_128>;
892 def : BitConvert <v2i64, v2f64, VReg_128>;
893 def : BitConvert <v2f64, v2i64, VReg_128>;
896 def : BitConvert <v8i32, v8f32, SReg_256>;
897 def : BitConvert <v8f32, v8i32, SReg_256>;
898 def : BitConvert <v8i32, v8f32, VReg_256>;
899 def : BitConvert <v8f32, v8i32, VReg_256>;
902 def : BitConvert <v16i32, v16f32, VReg_512>;
903 def : BitConvert <v16f32, v16i32, VReg_512>;
905 } // End SubtargetPredicate = isGCN
907 /********** =================== **********/
908 /********** Src & Dst modifiers **********/
909 /********** =================== **********/
912 // If denormals are not enabled, it only impacts the compare of the
913 // inputs. The output result is not flushed.
914 class ClampPat<Instruction inst, ValueType vt> : GCNPat <
915 (vt (AMDGPUclamp (VOP3Mods vt:$src0, i32:$src0_modifiers))),
916 (inst i32:$src0_modifiers, vt:$src0,
917 i32:$src0_modifiers, vt:$src0, DSTCLAMP.ENABLE, DSTOMOD.NONE)
920 def : ClampPat<V_MAX_F32_e64, f32>;
921 def : ClampPat<V_MAX_F64, f64>;
922 def : ClampPat<V_MAX_F16_e64, f16>;
924 let SubtargetPredicate = HasVOP3PInsts in {
926 (v2f16 (AMDGPUclamp (VOP3PMods v2f16:$src0, i32:$src0_modifiers))),
927 (V_PK_MAX_F16 $src0_modifiers, $src0,
928 $src0_modifiers, $src0, DSTCLAMP.ENABLE)
932 /********** ================================ **********/
933 /********** Floating point absolute/negative **********/
934 /********** ================================ **********/
936 // Prevent expanding both fneg and fabs.
939 (fneg (fabs f32:$src)),
940 (S_OR_B32 $src, (S_MOV_B32(i32 0x80000000))) // Set sign bit
943 // FIXME: Should use S_OR_B32
945 (fneg (fabs f64:$src)),
946 (REG_SEQUENCE VReg_64,
947 (i32 (EXTRACT_SUBREG f64:$src, sub0)),
949 (V_OR_B32_e32 (i32 (EXTRACT_SUBREG f64:$src, sub1)),
950 (V_MOV_B32_e32 (i32 0x80000000))), // Set sign bit.
956 (S_AND_B32 $src, (S_MOV_B32 (i32 0x7fffffff)))
961 (V_XOR_B32_e32 $src, (V_MOV_B32_e32 (i32 0x80000000)))
966 (REG_SEQUENCE VReg_64,
967 (i32 (EXTRACT_SUBREG f64:$src, sub0)),
969 (V_AND_B32_e64 (i32 (EXTRACT_SUBREG f64:$src, sub1)),
970 (V_MOV_B32_e32 (i32 0x7fffffff))), // Set sign bit.
976 (REG_SEQUENCE VReg_64,
977 (i32 (EXTRACT_SUBREG f64:$src, sub0)),
979 (V_XOR_B32_e32 (i32 (EXTRACT_SUBREG f64:$src, sub1)),
980 (i32 (V_MOV_B32_e32 (i32 0x80000000)))),
985 (fcopysign f16:$src0, f16:$src1),
986 (V_BFI_B32 (S_MOV_B32 (i32 0x00007fff)), $src0, $src1)
990 (fcopysign f32:$src0, f16:$src1),
991 (V_BFI_B32 (S_MOV_B32 (i32 0x7fffffff)), $src0,
992 (V_LSHLREV_B32_e64 (i32 16), $src1))
996 (fcopysign f64:$src0, f16:$src1),
997 (REG_SEQUENCE SReg_64,
998 (i32 (EXTRACT_SUBREG $src0, sub0)), sub0,
999 (V_BFI_B32 (S_MOV_B32 (i32 0x7fffffff)), (i32 (EXTRACT_SUBREG $src0, sub1)),
1000 (V_LSHLREV_B32_e64 (i32 16), $src1)), sub1)
1004 (fcopysign f16:$src0, f32:$src1),
1005 (V_BFI_B32 (S_MOV_B32 (i32 0x00007fff)), $src0,
1006 (V_LSHRREV_B32_e64 (i32 16), $src1))
1010 (fcopysign f16:$src0, f64:$src1),
1011 (V_BFI_B32 (S_MOV_B32 (i32 0x00007fff)), $src0,
1012 (V_LSHRREV_B32_e64 (i32 16), (EXTRACT_SUBREG $src1, sub1)))
1017 (S_XOR_B32 $src, (S_MOV_B32 (i32 0x00008000)))
1022 (S_AND_B32 $src, (S_MOV_B32 (i32 0x00007fff)))
1026 (fneg (fabs f16:$src)),
1027 (S_OR_B32 $src, (S_MOV_B32 (i32 0x00008000))) // Set sign bit
1032 (S_XOR_B32 $src, (S_MOV_B32 (i32 0x80008000)))
1037 (S_AND_B32 $src, (S_MOV_B32 (i32 0x7fff7fff)))
1040 // This is really (fneg (fabs v2f16:$src))
1042 // fabs is not reported as free because there is modifier for it in
1043 // VOP3P instructions, so it is turned into the bit op.
1045 (fneg (v2f16 (bitconvert (and_oneuse i32:$src, 0x7fff7fff)))),
1046 (S_OR_B32 $src, (S_MOV_B32 (i32 0x80008000))) // Set sign bit
1050 (fneg (v2f16 (fabs v2f16:$src))),
1051 (S_OR_B32 $src, (S_MOV_B32 (i32 0x80008000))) // Set sign bit
1054 /********** ================== **********/
1055 /********** Immediate Patterns **********/
1056 /********** ================== **********/
1059 (VGPRImm<(i32 imm)>:$imm),
1060 (V_MOV_B32_e32 imm:$imm)
1064 (VGPRImm<(f32 fpimm)>:$imm),
1065 (V_MOV_B32_e32 (f32 (bitcast_fpimm_to_i32 $imm)))
1070 (S_MOV_B32 imm:$imm)
1073 // FIXME: Workaround for ordering issue with peephole optimizer where
1074 // a register class copy interferes with immediate folding. Should
1075 // use s_mov_b32, which can be shrunk to s_movk_i32
1077 (VGPRImm<(f16 fpimm)>:$imm),
1078 (V_MOV_B32_e32 (f16 (bitcast_fpimm_to_i32 $imm)))
1083 (S_MOV_B32 (f32 (bitcast_fpimm_to_i32 $imm)))
1088 (S_MOV_B32 (i32 (bitcast_fpimm_to_i32 $imm)))
1092 (i32 frameindex:$fi),
1093 (V_MOV_B32_e32 (i32 (frameindex_to_targetframeindex $fi)))
1097 (i64 InlineImm<i64>:$imm),
1098 (S_MOV_B64 InlineImm<i64>:$imm)
1101 // XXX - Should this use a s_cmp to set SCC?
1103 // Set to sign-extended 64-bit value (true = -1, false = 0)
1106 (S_MOV_B64 (i64 (as_i64imm $imm)))
1110 (f64 InlineFPImm<f64>:$imm),
1111 (S_MOV_B64 (f64 (bitcast_fpimm_to_i64 InlineFPImm<f64>:$imm)))
1114 /********** ================== **********/
1115 /********** Intrinsic Patterns **********/
1116 /********** ================== **********/
1118 let SubtargetPredicate = isGCN in {
1119 def : POW_Common <V_LOG_F32_e32, V_EXP_F32_e32, V_MUL_LEGACY_F32_e32>;
1123 (i32 (sext i1:$src0)),
1124 (V_CNDMASK_B32_e64 (i32 0), (i32 -1), $src0)
1127 class Ext32Pat <SDNode ext> : GCNPat <
1128 (i32 (ext i1:$src0)),
1129 (V_CNDMASK_B32_e64 (i32 0), (i32 1), $src0)
1132 def : Ext32Pat <zext>;
1133 def : Ext32Pat <anyext>;
1135 // The multiplication scales from [0,1] to the unsigned integer range
1137 (AMDGPUurecip i32:$src0),
1139 (V_MUL_F32_e32 (i32 CONST.FP_UINT_MAX_PLUS_1),
1140 (V_RCP_IFLAG_F32_e32 (V_CVT_F32_U32_e32 $src0))))
1143 //===----------------------------------------------------------------------===//
1145 //===----------------------------------------------------------------------===//
1147 let SubtargetPredicate = isGCN in {
1149 def : IMad24Pat<V_MAD_I32_I24, 1>;
1150 def : UMad24Pat<V_MAD_U32_U24, 1>;
1152 // FIXME: This should only be done for VALU inputs
1153 defm : BFIPatterns <V_BFI_B32, S_MOV_B32, SReg_64>;
1154 def : ROTRPattern <V_ALIGNBIT_B32>;
1158 def : GCNPat<(i32 (trunc (srl i64:$src0, (and i32:$src1, (i32 31))))),
1159 (V_ALIGNBIT_B32 (i32 (EXTRACT_SUBREG (i64 $src0), sub1)),
1160 (i32 (EXTRACT_SUBREG (i64 $src0), sub0)), $src1)>;
1162 def : GCNPat<(i32 (trunc (srl i64:$src0, (i32 ShiftAmt32Imm:$src1)))),
1163 (V_ALIGNBIT_B32 (i32 (EXTRACT_SUBREG (i64 $src0), sub1)),
1164 (i32 (EXTRACT_SUBREG (i64 $src0), sub0)), $src1)>;
1166 /********** ====================== **********/
1167 /********** Indirect addressing **********/
1168 /********** ====================== **********/
1170 multiclass SI_INDIRECT_Pattern <ValueType vt, ValueType eltvt, string VecSize> {
1171 // Extract with offset
1173 (eltvt (extractelt vt:$src, (MOVRELOffset i32:$idx, (i32 imm:$offset)))),
1174 (!cast<Instruction>("SI_INDIRECT_SRC_"#VecSize) $src, $idx, imm:$offset)
1177 // Insert with offset
1179 (insertelt vt:$src, eltvt:$val, (MOVRELOffset i32:$idx, (i32 imm:$offset))),
1180 (!cast<Instruction>("SI_INDIRECT_DST_"#VecSize) $src, $idx, imm:$offset, $val)
1184 defm : SI_INDIRECT_Pattern <v2f32, f32, "V2">;
1185 defm : SI_INDIRECT_Pattern <v4f32, f32, "V4">;
1186 defm : SI_INDIRECT_Pattern <v8f32, f32, "V8">;
1187 defm : SI_INDIRECT_Pattern <v16f32, f32, "V16">;
1189 defm : SI_INDIRECT_Pattern <v2i32, i32, "V2">;
1190 defm : SI_INDIRECT_Pattern <v4i32, i32, "V4">;
1191 defm : SI_INDIRECT_Pattern <v8i32, i32, "V8">;
1192 defm : SI_INDIRECT_Pattern <v16i32, i32, "V16">;
1194 //===----------------------------------------------------------------------===//
1196 //===----------------------------------------------------------------------===//
1199 (add (sub_oneuse (umax i32:$src0, i32:$src1),
1200 (umin i32:$src0, i32:$src1)),
1202 (V_SAD_U32 $src0, $src1, $src2, (i1 0))
1206 (add (select_oneuse (i1 (setugt i32:$src0, i32:$src1)),
1207 (sub i32:$src0, i32:$src1),
1208 (sub i32:$src1, i32:$src0)),
1210 (V_SAD_U32 $src0, $src1, $src2, (i1 0))
1213 //===----------------------------------------------------------------------===//
1214 // Conversion Patterns
1215 //===----------------------------------------------------------------------===//
1217 def : GCNPat<(i32 (sext_inreg i32:$src, i1)),
1218 (S_BFE_I32 i32:$src, (i32 65536))>; // 0 | 1 << 16
1220 // Handle sext_inreg in i64
1222 (i64 (sext_inreg i64:$src, i1)),
1223 (S_BFE_I64 i64:$src, (i32 0x10000)) // 0 | 1 << 16
1227 (i16 (sext_inreg i16:$src, i1)),
1228 (S_BFE_I32 $src, (i32 0x00010000)) // 0 | 1 << 16
1232 (i16 (sext_inreg i16:$src, i8)),
1233 (S_BFE_I32 $src, (i32 0x80000)) // 0 | 8 << 16
1237 (i64 (sext_inreg i64:$src, i8)),
1238 (S_BFE_I64 i64:$src, (i32 0x80000)) // 0 | 8 << 16
1242 (i64 (sext_inreg i64:$src, i16)),
1243 (S_BFE_I64 i64:$src, (i32 0x100000)) // 0 | 16 << 16
1247 (i64 (sext_inreg i64:$src, i32)),
1248 (S_BFE_I64 i64:$src, (i32 0x200000)) // 0 | 32 << 16
1252 (i64 (zext i32:$src)),
1253 (REG_SEQUENCE SReg_64, $src, sub0, (S_MOV_B32 (i32 0)), sub1)
1257 (i64 (anyext i32:$src)),
1258 (REG_SEQUENCE SReg_64, $src, sub0, (i32 (IMPLICIT_DEF)), sub1)
1261 class ZExt_i64_i1_Pat <SDNode ext> : GCNPat <
1262 (i64 (ext i1:$src)),
1263 (REG_SEQUENCE VReg_64,
1264 (V_CNDMASK_B32_e64 (i32 0), (i32 1), $src), sub0,
1265 (S_MOV_B32 (i32 0)), sub1)
1269 def : ZExt_i64_i1_Pat<zext>;
1270 def : ZExt_i64_i1_Pat<anyext>;
1272 // FIXME: We need to use COPY_TO_REGCLASS to work-around the fact that
1273 // REG_SEQUENCE patterns don't support instructions with multiple outputs.
1275 (i64 (sext i32:$src)),
1276 (REG_SEQUENCE SReg_64, $src, sub0,
1277 (i32 (COPY_TO_REGCLASS (S_ASHR_I32 $src, (i32 31)), SReg_32_XM0)), sub1)
1281 (i64 (sext i1:$src)),
1282 (REG_SEQUENCE VReg_64,
1283 (V_CNDMASK_B32_e64 (i32 0), (i32 -1), $src), sub0,
1284 (V_CNDMASK_B32_e64 (i32 0), (i32 -1), $src), sub1)
1287 class FPToI1Pat<Instruction Inst, int KOne, ValueType kone_type, ValueType vt, SDPatternOperator fp_to_int> : GCNPat <
1288 (i1 (fp_to_int (vt (VOP3Mods vt:$src0, i32:$src0_modifiers)))),
1289 (i1 (Inst 0, (kone_type KOne), $src0_modifiers, $src0, DSTCLAMP.NONE))
1292 def : FPToI1Pat<V_CMP_EQ_F32_e64, CONST.FP32_ONE, i32, f32, fp_to_uint>;
1293 def : FPToI1Pat<V_CMP_EQ_F32_e64, CONST.FP32_NEG_ONE, i32, f32, fp_to_sint>;
1294 def : FPToI1Pat<V_CMP_EQ_F64_e64, CONST.FP64_ONE, i64, f64, fp_to_uint>;
1295 def : FPToI1Pat<V_CMP_EQ_F64_e64, CONST.FP64_NEG_ONE, i64, f64, fp_to_sint>;
1297 // If we need to perform a logical operation on i1 values, we need to
1298 // use vector comparisons since there is only one SCC register. Vector
1299 // comparisons still write to a pair of SGPRs, so treat these as
1300 // 64-bit comparisons. When legalizing SGPR copies, instructions
1301 // resulting in the copies from SCC to these instructions will be
1302 // moved to the VALU.
1304 (i1 (and i1:$src0, i1:$src1)),
1305 (S_AND_B64 $src0, $src1)
1309 (i1 (or i1:$src0, i1:$src1)),
1310 (S_OR_B64 $src0, $src1)
1314 (i1 (xor i1:$src0, i1:$src1)),
1315 (S_XOR_B64 $src0, $src1)
1319 (i1 (add i1:$src0, i1:$src1)),
1320 (S_XOR_B64 $src0, $src1)
1324 (i1 (sub i1:$src0, i1:$src1)),
1325 (S_XOR_B64 $src0, $src1)
1328 let AddedComplexity = 1 in {
1330 (i1 (add i1:$src0, (i1 -1))),
1335 (i1 (sub i1:$src0, (i1 -1))),
1341 (f16 (sint_to_fp i1:$src)),
1342 (V_CVT_F16_F32_e32 (V_CNDMASK_B32_e64 (i32 0), (i32 CONST.FP32_NEG_ONE), $src))
1346 (f16 (uint_to_fp i1:$src)),
1347 (V_CVT_F16_F32_e32 (V_CNDMASK_B32_e64 (i32 0), (i32 CONST.FP32_ONE), $src))
1351 (f32 (sint_to_fp i1:$src)),
1352 (V_CNDMASK_B32_e64 (i32 0), (i32 CONST.FP32_NEG_ONE), $src)
1356 (f32 (uint_to_fp i1:$src)),
1357 (V_CNDMASK_B32_e64 (i32 0), (i32 CONST.FP32_ONE), $src)
1361 (f64 (sint_to_fp i1:$src)),
1362 (V_CVT_F64_I32_e32 (V_CNDMASK_B32_e64 (i32 0), (i32 -1), $src))
1366 (f64 (uint_to_fp i1:$src)),
1367 (V_CVT_F64_U32_e32 (V_CNDMASK_B32_e64 (i32 0), (i32 1), $src))
1370 //===----------------------------------------------------------------------===//
1371 // Miscellaneous Patterns
1372 //===----------------------------------------------------------------------===//
1374 (i32 (AMDGPUfp16_zext f16:$src)),
1380 (i32 (trunc i64:$a)),
1381 (EXTRACT_SUBREG $a, sub0)
1385 (i1 (trunc i32:$a)),
1386 (V_CMP_EQ_U32_e64 (S_AND_B32 (i32 1), $a), (i32 1))
1390 (i1 (trunc i16:$a)),
1391 (V_CMP_EQ_U32_e64 (S_AND_B32 (i32 1), $a), (i32 1))
1395 (i1 (trunc i64:$a)),
1396 (V_CMP_EQ_U32_e64 (S_AND_B32 (i32 1),
1397 (i32 (EXTRACT_SUBREG $a, sub0))), (i32 1))
1401 (i32 (bswap i32:$a)),
1402 (V_BFI_B32 (S_MOV_B32 (i32 0x00ff00ff)),
1403 (V_ALIGNBIT_B32 $a, $a, (i32 24)),
1404 (V_ALIGNBIT_B32 $a, $a, (i32 8)))
1407 let OtherPredicates = [NoFP16Denormals] in {
1409 (fcanonicalize (f16 (VOP3Mods f16:$src, i32:$src_mods))),
1410 (V_MUL_F16_e64 0, (i32 CONST.FP16_ONE), $src_mods, $src, 0, 0)
1414 (fcanonicalize (f16 (fneg (VOP3Mods f16:$src, i32:$src_mods)))),
1415 (V_MUL_F16_e64 0, (i32 CONST.FP16_NEG_ONE), $src_mods, $src, 0, 0)
1419 (fcanonicalize (v2f16 (VOP3PMods v2f16:$src, i32:$src_mods))),
1420 (V_PK_MUL_F16 0, (i32 CONST.V2FP16_ONE), $src_mods, $src, DSTCLAMP.NONE)
1424 let OtherPredicates = [FP16Denormals] in {
1426 (fcanonicalize (f16 (VOP3Mods f16:$src, i32:$src_mods))),
1427 (V_MAX_F16_e64 $src_mods, $src, $src_mods, $src, 0, 0)
1430 let SubtargetPredicate = HasVOP3PInsts in {
1432 (fcanonicalize (v2f16 (VOP3PMods v2f16:$src, i32:$src_mods))),
1433 (V_PK_MAX_F16 $src_mods, $src, $src_mods, $src, DSTCLAMP.NONE)
1438 let OtherPredicates = [NoFP32Denormals] in {
1440 (fcanonicalize (f32 (VOP3Mods f32:$src, i32:$src_mods))),
1441 (V_MUL_F32_e64 0, (i32 CONST.FP32_ONE), $src_mods, $src, 0, 0)
1445 (fcanonicalize (f32 (fneg (VOP3Mods f32:$src, i32:$src_mods)))),
1446 (V_MUL_F32_e64 0, (i32 CONST.FP32_NEG_ONE), $src_mods, $src, 0, 0)
1450 let OtherPredicates = [FP32Denormals] in {
1452 (fcanonicalize (f32 (VOP3Mods f32:$src, i32:$src_mods))),
1453 (V_MAX_F32_e64 $src_mods, $src, $src_mods, $src, 0, 0)
1457 let OtherPredicates = [NoFP64Denormals] in {
1459 (fcanonicalize (f64 (VOP3Mods f64:$src, i32:$src_mods))),
1460 (V_MUL_F64 0, CONST.FP64_ONE, $src_mods, $src, 0, 0)
1464 let OtherPredicates = [FP64Denormals] in {
1466 (fcanonicalize (f64 (VOP3Mods f64:$src, i32:$src_mods))),
1467 (V_MAX_F64 $src_mods, $src, $src_mods, $src, 0, 0)
1471 let OtherPredicates = [HasDLInsts] in {
1473 (fma (f32 (VOP3Mods0 f32:$src0, i32:$src0_modifiers, i1:$clamp, i32:$omod)),
1474 (f32 (VOP3Mods f32:$src1, i32:$src1_modifiers)),
1475 (f32 (VOP3NoMods f32:$src2))),
1476 (V_FMAC_F32_e64 $src0_modifiers, $src0, $src1_modifiers, $src1,
1477 SRCMODS.NONE, $src2, $clamp, $omod)
1479 } // End OtherPredicates = [HasDLInsts]
1482 // Allow integer inputs
1483 class ExpPattern<SDPatternOperator node, ValueType vt, Instruction Inst> : GCNPat<
1484 (node (i8 timm:$tgt), (i8 timm:$en), vt:$src0, vt:$src1, vt:$src2, vt:$src3, (i1 timm:$compr), (i1 timm:$vm)),
1485 (Inst i8:$tgt, vt:$src0, vt:$src1, vt:$src2, vt:$src3, i1:$vm, i1:$compr, i8:$en)
1488 def : ExpPattern<AMDGPUexport, i32, EXP>;
1489 def : ExpPattern<AMDGPUexport_done, i32, EXP_DONE>;
1491 // COPY is workaround tablegen bug from multiple outputs
1492 // from S_LSHL_B32's multiple outputs from implicit scc def.
1494 (v2i16 (build_vector (i16 0), i16:$src1)),
1495 (v2i16 (COPY (S_LSHL_B32 i16:$src1, (i16 16))))
1499 (v2i16 (build_vector i16:$src0, (i16 undef))),
1500 (v2i16 (COPY $src0))
1504 (v2f16 (build_vector f16:$src0, (f16 undef))),
1505 (v2f16 (COPY $src0))
1509 (v2i16 (build_vector (i16 undef), i16:$src1)),
1510 (v2i16 (COPY (S_LSHL_B32 $src1, (i32 16))))
1514 (v2f16 (build_vector (f16 undef), f16:$src1)),
1515 (v2f16 (COPY (S_LSHL_B32 $src1, (i32 16))))
1518 let SubtargetPredicate = HasVOP3PInsts in {
1520 (v2i16 (build_vector i16:$src0, i16:$src1)),
1521 (v2i16 (S_PACK_LL_B32_B16 $src0, $src1))
1524 // With multiple uses of the shift, this will duplicate the shift and
1525 // increase register pressure.
1527 (v2i16 (build_vector i16:$src0, (i16 (trunc (srl_oneuse i32:$src1, (i32 16)))))),
1528 (v2i16 (S_PACK_LH_B32_B16 i16:$src0, i32:$src1))
1533 (v2i16 (build_vector (i16 (trunc (srl_oneuse i32:$src0, (i32 16)))),
1534 (i16 (trunc (srl_oneuse i32:$src1, (i32 16)))))),
1535 (v2i16 (S_PACK_HH_B32_B16 $src0, $src1))
1538 // TODO: Should source modifiers be matched to v_pack_b32_f16?
1540 (v2f16 (build_vector f16:$src0, f16:$src1)),
1541 (v2f16 (S_PACK_LL_B32_B16 $src0, $src1))
1544 } // End SubtargetPredicate = HasVOP3PInsts
1548 (v2f16 (scalar_to_vector f16:$src0)),
1553 (v2i16 (scalar_to_vector i16:$src0)),
1558 (v4i16 (scalar_to_vector i16:$src0)),
1559 (INSERT_SUBREG (IMPLICIT_DEF), $src0, sub0)
1563 (v4f16 (scalar_to_vector f16:$src0)),
1564 (INSERT_SUBREG (IMPLICIT_DEF), $src0, sub0)
1567 //===----------------------------------------------------------------------===//
1569 //===----------------------------------------------------------------------===//
1571 let SubtargetPredicate = isSI in {
1573 // V_FRACT is buggy on SI, so the F32 version is never used and (x-floor(x)) is
1574 // used instead. However, SI doesn't have V_FLOOR_F64, so the most efficient
1575 // way to implement it is using V_FRACT_F64.
1576 // The workaround for the V_FRACT bug is:
1577 // fract(x) = isnan(x) ? x : min(V_FRACT(x), 0.99999999999999999)
1579 // Convert floor(x) to (x - fract(x))
1581 (f64 (ffloor (f64 (VOP3Mods f64:$x, i32:$mods)))),
1586 (V_CNDMASK_B64_PSEUDO
1589 (V_FRACT_F64_e64 $mods, $x, DSTCLAMP.NONE, DSTOMOD.NONE),
1591 (V_MOV_B64_PSEUDO 0x3fefffffffffffff),
1592 DSTCLAMP.NONE, DSTOMOD.NONE),
1594 (V_CMP_CLASS_F64_e64 SRCMODS.NONE, $x, (i32 3 /*NaN*/))),
1595 DSTCLAMP.NONE, DSTOMOD.NONE)
1598 } // End SubtargetPredicates = isSI
1600 //============================================================================//
1601 // Miscellaneous Optimization Patterns
1602 //============================================================================//
1604 // Undo sub x, c -> add x, -c canonicalization since c is more likely
1605 // an inline immediate than -c.
1606 // TODO: Also do for 64-bit.
1608 (add i32:$src0, (i32 NegSubInlineConst32:$src1)),
1609 (S_SUB_I32 $src0, NegSubInlineConst32:$src1)
1613 multiclass BFMPatterns <ValueType vt, InstSI BFM, InstSI MOV> {
1615 (vt (shl (vt (add (vt (shl 1, vt:$a)), -1)), vt:$b)),
1620 (vt (add (vt (shl 1, vt:$a)), -1)),
1621 (BFM $a, (MOV (i32 0)))
1625 let SubtargetPredicate = isGCN in {
1627 defm : BFMPatterns <i32, S_BFM_B32, S_MOV_B32>;
1628 // FIXME: defm : BFMPatterns <i64, S_BFM_B64, S_MOV_B64>;
1630 defm : BFEPattern <V_BFE_U32, V_BFE_I32, S_MOV_B32>;
1631 defm : SHA256MaPattern <V_BFI_B32, V_XOR_B32_e64, SReg_64>;
1633 defm : IntMed3Pat<V_MED3_I32, smin, smax, smin_oneuse, smax_oneuse>;
1634 defm : IntMed3Pat<V_MED3_U32, umin, umax, umin_oneuse, umax_oneuse>;
1638 // This matches 16 permutations of
1639 // max(min(x, y), min(max(x, y), z))
1640 class FPMed3Pat<ValueType vt,
1641 //SDPatternOperator max, SDPatternOperator min,
1642 Instruction med3Inst> : GCNPat<
1643 (fmaxnum_like (fminnum_like_oneuse (VOP3Mods_nnan vt:$src0, i32:$src0_mods),
1644 (VOP3Mods_nnan vt:$src1, i32:$src1_mods)),
1645 (fminnum_like_oneuse (fmaxnum_like_oneuse (VOP3Mods_nnan vt:$src0, i32:$src0_mods),
1646 (VOP3Mods_nnan vt:$src1, i32:$src1_mods)),
1647 (vt (VOP3Mods_nnan vt:$src2, i32:$src2_mods)))),
1648 (med3Inst $src0_mods, $src0, $src1_mods, $src1, $src2_mods, $src2, DSTCLAMP.NONE, DSTOMOD.NONE)
1651 class FP16Med3Pat<ValueType vt,
1652 Instruction med3Inst> : GCNPat<
1653 (fmaxnum_like (fminnum_like_oneuse (VOP3Mods_nnan vt:$src0, i32:$src0_mods),
1654 (VOP3Mods_nnan vt:$src1, i32:$src1_mods)),
1655 (fminnum_like_oneuse (fmaxnum_like_oneuse (VOP3Mods_nnan vt:$src0, i32:$src0_mods),
1656 (VOP3Mods_nnan vt:$src1, i32:$src1_mods)),
1657 (vt (VOP3Mods_nnan vt:$src2, i32:$src2_mods)))),
1658 (med3Inst $src0_mods, $src0, $src1_mods, $src1, $src2_mods, $src2, DSTCLAMP.NONE)
1661 multiclass Int16Med3Pat<Instruction med3Inst,
1662 SDPatternOperator min,
1663 SDPatternOperator max,
1664 SDPatternOperator max_oneuse,
1665 SDPatternOperator min_oneuse,
1666 ValueType vt = i16> {
1667 // This matches 16 permutations of
1668 // max(min(x, y), min(max(x, y), z))
1670 (max (min_oneuse vt:$src0, vt:$src1),
1671 (min_oneuse (max_oneuse vt:$src0, vt:$src1), vt:$src2)),
1672 (med3Inst SRCMODS.NONE, $src0, SRCMODS.NONE, $src1, SRCMODS.NONE, $src2, DSTCLAMP.NONE)
1675 // This matches 16 permutations of
1676 // min(max(a, b), max(min(a, b), c))
1678 (min (max_oneuse vt:$src0, vt:$src1),
1679 (max_oneuse (min_oneuse vt:$src0, vt:$src1), vt:$src2)),
1680 (med3Inst SRCMODS.NONE, $src0, SRCMODS.NONE, $src1, SRCMODS.NONE, $src2, DSTCLAMP.NONE)
1684 def : FPMed3Pat<f32, V_MED3_F32>;
1686 let OtherPredicates = [isGFX9] in {
1687 def : FP16Med3Pat<f16, V_MED3_F16>;
1688 defm : Int16Med3Pat<V_MED3_I16, smin, smax, smax_oneuse, smin_oneuse>;
1689 defm : Int16Med3Pat<V_MED3_U16, umin, umax, umax_oneuse, umin_oneuse>;
1690 } // End Predicates = [isGFX9]