aboutsummaryrefslogtreecommitdiff
path: root/llvm/unittests/Analysis/ValueTrackingTest.cpp
diff options
context:
space:
mode:
authorNikita Popov <npopov@redhat.com>2025-02-03 17:37:07 +0100
committerNikita Popov <npopov@redhat.com>2025-02-03 17:45:28 +0100
commit3dc1ef1650c8389a6f195a474781cf2281208bed (patch)
treece41d32d4bc5d9ee0e9e8ddc3aadad97a6ca0ef6 /llvm/unittests/Analysis/ValueTrackingTest.cpp
parent707e2b83a5d7f5d1a363f992197e3afad6369d6e (diff)
downloadllvm-3dc1ef1650c8389a6f195a474781cf2281208bed.zip
llvm-3dc1ef1650c8389a6f195a474781cf2281208bed.tar.gz
llvm-3dc1ef1650c8389a6f195a474781cf2281208bed.tar.bz2
[ValueTracking] Add additional tests for computeKnownBits on GEPs (NFC)
These demonstrate miscompiles in the existing code.
Diffstat (limited to 'llvm/unittests/Analysis/ValueTrackingTest.cpp')
-rw-r--r--llvm/unittests/Analysis/ValueTrackingTest.cpp35
1 files changed, 35 insertions, 0 deletions
diff --git a/llvm/unittests/Analysis/ValueTrackingTest.cpp b/llvm/unittests/Analysis/ValueTrackingTest.cpp
index ee44aac..39865fa 100644
--- a/llvm/unittests/Analysis/ValueTrackingTest.cpp
+++ b/llvm/unittests/Analysis/ValueTrackingTest.cpp
@@ -2679,6 +2679,41 @@ TEST_F(ComputeKnownBitsTest, ComputeKnownBitsAbsoluteSymbol) {
EXPECT_EQ(0u, Known_0_256_Align8.countMinTrailingOnes());
}
+TEST_F(ComputeKnownBitsTest, ComputeKnownBitsGEPExtendBeforeMul) {
+ // FIXME: The index should be extended before multiplying with the scale.
+ parseAssembly(R"(
+ target datalayout = "p:16:16:16"
+
+ define void @test(i16 %arg) {
+ %and = and i16 %arg, u0x8000
+ %base = inttoptr i16 %and to ptr
+ %A = getelementptr i32, ptr %base, i8 80
+ ret void
+ }
+ )");
+ KnownBits Known = computeKnownBits(A, M->getDataLayout());
+ EXPECT_EQ(~64 & 0x7fff, Known.Zero);
+ EXPECT_EQ(64, Known.One);
+}
+
+TEST_F(ComputeKnownBitsTest, ComputeKnownBitsGEPOnlyIndexBits) {
+ // FIXME: GEP should only affect the index width.
+ parseAssembly(R"(
+ target datalayout = "p:16:16:16:8"
+
+ define void @test(i16 %arg) {
+ %and = and i16 %arg, u0x8000
+ %or = or i16 %and, u0x00ff
+ %base = inttoptr i16 %or to ptr
+ %A = getelementptr i8, ptr %base, i8 1
+ ret void
+ }
+ )");
+ KnownBits Known = computeKnownBits(A, M->getDataLayout());
+ EXPECT_EQ(0x7eff, Known.Zero);
+ EXPECT_EQ(0x100, Known.One);
+}
+
TEST_F(ValueTrackingTest, HaveNoCommonBitsSet) {
{
// Check for an inverted mask: (X & ~M) op (Y & M).