Skip to content

Commit a89e04e

Browse files
nikictstellar
authored andcommitted
[ValueTracking] Add additional tests for computeKnownBits on GEPs (NFC)
These demonstrate miscompiles in the existing code. (cherry picked from commit 3dc1ef1)
1 parent af970cd commit a89e04e

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

llvm/unittests/Analysis/ValueTrackingTest.cpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2679,6 +2679,41 @@ TEST_F(ComputeKnownBitsTest, ComputeKnownBitsAbsoluteSymbol) {
26792679
EXPECT_EQ(0u, Known_0_256_Align8.countMinTrailingOnes());
26802680
}
26812681

2682+
TEST_F(ComputeKnownBitsTest, ComputeKnownBitsGEPExtendBeforeMul) {
2683+
// FIXME: The index should be extended before multiplying with the scale.
2684+
parseAssembly(R"(
2685+
target datalayout = "p:16:16:16"
2686+
2687+
define void @test(i16 %arg) {
2688+
%and = and i16 %arg, u0x8000
2689+
%base = inttoptr i16 %and to ptr
2690+
%A = getelementptr i32, ptr %base, i8 80
2691+
ret void
2692+
}
2693+
)");
2694+
KnownBits Known = computeKnownBits(A, M->getDataLayout());
2695+
EXPECT_EQ(~64 & 0x7fff, Known.Zero);
2696+
EXPECT_EQ(64, Known.One);
2697+
}
2698+
2699+
TEST_F(ComputeKnownBitsTest, ComputeKnownBitsGEPOnlyIndexBits) {
2700+
// FIXME: GEP should only affect the index width.
2701+
parseAssembly(R"(
2702+
target datalayout = "p:16:16:16:8"
2703+
2704+
define void @test(i16 %arg) {
2705+
%and = and i16 %arg, u0x8000
2706+
%or = or i16 %and, u0x00ff
2707+
%base = inttoptr i16 %or to ptr
2708+
%A = getelementptr i8, ptr %base, i8 1
2709+
ret void
2710+
}
2711+
)");
2712+
KnownBits Known = computeKnownBits(A, M->getDataLayout());
2713+
EXPECT_EQ(0x7eff, Known.Zero);
2714+
EXPECT_EQ(0x100, Known.One);
2715+
}
2716+
26822717
TEST_F(ValueTrackingTest, HaveNoCommonBitsSet) {
26832718
{
26842719
// Check for an inverted mask: (X & ~M) op (Y & M).

0 commit comments

Comments
 (0)