diff options
author | Nikita Popov <npopov@redhat.com> | 2023-05-31 10:10:47 +0200 |
---|---|---|
committer | Nikita Popov <npopov@redhat.com> | 2023-05-31 17:50:01 +0200 |
commit | 660e4530124356442ff63d61b1f6dcb9c1def7e6 (patch) | |
tree | e579ef76101be8487c10d8dd1526889bc04bb876 /llvm/unittests/Support/KnownBitsTest.cpp | |
parent | 6eef8d9b2bbfdb3920b6eeafc939a2d62ad5295b (diff) | |
download | llvm-660e4530124356442ff63d61b1f6dcb9c1def7e6.zip llvm-660e4530124356442ff63d61b1f6dcb9c1def7e6.tar.gz llvm-660e4530124356442ff63d61b1f6dcb9c1def7e6.tar.bz2 |
[KnownBits] Also test 1-bit values in exhaustive tests (NFC)
Similar to what we do with ConstantRanges, also test 1-bit values
in exhaustive tests, as these often expose special conditions.
This would have exposed the assertion failure fixed in D151788
earlier.
Diffstat (limited to 'llvm/unittests/Support/KnownBitsTest.cpp')
-rw-r--r-- | llvm/unittests/Support/KnownBitsTest.cpp | 93 |
1 files changed, 48 insertions, 45 deletions
diff --git a/llvm/unittests/Support/KnownBitsTest.cpp b/llvm/unittests/Support/KnownBitsTest.cpp index 4ca9d52..9d184be 100644 --- a/llvm/unittests/Support/KnownBitsTest.cpp +++ b/llvm/unittests/Support/KnownBitsTest.cpp @@ -69,64 +69,67 @@ static testing::AssertionResult isOptimal(const KnownBits &Exact, static void testUnaryOpExhaustive(UnaryBitsFn BitsFn, UnaryIntFn IntFn, UnaryCheckFn CheckOptimalityFn = checkOptimalityUnary) { - unsigned Bits = 4; - ForeachKnownBits(Bits, [&](const KnownBits &Known) { - KnownBits Computed = BitsFn(Known); - KnownBits Exact(Bits); - Exact.Zero.setAllBits(); - Exact.One.setAllBits(); + for (unsigned Bits : {1, 4}) { + ForeachKnownBits(Bits, [&](const KnownBits &Known) { + KnownBits Computed = BitsFn(Known); + KnownBits Exact(Bits); + Exact.Zero.setAllBits(); + Exact.One.setAllBits(); - ForeachNumInKnownBits(Known, [&](const APInt &N) { - if (std::optional<APInt> Res = IntFn(N)) { - Exact.One &= *Res; - Exact.Zero &= ~*Res; + ForeachNumInKnownBits(Known, [&](const APInt &N) { + if (std::optional<APInt> Res = IntFn(N)) { + Exact.One &= *Res; + Exact.Zero &= ~*Res; + } + }); + + EXPECT_TRUE(!Computed.hasConflict()); + EXPECT_TRUE(isCorrect(Exact, Computed, Known)); + // We generally don't want to return conflicting known bits, even if it is + // legal for always poison results. + if (CheckOptimalityFn(Known) && !Exact.hasConflict()) { + EXPECT_TRUE(isOptimal(Exact, Computed, Known)); } }); - - EXPECT_TRUE(!Computed.hasConflict()); - EXPECT_TRUE(isCorrect(Exact, Computed, Known)); - // We generally don't want to return conflicting known bits, even if it is - // legal for always poison results. - if (CheckOptimalityFn(Known) && !Exact.hasConflict()) { - EXPECT_TRUE(isOptimal(Exact, Computed, Known)); - } - }); + } } static void testBinaryOpExhaustive(BinaryBitsFn BitsFn, BinaryIntFn IntFn, BinaryCheckFn CheckOptimalityFn = checkOptimalityBinary, bool RefinePoisonToZero = false) { - unsigned Bits = 4; - ForeachKnownBits(Bits, [&](const KnownBits &Known1) { - ForeachKnownBits(Bits, [&](const KnownBits &Known2) { - KnownBits Computed = BitsFn(Known1, Known2); - KnownBits Exact(Bits); - Exact.Zero.setAllBits(); - Exact.One.setAllBits(); + for (unsigned Bits : {1, 4}) { + ForeachKnownBits(Bits, [&](const KnownBits &Known1) { + ForeachKnownBits(Bits, [&](const KnownBits &Known2) { + KnownBits Computed = BitsFn(Known1, Known2); + KnownBits Exact(Bits); + Exact.Zero.setAllBits(); + Exact.One.setAllBits(); - ForeachNumInKnownBits(Known1, [&](const APInt &N1) { - ForeachNumInKnownBits(Known2, [&](const APInt &N2) { - if (std::optional<APInt> Res = IntFn(N1, N2)) { - Exact.One &= *Res; - Exact.Zero &= ~*Res; - } + ForeachNumInKnownBits(Known1, [&](const APInt &N1) { + ForeachNumInKnownBits(Known2, [&](const APInt &N2) { + if (std::optional<APInt> Res = IntFn(N1, N2)) { + Exact.One &= *Res; + Exact.Zero &= ~*Res; + } + }); }); - }); - EXPECT_TRUE(!Computed.hasConflict()); - EXPECT_TRUE(isCorrect(Exact, Computed, {Known1, Known2})); - // We generally don't want to return conflicting known bits, even if it is - // legal for always poison results. - if (CheckOptimalityFn(Known1, Known2) && !Exact.hasConflict()) { - EXPECT_TRUE(isOptimal(Exact, Computed, {Known1, Known2})); - } - // In some cases we choose to return zero if the result is always poison. - if (RefinePoisonToZero && Exact.hasConflict()) { - EXPECT_TRUE(Computed.isZero()); - } + EXPECT_TRUE(!Computed.hasConflict()); + EXPECT_TRUE(isCorrect(Exact, Computed, {Known1, Known2})); + // We generally don't want to return conflicting known bits, even if it + // is legal for always poison results. + if (CheckOptimalityFn(Known1, Known2) && !Exact.hasConflict()) { + EXPECT_TRUE(isOptimal(Exact, Computed, {Known1, Known2})); + } + // In some cases we choose to return zero if the result is always + // poison. + if (RefinePoisonToZero && Exact.hasConflict()) { + EXPECT_TRUE(Computed.isZero()); + } + }); }); - }); + } } namespace { |