diff options
| author | Graham Hunter <graham.hunter@arm.com> | 2019-06-18 10:11:56 +0000 |
|---|---|---|
| committer | Graham Hunter <graham.hunter@arm.com> | 2019-06-18 10:11:56 +0000 |
| commit | 43854e3ccc7fb9fa2cbe37529a72f77ca512bb86 (patch) | |
| tree | 3d8e9fffe51fc8b98b23a09d22a7070b339c9672 /llvm/unittests | |
| parent | 6658bfb171afa65ca11bd729fcc0301d5d09543e (diff) | |
| download | bcm5719-llvm-43854e3ccc7fb9fa2cbe37529a72f77ca512bb86.tar.gz bcm5719-llvm-43854e3ccc7fb9fa2cbe37529a72f77ca512bb86.zip | |
[SVE][IR] Scalable Vector IR Type with pr42210 fix
Recommit of D32530 with a few small changes:
- Stopped recursively walking through aggregates in
the verifier, so that we don't impose too much
overhead on large modules under LTO (see PR42210).
- Changed tests to match; the errors are slightly
different since they only report the array or
struct that actually contains a scalable vector,
rather than all aggregates which contain one in
a nested member.
- Corrected an older comment
Reviewers: thakis, rengolin, sdesmalen
Reviewed By: sdesmalen
Differential Revision: https://reviews.llvm.org/D63321
llvm-svn: 363658
Diffstat (limited to 'llvm/unittests')
| -rw-r--r-- | llvm/unittests/IR/CMakeLists.txt | 1 | ||||
| -rw-r--r-- | llvm/unittests/IR/VectorTypesTest.cpp | 164 |
2 files changed, 165 insertions, 0 deletions
diff --git a/llvm/unittests/IR/CMakeLists.txt b/llvm/unittests/IR/CMakeLists.txt index 5b35dc72683..d27c6d969f1 100644 --- a/llvm/unittests/IR/CMakeLists.txt +++ b/llvm/unittests/IR/CMakeLists.txt @@ -37,6 +37,7 @@ add_llvm_unittest(IRTests ValueHandleTest.cpp ValueMapTest.cpp ValueTest.cpp + VectorTypesTest.cpp VerifierTest.cpp WaymarkTest.cpp ) diff --git a/llvm/unittests/IR/VectorTypesTest.cpp b/llvm/unittests/IR/VectorTypesTest.cpp new file mode 100644 index 00000000000..f3caf6d6976 --- /dev/null +++ b/llvm/unittests/IR/VectorTypesTest.cpp @@ -0,0 +1,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 |

