diff options
Diffstat (limited to 'llvm/unittests/ADT/APIntTest.cpp')
| -rw-r--r-- | llvm/unittests/ADT/APIntTest.cpp | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/llvm/unittests/ADT/APIntTest.cpp b/llvm/unittests/ADT/APIntTest.cpp index 83bbc5e..58c17b4 100644 --- a/llvm/unittests/ADT/APIntTest.cpp +++ b/llvm/unittests/ADT/APIntTest.cpp @@ -2729,9 +2729,24 @@ TEST(APIntTest, umul_ov) { for (unsigned Bits = 1; Bits <= 5; ++Bits) for (unsigned A = 0; A != 1u << Bits; ++A) for (unsigned B = 0; B != 1u << Bits; ++B) { - APInt C = APInt(Bits, A).umul_ov(APInt(Bits, B), Overflow); - APInt D = APInt(2 * Bits, A) * APInt(2 * Bits, B); - EXPECT_TRUE(D.getHiBits(Bits).isNullValue() != Overflow); + APInt N1 = APInt(Bits, A), N2 = APInt(Bits, B); + APInt Narrow = N1.umul_ov(N2, Overflow); + APInt Wide = N1.zext(2 * Bits) * N2.zext(2 * Bits); + EXPECT_EQ(Wide.trunc(Bits), Narrow); + EXPECT_EQ(Narrow.zext(2 * Bits) != Wide, Overflow); + } +} + +TEST(APIntTest, smul_ov) { + for (unsigned Bits = 1; Bits <= 5; ++Bits) + for (unsigned A = 0; A != 1u << Bits; ++A) + for (unsigned B = 0; B != 1u << Bits; ++B) { + bool Overflow; + APInt N1 = APInt(Bits, A), N2 = APInt(Bits, B); + APInt Narrow = N1.smul_ov(N2, Overflow); + APInt Wide = N1.sext(2 * Bits) * N2.sext(2 * Bits); + EXPECT_EQ(Wide.trunc(Bits), Narrow); + EXPECT_EQ(Narrow.sext(2 * Bits) != Wide, Overflow); } } |
