Index: lib/Analysis/ValueTracking.cpp =================================================================== --- lib/Analysis/ValueTracking.cpp +++ lib/Analysis/ValueTracking.cpp @@ -1043,8 +1043,9 @@ computeKnownBits(I->getOperand(0), KnownZero, KnownOne, Depth + 1, Q); KnownZero = KnownZero.zextOrTrunc(BitWidth); KnownOne = KnownOne.zextOrTrunc(BitWidth); - // Any top bits are known to be zero. - if (BitWidth > SrcBitWidth) + // AddrSpaceCasting to a wider pointer does not guarantee newly added higher + // bits to be zero. For other instructions it is true. + if (BitWidth > SrcBitWidth && I->getOpcode() != Instruction::AddrSpaceCast) KnownZero |= APInt::getHighBitsSet(BitWidth, BitWidth - SrcBitWidth); break; } Index: test/Analysis/ValueTracking/knownzero-addrspacecast.ll =================================================================== --- /dev/null +++ test/Analysis/ValueTracking/knownzero-addrspacecast.ll @@ -0,0 +1,12 @@ +; RUN: opt -instsimplify -S < %s | FileCheck %s + +target datalayout = "e-p:32:32-p1:64:64-p2:64:64-p3:32:32-p4:64:64-p5:32:32-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-v2048:2048-n32:64" +target triple = "amdgcn-amd-amdhsa-opencl" + +define i64 @test() { + %p = alloca i8, align 4 + %g = addrspacecast i8* %p to i8 addrspace(4)* + %i = ptrtoint i8 addrspace(4)* %g to i64 + %shift = lshr i64 %i, 32 + ret i64 %shift +} \ No newline at end of file