[APInt] Add negate helper method to implement twos complement. Use it to shorten code.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@302716 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Craig Topper
2017-05-10 20:01:38 +00:00
parent 3750feec55
commit d53f653e9b
2 changed files with 10 additions and 8 deletions
+3 -6
View File
@@ -1846,10 +1846,8 @@ void APInt::fromString(unsigned numbits, StringRef str, uint8_t radix) {
*this += digit;
}
// If its negative, put it in two's complement form
if (isNeg) {
--(*this);
this->flipAllBits();
}
if (isNeg)
this->negate();
}
void APInt::toString(SmallVectorImpl<char> &Str, unsigned Radix,
@@ -1927,8 +1925,7 @@ void APInt::toString(SmallVectorImpl<char> &Str, unsigned Radix,
// They want to print the signed version and it is a negative value
// Flip the bits and add one to turn it into the equivalent positive
// value and put a '-' in the result.
Tmp.flipAllBits();
++Tmp;
Tmp.negate();
Str.push_back('-');
}