aboutsummaryrefslogtreecommitdiff
path: root/llvm/unittests/Support/KnownBitsTest.cpp
diff options
context:
space:
mode:
authorRoman Lebedev <lebedev.ri@gmail.com>2021-10-11 23:27:12 +0300
committerRoman Lebedev <lebedev.ri@gmail.com>2021-10-11 23:36:06 +0300
commit684cbae89a78f4329a018237ec6f230a82dbc883 (patch)
tree8ead618e289b1b2efbb11574e31ab36cdcbaadb6 /llvm/unittests/Support/KnownBitsTest.cpp
parent259390de9af659e2432c5b2af041ec6576c1b26d (diff)
downloadllvm-684cbae89a78f4329a018237ec6f230a82dbc883.zip
llvm-684cbae89a78f4329a018237ec6f230a82dbc883.tar.gz
llvm-684cbae89a78f4329a018237ec6f230a82dbc883.tar.bz2
[KnownBits] Introduce `countMaxActiveBits()` and use it in a few places
Diffstat (limited to 'llvm/unittests/Support/KnownBitsTest.cpp')
-rw-r--r--llvm/unittests/Support/KnownBitsTest.cpp11
1 files changed, 11 insertions, 0 deletions
diff --git a/llvm/unittests/Support/KnownBitsTest.cpp b/llvm/unittests/Support/KnownBitsTest.cpp
index c38f99a..f9631f2 100644
--- a/llvm/unittests/Support/KnownBitsTest.cpp
+++ b/llvm/unittests/Support/KnownBitsTest.cpp
@@ -431,6 +431,17 @@ TEST(KnownBitsTest, GetSignedMinMaxVal) {
});
}
+TEST(KnownBitsTest, CountMaxActiveBits) {
+ unsigned Bits = 4;
+ ForeachKnownBits(Bits, [&](const KnownBits &Known) {
+ unsigned Expected = 0;
+ ForeachNumInKnownBits(Known, [&](const APInt &N) {
+ Expected = std::max(Expected, N.getActiveBits());
+ });
+ EXPECT_EQ(Expected, Known.countMaxActiveBits());
+ });
+}
+
TEST(KnownBitsTest, SExtOrTrunc) {
const unsigned NarrowerSize = 4;
const unsigned BaseSize = 6;