diff options
author | Roman Lebedev <lebedev.ri@gmail.com> | 2019-12-03 17:45:47 +0300 |
---|---|---|
committer | Roman Lebedev <lebedev.ri@gmail.com> | 2019-12-03 20:04:51 +0300 |
commit | 9a20c79ddc2523fb68be4d4246d7835c761c382f (patch) | |
tree | 064eab89c1f5fe78847c52311ad22de67a89b054 /llvm/unittests/Support/KnownBitsTest.cpp | |
parent | 372ad32734ecb455f9fb4d0601229ca2dfc78b66 (diff) | |
download | bcm5719-llvm-9a20c79ddc2523fb68be4d4246d7835c761c382f.tar.gz bcm5719-llvm-9a20c79ddc2523fb68be4d4246d7835c761c382f.zip |
[NFC][KnownBits] Add getMinValue() / getMaxValue() methods
As it can be seen from accompanying cleanup, it is not unheard of
to write `~Known.Zero` meaning "what maximal value can this KnownBits
produce". But i think `~Known.Zero` isn't *that* self-explanatory,
as compared to a method with a name.
Note that not all `~Known.Zero` places were cleaned up,
only those where this arguably improves things.
Diffstat (limited to 'llvm/unittests/Support/KnownBitsTest.cpp')
-rw-r--r-- | llvm/unittests/Support/KnownBitsTest.cpp | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/llvm/unittests/Support/KnownBitsTest.cpp b/llvm/unittests/Support/KnownBitsTest.cpp index c2b3b127cf1..372521dc5c9 100644 --- a/llvm/unittests/Support/KnownBitsTest.cpp +++ b/llvm/unittests/Support/KnownBitsTest.cpp @@ -127,4 +127,18 @@ TEST(KnownBitsTest, AddSubExhaustive) { TestAddSubExhaustive(false); } +TEST(KnownBitsTest, GetMinMaxVal) { + unsigned Bits = 4; + ForeachKnownBits(Bits, [&](const KnownBits &Known) { + APInt Min = APInt::getMaxValue(Bits); + APInt Max = APInt::getMinValue(Bits); + ForeachNumInKnownBits(Known, [&](const APInt &N) { + Min = APIntOps::umin(Min, N); + Max = APIntOps::umax(Max, N); + }); + EXPECT_EQ(Min, Known.getMinValue()); + EXPECT_EQ(Max, Known.getMaxValue()); + }); +} + } // end anonymous namespace |