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 def has16BankLDS : Predicate<"Subtarget->getLDSBankCount() == 16">;
15 def has32BankLDS : Predicate<"Subtarget->getLDSBankCount() == 32">;
16 def HasVGPRIndexMode : Predicate<"Subtarget->hasVGPRIndexMode()">,
17 AssemblerPredicate<"FeatureVGPRIndexMode">;
18 def HasMovrel : Predicate<"Subtarget->hasMovrel()">,
19 AssemblerPredicate<"FeatureMovrel">;
21 class GCNPat<dag pattern, dag result> : AMDGPUPat<pattern, result> {
22 let SubtargetPredicate = isGCN;
26 include "VOPInstructions.td"
27 include "SOPInstructions.td"
28 include "SMInstructions.td"
29 include "FLATInstructions.td"
30 include "BUFInstructions.td"
32 //===----------------------------------------------------------------------===//
34 //===----------------------------------------------------------------------===//
36 defm EXP : EXP_m<0, AMDGPUexport>;
37 defm EXP_DONE : EXP_m<1, AMDGPUexport_done>;
39 //===----------------------------------------------------------------------===//
40 // VINTRP Instructions
41 //===----------------------------------------------------------------------===//
43 let Uses = [M0, EXEC] in {
45 // FIXME: Specify SchedRW for VINTRP insturctions.
47 multiclass V_INTERP_P1_F32_m : VINTRP_m <
50 (ins VGPR_32:$vsrc, Attr:$attr, AttrChan:$attrchan),
51 "v_interp_p1_f32 $vdst, $vsrc, $attr$attrchan",
52 [(set f32:$vdst, (AMDGPUinterp_p1 f32:$vsrc, (i32 imm:$attrchan),
56 let OtherPredicates = [has32BankLDS] in {
58 defm V_INTERP_P1_F32 : V_INTERP_P1_F32_m;
60 } // End OtherPredicates = [has32BankLDS]
62 let OtherPredicates = [has16BankLDS], Constraints = "@earlyclobber $vdst", isAsmParserOnly=1 in {
64 defm V_INTERP_P1_F32_16bank : V_INTERP_P1_F32_m;
66 } // End OtherPredicates = [has32BankLDS], Constraints = "@earlyclobber $vdst", isAsmParserOnly=1
68 let DisableEncoding = "$src0", Constraints = "$src0 = $vdst" in {
70 defm V_INTERP_P2_F32 : VINTRP_m <
73 (ins VGPR_32:$src0, VGPR_32:$vsrc, Attr:$attr, AttrChan:$attrchan),
74 "v_interp_p2_f32 $vdst, $vsrc, $attr$attrchan",
75 [(set f32:$vdst, (AMDGPUinterp_p2 f32:$src0, f32:$vsrc, (i32 imm:$attrchan),
78 } // End DisableEncoding = "$src0", Constraints = "$src0 = $vdst"
80 defm V_INTERP_MOV_F32 : VINTRP_m <
83 (ins InterpSlot:$vsrc, Attr:$attr, AttrChan:$attrchan),
84 "v_interp_mov_f32 $vdst, $vsrc, $attr$attrchan",
85 [(set f32:$vdst, (AMDGPUinterp_mov (i32 imm:$vsrc), (i32 imm:$attrchan),
88 } // End Uses = [M0, EXEC]
90 //===----------------------------------------------------------------------===//
91 // Pseudo Instructions
92 //===----------------------------------------------------------------------===//
93 def ATOMIC_FENCE : SPseudoInstSI<
94 (outs), (ins i32imm:$ordering, i32imm:$scope),
95 [(atomic_fence (i32 imm:$ordering), (i32 imm:$scope))],
96 "ATOMIC_FENCE $ordering, $scope"> {
97 let hasSideEffects = 1;
101 let hasSideEffects = 0, mayLoad = 0, mayStore = 0, Uses = [EXEC] in {
103 // For use in patterns
104 def V_CNDMASK_B64_PSEUDO : VOP3Common <(outs VReg_64:$vdst),
105 (ins VSrc_b64:$src0, VSrc_b64:$src1, SSrc_b64:$src2), "", []> {
107 let isCodeGenOnly = 1;
108 let usesCustomInserter = 1;
111 // 64-bit vector move instruction. This is mainly used by the
112 // SIFoldOperands pass to enable folding of inline immediates.
113 def V_MOV_B64_PSEUDO : VPseudoInstSI <(outs VReg_64:$vdst),
114 (ins VSrc_b64:$src0)>;
116 // Pseudoinstruction for @llvm.amdgcn.wqm. It is turned into a copy after the
117 // WQM pass processes it.
118 def WQM : PseudoInstSI <(outs unknown:$vdst), (ins unknown:$src0)>;
120 // Pseudoinstruction for @llvm.amdgcn.wwm. It is turned into a copy post-RA, so
121 // that the @earlyclobber is respected. The @earlyclobber is to make sure that
122 // the instruction that defines $src0 (which is run in WWM) doesn't
123 // accidentally clobber inactive channels of $vdst.
124 let Constraints = "@earlyclobber $vdst" in {
125 def WWM : PseudoInstSI <(outs unknown:$vdst), (ins unknown:$src0)>;
128 } // End let hasSideEffects = 0, mayLoad = 0, mayStore = 0, Uses = [EXEC]
130 def EXIT_WWM : SPseudoInstSI <(outs SReg_64:$sdst), (ins SReg_64:$src0)> {
131 let hasSideEffects = 0;
136 // Invert the exec mask and overwrite the inactive lanes of dst with inactive,
137 // restoring it after we're done.
138 def V_SET_INACTIVE_B32 : VPseudoInstSI <(outs VGPR_32:$vdst),
139 (ins VGPR_32: $src, VSrc_b32:$inactive),
140 [(set i32:$vdst, (int_amdgcn_set_inactive i32:$src, i32:$inactive))]> {
141 let Constraints = "$src = $vdst";
144 def V_SET_INACTIVE_B64 : VPseudoInstSI <(outs VReg_64:$vdst),
145 (ins VReg_64: $src, VSrc_b64:$inactive),
146 [(set i64:$vdst, (int_amdgcn_set_inactive i64:$src, i64:$inactive))]> {
147 let Constraints = "$src = $vdst";
151 let usesCustomInserter = 1, Defs = [SCC] in {
152 def S_ADD_U64_PSEUDO : SPseudoInstSI <
153 (outs SReg_64:$vdst), (ins SSrc_b64:$src0, SSrc_b64:$src1),
154 [(set SReg_64:$vdst, (add i64:$src0, i64:$src1))]
157 def S_SUB_U64_PSEUDO : SPseudoInstSI <
158 (outs SReg_64:$vdst), (ins SSrc_b64:$src0, SSrc_b64:$src1),
159 [(set SReg_64:$vdst, (sub i64:$src0, i64:$src1))]
162 def S_ADD_U64_CO_PSEUDO : SPseudoInstSI <
163 (outs SReg_64:$vdst, VOPDstS64:$sdst), (ins SSrc_b64:$src0, SSrc_b64:$src1)
166 def S_SUB_U64_CO_PSEUDO : SPseudoInstSI <
167 (outs SReg_64:$vdst, VOPDstS64:$sdst), (ins SSrc_b64:$src0, SSrc_b64:$src1)
170 } // End usesCustomInserter = 1, Defs = [SCC]
172 let usesCustomInserter = 1, SALU = 1 in {
173 def GET_GROUPSTATICSIZE : PseudoInstSI <(outs SReg_32:$sdst), (ins),
174 [(set SReg_32:$sdst, (int_amdgcn_groupstaticsize))]>;
175 } // End let usesCustomInserter = 1, SALU = 1
177 def S_MOV_B64_term : PseudoInstSI<(outs SReg_64:$dst),
178 (ins SSrc_b64:$src0)> {
180 let isAsCheapAsAMove = 1;
181 let isTerminator = 1;
184 def S_XOR_B64_term : PseudoInstSI<(outs SReg_64:$dst),
185 (ins SSrc_b64:$src0, SSrc_b64:$src1)> {
187 let isAsCheapAsAMove = 1;
188 let isTerminator = 1;
191 def S_ANDN2_B64_term : PseudoInstSI<(outs SReg_64:$dst),
192 (ins SSrc_b64:$src0, SSrc_b64:$src1)> {
194 let isAsCheapAsAMove = 1;
195 let isTerminator = 1;
198 def WAVE_BARRIER : SPseudoInstSI<(outs), (ins),
199 [(int_amdgcn_wave_barrier)]> {
201 let hasNoSchedulingInfo = 1;
202 let hasSideEffects = 1;
206 let isConvergent = 1;
211 // SI pseudo instructions. These are used by the CFG structurizer pass
212 // and should be lowered to ISA instructions prior to codegen.
214 // Dummy terminator instruction to use after control flow instructions
215 // replaced with exec mask operations.
216 def SI_MASK_BRANCH : VPseudoInstSI <
217 (outs), (ins brtarget:$target)> {
219 let isTerminator = 1;
222 let hasNoSchedulingInfo = 1;
227 let isTerminator = 1 in {
229 let OtherPredicates = [EnableLateCFGStructurize] in {
230 def SI_NON_UNIFORM_BRCOND_PSEUDO : CFPseudoInstSI <
232 (ins SReg_64:$vcc, brtarget:$target),
233 [(brcond i1:$vcc, bb:$target)]> {
238 def SI_IF: CFPseudoInstSI <
239 (outs SReg_64:$dst), (ins SReg_64:$vcc, brtarget:$target),
240 [(set i64:$dst, (AMDGPUif i1:$vcc, bb:$target))], 1, 1> {
241 let Constraints = "";
243 let hasSideEffects = 1;
246 def SI_ELSE : CFPseudoInstSI <
248 (ins SReg_64:$src, brtarget:$target, i1imm:$execfix), [], 1, 1> {
249 let Constraints = "$src = $dst";
251 let hasSideEffects = 1;
254 def SI_LOOP : CFPseudoInstSI <
255 (outs), (ins SReg_64:$saved, brtarget:$target),
256 [(AMDGPUloop i64:$saved, bb:$target)], 1, 1> {
259 let hasSideEffects = 1;
262 } // End isTerminator = 1
264 def SI_END_CF : CFPseudoInstSI <
265 (outs), (ins SReg_64:$saved),
266 [(int_amdgcn_end_cf i64:$saved)], 1, 1> {
268 let isAsCheapAsAMove = 1;
269 let isReMaterializable = 1;
270 let hasSideEffects = 1;
271 let mayLoad = 1; // FIXME: Should not need memory flags
275 def SI_BREAK : CFPseudoInstSI <
276 (outs SReg_64:$dst), (ins SReg_64:$src),
277 [(set i64:$dst, (int_amdgcn_break i64:$src))], 1> {
279 let isAsCheapAsAMove = 1;
280 let isReMaterializable = 1;
283 def SI_IF_BREAK : CFPseudoInstSI <
284 (outs SReg_64:$dst), (ins SReg_64:$vcc, SReg_64:$src),
285 [(set i64:$dst, (int_amdgcn_if_break i1:$vcc, i64:$src))]> {
287 let isAsCheapAsAMove = 1;
288 let isReMaterializable = 1;
291 def SI_ELSE_BREAK : CFPseudoInstSI <
292 (outs SReg_64:$dst), (ins SReg_64:$src0, SReg_64:$src1),
293 [(set i64:$dst, (int_amdgcn_else_break i64:$src0, i64:$src1))]> {
295 let isAsCheapAsAMove = 1;
296 let isReMaterializable = 1;
299 let Uses = [EXEC], Defs = [EXEC,VCC] in {
301 multiclass PseudoInstKill <dag ins> {
302 def _PSEUDO : PseudoInstSI <(outs), ins> {
303 let isConvergent = 1;
304 let usesCustomInserter = 1;
307 def _TERMINATOR : SPseudoInstSI <(outs), ins> {
308 let isTerminator = 1;
312 defm SI_KILL_I1 : PseudoInstKill <(ins SSrc_b64:$src, i1imm:$killvalue)>;
313 defm SI_KILL_F32_COND_IMM : PseudoInstKill <(ins VSrc_b32:$src0, i32imm:$src1, i32imm:$cond)>;
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;
376 // Return for returning function calls.
377 def SI_RETURN : SPseudoInstSI <
380 let isTerminator = 1;
383 let SchedRW = [WriteBranch];
386 // Return for returning function calls without output register.
388 // This version is only needed so we can fill in the output regiter in
389 // the custom inserter.
390 def SI_CALL_ISEL : SPseudoInstSI <
391 (outs), (ins SSrc_b64:$src0), [(AMDGPUcall i64:$src0)]> {
394 let SchedRW = [WriteBranch];
395 let usesCustomInserter = 1;
398 // Wrapper around s_swappc_b64 with extra $callee parameter to track
399 // the called function after regalloc.
400 def SI_CALL : SPseudoInstSI <
401 (outs SReg_64:$dst), (ins SSrc_b64:$src0, unknown:$callee)> {
404 let UseNamedOperandTable = 1;
405 let SchedRW = [WriteBranch];
408 // Tail call handling pseudo
409 def SI_TCRETURN_ISEL : SPseudoInstSI<(outs),
410 (ins SSrc_b64:$src0, i32imm:$fpdiff),
411 [(AMDGPUtc_return i64:$src0, i32:$fpdiff)]> {
413 let isTerminator = 1;
416 let SchedRW = [WriteBranch];
417 let usesCustomInserter = 1;
420 def SI_TCRETURN : SPseudoInstSI <
422 (ins SSrc_b64:$src0, unknown:$callee, i32imm:$fpdiff)> {
425 let isTerminator = 1;
428 let UseNamedOperandTable = 1;
429 let SchedRW = [WriteBranch];
433 def ADJCALLSTACKUP : SPseudoInstSI<
434 (outs), (ins i32imm:$amt0, i32imm:$amt1),
435 [(callseq_start timm:$amt0, timm:$amt1)],
436 "; adjcallstackup $amt0 $amt1"> {
437 let Size = 8; // Worst case. (s_add_u32 + constant)
439 let hasSideEffects = 1;
440 let usesCustomInserter = 1;
443 def ADJCALLSTACKDOWN : SPseudoInstSI<
444 (outs), (ins i32imm:$amt1, i32imm:$amt2),
445 [(callseq_end timm:$amt1, timm:$amt2)],
446 "; adjcallstackdown $amt1"> {
447 let Size = 8; // Worst case. (s_add_u32 + constant)
448 let hasSideEffects = 1;
449 let usesCustomInserter = 1;
452 let Defs = [M0, EXEC],
453 UseNamedOperandTable = 1 in {
455 class SI_INDIRECT_SRC<RegisterClass rc> : VPseudoInstSI <
456 (outs VGPR_32:$vdst),
457 (ins rc:$src, VS_32:$idx, i32imm:$offset)> {
458 let usesCustomInserter = 1;
461 class SI_INDIRECT_DST<RegisterClass rc> : VPseudoInstSI <
463 (ins rc:$src, VS_32:$idx, i32imm:$offset, VGPR_32:$val)> {
464 let Constraints = "$src = $vdst";
465 let usesCustomInserter = 1;
468 // TODO: We can support indirect SGPR access.
469 def SI_INDIRECT_SRC_V1 : SI_INDIRECT_SRC<VGPR_32>;
470 def SI_INDIRECT_SRC_V2 : SI_INDIRECT_SRC<VReg_64>;
471 def SI_INDIRECT_SRC_V4 : SI_INDIRECT_SRC<VReg_128>;
472 def SI_INDIRECT_SRC_V8 : SI_INDIRECT_SRC<VReg_256>;
473 def SI_INDIRECT_SRC_V16 : SI_INDIRECT_SRC<VReg_512>;
475 def SI_INDIRECT_DST_V1 : SI_INDIRECT_DST<VGPR_32>;
476 def SI_INDIRECT_DST_V2 : SI_INDIRECT_DST<VReg_64>;
477 def SI_INDIRECT_DST_V4 : SI_INDIRECT_DST<VReg_128>;
478 def SI_INDIRECT_DST_V8 : SI_INDIRECT_DST<VReg_256>;
479 def SI_INDIRECT_DST_V16 : SI_INDIRECT_DST<VReg_512>;
481 } // End Uses = [EXEC], Defs = [M0, EXEC]
483 multiclass SI_SPILL_SGPR <RegisterClass sgpr_class> {
484 let UseNamedOperandTable = 1, SGPRSpill = 1, Uses = [EXEC] in {
485 def _SAVE : PseudoInstSI <
487 (ins sgpr_class:$data, i32imm:$addr)> {
492 def _RESTORE : PseudoInstSI <
493 (outs sgpr_class:$data),
494 (ins i32imm:$addr)> {
498 } // End UseNamedOperandTable = 1
501 // You cannot use M0 as the output of v_readlane_b32 instructions or
502 // use it in the sdata operand of SMEM instructions. We still need to
503 // be able to spill the physical register m0, so allow it for
504 // SI_SPILL_32_* instructions.
505 defm SI_SPILL_S32 : SI_SPILL_SGPR <SReg_32>;
506 defm SI_SPILL_S64 : SI_SPILL_SGPR <SReg_64>;
507 defm SI_SPILL_S128 : SI_SPILL_SGPR <SReg_128>;
508 defm SI_SPILL_S256 : SI_SPILL_SGPR <SReg_256>;
509 defm SI_SPILL_S512 : SI_SPILL_SGPR <SReg_512>;
511 multiclass SI_SPILL_VGPR <RegisterClass vgpr_class> {
512 let UseNamedOperandTable = 1, VGPRSpill = 1,
513 SchedRW = [WriteVMEM] in {
514 def _SAVE : VPseudoInstSI <
516 (ins vgpr_class:$vdata, i32imm:$vaddr, SReg_128:$srsrc,
517 SReg_32:$soffset, i32imm:$offset)> {
520 // (2 * 4) + (8 * num_subregs) bytes maximum
521 let Size = !add(!shl(!srl(vgpr_class.Size, 5), 3), 8);
524 def _RESTORE : VPseudoInstSI <
525 (outs vgpr_class:$vdata),
526 (ins i32imm:$vaddr, SReg_128:$srsrc, SReg_32:$soffset,
531 // (2 * 4) + (8 * num_subregs) bytes maximum
532 let Size = !add(!shl(!srl(vgpr_class.Size, 5), 3), 8);
534 } // End UseNamedOperandTable = 1, VGPRSpill = 1, SchedRW = [WriteVMEM]
537 defm SI_SPILL_V32 : SI_SPILL_VGPR <VGPR_32>;
538 defm SI_SPILL_V64 : SI_SPILL_VGPR <VReg_64>;
539 defm SI_SPILL_V96 : SI_SPILL_VGPR <VReg_96>;
540 defm SI_SPILL_V128 : SI_SPILL_VGPR <VReg_128>;
541 defm SI_SPILL_V256 : SI_SPILL_VGPR <VReg_256>;
542 defm SI_SPILL_V512 : SI_SPILL_VGPR <VReg_512>;
544 def SI_PC_ADD_REL_OFFSET : SPseudoInstSI <
546 (ins si_ga:$ptr_lo, si_ga:$ptr_hi),
548 (i64 (SIpc_add_rel_offset (tglobaladdr:$ptr_lo), (tglobaladdr:$ptr_hi))))]> {
553 (AMDGPUinit_exec i64:$src),
554 (SI_INIT_EXEC (as_i64imm $src))
558 (AMDGPUinit_exec_from_input i32:$input, i32:$shift),
559 (SI_INIT_EXEC_FROM_INPUT (i32 $input), (as_i32imm $shift))
563 (AMDGPUtrap timm:$trapid),
568 (AMDGPUelse i64:$src, bb:$target),
569 (SI_ELSE $src, $target, 0)
574 (SI_KILL_I1_PSEUDO (i1 0), 0)
578 // -1.0 as i32 (LowerINTRINSIC_VOID converts all other constants to -1.0)
579 (AMDGPUkill (i32 -1082130432)),
580 (SI_KILL_I1_PSEUDO (i1 0), 0)
584 (int_amdgcn_kill i1:$src),
585 (SI_KILL_I1_PSEUDO $src, 0)
589 (int_amdgcn_kill (i1 (not i1:$src))),
590 (SI_KILL_I1_PSEUDO $src, -1)
594 (AMDGPUkill i32:$src),
595 (SI_KILL_F32_COND_IMM_PSEUDO $src, 0, 3) // 3 means SETOGE
599 (int_amdgcn_kill (i1 (setcc f32:$src, InlineFPImm<f32>:$imm, cond:$cond))),
600 (SI_KILL_F32_COND_IMM_PSEUDO $src, (bitcast_fpimm_to_i32 $imm), (cond_as_i32imm $cond))
602 // TODO: we could add more variants for other types of conditionals
604 //===----------------------------------------------------------------------===//
606 //===----------------------------------------------------------------------===//
608 let SubtargetPredicate = isGCN, OtherPredicates = [UnsafeFPMath] in {
610 //def : RcpPat<V_RCP_F64_e32, f64>;
611 //defm : RsqPat<V_RSQ_F64_e32, f64>;
612 //defm : RsqPat<V_RSQ_F32_e32, f32>;
614 def : RsqPat<V_RSQ_F32_e32, f32>;
615 def : RsqPat<V_RSQ_F64_e32, f64>;
617 // Convert (x - floor(x)) to fract(x)
619 (f32 (fsub (f32 (VOP3Mods f32:$x, i32:$mods)),
620 (f32 (ffloor (f32 (VOP3Mods f32:$x, i32:$mods)))))),
621 (V_FRACT_F32_e64 $mods, $x, DSTCLAMP.NONE, DSTOMOD.NONE)
624 // Convert (x + (-floor(x))) to fract(x)
626 (f64 (fadd (f64 (VOP3Mods f64:$x, i32:$mods)),
627 (f64 (fneg (f64 (ffloor (f64 (VOP3Mods f64:$x, i32:$mods)))))))),
628 (V_FRACT_F64_e64 $mods, $x, DSTCLAMP.NONE, DSTOMOD.NONE)
631 } // End SubtargetPredicate = isGCN, OtherPredicates = [UnsafeFPMath]
634 // f16_to_fp patterns
636 (f32 (f16_to_fp i32:$src0)),
637 (V_CVT_F32_F16_e64 SRCMODS.NONE, $src0, DSTCLAMP.NONE, DSTOMOD.NONE)
641 (f32 (f16_to_fp (and_oneuse i32:$src0, 0x7fff))),
642 (V_CVT_F32_F16_e64 SRCMODS.ABS, $src0, DSTCLAMP.NONE, DSTOMOD.NONE)
646 (f32 (f16_to_fp (or_oneuse i32:$src0, 0x8000))),
647 (V_CVT_F32_F16_e64 SRCMODS.NEG_ABS, $src0, DSTCLAMP.NONE, DSTOMOD.NONE)
651 (f32 (f16_to_fp (xor_oneuse i32:$src0, 0x8000))),
652 (V_CVT_F32_F16_e64 SRCMODS.NEG, $src0, DSTCLAMP.NONE, DSTOMOD.NONE)
656 (f64 (fpextend f16:$src)),
657 (V_CVT_F64_F32_e32 (V_CVT_F32_F16_e32 $src))
660 // fp_to_fp16 patterns
662 (i32 (AMDGPUfp_to_f16 (f32 (VOP3Mods f32:$src0, i32:$src0_modifiers)))),
663 (V_CVT_F16_F32_e64 $src0_modifiers, f32:$src0, DSTCLAMP.NONE, DSTOMOD.NONE)
667 (i32 (fp_to_sint f16:$src)),
668 (V_CVT_I32_F32_e32 (V_CVT_F32_F16_e32 $src))
672 (i32 (fp_to_uint f16:$src)),
673 (V_CVT_U32_F32_e32 (V_CVT_F32_F16_e32 $src))
677 (f16 (sint_to_fp i32:$src)),
678 (V_CVT_F16_F32_e32 (V_CVT_F32_I32_e32 $src))
682 (f16 (uint_to_fp i32:$src)),
683 (V_CVT_F16_F32_e32 (V_CVT_F32_U32_e32 $src))
686 //===----------------------------------------------------------------------===//
688 //===----------------------------------------------------------------------===//
690 multiclass FMADPat <ValueType vt, Instruction inst> {
692 (vt (fmad (VOP3NoMods vt:$src0),
693 (VOP3NoMods vt:$src1),
694 (VOP3NoMods vt:$src2))),
695 (inst SRCMODS.NONE, $src0, SRCMODS.NONE, $src1,
696 SRCMODS.NONE, $src2, DSTCLAMP.NONE, DSTOMOD.NONE)
700 defm : FMADPat <f16, V_MAC_F16_e64>;
701 defm : FMADPat <f32, V_MAC_F32_e64>;
703 class FMADModsPat<Instruction inst, SDPatternOperator mad_opr> : GCNPat<
704 (f32 (mad_opr (VOP3Mods f32:$src0, i32:$src0_mod),
705 (VOP3Mods f32:$src1, i32:$src1_mod),
706 (VOP3Mods f32:$src2, i32:$src2_mod))),
707 (inst $src0_mod, $src0, $src1_mod, $src1,
708 $src2_mod, $src2, DSTCLAMP.NONE, DSTOMOD.NONE)
711 def : FMADModsPat<V_MAD_F32, AMDGPUfmad_ftz>;
713 multiclass SelectPat <ValueType vt, Instruction inst> {
715 (vt (select i1:$src0, vt:$src1, vt:$src2)),
716 (inst $src2, $src1, $src0)
720 defm : SelectPat <i16, V_CNDMASK_B32_e64>;
721 defm : SelectPat <i32, V_CNDMASK_B32_e64>;
722 defm : SelectPat <f16, V_CNDMASK_B32_e64>;
723 defm : SelectPat <f32, V_CNDMASK_B32_e64>;
726 (i32 (add (i32 (ctpop i32:$popcnt)), i32:$val)),
727 (V_BCNT_U32_B32_e64 $popcnt, $val)
730 (i16 (add (i16 (trunc (ctpop i32:$popcnt))), i16:$val)),
731 (V_BCNT_U32_B32_e64 $popcnt, $val)
734 /********** ============================================ **********/
735 /********** Extraction, Insertion, Building and Casting **********/
736 /********** ============================================ **********/
738 foreach Index = 0-2 in {
739 def Extract_Element_v2i32_#Index : Extract_Element <
740 i32, v2i32, Index, !cast<SubRegIndex>(sub#Index)
742 def Insert_Element_v2i32_#Index : Insert_Element <
743 i32, v2i32, Index, !cast<SubRegIndex>(sub#Index)
746 def Extract_Element_v2f32_#Index : Extract_Element <
747 f32, v2f32, Index, !cast<SubRegIndex>(sub#Index)
749 def Insert_Element_v2f32_#Index : Insert_Element <
750 f32, v2f32, Index, !cast<SubRegIndex>(sub#Index)
754 foreach Index = 0-3 in {
755 def Extract_Element_v4i32_#Index : Extract_Element <
756 i32, v4i32, Index, !cast<SubRegIndex>(sub#Index)
758 def Insert_Element_v4i32_#Index : Insert_Element <
759 i32, v4i32, Index, !cast<SubRegIndex>(sub#Index)
762 def Extract_Element_v4f32_#Index : Extract_Element <
763 f32, v4f32, Index, !cast<SubRegIndex>(sub#Index)
765 def Insert_Element_v4f32_#Index : Insert_Element <
766 f32, v4f32, Index, !cast<SubRegIndex>(sub#Index)
770 foreach Index = 0-7 in {
771 def Extract_Element_v8i32_#Index : Extract_Element <
772 i32, v8i32, Index, !cast<SubRegIndex>(sub#Index)
774 def Insert_Element_v8i32_#Index : Insert_Element <
775 i32, v8i32, Index, !cast<SubRegIndex>(sub#Index)
778 def Extract_Element_v8f32_#Index : Extract_Element <
779 f32, v8f32, Index, !cast<SubRegIndex>(sub#Index)
781 def Insert_Element_v8f32_#Index : Insert_Element <
782 f32, v8f32, Index, !cast<SubRegIndex>(sub#Index)
786 foreach Index = 0-15 in {
787 def Extract_Element_v16i32_#Index : Extract_Element <
788 i32, v16i32, Index, !cast<SubRegIndex>(sub#Index)
790 def Insert_Element_v16i32_#Index : Insert_Element <
791 i32, v16i32, Index, !cast<SubRegIndex>(sub#Index)
794 def Extract_Element_v16f32_#Index : Extract_Element <
795 f32, v16f32, Index, !cast<SubRegIndex>(sub#Index)
797 def Insert_Element_v16f32_#Index : Insert_Element <
798 f32, v16f32, Index, !cast<SubRegIndex>(sub#Index)
802 let SubtargetPredicate = isGCN in {
804 // FIXME: Why do only some of these type combinations for SReg and
807 def : BitConvert <i16, f16, VGPR_32>;
808 def : BitConvert <f16, i16, VGPR_32>;
809 def : BitConvert <i16, f16, SReg_32>;
810 def : BitConvert <f16, i16, SReg_32>;
813 def : BitConvert <i32, f32, VGPR_32>;
814 def : BitConvert <f32, i32, VGPR_32>;
815 def : BitConvert <i32, f32, SReg_32>;
816 def : BitConvert <f32, i32, SReg_32>;
817 def : BitConvert <v2i16, i32, SReg_32>;
818 def : BitConvert <i32, v2i16, SReg_32>;
819 def : BitConvert <v2f16, i32, SReg_32>;
820 def : BitConvert <i32, v2f16, SReg_32>;
821 def : BitConvert <v2i16, v2f16, SReg_32>;
822 def : BitConvert <v2f16, v2i16, SReg_32>;
823 def : BitConvert <v2f16, f32, SReg_32>;
824 def : BitConvert <f32, v2f16, SReg_32>;
825 def : BitConvert <v2i16, f32, SReg_32>;
826 def : BitConvert <f32, v2i16, SReg_32>;
829 def : BitConvert <i64, f64, VReg_64>;
830 def : BitConvert <f64, i64, VReg_64>;
831 def : BitConvert <v2i32, v2f32, VReg_64>;
832 def : BitConvert <v2f32, v2i32, VReg_64>;
833 def : BitConvert <i64, v2i32, VReg_64>;
834 def : BitConvert <v2i32, i64, VReg_64>;
835 def : BitConvert <i64, v2f32, VReg_64>;
836 def : BitConvert <v2f32, i64, VReg_64>;
837 def : BitConvert <f64, v2f32, VReg_64>;
838 def : BitConvert <v2f32, f64, VReg_64>;
839 def : BitConvert <f64, v2i32, VReg_64>;
840 def : BitConvert <v2i32, f64, VReg_64>;
841 def : BitConvert <v4i32, v4f32, VReg_128>;
842 def : BitConvert <v4f32, v4i32, VReg_128>;
845 def : BitConvert <v2i64, v4i32, SReg_128>;
846 def : BitConvert <v4i32, v2i64, SReg_128>;
847 def : BitConvert <v2f64, v4f32, VReg_128>;
848 def : BitConvert <v2f64, v4i32, VReg_128>;
849 def : BitConvert <v4f32, v2f64, VReg_128>;
850 def : BitConvert <v4i32, v2f64, VReg_128>;
851 def : BitConvert <v2i64, v2f64, VReg_128>;
852 def : BitConvert <v2f64, v2i64, VReg_128>;
855 def : BitConvert <v8i32, v8f32, SReg_256>;
856 def : BitConvert <v8f32, v8i32, SReg_256>;
857 def : BitConvert <v8i32, v8f32, VReg_256>;
858 def : BitConvert <v8f32, v8i32, VReg_256>;
861 def : BitConvert <v16i32, v16f32, VReg_512>;
862 def : BitConvert <v16f32, v16i32, VReg_512>;
864 } // End SubtargetPredicate = isGCN
866 /********** =================== **********/
867 /********** Src & Dst modifiers **********/
868 /********** =================== **********/
871 // If denormals are not enabled, it only impacts the compare of the
872 // inputs. The output result is not flushed.
873 class ClampPat<Instruction inst, ValueType vt> : GCNPat <
874 (vt (AMDGPUclamp (VOP3Mods vt:$src0, i32:$src0_modifiers))),
875 (inst i32:$src0_modifiers, vt:$src0,
876 i32:$src0_modifiers, vt:$src0, DSTCLAMP.ENABLE, DSTOMOD.NONE)
879 def : ClampPat<V_MAX_F32_e64, f32>;
880 def : ClampPat<V_MAX_F64, f64>;
881 def : ClampPat<V_MAX_F16_e64, f16>;
884 (v2f16 (AMDGPUclamp (VOP3PMods v2f16:$src0, i32:$src0_modifiers))),
885 (V_PK_MAX_F16 $src0_modifiers, $src0,
886 $src0_modifiers, $src0, DSTCLAMP.ENABLE)
889 /********** ================================ **********/
890 /********** Floating point absolute/negative **********/
891 /********** ================================ **********/
893 // Prevent expanding both fneg and fabs.
896 (fneg (fabs f32:$src)),
897 (S_OR_B32 $src, (S_MOV_B32(i32 0x80000000))) // Set sign bit
900 // FIXME: Should use S_OR_B32
902 (fneg (fabs f64:$src)),
903 (REG_SEQUENCE VReg_64,
904 (i32 (EXTRACT_SUBREG f64:$src, sub0)),
906 (V_OR_B32_e32 (i32 (EXTRACT_SUBREG f64:$src, sub1)),
907 (V_MOV_B32_e32 (i32 0x80000000))), // Set sign bit.
913 (V_AND_B32_e64 $src, (V_MOV_B32_e32 (i32 0x7fffffff)))
918 (V_XOR_B32_e32 $src, (V_MOV_B32_e32 (i32 0x80000000)))
923 (REG_SEQUENCE VReg_64,
924 (i32 (EXTRACT_SUBREG f64:$src, sub0)),
926 (V_AND_B32_e64 (i32 (EXTRACT_SUBREG f64:$src, sub1)),
927 (V_MOV_B32_e32 (i32 0x7fffffff))), // Set sign bit.
933 (REG_SEQUENCE VReg_64,
934 (i32 (EXTRACT_SUBREG f64:$src, sub0)),
936 (V_XOR_B32_e32 (i32 (EXTRACT_SUBREG f64:$src, sub1)),
937 (i32 (V_MOV_B32_e32 (i32 0x80000000)))),
942 (fcopysign f16:$src0, f16:$src1),
943 (V_BFI_B32 (S_MOV_B32 (i32 0x00007fff)), $src0, $src1)
947 (fcopysign f32:$src0, f16:$src1),
948 (V_BFI_B32 (S_MOV_B32 (i32 0x7fffffff)), $src0,
949 (V_LSHLREV_B32_e64 (i32 16), $src1))
953 (fcopysign f64:$src0, f16:$src1),
954 (REG_SEQUENCE SReg_64,
955 (i32 (EXTRACT_SUBREG $src0, sub0)), sub0,
956 (V_BFI_B32 (S_MOV_B32 (i32 0x7fffffff)), (i32 (EXTRACT_SUBREG $src0, sub1)),
957 (V_LSHLREV_B32_e64 (i32 16), $src1)), sub1)
961 (fcopysign f16:$src0, f32:$src1),
962 (V_BFI_B32 (S_MOV_B32 (i32 0x00007fff)), $src0,
963 (V_LSHRREV_B32_e64 (i32 16), $src1))
967 (fcopysign f16:$src0, f64:$src1),
968 (V_BFI_B32 (S_MOV_B32 (i32 0x00007fff)), $src0,
969 (V_LSHRREV_B32_e64 (i32 16), (EXTRACT_SUBREG $src1, sub1)))
974 (V_XOR_B32_e32 $src, (V_MOV_B32_e32 (i32 0x00008000)))
979 (V_AND_B32_e64 $src, (V_MOV_B32_e32 (i32 0x00007fff)))
983 (fneg (fabs f16:$src)),
984 (S_OR_B32 $src, (S_MOV_B32 (i32 0x00008000))) // Set sign bit
989 (V_XOR_B32_e64 (S_MOV_B32 (i32 0x80008000)), $src)
994 (V_AND_B32_e64 (S_MOV_B32 (i32 0x7fff7fff)), $src)
997 // This is really (fneg (fabs v2f16:$src))
999 // fabs is not reported as free because there is modifier for it in
1000 // VOP3P instructions, so it is turned into the bit op.
1002 (fneg (v2f16 (bitconvert (and_oneuse i32:$src, 0x7fff7fff)))),
1003 (S_OR_B32 (S_MOV_B32 (i32 0x80008000)), $src) // Set sign bit
1006 /********** ================== **********/
1007 /********** Immediate Patterns **********/
1008 /********** ================== **********/
1011 (VGPRImm<(i32 imm)>:$imm),
1012 (V_MOV_B32_e32 imm:$imm)
1016 (VGPRImm<(f32 fpimm)>:$imm),
1017 (V_MOV_B32_e32 (f32 (bitcast_fpimm_to_i32 $imm)))
1022 (S_MOV_B32 imm:$imm)
1025 // FIXME: Workaround for ordering issue with peephole optimizer where
1026 // a register class copy interferes with immediate folding. Should
1027 // use s_mov_b32, which can be shrunk to s_movk_i32
1029 (VGPRImm<(f16 fpimm)>:$imm),
1030 (V_MOV_B32_e32 (f16 (bitcast_fpimm_to_i32 $imm)))
1035 (S_MOV_B32 (f32 (bitcast_fpimm_to_i32 $imm)))
1040 (S_MOV_B32 (i32 (bitcast_fpimm_to_i32 $imm)))
1044 (i32 frameindex:$fi),
1045 (V_MOV_B32_e32 (i32 (frameindex_to_targetframeindex $fi)))
1049 (i64 InlineImm<i64>:$imm),
1050 (S_MOV_B64 InlineImm<i64>:$imm)
1053 // XXX - Should this use a s_cmp to set SCC?
1055 // Set to sign-extended 64-bit value (true = -1, false = 0)
1058 (S_MOV_B64 (i64 (as_i64imm $imm)))
1062 (f64 InlineFPImm<f64>:$imm),
1063 (S_MOV_B64 (f64 (bitcast_fpimm_to_i64 InlineFPImm<f64>:$imm)))
1066 /********** ================== **********/
1067 /********** Intrinsic Patterns **********/
1068 /********** ================== **********/
1070 let SubtargetPredicate = isGCN in {
1071 def : POW_Common <V_LOG_F32_e32, V_EXP_F32_e32, V_MUL_LEGACY_F32_e32>;
1075 (i32 (sext i1:$src0)),
1076 (V_CNDMASK_B32_e64 (i32 0), (i32 -1), $src0)
1079 class Ext32Pat <SDNode ext> : GCNPat <
1080 (i32 (ext i1:$src0)),
1081 (V_CNDMASK_B32_e64 (i32 0), (i32 1), $src0)
1084 def : Ext32Pat <zext>;
1085 def : Ext32Pat <anyext>;
1087 // The multiplication scales from [0,1] to the unsigned integer range
1089 (AMDGPUurecip i32:$src0),
1091 (V_MUL_F32_e32 (i32 CONST.FP_UINT_MAX_PLUS_1),
1092 (V_RCP_IFLAG_F32_e32 (V_CVT_F32_U32_e32 $src0))))
1095 //===----------------------------------------------------------------------===//
1097 //===----------------------------------------------------------------------===//
1099 let SubtargetPredicate = isGCN in {
1101 def : IMad24Pat<V_MAD_I32_I24, 1>;
1102 def : UMad24Pat<V_MAD_U32_U24, 1>;
1104 defm : BFIPatterns <V_BFI_B32, S_MOV_B32, SReg_64>;
1105 def : ROTRPattern <V_ALIGNBIT_B32>;
1109 def : GCNPat<(i32 (trunc (srl i64:$src0, (and i32:$src1, (i32 31))))),
1110 (V_ALIGNBIT_B32 (i32 (EXTRACT_SUBREG (i64 $src0), sub1)),
1111 (i32 (EXTRACT_SUBREG (i64 $src0), sub0)), $src1)>;
1113 def : GCNPat<(i32 (trunc (srl i64:$src0, (i32 ShiftAmt32Imm:$src1)))),
1114 (V_ALIGNBIT_B32 (i32 (EXTRACT_SUBREG (i64 $src0), sub1)),
1115 (i32 (EXTRACT_SUBREG (i64 $src0), sub0)), $src1)>;
1117 /********** ====================== **********/
1118 /********** Indirect addressing **********/
1119 /********** ====================== **********/
1121 multiclass SI_INDIRECT_Pattern <ValueType vt, ValueType eltvt, string VecSize> {
1122 // Extract with offset
1124 (eltvt (extractelt vt:$src, (MOVRELOffset i32:$idx, (i32 imm:$offset)))),
1125 (!cast<Instruction>("SI_INDIRECT_SRC_"#VecSize) $src, $idx, imm:$offset)
1128 // Insert with offset
1130 (insertelt vt:$src, eltvt:$val, (MOVRELOffset i32:$idx, (i32 imm:$offset))),
1131 (!cast<Instruction>("SI_INDIRECT_DST_"#VecSize) $src, $idx, imm:$offset, $val)
1135 defm : SI_INDIRECT_Pattern <v2f32, f32, "V2">;
1136 defm : SI_INDIRECT_Pattern <v4f32, f32, "V4">;
1137 defm : SI_INDIRECT_Pattern <v8f32, f32, "V8">;
1138 defm : SI_INDIRECT_Pattern <v16f32, f32, "V16">;
1140 defm : SI_INDIRECT_Pattern <v2i32, i32, "V2">;
1141 defm : SI_INDIRECT_Pattern <v4i32, i32, "V4">;
1142 defm : SI_INDIRECT_Pattern <v8i32, i32, "V8">;
1143 defm : SI_INDIRECT_Pattern <v16i32, i32, "V16">;
1145 //===----------------------------------------------------------------------===//
1147 //===----------------------------------------------------------------------===//
1150 (add (sub_oneuse (umax i32:$src0, i32:$src1),
1151 (umin i32:$src0, i32:$src1)),
1153 (V_SAD_U32 $src0, $src1, $src2, (i1 0))
1157 (add (select_oneuse (i1 (setugt i32:$src0, i32:$src1)),
1158 (sub i32:$src0, i32:$src1),
1159 (sub i32:$src1, i32:$src0)),
1161 (V_SAD_U32 $src0, $src1, $src2, (i1 0))
1164 //===----------------------------------------------------------------------===//
1165 // Conversion Patterns
1166 //===----------------------------------------------------------------------===//
1168 def : GCNPat<(i32 (sext_inreg i32:$src, i1)),
1169 (S_BFE_I32 i32:$src, (i32 65536))>; // 0 | 1 << 16
1171 // Handle sext_inreg in i64
1173 (i64 (sext_inreg i64:$src, i1)),
1174 (S_BFE_I64 i64:$src, (i32 0x10000)) // 0 | 1 << 16
1178 (i16 (sext_inreg i16:$src, i1)),
1179 (S_BFE_I32 $src, (i32 0x00010000)) // 0 | 1 << 16
1183 (i16 (sext_inreg i16:$src, i8)),
1184 (S_BFE_I32 $src, (i32 0x80000)) // 0 | 8 << 16
1188 (i64 (sext_inreg i64:$src, i8)),
1189 (S_BFE_I64 i64:$src, (i32 0x80000)) // 0 | 8 << 16
1193 (i64 (sext_inreg i64:$src, i16)),
1194 (S_BFE_I64 i64:$src, (i32 0x100000)) // 0 | 16 << 16
1198 (i64 (sext_inreg i64:$src, i32)),
1199 (S_BFE_I64 i64:$src, (i32 0x200000)) // 0 | 32 << 16
1203 (i64 (zext i32:$src)),
1204 (REG_SEQUENCE SReg_64, $src, sub0, (S_MOV_B32 (i32 0)), sub1)
1208 (i64 (anyext i32:$src)),
1209 (REG_SEQUENCE SReg_64, $src, sub0, (i32 (IMPLICIT_DEF)), sub1)
1212 class ZExt_i64_i1_Pat <SDNode ext> : GCNPat <
1213 (i64 (ext i1:$src)),
1214 (REG_SEQUENCE VReg_64,
1215 (V_CNDMASK_B32_e64 (i32 0), (i32 1), $src), sub0,
1216 (S_MOV_B32 (i32 0)), sub1)
1220 def : ZExt_i64_i1_Pat<zext>;
1221 def : ZExt_i64_i1_Pat<anyext>;
1223 // FIXME: We need to use COPY_TO_REGCLASS to work-around the fact that
1224 // REG_SEQUENCE patterns don't support instructions with multiple outputs.
1226 (i64 (sext i32:$src)),
1227 (REG_SEQUENCE SReg_64, $src, sub0,
1228 (i32 (COPY_TO_REGCLASS (S_ASHR_I32 $src, (i32 31)), SReg_32_XM0)), sub1)
1232 (i64 (sext i1:$src)),
1233 (REG_SEQUENCE VReg_64,
1234 (V_CNDMASK_B32_e64 (i32 0), (i32 -1), $src), sub0,
1235 (V_CNDMASK_B32_e64 (i32 0), (i32 -1), $src), sub1)
1238 class FPToI1Pat<Instruction Inst, int KOne, ValueType kone_type, ValueType vt, SDPatternOperator fp_to_int> : GCNPat <
1239 (i1 (fp_to_int (vt (VOP3Mods vt:$src0, i32:$src0_modifiers)))),
1240 (i1 (Inst 0, (kone_type KOne), $src0_modifiers, $src0, DSTCLAMP.NONE))
1243 def : FPToI1Pat<V_CMP_EQ_F32_e64, CONST.FP32_ONE, i32, f32, fp_to_uint>;
1244 def : FPToI1Pat<V_CMP_EQ_F32_e64, CONST.FP32_NEG_ONE, i32, f32, fp_to_sint>;
1245 def : FPToI1Pat<V_CMP_EQ_F64_e64, CONST.FP64_ONE, i64, f64, fp_to_uint>;
1246 def : FPToI1Pat<V_CMP_EQ_F64_e64, CONST.FP64_NEG_ONE, i64, f64, fp_to_sint>;
1248 // If we need to perform a logical operation on i1 values, we need to
1249 // use vector comparisons since there is only one SCC register. Vector
1250 // comparisons still write to a pair of SGPRs, so treat these as
1251 // 64-bit comparisons. When legalizing SGPR copies, instructions
1252 // resulting in the copies from SCC to these instructions will be
1253 // moved to the VALU.
1255 (i1 (and i1:$src0, i1:$src1)),
1256 (S_AND_B64 $src0, $src1)
1260 (i1 (or i1:$src0, i1:$src1)),
1261 (S_OR_B64 $src0, $src1)
1265 (i1 (xor i1:$src0, i1:$src1)),
1266 (S_XOR_B64 $src0, $src1)
1270 (f32 (sint_to_fp i1:$src)),
1271 (V_CNDMASK_B32_e64 (i32 0), (i32 CONST.FP32_NEG_ONE), $src)
1275 (f32 (uint_to_fp i1:$src)),
1276 (V_CNDMASK_B32_e64 (i32 0), (i32 CONST.FP32_ONE), $src)
1280 (f64 (sint_to_fp i1:$src)),
1281 (V_CVT_F64_I32_e32 (V_CNDMASK_B32_e64 (i32 0), (i32 -1), $src))
1285 (f64 (uint_to_fp i1:$src)),
1286 (V_CVT_F64_U32_e32 (V_CNDMASK_B32_e64 (i32 0), (i32 1), $src))
1289 //===----------------------------------------------------------------------===//
1290 // Miscellaneous Patterns
1291 //===----------------------------------------------------------------------===//
1293 (i32 (AMDGPUfp16_zext f16:$src)),
1299 (i32 (trunc i64:$a)),
1300 (EXTRACT_SUBREG $a, sub0)
1304 (i1 (trunc i32:$a)),
1305 (V_CMP_EQ_U32_e64 (S_AND_B32 (i32 1), $a), (i32 1))
1309 (i1 (trunc i16:$a)),
1310 (V_CMP_EQ_U32_e64 (S_AND_B32 (i32 1), $a), (i32 1))
1314 (i1 (trunc i64:$a)),
1315 (V_CMP_EQ_U32_e64 (S_AND_B32 (i32 1),
1316 (i32 (EXTRACT_SUBREG $a, sub0))), (i32 1))
1320 (i32 (bswap i32:$a)),
1321 (V_BFI_B32 (S_MOV_B32 (i32 0x00ff00ff)),
1322 (V_ALIGNBIT_B32 $a, $a, (i32 24)),
1323 (V_ALIGNBIT_B32 $a, $a, (i32 8)))
1326 let OtherPredicates = [NoFP16Denormals] in {
1328 (fcanonicalize (f16 (VOP3Mods f16:$src, i32:$src_mods))),
1329 (V_MUL_F16_e64 0, (i32 CONST.FP16_ONE), $src_mods, $src, 0, 0)
1333 (fcanonicalize (v2f16 (VOP3PMods v2f16:$src, i32:$src_mods))),
1334 (V_PK_MUL_F16 0, (i32 CONST.V2FP16_ONE), $src_mods, $src, DSTCLAMP.NONE)
1338 let OtherPredicates = [FP16Denormals] in {
1340 (fcanonicalize (f16 (VOP3Mods f16:$src, i32:$src_mods))),
1341 (V_MAX_F16_e64 $src_mods, $src, $src_mods, $src, 0, 0)
1345 (fcanonicalize (v2f16 (VOP3PMods v2f16:$src, i32:$src_mods))),
1346 (V_PK_MAX_F16 $src_mods, $src, $src_mods, $src, DSTCLAMP.NONE)
1350 let OtherPredicates = [NoFP32Denormals] in {
1352 (fcanonicalize (f32 (VOP3Mods f32:$src, i32:$src_mods))),
1353 (V_MUL_F32_e64 0, (i32 CONST.FP32_ONE), $src_mods, $src, 0, 0)
1357 let OtherPredicates = [FP32Denormals] in {
1359 (fcanonicalize (f32 (VOP3Mods f32:$src, i32:$src_mods))),
1360 (V_MAX_F32_e64 $src_mods, $src, $src_mods, $src, 0, 0)
1364 let OtherPredicates = [NoFP64Denormals] in {
1366 (fcanonicalize (f64 (VOP3Mods f64:$src, i32:$src_mods))),
1367 (V_MUL_F64 0, CONST.FP64_ONE, $src_mods, $src, 0, 0)
1371 let OtherPredicates = [FP64Denormals] in {
1373 (fcanonicalize (f64 (VOP3Mods f64:$src, i32:$src_mods))),
1374 (V_MAX_F64 $src_mods, $src, $src_mods, $src, 0, 0)
1379 // Allow integer inputs
1380 class ExpPattern<SDPatternOperator node, ValueType vt, Instruction Inst> : GCNPat<
1381 (node (i8 timm:$tgt), (i8 timm:$en), vt:$src0, vt:$src1, vt:$src2, vt:$src3, (i1 timm:$compr), (i1 timm:$vm)),
1382 (Inst i8:$tgt, vt:$src0, vt:$src1, vt:$src2, vt:$src3, i1:$vm, i1:$compr, i8:$en)
1385 def : ExpPattern<AMDGPUexport, i32, EXP>;
1386 def : ExpPattern<AMDGPUexport_done, i32, EXP_DONE>;
1389 (v2i16 (build_vector i16:$src0, i16:$src1)),
1390 (v2i16 (S_PACK_LL_B32_B16 $src0, $src1))
1393 // COPY_TO_REGCLASS is workaround tablegen bug from multiple outputs
1394 // from S_LSHL_B32's multiple outputs from implicit scc def.
1396 (v2i16 (build_vector (i16 0), i16:$src1)),
1397 (v2i16 (COPY_TO_REGCLASS (S_LSHL_B32 i16:$src1, (i16 16)), SReg_32_XM0))
1400 // With multiple uses of the shift, this will duplicate the shift and
1401 // increase register pressure.
1403 (v2i16 (build_vector i16:$src0, (i16 (trunc (srl_oneuse i32:$src1, (i32 16)))))),
1404 (v2i16 (S_PACK_LH_B32_B16 i16:$src0, i32:$src1))
1408 (v2i16 (build_vector (i16 (trunc (srl_oneuse i32:$src0, (i32 16)))),
1409 (i16 (trunc (srl_oneuse i32:$src1, (i32 16)))))),
1410 (v2i16 (S_PACK_HH_B32_B16 $src0, $src1))
1413 // TODO: Should source modifiers be matched to v_pack_b32_f16?
1415 (v2f16 (build_vector f16:$src0, f16:$src1)),
1416 (v2f16 (S_PACK_LL_B32_B16 $src0, $src1))
1420 // (v2f16 (scalar_to_vector f16:$src0)),
1425 // (v2i16 (scalar_to_vector i16:$src0)),
1429 //===----------------------------------------------------------------------===//
1431 //===----------------------------------------------------------------------===//
1433 let SubtargetPredicate = isSI in {
1435 // V_FRACT is buggy on SI, so the F32 version is never used and (x-floor(x)) is
1436 // used instead. However, SI doesn't have V_FLOOR_F64, so the most efficient
1437 // way to implement it is using V_FRACT_F64.
1438 // The workaround for the V_FRACT bug is:
1439 // fract(x) = isnan(x) ? x : min(V_FRACT(x), 0.99999999999999999)
1441 // Convert floor(x) to (x - fract(x))
1443 (f64 (ffloor (f64 (VOP3Mods f64:$x, i32:$mods)))),
1448 (V_CNDMASK_B64_PSEUDO
1451 (V_FRACT_F64_e64 $mods, $x, DSTCLAMP.NONE, DSTOMOD.NONE),
1453 (V_MOV_B64_PSEUDO 0x3fefffffffffffff),
1454 DSTCLAMP.NONE, DSTOMOD.NONE),
1456 (V_CMP_CLASS_F64_e64 SRCMODS.NONE, $x, (i32 3 /*NaN*/))),
1457 DSTCLAMP.NONE, DSTOMOD.NONE)
1460 } // End SubtargetPredicates = isSI
1462 //============================================================================//
1463 // Miscellaneous Optimization Patterns
1464 //============================================================================//
1466 // Undo sub x, c -> add x, -c canonicalization since c is more likely
1467 // an inline immediate than -c.
1468 // TODO: Also do for 64-bit.
1470 (add i32:$src0, (i32 NegSubInlineConst32:$src1)),
1471 (S_SUB_I32 $src0, NegSubInlineConst32:$src1)
1475 multiclass BFMPatterns <ValueType vt, InstSI BFM, InstSI MOV> {
1477 (vt (shl (vt (add (vt (shl 1, vt:$a)), -1)), vt:$b)),
1482 (vt (add (vt (shl 1, vt:$a)), -1)),
1483 (BFM $a, (MOV (i32 0)))
1487 let SubtargetPredicate = isGCN in {
1489 defm : BFMPatterns <i32, S_BFM_B32, S_MOV_B32>;
1490 // FIXME: defm : BFMPatterns <i64, S_BFM_B64, S_MOV_B64>;
1492 defm : BFEPattern <V_BFE_U32, V_BFE_I32, S_MOV_B32>;
1493 def : SHA256MaPattern <V_BFI_B32, V_XOR_B32_e64>;
1495 def : IntMed3Pat<V_MED3_I32, smax, smax_oneuse, smin_oneuse>;
1496 def : IntMed3Pat<V_MED3_U32, umax, umax_oneuse, umin_oneuse>;
1500 // This matches 16 permutations of
1501 // max(min(x, y), min(max(x, y), z))
1502 class FPMed3Pat<ValueType vt,
1503 Instruction med3Inst> : GCNPat<
1504 (fmaxnum (fminnum_oneuse (VOP3Mods_nnan vt:$src0, i32:$src0_mods),
1505 (VOP3Mods_nnan vt:$src1, i32:$src1_mods)),
1506 (fminnum_oneuse (fmaxnum_oneuse (VOP3Mods_nnan vt:$src0, i32:$src0_mods),
1507 (VOP3Mods_nnan vt:$src1, i32:$src1_mods)),
1508 (vt (VOP3Mods_nnan vt:$src2, i32:$src2_mods)))),
1509 (med3Inst $src0_mods, $src0, $src1_mods, $src1, $src2_mods, $src2, DSTCLAMP.NONE, DSTOMOD.NONE)
1512 class FP16Med3Pat<ValueType vt,
1513 Instruction med3Inst> : GCNPat<
1514 (fmaxnum (fminnum_oneuse (VOP3Mods_nnan vt:$src0, i32:$src0_mods),
1515 (VOP3Mods_nnan vt:$src1, i32:$src1_mods)),
1516 (fminnum_oneuse (fmaxnum_oneuse (VOP3Mods_nnan vt:$src0, i32:$src0_mods),
1517 (VOP3Mods_nnan vt:$src1, i32:$src1_mods)),
1518 (vt (VOP3Mods_nnan vt:$src2, i32:$src2_mods)))),
1519 (med3Inst $src0_mods, $src0, $src1_mods, $src1, $src2_mods, $src2, DSTCLAMP.NONE)
1522 class Int16Med3Pat<Instruction med3Inst,
1523 SDPatternOperator max,
1524 SDPatternOperator max_oneuse,
1525 SDPatternOperator min_oneuse,
1526 ValueType vt = i32> : GCNPat<
1527 (max (min_oneuse vt:$src0, vt:$src1),
1528 (min_oneuse (max_oneuse vt:$src0, vt:$src1), vt:$src2)),
1529 (med3Inst SRCMODS.NONE, $src0, SRCMODS.NONE, $src1, SRCMODS.NONE, $src2, DSTCLAMP.NONE)
1532 def : FPMed3Pat<f32, V_MED3_F32>;
1534 let OtherPredicates = [isGFX9] in {
1535 def : FP16Med3Pat<f16, V_MED3_F16>;
1536 def : Int16Med3Pat<V_MED3_I16, smax, smax_oneuse, smin_oneuse, i16>;
1537 def : Int16Med3Pat<V_MED3_U16, umax, umax_oneuse, umin_oneuse, i16>;
1538 } // End Predicates = [isGFX9]