Index: llvm/lib/Transforms/Scalar/InferAddressSpaces.cpp =================================================================== --- llvm/lib/Transforms/Scalar/InferAddressSpaces.cpp +++ llvm/lib/Transforms/Scalar/InferAddressSpaces.cpp @@ -361,6 +361,8 @@ PushPtrOperand(LI->getPointerOperand()); else if (auto *SI = dyn_cast(&I)) PushPtrOperand(SI->getPointerOperand()); + else if (auto *P2I = dyn_cast(&I)) + PushPtrOperand(P2I->getPointerOperand()); else if (auto *RMW = dyn_cast(&I)) PushPtrOperand(RMW->getPointerOperand()); else if (auto *CmpX = dyn_cast(&I)) @@ -769,6 +771,9 @@ return OpNo == StoreInst::getPointerOperandIndex() && (VolatileIsAllowed || !SI->isVolatile()); + if (auto *P2I = dyn_cast(Inst)) + return OpNo == PtrToIntInst::getPointerOperandIndex(); + if (auto *RMW = dyn_cast(Inst)) return OpNo == AtomicRMWInst::getPointerOperandIndex() && (VolatileIsAllowed || !RMW->isVolatile()); Index: llvm/test/Transforms/InferAddressSpaces/AMDGPU/ptrtoint.ll =================================================================== --- /dev/null +++ llvm/test/Transforms/InferAddressSpaces/AMDGPU/ptrtoint.ll @@ -0,0 +1,12 @@ +; RUN: opt -S -mtriple=amdgcn-amd-amdhsa -infer-address-spaces %s | FileCheck %s + +; Optimized to private ptrtoint. +; CHECK-LABEL: @ptrtoint_private( +; CHECK-NEXT: %val = ptrtoint i32 addrspace(5)* %input to i32 +define i32 @ptrtoint_private(i32 addrspace(5)* nocapture %input) #0 { + %tmp0 = addrspacecast i32 addrspace(5)* %input to i32* + %val = ptrtoint i32* %tmp0 to i32 + ret i32 %val +} + +attributes #0 = { nounwind }