[llvm] [AMDGPU] Fix LDS access via flat pointer argument in amdgpu-sw-lower-lds (PR #209842)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 21 03:46:45 PDT 2026
================
@@ -790,6 +792,80 @@ void AMDGPUSwLowerLDS::translateLDSMemoryOperationsToGlobalMemory(
}
}
+void AMDGPUSwLowerLDS::lowerFlatToLocalRoundTrips(Function *Func) {
+ // After SW LDS lowering, storage that used to live in LDS now lives in global
+ // memory, but it may still be handed to a callee as a flat (generic) pointer.
+ // Such a callee can re-derive an LDS pointer with a round-trip pattern:
+ // %p = getelementptr ..., ptr %flat_arg ; flat, backed by global mem
+ // %c = addrspacecast ptr %p to ptr addrspace(3)
+ // load/store ... ptr addrspace(3) %c
+ // The addrspace(3) access would then hit dead LDS. Redo the access through
+ // the flat source pointer, which still points at the global backing buffer.
+ SmallVector<Instruction *> ToErase;
+ SmallPtrSet<AddrSpaceCastInst *, 8> Casts;
+ for (BasicBlock &BB : *Func) {
+ for (Instruction &Inst : BB) {
+ Value *Ptr = nullptr;
+ if (auto *LI = dyn_cast<LoadInst>(&Inst))
----------------
skc7 wrote:
Folded the logic into `translateLDSMemoryOperationsToGlobalMemory` path. The memory-op dispatch remains in the existing lowering path, and the new part is only pointer translation via `getFlatPtrForRoundTripLDSAccess`.
https://github.com/llvm/llvm-project/pull/209842
More information about the llvm-commits
mailing list