[llvm] [NVPTX] Check Before inserting AddrSpaceCastInst in NVPTXLoweringAlloca (PR #106127)
weiwei chen via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 26 13:47:03 PDT 2024
================
@@ -72,12 +72,22 @@ 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 = dyn_cast_or_null<PointerType>(
----------------
weiweichen wrote:
It comes from [here](https://github.com/llvm/llvm-project/blob/7854b16d2699ca7cc02d4ea066230d370c751ba9/llvm/lib/IR/Instructions.cpp#L3416)
```
AddrSpaceCastInst::AddrSpaceCastInst(Value *S, Type *Ty, const Twine &Name,
InsertPosition InsertBefore)
: CastInst(Ty, AddrSpaceCast, S, Name, InsertBefore) {
assert(castIsValid(getOpcode(), S, Ty) && "Illegal AddrSpaceCast");
}
```
where `castIsValid(getOpcode(), S, Ty)` returns `false` if `S` is already in the same address space which is from the logic [here](https://github.com/llvm/llvm-project/blob/7854b16d2699ca7cc02d4ea066230d370c751ba9/llvm/lib/IR/Instructions.cpp#L3333-L3334)
```
if (SrcPtrTy->getAddressSpace() == DstPtrTy->getAddressSpace())
return false;
```
@justinfargnoli, would it be better to remove ☝️ instead?
https://github.com/llvm/llvm-project/pull/106127
More information about the llvm-commits
mailing list