[lit] Remove unnecessary tracking of test_index
[llvm-complete.git] / unittests / CodeGen / ScalableVectorMVTsTest.cpp
blob14a619653744e41b15245aa96539ffaa8cab0ef4
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 //===----------------------------------------------------------------------===//
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"
16 using namespace llvm;
18 namespace {
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());
28 ASSERT_FALSE(VecTy.isFloatingPoint());
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());
40 ASSERT_FALSE(VecTy.isInteger());
44 TEST(ScalableVectorMVTsTest, HelperFuncs) {
45 LLVMContext Ctx;
47 // Create with scalable flag
48 EVT Vnx4i32 = EVT::getVectorVT(Ctx, MVT::i32, 4, /*Scalable=*/true);
49 ASSERT_TRUE(Vnx4i32.isScalableVector());
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());
56 // Create with inline llvm::ElementCount
57 EVT Vnx2i64 = EVT::getVectorVT(Ctx, MVT::i64, {2, true});
58 ASSERT_TRUE(Vnx2i64.isScalableVector());
60 // Check that changing scalar types/element count works
61 EXPECT_EQ(Vnx2i32.widenIntegerVectorElementType(Ctx), Vnx2i64);
62 EXPECT_EQ(Vnx4i32.getHalfNumVectorElementsVT(Ctx), Vnx2i32);
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);
68 // Check that float->int conversion works
69 EVT Vnx2f64 = EVT::getVectorVT(Ctx, MVT::f64, {2, true});
70 EXPECT_EQ(Vnx2f64.changeTypeToInteger(), Vnx2i64);
72 // Check fields inside llvm::ElementCount
73 EltCnt = Vnx4i32.getVectorElementCount();
74 EXPECT_EQ(EltCnt.Min, 4U);
75 ASSERT_TRUE(EltCnt.Scalable);
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());
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);
89 TEST(ScalableVectorMVTsTest, IRToVTTranslation) {
90 LLVMContext Ctx;
92 Type *Int64Ty = Type::getInt64Ty(Ctx);
93 VectorType *ScV8Int64Ty = VectorType::get(Int64Ty, {8, true});
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());
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());
110 TEST(ScalableVectorMVTsTest, VTToIRTranslation) {
111 LLVMContext Ctx;
113 EVT Enxv4f64 = EVT::getVectorVT(Ctx, MVT::f64, {4, true});
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());
123 } // end anonymous namespace