[docs] Fix build-docs.sh
[llvm-project.git] / llvm / unittests / CodeGen / GlobalISel / GISelUtilsTest.cpp
blobab174403c13c7838f735a54918707eaff7ad44c1
1 //===- GISelUtilsTest.cpp -------------------------------------------------===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
9 #include "llvm/CodeGen/GlobalISel/Utils.h"
10 #include "gtest/gtest.h"
12 using namespace llvm;
14 namespace {
15 static const LLT S1 = LLT::scalar(1);
16 static const LLT S8 = LLT::scalar(8);
17 static const LLT S16 = LLT::scalar(16);
18 static const LLT S32 = LLT::scalar(32);
19 static const LLT S64 = LLT::scalar(64);
20 static const LLT P0 = LLT::pointer(0, 64);
21 static const LLT P1 = LLT::pointer(1, 32);
23 static const LLT V2S8 = LLT::fixed_vector(2, 8);
24 static const LLT V4S8 = LLT::fixed_vector(4, 8);
25 static const LLT V8S8 = LLT::fixed_vector(8, 8);
27 static const LLT V2S16 = LLT::fixed_vector(2, 16);
28 static const LLT V3S16 = LLT::fixed_vector(3, 16);
29 static const LLT V4S16 = LLT::fixed_vector(4, 16);
31 static const LLT V2S32 = LLT::fixed_vector(2, 32);
32 static const LLT V3S32 = LLT::fixed_vector(3, 32);
33 static const LLT V4S32 = LLT::fixed_vector(4, 32);
34 static const LLT V6S32 = LLT::fixed_vector(6, 32);
36 static const LLT V2S64 = LLT::fixed_vector(2, 64);
37 static const LLT V3S64 = LLT::fixed_vector(3, 64);
38 static const LLT V4S64 = LLT::fixed_vector(4, 64);
40 static const LLT V2P0 = LLT::fixed_vector(2, P0);
41 static const LLT V3P0 = LLT::fixed_vector(3, P0);
42 static const LLT V4P0 = LLT::fixed_vector(4, P0);
43 static const LLT V6P0 = LLT::fixed_vector(6, P0);
45 static const LLT V2P1 = LLT::fixed_vector(2, P1);
46 static const LLT V4P1 = LLT::fixed_vector(4, P1);
48 TEST(GISelUtilsTest, getGCDType) {
49 EXPECT_EQ(S1, getGCDType(S1, S1));
50 EXPECT_EQ(S32, getGCDType(S32, S32));
51 EXPECT_EQ(S1, getGCDType(S1, S32));
52 EXPECT_EQ(S1, getGCDType(S32, S1));
53 EXPECT_EQ(S16, getGCDType(S16, S32));
54 EXPECT_EQ(S16, getGCDType(S32, S16));
56 EXPECT_EQ(V2S32, getGCDType(V2S32, V2S32));
57 EXPECT_EQ(S32, getGCDType(V3S32, V2S32));
58 EXPECT_EQ(S32, getGCDType(V2S32, V3S32));
60 EXPECT_EQ(V2S16, getGCDType(V4S16, V2S16));
61 EXPECT_EQ(V2S16, getGCDType(V2S16, V4S16));
63 EXPECT_EQ(V2S32, getGCDType(V4S32, V2S32));
64 EXPECT_EQ(V2S32, getGCDType(V2S32, V4S32));
66 EXPECT_EQ(S16, getGCDType(P0, S16));
67 EXPECT_EQ(S16, getGCDType(S16, P0));
69 EXPECT_EQ(S32, getGCDType(P0, S32));
70 EXPECT_EQ(S32, getGCDType(S32, P0));
72 EXPECT_EQ(P0, getGCDType(P0, S64));
73 EXPECT_EQ(S64, getGCDType(S64, P0));
75 EXPECT_EQ(S32, getGCDType(P0, P1));
76 EXPECT_EQ(S32, getGCDType(P1, P0));
78 EXPECT_EQ(P0, getGCDType(V3P0, V2P0));
79 EXPECT_EQ(P0, getGCDType(V2P0, V3P0));
81 EXPECT_EQ(P0, getGCDType(P0, V2P0));
82 EXPECT_EQ(P0, getGCDType(V2P0, P0));
85 EXPECT_EQ(V2P0, getGCDType(V2P0, V2P0));
86 EXPECT_EQ(P0, getGCDType(V3P0, V2P0));
87 EXPECT_EQ(P0, getGCDType(V2P0, V3P0));
88 EXPECT_EQ(V2P0, getGCDType(V4P0, V2P0));
90 EXPECT_EQ(V2P0, getGCDType(V2P0, V4P1));
91 EXPECT_EQ(V4P1, getGCDType(V4P1, V2P0));
93 EXPECT_EQ(V2P0, getGCDType(V4P0, V4P1));
94 EXPECT_EQ(V4P1, getGCDType(V4P1, V4P0));
96 // Elements have same size, but have different pointeriness, so prefer the
97 // original element type.
98 EXPECT_EQ(V2P0, getGCDType(V2P0, V4S64));
99 EXPECT_EQ(V2S64, getGCDType(V4S64, V2P0));
101 EXPECT_EQ(V2S16, getGCDType(V2S16, V4P1));
102 EXPECT_EQ(P1, getGCDType(V4P1, V2S16));
103 EXPECT_EQ(V2P1, getGCDType(V4P1, V4S16));
104 EXPECT_EQ(V4S16, getGCDType(V4S16, V2P1));
106 EXPECT_EQ(P0, getGCDType(P0, V2S64));
107 EXPECT_EQ(S64, getGCDType(V2S64, P0));
109 EXPECT_EQ(S16, getGCDType(V2S16, V3S16));
110 EXPECT_EQ(S16, getGCDType(V3S16, V2S16));
111 EXPECT_EQ(S16, getGCDType(V3S16, S16));
112 EXPECT_EQ(S16, getGCDType(S16, V3S16));
114 EXPECT_EQ(V2S16, getGCDType(V2S16, V2S32));
115 EXPECT_EQ(S32, getGCDType(V2S32, V2S16));
117 EXPECT_EQ(V4S8, getGCDType(V4S8, V2S32));
118 EXPECT_EQ(S32, getGCDType(V2S32, V4S8));
120 // Test cases where neither element type nicely divides.
121 EXPECT_EQ(LLT::scalar(3),
122 getGCDType(LLT::fixed_vector(3, 5), LLT::fixed_vector(2, 6)));
123 EXPECT_EQ(LLT::scalar(3),
124 getGCDType(LLT::fixed_vector(2, 6), LLT::fixed_vector(3, 5)));
126 // Have to go smaller than a pointer element.
127 EXPECT_EQ(LLT::scalar(3), getGCDType(LLT::fixed_vector(2, LLT::pointer(3, 6)),
128 LLT::fixed_vector(3, 5)));
129 EXPECT_EQ(LLT::scalar(3),
130 getGCDType(LLT::fixed_vector(3, 5),
131 LLT::fixed_vector(2, LLT::pointer(3, 6))));
133 EXPECT_EQ(V4S8, getGCDType(V4S8, S32));
134 EXPECT_EQ(S32, getGCDType(S32, V4S8));
135 EXPECT_EQ(V4S8, getGCDType(V4S8, P1));
136 EXPECT_EQ(P1, getGCDType(P1, V4S8));
138 EXPECT_EQ(V2S8, getGCDType(V2S8, V4S16));
139 EXPECT_EQ(S16, getGCDType(V4S16, V2S8));
141 EXPECT_EQ(S8, getGCDType(V2S8, LLT::fixed_vector(4, 2)));
142 EXPECT_EQ(LLT::fixed_vector(4, 2), getGCDType(LLT::fixed_vector(4, 2), S8));
144 EXPECT_EQ(LLT::pointer(4, 8),
145 getGCDType(LLT::fixed_vector(2, LLT::pointer(4, 8)),
146 LLT::fixed_vector(4, 2)));
148 EXPECT_EQ(LLT::fixed_vector(4, 2),
149 getGCDType(LLT::fixed_vector(4, 2),
150 LLT::fixed_vector(2, LLT::pointer(4, 8))));
152 EXPECT_EQ(LLT::scalar(4), getGCDType(LLT::fixed_vector(3, 4), S8));
153 EXPECT_EQ(LLT::scalar(4), getGCDType(S8, LLT::fixed_vector(3, 4)));
156 TEST(GISelUtilsTest, getLCMType) {
157 EXPECT_EQ(S1, getLCMType(S1, S1));
158 EXPECT_EQ(S32, getLCMType(S32, S1));
159 EXPECT_EQ(S32, getLCMType(S1, S32));
160 EXPECT_EQ(S32, getLCMType(S32, S32));
162 EXPECT_EQ(S32, getLCMType(S32, S16));
163 EXPECT_EQ(S32, getLCMType(S16, S32));
165 EXPECT_EQ(S64, getLCMType(S64, P0));
166 EXPECT_EQ(P0, getLCMType(P0, S64));
168 EXPECT_EQ(P0, getLCMType(S32, P0));
169 EXPECT_EQ(P0, getLCMType(P0, S32));
171 EXPECT_EQ(S32, getLCMType(S32, P1));
172 EXPECT_EQ(P1, getLCMType(P1, S32));
173 EXPECT_EQ(P0, getLCMType(P0, P0));
174 EXPECT_EQ(P1, getLCMType(P1, P1));
176 EXPECT_EQ(P0, getLCMType(P0, P1));
177 EXPECT_EQ(P0, getLCMType(P1, P0));
179 EXPECT_EQ(V2S32, getLCMType(V2S32, V2S32));
180 EXPECT_EQ(V2S32, getLCMType(V2S32, S32));
181 EXPECT_EQ(V2S32, getLCMType(S32, V2S32));
182 EXPECT_EQ(V2S32, getLCMType(V2S32, V2S32));
183 EXPECT_EQ(V6S32, getLCMType(V2S32, V3S32));
184 EXPECT_EQ(V6S32, getLCMType(V3S32, V2S32));
185 EXPECT_EQ(LLT::fixed_vector(12, S32), getLCMType(V4S32, V3S32));
186 EXPECT_EQ(LLT::fixed_vector(12, S32), getLCMType(V3S32, V4S32));
188 EXPECT_EQ(V2P0, getLCMType(V2P0, V2P0));
189 EXPECT_EQ(V2P0, getLCMType(V2P0, P0));
190 EXPECT_EQ(V2P0, getLCMType(P0, V2P0));
191 EXPECT_EQ(V2P0, getLCMType(V2P0, V2P0));
192 EXPECT_EQ(V6P0, getLCMType(V2P0, V3P0));
193 EXPECT_EQ(V6P0, getLCMType(V3P0, V2P0));
194 EXPECT_EQ(LLT::fixed_vector(12, P0), getLCMType(V4P0, V3P0));
195 EXPECT_EQ(LLT::fixed_vector(12, P0), getLCMType(V3P0, V4P0));
197 EXPECT_EQ(LLT::fixed_vector(12, S64), getLCMType(V4S64, V3P0));
198 EXPECT_EQ(LLT::fixed_vector(12, P0), getLCMType(V3P0, V4S64));
200 EXPECT_EQ(LLT::fixed_vector(12, P0), getLCMType(V4P0, V3S64));
201 EXPECT_EQ(LLT::fixed_vector(12, S64), getLCMType(V3S64, V4P0));
203 EXPECT_EQ(V2P0, getLCMType(V2P0, S32));
204 EXPECT_EQ(V4S32, getLCMType(S32, V2P0));
205 EXPECT_EQ(V2P0, getLCMType(V2P0, S64));
206 EXPECT_EQ(V2S64, getLCMType(S64, V2P0));
209 EXPECT_EQ(V2P0, getLCMType(V2P0, V2P1));
210 EXPECT_EQ(V4P1, getLCMType(V2P1, V2P0));
212 EXPECT_EQ(V2P0, getLCMType(V2P0, V4P1));
213 EXPECT_EQ(V4P1, getLCMType(V4P1, V2P0));
216 EXPECT_EQ(V2S32, getLCMType(V2S32, S64));
217 EXPECT_EQ(S64, getLCMType(S64, V2S32));
219 EXPECT_EQ(V4S16, getLCMType(V4S16, V2S32));
220 EXPECT_EQ(V2S32, getLCMType(V2S32, V4S16));
222 EXPECT_EQ(V2S32, getLCMType(V2S32, V4S8));
223 EXPECT_EQ(V8S8, getLCMType(V4S8, V2S32));
225 EXPECT_EQ(V2S16, getLCMType(V2S16, V4S8));
226 EXPECT_EQ(V4S8, getLCMType(V4S8, V2S16));
228 EXPECT_EQ(LLT::fixed_vector(6, S16), getLCMType(V3S16, V4S8));
229 EXPECT_EQ(LLT::fixed_vector(12, S8), getLCMType(V4S8, V3S16));
230 EXPECT_EQ(V4S16, getLCMType(V4S16, V4S8));
231 EXPECT_EQ(V8S8, getLCMType(V4S8, V4S16));
233 EXPECT_EQ(LLT::fixed_vector(6, 4), getLCMType(LLT::fixed_vector(3, 4), S8));
234 EXPECT_EQ(LLT::fixed_vector(3, 8), getLCMType(S8, LLT::fixed_vector(3, 4)));
236 EXPECT_EQ(LLT::fixed_vector(6, 4),
237 getLCMType(LLT::fixed_vector(3, 4), LLT::pointer(4, 8)));
238 EXPECT_EQ(LLT::fixed_vector(3, LLT::pointer(4, 8)),
239 getLCMType(LLT::pointer(4, 8), LLT::fixed_vector(3, 4)));
241 EXPECT_EQ(V2S64, getLCMType(V2S64, P0));
242 EXPECT_EQ(V2P0, getLCMType(P0, V2S64));
244 EXPECT_EQ(V2S64, getLCMType(V2S64, P1));
245 EXPECT_EQ(V4P1, getLCMType(P1, V2S64));