[llvm] r352264 - GlobalISel: Fix address space limit in LLT
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Fri Jan 25 17:42:14 PST 2019
Author: arsenm
Date: Fri Jan 25 17:42:13 2019
New Revision: 352264
URL: http://llvm.org/viewvc/llvm-project?rev=352264&view=rev
Log:
GlobalISel: Fix address space limit in LLT
The IR enforced limit for the address space is 24-bits, but LLT was
only using 23-bits. Additionally, the argument to the constructor was
truncating to 16-bits.
A similar problem still exists for the number of vector elements. The
IR enforces no limit, so if you try to use a vector with > 65535
elements the IRTranslator asserts in the LLT constructor.
Added:
llvm/trunk/test/CodeGen/AArch64/GlobalISel/irtranslator-max-address-space.ll
Modified:
llvm/trunk/include/llvm/Support/LowLevelTypeImpl.h
llvm/trunk/unittests/CodeGen/LowLevelTypeTest.cpp
Modified: llvm/trunk/include/llvm/Support/LowLevelTypeImpl.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/LowLevelTypeImpl.h?rev=352264&r1=352263&r2=352264&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/LowLevelTypeImpl.h (original)
+++ llvm/trunk/include/llvm/Support/LowLevelTypeImpl.h Fri Jan 25 17:42:13 2019
@@ -45,8 +45,8 @@ public:
SizeInBits, /*AddressSpace=*/0};
}
- /// Get a low-level pointer in the given address space (defaulting to 0).
- static LLT pointer(uint16_t AddressSpace, unsigned SizeInBits) {
+ /// Get a low-level pointer in the given address space.
+ static LLT pointer(unsigned AddressSpace, unsigned SizeInBits) {
assert(SizeInBits > 0 && "invalid pointer size");
return LLT{/*isPointer=*/true, /*isVector=*/false, /*NumElements=*/0,
SizeInBits, AddressSpace};
@@ -181,10 +181,10 @@ private:
static const constexpr BitFieldInfo ScalarSizeFieldInfo{32, 0};
/// * Pointer (isPointer == 1 && isVector == 0):
/// SizeInBits: 16;
- /// AddressSpace: 23;
+ /// AddressSpace: 24;
static const constexpr BitFieldInfo PointerSizeFieldInfo{16, 0};
static const constexpr BitFieldInfo PointerAddressSpaceFieldInfo{
- 23, PointerSizeFieldInfo[0] + PointerSizeFieldInfo[1]};
+ 24, PointerSizeFieldInfo[0] + PointerSizeFieldInfo[1]};
/// * Vector-of-non-pointer (isPointer == 0 && isVector == 1):
/// NumElements: 16;
/// SizeOfElement: 32;
@@ -194,13 +194,13 @@ private:
/// * Vector-of-pointer (isPointer == 1 && isVector == 1):
/// NumElements: 16;
/// SizeOfElement: 16;
- /// AddressSpace: 23;
+ /// AddressSpace: 24;
static const constexpr BitFieldInfo PointerVectorElementsFieldInfo{16, 0};
static const constexpr BitFieldInfo PointerVectorSizeFieldInfo{
16,
PointerVectorElementsFieldInfo[1] + PointerVectorElementsFieldInfo[0]};
static const constexpr BitFieldInfo PointerVectorAddressSpaceFieldInfo{
- 23, PointerVectorSizeFieldInfo[1] + PointerVectorSizeFieldInfo[0]};
+ 24, PointerVectorSizeFieldInfo[1] + PointerVectorSizeFieldInfo[0]};
uint64_t IsPointer : 1;
uint64_t IsVector : 1;
Added: llvm/trunk/test/CodeGen/AArch64/GlobalISel/irtranslator-max-address-space.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/AArch64/GlobalISel/irtranslator-max-address-space.ll?rev=352264&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/AArch64/GlobalISel/irtranslator-max-address-space.ll (added)
+++ llvm/trunk/test/CodeGen/AArch64/GlobalISel/irtranslator-max-address-space.ll Fri Jan 25 17:42:13 2019
@@ -0,0 +1,26 @@
+; RUN: llc -O0 -mtriple=aarch64-apple-ios -global-isel -stop-after=irtranslator %s -o - | FileCheck %s
+
+; CHECK-LABEL: name: store_max_address_space
+; CHECK: %0:_(p16777215) = COPY $x0
+; CHECK: G_STORE %1(s32), %0(p16777215) :: (store 4 into %ir.ptr, addrspace 16777215)
+define void @store_max_address_space(i32 addrspace(16777215)* %ptr) {
+ store i32 0, i32 addrspace(16777215)* %ptr
+ ret void
+}
+
+; CHECK-LABEL: name: store_max_address_space_vector
+; CHECK: %0:_(<2 x p16777215>) = COPY $q0
+; CHECK: %1:_(p16777215) = G_EXTRACT_VECTOR_ELT %0(<2 x p16777215>), %2(s64)
+; CHECK: %1(p16777215) :: (store 4 into %ir.elt0, addrspace 16777215)
+define void @store_max_address_space_vector(<2 x i32 addrspace(16777215)*> %vptr) {
+ %elt0 = extractelement <2 x i32 addrspace(16777215)*> %vptr, i32 0
+ store i32 0, i32 addrspace(16777215)* %elt0
+ ret void
+}
+
+; CHECK-LABEL: name: max_address_space_vector_max_num_elts
+; CHECK: %0:_(<65535 x p16777215>) = G_LOAD %1(p0) :: (volatile load 524280 from `<65535 x i32 addrspace(16777215)*>* undef`, align 524288)
+define void @max_address_space_vector_max_num_elts() {
+ %load = load volatile <65535 x i32 addrspace(16777215)*>, <65535 x i32 addrspace(16777215)*>* undef
+ ret void
+}
Modified: llvm/trunk/unittests/CodeGen/LowLevelTypeTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/CodeGen/LowLevelTypeTest.cpp?rev=352264&r1=352263&r2=352264&view=diff
==============================================================================
--- llvm/trunk/unittests/CodeGen/LowLevelTypeTest.cpp (original)
+++ llvm/trunk/unittests/CodeGen/LowLevelTypeTest.cpp Fri Jan 25 17:42:13 2019
@@ -120,39 +120,46 @@ TEST(LowLevelTypeTest, ScalarOrVector) {
TEST(LowLevelTypeTest, Pointer) {
LLVMContext C;
- DataLayout DL("");
+ DataLayout DL("p64:64:64-p127:512:512:512-p16777215:65528:8");
- for (unsigned AS : {0U, 1U, 127U, 0xffffU}) {
- const LLT Ty = LLT::pointer(AS, DL.getPointerSizeInBits(AS));
- const LLT VTy = LLT::vector(4, Ty);
-
- // Test kind.
- ASSERT_TRUE(Ty.isValid());
- ASSERT_TRUE(Ty.isPointer());
-
- ASSERT_FALSE(Ty.isScalar());
- ASSERT_FALSE(Ty.isVector());
-
- ASSERT_TRUE(VTy.isValid());
- ASSERT_TRUE(VTy.isVector());
- ASSERT_TRUE(VTy.getElementType().isPointer());
-
- // Test addressspace.
- EXPECT_EQ(AS, Ty.getAddressSpace());
- EXPECT_EQ(AS, VTy.getElementType().getAddressSpace());
-
- // Test equality operators.
- EXPECT_TRUE(Ty == Ty);
- EXPECT_FALSE(Ty != Ty);
- EXPECT_TRUE(VTy == VTy);
- EXPECT_FALSE(VTy != VTy);
-
- // Test Type->LLT conversion.
- Type *IRTy = PointerType::get(IntegerType::get(C, 8), AS);
- EXPECT_EQ(Ty, getLLTForType(*IRTy, DL));
- Type *IRVTy =
- VectorType::get(PointerType::get(IntegerType::get(C, 8), AS), 4);
- EXPECT_EQ(VTy, getLLTForType(*IRVTy, DL));
+ for (unsigned AS : {0U, 1U, 127U, 0xffffU,
+ static_cast<unsigned>(maxUIntN(23)),
+ static_cast<unsigned>(maxUIntN(24))}) {
+ for (unsigned NumElts : {2, 3, 4, 256, 65535}) {
+ const LLT Ty = LLT::pointer(AS, DL.getPointerSizeInBits(AS));
+ const LLT VTy = LLT::vector(NumElts, Ty);
+
+ // Test kind.
+ ASSERT_TRUE(Ty.isValid());
+ ASSERT_TRUE(Ty.isPointer());
+
+ ASSERT_FALSE(Ty.isScalar());
+ ASSERT_FALSE(Ty.isVector());
+
+ ASSERT_TRUE(VTy.isValid());
+ ASSERT_TRUE(VTy.isVector());
+ ASSERT_TRUE(VTy.getElementType().isPointer());
+
+ EXPECT_EQ(Ty, VTy.getElementType());
+ EXPECT_EQ(Ty.getSizeInBits(), VTy.getScalarSizeInBits());
+
+ // Test address space.
+ EXPECT_EQ(AS, Ty.getAddressSpace());
+ EXPECT_EQ(AS, VTy.getElementType().getAddressSpace());
+
+ // Test equality operators.
+ EXPECT_TRUE(Ty == Ty);
+ EXPECT_FALSE(Ty != Ty);
+ EXPECT_TRUE(VTy == VTy);
+ EXPECT_FALSE(VTy != VTy);
+
+ // Test Type->LLT conversion.
+ Type *IRTy = PointerType::get(IntegerType::get(C, 8), AS);
+ EXPECT_EQ(Ty, getLLTForType(*IRTy, DL));
+ Type *IRVTy =
+ VectorType::get(PointerType::get(IntegerType::get(C, 8), AS), NumElts);
+ EXPECT_EQ(VTy, getLLTForType(*IRVTy, DL));
+ }
}
}
More information about the llvm-commits
mailing list