[llvm] [AMDGPU] Handle lowering addrspace casts from LDS to FLAT address in amdgpu-sw-lower-lds. (PR #121214)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Feb 17 08:41:20 PST 2025
================
@@ -655,20 +654,37 @@ void AMDGPUSwLowerLDS::getLDSMemoryInstructions(
} else if (AtomicCmpXchgInst *XCHG = dyn_cast<AtomicCmpXchgInst>(&Inst)) {
if (XCHG->getPointerAddressSpace() == AMDGPUAS::LOCAL_ADDRESS)
LDSInstructions.insert(&Inst);
+ } else if (AddrSpaceCastInst *ASC = dyn_cast<AddrSpaceCastInst>(&Inst)) {
+ if (ASC->getSrcAddressSpace() == AMDGPUAS::LOCAL_ADDRESS &&
+ ASC->getDestAddressSpace() == AMDGPUAS::FLAT_ADDRESS)
+ LDSInstructions.insert(&Inst);
} else
continue;
}
}
}
-Value *
-AMDGPUSwLowerLDS::getTranslatedGlobalMemoryGEPOfLDSPointer(Value *LoadMallocPtr,
+Value *AMDGPUSwLowerLDS::getTranslatedGlobalMemoryPtrOfLDS(Value *LoadMallocPtr,
Value *LDSPtr) {
assert(LDSPtr && "Invalid LDS pointer operand");
+ Type *LDSPtrType = LDSPtr->getType();
+
+ if (LDSPtrType->isVectorTy()) {
+ // Handle vector of pointers
+ VectorType *VecPtrTy = cast<VectorType>(LDSPtrType);
+ ElementCount NumElements = VecPtrTy->getElementCount();
+ Type *Int32VecTy = VectorType::get(IRB.getInt32Ty(), NumElements);
+ Value *PtrToInt = IRB.CreatePtrToInt(LDSPtr, Int32VecTy);
+ // Create vector of pointers to global address space
+ Type *GlobalPtrVecTy =
+ VectorType::get(IRB.getPtrTy(AMDGPUAS::GLOBAL_ADDRESS), NumElements);
+ Value *GlobalPtrVec =
+ IRB.CreateInBoundsGEP(IRB.getInt8Ty(), LoadMallocPtr, PtrToInt);
+ GlobalPtrVec = IRB.CreateBitCast(GlobalPtrVec, GlobalPtrVecTy);
----------------
skc7 wrote:
Updated.
https://github.com/llvm/llvm-project/pull/121214
More information about the llvm-commits
mailing list