-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[KnownBitsTest] Common up isCorrect and isOptimal. NFC. #89585
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This de-duplicates the code that prints useful information when a test fails.
@llvm/pr-subscribers-llvm-support Author: Jay Foad (jayfoad) ChangesThis de-duplicates the code that prints useful information when a test Full diff: https://github.com/llvm/llvm-project/pull/89585.diff 1 Files Affected:
diff --git a/llvm/unittests/Support/KnownBitsTest.cpp b/llvm/unittests/Support/KnownBitsTest.cpp
index feb0231300f1fd..2fa650c2c3bf0e 100644
--- a/llvm/unittests/Support/KnownBitsTest.cpp
+++ b/llvm/unittests/Support/KnownBitsTest.cpp
@@ -25,26 +25,20 @@ using BinaryBitsFn =
using BinaryIntFn =
llvm::function_ref<std::optional<APInt>(const APInt &, const APInt &)>;
-static testing::AssertionResult isCorrect(const KnownBits &Exact,
- const KnownBits &Computed,
- ArrayRef<KnownBits> Inputs) {
- if (Computed.Zero.isSubsetOf(Exact.Zero) &&
- Computed.One.isSubsetOf(Exact.One))
- return testing::AssertionSuccess();
-
- testing::AssertionResult Result = testing::AssertionFailure();
- Result << "Inputs = ";
- for (const KnownBits &Input : Inputs)
- Result << Input << ", ";
- Result << "Computed = " << Computed << ", Exact = " << Exact;
- return Result;
-}
-
-static testing::AssertionResult isOptimal(const KnownBits &Exact,
- const KnownBits &Computed,
- ArrayRef<KnownBits> Inputs) {
- if (Computed == Exact)
- return testing::AssertionSuccess();
+static testing::AssertionResult checkResult(const KnownBits &Exact,
+ const KnownBits &Computed,
+ ArrayRef<KnownBits> Inputs,
+ bool CheckOptimality) {
+ if (CheckOptimality) {
+ // We generally don't want to return conflicting known bits, even if it is
+ // legal for always poison results.
+ if (Exact.hasConflict() || Computed == Exact)
+ return testing::AssertionSuccess();
+ } else {
+ if (Computed.Zero.isSubsetOf(Exact.Zero) &&
+ Computed.One.isSubsetOf(Exact.One))
+ return testing::AssertionSuccess();
+ }
testing::AssertionResult Result = testing::AssertionFailure();
Result << "Inputs = ";
@@ -71,12 +65,7 @@ static void testUnaryOpExhaustive(UnaryBitsFn BitsFn, UnaryIntFn IntFn,
});
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 (CheckOptimality && !Exact.hasConflict()) {
- EXPECT_TRUE(isOptimal(Exact, Computed, Known));
- }
+ EXPECT_TRUE(checkResult(Exact, Computed, Known, CheckOptimality));
});
}
}
@@ -102,12 +91,8 @@ static void testBinaryOpExhaustive(BinaryBitsFn BitsFn, BinaryIntFn IntFn,
});
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 (CheckOptimality && !Exact.hasConflict()) {
- EXPECT_TRUE(isOptimal(Exact, Computed, {Known1, Known2}));
- }
+ EXPECT_TRUE(
+ checkResult(Exact, Computed, {Known1, Known2}, CheckOptimality));
// In some cases we choose to return zero if the result is always
// poison.
if (RefinePoisonToZero && Exact.hasConflict()) {
@@ -201,23 +186,23 @@ static void TestAddSubExhaustive(bool IsAdd) {
KnownBits KnownComputed = KnownBits::computeForAddSub(
IsAdd, /*NSW=*/false, /*NUW=*/false, Known1, Known2);
- EXPECT_TRUE(isOptimal(Known, KnownComputed, {Known1, Known2}));
+ EXPECT_TRUE(checkResult(Known, KnownComputed, {Known1, Known2},
+ /*CheckOptimality=*/true));
KnownBits KnownNSWComputed = KnownBits::computeForAddSub(
IsAdd, /*NSW=*/true, /*NUW=*/false, Known1, Known2);
- if (!KnownNSW.hasConflict())
- EXPECT_TRUE(isOptimal(KnownNSW, KnownNSWComputed, {Known1, Known2}));
+ EXPECT_TRUE(checkResult(KnownNSW, KnownNSWComputed, {Known1, Known2},
+ /*CheckOptimality=*/true));
KnownBits KnownNUWComputed = KnownBits::computeForAddSub(
IsAdd, /*NSW=*/false, /*NUW=*/true, Known1, Known2);
- if (!KnownNUW.hasConflict())
- EXPECT_TRUE(isOptimal(KnownNUW, KnownNUWComputed, {Known1, Known2}));
+ EXPECT_TRUE(checkResult(KnownNUW, KnownNUWComputed, {Known1, Known2},
+ /*CheckOptimality=*/true));
KnownBits KnownNSWAndNUWComputed = KnownBits::computeForAddSub(
IsAdd, /*NSW=*/true, /*NUW=*/true, Known1, Known2);
- if (!KnownNSWAndNUW.hasConflict())
- EXPECT_TRUE(isOptimal(KnownNSWAndNUW, KnownNSWAndNUWComputed,
- {Known1, Known2}));
+ EXPECT_TRUE(checkResult(KnownNSWAndNUW, KnownNSWAndNUWComputed,
+ {Known1, Known2}, /*CheckOptimality=*/true));
});
});
}
|
|
||
KnownBits KnownNSWComputed = KnownBits::computeForAddSub( | ||
IsAdd, /*NSW=*/true, /*NUW=*/false, Known1, Known2); | ||
if (!KnownNSW.hasConflict()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This if
is now unnecessary since I moved the handling of always-poison results into checkResult
. Same below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
we're getting an assertion failure with this patch. I bisected it to this patch. I'm including a reproducer (not reduced) and my bisect script. Failing bot: https://ci.chromium.org/ui/p/fuchsia/builders/ci/clang_toolchain.ci.core.arm64-debug-subbuild/b8749763985778255185/overview I bisected with
Note if you want to use the bisect script you may need to update paths. The I have creduce running now, so I can probably post a smaller reproducer in a while. In the meantime, can you revert this until a fix is ready? |
Actually, looking at your patch, I'm not sure how this is causing an assertion failure. Still, can you take a look? |
oh, sorry for the noise. You can disregard my comments. seems like I started w/ a bad commit range in the bisect. So just to be clear, this patch is fine, and I'm very wrong. |
This de-duplicates the code that prints useful information when a test
fails.