[llvm] [NVPTX] Check Before inserting AddrSpaceCastInst in NVPTXLoweringAlloca (PR #106127)
weiwei chen via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 28 21:09:18 PDT 2024
================
@@ -72,12 +72,21 @@ bool NVPTXLowerAlloca::runOnFunction(Function &F) {
Changed = true;
auto ETy = allocaInst->getAllocatedType();
auto LocalAddrTy = PointerType::get(ETy, ADDRESS_SPACE_LOCAL);
- auto NewASCToLocal = new AddrSpaceCastInst(allocaInst, LocalAddrTy, "");
- auto GenericAddrTy = PointerType::get(ETy, ADDRESS_SPACE_GENERIC);
- auto NewASCToGeneric =
- new AddrSpaceCastInst(NewASCToLocal, GenericAddrTy, "");
- NewASCToLocal->insertAfter(allocaInst);
- NewASCToGeneric->insertAfter(NewASCToLocal);
+ PointerType *AllocInstPtrTy =
+ cast<PointerType>(allocaInst->getType()->getScalarType());
+ Instruction *NewASCToGeneric = allocaInst;
+ if (AllocInstPtrTy->getAddressSpace() != ADDRESS_SPACE_LOCAL) {
----------------
weiweichen wrote:
@Artem-B , as you mentioned "We bundle allocas and other on-stack objects into it. As such, it can only live in the local parameter space in PTX", I'm a bit confused why you think we should assert here instead of skip the address space cast to `local` if the alloc is already in the address space of `local`. Could you elaborate a bit more? Feels like maybe I'm missing something?
https://github.com/llvm/llvm-project/pull/106127
More information about the llvm-commits
mailing list