[PATCH] D33073: [APInt] Add a utility method to change the bit width and storage size of an APInt.

Roman Divacky via llvm-commits llvm-commits at lists.llvm.org
Thu May 11 01:01:16 PDT 2017


On Wed, May 10, 2017 at 09:42:44PM +0000, Craig Topper via Phabricator via llvm-commits wrote:
> craig.topper created this revision.
> 
> This adds a resize method to APInt that manages deleting/allocating storage for an APInt and changes its bit width. Use this to simplify code in copy assignment and divide.
> 
> The assignment code in particular was overly complicated. Treating every possible case as a separate implementation. I'm also pretty sure the clearUnusedBits code at the end was unnecessary. Since we always copying whole words from the source APInt. All unused bits should be clear in the source.
> 
> 
> https://reviews.llvm.org/D33073
> 
> Files:
>   include/llvm/ADT/APInt.h
>   lib/Support/APInt.cpp
> 

> Index: lib/Support/APInt.cpp
> ===================================================================
> --- lib/Support/APInt.cpp
> +++ lib/Support/APInt.cpp
> @@ -122,35 +122,38 @@
>    fromString(numbits, Str, radix);
>  }
>  
> +void APInt::resize(unsigned NewBitWidth) {
> +  // If the number of words is the same we can just change the width and stop.
> +  if (getNumWords() != getNumWords(NewBitWidth)) {
> +    BitWidth = NewBitWidth;
> +    return;
> +  }

Shouldn't the != be == ?

Thanks, Roman


More information about the llvm-commits mailing list