aboutsummaryrefslogtreecommitdiff
path: root/llvm/unittests/ADT/APIntTest.cpp
diff options
context:
space:
mode:
authorJay Foad <jay.foad@amd.com>2024-04-04 16:11:06 +0100
committerGitHub <noreply@github.com>2024-04-04 16:11:06 +0100
commit1b761205f2686516cebadbcbc37f798197d9c482 (patch)
tree2aa2a932303b99777e2d369c021ea612b4b43acc /llvm/unittests/ADT/APIntTest.cpp
parent51f1cb5355d296ccb7756944d0545d9c96066b78 (diff)
downloadllvm-1b761205f2686516cebadbcbc37f798197d9c482.zip
llvm-1b761205f2686516cebadbcbc37f798197d9c482.tar.gz
llvm-1b761205f2686516cebadbcbc37f798197d9c482.tar.bz2
[APInt] Add a simpler overload of multiplicativeInverse (#87610)
The current APInt::multiplicativeInverse takes a modulus which can be any value, but all in-tree callers use a power of two. Moreover, most callers want to use two to the power of the width of an existing APInt, which is awkward because 2^N is not representable as an N-bit APInt. Add a new overload of multiplicativeInverse which implicitly uses 2^BitWidth as the modulus.
Diffstat (limited to 'llvm/unittests/ADT/APIntTest.cpp')
-rw-r--r--llvm/unittests/ADT/APIntTest.cpp3
1 files changed, 2 insertions, 1 deletions
diff --git a/llvm/unittests/ADT/APIntTest.cpp b/llvm/unittests/ADT/APIntTest.cpp
index d5ef63e..23f9ee2 100644
--- a/llvm/unittests/ADT/APIntTest.cpp
+++ b/llvm/unittests/ADT/APIntTest.cpp
@@ -3257,9 +3257,10 @@ TEST(APIntTest, MultiplicativeInverseExaustive) {
.multiplicativeInverse(APInt::getSignedMinValue(BitWidth + 1))
.trunc(BitWidth);
APInt One = V * MulInv;
- if (!V.isZero() && V.countr_zero() == 0) {
+ if (V[0]) {
// Multiplicative inverse exists for all odd numbers.
EXPECT_TRUE(One.isOne());
+ EXPECT_TRUE((V * V.multiplicativeInverse()).isOne());
} else {
// Multiplicative inverse does not exist for even numbers (and 0).
EXPECT_TRUE(MulInv.isZero());