[APInt] In sext single word case, use SignExtend64 and let the APInt constructor mask off any excess bits.

The current code is trying to be clever with shifts to avoid needing to clear unused bits. But it looks like the compiler is unable to optimize out the unused bit handling in the APInt constructor. Given this its better to just use SignExtend64 and have more readable code.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@301133 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Craig Topper
2017-04-23 17:16:24 +00:00
parent a1e90f27e3
commit 7271492c50
2 changed files with 22 additions and 5 deletions
+2 -5
View File
@@ -942,11 +942,8 @@ APInt APInt::trunc(unsigned width) const {
APInt APInt::sext(unsigned width) const {
assert(width > BitWidth && "Invalid APInt SignExtend request");
if (width <= APINT_BITS_PER_WORD) {
uint64_t val = VAL << (APINT_BITS_PER_WORD - BitWidth);
val = (int64_t)val >> (width - BitWidth);
return APInt(width, val >> (APINT_BITS_PER_WORD - width));
}
if (width <= APINT_BITS_PER_WORD)
return APInt(width, SignExtend64(VAL, BitWidth));
APInt Result(getMemory(getNumWords(width)), width);