[llvm] [AMDGPU][LowerBufferFatPointers] Fix lack of rewrite when loading/storing null (PR #154128)
Krzysztof Drewniak via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 18 07:58:18 PDT 2025
https://github.com/krzysz00 updated https://github.com/llvm/llvm-project/pull/154128
>From e1db6b8efa609e38e8eb2bb5ce50f74a30f9fa0a Mon Sep 17 00:00:00 2001
From: Krzysztof Drewniak <Krzysztof.Drewniak at amd.com>
Date: Mon, 18 Aug 2025 14:39:17 +0000
Subject: [PATCH 1/2] [AMDGPU][LowerBufferFatPointers] Fix lack of rewrite when
loading/storing null
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
specilaizing constants out to instructions, but that doesn't account
foc trivial constants like null. Therefoe, we check the operands of
instructions for buffer fat pointers in order to find such constants
and ensure the pass runs.
---
llvm/lib/Target/AMDGPU/AMDGPULowerBufferFatPointers.cpp | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/llvm/lib/Target/AMDGPU/AMDGPULowerBufferFatPointers.cpp b/llvm/lib/Target/AMDGPU/AMDGPULowerBufferFatPointers.cpp
index ed73dc8903908..7090bc8124f9c 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPULowerBufferFatPointers.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPULowerBufferFatPointers.cpp
@@ -2366,8 +2366,12 @@ static bool containsBufferFatPointers(const Function &F,
BufferFatPtrToStructTypeMap *TypeMap) {
bool HasFatPointers = false;
for (const BasicBlock &BB : F)
- for (const Instruction &I : BB)
+ for (const Instruction &I : BB) {
HasFatPointers |= (I.getType() != TypeMap->remapType(I.getType()));
+ // Catch null pointer constasts in loads, stores, etc.
+ for (const Value *V : I.operand_values())
+ HasFatPointers |= (V->getType() != TypeMap->remapType(V->getType()));
+ }
return HasFatPointers;
}
>From 45a4f272876045100998079c0c71f938285c2bcc Mon Sep 17 00:00:00 2001
From: Krzysztof Drewniak <Krzysztof.Drewniak at amd.com>
Date: Mon, 18 Aug 2025 14:58:06 +0000
Subject: [PATCH 2/2] Whoops, forgot the tests
---
.../lower-buffer-fat-pointers-constants.ll | 20 +++++++++++++++++++
1 file changed, 20 insertions(+)
diff --git a/llvm/test/CodeGen/AMDGPU/lower-buffer-fat-pointers-constants.ll b/llvm/test/CodeGen/AMDGPU/lower-buffer-fat-pointers-constants.ll
index a0c1e573f8fbb..a7f3fe62f0d2e 100644
--- a/llvm/test/CodeGen/AMDGPU/lower-buffer-fat-pointers-constants.ll
+++ b/llvm/test/CodeGen/AMDGPU/lower-buffer-fat-pointers-constants.ll
@@ -223,3 +223,23 @@ define i32 @fancy_zero() {
ptr addrspace(7) addrspacecast (ptr addrspace(8) @buf to ptr addrspace(7))
to i32)
}
+
+define i32 @load_null() {
+; CHECK-LABEL: define i32 @load_null
+; CHECK-SAME: () #[[ATTR0]] {
+; CHECK-NEXT: [[X:%.*]] = call i32 @llvm.amdgcn.raw.ptr.buffer.load.i32(ptr addrspace(8) align 4 null, i32 0, i32 0, i32 0)
+; CHECK-NEXT: ret i32 [[X]]
+;
+ %x = load i32, ptr addrspace(7) null, align 4
+ ret i32 %x
+}
+
+define void @store_null() {
+; CHECK-LABEL: define void @store_null
+; CHECK-SAME: () #[[ATTR0]] {
+; 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)
+; CHECK-NEXT: ret void
+;
+ store i32 0, ptr addrspace(7) null, align 4
+ ret void
+}
More information about the llvm-commits
mailing list