diff options
author | Nikita Popov <npopov@redhat.com> | 2023-07-05 12:11:23 +0200 |
---|---|---|
committer | Nikita Popov <npopov@redhat.com> | 2023-07-05 12:18:00 +0200 |
commit | 8d3856836cd0aa5c87800b039a8c854b8044a711 (patch) | |
tree | 19783a58a233273a6b6d796c71cb3572124d499f /llvm/unittests/Analysis/ValueTrackingTest.cpp | |
parent | 1af0e34477a3b4a28a1c251e527c9f75f5cf69e1 (diff) | |
download | llvm-8d3856836cd0aa5c87800b039a8c854b8044a711.zip llvm-8d3856836cd0aa5c87800b039a8c854b8044a711.tar.gz llvm-8d3856836cd0aa5c87800b039a8c854b8044a711.tar.bz2 |
[ValueTracking] Don't handle ptrtoint with mismatches sizes
When processing assumes, we also handle assumes on ptrtoint of the
value. In canonical IR, these will have the same size as the value.
However, in non-canonical IR there may be an implicit zext or
trunc, which results in a bit width mismatch. We currently handle
this by adjusting bitwidth everywhere, but this is fragile and I'm
pretty sure that the way we do this is incorrect for some predicates,
because we effectively end up commuting an ext/trunc and an icmp.
Instead, add an m_PtrToIntSameSize() matcher that will only handle
bitwidth preserving cases. For the bitwidth-changing cases, wait
until they have been canonicalized.
The original handling for this was added purely to prevent crashes
in an earlier implementation which failed to account for this
entirely.
Diffstat (limited to 'llvm/unittests/Analysis/ValueTrackingTest.cpp')
-rw-r--r-- | llvm/unittests/Analysis/ValueTrackingTest.cpp | 10 |
1 files changed, 4 insertions, 6 deletions
diff --git a/llvm/unittests/Analysis/ValueTrackingTest.cpp b/llvm/unittests/Analysis/ValueTrackingTest.cpp index e8f15f3..4eed22d 100644 --- a/llvm/unittests/Analysis/ValueTrackingTest.cpp +++ b/llvm/unittests/Analysis/ValueTrackingTest.cpp @@ -2254,7 +2254,7 @@ TEST_F(ComputeKnownBitsTest, ComputeKnownUSubSatZerosPreserved) { } TEST_F(ComputeKnownBitsTest, ComputeKnownBitsPtrToIntTrunc) { - // ptrtoint truncates the pointer type. + // ptrtoint truncates the pointer type. Make sure we don't crash. parseAssembly( "define void @test(ptr %p) {\n" " %A = load ptr, ptr %p\n" @@ -2268,12 +2268,11 @@ TEST_F(ComputeKnownBitsTest, ComputeKnownBitsPtrToIntTrunc) { AssumptionCache AC(*F); KnownBits Known = computeKnownBits( A, M->getDataLayout(), /* Depth */ 0, &AC, F->front().getTerminator()); - EXPECT_EQ(Known.Zero.getZExtValue(), 31u); - EXPECT_EQ(Known.One.getZExtValue(), 0u); + EXPECT_TRUE(Known.isUnknown()); } TEST_F(ComputeKnownBitsTest, ComputeKnownBitsPtrToIntZext) { - // ptrtoint zero extends the pointer type. + // ptrtoint zero extends the pointer type. Make sure we don't crash. parseAssembly( "define void @test(ptr %p) {\n" " %A = load ptr, ptr %p\n" @@ -2287,8 +2286,7 @@ TEST_F(ComputeKnownBitsTest, ComputeKnownBitsPtrToIntZext) { AssumptionCache AC(*F); KnownBits Known = computeKnownBits( A, M->getDataLayout(), /* Depth */ 0, &AC, F->front().getTerminator()); - EXPECT_EQ(Known.Zero.getZExtValue(), 31u); - EXPECT_EQ(Known.One.getZExtValue(), 0u); + EXPECT_TRUE(Known.isUnknown()); } TEST_F(ComputeKnownBitsTest, ComputeKnownBitsFreeze) { |