diff --git a/llvm/lib/Transforms/Scalar/InferAddressSpaces.cpp b/llvm/lib/Transforms/Scalar/InferAddressSpaces.cpp --- a/llvm/lib/Transforms/Scalar/InferAddressSpaces.cpp +++ b/llvm/lib/Transforms/Scalar/InferAddressSpaces.cpp @@ -470,8 +470,8 @@ PushPtrOperand(ASC->getPointerOperand()); } else if (auto *I2P = dyn_cast(&I)) { if (isNoopPtrIntCastPair(cast(I2P), *DL, TTI)) - PushPtrOperand( - cast(I2P->getOperand(0))->getPointerOperand()); + if (PtrToIntInst *P2I = dyn_cast(I2P->getOperand(0))) + PushPtrOperand(P2I->getPointerOperand()); } } diff --git a/llvm/test/Transforms/InferAddressSpaces/AMDGPU/noop-ptrint-pair.ll b/llvm/test/Transforms/InferAddressSpaces/AMDGPU/noop-ptrint-pair.ll --- a/llvm/test/Transforms/InferAddressSpaces/AMDGPU/noop-ptrint-pair.ll +++ b/llvm/test/Transforms/InferAddressSpaces/AMDGPU/noop-ptrint-pair.ll @@ -69,6 +69,16 @@ ret i32* inttoptr (i64 ptrtoint (i32 addrspace(1)* @g to i64) to i32*) } +; COMMON-LABEL: @noop_ptrint_pair_ce3( +; AMDGCN-NEXT: %i = inttoptr i64 ptrtoint (i32 addrspace(1)* @g to i64) to i32* +; AMDGCN-NEXT: ret void +; NOTTI-NEXT: %i = inttoptr i64 ptrtoint (i32 addrspace(1)* @g to i64) to i32* +; NOTTI-NEXT: ret void +define void @noop_ptrint_pair_ce3() { + %i = inttoptr i64 ptrtoint (i32 addrspace(1)* @g to i64) to i32* + ret void +} + ; COMMON-LABEL: @non_noop_ptrint_pair_ce( ; AMDGCN-NEXT: store i32 0, i32* inttoptr (i64 ptrtoint (i32 addrspace(3)* @l to i64) to i32*) ; AMDGCN-NEXT: ret void