diff options
author | Noah Goldstein <goldstein.w.n@gmail.com> | 2023-05-23 11:13:13 -0500 |
---|---|---|
committer | Noah Goldstein <goldstein.w.n@gmail.com> | 2023-05-23 13:52:40 -0500 |
commit | 5f50b180c50e5108b8b18d167147bef8c00fe532 (patch) | |
tree | 399013ee4f3c259900a350ca5e3d190e1547348f /llvm/unittests/Support/KnownBitsTest.cpp | |
parent | 1e963b40813e18e3b285cab35a05b5e0fe166eec (diff) | |
download | llvm-5f50b180c50e5108b8b18d167147bef8c00fe532.zip llvm-5f50b180c50e5108b8b18d167147bef8c00fe532.tar.gz llvm-5f50b180c50e5108b8b18d167147bef8c00fe532.tar.bz2 |
[KnownBits] Add implementations for saturating add/sub functions
These where previously missing. Even in the case where overflow is
indeterminate we can still deduce some of the low/high bits.
Reviewed By: RKSimon
Differential Revision: https://reviews.llvm.org/D150102
Diffstat (limited to 'llvm/unittests/Support/KnownBitsTest.cpp')
-rw-r--r-- | llvm/unittests/Support/KnownBitsTest.cpp | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/llvm/unittests/Support/KnownBitsTest.cpp b/llvm/unittests/Support/KnownBitsTest.cpp index 14c5825..457b7c8 100644 --- a/llvm/unittests/Support/KnownBitsTest.cpp +++ b/llvm/unittests/Support/KnownBitsTest.cpp @@ -300,7 +300,38 @@ TEST(KnownBitsTest, BinaryExhaustive) { return N1.srem(N2); }, checkCorrectnessOnlyBinary); - + testBinaryOpExhaustive( + [](const KnownBits &Known1, const KnownBits &Known2) { + return KnownBits::sadd_sat(Known1, Known2); + }, + [](const APInt &N1, const APInt &N2) -> std::optional<APInt> { + return N1.sadd_sat(N2); + }, + checkCorrectnessOnlyBinary); + testBinaryOpExhaustive( + [](const KnownBits &Known1, const KnownBits &Known2) { + return KnownBits::uadd_sat(Known1, Known2); + }, + [](const APInt &N1, const APInt &N2) -> std::optional<APInt> { + return N1.uadd_sat(N2); + }, + checkCorrectnessOnlyBinary); + testBinaryOpExhaustive( + [](const KnownBits &Known1, const KnownBits &Known2) { + return KnownBits::ssub_sat(Known1, Known2); + }, + [](const APInt &N1, const APInt &N2) -> std::optional<APInt> { + return N1.ssub_sat(N2); + }, + checkCorrectnessOnlyBinary); + testBinaryOpExhaustive( + [](const KnownBits &Known1, const KnownBits &Known2) { + return KnownBits::usub_sat(Known1, Known2); + }, + [](const APInt &N1, const APInt &N2) -> std::optional<APInt> { + return N1.usub_sat(N2); + }, + checkCorrectnessOnlyBinary); testBinaryOpExhaustive( [](const KnownBits &Known1, const KnownBits &Known2) { return KnownBits::shl(Known1, Known2); |