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 /********** ============================================ **********/
731 /********** Extraction, Insertion, Building and Casting **********/
732 /********** ============================================ **********/
734 foreach Index = 0-2 in {
735 def Extract_Element_v2i32_#Index : Extract_Element <
736 i32, v2i32, Index, !cast<SubRegIndex>(sub#Index)
738 def Insert_Element_v2i32_#Index : Insert_Element <
739 i32, v2i32, Index, !cast<SubRegIndex>(sub#Index)
742 def Extract_Element_v2f32_#Index : Extract_Element <
743 f32, v2f32, Index, !cast<SubRegIndex>(sub#Index)
745 def Insert_Element_v2f32_#Index : Insert_Element <
746 f32, v2f32, Index, !cast<SubRegIndex>(sub#Index)
750 foreach Index = 0-3 in {
751 def Extract_Element_v4i32_#Index : Extract_Element <
752 i32, v4i32, Index, !cast<SubRegIndex>(sub#Index)
754 def Insert_Element_v4i32_#Index : Insert_Element <
755 i32, v4i32, Index, !cast<SubRegIndex>(sub#Index)
758 def Extract_Element_v4f32_#Index : Extract_Element <
759 f32, v4f32, Index, !cast<SubRegIndex>(sub#Index)
761 def Insert_Element_v4f32_#Index : Insert_Element <
762 f32, v4f32, Index, !cast<SubRegIndex>(sub#Index)
766 foreach Index = 0-7 in {
767 def Extract_Element_v8i32_#Index : Extract_Element <
768 i32, v8i32, Index, !cast<SubRegIndex>(sub#Index)
770 def Insert_Element_v8i32_#Index : Insert_Element <
771 i32, v8i32, Index, !cast<SubRegIndex>(sub#Index)
774 def Extract_Element_v8f32_#Index : Extract_Element <
775 f32, v8f32, Index, !cast<SubRegIndex>(sub#Index)
777 def Insert_Element_v8f32_#Index : Insert_Element <
778 f32, v8f32, Index, !cast<SubRegIndex>(sub#Index)
782 foreach Index = 0-15 in {
783 def Extract_Element_v16i32_#Index : Extract_Element <
784 i32, v16i32, Index, !cast<SubRegIndex>(sub#Index)
786 def Insert_Element_v16i32_#Index : Insert_Element <
787 i32, v16i32, Index, !cast<SubRegIndex>(sub#Index)
790 def Extract_Element_v16f32_#Index : Extract_Element <
791 f32, v16f32, Index, !cast<SubRegIndex>(sub#Index)
793 def Insert_Element_v16f32_#Index : Insert_Element <
794 f32, v16f32, Index, !cast<SubRegIndex>(sub#Index)
798 let SubtargetPredicate = isGCN in {
800 // FIXME: Why do only some of these type combinations for SReg and
803 def : BitConvert <i16, f16, VGPR_32>;
804 def : BitConvert <f16, i16, VGPR_32>;
805 def : BitConvert <i16, f16, SReg_32>;
806 def : BitConvert <f16, i16, SReg_32>;
809 def : BitConvert <i32, f32, VGPR_32>;
810 def : BitConvert <f32, i32, VGPR_32>;
811 def : BitConvert <i32, f32, SReg_32>;
812 def : BitConvert <f32, i32, SReg_32>;
813 def : BitConvert <v2i16, i32, SReg_32>;
814 def : BitConvert <i32, v2i16, SReg_32>;
815 def : BitConvert <v2f16, i32, SReg_32>;
816 def : BitConvert <i32, v2f16, SReg_32>;
817 def : BitConvert <v2i16, v2f16, SReg_32>;
818 def : BitConvert <v2f16, v2i16, SReg_32>;
819 def : BitConvert <v2f16, f32, SReg_32>;
820 def : BitConvert <f32, v2f16, SReg_32>;
821 def : BitConvert <v2i16, f32, SReg_32>;
822 def : BitConvert <f32, v2i16, SReg_32>;
825 def : BitConvert <i64, f64, VReg_64>;
826 def : BitConvert <f64, i64, VReg_64>;
827 def : BitConvert <v2i32, v2f32, VReg_64>;
828 def : BitConvert <v2f32, v2i32, VReg_64>;
829 def : BitConvert <i64, v2i32, VReg_64>;
830 def : BitConvert <v2i32, i64, VReg_64>;
831 def : BitConvert <i64, v2f32, VReg_64>;
832 def : BitConvert <v2f32, i64, VReg_64>;
833 def : BitConvert <f64, v2f32, VReg_64>;
834 def : BitConvert <v2f32, f64, VReg_64>;
835 def : BitConvert <f64, v2i32, VReg_64>;
836 def : BitConvert <v2i32, f64, VReg_64>;
837 def : BitConvert <v4i32, v4f32, VReg_128>;
838 def : BitConvert <v4f32, v4i32, VReg_128>;
841 def : BitConvert <v2i64, v4i32, SReg_128>;
842 def : BitConvert <v4i32, v2i64, SReg_128>;
843 def : BitConvert <v2f64, v4f32, VReg_128>;
844 def : BitConvert <v2f64, v4i32, VReg_128>;
845 def : BitConvert <v4f32, v2f64, VReg_128>;
846 def : BitConvert <v4i32, v2f64, VReg_128>;
847 def : BitConvert <v2i64, v2f64, VReg_128>;
848 def : BitConvert <v2f64, v2i64, VReg_128>;
851 def : BitConvert <v8i32, v8f32, SReg_256>;
852 def : BitConvert <v8f32, v8i32, SReg_256>;
853 def : BitConvert <v8i32, v8f32, VReg_256>;
854 def : BitConvert <v8f32, v8i32, VReg_256>;
857 def : BitConvert <v16i32, v16f32, VReg_512>;
858 def : BitConvert <v16f32, v16i32, VReg_512>;
860 } // End SubtargetPredicate = isGCN
862 /********** =================== **********/
863 /********** Src & Dst modifiers **********/
864 /********** =================== **********/
867 // If denormals are not enabled, it only impacts the compare of the
868 // inputs. The output result is not flushed.
869 class ClampPat<Instruction inst, ValueType vt> : GCNPat <
870 (vt (AMDGPUclamp (VOP3Mods vt:$src0, i32:$src0_modifiers))),
871 (inst i32:$src0_modifiers, vt:$src0,
872 i32:$src0_modifiers, vt:$src0, DSTCLAMP.ENABLE, DSTOMOD.NONE)
875 def : ClampPat<V_MAX_F32_e64, f32>;
876 def : ClampPat<V_MAX_F64, f64>;
877 def : ClampPat<V_MAX_F16_e64, f16>;
880 (v2f16 (AMDGPUclamp (VOP3PMods v2f16:$src0, i32:$src0_modifiers))),
881 (V_PK_MAX_F16 $src0_modifiers, $src0,
882 $src0_modifiers, $src0, DSTCLAMP.ENABLE)
885 /********** ================================ **********/
886 /********** Floating point absolute/negative **********/
887 /********** ================================ **********/
889 // Prevent expanding both fneg and fabs.
892 (fneg (fabs f32:$src)),
893 (S_OR_B32 $src, (S_MOV_B32(i32 0x80000000))) // Set sign bit
896 // FIXME: Should use S_OR_B32
898 (fneg (fabs f64:$src)),
899 (REG_SEQUENCE VReg_64,
900 (i32 (EXTRACT_SUBREG f64:$src, sub0)),
902 (V_OR_B32_e32 (i32 (EXTRACT_SUBREG f64:$src, sub1)),
903 (V_MOV_B32_e32 (i32 0x80000000))), // Set sign bit.
909 (V_AND_B32_e64 $src, (V_MOV_B32_e32 (i32 0x7fffffff)))
914 (V_XOR_B32_e32 $src, (V_MOV_B32_e32 (i32 0x80000000)))
919 (REG_SEQUENCE VReg_64,
920 (i32 (EXTRACT_SUBREG f64:$src, sub0)),
922 (V_AND_B32_e64 (i32 (EXTRACT_SUBREG f64:$src, sub1)),
923 (V_MOV_B32_e32 (i32 0x7fffffff))), // Set sign bit.
929 (REG_SEQUENCE VReg_64,
930 (i32 (EXTRACT_SUBREG f64:$src, sub0)),
932 (V_XOR_B32_e32 (i32 (EXTRACT_SUBREG f64:$src, sub1)),
933 (i32 (V_MOV_B32_e32 (i32 0x80000000)))),
938 (fcopysign f16:$src0, f16:$src1),
939 (V_BFI_B32 (S_MOV_B32 (i32 0x00007fff)), $src0, $src1)
943 (fcopysign f32:$src0, f16:$src1),
944 (V_BFI_B32 (S_MOV_B32 (i32 0x7fffffff)), $src0,
945 (V_LSHLREV_B32_e64 (i32 16), $src1))
949 (fcopysign f64:$src0, f16:$src1),
950 (REG_SEQUENCE SReg_64,
951 (i32 (EXTRACT_SUBREG $src0, sub0)), sub0,
952 (V_BFI_B32 (S_MOV_B32 (i32 0x7fffffff)), (i32 (EXTRACT_SUBREG $src0, sub1)),
953 (V_LSHLREV_B32_e64 (i32 16), $src1)), sub1)
957 (fcopysign f16:$src0, f32:$src1),
958 (V_BFI_B32 (S_MOV_B32 (i32 0x00007fff)), $src0,
959 (V_LSHRREV_B32_e64 (i32 16), $src1))
963 (fcopysign f16:$src0, f64:$src1),
964 (V_BFI_B32 (S_MOV_B32 (i32 0x00007fff)), $src0,
965 (V_LSHRREV_B32_e64 (i32 16), (EXTRACT_SUBREG $src1, sub1)))
970 (V_XOR_B32_e32 $src, (V_MOV_B32_e32 (i32 0x00008000)))
975 (V_AND_B32_e64 $src, (V_MOV_B32_e32 (i32 0x00007fff)))
979 (fneg (fabs f16:$src)),
980 (S_OR_B32 $src, (S_MOV_B32 (i32 0x00008000))) // Set sign bit
985 (V_XOR_B32_e64 (S_MOV_B32 (i32 0x80008000)), $src)
990 (V_AND_B32_e64 (S_MOV_B32 (i32 0x7fff7fff)), $src)
993 // This is really (fneg (fabs v2f16:$src))
995 // fabs is not reported as free because there is modifier for it in
996 // VOP3P instructions, so it is turned into the bit op.
998 (fneg (v2f16 (bitconvert (and_oneuse i32:$src, 0x7fff7fff)))),
999 (S_OR_B32 (S_MOV_B32 (i32 0x80008000)), $src) // Set sign bit
1002 /********** ================== **********/
1003 /********** Immediate Patterns **********/
1004 /********** ================== **********/
1007 (VGPRImm<(i32 imm)>:$imm),
1008 (V_MOV_B32_e32 imm:$imm)
1012 (VGPRImm<(f32 fpimm)>:$imm),
1013 (V_MOV_B32_e32 (f32 (bitcast_fpimm_to_i32 $imm)))
1018 (S_MOV_B32 imm:$imm)
1021 // FIXME: Workaround for ordering issue with peephole optimizer where
1022 // a register class copy interferes with immediate folding. Should
1023 // use s_mov_b32, which can be shrunk to s_movk_i32
1025 (VGPRImm<(f16 fpimm)>:$imm),
1026 (V_MOV_B32_e32 (f16 (bitcast_fpimm_to_i32 $imm)))
1031 (S_MOV_B32 (f32 (bitcast_fpimm_to_i32 $imm)))
1036 (S_MOV_B32 (i32 (bitcast_fpimm_to_i32 $imm)))
1040 (i32 frameindex:$fi),
1041 (V_MOV_B32_e32 (i32 (frameindex_to_targetframeindex $fi)))
1045 (i64 InlineImm<i64>:$imm),
1046 (S_MOV_B64 InlineImm<i64>:$imm)
1049 // XXX - Should this use a s_cmp to set SCC?
1051 // Set to sign-extended 64-bit value (true = -1, false = 0)
1054 (S_MOV_B64 (i64 (as_i64imm $imm)))
1058 (f64 InlineFPImm<f64>:$imm),
1059 (S_MOV_B64 (f64 (bitcast_fpimm_to_i64 InlineFPImm<f64>:$imm)))
1062 /********** ================== **********/
1063 /********** Intrinsic Patterns **********/
1064 /********** ================== **********/
1066 let SubtargetPredicate = isGCN in {
1067 def : POW_Common <V_LOG_F32_e32, V_EXP_F32_e32, V_MUL_LEGACY_F32_e32>;
1071 (i32 (sext i1:$src0)),
1072 (V_CNDMASK_B32_e64 (i32 0), (i32 -1), $src0)
1075 class Ext32Pat <SDNode ext> : GCNPat <
1076 (i32 (ext i1:$src0)),
1077 (V_CNDMASK_B32_e64 (i32 0), (i32 1), $src0)
1080 def : Ext32Pat <zext>;
1081 def : Ext32Pat <anyext>;
1083 // The multiplication scales from [0,1] to the unsigned integer range
1085 (AMDGPUurecip i32:$src0),
1087 (V_MUL_F32_e32 (i32 CONST.FP_UINT_MAX_PLUS_1),
1088 (V_RCP_IFLAG_F32_e32 (V_CVT_F32_U32_e32 $src0))))
1091 //===----------------------------------------------------------------------===//
1093 //===----------------------------------------------------------------------===//
1095 let SubtargetPredicate = isGCN in {
1097 def : IMad24Pat<V_MAD_I32_I24, 1>;
1098 def : UMad24Pat<V_MAD_U32_U24, 1>;
1100 defm : BFIPatterns <V_BFI_B32, S_MOV_B32, SReg_64>;
1101 def : ROTRPattern <V_ALIGNBIT_B32>;
1105 def : GCNPat<(i32 (trunc (srl i64:$src0, (and i32:$src1, (i32 31))))),
1106 (V_ALIGNBIT_B32 (i32 (EXTRACT_SUBREG (i64 $src0), sub1)),
1107 (i32 (EXTRACT_SUBREG (i64 $src0), sub0)), $src1)>;
1109 def : GCNPat<(i32 (trunc (srl i64:$src0, (i32 ShiftAmt32Imm:$src1)))),
1110 (V_ALIGNBIT_B32 (i32 (EXTRACT_SUBREG (i64 $src0), sub1)),
1111 (i32 (EXTRACT_SUBREG (i64 $src0), sub0)), $src1)>;
1113 /********** ====================== **********/
1114 /********** Indirect addressing **********/
1115 /********** ====================== **********/
1117 multiclass SI_INDIRECT_Pattern <ValueType vt, ValueType eltvt, string VecSize> {
1118 // Extract with offset
1120 (eltvt (extractelt vt:$src, (MOVRELOffset i32:$idx, (i32 imm:$offset)))),
1121 (!cast<Instruction>("SI_INDIRECT_SRC_"#VecSize) $src, $idx, imm:$offset)
1124 // Insert with offset
1126 (insertelt vt:$src, eltvt:$val, (MOVRELOffset i32:$idx, (i32 imm:$offset))),
1127 (!cast<Instruction>("SI_INDIRECT_DST_"#VecSize) $src, $idx, imm:$offset, $val)
1131 defm : SI_INDIRECT_Pattern <v2f32, f32, "V2">;
1132 defm : SI_INDIRECT_Pattern <v4f32, f32, "V4">;
1133 defm : SI_INDIRECT_Pattern <v8f32, f32, "V8">;
1134 defm : SI_INDIRECT_Pattern <v16f32, f32, "V16">;
1136 defm : SI_INDIRECT_Pattern <v2i32, i32, "V2">;
1137 defm : SI_INDIRECT_Pattern <v4i32, i32, "V4">;
1138 defm : SI_INDIRECT_Pattern <v8i32, i32, "V8">;
1139 defm : SI_INDIRECT_Pattern <v16i32, i32, "V16">;
1141 //===----------------------------------------------------------------------===//
1143 //===----------------------------------------------------------------------===//
1146 (add (sub_oneuse (umax i32:$src0, i32:$src1),
1147 (umin i32:$src0, i32:$src1)),
1149 (V_SAD_U32 $src0, $src1, $src2, (i1 0))
1153 (add (select_oneuse (i1 (setugt i32:$src0, i32:$src1)),
1154 (sub i32:$src0, i32:$src1),
1155 (sub i32:$src1, i32:$src0)),
1157 (V_SAD_U32 $src0, $src1, $src2, (i1 0))
1160 //===----------------------------------------------------------------------===//
1161 // Conversion Patterns
1162 //===----------------------------------------------------------------------===//
1164 def : GCNPat<(i32 (sext_inreg i32:$src, i1)),
1165 (S_BFE_I32 i32:$src, (i32 65536))>; // 0 | 1 << 16
1167 // Handle sext_inreg in i64
1169 (i64 (sext_inreg i64:$src, i1)),
1170 (S_BFE_I64 i64:$src, (i32 0x10000)) // 0 | 1 << 16
1174 (i16 (sext_inreg i16:$src, i1)),
1175 (S_BFE_I32 $src, (i32 0x00010000)) // 0 | 1 << 16
1179 (i16 (sext_inreg i16:$src, i8)),
1180 (S_BFE_I32 $src, (i32 0x80000)) // 0 | 8 << 16
1184 (i64 (sext_inreg i64:$src, i8)),
1185 (S_BFE_I64 i64:$src, (i32 0x80000)) // 0 | 8 << 16
1189 (i64 (sext_inreg i64:$src, i16)),
1190 (S_BFE_I64 i64:$src, (i32 0x100000)) // 0 | 16 << 16
1194 (i64 (sext_inreg i64:$src, i32)),
1195 (S_BFE_I64 i64:$src, (i32 0x200000)) // 0 | 32 << 16
1199 (i64 (zext i32:$src)),
1200 (REG_SEQUENCE SReg_64, $src, sub0, (S_MOV_B32 (i32 0)), sub1)
1204 (i64 (anyext i32:$src)),
1205 (REG_SEQUENCE SReg_64, $src, sub0, (i32 (IMPLICIT_DEF)), sub1)
1208 class ZExt_i64_i1_Pat <SDNode ext> : GCNPat <
1209 (i64 (ext i1:$src)),
1210 (REG_SEQUENCE VReg_64,
1211 (V_CNDMASK_B32_e64 (i32 0), (i32 1), $src), sub0,
1212 (S_MOV_B32 (i32 0)), sub1)
1216 def : ZExt_i64_i1_Pat<zext>;
1217 def : ZExt_i64_i1_Pat<anyext>;
1219 // FIXME: We need to use COPY_TO_REGCLASS to work-around the fact that
1220 // REG_SEQUENCE patterns don't support instructions with multiple outputs.
1222 (i64 (sext i32:$src)),
1223 (REG_SEQUENCE SReg_64, $src, sub0,
1224 (i32 (COPY_TO_REGCLASS (S_ASHR_I32 $src, (i32 31)), SReg_32_XM0)), sub1)
1228 (i64 (sext i1:$src)),
1229 (REG_SEQUENCE VReg_64,
1230 (V_CNDMASK_B32_e64 (i32 0), (i32 -1), $src), sub0,
1231 (V_CNDMASK_B32_e64 (i32 0), (i32 -1), $src), sub1)
1234 class FPToI1Pat<Instruction Inst, int KOne, ValueType kone_type, ValueType vt, SDPatternOperator fp_to_int> : GCNPat <
1235 (i1 (fp_to_int (vt (VOP3Mods vt:$src0, i32:$src0_modifiers)))),
1236 (i1 (Inst 0, (kone_type KOne), $src0_modifiers, $src0, DSTCLAMP.NONE))
1239 def : FPToI1Pat<V_CMP_EQ_F32_e64, CONST.FP32_ONE, i32, f32, fp_to_uint>;
1240 def : FPToI1Pat<V_CMP_EQ_F32_e64, CONST.FP32_NEG_ONE, i32, f32, fp_to_sint>;
1241 def : FPToI1Pat<V_CMP_EQ_F64_e64, CONST.FP64_ONE, i64, f64, fp_to_uint>;
1242 def : FPToI1Pat<V_CMP_EQ_F64_e64, CONST.FP64_NEG_ONE, i64, f64, fp_to_sint>;
1244 // If we need to perform a logical operation on i1 values, we need to
1245 // use vector comparisons since there is only one SCC register. Vector
1246 // comparisons still write to a pair of SGPRs, so treat these as
1247 // 64-bit comparisons. When legalizing SGPR copies, instructions
1248 // resulting in the copies from SCC to these instructions will be
1249 // moved to the VALU.
1251 (i1 (and i1:$src0, i1:$src1)),
1252 (S_AND_B64 $src0, $src1)
1256 (i1 (or i1:$src0, i1:$src1)),
1257 (S_OR_B64 $src0, $src1)
1261 (i1 (xor i1:$src0, i1:$src1)),
1262 (S_XOR_B64 $src0, $src1)
1266 (f32 (sint_to_fp i1:$src)),
1267 (V_CNDMASK_B32_e64 (i32 0), (i32 CONST.FP32_NEG_ONE), $src)
1271 (f32 (uint_to_fp i1:$src)),
1272 (V_CNDMASK_B32_e64 (i32 0), (i32 CONST.FP32_ONE), $src)
1276 (f64 (sint_to_fp i1:$src)),
1277 (V_CVT_F64_I32_e32 (V_CNDMASK_B32_e64 (i32 0), (i32 -1), $src))
1281 (f64 (uint_to_fp i1:$src)),
1282 (V_CVT_F64_U32_e32 (V_CNDMASK_B32_e64 (i32 0), (i32 1), $src))
1285 //===----------------------------------------------------------------------===//
1286 // Miscellaneous Patterns
1287 //===----------------------------------------------------------------------===//
1289 (i32 (AMDGPUfp16_zext f16:$src)),
1295 (i32 (trunc i64:$a)),
1296 (EXTRACT_SUBREG $a, sub0)
1300 (i1 (trunc i32:$a)),
1301 (V_CMP_EQ_U32_e64 (S_AND_B32 (i32 1), $a), (i32 1))
1305 (i1 (trunc i16:$a)),
1306 (V_CMP_EQ_U32_e64 (S_AND_B32 (i32 1), $a), (i32 1))
1310 (i1 (trunc i64:$a)),
1311 (V_CMP_EQ_U32_e64 (S_AND_B32 (i32 1),
1312 (i32 (EXTRACT_SUBREG $a, sub0))), (i32 1))
1316 (i32 (bswap i32:$a)),
1317 (V_BFI_B32 (S_MOV_B32 (i32 0x00ff00ff)),
1318 (V_ALIGNBIT_B32 $a, $a, (i32 24)),
1319 (V_ALIGNBIT_B32 $a, $a, (i32 8)))
1322 let OtherPredicates = [NoFP16Denormals] in {
1324 (fcanonicalize (f16 (VOP3Mods f16:$src, i32:$src_mods))),
1325 (V_MUL_F16_e64 0, (i32 CONST.FP16_ONE), $src_mods, $src, 0, 0)
1329 (fcanonicalize (v2f16 (VOP3PMods v2f16:$src, i32:$src_mods))),
1330 (V_PK_MUL_F16 0, (i32 CONST.V2FP16_ONE), $src_mods, $src, DSTCLAMP.NONE)
1334 let OtherPredicates = [FP16Denormals] in {
1336 (fcanonicalize (f16 (VOP3Mods f16:$src, i32:$src_mods))),
1337 (V_MAX_F16_e64 $src_mods, $src, $src_mods, $src, 0, 0)
1341 (fcanonicalize (v2f16 (VOP3PMods v2f16:$src, i32:$src_mods))),
1342 (V_PK_MAX_F16 $src_mods, $src, $src_mods, $src, DSTCLAMP.NONE)
1346 let OtherPredicates = [NoFP32Denormals] in {
1348 (fcanonicalize (f32 (VOP3Mods f32:$src, i32:$src_mods))),
1349 (V_MUL_F32_e64 0, (i32 CONST.FP32_ONE), $src_mods, $src, 0, 0)
1353 let OtherPredicates = [FP32Denormals] in {
1355 (fcanonicalize (f32 (VOP3Mods f32:$src, i32:$src_mods))),
1356 (V_MAX_F32_e64 $src_mods, $src, $src_mods, $src, 0, 0)
1360 let OtherPredicates = [NoFP64Denormals] in {
1362 (fcanonicalize (f64 (VOP3Mods f64:$src, i32:$src_mods))),
1363 (V_MUL_F64 0, CONST.FP64_ONE, $src_mods, $src, 0, 0)
1367 let OtherPredicates = [FP64Denormals] in {
1369 (fcanonicalize (f64 (VOP3Mods f64:$src, i32:$src_mods))),
1370 (V_MAX_F64 $src_mods, $src, $src_mods, $src, 0, 0)
1375 // Allow integer inputs
1376 class ExpPattern<SDPatternOperator node, ValueType vt, Instruction Inst> : GCNPat<
1377 (node (i8 timm:$tgt), (i8 timm:$en), vt:$src0, vt:$src1, vt:$src2, vt:$src3, (i1 timm:$compr), (i1 timm:$vm)),
1378 (Inst i8:$tgt, vt:$src0, vt:$src1, vt:$src2, vt:$src3, i1:$vm, i1:$compr, i8:$en)
1381 def : ExpPattern<AMDGPUexport, i32, EXP>;
1382 def : ExpPattern<AMDGPUexport_done, i32, EXP_DONE>;
1385 (v2i16 (build_vector i16:$src0, i16:$src1)),
1386 (v2i16 (S_PACK_LL_B32_B16 $src0, $src1))
1389 // COPY_TO_REGCLASS is workaround tablegen bug from multiple outputs
1390 // from S_LSHL_B32's multiple outputs from implicit scc def.
1392 (v2i16 (build_vector (i16 0), i16:$src1)),
1393 (v2i16 (COPY_TO_REGCLASS (S_LSHL_B32 i16:$src1, (i16 16)), SReg_32_XM0))
1396 // With multiple uses of the shift, this will duplicate the shift and
1397 // increase register pressure.
1399 (v2i16 (build_vector i16:$src0, (i16 (trunc (srl_oneuse i32:$src1, (i32 16)))))),
1400 (v2i16 (S_PACK_LH_B32_B16 i16:$src0, i32:$src1))
1404 (v2i16 (build_vector (i16 (trunc (srl_oneuse i32:$src0, (i32 16)))),
1405 (i16 (trunc (srl_oneuse i32:$src1, (i32 16)))))),
1406 (v2i16 (S_PACK_HH_B32_B16 $src0, $src1))
1409 // TODO: Should source modifiers be matched to v_pack_b32_f16?
1411 (v2f16 (build_vector f16:$src0, f16:$src1)),
1412 (v2f16 (S_PACK_LL_B32_B16 $src0, $src1))
1416 // (v2f16 (scalar_to_vector f16:$src0)),
1421 // (v2i16 (scalar_to_vector i16:$src0)),
1425 //===----------------------------------------------------------------------===//
1427 //===----------------------------------------------------------------------===//
1429 let SubtargetPredicate = isSI in {
1431 // V_FRACT is buggy on SI, so the F32 version is never used and (x-floor(x)) is
1432 // used instead. However, SI doesn't have V_FLOOR_F64, so the most efficient
1433 // way to implement it is using V_FRACT_F64.
1434 // The workaround for the V_FRACT bug is:
1435 // fract(x) = isnan(x) ? x : min(V_FRACT(x), 0.99999999999999999)
1437 // Convert floor(x) to (x - fract(x))
1439 (f64 (ffloor (f64 (VOP3Mods f64:$x, i32:$mods)))),
1444 (V_CNDMASK_B64_PSEUDO
1447 (V_FRACT_F64_e64 $mods, $x, DSTCLAMP.NONE, DSTOMOD.NONE),
1449 (V_MOV_B64_PSEUDO 0x3fefffffffffffff),
1450 DSTCLAMP.NONE, DSTOMOD.NONE),
1452 (V_CMP_CLASS_F64_e64 SRCMODS.NONE, $x, (i32 3 /*NaN*/))),
1453 DSTCLAMP.NONE, DSTOMOD.NONE)
1456 } // End SubtargetPredicates = isSI
1458 //============================================================================//
1459 // Miscellaneous Optimization Patterns
1460 //============================================================================//
1462 // Undo sub x, c -> add x, -c canonicalization since c is more likely
1463 // an inline immediate than -c.
1464 // TODO: Also do for 64-bit.
1466 (add i32:$src0, (i32 NegSubInlineConst32:$src1)),
1467 (S_SUB_I32 $src0, NegSubInlineConst32:$src1)
1471 multiclass BFMPatterns <ValueType vt, InstSI BFM, InstSI MOV> {
1473 (vt (shl (vt (add (vt (shl 1, vt:$a)), -1)), vt:$b)),
1478 (vt (add (vt (shl 1, vt:$a)), -1)),
1479 (BFM $a, (MOV (i32 0)))
1483 let SubtargetPredicate = isGCN in {
1485 defm : BFMPatterns <i32, S_BFM_B32, S_MOV_B32>;
1486 // FIXME: defm : BFMPatterns <i64, S_BFM_B64, S_MOV_B64>;
1488 defm : BFEPattern <V_BFE_U32, V_BFE_I32, S_MOV_B32>;
1489 def : SHA256MaPattern <V_BFI_B32, V_XOR_B32_e64>;
1491 def : IntMed3Pat<V_MED3_I32, smax, smax_oneuse, smin_oneuse>;
1492 def : IntMed3Pat<V_MED3_U32, umax, umax_oneuse, umin_oneuse>;
1496 // This matches 16 permutations of
1497 // max(min(x, y), min(max(x, y), z))
1498 class FPMed3Pat<ValueType vt,
1499 Instruction med3Inst> : GCNPat<
1500 (fmaxnum (fminnum_oneuse (VOP3Mods_nnan vt:$src0, i32:$src0_mods),
1501 (VOP3Mods_nnan vt:$src1, i32:$src1_mods)),
1502 (fminnum_oneuse (fmaxnum_oneuse (VOP3Mods_nnan vt:$src0, i32:$src0_mods),
1503 (VOP3Mods_nnan vt:$src1, i32:$src1_mods)),
1504 (vt (VOP3Mods_nnan vt:$src2, i32:$src2_mods)))),
1505 (med3Inst $src0_mods, $src0, $src1_mods, $src1, $src2_mods, $src2, DSTCLAMP.NONE, DSTOMOD.NONE)
1508 class FP16Med3Pat<ValueType vt,
1509 Instruction med3Inst> : GCNPat<
1510 (fmaxnum (fminnum_oneuse (VOP3Mods_nnan vt:$src0, i32:$src0_mods),
1511 (VOP3Mods_nnan vt:$src1, i32:$src1_mods)),
1512 (fminnum_oneuse (fmaxnum_oneuse (VOP3Mods_nnan vt:$src0, i32:$src0_mods),
1513 (VOP3Mods_nnan vt:$src1, i32:$src1_mods)),
1514 (vt (VOP3Mods_nnan vt:$src2, i32:$src2_mods)))),
1515 (med3Inst $src0_mods, $src0, $src1_mods, $src1, $src2_mods, $src2, DSTCLAMP.NONE)
1518 class Int16Med3Pat<Instruction med3Inst,
1519 SDPatternOperator max,
1520 SDPatternOperator max_oneuse,
1521 SDPatternOperator min_oneuse,
1522 ValueType vt = i32> : GCNPat<
1523 (max (min_oneuse vt:$src0, vt:$src1),
1524 (min_oneuse (max_oneuse vt:$src0, vt:$src1), vt:$src2)),
1525 (med3Inst SRCMODS.NONE, $src0, SRCMODS.NONE, $src1, SRCMODS.NONE, $src2, DSTCLAMP.NONE)
1528 def : FPMed3Pat<f32, V_MED3_F32>;
1530 let OtherPredicates = [isGFX9] in {
1531 def : FP16Med3Pat<f16, V_MED3_F16>;
1532 def : Int16Med3Pat<V_MED3_I16, smax, smax_oneuse, smin_oneuse, i16>;
1533 def : Int16Med3Pat<V_MED3_U16, umax, umax_oneuse, umin_oneuse, i16>;
1534 } // End Predicates = [isGFX9]