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,13 @@
+; RUN: opt -instsimplify -S < %s | FileCheck %s
+
+target datalayout = "p:32:32-p4:64:64"
+
+; When a pointer is addrspacecasted to a wider pointer, there is no guarantee
+; that the newly added high bits are zero.
+; CHECK-NOT: ret i64 0
+define i64 @test(i8* %p) {
+  %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