summaryrefslogtreecommitdiff
path: root/lib/Support/APInt.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2010-10-14 00:05:07 +0000
committerChris Lattner <sabre@nondot.org>2010-10-14 00:05:07 +0000
commiteafc5cb80d58cb9447623a557be4d4f55f42fbc3 (patch)
tree56190b2247d2cd228717675daad96d9864deee39 /lib/Support/APInt.cpp
parent08e90f5646e61c3be0eebfa172ec73a8b56abee8 (diff)
downloadllvm-eafc5cb80d58cb9447623a557be4d4f55f42fbc3.tar.gz
llvm-eafc5cb80d58cb9447623a557be4d4f55f42fbc3.tar.bz2
llvm-eafc5cb80d58cb9447623a557be4d4f55f42fbc3.tar.xz
add uadd_ov/usub_ov to apint, consolidate constant folding
logic to use the new APInt methods. Among other things this implements rdar://8501501 - llvm.smul.with.overflow.i32 should constant fold which comes from "clang -ftrapv", originally brought to my attention from PR8221. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@116457 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Support/APInt.cpp')
-rw-r--r--lib/Support/APInt.cpp12
1 files changed, 12 insertions, 0 deletions
diff --git a/lib/Support/APInt.cpp b/lib/Support/APInt.cpp
index ca68988712..3807314bac 100644
--- a/lib/Support/APInt.cpp
+++ b/lib/Support/APInt.cpp
@@ -2053,6 +2053,12 @@ APInt APInt::sadd_ov(const APInt &RHS, bool &Overflow) const {
return Res;
}
+APInt APInt::uadd_ov(const APInt &RHS, bool &Overflow) const {
+ APInt Res = *this+RHS;
+ Overflow = Res.ult(RHS);
+ return Res;
+}
+
APInt APInt::ssub_ov(const APInt &RHS, bool &Overflow) const {
APInt Res = *this - RHS;
Overflow = isNonNegative() != RHS.isNonNegative() &&
@@ -2060,6 +2066,12 @@ APInt APInt::ssub_ov(const APInt &RHS, bool &Overflow) const {
return Res;
}
+APInt APInt::usub_ov(const APInt &RHS, bool &Overflow) const {
+ APInt Res = *this+RHS;
+ Overflow = Res.ugt(RHS);
+ return Res;
+}
+
APInt APInt::sdiv_ov(const APInt &RHS, bool &Overflow) const {
// MININT/-1 --> overflow.
Overflow = isMinSignedValue() && RHS.isAllOnesValue();