1 | //===--- llvm/unittest/IR/VectorTypesTest.cpp - vector types unit tests ---===// |
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/IR/DataLayout.h" |
10 | #include "llvm/IR/DerivedTypes.h" |
11 | #include "llvm/IR/LLVMContext.h" |
12 | #include "llvm/Support/TypeSize.h" |
13 | #include "gtest/gtest.h" |
14 | using namespace llvm; |
15 | |
16 | namespace { |
17 | |
18 | #define EXPECT_VTY_EQ(LHS, RHS) \ |
19 | do { \ |
20 | ASSERT_NE(LHS, nullptr) << #LHS << " must not be null"; \ |
21 | ASSERT_NE(RHS, nullptr) << #RHS << " must not be null"; \ |
22 | EXPECT_EQ(LHS, RHS) << "Expect that " << #LHS << " == " << #RHS \ |
23 | << " where " << #LHS << " = " << *LHS << " and " \ |
24 | << #RHS << " = " << *RHS; \ |
25 | } while (false) |
26 | |
27 | #define EXPECT_VTY_NE(LHS, RHS) \ |
28 | do { \ |
29 | ASSERT_NE(LHS, nullptr) << #LHS << " must not be null"; \ |
30 | ASSERT_NE(RHS, nullptr) << #RHS << " must not be null"; \ |
31 | EXPECT_NE(LHS, RHS) << "Expect that " << #LHS << " != " << #RHS \ |
32 | << " where " << #LHS << " = " << *LHS << " and " \ |
33 | << #RHS << " = " << *RHS; \ |
34 | } while (false) |
35 | |
36 | TEST(VectorTypesTest, FixedLength) { |
37 | LLVMContext Ctx; |
38 | |
39 | Type *Int8Ty = Type::getInt8Ty(C&: Ctx); |
40 | Type *Int16Ty = Type::getInt16Ty(C&: Ctx); |
41 | Type *Int32Ty = Type::getInt32Ty(C&: Ctx); |
42 | Type *Int64Ty = Type::getInt64Ty(C&: Ctx); |
43 | Type *Float64Ty = Type::getDoubleTy(C&: Ctx); |
44 | |
45 | auto *V16Int8Ty = FixedVectorType::get(ElementType: Int8Ty, NumElts: 16); |
46 | ASSERT_NE(nullptr, V16Int8Ty); |
47 | EXPECT_EQ(V16Int8Ty->getNumElements(), 16U); |
48 | EXPECT_EQ(V16Int8Ty->getElementType()->getScalarSizeInBits(), 8U); |
49 | |
50 | auto *V8Int32Ty = |
51 | dyn_cast<FixedVectorType>(Val: VectorType::get(ElementType: Int32Ty, NumElements: 8, Scalable: false)); |
52 | ASSERT_NE(nullptr, V8Int32Ty); |
53 | EXPECT_EQ(V8Int32Ty->getNumElements(), 8U); |
54 | EXPECT_EQ(V8Int32Ty->getElementType()->getScalarSizeInBits(), 32U); |
55 | |
56 | auto *V8Int8Ty = |
57 | dyn_cast<FixedVectorType>(Val: VectorType::get(ElementType: Int8Ty, Other: V8Int32Ty)); |
58 | EXPECT_VTY_NE(V8Int32Ty, V8Int8Ty); |
59 | EXPECT_EQ(V8Int8Ty->getElementCount(), V8Int32Ty->getElementCount()); |
60 | EXPECT_EQ(V8Int8Ty->getElementType()->getScalarSizeInBits(), 8U); |
61 | |
62 | auto *V8Int32Ty2 = |
63 | dyn_cast<FixedVectorType>(Val: VectorType::get(ElementType: Int32Ty, Other: V8Int32Ty)); |
64 | EXPECT_VTY_EQ(V8Int32Ty, V8Int32Ty2); |
65 | |
66 | auto *V8Int16Ty = dyn_cast<FixedVectorType>( |
67 | Val: VectorType::get(ElementType: Int16Ty, EC: ElementCount::getFixed(MinVal: 8))); |
68 | ASSERT_NE(nullptr, V8Int16Ty); |
69 | EXPECT_EQ(V8Int16Ty->getNumElements(), 8U); |
70 | EXPECT_EQ(V8Int16Ty->getElementType()->getScalarSizeInBits(), 16U); |
71 | |
72 | auto EltCnt = ElementCount::getFixed(MinVal: 4); |
73 | auto *V4Int64Ty = dyn_cast<FixedVectorType>(Val: VectorType::get(ElementType: Int64Ty, EC: EltCnt)); |
74 | ASSERT_NE(nullptr, V4Int64Ty); |
75 | EXPECT_EQ(V4Int64Ty->getNumElements(), 4U); |
76 | EXPECT_EQ(V4Int64Ty->getElementType()->getScalarSizeInBits(), 64U); |
77 | |
78 | auto *V2Int64Ty = dyn_cast<FixedVectorType>( |
79 | Val: VectorType::get(ElementType: Int64Ty, EC: EltCnt.divideCoefficientBy(RHS: 2))); |
80 | ASSERT_NE(nullptr, V2Int64Ty); |
81 | EXPECT_EQ(V2Int64Ty->getNumElements(), 2U); |
82 | EXPECT_EQ(V2Int64Ty->getElementType()->getScalarSizeInBits(), 64U); |
83 | |
84 | auto *V8Int64Ty = |
85 | dyn_cast<FixedVectorType>(Val: VectorType::get(ElementType: Int64Ty, EC: EltCnt * 2)); |
86 | ASSERT_NE(nullptr, V8Int64Ty); |
87 | EXPECT_EQ(V8Int64Ty->getNumElements(), 8U); |
88 | EXPECT_EQ(V8Int64Ty->getElementType()->getScalarSizeInBits(), 64U); |
89 | |
90 | auto *V4Float64Ty = |
91 | dyn_cast<FixedVectorType>(Val: VectorType::get(ElementType: Float64Ty, EC: EltCnt)); |
92 | ASSERT_NE(nullptr, V4Float64Ty); |
93 | EXPECT_EQ(V4Float64Ty->getNumElements(), 4U); |
94 | EXPECT_EQ(V4Float64Ty->getElementType()->getScalarSizeInBits(), 64U); |
95 | |
96 | auto *ExtTy = dyn_cast<FixedVectorType>( |
97 | Val: VectorType::getExtendedElementVectorType(VTy: V8Int16Ty)); |
98 | EXPECT_VTY_EQ(ExtTy, V8Int32Ty); |
99 | EXPECT_EQ(ExtTy->getNumElements(), 8U); |
100 | EXPECT_EQ(ExtTy->getElementType()->getScalarSizeInBits(), 32U); |
101 | |
102 | auto *TruncTy = dyn_cast<FixedVectorType>( |
103 | Val: VectorType::getTruncatedElementVectorType(VTy: V8Int32Ty)); |
104 | EXPECT_VTY_EQ(TruncTy, V8Int16Ty); |
105 | EXPECT_EQ(TruncTy->getNumElements(), 8U); |
106 | EXPECT_EQ(TruncTy->getElementType()->getScalarSizeInBits(), 16U); |
107 | |
108 | auto *HalvedTy = dyn_cast<FixedVectorType>( |
109 | Val: VectorType::getHalfElementsVectorType(VTy: V4Int64Ty)); |
110 | EXPECT_VTY_EQ(HalvedTy, V2Int64Ty); |
111 | EXPECT_EQ(HalvedTy->getNumElements(), 2U); |
112 | EXPECT_EQ(HalvedTy->getElementType()->getScalarSizeInBits(), 64U); |
113 | |
114 | auto *DoubledTy = dyn_cast<FixedVectorType>( |
115 | Val: VectorType::getDoubleElementsVectorType(VTy: V4Int64Ty)); |
116 | EXPECT_VTY_EQ(DoubledTy, V8Int64Ty); |
117 | EXPECT_EQ(DoubledTy->getNumElements(), 8U); |
118 | EXPECT_EQ(DoubledTy->getElementType()->getScalarSizeInBits(), 64U); |
119 | |
120 | auto *ConvTy = dyn_cast<FixedVectorType>(Val: VectorType::getInteger(VTy: V4Float64Ty)); |
121 | EXPECT_VTY_EQ(ConvTy, V4Int64Ty); |
122 | EXPECT_EQ(ConvTy->getNumElements(), 4U); |
123 | EXPECT_EQ(ConvTy->getElementType()->getScalarSizeInBits(), 64U); |
124 | |
125 | EltCnt = V8Int64Ty->getElementCount(); |
126 | EXPECT_EQ(EltCnt.getKnownMinValue(), 8U); |
127 | ASSERT_FALSE(EltCnt.isScalable()); |
128 | } |
129 | |
130 | TEST(VectorTypesTest, Scalable) { |
131 | LLVMContext Ctx; |
132 | |
133 | Type *Int8Ty = Type::getInt8Ty(C&: Ctx); |
134 | Type *Int16Ty = Type::getInt16Ty(C&: Ctx); |
135 | Type *Int32Ty = Type::getInt32Ty(C&: Ctx); |
136 | Type *Int64Ty = Type::getInt64Ty(C&: Ctx); |
137 | Type *Float64Ty = Type::getDoubleTy(C&: Ctx); |
138 | |
139 | auto *ScV16Int8Ty = ScalableVectorType::get(ElementType: Int8Ty, MinNumElts: 16); |
140 | ASSERT_NE(nullptr, ScV16Int8Ty); |
141 | EXPECT_EQ(ScV16Int8Ty->getMinNumElements(), 16U); |
142 | EXPECT_EQ(ScV16Int8Ty->getScalarSizeInBits(), 8U); |
143 | |
144 | auto *ScV8Int32Ty = |
145 | dyn_cast<ScalableVectorType>(Val: VectorType::get(ElementType: Int32Ty, NumElements: 8, Scalable: true)); |
146 | ASSERT_NE(nullptr, ScV8Int32Ty); |
147 | EXPECT_EQ(ScV8Int32Ty->getMinNumElements(), 8U); |
148 | EXPECT_EQ(ScV8Int32Ty->getElementType()->getScalarSizeInBits(), 32U); |
149 | |
150 | auto *ScV8Int8Ty = |
151 | dyn_cast<ScalableVectorType>(Val: VectorType::get(ElementType: Int8Ty, Other: ScV8Int32Ty)); |
152 | EXPECT_VTY_NE(ScV8Int32Ty, ScV8Int8Ty); |
153 | EXPECT_EQ(ScV8Int8Ty->getElementCount(), ScV8Int32Ty->getElementCount()); |
154 | EXPECT_EQ(ScV8Int8Ty->getElementType()->getScalarSizeInBits(), 8U); |
155 | |
156 | auto *ScV8Int32Ty2 = |
157 | dyn_cast<ScalableVectorType>(Val: VectorType::get(ElementType: Int32Ty, Other: ScV8Int32Ty)); |
158 | EXPECT_VTY_EQ(ScV8Int32Ty, ScV8Int32Ty2); |
159 | |
160 | auto *ScV8Int16Ty = dyn_cast<ScalableVectorType>( |
161 | Val: VectorType::get(ElementType: Int16Ty, EC: ElementCount::getScalable(MinVal: 8))); |
162 | ASSERT_NE(nullptr, ScV8Int16Ty); |
163 | EXPECT_EQ(ScV8Int16Ty->getMinNumElements(), 8U); |
164 | EXPECT_EQ(ScV8Int16Ty->getElementType()->getScalarSizeInBits(), 16U); |
165 | |
166 | auto EltCnt = ElementCount::getScalable(MinVal: 4); |
167 | auto *ScV4Int64Ty = |
168 | dyn_cast<ScalableVectorType>(Val: VectorType::get(ElementType: Int64Ty, EC: EltCnt)); |
169 | ASSERT_NE(nullptr, ScV4Int64Ty); |
170 | EXPECT_EQ(ScV4Int64Ty->getMinNumElements(), 4U); |
171 | EXPECT_EQ(ScV4Int64Ty->getElementType()->getScalarSizeInBits(), 64U); |
172 | |
173 | auto *ScV2Int64Ty = dyn_cast<ScalableVectorType>( |
174 | Val: VectorType::get(ElementType: Int64Ty, EC: EltCnt.divideCoefficientBy(RHS: 2))); |
175 | ASSERT_NE(nullptr, ScV2Int64Ty); |
176 | EXPECT_EQ(ScV2Int64Ty->getMinNumElements(), 2U); |
177 | EXPECT_EQ(ScV2Int64Ty->getElementType()->getScalarSizeInBits(), 64U); |
178 | |
179 | auto *ScV8Int64Ty = |
180 | dyn_cast<ScalableVectorType>(Val: VectorType::get(ElementType: Int64Ty, EC: EltCnt * 2)); |
181 | ASSERT_NE(nullptr, ScV8Int64Ty); |
182 | EXPECT_EQ(ScV8Int64Ty->getMinNumElements(), 8U); |
183 | EXPECT_EQ(ScV8Int64Ty->getElementType()->getScalarSizeInBits(), 64U); |
184 | |
185 | auto *ScV4Float64Ty = |
186 | dyn_cast<ScalableVectorType>(Val: VectorType::get(ElementType: Float64Ty, EC: EltCnt)); |
187 | ASSERT_NE(nullptr, ScV4Float64Ty); |
188 | EXPECT_EQ(ScV4Float64Ty->getMinNumElements(), 4U); |
189 | EXPECT_EQ(ScV4Float64Ty->getElementType()->getScalarSizeInBits(), 64U); |
190 | |
191 | auto *ExtTy = dyn_cast<ScalableVectorType>( |
192 | Val: VectorType::getExtendedElementVectorType(VTy: ScV8Int16Ty)); |
193 | EXPECT_VTY_EQ(ExtTy, ScV8Int32Ty); |
194 | EXPECT_EQ(ExtTy->getMinNumElements(), 8U); |
195 | EXPECT_EQ(ExtTy->getElementType()->getScalarSizeInBits(), 32U); |
196 | |
197 | auto *TruncTy = dyn_cast<ScalableVectorType>( |
198 | Val: VectorType::getTruncatedElementVectorType(VTy: ScV8Int32Ty)); |
199 | EXPECT_VTY_EQ(TruncTy, ScV8Int16Ty); |
200 | EXPECT_EQ(TruncTy->getMinNumElements(), 8U); |
201 | EXPECT_EQ(TruncTy->getElementType()->getScalarSizeInBits(), 16U); |
202 | |
203 | auto *HalvedTy = dyn_cast<ScalableVectorType>( |
204 | Val: VectorType::getHalfElementsVectorType(VTy: ScV4Int64Ty)); |
205 | EXPECT_VTY_EQ(HalvedTy, ScV2Int64Ty); |
206 | EXPECT_EQ(HalvedTy->getMinNumElements(), 2U); |
207 | EXPECT_EQ(HalvedTy->getElementType()->getScalarSizeInBits(), 64U); |
208 | |
209 | auto *DoubledTy = dyn_cast<ScalableVectorType>( |
210 | Val: VectorType::getDoubleElementsVectorType(VTy: ScV4Int64Ty)); |
211 | EXPECT_VTY_EQ(DoubledTy, ScV8Int64Ty); |
212 | EXPECT_EQ(DoubledTy->getMinNumElements(), 8U); |
213 | EXPECT_EQ(DoubledTy->getElementType()->getScalarSizeInBits(), 64U); |
214 | |
215 | auto *ConvTy = |
216 | dyn_cast<ScalableVectorType>(Val: VectorType::getInteger(VTy: ScV4Float64Ty)); |
217 | EXPECT_VTY_EQ(ConvTy, ScV4Int64Ty); |
218 | EXPECT_EQ(ConvTy->getMinNumElements(), 4U); |
219 | EXPECT_EQ(ConvTy->getElementType()->getScalarSizeInBits(), 64U); |
220 | |
221 | EltCnt = ScV8Int64Ty->getElementCount(); |
222 | EXPECT_EQ(EltCnt.getKnownMinValue(), 8U); |
223 | ASSERT_TRUE(EltCnt.isScalable()); |
224 | } |
225 | |
226 | TEST(VectorTypesTest, BaseVectorType) { |
227 | LLVMContext Ctx; |
228 | |
229 | Type *Int16Ty = Type::getInt16Ty(C&: Ctx); |
230 | Type *Int32Ty = Type::getInt32Ty(C&: Ctx); |
231 | |
232 | std::array<VectorType *, 8> VTys = { |
233 | VectorType::get(ElementType: Int16Ty, EC: ElementCount::getScalable(MinVal: 4)), |
234 | VectorType::get(ElementType: Int16Ty, EC: ElementCount::getFixed(MinVal: 4)), |
235 | VectorType::get(ElementType: Int16Ty, EC: ElementCount::getScalable(MinVal: 2)), |
236 | VectorType::get(ElementType: Int16Ty, EC: ElementCount::getFixed(MinVal: 2)), |
237 | VectorType::get(ElementType: Int32Ty, EC: ElementCount::getScalable(MinVal: 4)), |
238 | VectorType::get(ElementType: Int32Ty, EC: ElementCount::getFixed(MinVal: 4)), |
239 | VectorType::get(ElementType: Int32Ty, EC: ElementCount::getScalable(MinVal: 2)), |
240 | VectorType::get(ElementType: Int32Ty, EC: ElementCount::getFixed(MinVal: 2))}; |
241 | |
242 | /* |
243 | The comparison matrix is symmetric, so we only check the upper triangle: |
244 | |
245 | (0,0) (0,1) (0,2) ... (0,7) |
246 | (1,0) (1,1) (1,2) . |
247 | (2,0) (2,1) (2,2) . |
248 | . . . |
249 | . . |
250 | . . |
251 | (7,0) ... (7,7) |
252 | */ |
253 | for (size_t I = 0, IEnd = VTys.size(); I < IEnd; ++I) { |
254 | // test I == J |
255 | VectorType *VI = VTys[I]; |
256 | ElementCount ECI = VI->getElementCount(); |
257 | EXPECT_EQ(isa<ScalableVectorType>(VI), ECI.isScalable()); |
258 | |
259 | for (size_t J = I + 1, JEnd = VTys.size(); J < JEnd; ++J) { |
260 | // test I < J |
261 | VectorType *VJ = VTys[J]; |
262 | EXPECT_VTY_NE(VI, VJ); |
263 | |
264 | VectorType *VJPrime = VectorType::get(ElementType: VI->getElementType(), Other: VJ); |
265 | if (VI->getElementType() == VJ->getElementType()) { |
266 | EXPECT_VTY_EQ(VJ, VJPrime); |
267 | } else { |
268 | EXPECT_VTY_NE(VJ, VJPrime); |
269 | } |
270 | |
271 | EXPECT_EQ(VJ->getTypeID(), VJPrime->getTypeID()) |
272 | << "VJ and VJPrime are the same sort of vector" ; |
273 | } |
274 | } |
275 | } |
276 | |
277 | TEST(VectorTypesTest, FixedLenComparisons) { |
278 | LLVMContext Ctx; |
279 | DataLayout DL("" ); |
280 | |
281 | Type *Int32Ty = Type::getInt32Ty(C&: Ctx); |
282 | Type *Int64Ty = Type::getInt64Ty(C&: Ctx); |
283 | |
284 | auto *V2Int32Ty = FixedVectorType::get(ElementType: Int32Ty, NumElts: 2); |
285 | auto *V4Int32Ty = FixedVectorType::get(ElementType: Int32Ty, NumElts: 4); |
286 | |
287 | auto *V2Int64Ty = FixedVectorType::get(ElementType: Int64Ty, NumElts: 2); |
288 | |
289 | TypeSize V2I32Len = V2Int32Ty->getPrimitiveSizeInBits(); |
290 | EXPECT_EQ(V2I32Len.getKnownMinValue(), 64U); |
291 | EXPECT_FALSE(V2I32Len.isScalable()); |
292 | |
293 | EXPECT_LT(V2Int32Ty->getPrimitiveSizeInBits().getFixedValue(), |
294 | V4Int32Ty->getPrimitiveSizeInBits().getFixedValue()); |
295 | EXPECT_GT(V2Int64Ty->getPrimitiveSizeInBits().getFixedValue(), |
296 | V2Int32Ty->getPrimitiveSizeInBits().getFixedValue()); |
297 | EXPECT_EQ(V4Int32Ty->getPrimitiveSizeInBits(), |
298 | V2Int64Ty->getPrimitiveSizeInBits()); |
299 | EXPECT_NE(V2Int32Ty->getPrimitiveSizeInBits(), |
300 | V2Int64Ty->getPrimitiveSizeInBits()); |
301 | |
302 | // Check that a fixed-only comparison works for fixed size vectors. |
303 | EXPECT_EQ(V2Int64Ty->getPrimitiveSizeInBits().getFixedValue(), |
304 | V4Int32Ty->getPrimitiveSizeInBits().getFixedValue()); |
305 | |
306 | // Check the DataLayout interfaces. |
307 | EXPECT_EQ(DL.getTypeSizeInBits(V2Int64Ty), DL.getTypeSizeInBits(V4Int32Ty)); |
308 | EXPECT_EQ(DL.getTypeSizeInBits(V2Int32Ty), 64U); |
309 | EXPECT_EQ(DL.getTypeSizeInBits(V2Int64Ty), 128U); |
310 | EXPECT_EQ(DL.getTypeStoreSize(V2Int64Ty), DL.getTypeStoreSize(V4Int32Ty)); |
311 | EXPECT_NE(DL.getTypeStoreSizeInBits(V2Int32Ty), |
312 | DL.getTypeStoreSizeInBits(V2Int64Ty)); |
313 | EXPECT_EQ(DL.getTypeStoreSizeInBits(V2Int32Ty), 64U); |
314 | EXPECT_EQ(DL.getTypeStoreSize(V2Int64Ty), 16U); |
315 | EXPECT_EQ(DL.getTypeAllocSize(V4Int32Ty), DL.getTypeAllocSize(V2Int64Ty)); |
316 | EXPECT_NE(DL.getTypeAllocSizeInBits(V2Int32Ty), |
317 | DL.getTypeAllocSizeInBits(V2Int64Ty)); |
318 | EXPECT_EQ(DL.getTypeAllocSizeInBits(V4Int32Ty), 128U); |
319 | EXPECT_EQ(DL.getTypeAllocSize(V2Int32Ty), 8U); |
320 | ASSERT_TRUE(DL.typeSizeEqualsStoreSize(V4Int32Ty)); |
321 | } |
322 | |
323 | TEST(VectorTypesTest, ScalableComparisons) { |
324 | LLVMContext Ctx; |
325 | DataLayout DL("" ); |
326 | |
327 | Type *Int32Ty = Type::getInt32Ty(C&: Ctx); |
328 | Type *Int64Ty = Type::getInt64Ty(C&: Ctx); |
329 | |
330 | auto *ScV2Int32Ty = ScalableVectorType::get(ElementType: Int32Ty, MinNumElts: 2); |
331 | auto *ScV4Int32Ty = ScalableVectorType::get(ElementType: Int32Ty, MinNumElts: 4); |
332 | |
333 | auto *ScV2Int64Ty = ScalableVectorType::get(ElementType: Int64Ty, MinNumElts: 2); |
334 | |
335 | TypeSize ScV2I32Len = ScV2Int32Ty->getPrimitiveSizeInBits(); |
336 | EXPECT_EQ(ScV2I32Len.getKnownMinValue(), 64U); |
337 | EXPECT_TRUE(ScV2I32Len.isScalable()); |
338 | |
339 | EXPECT_LT(ScV2Int32Ty->getPrimitiveSizeInBits().getKnownMinValue(), |
340 | ScV4Int32Ty->getPrimitiveSizeInBits().getKnownMinValue()); |
341 | EXPECT_GT(ScV2Int64Ty->getPrimitiveSizeInBits().getKnownMinValue(), |
342 | ScV2Int32Ty->getPrimitiveSizeInBits().getKnownMinValue()); |
343 | EXPECT_EQ(ScV4Int32Ty->getPrimitiveSizeInBits().getKnownMinValue(), |
344 | ScV2Int64Ty->getPrimitiveSizeInBits().getKnownMinValue()); |
345 | EXPECT_NE(ScV2Int32Ty->getPrimitiveSizeInBits().getKnownMinValue(), |
346 | ScV2Int64Ty->getPrimitiveSizeInBits().getKnownMinValue()); |
347 | |
348 | // Check the DataLayout interfaces. |
349 | EXPECT_EQ(DL.getTypeSizeInBits(ScV2Int64Ty), |
350 | DL.getTypeSizeInBits(ScV4Int32Ty)); |
351 | EXPECT_EQ(DL.getTypeSizeInBits(ScV2Int32Ty).getKnownMinValue(), 64U); |
352 | EXPECT_EQ(DL.getTypeStoreSize(ScV2Int64Ty), DL.getTypeStoreSize(ScV4Int32Ty)); |
353 | EXPECT_NE(DL.getTypeStoreSizeInBits(ScV2Int32Ty), |
354 | DL.getTypeStoreSizeInBits(ScV2Int64Ty)); |
355 | EXPECT_EQ(DL.getTypeStoreSizeInBits(ScV2Int32Ty).getKnownMinValue(), 64U); |
356 | EXPECT_EQ(DL.getTypeStoreSize(ScV2Int64Ty).getKnownMinValue(), 16U); |
357 | EXPECT_EQ(DL.getTypeAllocSize(ScV4Int32Ty), DL.getTypeAllocSize(ScV2Int64Ty)); |
358 | EXPECT_NE(DL.getTypeAllocSizeInBits(ScV2Int32Ty), |
359 | DL.getTypeAllocSizeInBits(ScV2Int64Ty)); |
360 | EXPECT_EQ(DL.getTypeAllocSizeInBits(ScV4Int32Ty).getKnownMinValue(), 128U); |
361 | EXPECT_EQ(DL.getTypeAllocSize(ScV2Int32Ty).getKnownMinValue(), 8U); |
362 | ASSERT_TRUE(DL.typeSizeEqualsStoreSize(ScV4Int32Ty)); |
363 | } |
364 | |
365 | TEST(VectorTypesTest, CrossComparisons) { |
366 | LLVMContext Ctx; |
367 | |
368 | Type *Int32Ty = Type::getInt32Ty(C&: Ctx); |
369 | |
370 | auto *V4Int32Ty = FixedVectorType::get(ElementType: Int32Ty, NumElts: 4); |
371 | auto *ScV4Int32Ty = ScalableVectorType::get(ElementType: Int32Ty, MinNumElts: 4); |
372 | |
373 | // Even though the minimum size is the same, a scalable vector could be |
374 | // larger so we don't consider them to be the same size. |
375 | EXPECT_NE(V4Int32Ty->getPrimitiveSizeInBits(), |
376 | ScV4Int32Ty->getPrimitiveSizeInBits()); |
377 | // If we are only checking the minimum, then they are the same size. |
378 | EXPECT_EQ(V4Int32Ty->getPrimitiveSizeInBits().getKnownMinValue(), |
379 | ScV4Int32Ty->getPrimitiveSizeInBits().getKnownMinValue()); |
380 | |
381 | // We can't use ordering comparisons (<,<=,>,>=) between scalable and |
382 | // non-scalable vector sizes. |
383 | } |
384 | |
385 | } // end anonymous namespace |
386 | |