summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Support/APInt.cpp
diff options
context:
space:
mode:
authorRoman Lebedev <lebedev.ri@gmail.com>2019-10-25 18:17:48 +0300
committerRoman Lebedev <lebedev.ri@gmail.com>2019-10-25 18:20:00 +0300
commit1cc8e1e1d7d78fc3f2185c5ba207cd21f227fa1c (patch)
tree23ed419b7338aceb2b0b098502c476e27b1a061d /llvm/lib/Support/APInt.cpp
parentb2c184458e990c8faeffd5047e7086e4f7ff07a6 (diff)
downloadbcm5719-llvm-1cc8e1e1d7d78fc3f2185c5ba207cd21f227fa1c.tar.gz
bcm5719-llvm-1cc8e1e1d7d78fc3f2185c5ba207cd21f227fa1c.zip
[APInt] Add saturating left-shift ops
Summary: There are `*_ov()` functions already, so at least for consistency it may be good to also have saturating variants. These may or may not be needed for `ConstantRange`'s `shlWithNoWrap()` Reviewers: spatel, nikic Reviewed By: nikic Subscribers: hiraditya, dexonsmith, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D69398
Diffstat (limited to 'llvm/lib/Support/APInt.cpp')
-rw-r--r--llvm/lib/Support/APInt.cpp19
1 files changed, 19 insertions, 0 deletions
diff --git a/llvm/lib/Support/APInt.cpp b/llvm/lib/Support/APInt.cpp
index df2e6197b2a..08e9757702a 100644
--- a/llvm/lib/Support/APInt.cpp
+++ b/llvm/lib/Support/APInt.cpp
@@ -2070,6 +2070,25 @@ APInt APInt::umul_sat(const APInt &RHS) const {
return APInt::getMaxValue(BitWidth);
}
+APInt APInt::sshl_sat(const APInt &RHS) const {
+ bool Overflow;
+ APInt Res = sshl_ov(RHS, Overflow);
+ if (!Overflow)
+ return Res;
+
+ return isNegative() ? APInt::getSignedMinValue(BitWidth)
+ : APInt::getSignedMaxValue(BitWidth);
+}
+
+APInt APInt::ushl_sat(const APInt &RHS) const {
+ bool Overflow;
+ APInt Res = ushl_ov(RHS, Overflow);
+ if (!Overflow)
+ return Res;
+
+ return APInt::getMaxValue(BitWidth);
+}
+
void APInt::fromString(unsigned numbits, StringRef str, uint8_t radix) {
// Check our assumptions here
assert(!str.empty() && "Invalid string length");
OpenPOWER on IntegriCloud