mirror of
https://github.com/RPCS3/llvm.git
synced 2026-07-19 23:23:38 -04:00
[APInt] Optimize umul_ov
Change two costly udiv() calls to lshr(1)*RHS + left-shift + plus On one 64-bit umul_ov benchmark, I measured an obvious improvement: 12.8129s -> 3.6257s Note, there may be some value to special case 64-bit (the most common case) with __builtin_umulll_overflow(). Differential Revision: https://reviews.llvm.org/D60669 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@358730 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
+12
-5
@@ -1914,12 +1914,19 @@ APInt APInt::smul_ov(const APInt &RHS, bool &Overflow) const {
|
||||
}
|
||||
|
||||
APInt APInt::umul_ov(const APInt &RHS, bool &Overflow) const {
|
||||
APInt Res = *this * RHS;
|
||||
if (countLeadingZeros() + RHS.countLeadingZeros() + 2 <= BitWidth) {
|
||||
Overflow = true;
|
||||
return *this * RHS;
|
||||
}
|
||||
|
||||
if (*this != 0 && RHS != 0)
|
||||
Overflow = Res.udiv(RHS) != *this || Res.udiv(*this) != RHS;
|
||||
else
|
||||
Overflow = false;
|
||||
APInt Res = lshr(1) * RHS;
|
||||
Overflow = Res.isNegative();
|
||||
Res <<= 1;
|
||||
if ((*this)[0]) {
|
||||
Res += RHS;
|
||||
if (Res.ult(RHS))
|
||||
Overflow = true;
|
||||
}
|
||||
return Res;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user