1 //===-- AMDGPUGIsel.td - AMDGPU GlobalISel Patterns---------*- tablegen -*-===//
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 files contains patterns that should only be used by GlobalISel. For
9 // example patterns for V_* instructions that have S_* equivalents.
10 // SelectionDAG does not support selecting V_* instructions.
11 //===----------------------------------------------------------------------===//
15 def sd_vsrc0 : ComplexPattern<i32, 1, "">;
17 GIComplexOperandMatcher<s32, "selectVSRC0">,
18 GIComplexPatternEquiv<sd_vsrc0>;
20 def sd_vcsrc : ComplexPattern<i32, 1, "">;
22 GIComplexOperandMatcher<s32, "selectVCSRC">,
23 GIComplexPatternEquiv<sd_vcsrc>;
26 GIComplexOperandMatcher<s32, "selectVOP3Mods0">,
27 GIComplexPatternEquiv<VOP3Mods0>;
30 GIComplexOperandMatcher<s32, "selectVOP3Mods">,
31 GIComplexPatternEquiv<VOP3Mods>;
34 GIComplexOperandMatcher<s32, "selectVOP3OMods">,
35 GIComplexPatternEquiv<VOP3OMods>;
38 GIComplexOperandMatcher<s64, "selectSmrdImm">,
39 GIComplexPatternEquiv<SMRDImm>;
42 GIComplexOperandMatcher<s64, "selectSmrdImm32">,
43 GIComplexPatternEquiv<SMRDImm32>;
46 GIComplexOperandMatcher<s64, "selectSmrdSgpr">,
47 GIComplexPatternEquiv<SMRDSgpr>;
50 GIComplexOperandMatcher<s64, "selectFlatOffset">,
51 GIComplexPatternEquiv<FLATOffset>;
52 def gi_flat_offset_signed :
53 GIComplexOperandMatcher<s64, "selectFlatOffsetSigned">,
54 GIComplexPatternEquiv<FLATOffsetSigned>;
56 def gi_mubuf_scratch_offset :
57 GIComplexOperandMatcher<s32, "selectMUBUFScratchOffset">,
58 GIComplexPatternEquiv<MUBUFScratchOffset>;
59 def gi_mubuf_scratch_offen :
60 GIComplexOperandMatcher<s32, "selectMUBUFScratchOffen">,
61 GIComplexPatternEquiv<MUBUFScratchOffen>;
63 def gi_ds_1addr_1offset :
64 GIComplexOperandMatcher<s32, "selectDS1Addr1Offset">,
65 GIComplexPatternEquiv<DS1Addr1Offset>;
68 // Separate load nodes are defined to glue m0 initialization in
69 // SelectionDAG. The GISel selector can just insert m0 initialization
70 // directly before before selecting a glue-less load, so hide this
72 def : GINodeEquiv<G_LOAD, AMDGPUld_glue>;
73 def : GINodeEquiv<G_STORE, AMDGPUst_glue>;
75 def : GINodeEquiv<G_ATOMIC_CMPXCHG, atomic_cmp_swap_glue>;
76 def : GINodeEquiv<G_ATOMICRMW_XCHG, atomic_swap_glue>;
77 def : GINodeEquiv<G_ATOMICRMW_ADD, atomic_load_add_glue>;
78 def : GINodeEquiv<G_ATOMICRMW_SUB, atomic_load_sub_glue>;
79 def : GINodeEquiv<G_ATOMICRMW_AND, atomic_load_and_glue>;
80 def : GINodeEquiv<G_ATOMICRMW_OR, atomic_load_or_glue>;
81 def : GINodeEquiv<G_ATOMICRMW_XOR, atomic_load_xor_glue>;
82 def : GINodeEquiv<G_ATOMICRMW_MIN, atomic_load_min_glue>;
83 def : GINodeEquiv<G_ATOMICRMW_MAX, atomic_load_max_glue>;
84 def : GINodeEquiv<G_ATOMICRMW_UMIN, atomic_load_umin_glue>;
85 def : GINodeEquiv<G_ATOMICRMW_UMAX, atomic_load_umax_glue>;
86 def : GINodeEquiv<G_ATOMICRMW_FADD, atomic_load_fadd_glue>;
90 SDPatternOperator node,
93 ValueType src0_vt = dst_vt, ValueType src1_vt = src0_vt> : GCNPat <
95 (dst_vt (node (src0_vt SReg_32:$src0), (src1_vt SReg_32:$src1))),
96 (inst src0_vt:$src0, src1_vt:$src1)
100 SDPatternOperator node,
103 ValueType src0_vt = dst_vt, ValueType src1_vt = src0_vt> : GCNPat <
105 (dst_vt (node (src0_vt (sd_vsrc0 src0_vt:$src0)), (src1_vt VGPR_32:$src1))),
106 (inst src0_vt:$src0, src1_vt:$src1)
109 class GISelVop2CommutePat <
110 SDPatternOperator node,
113 ValueType src0_vt = dst_vt, ValueType src1_vt = src0_vt> : GCNPat <
115 (dst_vt (node (src1_vt VGPR_32:$src1), (src0_vt (sd_vsrc0 src0_vt:$src0)))),
116 (inst src0_vt:$src0, src1_vt:$src1)
119 class GISelVop3Pat2 <
120 SDPatternOperator node,
123 ValueType src0_vt = dst_vt, ValueType src1_vt = src0_vt> : GCNPat <
125 (dst_vt (node (src0_vt (sd_vcsrc src0_vt:$src0)), (src1_vt (sd_vcsrc src1_vt:$src1)))),
126 (inst src0_vt:$src0, src1_vt:$src1)
129 class GISelVop3Pat2CommutePat <
130 SDPatternOperator node,
133 ValueType src0_vt = dst_vt, ValueType src1_vt = src0_vt> : GCNPat <
135 (dst_vt (node (src0_vt (sd_vcsrc src0_vt:$src0)), (src1_vt (sd_vcsrc src1_vt:$src1)))),
136 (inst src0_vt:$src1, src1_vt:$src0)
139 class GISelVop3Pat2ModsPat <
140 SDPatternOperator node,
143 ValueType src0_vt = dst_vt, ValueType src1_vt = src0_vt> : GCNPat <
145 (dst_vt (node (src0_vt (VOP3Mods0 src0_vt:$src0, i32:$src0_modifiers, i1:$clamp, i32:$omods)),
146 (src1_vt (VOP3Mods src1_vt:$src1, i32:$src1_modifiers)))),
147 (inst i32:$src0_modifiers, src0_vt:$src0,
148 i32:$src1_modifiers, src1_vt:$src1, $clamp, $omods)
151 multiclass GISelVop2IntrPat <
152 SDPatternOperator node, Instruction inst,
153 ValueType dst_vt, ValueType src_vt = dst_vt> {
155 def : GISelVop2Pat <node, inst, dst_vt, src_vt>;
157 // FIXME: Intrinsics aren't marked as commutable, so we need to add an explcit
158 // pattern to handle commuting. This is another reason why legalizing to a
159 // generic machine instruction may be better that matching the intrinsic
161 def : GISelVop2CommutePat <node, inst, dst_vt, src_vt>;
164 def : GISelSop2Pat <or, S_OR_B32, i32>;
165 def : GISelVop2Pat <or, V_OR_B32_e32, i32>;
167 // FIXME: We can't re-use SelectionDAG patterns here because they match
168 // against a custom SDNode and we would need to create a generic machine
169 // instruction that is equivalent to the custom SDNode. This would also require
170 // us to custom legalize the intrinsic to the new generic machine instruction,
171 // but I can't get custom legalizing of intrinsic to work and I'm not sure if
172 // this is even supported yet.
173 def : GISelVop3Pat2ModsPat <
174 int_amdgcn_cvt_pkrtz, V_CVT_PKRTZ_F16_F32_e64, v2f16, f32>;
176 defm : GISelVop2IntrPat <int_maxnum, V_MAX_F32_e32, f32>;
177 def : GISelVop3Pat2ModsPat <int_maxnum, V_MAX_F64, f64>;
178 defm : GISelVop2IntrPat <int_minnum, V_MIN_F32_e32, f32>;
179 def : GISelVop3Pat2ModsPat <int_minnum, V_MIN_F64, f64>;
181 // Since GlobalISel is more flexible then SelectionDAG, I think we can get
182 // away with adding patterns for integer types and not legalizing all
183 // loads and stores to vector types. This should help simplify the load/store
185 foreach Ty = [i64, p0, p1, p4] in {
186 defm : SMRD_Pattern <"S_LOAD_DWORDX2", Ty>;