1 | //===- llvm/unittest/CodeGen/GlobalISel/LowLevelTypeTest.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 | //===----------------------------------------------------------------------===// |
8 | |
9 | #include "llvm/CodeGen/LowLevelTypeUtils.h" |
10 | #include "llvm/IR/DataLayout.h" |
11 | #include "llvm/IR/DerivedTypes.h" |
12 | #include "llvm/IR/LLVMContext.h" |
13 | #include "llvm/IR/Type.h" |
14 | #include "llvm/Support/TypeSize.h" |
15 | #include "gtest/gtest.h" |
16 | |
17 | using namespace llvm; |
18 | |
19 | namespace { |
20 | |
21 | TEST(LowLevelTypeTest, Token) { |
22 | LLVMContext C; |
23 | DataLayout DL("" ); |
24 | |
25 | const LLT TTy = LLT::token(); |
26 | |
27 | // Test kind. |
28 | EXPECT_TRUE(TTy.isValid()); |
29 | EXPECT_TRUE(TTy.isScalar()); |
30 | EXPECT_TRUE(TTy.isToken()); |
31 | |
32 | EXPECT_FALSE(TTy.isPointer()); |
33 | EXPECT_FALSE(TTy.isVector()); |
34 | |
35 | const LLT STy = LLT::scalar(SizeInBits: 0); |
36 | EXPECT_EQ(STy, TTy); |
37 | } |
38 | |
39 | TEST(LowLevelTypeTest, Scalar) { |
40 | LLVMContext C; |
41 | DataLayout DL("" ); |
42 | |
43 | for (unsigned S : {0U, 1U, 17U, 32U, 64U, 0xfffffU}) { |
44 | const LLT Ty = LLT::scalar(SizeInBits: S); |
45 | |
46 | // Test kind. |
47 | ASSERT_TRUE(Ty.isValid()); |
48 | ASSERT_TRUE(Ty.isScalar()); |
49 | |
50 | ASSERT_FALSE(Ty.isPointer()); |
51 | ASSERT_FALSE(Ty.isVector()); |
52 | |
53 | EXPECT_TRUE(S != 0 || Ty.isToken()); |
54 | |
55 | // Test sizes. |
56 | EXPECT_EQ(S, Ty.getSizeInBits()); |
57 | EXPECT_EQ(S, Ty.getScalarSizeInBits()); |
58 | |
59 | // Test equality operators. |
60 | EXPECT_TRUE(Ty == Ty); |
61 | EXPECT_FALSE(Ty != Ty); |
62 | |
63 | // Test Type->LLT conversion. |
64 | if (S != 0) { |
65 | Type *IRTy = IntegerType::get(C, NumBits: S); |
66 | EXPECT_EQ(Ty, getLLTForType(*IRTy, DL)); |
67 | } |
68 | } |
69 | } |
70 | |
71 | TEST(LowLevelTypeTest, Vector) { |
72 | LLVMContext C; |
73 | DataLayout DL("" ); |
74 | |
75 | for (unsigned S : {0U, 1U, 17U, 32U, 64U, 0xfffU}) { |
76 | for (auto EC : |
77 | {ElementCount::getFixed(MinVal: 2), ElementCount::getFixed(MinVal: 3), |
78 | ElementCount::getFixed(MinVal: 4), ElementCount::getFixed(MinVal: 32), |
79 | ElementCount::getFixed(MinVal: 0xff), ElementCount::getScalable(MinVal: 2), |
80 | ElementCount::getScalable(MinVal: 3), ElementCount::getScalable(MinVal: 4), |
81 | ElementCount::getScalable(MinVal: 32), ElementCount::getScalable(MinVal: 0xff)}) { |
82 | const LLT STy = LLT::scalar(SizeInBits: S); |
83 | const LLT VTy = LLT::vector(EC, ScalarSizeInBits: S); |
84 | |
85 | // Test the alternative vector(). |
86 | { |
87 | const LLT VSTy = LLT::vector(EC, ScalarTy: STy); |
88 | EXPECT_EQ(VTy, VSTy); |
89 | } |
90 | |
91 | // Test getElementType(). |
92 | EXPECT_EQ(STy, VTy.getElementType()); |
93 | |
94 | // Test kind. |
95 | ASSERT_TRUE(VTy.isValid()); |
96 | ASSERT_TRUE(VTy.isVector()); |
97 | |
98 | ASSERT_FALSE(VTy.isScalar()); |
99 | ASSERT_FALSE(VTy.isPointer()); |
100 | ASSERT_FALSE(VTy.isToken()); |
101 | |
102 | // Test sizes. |
103 | EXPECT_EQ(S, VTy.getScalarSizeInBits()); |
104 | EXPECT_EQ(EC, VTy.getElementCount()); |
105 | if (!EC.isScalable()) |
106 | EXPECT_EQ(S * EC.getFixedValue(), VTy.getSizeInBits()); |
107 | else |
108 | EXPECT_EQ(TypeSize::getScalable(S * EC.getKnownMinValue()), |
109 | VTy.getSizeInBits()); |
110 | |
111 | // Test equality operators. |
112 | EXPECT_TRUE(VTy == VTy); |
113 | EXPECT_FALSE(VTy != VTy); |
114 | |
115 | // Test inequality operators on.. |
116 | // ..different kind. |
117 | EXPECT_NE(VTy, STy); |
118 | |
119 | // Test Type->LLT conversion. |
120 | if (S != 0) { |
121 | Type *IRSTy = IntegerType::get(C, NumBits: S); |
122 | Type *IRTy = VectorType::get(ElementType: IRSTy, EC); |
123 | EXPECT_EQ(VTy, getLLTForType(*IRTy, DL)); |
124 | } |
125 | } |
126 | } |
127 | } |
128 | |
129 | TEST(LowLevelTypeTest, ScalarOrVector) { |
130 | // Test version with number of bits for scalar type. |
131 | EXPECT_EQ(LLT::scalar(32), |
132 | LLT::scalarOrVector(ElementCount::getFixed(1), 32)); |
133 | EXPECT_EQ(LLT::fixed_vector(2, 32), |
134 | LLT::scalarOrVector(ElementCount::getFixed(2), 32)); |
135 | EXPECT_EQ(LLT::scalable_vector(1, 32), |
136 | LLT::scalarOrVector(ElementCount::getScalable(1), 32)); |
137 | |
138 | // Test version with LLT for scalar type. |
139 | EXPECT_EQ(LLT::scalar(32), |
140 | LLT::scalarOrVector(ElementCount::getFixed(1), LLT::scalar(32))); |
141 | EXPECT_EQ(LLT::fixed_vector(2, 32), |
142 | LLT::scalarOrVector(ElementCount::getFixed(2), LLT::scalar(32))); |
143 | |
144 | // Test with pointer elements. |
145 | EXPECT_EQ(LLT::pointer(1, 32), LLT::scalarOrVector(ElementCount::getFixed(1), |
146 | LLT::pointer(1, 32))); |
147 | EXPECT_EQ( |
148 | LLT::fixed_vector(2, LLT::pointer(1, 32)), |
149 | LLT::scalarOrVector(ElementCount::getFixed(2), LLT::pointer(1, 32))); |
150 | } |
151 | |
152 | TEST(LowLevelTypeTest, ChangeElementType) { |
153 | const LLT P0 = LLT::pointer(AddressSpace: 0, SizeInBits: 32); |
154 | const LLT P1 = LLT::pointer(AddressSpace: 1, SizeInBits: 64); |
155 | |
156 | const LLT S32 = LLT::scalar(SizeInBits: 32); |
157 | const LLT S64 = LLT::scalar(SizeInBits: 64); |
158 | |
159 | const LLT V2S32 = LLT::fixed_vector(NumElements: 2, ScalarSizeInBits: 32); |
160 | const LLT V2S64 = LLT::fixed_vector(NumElements: 2, ScalarSizeInBits: 64); |
161 | |
162 | const LLT V2P0 = LLT::fixed_vector(NumElements: 2, ScalarTy: P0); |
163 | const LLT V2P1 = LLT::fixed_vector(NumElements: 2, ScalarTy: P1); |
164 | |
165 | EXPECT_EQ(S64, S32.changeElementType(S64)); |
166 | EXPECT_EQ(S32, S32.changeElementType(S32)); |
167 | |
168 | EXPECT_EQ(S32, S64.changeElementSize(32)); |
169 | EXPECT_EQ(S32, S32.changeElementSize(32)); |
170 | |
171 | EXPECT_EQ(V2S64, V2S32.changeElementType(S64)); |
172 | EXPECT_EQ(V2S32, V2S64.changeElementType(S32)); |
173 | |
174 | EXPECT_EQ(V2S64, V2S32.changeElementSize(64)); |
175 | EXPECT_EQ(V2S32, V2S64.changeElementSize(32)); |
176 | |
177 | EXPECT_EQ(P0, S32.changeElementType(P0)); |
178 | EXPECT_EQ(S32, P0.changeElementType(S32)); |
179 | |
180 | EXPECT_EQ(V2P1, V2P0.changeElementType(P1)); |
181 | EXPECT_EQ(V2S32, V2P0.changeElementType(S32)); |
182 | |
183 | // Similar tests for scalable vectors. |
184 | const LLT NXV2S32 = LLT::scalable_vector(MinNumElements: 2, ScalarSizeInBits: 32); |
185 | const LLT NXV2S64 = LLT::scalable_vector(MinNumElements: 2, ScalarSizeInBits: 64); |
186 | |
187 | const LLT NXV2P0 = LLT::scalable_vector(MinNumElements: 2, ScalarTy: P0); |
188 | const LLT NXV2P1 = LLT::scalable_vector(MinNumElements: 2, ScalarTy: P1); |
189 | |
190 | EXPECT_EQ(NXV2S64, NXV2S32.changeElementType(S64)); |
191 | EXPECT_EQ(NXV2S32, NXV2S64.changeElementType(S32)); |
192 | |
193 | EXPECT_EQ(NXV2S64, NXV2S32.changeElementSize(64)); |
194 | EXPECT_EQ(NXV2S32, NXV2S64.changeElementSize(32)); |
195 | |
196 | EXPECT_EQ(NXV2P1, NXV2P0.changeElementType(P1)); |
197 | EXPECT_EQ(NXV2S32, NXV2P0.changeElementType(S32)); |
198 | } |
199 | |
200 | TEST(LowLevelTypeTest, ChangeNumElements) { |
201 | const LLT P0 = LLT::pointer(AddressSpace: 0, SizeInBits: 32); |
202 | const LLT V2P0 = LLT::fixed_vector(NumElements: 2, ScalarTy: P0); |
203 | const LLT V3P0 = LLT::fixed_vector(NumElements: 3, ScalarTy: P0); |
204 | |
205 | const LLT S64 = LLT::scalar(SizeInBits: 64); |
206 | const LLT V2S64 = LLT::fixed_vector(NumElements: 2, ScalarSizeInBits: 64); |
207 | const LLT V3S64 = LLT::fixed_vector(NumElements: 3, ScalarSizeInBits: 64); |
208 | |
209 | // Vector to scalar |
210 | EXPECT_EQ(S64, V2S64.changeElementCount(ElementCount::getFixed(1))); |
211 | |
212 | // Vector to vector |
213 | EXPECT_EQ(V3S64, V2S64.changeElementCount(ElementCount::getFixed(3))); |
214 | |
215 | // Scalar to vector |
216 | EXPECT_EQ(V2S64, S64.changeElementCount(ElementCount::getFixed(2))); |
217 | |
218 | EXPECT_EQ(P0, V2P0.changeElementCount(ElementCount::getFixed(1))); |
219 | EXPECT_EQ(V3P0, V2P0.changeElementCount(ElementCount::getFixed(3))); |
220 | EXPECT_EQ(V2P0, P0.changeElementCount(ElementCount::getFixed(2))); |
221 | |
222 | const LLT NXV2S64 = LLT::scalable_vector(MinNumElements: 2, ScalarSizeInBits: 64); |
223 | const LLT NXV3S64 = LLT::scalable_vector(MinNumElements: 3, ScalarSizeInBits: 64); |
224 | const LLT NXV2P0 = LLT::scalable_vector(MinNumElements: 2, ScalarTy: P0); |
225 | |
226 | // Scalable vector to scalar |
227 | EXPECT_EQ(S64, NXV2S64.changeElementCount(ElementCount::getFixed(1))); |
228 | EXPECT_EQ(P0, NXV2P0.changeElementCount(ElementCount::getFixed(1))); |
229 | |
230 | // Fixed-width vector to scalable vector |
231 | EXPECT_EQ(NXV3S64, V2S64.changeElementCount(ElementCount::getScalable(3))); |
232 | |
233 | // Scalable vector to fixed-width vector |
234 | EXPECT_EQ(V3P0, NXV2P0.changeElementCount(ElementCount::getFixed(3))); |
235 | |
236 | // Scalar to scalable vector |
237 | EXPECT_EQ(NXV2S64, S64.changeElementCount(ElementCount::getScalable(2))); |
238 | EXPECT_EQ(NXV2P0, P0.changeElementCount(ElementCount::getScalable(2))); |
239 | } |
240 | |
241 | #ifdef GTEST_HAS_DEATH_TEST |
242 | #ifndef NDEBUG |
243 | |
244 | // Invalid to directly change the element size for pointers. |
245 | TEST(LowLevelTypeTest, ChangeElementTypeDeath) { |
246 | const LLT P0 = LLT::pointer(AddressSpace: 0, SizeInBits: 32); |
247 | const LLT V2P0 = LLT::fixed_vector(NumElements: 2, ScalarTy: P0); |
248 | |
249 | EXPECT_DEATH(P0.changeElementSize(64), |
250 | "invalid to directly change element size for pointers" ); |
251 | EXPECT_DEATH(V2P0.changeElementSize(64), |
252 | "invalid to directly change element size for pointers" ); |
253 | |
254 | // Make sure this still fails even without a change in size. |
255 | EXPECT_DEATH(P0.changeElementSize(32), |
256 | "invalid to directly change element size for pointers" ); |
257 | EXPECT_DEATH(V2P0.changeElementSize(32), |
258 | "invalid to directly change element size for pointers" ); |
259 | } |
260 | |
261 | #endif |
262 | #endif |
263 | |
264 | TEST(LowLevelTypeTest, Pointer) { |
265 | LLVMContext C; |
266 | DataLayout DL("p64:64:64-p127:512:512:512-p16777215:65528:8" ); |
267 | |
268 | for (unsigned AS : {0U, 1U, 127U, 0xffffU, |
269 | static_cast<unsigned>(maxUIntN(N: 23)), |
270 | static_cast<unsigned>(maxUIntN(N: 24))}) { |
271 | for (ElementCount EC : |
272 | {ElementCount::getFixed(MinVal: 2), ElementCount::getFixed(MinVal: 3), |
273 | ElementCount::getFixed(MinVal: 4), ElementCount::getFixed(MinVal: 256), |
274 | ElementCount::getFixed(MinVal: 65535), ElementCount::getScalable(MinVal: 2), |
275 | ElementCount::getScalable(MinVal: 3), ElementCount::getScalable(MinVal: 4), |
276 | ElementCount::getScalable(MinVal: 256), ElementCount::getScalable(MinVal: 65535)}) { |
277 | const LLT Ty = LLT::pointer(AddressSpace: AS, SizeInBits: DL.getPointerSizeInBits(AS)); |
278 | const LLT VTy = LLT::vector(EC, ScalarTy: Ty); |
279 | |
280 | // Test kind. |
281 | ASSERT_TRUE(Ty.isValid()); |
282 | ASSERT_TRUE(Ty.isPointer()); |
283 | ASSERT_TRUE(Ty.isPointerOrPointerVector()); |
284 | |
285 | ASSERT_FALSE(Ty.isScalar()); |
286 | ASSERT_FALSE(Ty.isVector()); |
287 | |
288 | ASSERT_TRUE(VTy.isValid()); |
289 | ASSERT_TRUE(VTy.isVector()); |
290 | ASSERT_TRUE(VTy.getElementType().isPointer()); |
291 | ASSERT_TRUE(VTy.isPointerVector()); |
292 | ASSERT_TRUE(VTy.isPointerOrPointerVector()); |
293 | |
294 | EXPECT_EQ(Ty, VTy.getElementType()); |
295 | EXPECT_EQ(Ty.getSizeInBits(), VTy.getScalarSizeInBits()); |
296 | |
297 | // Test address space. |
298 | EXPECT_EQ(AS, Ty.getAddressSpace()); |
299 | EXPECT_EQ(AS, VTy.getElementType().getAddressSpace()); |
300 | |
301 | // Test equality operators. |
302 | EXPECT_TRUE(Ty == Ty); |
303 | EXPECT_FALSE(Ty != Ty); |
304 | EXPECT_TRUE(VTy == VTy); |
305 | EXPECT_FALSE(VTy != VTy); |
306 | |
307 | // Test Type->LLT conversion. |
308 | Type *IRTy = PointerType::get(ElementType: IntegerType::get(C, NumBits: 8), AddressSpace: AS); |
309 | EXPECT_EQ(Ty, getLLTForType(*IRTy, DL)); |
310 | Type *IRVTy = |
311 | VectorType::get(ElementType: PointerType::get(ElementType: IntegerType::get(C, NumBits: 8), AddressSpace: AS), EC); |
312 | EXPECT_EQ(VTy, getLLTForType(*IRVTy, DL)); |
313 | } |
314 | } |
315 | } |
316 | |
317 | TEST(LowLevelTypeTest, Invalid) { |
318 | const LLT Ty; |
319 | |
320 | ASSERT_FALSE(Ty.isValid()); |
321 | ASSERT_FALSE(Ty.isScalar()); |
322 | ASSERT_FALSE(Ty.isPointer()); |
323 | ASSERT_FALSE(Ty.isVector()); |
324 | ASSERT_FALSE(Ty.isToken()); |
325 | } |
326 | |
327 | TEST(LowLevelTypeTest, Divide) { |
328 | // Test basic scalar->scalar cases. |
329 | EXPECT_EQ(LLT::scalar(16), LLT::scalar(32).divide(2)); |
330 | EXPECT_EQ(LLT::scalar(8), LLT::scalar(32).divide(4)); |
331 | EXPECT_EQ(LLT::scalar(8), LLT::scalar(32).divide(4)); |
332 | |
333 | // Test pointer->scalar |
334 | EXPECT_EQ(LLT::scalar(32), LLT::pointer(0, 64).divide(2)); |
335 | |
336 | // Test dividing vectors. |
337 | EXPECT_EQ(LLT::scalar(32), LLT::fixed_vector(2, 32).divide(2)); |
338 | EXPECT_EQ(LLT::fixed_vector(2, 32), LLT::fixed_vector(4, 32).divide(2)); |
339 | |
340 | // Test vector of pointers |
341 | EXPECT_EQ(LLT::pointer(1, 64), |
342 | LLT::fixed_vector(4, LLT::pointer(1, 64)).divide(4)); |
343 | EXPECT_EQ(LLT::fixed_vector(2, LLT::pointer(1, 64)), |
344 | LLT::fixed_vector(4, LLT::pointer(1, 64)).divide(2)); |
345 | } |
346 | |
347 | TEST(LowLevelTypeTest, MultiplyElements) { |
348 | // Basic scalar->vector cases |
349 | EXPECT_EQ(LLT::fixed_vector(2, 16), LLT::scalar(16).multiplyElements(2)); |
350 | EXPECT_EQ(LLT::fixed_vector(3, 16), LLT::scalar(16).multiplyElements(3)); |
351 | EXPECT_EQ(LLT::fixed_vector(4, 32), LLT::scalar(32).multiplyElements(4)); |
352 | EXPECT_EQ(LLT::fixed_vector(4, 7), LLT::scalar(7).multiplyElements(4)); |
353 | |
354 | // Basic vector to vector cases |
355 | EXPECT_EQ(LLT::fixed_vector(4, 32), |
356 | LLT::fixed_vector(2, 32).multiplyElements(2)); |
357 | EXPECT_EQ(LLT::fixed_vector(9, 32), |
358 | LLT::fixed_vector(3, 32).multiplyElements(3)); |
359 | |
360 | // Pointer to vector of pointers |
361 | EXPECT_EQ(LLT::fixed_vector(2, LLT::pointer(0, 32)), |
362 | LLT::pointer(0, 32).multiplyElements(2)); |
363 | EXPECT_EQ(LLT::fixed_vector(3, LLT::pointer(1, 32)), |
364 | LLT::pointer(1, 32).multiplyElements(3)); |
365 | EXPECT_EQ(LLT::fixed_vector(4, LLT::pointer(1, 64)), |
366 | LLT::pointer(1, 64).multiplyElements(4)); |
367 | |
368 | // Vector of pointers to vector of pointers |
369 | EXPECT_EQ(LLT::fixed_vector(8, LLT::pointer(1, 64)), |
370 | LLT::fixed_vector(2, LLT::pointer(1, 64)).multiplyElements(4)); |
371 | EXPECT_EQ(LLT::fixed_vector(9, LLT::pointer(1, 32)), |
372 | LLT::fixed_vector(3, LLT::pointer(1, 32)).multiplyElements(3)); |
373 | |
374 | // Scalable vectors |
375 | EXPECT_EQ(LLT::scalable_vector(4, 16), |
376 | LLT::scalable_vector(2, 16).multiplyElements(2)); |
377 | EXPECT_EQ(LLT::scalable_vector(6, 16), |
378 | LLT::scalable_vector(2, 16).multiplyElements(3)); |
379 | EXPECT_EQ(LLT::scalable_vector(9, 16), |
380 | LLT::scalable_vector(3, 16).multiplyElements(3)); |
381 | EXPECT_EQ(LLT::scalable_vector(4, 32), |
382 | LLT::scalable_vector(2, 32).multiplyElements(2)); |
383 | EXPECT_EQ(LLT::scalable_vector(256, 32), |
384 | LLT::scalable_vector(8, 32).multiplyElements(32)); |
385 | |
386 | // Scalable vectors of pointers |
387 | EXPECT_EQ(LLT::scalable_vector(4, LLT::pointer(0, 32)), |
388 | LLT::scalable_vector(2, LLT::pointer(0, 32)).multiplyElements(2)); |
389 | EXPECT_EQ(LLT::scalable_vector(32, LLT::pointer(1, 64)), |
390 | LLT::scalable_vector(8, LLT::pointer(1, 64)).multiplyElements(4)); |
391 | } |
392 | |
393 | constexpr LLT CELLT = LLT(); |
394 | constexpr LLT CES32 = LLT::scalar(SizeInBits: 32); |
395 | constexpr LLT CEV2S32 = LLT::fixed_vector(NumElements: 2, ScalarSizeInBits: 32); |
396 | constexpr LLT CESV2S32 = LLT::scalable_vector(MinNumElements: 2, ScalarSizeInBits: 32); |
397 | constexpr LLT CEP0 = LLT::pointer(AddressSpace: 0, SizeInBits: 32); |
398 | constexpr LLT CEV2P1 = LLT::fixed_vector(NumElements: 2, ScalarTy: LLT::pointer(AddressSpace: 1, SizeInBits: 64)); |
399 | |
400 | static_assert(!CELLT.isValid()); |
401 | static_assert(CES32.isValid()); |
402 | static_assert(CEV2S32.isValid()); |
403 | static_assert(CESV2S32.isValid()); |
404 | static_assert(CEP0.isValid()); |
405 | static_assert(CEV2P1.isValid()); |
406 | static_assert(CEV2P1.isVector()); |
407 | static_assert(CEV2P1.getElementCount() == ElementCount::getFixed(MinVal: 2)); |
408 | static_assert(CEV2P1.getElementCount() != ElementCount::getFixed(MinVal: 1)); |
409 | static_assert(CEV2S32.getElementCount() == ElementCount::getFixed(MinVal: 2)); |
410 | static_assert(CEV2S32.getSizeInBits() == TypeSize::getFixed(ExactSize: 64)); |
411 | static_assert(CEV2P1.getSizeInBits() == TypeSize::getFixed(ExactSize: 128)); |
412 | static_assert(CEV2P1.getScalarType() == LLT::pointer(AddressSpace: 1, SizeInBits: 64)); |
413 | static_assert(CES32.getScalarType() == CES32); |
414 | static_assert(CEV2S32.getScalarType() == CES32); |
415 | static_assert(CEV2S32.changeElementType(NewEltTy: CEP0) == LLT::fixed_vector(NumElements: 2, ScalarTy: CEP0)); |
416 | static_assert(CEV2S32.changeElementSize(NewEltSize: 16) == LLT::fixed_vector(NumElements: 2, ScalarSizeInBits: 16)); |
417 | static_assert(CEV2S32.changeElementCount(EC: ElementCount::getFixed(MinVal: 4)) == |
418 | LLT::fixed_vector(NumElements: 4, ScalarSizeInBits: 32)); |
419 | static_assert(CES32.isByteSized()); |
420 | static_assert(!LLT::scalar(SizeInBits: 7).isByteSized()); |
421 | static_assert(CES32.getScalarSizeInBits() == 32); |
422 | static_assert(CEP0.getAddressSpace() == 0); |
423 | static_assert(LLT::pointer(AddressSpace: 1, SizeInBits: 64).getAddressSpace() == 1); |
424 | static_assert(CEV2S32.multiplyElements(Factor: 2) == LLT::fixed_vector(NumElements: 4, ScalarSizeInBits: 32)); |
425 | static_assert(CEV2S32.divide(Factor: 2) == LLT::scalar(SizeInBits: 32)); |
426 | static_assert(LLT::scalarOrVector(EC: ElementCount::getFixed(MinVal: 1), ScalarTy: LLT::scalar(SizeInBits: 32)) == |
427 | LLT::scalar(SizeInBits: 32)); |
428 | static_assert(LLT::scalarOrVector(EC: ElementCount::getFixed(MinVal: 2), ScalarTy: LLT::scalar(SizeInBits: 32)) == |
429 | LLT::fixed_vector(NumElements: 2, ScalarSizeInBits: 32)); |
430 | static_assert(LLT::scalarOrVector(EC: ElementCount::getFixed(MinVal: 2), ScalarTy: CEP0) == |
431 | LLT::fixed_vector(NumElements: 2, ScalarTy: CEP0)); |
432 | |
433 | TEST(LowLevelTypeTest, ConstExpr) { |
434 | EXPECT_EQ(LLT(), CELLT); |
435 | EXPECT_EQ(LLT::scalar(32), CES32); |
436 | EXPECT_EQ(LLT::fixed_vector(2, 32), CEV2S32); |
437 | EXPECT_EQ(LLT::pointer(0, 32), CEP0); |
438 | EXPECT_EQ(LLT::scalable_vector(2, 32), CESV2S32); |
439 | } |
440 | |
441 | TEST(LowLevelTypeTest, IsFixedVector) { |
442 | EXPECT_FALSE(LLT::scalar(32).isFixedVector()); |
443 | EXPECT_TRUE(LLT::fixed_vector(2, 32).isFixedVector()); |
444 | EXPECT_FALSE(LLT::scalable_vector(2, 32).isFixedVector()); |
445 | EXPECT_FALSE(LLT::scalable_vector(1, 32).isFixedVector()); |
446 | } |
447 | |
448 | TEST(LowLevelTypeTest, IsScalableVector) { |
449 | EXPECT_FALSE(LLT::scalar(32).isScalableVector()); |
450 | EXPECT_FALSE(LLT::fixed_vector(2, 32).isScalableVector()); |
451 | EXPECT_TRUE(LLT::scalable_vector(2, 32).isScalableVector()); |
452 | EXPECT_TRUE(LLT::scalable_vector(1, 32).isScalableVector()); |
453 | } |
454 | } |
455 | |