From 698661c741aeadde16956ac4021d1ee1d1eeac85 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Thu, 14 Oct 2010 00:05:07 +0000 Subject: 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 --- llvm/lib/Support/APInt.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'llvm/lib/Support/APInt.cpp') diff --git a/llvm/lib/Support/APInt.cpp b/llvm/lib/Support/APInt.cpp index ca68988..3807314 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(); -- cgit v1.1