[llvm] [KnownBitsTest] Print name of function when exhaustive tests fail (PR #89588)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Apr 22 03:33:59 PDT 2024
github-actions[bot] wrote:
<!--LLVM CODE FORMAT COMMENT: {clang-format}-->
:warning: C/C++ code formatter, clang-format found issues in your code. :warning:
<details>
<summary>
You can test this locally with the following command:
</summary>
``````````bash
git-clang-format --diff c2d665b7aeb68f3e8e643ee9dfe5bb7dd31137e5 5b936af2ee94a8e76b0cae0a72d990e5b49bba00 -- llvm/unittests/Support/KnownBitsTest.cpp
``````````
</details>
<details>
<summary>
View the diff from clang-format here.
</summary>
``````````diff
diff --git a/llvm/unittests/Support/KnownBitsTest.cpp b/llvm/unittests/Support/KnownBitsTest.cpp
index 8946444c22..b970137e63 100644
--- a/llvm/unittests/Support/KnownBitsTest.cpp
+++ b/llvm/unittests/Support/KnownBitsTest.cpp
@@ -10,11 +10,11 @@
//
//===----------------------------------------------------------------------===//
+#include "llvm/Support/KnownBits.h"
+#include "KnownBitsTest.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/Twine.h"
-#include "llvm/Support/KnownBits.h"
-#include "KnownBitsTest.h"
#include "gtest/gtest.h"
using namespace llvm;
@@ -27,8 +27,7 @@ using BinaryBitsFn =
using BinaryIntFn =
llvm::function_ref<std::optional<APInt>(const APInt &, const APInt &)>;
-static testing::AssertionResult checkResult(Twine Name,
- const KnownBits &Exact,
+static testing::AssertionResult checkResult(Twine Name, const KnownBits &Exact,
const KnownBits &Computed,
ArrayRef<KnownBits> Inputs,
bool CheckOptimality) {
@@ -52,7 +51,8 @@ static testing::AssertionResult checkResult(Twine Name,
return Result;
}
-static void testUnaryOpExhaustive(StringRef Name, UnaryBitsFn BitsFn, UnaryIntFn IntFn,
+static void testUnaryOpExhaustive(StringRef Name, UnaryBitsFn BitsFn,
+ UnaryIntFn IntFn,
bool CheckOptimality = true) {
for (unsigned Bits : {1, 4}) {
ForeachKnownBits(Bits, [&](const KnownBits &Known) {
@@ -74,7 +74,8 @@ static void testUnaryOpExhaustive(StringRef Name, UnaryBitsFn BitsFn, UnaryIntFn
}
}
-static void testBinaryOpExhaustive(StringRef Name, BinaryBitsFn BitsFn, BinaryIntFn IntFn,
+static void testBinaryOpExhaustive(StringRef Name, BinaryBitsFn BitsFn,
+ BinaryIntFn IntFn,
bool CheckOptimality = true,
bool RefinePoisonToZero = false) {
for (unsigned Bits : {1, 4}) {
@@ -95,8 +96,8 @@ static void testBinaryOpExhaustive(StringRef Name, BinaryBitsFn BitsFn, BinaryIn
});
EXPECT_TRUE(!Computed.hasConflict());
- EXPECT_TRUE(
- checkResult(Name, Exact, Computed, {Known1, Known2}, CheckOptimality));
+ EXPECT_TRUE(checkResult(Name, Exact, Computed, {Known1, Known2},
+ CheckOptimality));
// In some cases we choose to return zero if the result is always
// poison.
if (RefinePoisonToZero && Exact.hasConflict()) {
@@ -196,18 +197,21 @@ static void TestAddSubExhaustive(bool IsAdd) {
KnownBits KnownNSWComputed = KnownBits::computeForAddSub(
IsAdd, /*NSW=*/true, /*NUW=*/false, Known1, Known2);
- EXPECT_TRUE(checkResult(Name + " nsw", KnownNSW, KnownNSWComputed, {Known1, Known2},
+ EXPECT_TRUE(checkResult(Name + " nsw", KnownNSW, KnownNSWComputed,
+ {Known1, Known2},
/*CheckOptimality=*/true));
KnownBits KnownNUWComputed = KnownBits::computeForAddSub(
IsAdd, /*NSW=*/false, /*NUW=*/true, Known1, Known2);
- EXPECT_TRUE(checkResult(Name + " nuw", KnownNUW, KnownNUWComputed, {Known1, Known2},
+ EXPECT_TRUE(checkResult(Name + " nuw", KnownNUW, KnownNUWComputed,
+ {Known1, Known2},
/*CheckOptimality=*/true));
KnownBits KnownNSWAndNUWComputed = KnownBits::computeForAddSub(
IsAdd, /*NSW=*/true, /*NUW=*/true, Known1, Known2);
- EXPECT_TRUE(checkResult(Name + " nsw nuw", KnownNSWAndNUW, KnownNSWAndNUWComputed,
- {Known1, Known2}, /*CheckOptimality=*/true));
+ EXPECT_TRUE(checkResult(Name + " nsw nuw", KnownNSWAndNUW,
+ KnownNSWAndNUWComputed, {Known1, Known2},
+ /*CheckOptimality=*/true));
});
});
}
@@ -271,17 +275,20 @@ TEST(KnownBitsTest, SignBitUnknown) {
}
TEST(KnownBitsTest, BinaryExhaustive) {
- testBinaryOpExhaustive("and",
+ testBinaryOpExhaustive(
+ "and",
[](const KnownBits &Known1, const KnownBits &Known2) {
return Known1 & Known2;
},
[](const APInt &N1, const APInt &N2) { return N1 & N2; });
- testBinaryOpExhaustive("or",
+ testBinaryOpExhaustive(
+ "or",
[](const KnownBits &Known1, const KnownBits &Known2) {
return Known1 | Known2;
},
[](const APInt &N1, const APInt &N2) { return N1 | N2; });
- testBinaryOpExhaustive("xor",
+ testBinaryOpExhaustive(
+ "xor",
[](const KnownBits &Known1, const KnownBits &Known2) {
return Known1 ^ Known2;
},
@@ -292,7 +299,8 @@ TEST(KnownBitsTest, BinaryExhaustive) {
testBinaryOpExhaustive("smin", KnownBits::smin, APIntOps::smin);
testBinaryOpExhaustive("abdu", KnownBits::abdu, APIntOps::abdu);
testBinaryOpExhaustive("abds", KnownBits::abds, APIntOps::abds);
- testBinaryOpExhaustive("udiv",
+ testBinaryOpExhaustive(
+ "udiv",
[](const KnownBits &Known1, const KnownBits &Known2) {
return KnownBits::udiv(Known1, Known2);
},
@@ -302,7 +310,8 @@ TEST(KnownBitsTest, BinaryExhaustive) {
return N1.udiv(N2);
},
/*CheckOptimality=*/false);
- testBinaryOpExhaustive("udiv exact",
+ testBinaryOpExhaustive(
+ "udiv exact",
[](const KnownBits &Known1, const KnownBits &Known2) {
return KnownBits::udiv(Known1, Known2, /*Exact*/ true);
},
@@ -312,7 +321,8 @@ TEST(KnownBitsTest, BinaryExhaustive) {
return N1.udiv(N2);
},
/*CheckOptimality=*/false);
- testBinaryOpExhaustive("sdiv",
+ testBinaryOpExhaustive(
+ "sdiv",
[](const KnownBits &Known1, const KnownBits &Known2) {
return KnownBits::sdiv(Known1, Known2);
},
@@ -322,7 +332,8 @@ TEST(KnownBitsTest, BinaryExhaustive) {
return N1.sdiv(N2);
},
/*CheckOptimality=*/false);
- testBinaryOpExhaustive("sdiv exact",
+ testBinaryOpExhaustive(
+ "sdiv exact",
[](const KnownBits &Known1, const KnownBits &Known2) {
return KnownBits::sdiv(Known1, Known2, /*Exact*/ true);
},
@@ -333,47 +344,48 @@ TEST(KnownBitsTest, BinaryExhaustive) {
return N1.sdiv(N2);
},
/*CheckOptimality=*/false);
- testBinaryOpExhaustive("urem",
- KnownBits::urem,
+ testBinaryOpExhaustive(
+ "urem", KnownBits::urem,
[](const APInt &N1, const APInt &N2) -> std::optional<APInt> {
if (N2.isZero())
return std::nullopt;
return N1.urem(N2);
},
/*CheckOptimality=*/false);
- testBinaryOpExhaustive("srem",
- KnownBits::srem,
+ testBinaryOpExhaustive(
+ "srem", KnownBits::srem,
[](const APInt &N1, const APInt &N2) -> std::optional<APInt> {
if (N2.isZero())
return std::nullopt;
return N1.srem(N2);
},
/*CheckOptimality=*/false);
- testBinaryOpExhaustive("sadd_sat",
- KnownBits::sadd_sat,
+ testBinaryOpExhaustive(
+ "sadd_sat", KnownBits::sadd_sat,
[](const APInt &N1, const APInt &N2) -> std::optional<APInt> {
return N1.sadd_sat(N2);
},
/*CheckOptimality=*/false);
- testBinaryOpExhaustive("uadd_sat",
- KnownBits::uadd_sat,
+ testBinaryOpExhaustive(
+ "uadd_sat", KnownBits::uadd_sat,
[](const APInt &N1, const APInt &N2) -> std::optional<APInt> {
return N1.uadd_sat(N2);
},
/*CheckOptimality=*/false);
- testBinaryOpExhaustive("ssub_sat",
- KnownBits::ssub_sat,
+ testBinaryOpExhaustive(
+ "ssub_sat", KnownBits::ssub_sat,
[](const APInt &N1, const APInt &N2) -> std::optional<APInt> {
return N1.ssub_sat(N2);
},
/*CheckOptimality=*/false);
- testBinaryOpExhaustive("usub_sat",
- KnownBits::usub_sat,
+ testBinaryOpExhaustive(
+ "usub_sat", KnownBits::usub_sat,
[](const APInt &N1, const APInt &N2) -> std::optional<APInt> {
return N1.usub_sat(N2);
},
/*CheckOptimality=*/false);
- testBinaryOpExhaustive("shl",
+ testBinaryOpExhaustive(
+ "shl",
[](const KnownBits &Known1, const KnownBits &Known2) {
return KnownBits::shl(Known1, Known2);
},
@@ -383,7 +395,8 @@ TEST(KnownBitsTest, BinaryExhaustive) {
return N1.shl(N2);
},
/*CheckOptimality=*/true, /* RefinePoisonToZero */ true);
- testBinaryOpExhaustive("ushl_ov",
+ testBinaryOpExhaustive(
+ "ushl_ov",
[](const KnownBits &Known1, const KnownBits &Known2) {
return KnownBits::shl(Known1, Known2, /* NUW */ true);
},
@@ -395,7 +408,8 @@ TEST(KnownBitsTest, BinaryExhaustive) {
return Res;
},
/*CheckOptimality=*/true, /* RefinePoisonToZero */ true);
- testBinaryOpExhaustive("shl nsw",
+ testBinaryOpExhaustive(
+ "shl nsw",
[](const KnownBits &Known1, const KnownBits &Known2) {
return KnownBits::shl(Known1, Known2, /* NUW */ false, /* NSW */ true);
},
@@ -407,7 +421,8 @@ TEST(KnownBitsTest, BinaryExhaustive) {
return Res;
},
/*CheckOptimality=*/true, /* RefinePoisonToZero */ true);
- testBinaryOpExhaustive("shl nuw",
+ testBinaryOpExhaustive(
+ "shl nuw",
[](const KnownBits &Known1, const KnownBits &Known2) {
return KnownBits::shl(Known1, Known2, /* NUW */ true, /* NSW */ true);
},
@@ -421,7 +436,8 @@ TEST(KnownBitsTest, BinaryExhaustive) {
},
/*CheckOptimality=*/true, /* RefinePoisonToZero */ true);
- testBinaryOpExhaustive("lshr",
+ testBinaryOpExhaustive(
+ "lshr",
[](const KnownBits &Known1, const KnownBits &Known2) {
return KnownBits::lshr(Known1, Known2);
},
@@ -431,7 +447,8 @@ TEST(KnownBitsTest, BinaryExhaustive) {
return N1.lshr(N2);
},
/*CheckOptimality=*/true, /* RefinePoisonToZero */ true);
- testBinaryOpExhaustive("lshr exact",
+ testBinaryOpExhaustive(
+ "lshr exact",
[](const KnownBits &Known1, const KnownBits &Known2) {
return KnownBits::lshr(Known1, Known2, /*ShAmtNonZero=*/false,
/*Exact=*/true);
@@ -444,7 +461,8 @@ TEST(KnownBitsTest, BinaryExhaustive) {
return N1.lshr(N2);
},
/*CheckOptimality=*/true, /* RefinePoisonToZero */ true);
- testBinaryOpExhaustive("ashr",
+ testBinaryOpExhaustive(
+ "ashr",
[](const KnownBits &Known1, const KnownBits &Known2) {
return KnownBits::ashr(Known1, Known2);
},
@@ -454,7 +472,8 @@ TEST(KnownBitsTest, BinaryExhaustive) {
return N1.ashr(N2);
},
/*CheckOptimality=*/true, /* RefinePoisonToZero */ true);
- testBinaryOpExhaustive("ashr exact",
+ testBinaryOpExhaustive(
+ "ashr exact",
[](const KnownBits &Known1, const KnownBits &Known2) {
return KnownBits::ashr(Known1, Known2, /*ShAmtNonZero=*/false,
/*Exact=*/true);
@@ -467,39 +486,45 @@ TEST(KnownBitsTest, BinaryExhaustive) {
return N1.ashr(N2);
},
/*CheckOptimality=*/true, /* RefinePoisonToZero */ true);
- testBinaryOpExhaustive("mul",
+ testBinaryOpExhaustive(
+ "mul",
[](const KnownBits &Known1, const KnownBits &Known2) {
return KnownBits::mul(Known1, Known2);
},
[](const APInt &N1, const APInt &N2) { return N1 * N2; },
/*CheckOptimality=*/false);
- testBinaryOpExhaustive("mulhs",
- KnownBits::mulhs,
+ testBinaryOpExhaustive(
+ "mulhs", KnownBits::mulhs,
[](const APInt &N1, const APInt &N2) { return APIntOps::mulhs(N1, N2); },
/*CheckOptimality=*/false);
- testBinaryOpExhaustive("mulhu",
- KnownBits::mulhu,
+ testBinaryOpExhaustive(
+ "mulhu", KnownBits::mulhu,
[](const APInt &N1, const APInt &N2) { return APIntOps::mulhu(N1, N2); },
/*CheckOptimality=*/false);
}
TEST(KnownBitsTest, UnaryExhaustive) {
- testUnaryOpExhaustive("abs", [](const KnownBits &Known) { return Known.abs(); },
- [](const APInt &N) { return N.abs(); });
-
- testUnaryOpExhaustive("abs(true)", [](const KnownBits &Known) { return Known.abs(true); },
- [](const APInt &N) -> std::optional<APInt> {
- if (N.isMinSignedValue())
- return std::nullopt;
- return N.abs();
- });
-
- testUnaryOpExhaustive("blsi", [](const KnownBits &Known) { return Known.blsi(); },
- [](const APInt &N) { return N & -N; });
- testUnaryOpExhaustive("blsmsk", [](const KnownBits &Known) { return Known.blsmsk(); },
- [](const APInt &N) { return N ^ (N - 1); });
-
- testUnaryOpExhaustive("mul self",
+ testUnaryOpExhaustive(
+ "abs", [](const KnownBits &Known) { return Known.abs(); },
+ [](const APInt &N) { return N.abs(); });
+
+ testUnaryOpExhaustive(
+ "abs(true)", [](const KnownBits &Known) { return Known.abs(true); },
+ [](const APInt &N) -> std::optional<APInt> {
+ if (N.isMinSignedValue())
+ return std::nullopt;
+ return N.abs();
+ });
+
+ testUnaryOpExhaustive(
+ "blsi", [](const KnownBits &Known) { return Known.blsi(); },
+ [](const APInt &N) { return N & -N; });
+ testUnaryOpExhaustive(
+ "blsmsk", [](const KnownBits &Known) { return Known.blsmsk(); },
+ [](const APInt &N) { return N ^ (N - 1); });
+
+ testUnaryOpExhaustive(
+ "mul self",
[](const KnownBits &Known) {
return KnownBits::mul(Known, Known, /*SelfMultiply*/ true);
},
``````````
</details>
https://github.com/llvm/llvm-project/pull/89588
More information about the llvm-commits
mailing list