diff options
author | Krzysztof Parzyszek <kparzysz@codeaurora.org> | 2018-07-19 18:07:56 +0000 |
---|---|---|
committer | Krzysztof Parzyszek <kparzysz@codeaurora.org> | 2018-07-19 18:07:56 +0000 |
commit | 55a0dcee0718d7a6e6036dd65111ba60a65d34c4 (patch) | |
tree | cb8ee3294b058dc966e850f5cfdf35c4a22fa938 /llvm/unittests/ADT | |
parent | e9b3f58290b7e4022c988abe1569131ef3d0c944 (diff) | |
download | bcm5719-llvm-55a0dcee0718d7a6e6036dd65111ba60a65d34c4.tar.gz bcm5719-llvm-55a0dcee0718d7a6e6036dd65111ba60a65d34c4.zip |
[APInt] Keep the original bit width in quotient and remainder
Some trivial cases in udivrem were handled by directly assigning 0 or 1
to APInt objects. This would set the bit width to 1, instead of the bit
width of the inputs. A potentially undesirable side effect of that is
that with the bit width of 1, 1 equals -1.
Differential Revision: https://reviews.llvm.org/D49554
llvm-svn: 337478
Diffstat (limited to 'llvm/unittests/ADT')
-rw-r--r-- | llvm/unittests/ADT/APIntTest.cpp | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/llvm/unittests/ADT/APIntTest.cpp b/llvm/unittests/ADT/APIntTest.cpp index 4eb6d676b8c..48f91195e44 100644 --- a/llvm/unittests/ADT/APIntTest.cpp +++ b/llvm/unittests/ADT/APIntTest.cpp @@ -1060,6 +1060,38 @@ TEST(APIntTest, divremuint) { APInt{1024, 1}); } +TEST(APIntTest, divrem_simple) { + // Test simple cases. + APInt A(65, 2), B(65, 2); + APInt Q, R; + + // X / X + APInt::sdivrem(A, B, Q, R); + EXPECT_EQ(Q, APInt(65, 1)); + EXPECT_EQ(R, APInt(65, 0)); + APInt::udivrem(A, B, Q, R); + EXPECT_EQ(Q, APInt(65, 1)); + EXPECT_EQ(R, APInt(65, 0)); + + // 0 / X + APInt O(65, 0); + APInt::sdivrem(O, B, Q, R); + EXPECT_EQ(Q, APInt(65, 0)); + EXPECT_EQ(R, APInt(65, 0)); + APInt::udivrem(O, B, Q, R); + EXPECT_EQ(Q, APInt(65, 0)); + EXPECT_EQ(R, APInt(65, 0)); + + // X / 1 + APInt I(65, 1); + APInt::sdivrem(A, I, Q, R); + EXPECT_EQ(Q, A); + EXPECT_EQ(R, APInt(65, 0)); + APInt::udivrem(A, I, Q, R); + EXPECT_EQ(Q, A); + EXPECT_EQ(R, APInt(65, 0)); +} + TEST(APIntTest, fromString) { EXPECT_EQ(APInt(32, 0), APInt(32, "0", 2)); EXPECT_EQ(APInt(32, 1), APInt(32, "1", 2)); |