aboutsummaryrefslogtreecommitdiff
path: root/llvm/unittests/Analysis/ValueTrackingTest.cpp
diff options
context:
space:
mode:
authorNikita Popov <npopov@redhat.com>2025-02-04 14:29:58 +0100
committerGitHub <noreply@github.com>2025-02-04 14:29:58 +0100
commit3bd11b502c1846afa5e1257c94b7a70566e34686 (patch)
tree48881f3d34110a1232ef58b254c36fcfaac36952 /llvm/unittests/Analysis/ValueTrackingTest.cpp
parent6fc66d322b00bdabc27fe8e14b27ab9bd53ba770 (diff)
downloadllvm-3bd11b502c1846afa5e1257c94b7a70566e34686.zip
llvm-3bd11b502c1846afa5e1257c94b7a70566e34686.tar.gz
llvm-3bd11b502c1846afa5e1257c94b7a70566e34686.tar.bz2
[ValueTracking] Fix bit width handling in computeKnownBits() for GEPs (#125532)
For GEPs, we have three bit widths involved: The pointer bit width, the index bit width, and the bit width of the GEP operands. The correct behavior here is: * We need to sextOrTrunc the GEP operand to the index width *before* multiplying by the scale. * If the index width and pointer width differ, GEP only ever modifies the low bits. Adds should not overflow into the high bits. I'm testing this via unit tests because it's a bit tricky to test in IR with InstCombine canonicalization getting in the way.
Diffstat (limited to 'llvm/unittests/Analysis/ValueTrackingTest.cpp')
-rw-r--r--llvm/unittests/Analysis/ValueTrackingTest.cpp12
1 files changed, 6 insertions, 6 deletions
diff --git a/llvm/unittests/Analysis/ValueTrackingTest.cpp b/llvm/unittests/Analysis/ValueTrackingTest.cpp
index 39865fa..50e5e0e 100644
--- a/llvm/unittests/Analysis/ValueTrackingTest.cpp
+++ b/llvm/unittests/Analysis/ValueTrackingTest.cpp
@@ -2680,7 +2680,7 @@ TEST_F(ComputeKnownBitsTest, ComputeKnownBitsAbsoluteSymbol) {
}
TEST_F(ComputeKnownBitsTest, ComputeKnownBitsGEPExtendBeforeMul) {
- // FIXME: The index should be extended before multiplying with the scale.
+ // The index should be extended before multiplying with the scale.
parseAssembly(R"(
target datalayout = "p:16:16:16"
@@ -2692,12 +2692,12 @@ TEST_F(ComputeKnownBitsTest, ComputeKnownBitsGEPExtendBeforeMul) {
}
)");
KnownBits Known = computeKnownBits(A, M->getDataLayout());
- EXPECT_EQ(~64 & 0x7fff, Known.Zero);
- EXPECT_EQ(64, Known.One);
+ EXPECT_EQ(~320 & 0x7fff, Known.Zero);
+ EXPECT_EQ(320, Known.One);
}
TEST_F(ComputeKnownBitsTest, ComputeKnownBitsGEPOnlyIndexBits) {
- // FIXME: GEP should only affect the index width.
+ // GEP should only affect the index width.
parseAssembly(R"(
target datalayout = "p:16:16:16:8"
@@ -2710,8 +2710,8 @@ TEST_F(ComputeKnownBitsTest, ComputeKnownBitsGEPOnlyIndexBits) {
}
)");
KnownBits Known = computeKnownBits(A, M->getDataLayout());
- EXPECT_EQ(0x7eff, Known.Zero);
- EXPECT_EQ(0x100, Known.One);
+ EXPECT_EQ(0x7fff, Known.Zero);
+ EXPECT_EQ(0, Known.One);
}
TEST_F(ValueTrackingTest, HaveNoCommonBitsSet) {