summaryrefslogtreecommitdiffstats
path: root/llvm/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
commit698661c741aeadde16956ac4021d1ee1d1eeac85 (patch)
treef14cb6679724a346e83dae3faa70d6ac118fd50a /llvm/lib/Support/APInt.cpp
parentedf5e640fa05fbabc7822be42fe71bbcbe1156cc (diff)
downloadbcm5719-llvm-698661c741aeadde16956ac4021d1ee1d1eeac85.tar.gz
bcm5719-llvm-698661c741aeadde16956ac4021d1ee1d1eeac85.zip
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. llvm-svn: 116457
Diffstat (limited to 'llvm/lib/Support/APInt.cpp')
-rw-r--r--llvm/lib/Support/APInt.cpp12
1 files changed, 12 insertions, 0 deletions
diff --git a/llvm/lib/Support/APInt.cpp b/llvm/lib/Support/APInt.cpp
index ca68988712d..3807314bac4 100644
--- a/llvm/lib/Support/APInt.cpp
+++ b/llvm/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();
OpenPOWER on IntegriCloud