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 SDPatternOperator node,
41 ValueType src0_vt = dst_vt, ValueType src1_vt = src0_vt> : GCNPat <
43 (dst_vt (node (src0_vt SReg_32:$src0), (src1_vt SReg_32:$src1))),
44 (inst src0_vt:$src0, src1_vt:$src1)
48 SDPatternOperator node,
51 ValueType src0_vt = dst_vt, ValueType src1_vt = src0_vt> : GCNPat <
53 (dst_vt (node (src0_vt (sd_vsrc0 src0_vt:$src0)), (src1_vt VGPR_32:$src1))),
54 (inst src0_vt:$src0, src1_vt:$src1)
57 class GISelVop2CommutePat <
58 SDPatternOperator node,
61 ValueType src0_vt = dst_vt, ValueType src1_vt = src0_vt> : GCNPat <
63 (dst_vt (node (src1_vt VGPR_32:$src1), (src0_vt (sd_vsrc0 src0_vt:$src0)))),
64 (inst src0_vt:$src0, src1_vt:$src1)
68 SDPatternOperator node,
71 ValueType src0_vt = dst_vt, ValueType src1_vt = src0_vt> : GCNPat <
73 (dst_vt (node (src0_vt (sd_vcsrc src0_vt:$src0)), (src1_vt (sd_vcsrc src1_vt:$src1)))),
74 (inst src0_vt:$src0, src1_vt:$src1)
77 class GISelVop3Pat2CommutePat <
78 SDPatternOperator node,
81 ValueType src0_vt = dst_vt, ValueType src1_vt = src0_vt> : GCNPat <
83 (dst_vt (node (src0_vt (sd_vcsrc src0_vt:$src0)), (src1_vt (sd_vcsrc src1_vt:$src1)))),
84 (inst src0_vt:$src1, src1_vt:$src0)
87 class GISelVop3Pat2ModsPat <
88 SDPatternOperator node,
91 ValueType src0_vt = dst_vt, ValueType src1_vt = src0_vt> : GCNPat <
93 (dst_vt (node (src0_vt (VOP3Mods0 src0_vt:$src0, i32:$src0_modifiers, i1:$clamp, i32:$omods)),
94 (src1_vt (VOP3Mods src1_vt:$src1, i32:$src1_modifiers)))),
95 (inst i32:$src0_modifiers, src0_vt:$src0,
96 i32:$src1_modifiers, src1_vt:$src1, $clamp, $omods)
99 multiclass GISelVop2IntrPat <
100 SDPatternOperator node, Instruction inst,
101 ValueType dst_vt, ValueType src_vt = dst_vt> {
103 def : GISelVop2Pat <node, inst, dst_vt, src_vt>;
105 // FIXME: Intrinsics aren't marked as commutable, so we need to add an explcit
106 // pattern to handle commuting. This is another reason why legalizing to a
107 // generic machine instruction may be better that matching the intrinsic
109 def : GISelVop2CommutePat <node, inst, dst_vt, src_vt>;
112 def : GISelSop2Pat <or, S_OR_B32, i32>;
113 def : GISelVop2Pat <or, V_OR_B32_e32, i32>;
115 def : GISelSop2Pat <sra, S_ASHR_I32, i32>;
116 let AddedComplexity = 100 in {
117 let SubtargetPredicate = isSICI in {
118 def : GISelVop2Pat <sra, V_ASHR_I32_e32, i32>;
120 def : GISelVop2CommutePat <sra, V_ASHRREV_I32_e32, i32>;
122 def : GISelVop3Pat2CommutePat <sra, V_ASHRREV_I32_e64, i32>;
124 // FIXME: We can't re-use SelectionDAG patterns here because they match
125 // against a custom SDNode and we would need to create a generic machine
126 // instruction that is equivalent to the custom SDNode. This would also require
127 // us to custom legalize the intrinsic to the new generic machine instruction,
128 // but I can't get custom legalizing of intrinsic to work and I'm not sure if
129 // this is even supported yet.
130 def : GISelVop3Pat2ModsPat <
131 int_amdgcn_cvt_pkrtz, V_CVT_PKRTZ_F16_F32_e64, v2f16, f32>;
133 defm : GISelVop2IntrPat <int_maxnum, V_MAX_F32_e32, f32>;
134 def : GISelVop3Pat2ModsPat <int_maxnum, V_MAX_F64, f64>;
135 defm : GISelVop2IntrPat <int_minnum, V_MIN_F32_e32, f32>;
136 def : GISelVop3Pat2ModsPat <int_minnum, V_MIN_F64, f64>;