[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
Thu Feb 6 02:51:23 PST 2025
================
@@ -655,20 +654,40 @@ 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);
+ Type *GlobalPtrVecTy =
+ VectorType::get(IRB.getPtrTy(AMDGPUAS::GLOBAL_ADDRESS), NumElements);
+ Value *GlobalPtrVec = PoisonValue::get(GlobalPtrVecTy);
+ for (uint64_t Index = 0; Index < NumElements.getKnownMinValue(); ++Index) {
+ Value *ExtElem = IRB.CreateExtractElement(PtrToInt, Index);
+ Value *Gep =
+ IRB.CreateInBoundsGEP(IRB.getInt8Ty(), LoadMallocPtr, {ExtElem});
+ GlobalPtrVec = IRB.CreateInsertElement(GlobalPtrVec, Gep, Index);
+ }
+ return GlobalPtrVec;
+ }
----------------
skc7 wrote:
Thanks for feedback @arsenm . I was unaware that GEP supports vector of ptrs [[LINK](https://llvm.org/docs/LangRef.html#vector-of-pointers)] . Have updated PR to instead use vector of ptrs.
https://github.com/llvm/llvm-project/pull/121214
More information about the llvm-commits
mailing list