File: VectorTypesTest.cpp

package info (click to toggle)
llvm-toolchain-9 1%3A9.0.1-16
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 882,436 kB
  • sloc: cpp: 4,167,636; ansic: 714,256; asm: 457,610; python: 155,927; objc: 65,094; sh: 42,856; lisp: 26,908; perl: 7,786; pascal: 7,722; makefile: 6,881; ml: 5,581; awk: 3,648; cs: 2,027; xml: 888; javascript: 381; ruby: 156
file content (164 lines) | stat: -rw-r--r-- 6,576 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
//===--- llvm/unittest/IR/VectorTypesTest.cpp - vector types unit tests ---===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#include "llvm/IR/DerivedTypes.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/Support/ScalableSize.h"
#include "gtest/gtest.h"
using namespace llvm;

namespace {
TEST(VectorTypesTest, FixedLength) {
  LLVMContext Ctx;

  Type *Int16Ty = Type::getInt16Ty(Ctx);
  Type *Int32Ty = Type::getInt32Ty(Ctx);
  Type *Int64Ty = Type::getInt64Ty(Ctx);
  Type *Float64Ty = Type::getDoubleTy(Ctx);

  VectorType *V8Int32Ty = VectorType::get(Int32Ty, 8);
  ASSERT_FALSE(V8Int32Ty->isScalable());
  EXPECT_EQ(V8Int32Ty->getNumElements(), 8U);
  EXPECT_EQ(V8Int32Ty->getElementType()->getScalarSizeInBits(), 32U);

  VectorType *V8Int16Ty = VectorType::get(Int16Ty, {8, false});
  ASSERT_FALSE(V8Int16Ty->isScalable());
  EXPECT_EQ(V8Int16Ty->getNumElements(), 8U);
  EXPECT_EQ(V8Int16Ty->getElementType()->getScalarSizeInBits(), 16U);

  ElementCount EltCnt(4, false);
  VectorType *V4Int64Ty = VectorType::get(Int64Ty, EltCnt);
  ASSERT_FALSE(V4Int64Ty->isScalable());
  EXPECT_EQ(V4Int64Ty->getNumElements(), 4U);
  EXPECT_EQ(V4Int64Ty->getElementType()->getScalarSizeInBits(), 64U);

  VectorType *V2Int64Ty = VectorType::get(Int64Ty, EltCnt/2);
  ASSERT_FALSE(V2Int64Ty->isScalable());
  EXPECT_EQ(V2Int64Ty->getNumElements(), 2U);
  EXPECT_EQ(V2Int64Ty->getElementType()->getScalarSizeInBits(), 64U);

  VectorType *V8Int64Ty = VectorType::get(Int64Ty, EltCnt*2);
  ASSERT_FALSE(V8Int64Ty->isScalable());
  EXPECT_EQ(V8Int64Ty->getNumElements(), 8U);
  EXPECT_EQ(V8Int64Ty->getElementType()->getScalarSizeInBits(), 64U);

  VectorType *V4Float64Ty = VectorType::get(Float64Ty, EltCnt);
  ASSERT_FALSE(V4Float64Ty->isScalable());
  EXPECT_EQ(V4Float64Ty->getNumElements(), 4U);
  EXPECT_EQ(V4Float64Ty->getElementType()->getScalarSizeInBits(), 64U);

  VectorType *ExtTy = VectorType::getExtendedElementVectorType(V8Int16Ty);
  EXPECT_EQ(ExtTy, V8Int32Ty);
  ASSERT_FALSE(ExtTy->isScalable());
  EXPECT_EQ(ExtTy->getNumElements(), 8U);
  EXPECT_EQ(ExtTy->getElementType()->getScalarSizeInBits(), 32U);

  VectorType *TruncTy = VectorType::getTruncatedElementVectorType(V8Int32Ty);
  EXPECT_EQ(TruncTy, V8Int16Ty);
  ASSERT_FALSE(TruncTy->isScalable());
  EXPECT_EQ(TruncTy->getNumElements(), 8U);
  EXPECT_EQ(TruncTy->getElementType()->getScalarSizeInBits(), 16U);

  VectorType *HalvedTy = VectorType::getHalfElementsVectorType(V4Int64Ty);
  EXPECT_EQ(HalvedTy, V2Int64Ty);
  ASSERT_FALSE(HalvedTy->isScalable());
  EXPECT_EQ(HalvedTy->getNumElements(), 2U);
  EXPECT_EQ(HalvedTy->getElementType()->getScalarSizeInBits(), 64U);

  VectorType *DoubledTy = VectorType::getDoubleElementsVectorType(V4Int64Ty);
  EXPECT_EQ(DoubledTy, V8Int64Ty);
  ASSERT_FALSE(DoubledTy->isScalable());
  EXPECT_EQ(DoubledTy->getNumElements(), 8U);
  EXPECT_EQ(DoubledTy->getElementType()->getScalarSizeInBits(), 64U);

  VectorType *ConvTy = VectorType::getInteger(V4Float64Ty);
  EXPECT_EQ(ConvTy, V4Int64Ty);
  ASSERT_FALSE(ConvTy->isScalable());
  EXPECT_EQ(ConvTy->getNumElements(), 4U);
  EXPECT_EQ(ConvTy->getElementType()->getScalarSizeInBits(), 64U);

  EltCnt = V8Int64Ty->getElementCount();
  EXPECT_EQ(EltCnt.Min, 8U);
  ASSERT_FALSE(EltCnt.Scalable);
}

TEST(VectorTypesTest, Scalable) {
  LLVMContext Ctx;

  Type *Int16Ty = Type::getInt16Ty(Ctx);
  Type *Int32Ty = Type::getInt32Ty(Ctx);
  Type *Int64Ty = Type::getInt64Ty(Ctx);
  Type *Float64Ty = Type::getDoubleTy(Ctx);

  VectorType *ScV8Int32Ty = VectorType::get(Int32Ty, 8, true);
  ASSERT_TRUE(ScV8Int32Ty->isScalable());
  EXPECT_EQ(ScV8Int32Ty->getNumElements(), 8U);
  EXPECT_EQ(ScV8Int32Ty->getElementType()->getScalarSizeInBits(), 32U);

  VectorType *ScV8Int16Ty = VectorType::get(Int16Ty, {8, true});
  ASSERT_TRUE(ScV8Int16Ty->isScalable());
  EXPECT_EQ(ScV8Int16Ty->getNumElements(), 8U);
  EXPECT_EQ(ScV8Int16Ty->getElementType()->getScalarSizeInBits(), 16U);

  ElementCount EltCnt(4, true);
  VectorType *ScV4Int64Ty = VectorType::get(Int64Ty, EltCnt);
  ASSERT_TRUE(ScV4Int64Ty->isScalable());
  EXPECT_EQ(ScV4Int64Ty->getNumElements(), 4U);
  EXPECT_EQ(ScV4Int64Ty->getElementType()->getScalarSizeInBits(), 64U);

  VectorType *ScV2Int64Ty = VectorType::get(Int64Ty, EltCnt/2);
  ASSERT_TRUE(ScV2Int64Ty->isScalable());
  EXPECT_EQ(ScV2Int64Ty->getNumElements(), 2U);
  EXPECT_EQ(ScV2Int64Ty->getElementType()->getScalarSizeInBits(), 64U);

  VectorType *ScV8Int64Ty = VectorType::get(Int64Ty, EltCnt*2);
  ASSERT_TRUE(ScV8Int64Ty->isScalable());
  EXPECT_EQ(ScV8Int64Ty->getNumElements(), 8U);
  EXPECT_EQ(ScV8Int64Ty->getElementType()->getScalarSizeInBits(), 64U);

  VectorType *ScV4Float64Ty = VectorType::get(Float64Ty, EltCnt);
  ASSERT_TRUE(ScV4Float64Ty->isScalable());
  EXPECT_EQ(ScV4Float64Ty->getNumElements(), 4U);
  EXPECT_EQ(ScV4Float64Ty->getElementType()->getScalarSizeInBits(), 64U);

  VectorType *ExtTy = VectorType::getExtendedElementVectorType(ScV8Int16Ty);
  EXPECT_EQ(ExtTy, ScV8Int32Ty);
  ASSERT_TRUE(ExtTy->isScalable());
  EXPECT_EQ(ExtTy->getNumElements(), 8U);
  EXPECT_EQ(ExtTy->getElementType()->getScalarSizeInBits(), 32U);

  VectorType *TruncTy = VectorType::getTruncatedElementVectorType(ScV8Int32Ty);
  EXPECT_EQ(TruncTy, ScV8Int16Ty);
  ASSERT_TRUE(TruncTy->isScalable());
  EXPECT_EQ(TruncTy->getNumElements(), 8U);
  EXPECT_EQ(TruncTy->getElementType()->getScalarSizeInBits(), 16U);

  VectorType *HalvedTy = VectorType::getHalfElementsVectorType(ScV4Int64Ty);
  EXPECT_EQ(HalvedTy, ScV2Int64Ty);
  ASSERT_TRUE(HalvedTy->isScalable());
  EXPECT_EQ(HalvedTy->getNumElements(), 2U);
  EXPECT_EQ(HalvedTy->getElementType()->getScalarSizeInBits(), 64U);

  VectorType *DoubledTy = VectorType::getDoubleElementsVectorType(ScV4Int64Ty);
  EXPECT_EQ(DoubledTy, ScV8Int64Ty);
  ASSERT_TRUE(DoubledTy->isScalable());
  EXPECT_EQ(DoubledTy->getNumElements(), 8U);
  EXPECT_EQ(DoubledTy->getElementType()->getScalarSizeInBits(), 64U);

  VectorType *ConvTy = VectorType::getInteger(ScV4Float64Ty);
  EXPECT_EQ(ConvTy, ScV4Int64Ty);
  ASSERT_TRUE(ConvTy->isScalable());
  EXPECT_EQ(ConvTy->getNumElements(), 4U);
  EXPECT_EQ(ConvTy->getElementType()->getScalarSizeInBits(), 64U);

  EltCnt = ScV8Int64Ty->getElementCount();
  EXPECT_EQ(EltCnt.Min, 8U);
  ASSERT_TRUE(EltCnt.Scalable);
}

} // end anonymous namespace