[llvm] 660e453 - [KnownBits] Also test 1-bit values in exhaustive tests (NFC)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Wed May 31 08:50:13 PDT 2023
Author: Nikita Popov
Date: 2023-05-31T17:50:01+02:00
New Revision: 660e4530124356442ff63d61b1f6dcb9c1def7e6
URL: https://github.com/llvm/llvm-project/commit/660e4530124356442ff63d61b1f6dcb9c1def7e6
DIFF: https://github.com/llvm/llvm-project/commit/660e4530124356442ff63d61b1f6dcb9c1def7e6.diff
LOG: [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.
Added:
Modified:
llvm/unittests/Support/KnownBitsTest.cpp
Removed:
################################################################################
diff --git a/llvm/unittests/Support/KnownBitsTest.cpp b/llvm/unittests/Support/KnownBitsTest.cpp
index 4ca9d5250943a..9d184beea3ba9 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 {
More information about the llvm-commits
mailing list