llvm.org GIT mirror llvm / 6033f8c
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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@352264 91177308-0d34-0410-b5e6-96231b3b80d8 Matt Arsenault 1 year, 4 months ago
3 changed file(s) with 65 addition(s) and 32 deletion(s). Raw diff Collapse all Expand all
4444 SizeInBits, /*AddressSpace=*/0};
4545 }
4646
47 /// Get a low-level pointer in the given address space (defaulting to 0).
48 static LLT pointer(uint16_t AddressSpace, unsigned SizeInBits) {
47 /// Get a low-level pointer in the given address space.
48 static LLT pointer(unsigned AddressSpace, unsigned SizeInBits) {
4949 assert(SizeInBits > 0 && "invalid pointer size");
5050 return LLT{/*isPointer=*/true, /*isVector=*/false, /*NumElements=*/0,
5151 SizeInBits, AddressSpace};
180180 static const constexpr BitFieldInfo ScalarSizeFieldInfo{32, 0};
181181 /// * Pointer (isPointer == 1 && isVector == 0):
182182 /// SizeInBits: 16;
183 /// AddressSpace: 23;
183 /// AddressSpace: 24;
184184 static const constexpr BitFieldInfo PointerSizeFieldInfo{16, 0};
185185 static const constexpr BitFieldInfo PointerAddressSpaceFieldInfo{
186 23, PointerSizeFieldInfo[0] + PointerSizeFieldInfo[1]};
186 24, PointerSizeFieldInfo[0] + PointerSizeFieldInfo[1]};
187187 /// * Vector-of-non-pointer (isPointer == 0 && isVector == 1):
188188 /// NumElements: 16;
189189 /// SizeOfElement: 32;
193193 /// * Vector-of-pointer (isPointer == 1 && isVector == 1):
194194 /// NumElements: 16;
195195 /// SizeOfElement: 16;
196 /// AddressSpace: 23;
196 /// AddressSpace: 24;
197197 static const constexpr BitFieldInfo PointerVectorElementsFieldInfo{16, 0};
198198 static const constexpr BitFieldInfo PointerVectorSizeFieldInfo{
199199 16,
200200 PointerVectorElementsFieldInfo[1] + PointerVectorElementsFieldInfo[0]};
201201 static const constexpr BitFieldInfo PointerVectorAddressSpaceFieldInfo{
202 23, PointerVectorSizeFieldInfo[1] + PointerVectorSizeFieldInfo[0]};
202 24, PointerVectorSizeFieldInfo[1] + PointerVectorSizeFieldInfo[0]};
203203
204204 uint64_t IsPointer : 1;
205205 uint64_t IsVector : 1;
0 ; RUN: llc -O0 -mtriple=aarch64-apple-ios -global-isel -stop-after=irtranslator %s -o - | FileCheck %s
1
2 ; CHECK-LABEL: name: store_max_address_space
3 ; CHECK: %0:_(p16777215) = COPY $x0
4 ; CHECK: G_STORE %1(s32), %0(p16777215) :: (store 4 into %ir.ptr, addrspace 16777215)
5 define void @store_max_address_space(i32 addrspace(16777215)* %ptr) {
6 store i32 0, i32 addrspace(16777215)* %ptr
7 ret void
8 }
9
10 ; CHECK-LABEL: name: store_max_address_space_vector
11 ; CHECK: %0:_(<2 x p16777215>) = COPY $q0
12 ; CHECK: %1:_(p16777215) = G_EXTRACT_VECTOR_ELT %0(<2 x p16777215>), %2(s64)
13 ; CHECK: %1(p16777215) :: (store 4 into %ir.elt0, addrspace 16777215)
14 define void @store_max_address_space_vector(<2 x i32 addrspace(16777215)*> %vptr) {
15 %elt0 = extractelement <2 x i32 addrspace(16777215)*> %vptr, i32 0
16 store i32 0, i32 addrspace(16777215)* %elt0
17 ret void
18 }
19
20 ; CHECK-LABEL: name: max_address_space_vector_max_num_elts
21 ; CHECK: %0:_(<65535 x p16777215>) = G_LOAD %1(p0) :: (volatile load 524280 from `<65535 x i32 addrspace(16777215)*>* undef`, align 524288)
22 define void @max_address_space_vector_max_num_elts() {
23 %load = load volatile <65535 x i32 addrspace(16777215)*>, <65535 x i32 addrspace(16777215)*>* undef
24 ret void
25 }
119119
120120 TEST(LowLevelTypeTest, Pointer) {
121121 LLVMContext C;
122 DataLayout DL("");
122 DataLayout DL("p64:64:64-p127:512:512:512-p16777215:65528:8");
123123
124 for (unsigned AS : {0U, 1U, 127U, 0xffffU}) {
125 const LLT Ty = LLT::pointer(AS, DL.getPointerSizeInBits(AS));
126 const LLT VTy = LLT::vector(4, Ty);
124 for (unsigned AS : {0U, 1U, 127U, 0xffffU,
125 static_cast(maxUIntN(23)),
126 static_cast(maxUIntN(24))}) {
127 for (unsigned NumElts : {2, 3, 4, 256, 65535}) {
128 const LLT Ty = LLT::pointer(AS, DL.getPointerSizeInBits(AS));
129 const LLT VTy = LLT::vector(NumElts, Ty);
127130
128 // Test kind.
129 ASSERT_TRUE(Ty.isValid());
130 ASSERT_TRUE(Ty.isPointer());
131 // Test kind.
132 ASSERT_TRUE(Ty.isValid());
133 ASSERT_TRUE(Ty.isPointer());
131134
132 ASSERT_FALSE(Ty.isScalar());
133 ASSERT_FALSE(Ty.isVector());
135 ASSERT_FALSE(Ty.isScalar());
136 ASSERT_FALSE(Ty.isVector());
134137
135 ASSERT_TRUE(VTy.isValid());
136 ASSERT_TRUE(VTy.isVector());
137 ASSERT_TRUE(VTy.getElementType().isPointer());
138 ASSERT_TRUE(VTy.isValid());
139 ASSERT_TRUE(VTy.isVector());
140 ASSERT_TRUE(VTy.getElementType().isPointer());
138141
139 // Test addressspace.
140 EXPECT_EQ(AS, Ty.getAddressSpace());
141 EXPECT_EQ(AS, VTy.getElementType().getAddressSpace());
142 EXPECT_EQ(Ty, VTy.getElementType());
143 EXPECT_EQ(Ty.getSizeInBits(), VTy.getScalarSizeInBits());
142144
143 // Test equality operators.
144 EXPECT_TRUE(Ty == Ty);
145 EXPECT_FALSE(Ty != Ty);
146 EXPECT_TRUE(VTy == VTy);
147 EXPECT_FALSE(VTy != VTy);
145 // Test address space.
146 EXPECT_EQ(AS, Ty.getAddressSpace());
147 EXPECT_EQ(AS, VTy.getElementType().getAddressSpace());
148148
149 // Test Type->LLT conversion.
150 Type *IRTy = PointerType::get(IntegerType::get(C, 8), AS);
151 EXPECT_EQ(Ty, getLLTForType(*IRTy, DL));
152 Type *IRVTy =
153 VectorType::get(PointerType::get(IntegerType::get(C, 8), AS), 4);
154 EXPECT_EQ(VTy, getLLTForType(*IRVTy, DL));
149 // Test equality operators.
150 EXPECT_TRUE(Ty == Ty);
151 EXPECT_FALSE(Ty != Ty);
152 EXPECT_TRUE(VTy == VTy);
153 EXPECT_FALSE(VTy != VTy);
154
155 // Test Type->LLT conversion.
156 Type *IRTy = PointerType::get(IntegerType::get(C, 8), AS);
157 EXPECT_EQ(Ty, getLLTForType(*IRTy, DL));
158 Type *IRVTy =
159 VectorType::get(PointerType::get(IntegerType::get(C, 8), AS), NumElts);
160 EXPECT_EQ(VTy, getLLTForType(*IRVTy, DL));
161 }
155162 }
156163 }
157164