Skip to content

Conversation

@krzysz00
Copy link
Contributor

@krzysz00 krzysz00 commented Aug 18, 2025

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.

…ring null

Fixes llvm#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.
@llvmbot
Copy link
Member

llvmbot commented Aug 18, 2025

@llvm/pr-subscribers-backend-amdgpu

Author: Krzysztof Drewniak (krzysz00)

Changes

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.


Full diff: https://github.com/llvm/llvm-project/pull/154128.diff

1 Files Affected:

  • (modified) llvm/lib/Target/AMDGPU/AMDGPULowerBufferFatPointers.cpp (+5-1)
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;
 }
 

Copy link
Contributor

@nikic nikic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test?

@krzysz00 krzysz00 requested a review from nikic August 18, 2025 14:58
@krzysz00
Copy link
Contributor Author

Forgot the test lol

Co-authored-by: Nikita Popov <[email protected]>
;
store i32 0, ptr addrspace(7) null, align 4
ret void
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you also test the poison case

@krzysz00 krzysz00 merged commit 7f27482 into llvm:main Aug 18, 2025
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Store to null buffer fat pointers asserts in SelectionDAG

4 participants