Mercurial > hg > CbC > CbC_llvm
comparison llvm/unittests/CodeGen/ScalableVectorMVTsTest.cpp @ 150:1d019706d866
LLVM10
author | anatofuz |
---|---|
date | Thu, 13 Feb 2020 15:10:13 +0900 |
parents | |
children | 0572611fdcc8 |
comparison
equal
deleted
inserted
replaced
147:c2174574ed3a | 150:1d019706d866 |
---|---|
1 //===-------- llvm/unittest/CodeGen/ScalableVectorMVTsTest.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/ValueTypes.h" | |
10 #include "llvm/IR/DerivedTypes.h" | |
11 #include "llvm/IR/LLVMContext.h" | |
12 #include "llvm/Support/MachineValueType.h" | |
13 #include "llvm/Support/TypeSize.h" | |
14 #include "gtest/gtest.h" | |
15 | |
16 using namespace llvm; | |
17 | |
18 namespace { | |
19 | |
20 TEST(ScalableVectorMVTsTest, IntegerMVTs) { | |
21 for (auto VecTy : MVT::integer_scalable_vector_valuetypes()) { | |
22 ASSERT_TRUE(VecTy.isValid()); | |
23 ASSERT_TRUE(VecTy.isInteger()); | |
24 ASSERT_TRUE(VecTy.isVector()); | |
25 ASSERT_TRUE(VecTy.isScalableVector()); | |
26 ASSERT_TRUE(VecTy.getScalarType().isValid()); | |
27 | |
28 ASSERT_FALSE(VecTy.isFloatingPoint()); | |
29 } | |
30 } | |
31 | |
32 TEST(ScalableVectorMVTsTest, FloatMVTs) { | |
33 for (auto VecTy : MVT::fp_scalable_vector_valuetypes()) { | |
34 ASSERT_TRUE(VecTy.isValid()); | |
35 ASSERT_TRUE(VecTy.isFloatingPoint()); | |
36 ASSERT_TRUE(VecTy.isVector()); | |
37 ASSERT_TRUE(VecTy.isScalableVector()); | |
38 ASSERT_TRUE(VecTy.getScalarType().isValid()); | |
39 | |
40 ASSERT_FALSE(VecTy.isInteger()); | |
41 } | |
42 } | |
43 | |
44 TEST(ScalableVectorMVTsTest, HelperFuncs) { | |
45 LLVMContext Ctx; | |
46 | |
47 // Create with scalable flag | |
48 EVT Vnx4i32 = EVT::getVectorVT(Ctx, MVT::i32, 4, /*Scalable=*/true); | |
49 ASSERT_TRUE(Vnx4i32.isScalableVector()); | |
50 | |
51 // Create with separate llvm::ElementCount | |
52 auto EltCnt = ElementCount(2, true); | |
53 EVT Vnx2i32 = EVT::getVectorVT(Ctx, MVT::i32, EltCnt); | |
54 ASSERT_TRUE(Vnx2i32.isScalableVector()); | |
55 | |
56 // Create with inline llvm::ElementCount | |
57 EVT Vnx2i64 = EVT::getVectorVT(Ctx, MVT::i64, {2, true}); | |
58 ASSERT_TRUE(Vnx2i64.isScalableVector()); | |
59 | |
60 // Check that changing scalar types/element count works | |
61 EXPECT_EQ(Vnx2i32.widenIntegerVectorElementType(Ctx), Vnx2i64); | |
62 EXPECT_EQ(Vnx4i32.getHalfNumVectorElementsVT(Ctx), Vnx2i32); | |
63 | |
64 // Check that overloaded '*' and '/' operators work | |
65 EXPECT_EQ(EVT::getVectorVT(Ctx, MVT::i64, EltCnt * 2), MVT::nxv4i64); | |
66 EXPECT_EQ(EVT::getVectorVT(Ctx, MVT::i64, EltCnt / 2), MVT::nxv1i64); | |
67 | |
68 // Check that float->int conversion works | |
69 EVT Vnx2f64 = EVT::getVectorVT(Ctx, MVT::f64, {2, true}); | |
70 EXPECT_EQ(Vnx2f64.changeTypeToInteger(), Vnx2i64); | |
71 | |
72 // Check fields inside llvm::ElementCount | |
73 EltCnt = Vnx4i32.getVectorElementCount(); | |
74 EXPECT_EQ(EltCnt.Min, 4U); | |
75 ASSERT_TRUE(EltCnt.Scalable); | |
76 | |
77 // Check that fixed-length vector types aren't scalable. | |
78 EVT V8i32 = EVT::getVectorVT(Ctx, MVT::i32, 8); | |
79 ASSERT_FALSE(V8i32.isScalableVector()); | |
80 EVT V4f64 = EVT::getVectorVT(Ctx, MVT::f64, {4, false}); | |
81 ASSERT_FALSE(V4f64.isScalableVector()); | |
82 | |
83 // Check that llvm::ElementCount works for fixed-length types. | |
84 EltCnt = V8i32.getVectorElementCount(); | |
85 EXPECT_EQ(EltCnt.Min, 8U); | |
86 ASSERT_FALSE(EltCnt.Scalable); | |
87 } | |
88 | |
89 TEST(ScalableVectorMVTsTest, IRToVTTranslation) { | |
90 LLVMContext Ctx; | |
91 | |
92 Type *Int64Ty = Type::getInt64Ty(Ctx); | |
93 VectorType *ScV8Int64Ty = VectorType::get(Int64Ty, {8, true}); | |
94 | |
95 // Check that we can map a scalable IR type to an MVT | |
96 MVT Mnxv8i64 = MVT::getVT(ScV8Int64Ty); | |
97 ASSERT_TRUE(Mnxv8i64.isScalableVector()); | |
98 ASSERT_EQ(ScV8Int64Ty->getElementCount(), Mnxv8i64.getVectorElementCount()); | |
99 ASSERT_EQ(MVT::getVT(ScV8Int64Ty->getElementType()), | |
100 Mnxv8i64.getScalarType()); | |
101 | |
102 // Check that we can map a scalable IR type to an EVT | |
103 EVT Enxv8i64 = EVT::getEVT(ScV8Int64Ty); | |
104 ASSERT_TRUE(Enxv8i64.isScalableVector()); | |
105 ASSERT_EQ(ScV8Int64Ty->getElementCount(), Enxv8i64.getVectorElementCount()); | |
106 ASSERT_EQ(EVT::getEVT(ScV8Int64Ty->getElementType()), | |
107 Enxv8i64.getScalarType()); | |
108 } | |
109 | |
110 TEST(ScalableVectorMVTsTest, VTToIRTranslation) { | |
111 LLVMContext Ctx; | |
112 | |
113 EVT Enxv4f64 = EVT::getVectorVT(Ctx, MVT::f64, {4, true}); | |
114 | |
115 Type *Ty = Enxv4f64.getTypeForEVT(Ctx); | |
116 VectorType *ScV4Float64Ty = cast<VectorType>(Ty); | |
117 ASSERT_TRUE(ScV4Float64Ty->isScalable()); | |
118 ASSERT_EQ(Enxv4f64.getVectorElementCount(), ScV4Float64Ty->getElementCount()); | |
119 ASSERT_EQ(Enxv4f64.getScalarType().getTypeForEVT(Ctx), | |
120 ScV4Float64Ty->getElementType()); | |
121 } | |
122 | |
123 TEST(ScalableVectorMVTsTest, SizeQueries) { | |
124 LLVMContext Ctx; | |
125 | |
126 EVT nxv4i32 = EVT::getVectorVT(Ctx, MVT::i32, 4, /*Scalable=*/ true); | |
127 EVT nxv2i32 = EVT::getVectorVT(Ctx, MVT::i32, 2, /*Scalable=*/ true); | |
128 EVT nxv2i64 = EVT::getVectorVT(Ctx, MVT::i64, 2, /*Scalable=*/ true); | |
129 EVT nxv2f64 = EVT::getVectorVT(Ctx, MVT::f64, 2, /*Scalable=*/ true); | |
130 | |
131 EVT v4i32 = EVT::getVectorVT(Ctx, MVT::i32, 4); | |
132 EVT v2i32 = EVT::getVectorVT(Ctx, MVT::i32, 2); | |
133 EVT v2i64 = EVT::getVectorVT(Ctx, MVT::i64, 2); | |
134 EVT v2f64 = EVT::getVectorVT(Ctx, MVT::f64, 2); | |
135 | |
136 // Check equivalence and ordering on scalable types. | |
137 EXPECT_EQ(nxv4i32.getSizeInBits(), nxv2i64.getSizeInBits()); | |
138 EXPECT_EQ(nxv2f64.getSizeInBits(), nxv2i64.getSizeInBits()); | |
139 EXPECT_NE(nxv2i32.getSizeInBits(), nxv4i32.getSizeInBits()); | |
140 EXPECT_LT(nxv2i32.getSizeInBits(), nxv2i64.getSizeInBits()); | |
141 EXPECT_LE(nxv4i32.getSizeInBits(), nxv2i64.getSizeInBits()); | |
142 EXPECT_GT(nxv4i32.getSizeInBits(), nxv2i32.getSizeInBits()); | |
143 EXPECT_GE(nxv2i64.getSizeInBits(), nxv4i32.getSizeInBits()); | |
144 | |
145 // Check equivalence and ordering on fixed types. | |
146 EXPECT_EQ(v4i32.getSizeInBits(), v2i64.getSizeInBits()); | |
147 EXPECT_EQ(v2f64.getSizeInBits(), v2i64.getSizeInBits()); | |
148 EXPECT_NE(v2i32.getSizeInBits(), v4i32.getSizeInBits()); | |
149 EXPECT_LT(v2i32.getSizeInBits(), v2i64.getSizeInBits()); | |
150 EXPECT_LE(v4i32.getSizeInBits(), v2i64.getSizeInBits()); | |
151 EXPECT_GT(v4i32.getSizeInBits(), v2i32.getSizeInBits()); | |
152 EXPECT_GE(v2i64.getSizeInBits(), v4i32.getSizeInBits()); | |
153 | |
154 // Check that scalable and non-scalable types with the same minimum size | |
155 // are not considered equal. | |
156 ASSERT_TRUE(v4i32.getSizeInBits() != nxv4i32.getSizeInBits()); | |
157 ASSERT_FALSE(v2i64.getSizeInBits() == nxv2f64.getSizeInBits()); | |
158 | |
159 // Check that we can obtain a known-exact size from a non-scalable type. | |
160 EXPECT_EQ(v4i32.getSizeInBits(), 128U); | |
161 EXPECT_EQ(v2i64.getSizeInBits().getFixedSize(), 128U); | |
162 | |
163 // Check that we can query the known minimum size for both scalable and | |
164 // fixed length types. | |
165 EXPECT_EQ(nxv2i32.getSizeInBits().getKnownMinSize(), 64U); | |
166 EXPECT_EQ(nxv2f64.getSizeInBits().getKnownMinSize(), 128U); | |
167 EXPECT_EQ(v2i32.getSizeInBits().getKnownMinSize(), | |
168 nxv2i32.getSizeInBits().getKnownMinSize()); | |
169 | |
170 // Check scalable property. | |
171 ASSERT_FALSE(v4i32.getSizeInBits().isScalable()); | |
172 ASSERT_TRUE(nxv4i32.getSizeInBits().isScalable()); | |
173 | |
174 // Check convenience size scaling methods. | |
175 EXPECT_EQ(v2i32.getSizeInBits() * 2, v4i32.getSizeInBits()); | |
176 EXPECT_EQ(2 * nxv2i32.getSizeInBits(), nxv4i32.getSizeInBits()); | |
177 EXPECT_EQ(nxv2f64.getSizeInBits() / 2, nxv2i32.getSizeInBits()); | |
178 } | |
179 | |
180 } // end anonymous namespace |