diff options
author | Frits van Bommel <fvbommel@gmail.com> | 2011-03-27 14:26:13 +0000 |
---|---|---|
committer | Frits van Bommel <fvbommel@gmail.com> | 2011-03-27 14:26:13 +0000 |
commit | 0bb2ad2cf7f8032492401d82e0cb6be6b98406a0 (patch) | |
tree | 6e79e42f5d24f438eb4fa23cf16a41fe102df8d8 /llvm/lib/Support | |
parent | d5f631cd2a518f615020c42635a818259dd0f445 (diff) | |
download | bcm5719-llvm-0bb2ad2cf7f8032492401d82e0cb6be6b98406a0.tar.gz bcm5719-llvm-0bb2ad2cf7f8032492401d82e0cb6be6b98406a0.zip |
Constant folding support for calls to umul.with.overflow(), basically identical to the smul.with.overflow() code.
llvm-svn: 128379
Diffstat (limited to 'llvm/lib/Support')
-rw-r--r-- | llvm/lib/Support/APInt.cpp | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/llvm/lib/Support/APInt.cpp b/llvm/lib/Support/APInt.cpp index f4aae72ecaf..5789721c3a8 100644 --- a/llvm/lib/Support/APInt.cpp +++ b/llvm/lib/Support/APInt.cpp @@ -2078,6 +2078,16 @@ APInt APInt::smul_ov(const APInt &RHS, bool &Overflow) const { return Res; } +APInt APInt::umul_ov(const APInt &RHS, bool &Overflow) const { + APInt Res = *this * RHS; + + if (*this != 0 && RHS != 0) + Overflow = Res.udiv(RHS) != *this || Res.udiv(*this) != RHS; + else + Overflow = false; + return Res; +} + APInt APInt::sshl_ov(unsigned ShAmt, bool &Overflow) const { Overflow = ShAmt >= getBitWidth(); if (Overflow) |