[ARM] MVE big endian bitcasts
[llvm-complete.git] / unittests / CodeGen / ScalableVectorMVTsTest.cpp
blob3dd3bec8db79cf1eea4e4665832e7b7be18c36f8
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/LLVMContext.h"
11 #include "llvm/Support/MachineValueType.h"
12 #include "gtest/gtest.h"
14 using namespace llvm;
16 namespace {
18 TEST(ScalableVectorMVTsTest, IntegerMVTs) {
19 for (auto VecTy : MVT::integer_scalable_vector_valuetypes()) {
20 ASSERT_TRUE(VecTy.isValid());
21 ASSERT_TRUE(VecTy.isInteger());
22 ASSERT_TRUE(VecTy.isVector());
23 ASSERT_TRUE(VecTy.isScalableVector());
24 ASSERT_TRUE(VecTy.getScalarType().isValid());
26 ASSERT_FALSE(VecTy.isFloatingPoint());
30 TEST(ScalableVectorMVTsTest, FloatMVTs) {
31 for (auto VecTy : MVT::fp_scalable_vector_valuetypes()) {
32 ASSERT_TRUE(VecTy.isValid());
33 ASSERT_TRUE(VecTy.isFloatingPoint());
34 ASSERT_TRUE(VecTy.isVector());
35 ASSERT_TRUE(VecTy.isScalableVector());
36 ASSERT_TRUE(VecTy.getScalarType().isValid());
38 ASSERT_FALSE(VecTy.isInteger());
42 TEST(ScalableVectorMVTsTest, HelperFuncs) {
43 LLVMContext Ctx;
45 // Create with scalable flag
46 EVT Vnx4i32 = EVT::getVectorVT(Ctx, MVT::i32, 4, /*Scalable=*/true);
47 ASSERT_TRUE(Vnx4i32.isScalableVector());
49 // Create with separate MVT::ElementCount
50 auto EltCnt = MVT::ElementCount(2, true);
51 EVT Vnx2i32 = EVT::getVectorVT(Ctx, MVT::i32, EltCnt);
52 ASSERT_TRUE(Vnx2i32.isScalableVector());
54 // Create with inline MVT::ElementCount
55 EVT Vnx2i64 = EVT::getVectorVT(Ctx, MVT::i64, {2, true});
56 ASSERT_TRUE(Vnx2i64.isScalableVector());
58 // Check that changing scalar types/element count works
59 EXPECT_EQ(Vnx2i32.widenIntegerVectorElementType(Ctx), Vnx2i64);
60 EXPECT_EQ(Vnx4i32.getHalfNumVectorElementsVT(Ctx), Vnx2i32);
62 // Check that overloaded '*' and '/' operators work
63 EXPECT_EQ(EVT::getVectorVT(Ctx, MVT::i64, EltCnt * 2), MVT::nxv4i64);
64 EXPECT_EQ(EVT::getVectorVT(Ctx, MVT::i64, EltCnt / 2), MVT::nxv1i64);
66 // Check that float->int conversion works
67 EVT Vnx2f64 = EVT::getVectorVT(Ctx, MVT::f64, {2, true});
68 EXPECT_EQ(Vnx2f64.changeTypeToInteger(), Vnx2i64);
70 // Check fields inside MVT::ElementCount
71 EltCnt = Vnx4i32.getVectorElementCount();
72 EXPECT_EQ(EltCnt.Min, 4U);
73 ASSERT_TRUE(EltCnt.Scalable);
75 // Check that fixed-length vector types aren't scalable.
76 EVT V8i32 = EVT::getVectorVT(Ctx, MVT::i32, 8);
77 ASSERT_FALSE(V8i32.isScalableVector());
78 EVT V4f64 = EVT::getVectorVT(Ctx, MVT::f64, {4, false});
79 ASSERT_FALSE(V4f64.isScalableVector());
81 // Check that MVT::ElementCount works for fixed-length types.
82 EltCnt = V8i32.getVectorElementCount();
83 EXPECT_EQ(EltCnt.Min, 8U);
84 ASSERT_FALSE(EltCnt.Scalable);