diff options
| author | Pawel Bylica <chfast@gmail.com> | 2015-06-25 10:23:52 +0000 |
|---|---|---|
| committer | Pawel Bylica <chfast@gmail.com> | 2015-06-25 10:23:52 +0000 |
| commit | 8bebed98a69c7402bffea969e4f9c912cf1f431c (patch) | |
| tree | dd7a2d46fd657dd3b753ff665824136a503e3d42 /llvm/unittests/ADT/APIntTest.cpp | |
| parent | 7bc44dcb0cfd9f8eaac2893fedc5daabacee5692 (diff) | |
| download | bcm5719-llvm-8bebed98a69c7402bffea969e4f9c912cf1f431c.tar.gz bcm5719-llvm-8bebed98a69c7402bffea969e4f9c912cf1f431c.zip | |
Express APInt::{s,u}{l,g}e(uint64_t) in terms of APInt::{s,u}{l,g}t(uint64_t). NFC.
This is preparation for http://reviews.llvm.org/D10655: Change APInt comparison with uint64_t.
Some unit tests added also.
llvm-svn: 240626
Diffstat (limited to 'llvm/unittests/ADT/APIntTest.cpp')
| -rw-r--r-- | llvm/unittests/ADT/APIntTest.cpp | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/llvm/unittests/ADT/APIntTest.cpp b/llvm/unittests/ADT/APIntTest.cpp index e4398f0f669..098140c50c6 100644 --- a/llvm/unittests/ADT/APIntTest.cpp +++ b/llvm/unittests/ADT/APIntTest.cpp @@ -215,6 +215,44 @@ TEST(APIntTest, i1) { } } +TEST(APIntTest, compare) { + std::array<APInt, 5> testVals{{ + APInt{16, 2}, + APInt{16, 1}, + APInt{16, 0}, + APInt{16, (uint64_t)-1, true}, + APInt{16, (uint64_t)-2, true}, + }}; + + for (auto &arg1 : testVals) + for (auto &arg2 : testVals) { + auto uv1 = arg1.getZExtValue(); + auto uv2 = arg2.getZExtValue(); + auto sv1 = arg1.getSExtValue(); + auto sv2 = arg2.getSExtValue(); + + EXPECT_EQ(uv1 < uv2, arg1.ult(arg2)); + EXPECT_EQ(uv1 <= uv2, arg1.ule(arg2)); + EXPECT_EQ(uv1 > uv2, arg1.ugt(arg2)); + EXPECT_EQ(uv1 >= uv2, arg1.uge(arg2)); + + EXPECT_EQ(sv1 < sv2, arg1.slt(arg2)); + EXPECT_EQ(sv1 <= sv2, arg1.sle(arg2)); + EXPECT_EQ(sv1 > sv2, arg1.sgt(arg2)); + EXPECT_EQ(sv1 >= sv2, arg1.sge(arg2)); + + EXPECT_EQ(uv1 < uv2, arg1.ult(uv2)); + EXPECT_EQ(uv1 <= uv2, arg1.ule(uv2)); + EXPECT_EQ(uv1 > uv2, arg1.ugt(uv2)); + EXPECT_EQ(uv1 >= uv2, arg1.uge(uv2)); + + EXPECT_EQ(sv1 < sv2, arg1.slt(sv2)); + EXPECT_EQ(sv1 <= sv2, arg1.sle(sv2)); + EXPECT_EQ(sv1 > sv2, arg1.sgt(sv2)); + EXPECT_EQ(sv1 >= sv2, arg1.sge(sv2)); + } +} + // Tests different div/rem varaints using scheme (a * b + c) / a void testDiv(APInt a, APInt b, APInt c) { |

