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>;
37 def gi_vop3omods0clamp0omod :
38 GIComplexOperandMatcher<s32, "selectVOP3Mods0Clamp0OMod">,
39 GIComplexPatternEquiv<VOP3Mods0Clamp0OMod>;
41 def gi_vop3opselmods0 :
42 GIComplexOperandMatcher<s32, "selectVOP3OpSelMods0">,
43 GIComplexPatternEquiv<VOP3OpSelMods0>;
45 def gi_vop3opselmods :
46 GIComplexOperandMatcher<s32, "selectVOP3OpSelMods">,
47 GIComplexPatternEquiv<VOP3OpSelMods>;
50 GIComplexOperandMatcher<s64, "selectSmrdImm">,
51 GIComplexPatternEquiv<SMRDImm>;
54 GIComplexOperandMatcher<s64, "selectSmrdImm32">,
55 GIComplexPatternEquiv<SMRDImm32>;
58 GIComplexOperandMatcher<s64, "selectSmrdSgpr">,
59 GIComplexPatternEquiv<SMRDSgpr>;
61 // FIXME: Why are the atomic versions separated?
63 GIComplexOperandMatcher<s64, "selectFlatOffset">,
64 GIComplexPatternEquiv<FLATOffset>;
65 def gi_flat_offset_signed :
66 GIComplexOperandMatcher<s64, "selectFlatOffsetSigned">,
67 GIComplexPatternEquiv<FLATOffsetSigned>;
69 GIComplexOperandMatcher<s64, "selectFlatOffset">,
70 GIComplexPatternEquiv<FLATAtomic>;
71 def gi_flat_signed_atomic :
72 GIComplexOperandMatcher<s64, "selectFlatOffsetSigned">,
73 GIComplexPatternEquiv<FLATSignedAtomic>;
75 def gi_mubuf_scratch_offset :
76 GIComplexOperandMatcher<s32, "selectMUBUFScratchOffset">,
77 GIComplexPatternEquiv<MUBUFScratchOffset>;
78 def gi_mubuf_scratch_offen :
79 GIComplexOperandMatcher<s32, "selectMUBUFScratchOffen">,
80 GIComplexPatternEquiv<MUBUFScratchOffen>;
82 def gi_ds_1addr_1offset :
83 GIComplexOperandMatcher<s32, "selectDS1Addr1Offset">,
84 GIComplexPatternEquiv<DS1Addr1Offset>;
87 // Separate load nodes are defined to glue m0 initialization in
88 // SelectionDAG. The GISel selector can just insert m0 initialization
89 // directly before before selecting a glue-less load, so hide this
92 def : GINodeEquiv<G_LOAD, AMDGPUld_glue> {
93 let CheckMMOIsNonAtomic = 1;
96 def : GINodeEquiv<G_STORE, AMDGPUst_glue> {
97 let CheckMMOIsNonAtomic = 1;
100 def : GINodeEquiv<G_LOAD, AMDGPUatomic_ld_glue> {
101 bit CheckMMOIsAtomic = 1;
106 def : GINodeEquiv<G_ATOMIC_CMPXCHG, atomic_cmp_swap_glue>;
107 def : GINodeEquiv<G_ATOMICRMW_XCHG, atomic_swap_glue>;
108 def : GINodeEquiv<G_ATOMICRMW_ADD, atomic_load_add_glue>;
109 def : GINodeEquiv<G_ATOMICRMW_SUB, atomic_load_sub_glue>;
110 def : GINodeEquiv<G_ATOMICRMW_AND, atomic_load_and_glue>;
111 def : GINodeEquiv<G_ATOMICRMW_OR, atomic_load_or_glue>;
112 def : GINodeEquiv<G_ATOMICRMW_XOR, atomic_load_xor_glue>;
113 def : GINodeEquiv<G_ATOMICRMW_MIN, atomic_load_min_glue>;
114 def : GINodeEquiv<G_ATOMICRMW_MAX, atomic_load_max_glue>;
115 def : GINodeEquiv<G_ATOMICRMW_UMIN, atomic_load_umin_glue>;
116 def : GINodeEquiv<G_ATOMICRMW_UMAX, atomic_load_umax_glue>;
117 def : GINodeEquiv<G_ATOMICRMW_FADD, atomic_load_fadd_glue>;
121 SDPatternOperator node,
124 ValueType src0_vt = dst_vt, ValueType src1_vt = src0_vt> : GCNPat <
126 (dst_vt (node (src0_vt SReg_32:$src0), (src1_vt SReg_32:$src1))),
127 (inst src0_vt:$src0, src1_vt:$src1)
131 SDPatternOperator node,
134 ValueType src0_vt = dst_vt, ValueType src1_vt = src0_vt> : GCNPat <
136 (dst_vt (node (src0_vt (sd_vsrc0 src0_vt:$src0)), (src1_vt VGPR_32:$src1))),
137 (inst src0_vt:$src0, src1_vt:$src1)
140 class GISelVop2CommutePat <
141 SDPatternOperator node,
144 ValueType src0_vt = dst_vt, ValueType src1_vt = src0_vt> : GCNPat <
146 (dst_vt (node (src1_vt VGPR_32:$src1), (src0_vt (sd_vsrc0 src0_vt:$src0)))),
147 (inst src0_vt:$src0, src1_vt:$src1)
150 class GISelVop3Pat2 <
151 SDPatternOperator node,
154 ValueType src0_vt = dst_vt, ValueType src1_vt = src0_vt> : GCNPat <
156 (dst_vt (node (src0_vt (sd_vcsrc src0_vt:$src0)), (src1_vt (sd_vcsrc src1_vt:$src1)))),
157 (inst src0_vt:$src0, src1_vt:$src1)
160 class GISelVop3Pat2CommutePat <
161 SDPatternOperator node,
164 ValueType src0_vt = dst_vt, ValueType src1_vt = src0_vt> : GCNPat <
166 (dst_vt (node (src0_vt (sd_vcsrc src0_vt:$src0)), (src1_vt (sd_vcsrc src1_vt:$src1)))),
167 (inst src0_vt:$src1, src1_vt:$src0)
170 class GISelVop3Pat2ModsPat <
171 SDPatternOperator node,
174 ValueType src0_vt = dst_vt, ValueType src1_vt = src0_vt> : GCNPat <
176 (dst_vt (node (src0_vt (VOP3Mods0 src0_vt:$src0, i32:$src0_modifiers, i1:$clamp, i32:$omods)),
177 (src1_vt (VOP3Mods src1_vt:$src1, i32:$src1_modifiers)))),
178 (inst i32:$src0_modifiers, src0_vt:$src0,
179 i32:$src1_modifiers, src1_vt:$src1, $clamp, $omods)
182 multiclass GISelVop2IntrPat <
183 SDPatternOperator node, Instruction inst,
184 ValueType dst_vt, ValueType src_vt = dst_vt> {
186 def : GISelVop2Pat <node, inst, dst_vt, src_vt>;
188 // FIXME: Intrinsics aren't marked as commutable, so we need to add an explcit
189 // pattern to handle commuting. This is another reason why legalizing to a
190 // generic machine instruction may be better that matching the intrinsic
192 def : GISelVop2CommutePat <node, inst, dst_vt, src_vt>;
195 def : GISelSop2Pat <or, S_OR_B32, i32>;
196 def : GISelVop2Pat <or, V_OR_B32_e32, i32>;
198 // Since GlobalISel is more flexible then SelectionDAG, I think we can get
199 // away with adding patterns for integer types and not legalizing all
200 // loads and stores to vector types. This should help simplify the load/store
202 foreach Ty = [i64, p0, p1, p4] in {
203 defm : SMRD_Pattern <"S_LOAD_DWORDX2", Ty>;
206 def gi_as_i32timm : GICustomOperandRenderer<"renderTruncImm32">,
207 GISDNodeXFormEquiv<as_i32timm>;