aboutsummaryrefslogtreecommitdiff
path: root/llvm/unittests/ADT/APIntTest.cpp
diff options
context:
space:
mode:
authorJay Foad <jay.foad@amd.com>2024-04-04 17:24:16 +0100
committerGitHub <noreply@github.com>2024-04-04 17:24:16 +0100
commit0b293e8c36d97bbd7f85ed5b67ce510ff7fd86ee (patch)
tree7ad7b7d3729ba4d09a6545c41d4116fde8d5e85c /llvm/unittests/ADT/APIntTest.cpp
parented412494988411fc1aae2f1014c4ecad56d8085f (diff)
downloadllvm-0b293e8c36d97bbd7f85ed5b67ce510ff7fd86ee.zip
llvm-0b293e8c36d97bbd7f85ed5b67ce510ff7fd86ee.tar.gz
llvm-0b293e8c36d97bbd7f85ed5b67ce510ff7fd86ee.tar.bz2
[APInt] Remove multiplicativeInverse with explicit modulus (#87644)
All callers have been changed to use the new simpler overload with an implicit modulus of 2^BitWidth. The old form was never used or tested with non-power-of-two modulus anyway.
Diffstat (limited to 'llvm/unittests/ADT/APIntTest.cpp')
-rw-r--r--llvm/unittests/ADT/APIntTest.cpp19
1 files changed, 4 insertions, 15 deletions
diff --git a/llvm/unittests/ADT/APIntTest.cpp b/llvm/unittests/ADT/APIntTest.cpp
index 23f9ee2..76fc264 100644
--- a/llvm/unittests/ADT/APIntTest.cpp
+++ b/llvm/unittests/ADT/APIntTest.cpp
@@ -3249,22 +3249,11 @@ TEST(APIntTest, SolveQuadraticEquationWrap) {
}
TEST(APIntTest, MultiplicativeInverseExaustive) {
- for (unsigned BitWidth = 1; BitWidth <= 16; ++BitWidth) {
- for (unsigned Value = 0; Value < (1u << BitWidth); ++Value) {
+ for (unsigned BitWidth = 1; BitWidth <= 8; ++BitWidth) {
+ for (unsigned Value = 1; Value < (1u << BitWidth); Value += 2) {
+ // Multiplicative inverse exists for all odd numbers.
APInt V = APInt(BitWidth, Value);
- APInt MulInv =
- V.zext(BitWidth + 1)
- .multiplicativeInverse(APInt::getSignedMinValue(BitWidth + 1))
- .trunc(BitWidth);
- APInt One = V * MulInv;
- 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());
- }
+ EXPECT_EQ(V * V.multiplicativeInverse(), 1);
}
}
}