[PATCH] D26803: Fix known zero bits for addrspacecast
Yaxun Liu via llvm-commits
llvm-commits at lists.llvm.org
Thu Nov 17 09:21:19 PST 2016
yaxunl updated this revision to Diff 78373.
yaxunl added a comment.
Simplify the test.
https://reviews.llvm.org/D26803
Files:
lib/Analysis/ValueTracking.cpp
test/Analysis/ValueTracking/knownzero-addrspacecast.ll
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
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;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D26803.78373.patch
Type: text/x-patch
Size: 1423 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161117/bc418ab2/attachment.bin>
More information about the llvm-commits
mailing list