[PATCH] D30629: [APInt] Give the value union a name so we can remove assumptions on VAL being the larger member

Craig Topper via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Mar 5 19:52:31 PST 2017


craig.topper created this revision.
Herald added a subscriber: mehdi_amini.

Currently several places assume the VAL member is always at least the same size as pVal. In particular for a memcpy in the move assignment operator. While this is a true assumption, it isn't good practice to assume this.

This patch gives the union a name so we can write the memcpy in terms of the union itself. This also adds a similar memcpy to the move constructor where we previously just copied using VAL directly.

This patch is mostly just a mechanical addition of the U in front of VAL and pVAL everywhere. But several constructors had to be modified since we can't directly initializer a field of named union from the initializer list.

For the string constructor I pushed the VAL initialization down to where we know whether we need to use VAL or pVal. This leaves the upper bits of the union unitialized on a 32-bit target, but I'm not sure that's really a problem.

For the uint64_t constructor and the copy constructor I just removed the initialization of VAL to 0 altogether. pVal or VAL will always be assigned as needed. Again this makes the upper bits of the union garbage on 32-bit targets, but hopefully that's ok. This removal also makes the compiled binaries smaller because the compiler was unable to infer that the store is unnecessary on 64-bit target due to slow case init function being out of line.


https://reviews.llvm.org/D30629

Files:
  include/llvm/ADT/APInt.h
  lib/IR/LLVMContextImpl.h
  lib/Support/APInt.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D30629.90637.patch
Type: text/x-patch
Size: 44495 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170306/03b03bbf/attachment-0001.bin>


More information about the llvm-commits mailing list