Skip to content

Commit 7f27482

Browse files
krzysz00nikic
andauthored
[AMDGPU][LowerBufferFatPointers] Fix lack of rewrite when loading/storing null (#154128)
Fixes #154056. The fat buffer lowering pass was erroniously detecting that it did not need to run on functions that only load/store to the null constant (or other such constants). We thought this would be covered by specializing constants out to instructions, but that doesn't account foc trivial constants like null. Therefore, we check the operands of instructions for buffer fat pointers in order to find such constants and ensure the pass runs. --------- Co-authored-by: Nikita Popov <[email protected]>
1 parent 9982957 commit 7f27482

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

llvm/lib/Target/AMDGPU/AMDGPULowerBufferFatPointers.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2366,8 +2366,12 @@ static bool containsBufferFatPointers(const Function &F,
23662366
BufferFatPtrToStructTypeMap *TypeMap) {
23672367
bool HasFatPointers = false;
23682368
for (const BasicBlock &BB : F)
2369-
for (const Instruction &I : BB)
2369+
for (const Instruction &I : BB) {
23702370
HasFatPointers |= (I.getType() != TypeMap->remapType(I.getType()));
2371+
// Catch null pointer constants in loads, stores, etc.
2372+
for (const Value *V : I.operand_values())
2373+
HasFatPointers |= (V->getType() != TypeMap->remapType(V->getType()));
2374+
}
23712375
return HasFatPointers;
23722376
}
23732377

llvm/test/CodeGen/AMDGPU/lower-buffer-fat-pointers-constants.ll

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,3 +223,43 @@ define i32 @fancy_zero() {
223223
ptr addrspace(7) addrspacecast (ptr addrspace(8) @buf to ptr addrspace(7))
224224
to i32)
225225
}
226+
227+
define i32 @load_null() {
228+
; CHECK-LABEL: define i32 @load_null
229+
; CHECK-SAME: () #[[ATTR0]] {
230+
; CHECK-NEXT: [[X:%.*]] = call i32 @llvm.amdgcn.raw.ptr.buffer.load.i32(ptr addrspace(8) align 4 null, i32 0, i32 0, i32 0)
231+
; CHECK-NEXT: ret i32 [[X]]
232+
;
233+
%x = load i32, ptr addrspace(7) null, align 4
234+
ret i32 %x
235+
}
236+
237+
define void @store_null() {
238+
; CHECK-LABEL: define void @store_null
239+
; CHECK-SAME: () #[[ATTR0]] {
240+
; CHECK-NEXT: call void @llvm.amdgcn.raw.ptr.buffer.store.i32(i32 0, ptr addrspace(8) align 4 null, i32 0, i32 0, i32 0)
241+
; CHECK-NEXT: ret void
242+
;
243+
store i32 0, ptr addrspace(7) null, align 4
244+
ret void
245+
}
246+
247+
define i32 @load_poison() {
248+
; CHECK-LABEL: define i32 @load_poison
249+
; CHECK-SAME: () #[[ATTR0]] {
250+
; CHECK-NEXT: [[X:%.*]] = call i32 @llvm.amdgcn.raw.ptr.buffer.load.i32(ptr addrspace(8) align 4 poison, i32 poison, i32 0, i32 0)
251+
; CHECK-NEXT: ret i32 [[X]]
252+
;
253+
%x = load i32, ptr addrspace(7) poison, align 4
254+
ret i32 %x
255+
}
256+
257+
define void @store_poison() {
258+
; CHECK-LABEL: define void @store_poison
259+
; CHECK-SAME: () #[[ATTR0]] {
260+
; CHECK-NEXT: call void @llvm.amdgcn.raw.ptr.buffer.store.i32(i32 0, ptr addrspace(8) align 4 poison, i32 poison, i32 0, i32 0)
261+
; CHECK-NEXT: ret void
262+
;
263+
store i32 0, ptr addrspace(7) poison, align 4
264+
ret void
265+
}

0 commit comments

Comments
 (0)