aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Support/APInt.cpp
diff options
context:
space:
mode:
authorKerry McLaughlin <kerry.mclaughlin@arm.com>2020-11-23 11:05:50 +0000
committerKerry McLaughlin <kerry.mclaughlin@arm.com>2020-11-23 11:27:30 +0000
commitd3a0f9b9ec88ce0737470652330262f8ed46daa7 (patch)
treed2a9e0861b1ab36605cf40544c096ad966fb4ece /llvm/lib/Support/APInt.cpp
parent1319c6624ed6b0a6fb48d975bbf278263a85fcef (diff)
downloadllvm-d3a0f9b9ec88ce0737470652330262f8ed46daa7.zip
llvm-d3a0f9b9ec88ce0737470652330262f8ed46daa7.tar.gz
llvm-d3a0f9b9ec88ce0737470652330262f8ed46daa7.tar.bz2
[APInt] Add the truncOrSelf resizing operator to APInt
Truncates the APInt if the bit width is greater than the width specified, otherwise do nothing Reviewed By: RKSimon Differential Revision: https://reviews.llvm.org/D91445
Diffstat (limited to 'llvm/lib/Support/APInt.cpp')
-rw-r--r--llvm/lib/Support/APInt.cpp6
1 files changed, 6 insertions, 0 deletions
diff --git a/llvm/lib/Support/APInt.cpp b/llvm/lib/Support/APInt.cpp
index fc339de..12ceb2d 100644
--- a/llvm/lib/Support/APInt.cpp
+++ b/llvm/lib/Support/APInt.cpp
@@ -961,6 +961,12 @@ APInt APInt::sextOrTrunc(unsigned width) const {
return *this;
}
+APInt APInt::truncOrSelf(unsigned width) const {
+ if (BitWidth > width)
+ return trunc(width);
+ return *this;
+}
+
APInt APInt::zextOrSelf(unsigned width) const {
if (BitWidth < width)
return zext(width);