1 //===-- SIInstructions.td - SI Instruction Defintions ---------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
8 // This file was originally auto-generated from a GPU register header file and
9 // all the instruction definitions were originally commented out. Instructions
10 // that are not yet supported remain commented out.
11 //===----------------------------------------------------------------------===//
13 class GCNPat<dag pattern, dag result> : Pat<pattern, result>, GCNPredicateControl {
17 include "SOPInstructions.td"
18 include "VOPInstructions.td"
19 include "SMInstructions.td"
20 include "FLATInstructions.td"
21 include "BUFInstructions.td"
23 //===----------------------------------------------------------------------===//
25 //===----------------------------------------------------------------------===//
27 defm EXP : EXP_m<0, AMDGPUexport>;
28 defm EXP_DONE : EXP_m<1, AMDGPUexport_done>;
30 //===----------------------------------------------------------------------===//
31 // VINTRP Instructions
32 //===----------------------------------------------------------------------===//
34 // Used to inject printing of "_e32" suffix for VI (there are "_e64" variants for VI)
35 def VINTRPDst : VINTRPDstOperand <VGPR_32>;
37 let Uses = [M0, EXEC] in {
39 // FIXME: Specify SchedRW for VINTRP insturctions.
41 multiclass V_INTERP_P1_F32_m : VINTRP_m <
43 (outs VINTRPDst:$vdst),
44 (ins VGPR_32:$vsrc, Attr:$attr, AttrChan:$attrchan),
45 "v_interp_p1_f32$vdst, $vsrc, $attr$attrchan",
46 [(set f32:$vdst, (AMDGPUinterp_p1 f32:$vsrc, (i32 timm:$attrchan),
50 let OtherPredicates = [has32BankLDS] in {
52 defm V_INTERP_P1_F32 : V_INTERP_P1_F32_m;
54 } // End OtherPredicates = [has32BankLDS]
56 let OtherPredicates = [has16BankLDS], Constraints = "@earlyclobber $vdst", isAsmParserOnly=1 in {
58 defm V_INTERP_P1_F32_16bank : V_INTERP_P1_F32_m;
60 } // End OtherPredicates = [has32BankLDS], Constraints = "@earlyclobber $vdst", isAsmParserOnly=1
62 let DisableEncoding = "$src0", Constraints = "$src0 = $vdst" in {
64 defm V_INTERP_P2_F32 : VINTRP_m <
66 (outs VINTRPDst:$vdst),
67 (ins VGPR_32:$src0, VGPR_32:$vsrc, Attr:$attr, AttrChan:$attrchan),
68 "v_interp_p2_f32$vdst, $vsrc, $attr$attrchan",
69 [(set f32:$vdst, (AMDGPUinterp_p2 f32:$src0, f32:$vsrc, (i32 timm:$attrchan),
72 } // End DisableEncoding = "$src0", Constraints = "$src0 = $vdst"
74 defm V_INTERP_MOV_F32 : VINTRP_m <
76 (outs VINTRPDst:$vdst),
77 (ins InterpSlot:$vsrc, Attr:$attr, AttrChan:$attrchan),
78 "v_interp_mov_f32$vdst, $vsrc, $attr$attrchan",
79 [(set f32:$vdst, (AMDGPUinterp_mov (i32 imm:$vsrc), (i32 timm:$attrchan),
82 } // End Uses = [M0, EXEC]
84 //===----------------------------------------------------------------------===//
85 // Pseudo Instructions
86 //===----------------------------------------------------------------------===//
87 def ATOMIC_FENCE : SPseudoInstSI<
88 (outs), (ins i32imm:$ordering, i32imm:$scope),
89 [(atomic_fence (i32 imm:$ordering), (i32 imm:$scope))],
90 "ATOMIC_FENCE $ordering, $scope"> {
91 let hasSideEffects = 1;
95 let hasSideEffects = 0, mayLoad = 0, mayStore = 0, Uses = [EXEC] in {
97 // For use in patterns
98 def V_CNDMASK_B64_PSEUDO : VOP3Common <(outs VReg_64:$vdst),
99 (ins VSrc_b64:$src0, VSrc_b64:$src1, SSrc_b64:$src2), "", []> {
101 let isCodeGenOnly = 1;
102 let usesCustomInserter = 1;
105 // 64-bit vector move instruction. This is mainly used by the
106 // SIFoldOperands pass to enable folding of inline immediates.
107 def V_MOV_B64_PSEUDO : VPseudoInstSI <(outs VReg_64:$vdst),
108 (ins VSrc_b64:$src0)>;
110 // Pseudoinstruction for @llvm.amdgcn.wqm. It is turned into a copy after the
111 // WQM pass processes it.
112 def WQM : PseudoInstSI <(outs unknown:$vdst), (ins unknown:$src0)>;
114 // Pseudoinstruction for @llvm.amdgcn.softwqm. Like @llvm.amdgcn.wqm it is
115 // turned into a copy by WQM pass, but does not seed WQM requirements.
116 def SOFT_WQM : PseudoInstSI <(outs unknown:$vdst), (ins unknown:$src0)>;
118 // Pseudoinstruction for @llvm.amdgcn.wwm. It is turned into a copy post-RA, so
119 // that the @earlyclobber is respected. The @earlyclobber is to make sure that
120 // the instruction that defines $src0 (which is run in WWM) doesn't
121 // accidentally clobber inactive channels of $vdst.
122 let Constraints = "@earlyclobber $vdst" in {
123 def WWM : PseudoInstSI <(outs unknown:$vdst), (ins unknown:$src0)>;
126 } // End let hasSideEffects = 0, mayLoad = 0, mayStore = 0, Uses = [EXEC]
128 def ENTER_WWM : SPseudoInstSI <(outs SReg_1:$sdst), (ins i64imm:$src0)> {
130 let hasSideEffects = 0;
135 def EXIT_WWM : SPseudoInstSI <(outs SReg_1:$sdst), (ins SReg_1:$src0)> {
136 let hasSideEffects = 0;
141 // Invert the exec mask and overwrite the inactive lanes of dst with inactive,
142 // restoring it after we're done.
143 def V_SET_INACTIVE_B32 : VPseudoInstSI <(outs VGPR_32:$vdst),
144 (ins VGPR_32: $src, VSrc_b32:$inactive),
145 [(set i32:$vdst, (int_amdgcn_set_inactive i32:$src, i32:$inactive))]> {
146 let Constraints = "$src = $vdst";
149 def V_SET_INACTIVE_B64 : VPseudoInstSI <(outs VReg_64:$vdst),
150 (ins VReg_64: $src, VSrc_b64:$inactive),
151 [(set i64:$vdst, (int_amdgcn_set_inactive i64:$src, i64:$inactive))]> {
152 let Constraints = "$src = $vdst";
156 let usesCustomInserter = 1, Defs = [SCC] in {
157 def S_ADD_U64_PSEUDO : SPseudoInstSI <
158 (outs SReg_64:$vdst), (ins SSrc_b64:$src0, SSrc_b64:$src1),
159 [(set SReg_64:$vdst, (add i64:$src0, i64:$src1))]
162 def S_SUB_U64_PSEUDO : SPseudoInstSI <
163 (outs SReg_64:$vdst), (ins SSrc_b64:$src0, SSrc_b64:$src1),
164 [(set SReg_64:$vdst, (sub i64:$src0, i64:$src1))]
167 def S_ADD_U64_CO_PSEUDO : SPseudoInstSI <
168 (outs SReg_64:$vdst, VOPDstS64orS32:$sdst), (ins SSrc_b64:$src0, SSrc_b64:$src1)
171 def S_SUB_U64_CO_PSEUDO : SPseudoInstSI <
172 (outs SReg_64:$vdst, VOPDstS64orS32:$sdst), (ins SSrc_b64:$src0, SSrc_b64:$src1)
174 } // End usesCustomInserter = 1, Defs = [SCC]
176 let usesCustomInserter = 1 in {
177 def GET_GROUPSTATICSIZE : SPseudoInstSI <(outs SReg_32:$sdst), (ins),
178 [(set SReg_32:$sdst, (int_amdgcn_groupstaticsize))]>;
179 } // End let usesCustomInserter = 1, SALU = 1
181 // Wrap an instruction by duplicating it, except for setting isTerminator.
182 class WrapTerminatorInst<SOP_Pseudo base_inst> : SPseudoInstSI<
183 base_inst.OutOperandList,
184 base_inst.InOperandList> {
185 let Uses = base_inst.Uses;
186 let Defs = base_inst.Defs;
187 let isTerminator = 1;
188 let isAsCheapAsAMove = base_inst.isAsCheapAsAMove;
189 let hasSideEffects = base_inst.hasSideEffects;
190 let UseNamedOperandTable = base_inst.UseNamedOperandTable;
191 let CodeSize = base_inst.CodeSize;
194 let WaveSizePredicate = isWave64 in {
195 def S_MOV_B64_term : WrapTerminatorInst<S_MOV_B64>;
196 def S_XOR_B64_term : WrapTerminatorInst<S_XOR_B64>;
197 def S_ANDN2_B64_term : WrapTerminatorInst<S_ANDN2_B64>;
200 let WaveSizePredicate = isWave32 in {
201 def S_MOV_B32_term : WrapTerminatorInst<S_MOV_B32>;
202 def S_XOR_B32_term : WrapTerminatorInst<S_XOR_B32>;
203 def S_OR_B32_term : WrapTerminatorInst<S_OR_B32>;
204 def S_ANDN2_B32_term : WrapTerminatorInst<S_ANDN2_B32>;
207 def WAVE_BARRIER : SPseudoInstSI<(outs), (ins),
208 [(int_amdgcn_wave_barrier)]> {
210 let hasNoSchedulingInfo = 1;
211 let hasSideEffects = 1;
214 let isConvergent = 1;
219 // SI pseudo instructions. These are used by the CFG structurizer pass
220 // and should be lowered to ISA instructions prior to codegen.
222 // Dummy terminator instruction to use after control flow instructions
223 // replaced with exec mask operations.
224 def SI_MASK_BRANCH : VPseudoInstSI <
225 (outs), (ins brtarget:$target)> {
227 let isTerminator = 1;
230 let hasNoSchedulingInfo = 1;
235 let isTerminator = 1 in {
237 let OtherPredicates = [EnableLateCFGStructurize] in {
238 def SI_NON_UNIFORM_BRCOND_PSEUDO : CFPseudoInstSI <
240 (ins SReg_1:$vcc, brtarget:$target),
241 [(brcond i1:$vcc, bb:$target)]> {
246 def SI_IF: CFPseudoInstSI <
247 (outs SReg_1:$dst), (ins SReg_1:$vcc, brtarget:$target),
248 [(set i1:$dst, (AMDGPUif i1:$vcc, bb:$target))], 1, 1> {
249 let Constraints = "";
251 let hasSideEffects = 1;
254 def SI_ELSE : CFPseudoInstSI <
256 (ins SReg_1:$src, brtarget:$target, i1imm:$execfix), [], 1, 1> {
258 let hasSideEffects = 1;
261 def SI_LOOP : CFPseudoInstSI <
262 (outs), (ins SReg_1:$saved, brtarget:$target),
263 [(AMDGPUloop i1:$saved, bb:$target)], 1, 1> {
266 let hasSideEffects = 1;
269 } // End isTerminator = 1
271 def SI_END_CF : CFPseudoInstSI <
272 (outs), (ins SReg_1:$saved), [], 1, 1> {
274 let isAsCheapAsAMove = 1;
275 let isReMaterializable = 1;
276 let hasSideEffects = 1;
277 let mayLoad = 1; // FIXME: Should not need memory flags
281 def SI_IF_BREAK : CFPseudoInstSI <
282 (outs SReg_1:$dst), (ins SReg_1:$vcc, SReg_1:$src), []> {
284 let isAsCheapAsAMove = 1;
285 let isReMaterializable = 1;
288 let Uses = [EXEC] in {
290 multiclass PseudoInstKill <dag ins> {
291 // Even though this pseudo can usually be expanded without an SCC def, we
292 // conservatively assume that it has an SCC def, both because it is sometimes
293 // required in degenerate cases (when V_CMPX cannot be used due to constant
294 // bus limitations) and because it allows us to avoid having to track SCC
295 // liveness across basic blocks.
296 let Defs = [EXEC,VCC,SCC] in
297 def _PSEUDO : PseudoInstSI <(outs), ins> {
298 let isConvergent = 1;
299 let usesCustomInserter = 1;
302 let Defs = [EXEC,VCC,SCC] in
303 def _TERMINATOR : SPseudoInstSI <(outs), ins> {
304 let isTerminator = 1;
308 defm SI_KILL_I1 : PseudoInstKill <(ins SCSrc_i1:$src, i1imm:$killvalue)>;
309 defm SI_KILL_F32_COND_IMM : PseudoInstKill <(ins VSrc_b32:$src0, i32imm:$src1, i32imm:$cond)>;
311 let Defs = [EXEC,VCC] in
312 def SI_ILLEGAL_COPY : SPseudoInstSI <
313 (outs unknown:$dst), (ins unknown:$src),
314 [], " ; illegal copy $src to $dst">;
316 } // End Uses = [EXEC], Defs = [EXEC,VCC]
318 // Branch on undef scc. Used to avoid intermediate copy from
319 // IMPLICIT_DEF to SCC.
320 def SI_BR_UNDEF : SPseudoInstSI <(outs), (ins sopp_brtarget:$simm16)> {
321 let isTerminator = 1;
322 let usesCustomInserter = 1;
326 def SI_PS_LIVE : PseudoInstSI <
327 (outs SReg_1:$dst), (ins),
328 [(set i1:$dst, (int_amdgcn_ps_live))]> {
332 def SI_MASKED_UNREACHABLE : SPseudoInstSI <(outs), (ins),
333 [(int_amdgcn_unreachable)],
334 "; divergent unreachable"> {
336 let hasNoSchedulingInfo = 1;
340 // Used as an isel pseudo to directly emit initialization with an
341 // s_mov_b32 rather than a copy of another initialized
342 // register. MachineCSE skips copies, and we don't want to have to
343 // fold operands before it runs.
344 def SI_INIT_M0 : SPseudoInstSI <(outs), (ins SSrc_b32:$src)> {
346 let usesCustomInserter = 1;
347 let isAsCheapAsAMove = 1;
348 let isReMaterializable = 1;
351 def SI_INIT_EXEC : SPseudoInstSI <
352 (outs), (ins i64imm:$src), []> {
354 let usesCustomInserter = 1;
355 let isAsCheapAsAMove = 1;
356 let WaveSizePredicate = isWave64;
359 // FIXME: Intrinsic should be mangled for wave size.
360 def SI_INIT_EXEC_LO : SPseudoInstSI <
361 (outs), (ins i32imm:$src), []> {
362 let Defs = [EXEC_LO];
363 let usesCustomInserter = 1;
364 let isAsCheapAsAMove = 1;
365 let WaveSizePredicate = isWave32;
368 def SI_INIT_EXEC_FROM_INPUT : SPseudoInstSI <
369 (outs), (ins SSrc_b32:$input, i32imm:$shift), []> {
371 let usesCustomInserter = 1;
374 // Return for returning shaders to a shader variant epilog.
375 def SI_RETURN_TO_EPILOG : SPseudoInstSI <
376 (outs), (ins variable_ops), [(AMDGPUreturn_to_epilog)]> {
377 let isTerminator = 1;
380 let hasNoSchedulingInfo = 1;
385 // Return for returning function calls.
386 def SI_RETURN : SPseudoInstSI <
389 let isTerminator = 1;
392 let SchedRW = [WriteBranch];
395 // Return for returning function calls without output register.
397 // This version is only needed so we can fill in the output regiter in
398 // the custom inserter.
399 def SI_CALL_ISEL : SPseudoInstSI <
400 (outs), (ins SSrc_b64:$src0, unknown:$callee),
401 [(AMDGPUcall i64:$src0, tglobaladdr:$callee)]> {
404 let SchedRW = [WriteBranch];
405 let usesCustomInserter = 1;
406 // TODO: Should really base this on the call target
407 let isConvergent = 1;
410 // Wrapper around s_swappc_b64 with extra $callee parameter to track
411 // the called function after regalloc.
412 def SI_CALL : SPseudoInstSI <
413 (outs SReg_64:$dst), (ins SSrc_b64:$src0, unknown:$callee)> {
416 let UseNamedOperandTable = 1;
417 let SchedRW = [WriteBranch];
418 // TODO: Should really base this on the call target
419 let isConvergent = 1;
422 // Tail call handling pseudo
423 def SI_TCRETURN : SPseudoInstSI <(outs),
424 (ins SSrc_b64:$src0, unknown:$callee, i32imm:$fpdiff),
425 [(AMDGPUtc_return i64:$src0, tglobaladdr:$callee, i32:$fpdiff)]> {
428 let isTerminator = 1;
431 let UseNamedOperandTable = 1;
432 let SchedRW = [WriteBranch];
433 // TODO: Should really base this on the call target
434 let isConvergent = 1;
438 def ADJCALLSTACKUP : SPseudoInstSI<
439 (outs), (ins i32imm:$amt0, i32imm:$amt1),
440 [(callseq_start timm:$amt0, timm:$amt1)],
441 "; adjcallstackup $amt0 $amt1"> {
442 let Size = 8; // Worst case. (s_add_u32 + constant)
444 let hasSideEffects = 1;
445 let usesCustomInserter = 1;
446 let SchedRW = [WriteSALU];
450 def ADJCALLSTACKDOWN : SPseudoInstSI<
451 (outs), (ins i32imm:$amt1, i32imm:$amt2),
452 [(callseq_end timm:$amt1, timm:$amt2)],
453 "; adjcallstackdown $amt1"> {
454 let Size = 8; // Worst case. (s_add_u32 + constant)
455 let hasSideEffects = 1;
456 let usesCustomInserter = 1;
457 let SchedRW = [WriteSALU];
461 let Defs = [M0, EXEC, SCC],
462 UseNamedOperandTable = 1 in {
464 class SI_INDIRECT_SRC<RegisterClass rc> : VPseudoInstSI <
465 (outs VGPR_32:$vdst),
466 (ins rc:$src, VS_32:$idx, i32imm:$offset)> {
467 let usesCustomInserter = 1;
470 class SI_INDIRECT_DST<RegisterClass rc> : VPseudoInstSI <
472 (ins rc:$src, VS_32:$idx, i32imm:$offset, VGPR_32:$val)> {
473 let Constraints = "$src = $vdst";
474 let usesCustomInserter = 1;
477 // TODO: We can support indirect SGPR access.
478 def SI_INDIRECT_SRC_V1 : SI_INDIRECT_SRC<VGPR_32>;
479 def SI_INDIRECT_SRC_V2 : SI_INDIRECT_SRC<VReg_64>;
480 def SI_INDIRECT_SRC_V4 : SI_INDIRECT_SRC<VReg_128>;
481 def SI_INDIRECT_SRC_V8 : SI_INDIRECT_SRC<VReg_256>;
482 def SI_INDIRECT_SRC_V16 : SI_INDIRECT_SRC<VReg_512>;
484 def SI_INDIRECT_DST_V1 : SI_INDIRECT_DST<VGPR_32>;
485 def SI_INDIRECT_DST_V2 : SI_INDIRECT_DST<VReg_64>;
486 def SI_INDIRECT_DST_V4 : SI_INDIRECT_DST<VReg_128>;
487 def SI_INDIRECT_DST_V8 : SI_INDIRECT_DST<VReg_256>;
488 def SI_INDIRECT_DST_V16 : SI_INDIRECT_DST<VReg_512>;
490 } // End Uses = [EXEC], Defs = [M0, EXEC]
492 multiclass SI_SPILL_SGPR <RegisterClass sgpr_class> {
493 let UseNamedOperandTable = 1, SGPRSpill = 1, Uses = [EXEC] in {
494 def _SAVE : PseudoInstSI <
496 (ins sgpr_class:$data, i32imm:$addr)> {
501 def _RESTORE : PseudoInstSI <
502 (outs sgpr_class:$data),
503 (ins i32imm:$addr)> {
507 } // End UseNamedOperandTable = 1
510 // You cannot use M0 as the output of v_readlane_b32 instructions or
511 // use it in the sdata operand of SMEM instructions. We still need to
512 // be able to spill the physical register m0, so allow it for
513 // SI_SPILL_32_* instructions.
514 defm SI_SPILL_S32 : SI_SPILL_SGPR <SReg_32>;
515 defm SI_SPILL_S64 : SI_SPILL_SGPR <SReg_64>;
516 defm SI_SPILL_S96 : SI_SPILL_SGPR <SReg_96>;
517 defm SI_SPILL_S128 : SI_SPILL_SGPR <SReg_128>;
518 defm SI_SPILL_S160 : SI_SPILL_SGPR <SReg_160>;
519 defm SI_SPILL_S256 : SI_SPILL_SGPR <SReg_256>;
520 defm SI_SPILL_S512 : SI_SPILL_SGPR <SReg_512>;
521 defm SI_SPILL_S1024 : SI_SPILL_SGPR <SReg_1024>;
523 multiclass SI_SPILL_VGPR <RegisterClass vgpr_class> {
524 let UseNamedOperandTable = 1, VGPRSpill = 1,
525 SchedRW = [WriteVMEM] in {
526 def _SAVE : VPseudoInstSI <
528 (ins vgpr_class:$vdata, i32imm:$vaddr, SReg_128:$srsrc,
529 SReg_32:$soffset, i32imm:$offset)> {
532 // (2 * 4) + (8 * num_subregs) bytes maximum
533 int MaxSize = !add(!shl(!srl(vgpr_class.Size, 5), 3), 8);
534 // Size field is unsigned char and cannot fit more.
535 let Size = !if(!le(MaxSize, 256), MaxSize, 252);
538 def _RESTORE : VPseudoInstSI <
539 (outs vgpr_class:$vdata),
540 (ins i32imm:$vaddr, SReg_128:$srsrc, SReg_32:$soffset,
545 // (2 * 4) + (8 * num_subregs) bytes maximum
546 int MaxSize = !add(!shl(!srl(vgpr_class.Size, 5), 3), 8);
547 // Size field is unsigned char and cannot fit more.
548 let Size = !if(!le(MaxSize, 256), MaxSize, 252);
550 } // End UseNamedOperandTable = 1, VGPRSpill = 1, SchedRW = [WriteVMEM]
553 defm SI_SPILL_V32 : SI_SPILL_VGPR <VGPR_32>;
554 defm SI_SPILL_V64 : SI_SPILL_VGPR <VReg_64>;
555 defm SI_SPILL_V96 : SI_SPILL_VGPR <VReg_96>;
556 defm SI_SPILL_V128 : SI_SPILL_VGPR <VReg_128>;
557 defm SI_SPILL_V160 : SI_SPILL_VGPR <VReg_160>;
558 defm SI_SPILL_V256 : SI_SPILL_VGPR <VReg_256>;
559 defm SI_SPILL_V512 : SI_SPILL_VGPR <VReg_512>;
560 defm SI_SPILL_V1024 : SI_SPILL_VGPR <VReg_1024>;
562 multiclass SI_SPILL_AGPR <RegisterClass vgpr_class> {
563 let UseNamedOperandTable = 1, VGPRSpill = 1,
564 Constraints = "@earlyclobber $tmp",
565 SchedRW = [WriteVMEM] in {
566 def _SAVE : VPseudoInstSI <
568 (ins vgpr_class:$vdata, i32imm:$vaddr, SReg_128:$srsrc,
569 SReg_32:$soffset, i32imm:$offset)> {
572 // (2 * 4) + (16 * num_subregs) bytes maximum
573 int MaxSize = !add(!shl(!srl(vgpr_class.Size, 5), 4), 8);
574 // Size field is unsigned char and cannot fit more.
575 let Size = !if(!le(MaxSize, 256), MaxSize, 252);
578 def _RESTORE : VPseudoInstSI <
579 (outs vgpr_class:$vdata, VGPR_32:$tmp),
580 (ins i32imm:$vaddr, SReg_128:$srsrc, SReg_32:$soffset,
585 // (2 * 4) + (16 * num_subregs) bytes maximum
586 int MaxSize = !add(!shl(!srl(vgpr_class.Size, 5), 4), 8);
587 // Size field is unsigned char and cannot fit more.
588 let Size = !if(!le(MaxSize, 256), MaxSize, 252);
590 } // End UseNamedOperandTable = 1, VGPRSpill = 1, SchedRW = [WriteVMEM]
593 defm SI_SPILL_A32 : SI_SPILL_AGPR <AGPR_32>;
594 defm SI_SPILL_A64 : SI_SPILL_AGPR <AReg_64>;
595 defm SI_SPILL_A128 : SI_SPILL_AGPR <AReg_128>;
596 defm SI_SPILL_A512 : SI_SPILL_AGPR <AReg_512>;
597 defm SI_SPILL_A1024 : SI_SPILL_AGPR <AReg_1024>;
599 def SI_PC_ADD_REL_OFFSET : SPseudoInstSI <
601 (ins si_ga:$ptr_lo, si_ga:$ptr_hi),
603 (i64 (SIpc_add_rel_offset tglobaladdr:$ptr_lo, tglobaladdr:$ptr_hi)))]> {
608 (SIpc_add_rel_offset tglobaladdr:$ptr_lo, 0),
609 (SI_PC_ADD_REL_OFFSET $ptr_lo, (i32 0))
613 (int_amdgcn_init_exec i64:$src),
614 (SI_INIT_EXEC (as_i64imm $src))> {
615 let WaveSizePredicate = isWave64;
619 (int_amdgcn_init_exec i64:$src),
620 (SI_INIT_EXEC_LO (as_i32imm $src))> {
621 let WaveSizePredicate = isWave32;
625 (int_amdgcn_init_exec_from_input i32:$input, i32:$shift),
626 (SI_INIT_EXEC_FROM_INPUT (i32 $input), (as_i32imm $shift))
630 (AMDGPUtrap timm:$trapid),
635 (AMDGPUelse i1:$src, bb:$target),
636 (SI_ELSE $src, $target, 0)
640 // -1.0 as i32 (LowerINTRINSIC_VOID converts all other constants to -1.0)
641 (AMDGPUkill (i32 -1082130432)),
642 (SI_KILL_I1_PSEUDO (i1 0), 0)
646 (int_amdgcn_kill i1:$src),
647 (SI_KILL_I1_PSEUDO $src, 0)
651 (int_amdgcn_kill (i1 (not i1:$src))),
652 (SI_KILL_I1_PSEUDO $src, -1)
656 (AMDGPUkill i32:$src),
657 (SI_KILL_F32_COND_IMM_PSEUDO $src, 0, 3) // 3 means SETOGE
661 (int_amdgcn_kill (i1 (setcc f32:$src, InlineFPImm<f32>:$imm, cond:$cond))),
662 (SI_KILL_F32_COND_IMM_PSEUDO $src, (bitcast_fpimm_to_i32 $imm), (cond_as_i32imm $cond))
665 // TODO: we could add more variants for other types of conditionals
668 (i64 (int_amdgcn_icmp i1:$src, (i1 0), (i32 33))),
669 (COPY $src) // Return the SGPRs representing i1 src
673 (i32 (int_amdgcn_icmp i1:$src, (i1 0), (i32 33))),
674 (COPY $src) // Return the SGPRs representing i1 src
677 //===----------------------------------------------------------------------===//
679 //===----------------------------------------------------------------------===//
681 let OtherPredicates = [UnsafeFPMath] in {
683 //def : RcpPat<V_RCP_F64_e32, f64>;
684 //defm : RsqPat<V_RSQ_F64_e32, f64>;
685 //defm : RsqPat<V_RSQ_F32_e32, f32>;
687 def : RsqPat<V_RSQ_F32_e32, f32>;
688 def : RsqPat<V_RSQ_F64_e32, f64>;
690 // Convert (x - floor(x)) to fract(x)
692 (f32 (fsub (f32 (VOP3Mods f32:$x, i32:$mods)),
693 (f32 (ffloor (f32 (VOP3Mods f32:$x, i32:$mods)))))),
694 (V_FRACT_F32_e64 $mods, $x, DSTCLAMP.NONE, DSTOMOD.NONE)
697 // Convert (x + (-floor(x))) to fract(x)
699 (f64 (fadd (f64 (VOP3Mods f64:$x, i32:$mods)),
700 (f64 (fneg (f64 (ffloor (f64 (VOP3Mods f64:$x, i32:$mods)))))))),
701 (V_FRACT_F64_e64 $mods, $x, DSTCLAMP.NONE, DSTOMOD.NONE)
704 } // End OtherPredicates = [UnsafeFPMath]
707 // f16_to_fp patterns
709 (f32 (f16_to_fp i32:$src0)),
710 (V_CVT_F32_F16_e64 SRCMODS.NONE, $src0, DSTCLAMP.NONE, DSTOMOD.NONE)
714 (f32 (f16_to_fp (and_oneuse i32:$src0, 0x7fff))),
715 (V_CVT_F32_F16_e64 SRCMODS.ABS, $src0, DSTCLAMP.NONE, DSTOMOD.NONE)
719 (f32 (f16_to_fp (i32 (srl_oneuse (and_oneuse i32:$src0, 0x7fff0000), (i32 16))))),
720 (V_CVT_F32_F16_e64 SRCMODS.ABS, (i32 (V_LSHRREV_B32_e64 (i32 16), i32:$src0)), DSTCLAMP.NONE, DSTOMOD.NONE)
724 (f32 (f16_to_fp (or_oneuse i32:$src0, 0x8000))),
725 (V_CVT_F32_F16_e64 SRCMODS.NEG_ABS, $src0, DSTCLAMP.NONE, DSTOMOD.NONE)
729 (f32 (f16_to_fp (xor_oneuse i32:$src0, 0x8000))),
730 (V_CVT_F32_F16_e64 SRCMODS.NEG, $src0, DSTCLAMP.NONE, DSTOMOD.NONE)
734 (f64 (fpextend f16:$src)),
735 (V_CVT_F64_F32_e32 (V_CVT_F32_F16_e32 $src))
738 // fp_to_fp16 patterns
740 (i32 (AMDGPUfp_to_f16 (f32 (VOP3Mods f32:$src0, i32:$src0_modifiers)))),
741 (V_CVT_F16_F32_e64 $src0_modifiers, f32:$src0, DSTCLAMP.NONE, DSTOMOD.NONE)
745 (i32 (fp_to_sint f16:$src)),
746 (V_CVT_I32_F32_e32 (V_CVT_F32_F16_e32 VSrc_b32:$src))
750 (i32 (fp_to_uint f16:$src)),
751 (V_CVT_U32_F32_e32 (V_CVT_F32_F16_e32 VSrc_b32:$src))
755 (f16 (sint_to_fp i32:$src)),
756 (V_CVT_F16_F32_e32 (V_CVT_F32_I32_e32 VSrc_b32:$src))
760 (f16 (uint_to_fp i32:$src)),
761 (V_CVT_F16_F32_e32 (V_CVT_F32_U32_e32 VSrc_b32:$src))
764 //===----------------------------------------------------------------------===//
766 //===----------------------------------------------------------------------===//
768 multiclass FMADPat <ValueType vt, Instruction inst> {
770 (vt (fmad (VOP3NoMods vt:$src0),
771 (VOP3NoMods vt:$src1),
772 (VOP3NoMods vt:$src2))),
773 (inst SRCMODS.NONE, $src0, SRCMODS.NONE, $src1,
774 SRCMODS.NONE, $src2, DSTCLAMP.NONE, DSTOMOD.NONE)
778 defm : FMADPat <f16, V_MAC_F16_e64>;
779 defm : FMADPat <f32, V_MAC_F32_e64>;
781 class FMADModsPat<Instruction inst, SDPatternOperator mad_opr, ValueType Ty>
783 (Ty (mad_opr (VOP3Mods Ty:$src0, i32:$src0_mod),
784 (VOP3Mods Ty:$src1, i32:$src1_mod),
785 (VOP3Mods Ty:$src2, i32:$src2_mod))),
786 (inst $src0_mod, $src0, $src1_mod, $src1,
787 $src2_mod, $src2, DSTCLAMP.NONE, DSTOMOD.NONE)
790 def : FMADModsPat<V_MAD_F32, AMDGPUfmad_ftz, f32>;
791 def : FMADModsPat<V_MAD_F16, AMDGPUfmad_ftz, f16> {
792 let SubtargetPredicate = Has16BitInsts;
795 multiclass SelectPat <ValueType vt> {
797 (vt (select i1:$src0, (VOP3Mods_f32 vt:$src1, i32:$src1_mods),
798 (VOP3Mods_f32 vt:$src2, i32:$src2_mods))),
799 (V_CNDMASK_B32_e64 $src2_mods, $src2, $src1_mods, $src1, $src0)
803 defm : SelectPat <i16>;
804 defm : SelectPat <i32>;
805 defm : SelectPat <f16>;
806 defm : SelectPat <f32>;
808 let AddedComplexity = 1 in {
810 (i32 (add (i32 (getDivergentFrag<ctpop>.ret i32:$popcnt)), i32:$val)),
811 (V_BCNT_U32_B32_e64 $popcnt, $val)
816 (i32 (ctpop i32:$popcnt)),
817 (V_BCNT_U32_B32_e64 VSrc_b32:$popcnt, (i32 0))
821 (i16 (add (i16 (trunc (i32 (getDivergentFrag<ctpop>.ret i32:$popcnt)))), i16:$val)),
822 (V_BCNT_U32_B32_e64 $popcnt, $val)
825 /********** ============================================ **********/
826 /********** Extraction, Insertion, Building and Casting **********/
827 /********** ============================================ **********/
829 foreach Index = 0-2 in {
830 def Extract_Element_v2i32_#Index : Extract_Element <
831 i32, v2i32, Index, !cast<SubRegIndex>(sub#Index)
833 def Insert_Element_v2i32_#Index : Insert_Element <
834 i32, v2i32, Index, !cast<SubRegIndex>(sub#Index)
837 def Extract_Element_v2f32_#Index : Extract_Element <
838 f32, v2f32, Index, !cast<SubRegIndex>(sub#Index)
840 def Insert_Element_v2f32_#Index : Insert_Element <
841 f32, v2f32, Index, !cast<SubRegIndex>(sub#Index)
845 foreach Index = 0-2 in {
846 def Extract_Element_v3i32_#Index : Extract_Element <
847 i32, v3i32, Index, !cast<SubRegIndex>(sub#Index)
849 def Insert_Element_v3i32_#Index : Insert_Element <
850 i32, v3i32, Index, !cast<SubRegIndex>(sub#Index)
853 def Extract_Element_v3f32_#Index : Extract_Element <
854 f32, v3f32, Index, !cast<SubRegIndex>(sub#Index)
856 def Insert_Element_v3f32_#Index : Insert_Element <
857 f32, v3f32, Index, !cast<SubRegIndex>(sub#Index)
861 foreach Index = 0-3 in {
862 def Extract_Element_v4i32_#Index : Extract_Element <
863 i32, v4i32, Index, !cast<SubRegIndex>(sub#Index)
865 def Insert_Element_v4i32_#Index : Insert_Element <
866 i32, v4i32, Index, !cast<SubRegIndex>(sub#Index)
869 def Extract_Element_v4f32_#Index : Extract_Element <
870 f32, v4f32, Index, !cast<SubRegIndex>(sub#Index)
872 def Insert_Element_v4f32_#Index : Insert_Element <
873 f32, v4f32, Index, !cast<SubRegIndex>(sub#Index)
877 foreach Index = 0-4 in {
878 def Extract_Element_v5i32_#Index : Extract_Element <
879 i32, v5i32, Index, !cast<SubRegIndex>(sub#Index)
881 def Insert_Element_v5i32_#Index : Insert_Element <
882 i32, v5i32, Index, !cast<SubRegIndex>(sub#Index)
885 def Extract_Element_v5f32_#Index : Extract_Element <
886 f32, v5f32, Index, !cast<SubRegIndex>(sub#Index)
888 def Insert_Element_v5f32_#Index : Insert_Element <
889 f32, v5f32, Index, !cast<SubRegIndex>(sub#Index)
893 foreach Index = 0-7 in {
894 def Extract_Element_v8i32_#Index : Extract_Element <
895 i32, v8i32, Index, !cast<SubRegIndex>(sub#Index)
897 def Insert_Element_v8i32_#Index : Insert_Element <
898 i32, v8i32, Index, !cast<SubRegIndex>(sub#Index)
901 def Extract_Element_v8f32_#Index : Extract_Element <
902 f32, v8f32, Index, !cast<SubRegIndex>(sub#Index)
904 def Insert_Element_v8f32_#Index : Insert_Element <
905 f32, v8f32, Index, !cast<SubRegIndex>(sub#Index)
909 foreach Index = 0-15 in {
910 def Extract_Element_v16i32_#Index : Extract_Element <
911 i32, v16i32, Index, !cast<SubRegIndex>(sub#Index)
913 def Insert_Element_v16i32_#Index : Insert_Element <
914 i32, v16i32, Index, !cast<SubRegIndex>(sub#Index)
917 def Extract_Element_v16f32_#Index : Extract_Element <
918 f32, v16f32, Index, !cast<SubRegIndex>(sub#Index)
920 def Insert_Element_v16f32_#Index : Insert_Element <
921 f32, v16f32, Index, !cast<SubRegIndex>(sub#Index)
927 (extract_subvector v4i16:$vec, (i32 0)),
928 (v2i16 (EXTRACT_SUBREG v4i16:$vec, sub0))
932 (extract_subvector v4i16:$vec, (i32 2)),
933 (v2i16 (EXTRACT_SUBREG v4i16:$vec, sub1))
937 (extract_subvector v4f16:$vec, (i32 0)),
938 (v2f16 (EXTRACT_SUBREG v4f16:$vec, sub0))
942 (extract_subvector v4f16:$vec, (i32 2)),
943 (v2f16 (EXTRACT_SUBREG v4f16:$vec, sub1))
946 foreach Index = 0-31 in {
947 def Extract_Element_v32i32_#Index : Extract_Element <
948 i32, v32i32, Index, !cast<SubRegIndex>(sub#Index)
951 def Insert_Element_v32i32_#Index : Insert_Element <
952 i32, v32i32, Index, !cast<SubRegIndex>(sub#Index)
955 def Extract_Element_v32f32_#Index : Extract_Element <
956 f32, v32f32, Index, !cast<SubRegIndex>(sub#Index)
959 def Insert_Element_v32f32_#Index : Insert_Element <
960 f32, v32f32, Index, !cast<SubRegIndex>(sub#Index)
964 // FIXME: Why do only some of these type combinations for SReg and
967 def : BitConvert <i16, f16, VGPR_32>;
968 def : BitConvert <f16, i16, VGPR_32>;
969 def : BitConvert <i16, f16, SReg_32>;
970 def : BitConvert <f16, i16, SReg_32>;
973 def : BitConvert <i32, f32, VGPR_32>;
974 def : BitConvert <f32, i32, VGPR_32>;
975 def : BitConvert <i32, f32, SReg_32>;
976 def : BitConvert <f32, i32, SReg_32>;
977 def : BitConvert <v2i16, i32, SReg_32>;
978 def : BitConvert <i32, v2i16, SReg_32>;
979 def : BitConvert <v2f16, i32, SReg_32>;
980 def : BitConvert <i32, v2f16, SReg_32>;
981 def : BitConvert <v2i16, v2f16, SReg_32>;
982 def : BitConvert <v2f16, v2i16, SReg_32>;
983 def : BitConvert <v2f16, f32, SReg_32>;
984 def : BitConvert <f32, v2f16, SReg_32>;
985 def : BitConvert <v2i16, f32, SReg_32>;
986 def : BitConvert <f32, v2i16, SReg_32>;
989 def : BitConvert <i64, f64, VReg_64>;
990 def : BitConvert <f64, i64, VReg_64>;
991 def : BitConvert <v2i32, v2f32, VReg_64>;
992 def : BitConvert <v2f32, v2i32, VReg_64>;
993 def : BitConvert <i64, v2i32, VReg_64>;
994 def : BitConvert <v2i32, i64, VReg_64>;
995 def : BitConvert <i64, v2f32, VReg_64>;
996 def : BitConvert <v2f32, i64, VReg_64>;
997 def : BitConvert <f64, v2f32, VReg_64>;
998 def : BitConvert <v2f32, f64, VReg_64>;
999 def : BitConvert <f64, v2i32, VReg_64>;
1000 def : BitConvert <v2i32, f64, VReg_64>;
1001 def : BitConvert <v4i16, v4f16, VReg_64>;
1002 def : BitConvert <v4f16, v4i16, VReg_64>;
1005 def : BitConvert <v2i32, v4f16, VReg_64>;
1006 def : BitConvert <v4f16, v2i32, VReg_64>;
1007 def : BitConvert <v2i32, v4f16, VReg_64>;
1008 def : BitConvert <v2i32, v4i16, VReg_64>;
1009 def : BitConvert <v4i16, v2i32, VReg_64>;
1010 def : BitConvert <v2f32, v4f16, VReg_64>;
1011 def : BitConvert <v4f16, v2f32, VReg_64>;
1012 def : BitConvert <v2f32, v4i16, VReg_64>;
1013 def : BitConvert <v4i16, v2f32, VReg_64>;
1014 def : BitConvert <v4i16, f64, VReg_64>;
1015 def : BitConvert <v4f16, f64, VReg_64>;
1016 def : BitConvert <f64, v4i16, VReg_64>;
1017 def : BitConvert <f64, v4f16, VReg_64>;
1018 def : BitConvert <v4i16, i64, VReg_64>;
1019 def : BitConvert <v4f16, i64, VReg_64>;
1020 def : BitConvert <i64, v4i16, VReg_64>;
1021 def : BitConvert <i64, v4f16, VReg_64>;
1023 def : BitConvert <v4i32, v4f32, VReg_128>;
1024 def : BitConvert <v4f32, v4i32, VReg_128>;
1027 def : BitConvert <v3i32, v3f32, SGPR_96>;
1028 def : BitConvert <v3f32, v3i32, SGPR_96>;
1031 def : BitConvert <v2i64, v4i32, SReg_128>;
1032 def : BitConvert <v4i32, v2i64, SReg_128>;
1033 def : BitConvert <v2f64, v4f32, VReg_128>;
1034 def : BitConvert <v2f64, v4i32, VReg_128>;
1035 def : BitConvert <v4f32, v2f64, VReg_128>;
1036 def : BitConvert <v4i32, v2f64, VReg_128>;
1037 def : BitConvert <v2i64, v2f64, VReg_128>;
1038 def : BitConvert <v2f64, v2i64, VReg_128>;
1041 def : BitConvert <v5i32, v5f32, SGPR_160>;
1042 def : BitConvert <v5f32, v5i32, SGPR_160>;
1045 def : BitConvert <v8i32, v8f32, SReg_256>;
1046 def : BitConvert <v8f32, v8i32, SReg_256>;
1047 def : BitConvert <v8i32, v8f32, VReg_256>;
1048 def : BitConvert <v8f32, v8i32, VReg_256>;
1051 def : BitConvert <v16i32, v16f32, VReg_512>;
1052 def : BitConvert <v16f32, v16i32, VReg_512>;
1055 def : BitConvert <v32i32, v32f32, VReg_1024>;
1056 def : BitConvert <v32f32, v32i32, VReg_1024>;
1058 /********** =================== **********/
1059 /********** Src & Dst modifiers **********/
1060 /********** =================== **********/
1063 // If denormals are not enabled, it only impacts the compare of the
1064 // inputs. The output result is not flushed.
1065 class ClampPat<Instruction inst, ValueType vt> : GCNPat <
1066 (vt (AMDGPUclamp (VOP3Mods vt:$src0, i32:$src0_modifiers))),
1067 (inst i32:$src0_modifiers, vt:$src0,
1068 i32:$src0_modifiers, vt:$src0, DSTCLAMP.ENABLE, DSTOMOD.NONE)
1071 def : ClampPat<V_MAX_F32_e64, f32>;
1072 def : ClampPat<V_MAX_F64, f64>;
1073 def : ClampPat<V_MAX_F16_e64, f16>;
1075 let SubtargetPredicate = HasVOP3PInsts in {
1077 (v2f16 (AMDGPUclamp (VOP3PMods v2f16:$src0, i32:$src0_modifiers))),
1078 (V_PK_MAX_F16 $src0_modifiers, $src0,
1079 $src0_modifiers, $src0, DSTCLAMP.ENABLE)
1083 /********** ================================ **********/
1084 /********** Floating point absolute/negative **********/
1085 /********** ================================ **********/
1087 // Prevent expanding both fneg and fabs.
1088 // TODO: Add IgnoredBySelectionDAG bit?
1089 let AddedComplexity = 1 in { // Prefer SALU to VALU patterns for DAG
1092 (fneg (fabs (f32 SReg_32:$src))),
1093 (S_OR_B32 SReg_32:$src, (S_MOV_B32 (i32 0x80000000))) // Set sign bit
1097 (fabs (f32 SReg_32:$src)),
1098 (S_AND_B32 SReg_32:$src, (S_MOV_B32 (i32 0x7fffffff)))
1102 (fneg (f32 SReg_32:$src)),
1103 (S_XOR_B32 SReg_32:$src, (S_MOV_B32 (i32 0x80000000)))
1107 (fneg (f16 SReg_32:$src)),
1108 (S_XOR_B32 SReg_32:$src, (S_MOV_B32 (i32 0x00008000)))
1112 (fneg (f16 VGPR_32:$src)),
1113 (V_XOR_B32_e32 (S_MOV_B32 (i32 0x00008000)), VGPR_32:$src)
1117 (fabs (f16 SReg_32:$src)),
1118 (S_AND_B32 SReg_32:$src, (S_MOV_B32 (i32 0x00007fff)))
1122 (fneg (fabs (f16 SReg_32:$src))),
1123 (S_OR_B32 SReg_32:$src, (S_MOV_B32 (i32 0x00008000))) // Set sign bit
1127 (fneg (fabs (f16 VGPR_32:$src))),
1128 (V_OR_B32_e32 (S_MOV_B32 (i32 0x00008000)), VGPR_32:$src) // Set sign bit
1132 (fneg (v2f16 SReg_32:$src)),
1133 (S_XOR_B32 SReg_32:$src, (S_MOV_B32 (i32 0x80008000)))
1137 (fabs (v2f16 SReg_32:$src)),
1138 (S_AND_B32 SReg_32:$src, (S_MOV_B32 (i32 0x7fff7fff)))
1141 // This is really (fneg (fabs v2f16:$src))
1143 // fabs is not reported as free because there is modifier for it in
1144 // VOP3P instructions, so it is turned into the bit op.
1146 (fneg (v2f16 (bitconvert (and_oneuse (i32 SReg_32:$src), 0x7fff7fff)))),
1147 (S_OR_B32 SReg_32:$src, (S_MOV_B32 (i32 0x80008000))) // Set sign bit
1151 (fneg (v2f16 (fabs SReg_32:$src))),
1152 (S_OR_B32 SReg_32:$src, (S_MOV_B32 (i32 0x80008000))) // Set sign bit
1155 // FIXME: The implicit-def of scc from S_[X]OR_B32 is mishandled
1157 // (fneg (f64 SReg_64:$src)),
1158 // (REG_SEQUENCE SReg_64,
1159 // (i32 (EXTRACT_SUBREG SReg_64:$src, sub0)),
1161 // (S_XOR_B32 (i32 (EXTRACT_SUBREG SReg_64:$src, sub1)),
1162 // (i32 (S_MOV_B32 (i32 0x80000000)))),
1167 // (fneg (fabs (f64 SReg_64:$src))),
1168 // (REG_SEQUENCE SReg_64,
1169 // (i32 (EXTRACT_SUBREG SReg_64:$src, sub0)),
1171 // (S_OR_B32 (i32 (EXTRACT_SUBREG SReg_64:$src, sub1)),
1172 // (S_MOV_B32 (i32 0x80000000))), // Set sign bit.
1176 } // End let AddedComplexity = 1
1179 (fabs (f32 VGPR_32:$src)),
1180 (V_AND_B32_e32 (S_MOV_B32 (i32 0x7fffffff)), VGPR_32:$src)
1184 (fneg (f32 VGPR_32:$src)),
1185 (V_XOR_B32_e32 (S_MOV_B32 (i32 0x80000000)), VGPR_32:$src)
1189 (fabs (f16 VGPR_32:$src)),
1190 (V_AND_B32_e32 (S_MOV_B32 (i32 0x00007fff)), VGPR_32:$src)
1194 (fneg (v2f16 VGPR_32:$src)),
1195 (V_XOR_B32_e32 (S_MOV_B32 (i32 0x80008000)), VGPR_32:$src)
1199 (fabs (v2f16 VGPR_32:$src)),
1200 (V_AND_B32_e32 (S_MOV_B32 (i32 0x7fff7fff)), VGPR_32:$src)
1204 (fneg (v2f16 (fabs VGPR_32:$src))),
1205 (V_OR_B32_e32 (S_MOV_B32 (i32 0x80008000)), VGPR_32:$src) // Set sign bit
1209 (fabs (f64 VReg_64:$src)),
1210 (REG_SEQUENCE VReg_64,
1211 (i32 (EXTRACT_SUBREG VReg_64:$src, sub0)),
1213 (V_AND_B32_e64 (i32 (EXTRACT_SUBREG VReg_64:$src, sub1)),
1214 (V_MOV_B32_e32 (i32 0x7fffffff))), // Set sign bit.
1218 // TODO: Use SGPR for constant
1220 (fneg (f64 VReg_64:$src)),
1221 (REG_SEQUENCE VReg_64,
1222 (i32 (EXTRACT_SUBREG VReg_64:$src, sub0)),
1224 (V_XOR_B32_e32 (i32 (EXTRACT_SUBREG VReg_64:$src, sub1)),
1225 (i32 (V_MOV_B32_e32 (i32 0x80000000)))),
1229 // TODO: Use SGPR for constant
1231 (fneg (fabs (f64 VReg_64:$src))),
1232 (REG_SEQUENCE VReg_64,
1233 (i32 (EXTRACT_SUBREG VReg_64:$src, sub0)),
1235 (V_OR_B32_e32 (i32 (EXTRACT_SUBREG VReg_64:$src, sub1)),
1236 (V_MOV_B32_e32 (i32 0x80000000))), // Set sign bit.
1241 (fcopysign f16:$src0, f16:$src1),
1242 (V_BFI_B32 (S_MOV_B32 (i32 0x00007fff)), $src0, $src1)
1246 (fcopysign f32:$src0, f16:$src1),
1247 (V_BFI_B32 (S_MOV_B32 (i32 0x7fffffff)), $src0,
1248 (V_LSHLREV_B32_e64 (i32 16), $src1))
1252 (fcopysign f64:$src0, f16:$src1),
1253 (REG_SEQUENCE SReg_64,
1254 (i32 (EXTRACT_SUBREG $src0, sub0)), sub0,
1255 (V_BFI_B32 (S_MOV_B32 (i32 0x7fffffff)), (i32 (EXTRACT_SUBREG $src0, sub1)),
1256 (V_LSHLREV_B32_e64 (i32 16), $src1)), sub1)
1260 (fcopysign f16:$src0, f32:$src1),
1261 (V_BFI_B32 (S_MOV_B32 (i32 0x00007fff)), $src0,
1262 (V_LSHRREV_B32_e64 (i32 16), $src1))
1266 (fcopysign f16:$src0, f64:$src1),
1267 (V_BFI_B32 (S_MOV_B32 (i32 0x00007fff)), $src0,
1268 (V_LSHRREV_B32_e64 (i32 16), (EXTRACT_SUBREG $src1, sub1)))
1271 /********** ================== **********/
1272 /********** Immediate Patterns **********/
1273 /********** ================== **********/
1276 (VGPRImm<(i32 imm)>:$imm),
1277 (V_MOV_B32_e32 imm:$imm)
1281 (VGPRImm<(f32 fpimm)>:$imm),
1282 (V_MOV_B32_e32 (f32 (bitcast_fpimm_to_i32 $imm)))
1287 (S_MOV_B32 imm:$imm)
1291 (VGPRImm<(SIlds tglobaladdr:$ga)>),
1296 (SIlds tglobaladdr:$ga),
1300 // FIXME: Workaround for ordering issue with peephole optimizer where
1301 // a register class copy interferes with immediate folding. Should
1302 // use s_mov_b32, which can be shrunk to s_movk_i32
1304 (VGPRImm<(f16 fpimm)>:$imm),
1305 (V_MOV_B32_e32 (f16 (bitcast_fpimm_to_i32 $imm)))
1310 (S_MOV_B32 (f32 (bitcast_fpimm_to_i32 $imm)))
1315 (S_MOV_B32 (i32 (bitcast_fpimm_to_i32 $imm)))
1319 (i32 frameindex:$fi),
1320 (V_MOV_B32_e32 (i32 (frameindex_to_targetframeindex $fi)))
1324 (i64 InlineImm<i64>:$imm),
1325 (S_MOV_B64 InlineImm<i64>:$imm)
1328 // XXX - Should this use a s_cmp to set SCC?
1330 // Set to sign-extended 64-bit value (true = -1, false = 0)
1333 (S_MOV_B64 (i64 (as_i64imm $imm)))
1335 let WaveSizePredicate = isWave64;
1340 (S_MOV_B32 (i32 (as_i32imm $imm)))
1342 let WaveSizePredicate = isWave32;
1346 (f64 InlineFPImm<f64>:$imm),
1347 (S_MOV_B64 (f64 (bitcast_fpimm_to_i64 InlineFPImm<f64>:$imm)))
1350 /********** ================== **********/
1351 /********** Intrinsic Patterns **********/
1352 /********** ================== **********/
1354 def : POW_Common <V_LOG_F32_e32, V_EXP_F32_e32, V_MUL_LEGACY_F32_e32>;
1357 (i32 (sext i1:$src0)),
1358 (V_CNDMASK_B32_e64 /*src0mod*/(i32 0), /*src0*/(i32 0),
1359 /*src1mod*/(i32 0), /*src1*/(i32 -1), $src0)
1362 class Ext32Pat <SDNode ext> : GCNPat <
1363 (i32 (ext i1:$src0)),
1364 (V_CNDMASK_B32_e64 /*src0mod*/(i32 0), /*src0*/(i32 0),
1365 /*src1mod*/(i32 0), /*src1*/(i32 1), $src0)
1368 def : Ext32Pat <zext>;
1369 def : Ext32Pat <anyext>;
1371 // The multiplication scales from [0,1] to the unsigned integer range
1373 (AMDGPUurecip i32:$src0),
1375 (V_MUL_F32_e32 (i32 CONST.FP_UINT_MAX_PLUS_1),
1376 (V_RCP_IFLAG_F32_e32 (V_CVT_F32_U32_e32 $src0))))
1379 //===----------------------------------------------------------------------===//
1381 //===----------------------------------------------------------------------===//
1383 def : IMad24Pat<V_MAD_I32_I24, 1>;
1384 def : UMad24Pat<V_MAD_U32_U24, 1>;
1386 // FIXME: This should only be done for VALU inputs
1387 defm : BFIPatterns <V_BFI_B32, S_MOV_B32, SReg_64>;
1388 def : ROTRPattern <V_ALIGNBIT_B32>;
1390 def : GCNPat<(i32 (trunc (srl i64:$src0, (and i32:$src1, (i32 31))))),
1391 (V_ALIGNBIT_B32 (i32 (EXTRACT_SUBREG (i64 $src0), sub1)),
1392 (i32 (EXTRACT_SUBREG (i64 $src0), sub0)), $src1)>;
1394 def : GCNPat<(i32 (trunc (srl i64:$src0, (i32 ShiftAmt32Imm:$src1)))),
1395 (V_ALIGNBIT_B32 (i32 (EXTRACT_SUBREG (i64 $src0), sub1)),
1396 (i32 (EXTRACT_SUBREG (i64 $src0), sub0)), $src1)>;
1398 /********** ====================== **********/
1399 /********** Indirect addressing **********/
1400 /********** ====================== **********/
1402 multiclass SI_INDIRECT_Pattern <ValueType vt, ValueType eltvt, string VecSize> {
1403 // Extract with offset
1405 (eltvt (extractelt vt:$src, (MOVRELOffset i32:$idx, (i32 imm:$offset)))),
1406 (!cast<Instruction>("SI_INDIRECT_SRC_"#VecSize) $src, $idx, imm:$offset)
1409 // Insert with offset
1411 (insertelt vt:$src, eltvt:$val, (MOVRELOffset i32:$idx, (i32 imm:$offset))),
1412 (!cast<Instruction>("SI_INDIRECT_DST_"#VecSize) $src, $idx, imm:$offset, $val)
1416 defm : SI_INDIRECT_Pattern <v2f32, f32, "V2">;
1417 defm : SI_INDIRECT_Pattern <v4f32, f32, "V4">;
1418 defm : SI_INDIRECT_Pattern <v8f32, f32, "V8">;
1419 defm : SI_INDIRECT_Pattern <v16f32, f32, "V16">;
1421 defm : SI_INDIRECT_Pattern <v2i32, i32, "V2">;
1422 defm : SI_INDIRECT_Pattern <v4i32, i32, "V4">;
1423 defm : SI_INDIRECT_Pattern <v8i32, i32, "V8">;
1424 defm : SI_INDIRECT_Pattern <v16i32, i32, "V16">;
1426 //===----------------------------------------------------------------------===//
1428 //===----------------------------------------------------------------------===//
1431 (add (sub_oneuse (umax i32:$src0, i32:$src1),
1432 (umin i32:$src0, i32:$src1)),
1434 (V_SAD_U32 $src0, $src1, $src2, (i1 0))
1438 (add (select_oneuse (i1 (setugt i32:$src0, i32:$src1)),
1439 (sub i32:$src0, i32:$src1),
1440 (sub i32:$src1, i32:$src0)),
1442 (V_SAD_U32 $src0, $src1, $src2, (i1 0))
1445 //===----------------------------------------------------------------------===//
1446 // Conversion Patterns
1447 //===----------------------------------------------------------------------===//
1449 def : GCNPat<(i32 (sext_inreg i32:$src, i1)),
1450 (S_BFE_I32 i32:$src, (i32 65536))>; // 0 | 1 << 16
1452 // Handle sext_inreg in i64
1454 (i64 (sext_inreg i64:$src, i1)),
1455 (S_BFE_I64 i64:$src, (i32 0x10000)) // 0 | 1 << 16
1459 (i16 (sext_inreg i16:$src, i1)),
1460 (S_BFE_I32 $src, (i32 0x00010000)) // 0 | 1 << 16
1464 (i16 (sext_inreg i16:$src, i8)),
1465 (S_BFE_I32 $src, (i32 0x80000)) // 0 | 8 << 16
1469 (i64 (sext_inreg i64:$src, i8)),
1470 (S_BFE_I64 i64:$src, (i32 0x80000)) // 0 | 8 << 16
1474 (i64 (sext_inreg i64:$src, i16)),
1475 (S_BFE_I64 i64:$src, (i32 0x100000)) // 0 | 16 << 16
1479 (i64 (sext_inreg i64:$src, i32)),
1480 (S_BFE_I64 i64:$src, (i32 0x200000)) // 0 | 32 << 16
1484 (i64 (zext i32:$src)),
1485 (REG_SEQUENCE SReg_64, $src, sub0, (S_MOV_B32 (i32 0)), sub1)
1489 (i64 (anyext i32:$src)),
1490 (REG_SEQUENCE SReg_64, $src, sub0, (i32 (IMPLICIT_DEF)), sub1)
1493 class ZExt_i64_i1_Pat <SDNode ext> : GCNPat <
1494 (i64 (ext i1:$src)),
1495 (REG_SEQUENCE VReg_64,
1496 (V_CNDMASK_B32_e64 /*src0mod*/(i32 0), /*src0*/(i32 0),
1497 /*src1mod*/(i32 0), /*src1*/(i32 1), $src),
1498 sub0, (S_MOV_B32 (i32 0)), sub1)
1502 def : ZExt_i64_i1_Pat<zext>;
1503 def : ZExt_i64_i1_Pat<anyext>;
1505 // FIXME: We need to use COPY_TO_REGCLASS to work-around the fact that
1506 // REG_SEQUENCE patterns don't support instructions with multiple outputs.
1508 (i64 (sext i32:$src)),
1509 (REG_SEQUENCE SReg_64, $src, sub0,
1510 (i32 (COPY_TO_REGCLASS (S_ASHR_I32 $src, (i32 31)), SReg_32_XM0)), sub1)
1514 (i64 (sext i1:$src)),
1515 (REG_SEQUENCE VReg_64,
1516 (V_CNDMASK_B32_e64 /*src0mod*/(i32 0), /*src0*/(i32 0),
1517 /*src1mod*/(i32 0), /*src1*/(i32 -1), $src), sub0,
1518 (V_CNDMASK_B32_e64 /*src0mod*/(i32 0), /*src0*/(i32 0),
1519 /*src1mod*/(i32 0), /*src1*/(i32 -1), $src), sub1)
1522 class FPToI1Pat<Instruction Inst, int KOne, ValueType kone_type, ValueType vt, SDPatternOperator fp_to_int> : GCNPat <
1523 (i1 (fp_to_int (vt (VOP3Mods vt:$src0, i32:$src0_modifiers)))),
1524 (i1 (Inst 0, (kone_type KOne), $src0_modifiers, $src0, DSTCLAMP.NONE))
1527 def : FPToI1Pat<V_CMP_EQ_F32_e64, CONST.FP32_ONE, i32, f32, fp_to_uint>;
1528 def : FPToI1Pat<V_CMP_EQ_F32_e64, CONST.FP32_NEG_ONE, i32, f32, fp_to_sint>;
1529 def : FPToI1Pat<V_CMP_EQ_F64_e64, CONST.FP64_ONE, i64, f64, fp_to_uint>;
1530 def : FPToI1Pat<V_CMP_EQ_F64_e64, CONST.FP64_NEG_ONE, i64, f64, fp_to_sint>;
1532 // If we need to perform a logical operation on i1 values, we need to
1533 // use vector comparisons since there is only one SCC register. Vector
1534 // comparisons may write to a pair of SGPRs or a single SGPR, so treat
1535 // these as 32 or 64-bit comparisons. When legalizing SGPR copies,
1536 // instructions resulting in the copies from SCC to these instructions
1537 // will be moved to the VALU.
1539 let WaveSizePredicate = isWave64 in {
1541 (i1 (and i1:$src0, i1:$src1)),
1542 (S_AND_B64 $src0, $src1)
1546 (i1 (or i1:$src0, i1:$src1)),
1547 (S_OR_B64 $src0, $src1)
1551 (i1 (xor i1:$src0, i1:$src1)),
1552 (S_XOR_B64 $src0, $src1)
1556 (i1 (add i1:$src0, i1:$src1)),
1557 (S_XOR_B64 $src0, $src1)
1561 (i1 (sub i1:$src0, i1:$src1)),
1562 (S_XOR_B64 $src0, $src1)
1565 let AddedComplexity = 1 in {
1567 (i1 (add i1:$src0, (i1 -1))),
1572 (i1 (sub i1:$src0, (i1 -1))),
1578 let WaveSizePredicate = isWave32 in {
1580 (i1 (and i1:$src0, i1:$src1)),
1581 (S_AND_B32 $src0, $src1)
1585 (i1 (or i1:$src0, i1:$src1)),
1586 (S_OR_B32 $src0, $src1)
1590 (i1 (xor i1:$src0, i1:$src1)),
1591 (S_XOR_B32 $src0, $src1)
1595 (i1 (add i1:$src0, i1:$src1)),
1596 (S_XOR_B32 $src0, $src1)
1600 (i1 (sub i1:$src0, i1:$src1)),
1601 (S_XOR_B32 $src0, $src1)
1604 let AddedComplexity = 1 in {
1606 (i1 (add i1:$src0, (i1 -1))),
1611 (i1 (sub i1:$src0, (i1 -1))),
1618 (f16 (sint_to_fp i1:$src)),
1619 (V_CVT_F16_F32_e32 (
1620 V_CNDMASK_B32_e64 /*src0mod*/(i32 0), /*src0*/(i32 0),
1621 /*src1mod*/(i32 0), /*src1*/(i32 CONST.FP32_NEG_ONE),
1626 (f16 (uint_to_fp i1:$src)),
1627 (V_CVT_F16_F32_e32 (
1628 V_CNDMASK_B32_e64 /*src0mod*/(i32 0), /*src0*/(i32 0),
1629 /*src1mod*/(i32 0), /*src1*/(i32 CONST.FP32_ONE),
1634 (f32 (sint_to_fp i1:$src)),
1635 (V_CNDMASK_B32_e64 /*src0mod*/(i32 0), /*src0*/(i32 0),
1636 /*src1mod*/(i32 0), /*src1*/(i32 CONST.FP32_NEG_ONE),
1641 (f32 (uint_to_fp i1:$src)),
1642 (V_CNDMASK_B32_e64 /*src0mod*/(i32 0), /*src0*/(i32 0),
1643 /*src1mod*/(i32 0), /*src1*/(i32 CONST.FP32_ONE),
1648 (f64 (sint_to_fp i1:$src)),
1649 (V_CVT_F64_I32_e32 (V_CNDMASK_B32_e64 /*src0mod*/(i32 0), /*src0*/(i32 0),
1650 /*src1mod*/(i32 0), /*src1*/(i32 -1),
1655 (f64 (uint_to_fp i1:$src)),
1656 (V_CVT_F64_U32_e32 (V_CNDMASK_B32_e64 /*src0mod*/(i32 0), /*src0*/(i32 0),
1657 /*src1mod*/(i32 0), /*src1*/(i32 1),
1661 //===----------------------------------------------------------------------===//
1662 // Miscellaneous Patterns
1663 //===----------------------------------------------------------------------===//
1665 (i32 (AMDGPUfp16_zext f16:$src)),
1671 (i32 (trunc i64:$a)),
1672 (EXTRACT_SUBREG $a, sub0)
1676 (i1 (trunc i32:$a)),
1677 (V_CMP_EQ_U32_e64 (S_AND_B32 (i32 1), $a), (i32 1))
1681 (i1 (trunc i16:$a)),
1682 (V_CMP_EQ_U32_e64 (S_AND_B32 (i32 1), $a), (i32 1))
1686 (i1 (trunc i64:$a)),
1687 (V_CMP_EQ_U32_e64 (S_AND_B32 (i32 1),
1688 (i32 (EXTRACT_SUBREG $a, sub0))), (i32 1))
1692 (i32 (bswap i32:$a)),
1693 (V_BFI_B32 (S_MOV_B32 (i32 0x00ff00ff)),
1694 (V_ALIGNBIT_B32 $a, $a, (i32 24)),
1695 (V_ALIGNBIT_B32 $a, $a, (i32 8)))
1698 let OtherPredicates = [NoFP16Denormals] in {
1700 (fcanonicalize (f16 (VOP3Mods f16:$src, i32:$src_mods))),
1701 (V_MUL_F16_e64 0, (i32 CONST.FP16_ONE), $src_mods, $src, 0, 0)
1705 (fcanonicalize (f16 (fneg (VOP3Mods f16:$src, i32:$src_mods)))),
1706 (V_MUL_F16_e64 0, (i32 CONST.FP16_NEG_ONE), $src_mods, $src, 0, 0)
1710 (fcanonicalize (v2f16 (VOP3PMods v2f16:$src, i32:$src_mods))),
1711 (V_PK_MUL_F16 0, (i32 CONST.FP16_ONE), $src_mods, $src, DSTCLAMP.NONE)
1715 let OtherPredicates = [FP16Denormals] in {
1717 (fcanonicalize (f16 (VOP3Mods f16:$src, i32:$src_mods))),
1718 (V_MAX_F16_e64 $src_mods, $src, $src_mods, $src, 0, 0)
1721 let SubtargetPredicate = HasVOP3PInsts in {
1723 (fcanonicalize (v2f16 (VOP3PMods v2f16:$src, i32:$src_mods))),
1724 (V_PK_MAX_F16 $src_mods, $src, $src_mods, $src, DSTCLAMP.NONE)
1729 let OtherPredicates = [NoFP32Denormals] in {
1731 (fcanonicalize (f32 (VOP3Mods f32:$src, i32:$src_mods))),
1732 (V_MUL_F32_e64 0, (i32 CONST.FP32_ONE), $src_mods, $src, 0, 0)
1736 (fcanonicalize (f32 (fneg (VOP3Mods f32:$src, i32:$src_mods)))),
1737 (V_MUL_F32_e64 0, (i32 CONST.FP32_NEG_ONE), $src_mods, $src, 0, 0)
1741 let OtherPredicates = [FP32Denormals] in {
1743 (fcanonicalize (f32 (VOP3Mods f32:$src, i32:$src_mods))),
1744 (V_MAX_F32_e64 $src_mods, $src, $src_mods, $src, 0, 0)
1748 let OtherPredicates = [NoFP64Denormals] in {
1750 (fcanonicalize (f64 (VOP3Mods f64:$src, i32:$src_mods))),
1751 (V_MUL_F64 0, CONST.FP64_ONE, $src_mods, $src, 0, 0)
1755 let OtherPredicates = [FP64Denormals] in {
1757 (fcanonicalize (f64 (VOP3Mods f64:$src, i32:$src_mods))),
1758 (V_MAX_F64 $src_mods, $src, $src_mods, $src, 0, 0)
1762 let OtherPredicates = [HasDLInsts] in {
1764 (fma (f32 (VOP3Mods0 f32:$src0, i32:$src0_modifiers, i1:$clamp, i32:$omod)),
1765 (f32 (VOP3Mods f32:$src1, i32:$src1_modifiers)),
1766 (f32 (VOP3NoMods f32:$src2))),
1767 (V_FMAC_F32_e64 $src0_modifiers, $src0, $src1_modifiers, $src1,
1768 SRCMODS.NONE, $src2, $clamp, $omod)
1770 } // End OtherPredicates = [HasDLInsts]
1772 let SubtargetPredicate = isGFX10Plus in
1774 (fma (f16 (VOP3Mods0 f32:$src0, i32:$src0_modifiers, i1:$clamp, i32:$omod)),
1775 (f16 (VOP3Mods f32:$src1, i32:$src1_modifiers)),
1776 (f16 (VOP3NoMods f32:$src2))),
1777 (V_FMAC_F16_e64 $src0_modifiers, $src0, $src1_modifiers, $src1,
1778 SRCMODS.NONE, $src2, $clamp, $omod)
1781 // Allow integer inputs
1782 class ExpPattern<SDPatternOperator node, ValueType vt, Instruction Inst> : GCNPat<
1783 (node (i8 timm:$tgt), (i8 timm:$en), vt:$src0, vt:$src1, vt:$src2, vt:$src3, (i1 timm:$compr), (i1 timm:$vm)),
1784 (Inst i8:$tgt, vt:$src0, vt:$src1, vt:$src2, vt:$src3, i1:$vm, i1:$compr, i8:$en)
1787 def : ExpPattern<AMDGPUexport, i32, EXP>;
1788 def : ExpPattern<AMDGPUexport_done, i32, EXP_DONE>;
1790 // COPY is workaround tablegen bug from multiple outputs
1791 // from S_LSHL_B32's multiple outputs from implicit scc def.
1793 (v2i16 (build_vector (i16 0), i16:$src1)),
1794 (v2i16 (COPY (S_LSHL_B32 i16:$src1, (i16 16))))
1798 (v2i16 (build_vector i16:$src0, (i16 undef))),
1799 (v2i16 (COPY $src0))
1803 (v2f16 (build_vector f16:$src0, (f16 undef))),
1804 (v2f16 (COPY $src0))
1808 (v2i16 (build_vector (i16 undef), i16:$src1)),
1809 (v2i16 (COPY (S_LSHL_B32 $src1, (i32 16))))
1813 (v2f16 (build_vector (f16 undef), f16:$src1)),
1814 (v2f16 (COPY (S_LSHL_B32 $src1, (i32 16))))
1817 let SubtargetPredicate = HasVOP3PInsts in {
1819 (v2i16 (build_vector i16:$src0, i16:$src1)),
1820 (v2i16 (S_PACK_LL_B32_B16 $src0, $src1))
1823 // With multiple uses of the shift, this will duplicate the shift and
1824 // increase register pressure.
1826 (v2i16 (build_vector i16:$src0, (i16 (trunc (srl_oneuse i32:$src1, (i32 16)))))),
1827 (v2i16 (S_PACK_LH_B32_B16 i16:$src0, i32:$src1))
1832 (v2i16 (build_vector (i16 (trunc (srl_oneuse i32:$src0, (i32 16)))),
1833 (i16 (trunc (srl_oneuse i32:$src1, (i32 16)))))),
1834 (v2i16 (S_PACK_HH_B32_B16 $src0, $src1))
1837 // TODO: Should source modifiers be matched to v_pack_b32_f16?
1839 (v2f16 (build_vector f16:$src0, f16:$src1)),
1840 (v2f16 (S_PACK_LL_B32_B16 $src0, $src1))
1843 } // End SubtargetPredicate = HasVOP3PInsts
1847 (v2f16 (scalar_to_vector f16:$src0)),
1852 (v2i16 (scalar_to_vector i16:$src0)),
1857 (v4i16 (scalar_to_vector i16:$src0)),
1858 (INSERT_SUBREG (IMPLICIT_DEF), $src0, sub0)
1862 (v4f16 (scalar_to_vector f16:$src0)),
1863 (INSERT_SUBREG (IMPLICIT_DEF), $src0, sub0)
1866 //===----------------------------------------------------------------------===//
1868 //===----------------------------------------------------------------------===//
1870 let SubtargetPredicate = isGFX6 in {
1872 // V_FRACT is buggy on SI, so the F32 version is never used and (x-floor(x)) is
1873 // used instead. However, SI doesn't have V_FLOOR_F64, so the most efficient
1874 // way to implement it is using V_FRACT_F64.
1875 // The workaround for the V_FRACT bug is:
1876 // fract(x) = isnan(x) ? x : min(V_FRACT(x), 0.99999999999999999)
1878 // Convert floor(x) to (x - fract(x))
1880 (f64 (ffloor (f64 (VOP3Mods f64:$x, i32:$mods)))),
1885 (V_CNDMASK_B64_PSEUDO
1888 (V_FRACT_F64_e64 $mods, $x, DSTCLAMP.NONE, DSTOMOD.NONE),
1890 (V_MOV_B64_PSEUDO 0x3fefffffffffffff),
1891 DSTCLAMP.NONE, DSTOMOD.NONE),
1893 (V_CMP_CLASS_F64_e64 SRCMODS.NONE, $x, (i32 3 /*NaN*/))),
1894 DSTCLAMP.NONE, DSTOMOD.NONE)
1897 } // End SubtargetPredicates = isGFX6
1899 //============================================================================//
1900 // Miscellaneous Optimization Patterns
1901 //============================================================================//
1903 // Undo sub x, c -> add x, -c canonicalization since c is more likely
1904 // an inline immediate than -c.
1905 // TODO: Also do for 64-bit.
1907 (add i32:$src0, (i32 NegSubInlineConst32:$src1)),
1908 (S_SUB_I32 $src0, NegSubInlineConst32:$src1)
1911 // Avoid pointlessly materializing a constant in VGPR.
1912 // FIXME: Should also do this for readlane, but tablegen crashes on
1913 // the ignored src1.
1915 (int_amdgcn_readfirstlane (i32 imm:$src)),
1919 multiclass BFMPatterns <ValueType vt, InstSI BFM, InstSI MOV> {
1921 (vt (shl (vt (add (vt (shl 1, vt:$a)), -1)), vt:$b)),
1926 (vt (add (vt (shl 1, vt:$a)), -1)),
1927 (BFM $a, (MOV (i32 0)))
1931 defm : BFMPatterns <i32, S_BFM_B32, S_MOV_B32>;
1932 // FIXME: defm : BFMPatterns <i64, S_BFM_B64, S_MOV_B64>;
1934 defm : BFEPattern <V_BFE_U32, V_BFE_I32, S_MOV_B32>;
1935 defm : SHA256MaPattern <V_BFI_B32, V_XOR_B32_e64, SReg_64>;
1937 defm : IntMed3Pat<V_MED3_I32, smin, smax, smin_oneuse, smax_oneuse>;
1938 defm : IntMed3Pat<V_MED3_U32, umin, umax, umin_oneuse, umax_oneuse>;
1940 // This matches 16 permutations of
1941 // max(min(x, y), min(max(x, y), z))
1942 class FPMed3Pat<ValueType vt,
1943 //SDPatternOperator max, SDPatternOperator min,
1944 Instruction med3Inst> : GCNPat<
1945 (fmaxnum_like (fminnum_like_oneuse (VOP3Mods_nnan vt:$src0, i32:$src0_mods),
1946 (VOP3Mods_nnan vt:$src1, i32:$src1_mods)),
1947 (fminnum_like_oneuse (fmaxnum_like_oneuse (VOP3Mods_nnan vt:$src0, i32:$src0_mods),
1948 (VOP3Mods_nnan vt:$src1, i32:$src1_mods)),
1949 (vt (VOP3Mods_nnan vt:$src2, i32:$src2_mods)))),
1950 (med3Inst $src0_mods, $src0, $src1_mods, $src1, $src2_mods, $src2, DSTCLAMP.NONE, DSTOMOD.NONE)
1953 class FP16Med3Pat<ValueType vt,
1954 Instruction med3Inst> : GCNPat<
1955 (fmaxnum_like (fminnum_like_oneuse (VOP3Mods_nnan vt:$src0, i32:$src0_mods),
1956 (VOP3Mods_nnan vt:$src1, i32:$src1_mods)),
1957 (fminnum_like_oneuse (fmaxnum_like_oneuse (VOP3Mods_nnan vt:$src0, i32:$src0_mods),
1958 (VOP3Mods_nnan vt:$src1, i32:$src1_mods)),
1959 (vt (VOP3Mods_nnan vt:$src2, i32:$src2_mods)))),
1960 (med3Inst $src0_mods, $src0, $src1_mods, $src1, $src2_mods, $src2, DSTCLAMP.NONE)
1963 multiclass Int16Med3Pat<Instruction med3Inst,
1964 SDPatternOperator min,
1965 SDPatternOperator max,
1966 SDPatternOperator max_oneuse,
1967 SDPatternOperator min_oneuse,
1968 ValueType vt = i16> {
1969 // This matches 16 permutations of
1970 // max(min(x, y), min(max(x, y), z))
1972 (max (min_oneuse vt:$src0, vt:$src1),
1973 (min_oneuse (max_oneuse vt:$src0, vt:$src1), vt:$src2)),
1974 (med3Inst SRCMODS.NONE, $src0, SRCMODS.NONE, $src1, SRCMODS.NONE, $src2, DSTCLAMP.NONE)
1977 // This matches 16 permutations of
1978 // min(max(a, b), max(min(a, b), c))
1980 (min (max_oneuse vt:$src0, vt:$src1),
1981 (max_oneuse (min_oneuse vt:$src0, vt:$src1), vt:$src2)),
1982 (med3Inst SRCMODS.NONE, $src0, SRCMODS.NONE, $src1, SRCMODS.NONE, $src2, DSTCLAMP.NONE)
1986 def : FPMed3Pat<f32, V_MED3_F32>;
1988 let OtherPredicates = [isGFX9Plus] in {
1989 def : FP16Med3Pat<f16, V_MED3_F16>;
1990 defm : Int16Med3Pat<V_MED3_I16, smin, smax, smax_oneuse, smin_oneuse>;
1991 defm : Int16Med3Pat<V_MED3_U16, umin, umax, umax_oneuse, umin_oneuse>;
1992 } // End Predicates = [isGFX9Plus]