aboutsummaryrefslogtreecommitdiff
path: root/llvm/unittests/Support/KnownBitsTest.cpp
diff options
context:
space:
mode:
authorNoah Goldstein <goldstein.w.n@gmail.com>2023-05-06 20:58:23 -0500
committerNoah Goldstein <goldstein.w.n@gmail.com>2023-05-16 18:58:12 -0500
commit7d05ab99edb9f5ef06c3d635afcd22502866f447 (patch)
tree1e1b4191245d697489c5d28f28aecb08a3d1fa84 /llvm/unittests/Support/KnownBitsTest.cpp
parent8c569c922bc5bbe9fb67ff3ff3ac28e17b012360 (diff)
downloadllvm-7d05ab99edb9f5ef06c3d635afcd22502866f447.zip
llvm-7d05ab99edb9f5ef06c3d635afcd22502866f447.tar.gz
llvm-7d05ab99edb9f5ef06c3d635afcd22502866f447.tar.bz2
[KnownBits] Improve `KnownBits::udiv`
We can more precisely determine the upper bits doing `MaxNum / MinDenum` as opposed to only using the MSB. As well, if the `exact` flag is set, we can sometimes determine some of the low-bits. Differential Revision: https://reviews.llvm.org/D150094
Diffstat (limited to 'llvm/unittests/Support/KnownBitsTest.cpp')
-rw-r--r--llvm/unittests/Support/KnownBitsTest.cpp10
1 files changed, 10 insertions, 0 deletions
diff --git a/llvm/unittests/Support/KnownBitsTest.cpp b/llvm/unittests/Support/KnownBitsTest.cpp
index 22dcbed..0322da6 100644
--- a/llvm/unittests/Support/KnownBitsTest.cpp
+++ b/llvm/unittests/Support/KnownBitsTest.cpp
@@ -251,6 +251,16 @@ TEST(KnownBitsTest, BinaryExhaustive) {
checkCorrectnessOnlyBinary);
testBinaryOpExhaustive(
[](const KnownBits &Known1, const KnownBits &Known2) {
+ return KnownBits::udiv(Known1, Known2, /*Exact*/ true);
+ },
+ [](const APInt &N1, const APInt &N2) -> std::optional<APInt> {
+ if (N2.isZero() || !N1.urem(N2).isZero())
+ return std::nullopt;
+ return N1.udiv(N2);
+ },
+ checkCorrectnessOnlyBinary);
+ testBinaryOpExhaustive(
+ [](const KnownBits &Known1, const KnownBits &Known2) {
return KnownBits::sdiv(Known1, Known2);
},
[](const APInt &N1, const APInt &N2) -> std::optional<APInt> {