Re: [PATCH] D53137: Scalable vector core instruction support + size queries
Hi Graham, It seems you forgot to push the last round of fixes. Just saying :) Cheers, Diana On Tue, 8 Oct 2019 at 16:01, Graham Hunter via Phabricator wrote: > > huntergr added a comment. > > Hmm, forgot to add the last round of minor fixes before committing. Sorry > about that, will push them as well. > > > Repository: > rG LLVM Github Monorepo > > CHANGES SINCE LAST ACTION > https://reviews.llvm.org/D53137/new/ > > https://reviews.llvm.org/D53137 > > > ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D53137: Scalable vector core instruction support + size queries
huntergr added a comment. Hmm, forgot to add the last round of minor fixes before committing. Sorry about that, will push them as well. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D53137/new/ https://reviews.llvm.org/D53137 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D53137: Scalable vector core instruction support + size queries
This revision was automatically updated to reflect the committed changes. Closed by commit rGb302561b763a: [SVE][IR] Scalable Vector size queries and IR instruction support (authored by huntergr). Changed prior to commit: https://reviews.llvm.org/D53137?vs=222593=223835#toc Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D53137/new/ https://reviews.llvm.org/D53137 Files: clang/lib/CodeGen/CGCall.cpp clang/lib/CodeGen/CGStmt.cpp clang/lib/CodeGen/CodeGenFunction.cpp llvm/include/llvm/ADT/DenseMapInfo.h llvm/include/llvm/IR/DataLayout.h llvm/include/llvm/IR/DerivedTypes.h llvm/include/llvm/IR/InstrTypes.h llvm/include/llvm/IR/Type.h llvm/include/llvm/Support/MachineValueType.h llvm/include/llvm/Support/ScalableSize.h llvm/include/llvm/Support/TypeSize.h llvm/lib/Analysis/InlineCost.cpp llvm/lib/CodeGen/Analysis.cpp llvm/lib/IR/DataLayout.cpp llvm/lib/IR/Instructions.cpp llvm/lib/IR/Type.cpp llvm/lib/Target/AArch64/AArch64ISelLowering.cpp llvm/lib/Transforms/Scalar/SROA.cpp llvm/test/Other/scalable-vectors-core-ir.ll llvm/unittests/CodeGen/ScalableVectorMVTsTest.cpp llvm/unittests/IR/VectorTypesTest.cpp Index: llvm/unittests/IR/VectorTypesTest.cpp === --- llvm/unittests/IR/VectorTypesTest.cpp +++ llvm/unittests/IR/VectorTypesTest.cpp @@ -6,9 +6,10 @@ // //===--===// +#include "llvm/IR/DataLayout.h" #include "llvm/IR/DerivedTypes.h" #include "llvm/IR/LLVMContext.h" -#include "llvm/Support/ScalableSize.h" +#include "llvm/Support/TypeSize.h" #include "gtest/gtest.h" using namespace llvm; @@ -161,4 +162,117 @@ ASSERT_TRUE(EltCnt.Scalable); } +TEST(VectorTypesTest, FixedLenComparisons) { + LLVMContext Ctx; + DataLayout DL(""); + + Type *Int32Ty = Type::getInt32Ty(Ctx); + Type *Int64Ty = Type::getInt64Ty(Ctx); + + VectorType *V2Int32Ty = VectorType::get(Int32Ty, 2); + VectorType *V4Int32Ty = VectorType::get(Int32Ty, 4); + + VectorType *V2Int64Ty = VectorType::get(Int64Ty, 2); + + TypeSize V2I32Len = V2Int32Ty->getPrimitiveSizeInBits(); + EXPECT_EQ(V2I32Len.getKnownMinSize(), 64U); + EXPECT_FALSE(V2I32Len.isScalable()); + + EXPECT_LT(V2Int32Ty->getPrimitiveSizeInBits(), +V4Int32Ty->getPrimitiveSizeInBits()); + EXPECT_GT(V2Int64Ty->getPrimitiveSizeInBits(), +V2Int32Ty->getPrimitiveSizeInBits()); + EXPECT_EQ(V4Int32Ty->getPrimitiveSizeInBits(), +V2Int64Ty->getPrimitiveSizeInBits()); + EXPECT_NE(V2Int32Ty->getPrimitiveSizeInBits(), +V2Int64Ty->getPrimitiveSizeInBits()); + + // Check that a fixed-only comparison works for fixed size vectors. + EXPECT_EQ(V2Int64Ty->getPrimitiveSizeInBits().getFixedSize(), +V4Int32Ty->getPrimitiveSizeInBits().getFixedSize()); + + // Check the DataLayout interfaces. + EXPECT_EQ(DL.getTypeSizeInBits(V2Int64Ty), +DL.getTypeSizeInBits(V4Int32Ty)); + EXPECT_EQ(DL.getTypeSizeInBits(V2Int32Ty), 64U); + EXPECT_EQ(DL.getTypeSizeInBits(V2Int64Ty), 128U); + EXPECT_EQ(DL.getTypeStoreSize(V2Int64Ty), +DL.getTypeStoreSize(V4Int32Ty)); + EXPECT_NE(DL.getTypeStoreSizeInBits(V2Int32Ty), +DL.getTypeStoreSizeInBits(V2Int64Ty)); + EXPECT_EQ(DL.getTypeStoreSizeInBits(V2Int32Ty), 64U); + EXPECT_EQ(DL.getTypeStoreSize(V2Int64Ty), 16U); + EXPECT_EQ(DL.getTypeAllocSize(V4Int32Ty), +DL.getTypeAllocSize(V2Int64Ty)); + EXPECT_NE(DL.getTypeAllocSizeInBits(V2Int32Ty), +DL.getTypeAllocSizeInBits(V2Int64Ty)); + EXPECT_EQ(DL.getTypeAllocSizeInBits(V4Int32Ty), 128U); + EXPECT_EQ(DL.getTypeAllocSize(V2Int32Ty), 8U); + ASSERT_TRUE(DL.typeSizeEqualsStoreSize(V4Int32Ty)); +} + +TEST(VectorTypesTest, ScalableComparisons) { + LLVMContext Ctx; + DataLayout DL(""); + + Type *Int32Ty = Type::getInt32Ty(Ctx); + Type *Int64Ty = Type::getInt64Ty(Ctx); + + VectorType *ScV2Int32Ty = VectorType::get(Int32Ty, {2, true}); + VectorType *ScV4Int32Ty = VectorType::get(Int32Ty, {4, true}); + + VectorType *ScV2Int64Ty = VectorType::get(Int64Ty, {2, true}); + + TypeSize ScV2I32Len = ScV2Int32Ty->getPrimitiveSizeInBits(); + EXPECT_EQ(ScV2I32Len.getKnownMinSize(), 64U); + EXPECT_TRUE(ScV2I32Len.isScalable()); + + EXPECT_LT(ScV2Int32Ty->getPrimitiveSizeInBits(), +ScV4Int32Ty->getPrimitiveSizeInBits()); + EXPECT_GT(ScV2Int64Ty->getPrimitiveSizeInBits(), +ScV2Int32Ty->getPrimitiveSizeInBits()); + EXPECT_EQ(ScV4Int32Ty->getPrimitiveSizeInBits(), +ScV2Int64Ty->getPrimitiveSizeInBits()); + EXPECT_NE(ScV2Int32Ty->getPrimitiveSizeInBits(), +ScV2Int64Ty->getPrimitiveSizeInBits()); + + // Check the DataLayout interfaces. + EXPECT_EQ(DL.getTypeSizeInBits(ScV2Int64Ty), +DL.getTypeSizeInBits(ScV4Int32Ty)); + EXPECT_EQ(DL.getTypeSizeInBits(ScV2Int32Ty).getKnownMinSize(), 64U); +
[PATCH] D53137: Scalable vector core instruction support + size queries
sdesmalen accepted this revision. sdesmalen added a comment. Thanks @huntergr , I think this interface looks really nice. LGTM! Comment at: llvm/include/llvm/IR/DataLayout.h:456 + TypeSize getTypeStoreSize(Type *Ty) const { +auto BaseSize = getTypeSizeInBits(Ty); +return { (BaseSize.getKnownMinSize() + 7) / 8, BaseSize.isScalable() }; nit: use TypeSize instead of auto. Comment at: llvm/include/llvm/IR/DataLayout.h:622 case Type::LabelTyID: -return getPointerSizeInBits(0); +return TypeSize::Fixed(getPointerSizeInBits(0)); case Type::PointerTyID: Nice, I like the interface of `TypeSize::Fixed()` for fixed-size types. Comment at: llvm/lib/IR/Instructions.cpp:2990 // Get the bit sizes, we'll need these - unsigned SrcBits = SrcTy->getPrimitiveSizeInBits(); // 0 for ptr - unsigned DestBits = DestTy->getPrimitiveSizeInBits(); // 0 for ptr + auto SrcBits = SrcTy->getPrimitiveSizeInBits(); // 0 for ptr + auto DestBits = DestTy->getPrimitiveSizeInBits(); // 0 for ptr nit: auto -> TypeSize ? Comment at: llvm/lib/IR/Instructions.cpp:3052 - unsigned SrcBits = SrcTy->getPrimitiveSizeInBits(); // 0 for ptr - unsigned DestBits = DestTy->getPrimitiveSizeInBits(); // 0 for ptr + auto SrcBits = SrcTy->getPrimitiveSizeInBits(); // 0 for ptr + auto DestBits = DestTy->getPrimitiveSizeInBits(); // 0 for ptr nit: auto -> TypeSize ? Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D53137/new/ https://reviews.llvm.org/D53137 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D53137: Scalable vector core instruction support + size queries
rovka accepted this revision. rovka marked 2 inline comments as done. rovka added a comment. This revision is now accepted and ready to land. This looks good to me, maybe wait a while to see if anyone else has any further comments. Comment at: llvm/include/llvm/IR/DataLayout.h:454 +auto BaseSize = getTypeSizeInBits(Ty); +return { (BaseSize.getKnownMinSize() + 7) / 8, BaseSize.isScalable() }; } huntergr wrote: > rovka wrote: > > We already overload operator /, why not overload + as well so we don't have > > to change the body of this method? > Scaling a size with * or / has a clear meaning to me, since it's independent > of vscale; getting a vector that's half the size or four times larger just > works. > > Using + (or -) on the other hand doesn't seem to be as clear; I wasn't sure > if a standalone int should be automatically treated as being the same as the > TypeSize, or always considered Fixed. If we try for the former I can imagine > quite a few bugs arising. > > I could add a roundBitsToNearestByteSize method to move the arithmetic > elsewhere if that would be acceptable? You're right, + on TypeSizes would be confusing. This looks ok as-is then, no need to fiddle with it more. Comment at: llvm/include/llvm/IR/DataLayout.h:656 + getTypeSizeInBits(VTy->getElementType()).getKnownMinSize(); +return ScalableSize(MinBits, EltCnt.Scalable); } huntergr wrote: > rovka wrote: > > Maybe just return VTy->getElementCount() * > > getTypeSizeInBits(VTy->getElementType()).getFixedSize(). > There's no support for generating a TypeSize from an ElementCount in that > way; is that an interface you feel is useful? > > (I'll certainly change the `getKnownMinSize` to `getFixedSize` though, since > we're just referring to a scalar) Actually, no, now that I think about it a bit more it might be clearer to spell it out this way. Comment at: llvm/include/llvm/Support/TypeSize.h:122 + // Use in places where a scalable size doesn't make sense (e.g. non-vector + // types, or vectors in backends which don't support scalable vectors) + uint64_t getFixedSize() const { Microscopic nit: punctuation. Comment at: llvm/include/llvm/Support/TypeSize.h:143 + // NOTE: This interface is obsolete and will be removed in a future version + // of LLVM in favour of calling getFixedSize() directly + operator uint64_t() const { Ditto. Comment at: llvm/include/llvm/Support/TypeSize.h:148 + + // Additional convenience operators needed to avoid ambiguous parses + // TODO: Make uint64_t the default operator? Ditto. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D53137/new/ https://reviews.llvm.org/D53137 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D53137: Scalable vector core instruction support + size queries
huntergr updated this revision to Diff 222593. huntergr added a comment. Herald added a subscriber: dexonsmith. - Renamed `ScalableSize` to `TypeSize`, including header name. - added `alignTo` function that takes and returns a `TypeSize`. I wasn't sure if this should be added to MathExtras.h where the other variants live, so just kept it in TypeSize.h for now Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D53137/new/ https://reviews.llvm.org/D53137 Files: clang/lib/CodeGen/CGCall.cpp clang/lib/CodeGen/CGStmt.cpp clang/lib/CodeGen/CodeGenFunction.cpp llvm/include/llvm/ADT/DenseMapInfo.h llvm/include/llvm/IR/DataLayout.h llvm/include/llvm/IR/DerivedTypes.h llvm/include/llvm/IR/InstrTypes.h llvm/include/llvm/IR/Type.h llvm/include/llvm/Support/MachineValueType.h llvm/include/llvm/Support/ScalableSize.h llvm/include/llvm/Support/TypeSize.h llvm/lib/Analysis/InlineCost.cpp llvm/lib/CodeGen/Analysis.cpp llvm/lib/IR/DataLayout.cpp llvm/lib/IR/Instructions.cpp llvm/lib/IR/Type.cpp llvm/lib/Target/AArch64/AArch64ISelLowering.cpp llvm/lib/Transforms/Scalar/SROA.cpp llvm/test/Other/scalable-vectors-core-ir.ll llvm/unittests/CodeGen/ScalableVectorMVTsTest.cpp llvm/unittests/IR/VectorTypesTest.cpp Index: llvm/unittests/IR/VectorTypesTest.cpp === --- llvm/unittests/IR/VectorTypesTest.cpp +++ llvm/unittests/IR/VectorTypesTest.cpp @@ -6,9 +6,10 @@ // //===--===// +#include "llvm/IR/DataLayout.h" #include "llvm/IR/DerivedTypes.h" #include "llvm/IR/LLVMContext.h" -#include "llvm/Support/ScalableSize.h" +#include "llvm/Support/TypeSize.h" #include "gtest/gtest.h" using namespace llvm; @@ -161,4 +162,117 @@ ASSERT_TRUE(EltCnt.Scalable); } +TEST(VectorTypesTest, FixedLenComparisons) { + LLVMContext Ctx; + DataLayout DL(""); + + Type *Int32Ty = Type::getInt32Ty(Ctx); + Type *Int64Ty = Type::getInt64Ty(Ctx); + + VectorType *V2Int32Ty = VectorType::get(Int32Ty, 2); + VectorType *V4Int32Ty = VectorType::get(Int32Ty, 4); + + VectorType *V2Int64Ty = VectorType::get(Int64Ty, 2); + + TypeSize V2I32Len = V2Int32Ty->getPrimitiveSizeInBits(); + EXPECT_EQ(V2I32Len.getKnownMinSize(), 64U); + EXPECT_FALSE(V2I32Len.isScalable()); + + EXPECT_LT(V2Int32Ty->getPrimitiveSizeInBits(), +V4Int32Ty->getPrimitiveSizeInBits()); + EXPECT_GT(V2Int64Ty->getPrimitiveSizeInBits(), +V2Int32Ty->getPrimitiveSizeInBits()); + EXPECT_EQ(V4Int32Ty->getPrimitiveSizeInBits(), +V2Int64Ty->getPrimitiveSizeInBits()); + EXPECT_NE(V2Int32Ty->getPrimitiveSizeInBits(), +V2Int64Ty->getPrimitiveSizeInBits()); + + // Check that a fixed-only comparison works for fixed size vectors. + EXPECT_EQ(V2Int64Ty->getPrimitiveSizeInBits().getFixedSize(), +V4Int32Ty->getPrimitiveSizeInBits().getFixedSize()); + + // Check the DataLayout interfaces. + EXPECT_EQ(DL.getTypeSizeInBits(V2Int64Ty), +DL.getTypeSizeInBits(V4Int32Ty)); + EXPECT_EQ(DL.getTypeSizeInBits(V2Int32Ty), 64U); + EXPECT_EQ(DL.getTypeSizeInBits(V2Int64Ty), 128U); + EXPECT_EQ(DL.getTypeStoreSize(V2Int64Ty), +DL.getTypeStoreSize(V4Int32Ty)); + EXPECT_NE(DL.getTypeStoreSizeInBits(V2Int32Ty), +DL.getTypeStoreSizeInBits(V2Int64Ty)); + EXPECT_EQ(DL.getTypeStoreSizeInBits(V2Int32Ty), 64U); + EXPECT_EQ(DL.getTypeStoreSize(V2Int64Ty), 16U); + EXPECT_EQ(DL.getTypeAllocSize(V4Int32Ty), +DL.getTypeAllocSize(V2Int64Ty)); + EXPECT_NE(DL.getTypeAllocSizeInBits(V2Int32Ty), +DL.getTypeAllocSizeInBits(V2Int64Ty)); + EXPECT_EQ(DL.getTypeAllocSizeInBits(V4Int32Ty), 128U); + EXPECT_EQ(DL.getTypeAllocSize(V2Int32Ty), 8U); + ASSERT_TRUE(DL.typeSizeEqualsStoreSize(V4Int32Ty)); +} + +TEST(VectorTypesTest, ScalableComparisons) { + LLVMContext Ctx; + DataLayout DL(""); + + Type *Int32Ty = Type::getInt32Ty(Ctx); + Type *Int64Ty = Type::getInt64Ty(Ctx); + + VectorType *ScV2Int32Ty = VectorType::get(Int32Ty, {2, true}); + VectorType *ScV4Int32Ty = VectorType::get(Int32Ty, {4, true}); + + VectorType *ScV2Int64Ty = VectorType::get(Int64Ty, {2, true}); + + TypeSize ScV2I32Len = ScV2Int32Ty->getPrimitiveSizeInBits(); + EXPECT_EQ(ScV2I32Len.getKnownMinSize(), 64U); + EXPECT_TRUE(ScV2I32Len.isScalable()); + + EXPECT_LT(ScV2Int32Ty->getPrimitiveSizeInBits(), +ScV4Int32Ty->getPrimitiveSizeInBits()); + EXPECT_GT(ScV2Int64Ty->getPrimitiveSizeInBits(), +ScV2Int32Ty->getPrimitiveSizeInBits()); + EXPECT_EQ(ScV4Int32Ty->getPrimitiveSizeInBits(), +ScV2Int64Ty->getPrimitiveSizeInBits()); + EXPECT_NE(ScV2Int32Ty->getPrimitiveSizeInBits(), +ScV2Int64Ty->getPrimitiveSizeInBits()); + + // Check the DataLayout interfaces. + EXPECT_EQ(DL.getTypeSizeInBits(ScV2Int64Ty), +DL.getTypeSizeInBits(ScV4Int32Ty)); +
[PATCH] D53137: Scalable vector core instruction support + size queries
huntergr added inline comments. Comment at: llvm/include/llvm/IR/DataLayout.h:454 +auto BaseSize = getTypeSizeInBits(Ty); +return { (BaseSize.getKnownMinSize() + 7) / 8, BaseSize.isScalable() }; } rovka wrote: > We already overload operator /, why not overload + as well so we don't have > to change the body of this method? Scaling a size with * or / has a clear meaning to me, since it's independent of vscale; getting a vector that's half the size or four times larger just works. Using + (or -) on the other hand doesn't seem to be as clear; I wasn't sure if a standalone int should be automatically treated as being the same as the TypeSize, or always considered Fixed. If we try for the former I can imagine quite a few bugs arising. I could add a roundBitsToNearestByteSize method to move the arithmetic elsewhere if that would be acceptable? Comment at: llvm/include/llvm/IR/DataLayout.h:656 + getTypeSizeInBits(VTy->getElementType()).getKnownMinSize(); +return ScalableSize(MinBits, EltCnt.Scalable); } rovka wrote: > Maybe just return VTy->getElementCount() * > getTypeSizeInBits(VTy->getElementType()).getFixedSize(). There's no support for generating a TypeSize from an ElementCount in that way; is that an interface you feel is useful? (I'll certainly change the `getKnownMinSize` to `getFixedSize` though, since we're just referring to a scalar) Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D53137/new/ https://reviews.llvm.org/D53137 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D53137: Scalable vector core instruction support + size queries
rovka added a comment. > I suspect 'ScalableSize' is the wrong term now; 'TypeSize' may be better. > Thoughts? I agree, TypeSize sounds better. Maybe we can replace the public constructor with 2 static methods, TypeSize::Fixed(Size) and TypeSize::Scalable(Size), so we don't always have to spell out /* Scalable =*/. Comment at: llvm/include/llvm/IR/DataLayout.h:454 +auto BaseSize = getTypeSizeInBits(Ty); +return { (BaseSize.getKnownMinSize() + 7) / 8, BaseSize.isScalable() }; } We already overload operator /, why not overload + as well so we don't have to change the body of this method? Comment at: llvm/include/llvm/IR/DataLayout.h:487 +auto BaseSize = getTypeStoreSize(Ty); +uint64_t MinAlignedSize = alignTo(BaseSize.getKnownMinSize(), + getABITypeAlignment(Ty)); Can we add a version of alignTo that works with ScalableSize instead? Comment at: llvm/include/llvm/IR/DataLayout.h:656 + getTypeSizeInBits(VTy->getElementType()).getKnownMinSize(); +return ScalableSize(MinBits, EltCnt.Scalable); } Maybe just return VTy->getElementCount() * getTypeSizeInBits(VTy->getElementType()).getFixedSize(). Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D53137/new/ https://reviews.llvm.org/D53137 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D53137: Scalable vector core instruction support + size queries
huntergr updated this revision to Diff 221283. huntergr added a comment. Herald added subscribers: cfe-commits, haicheng, eraman. Herald added a project: clang. - Changed existing interface to return ScalableSize objects and added a (mostly) transparent conversion, as per Sander's suggestion. - Removed new interfaces for DataLayout and Type. - Fixed cases where the transparent conversion doesn't quite work (e.g. std::max/min, where the types must be the same) I suspect 'ScalableSize' is the wrong term now; 'TypeSize' may be better. Thoughts? Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D53137/new/ https://reviews.llvm.org/D53137 Files: clang/lib/CodeGen/CGCall.cpp clang/lib/CodeGen/CGStmt.cpp clang/lib/CodeGen/CodeGenFunction.cpp llvm/include/llvm/IR/DataLayout.h llvm/include/llvm/IR/InstrTypes.h llvm/include/llvm/IR/Type.h llvm/include/llvm/Support/ScalableSize.h llvm/lib/Analysis/InlineCost.cpp llvm/lib/CodeGen/Analysis.cpp llvm/lib/IR/DataLayout.cpp llvm/lib/IR/Instructions.cpp llvm/lib/IR/Type.cpp llvm/lib/Target/AArch64/AArch64ISelLowering.cpp llvm/lib/Transforms/Scalar/SROA.cpp llvm/test/Other/scalable-vectors-core-ir.ll llvm/unittests/IR/VectorTypesTest.cpp Index: llvm/unittests/IR/VectorTypesTest.cpp === --- llvm/unittests/IR/VectorTypesTest.cpp +++ llvm/unittests/IR/VectorTypesTest.cpp @@ -6,6 +6,7 @@ // //===--===// +#include "llvm/IR/DataLayout.h" #include "llvm/IR/DerivedTypes.h" #include "llvm/IR/LLVMContext.h" #include "llvm/Support/ScalableSize.h" @@ -161,4 +162,117 @@ ASSERT_TRUE(EltCnt.Scalable); } +TEST(VectorTypesTest, FixedLenComparisons) { + LLVMContext Ctx; + DataLayout DL(""); + + Type *Int32Ty = Type::getInt32Ty(Ctx); + Type *Int64Ty = Type::getInt64Ty(Ctx); + + VectorType *V2Int32Ty = VectorType::get(Int32Ty, 2); + VectorType *V4Int32Ty = VectorType::get(Int32Ty, 4); + + VectorType *V2Int64Ty = VectorType::get(Int64Ty, 2); + + ScalableSize V2I32Len = V2Int32Ty->getPrimitiveSizeInBits(); + EXPECT_EQ(V2I32Len.getKnownMinSize(), 64U); + EXPECT_FALSE(V2I32Len.isScalable()); + + EXPECT_LT(V2Int32Ty->getPrimitiveSizeInBits(), +V4Int32Ty->getPrimitiveSizeInBits()); + EXPECT_GT(V2Int64Ty->getPrimitiveSizeInBits(), +V2Int32Ty->getPrimitiveSizeInBits()); + EXPECT_EQ(V4Int32Ty->getPrimitiveSizeInBits(), +V2Int64Ty->getPrimitiveSizeInBits()); + EXPECT_NE(V2Int32Ty->getPrimitiveSizeInBits(), +V2Int64Ty->getPrimitiveSizeInBits()); + + // Check that a fixed-only comparison works for fixed size vectors. + EXPECT_EQ(V2Int64Ty->getPrimitiveSizeInBits().getFixedSize(), +V4Int32Ty->getPrimitiveSizeInBits().getFixedSize()); + + // Check the DataLayout interfaces. + EXPECT_EQ(DL.getTypeSizeInBits(V2Int64Ty), +DL.getTypeSizeInBits(V4Int32Ty)); + EXPECT_EQ(DL.getTypeSizeInBits(V2Int32Ty), 64U); + EXPECT_EQ(DL.getTypeSizeInBits(V2Int64Ty), 128U); + EXPECT_EQ(DL.getTypeStoreSize(V2Int64Ty), +DL.getTypeStoreSize(V4Int32Ty)); + EXPECT_NE(DL.getTypeStoreSizeInBits(V2Int32Ty), +DL.getTypeStoreSizeInBits(V2Int64Ty)); + EXPECT_EQ(DL.getTypeStoreSizeInBits(V2Int32Ty), 64U); + EXPECT_EQ(DL.getTypeStoreSize(V2Int64Ty), 16U); + EXPECT_EQ(DL.getTypeAllocSize(V4Int32Ty), +DL.getTypeAllocSize(V2Int64Ty)); + EXPECT_NE(DL.getTypeAllocSizeInBits(V2Int32Ty), +DL.getTypeAllocSizeInBits(V2Int64Ty)); + EXPECT_EQ(DL.getTypeAllocSizeInBits(V4Int32Ty), 128U); + EXPECT_EQ(DL.getTypeAllocSize(V2Int32Ty), 8U); + ASSERT_TRUE(DL.typeSizeEqualsStoreSize(V4Int32Ty)); +} + +TEST(VectorTypesTest, ScalableComparisons) { + LLVMContext Ctx; + DataLayout DL(""); + + Type *Int32Ty = Type::getInt32Ty(Ctx); + Type *Int64Ty = Type::getInt64Ty(Ctx); + + VectorType *ScV2Int32Ty = VectorType::get(Int32Ty, {2, true}); + VectorType *ScV4Int32Ty = VectorType::get(Int32Ty, {4, true}); + + VectorType *ScV2Int64Ty = VectorType::get(Int64Ty, {2, true}); + + ScalableSize ScV2I32Len = ScV2Int32Ty->getPrimitiveSizeInBits(); + EXPECT_EQ(ScV2I32Len.getKnownMinSize(), 64U); + EXPECT_TRUE(ScV2I32Len.isScalable()); + + EXPECT_LT(ScV2Int32Ty->getPrimitiveSizeInBits(), +ScV4Int32Ty->getPrimitiveSizeInBits()); + EXPECT_GT(ScV2Int64Ty->getPrimitiveSizeInBits(), +ScV2Int32Ty->getPrimitiveSizeInBits()); + EXPECT_EQ(ScV4Int32Ty->getPrimitiveSizeInBits(), +ScV2Int64Ty->getPrimitiveSizeInBits()); + EXPECT_NE(ScV2Int32Ty->getPrimitiveSizeInBits(), +ScV2Int64Ty->getPrimitiveSizeInBits()); + + // Check the DataLayout interfaces. + EXPECT_EQ(DL.getTypeSizeInBits(ScV2Int64Ty), +DL.getTypeSizeInBits(ScV4Int32Ty)); + EXPECT_EQ(DL.getTypeSizeInBits(ScV2Int32Ty).getKnownMinSize(), 64U); +