[GVN] Fix handling of sub-byte types in big-endian mode
authorUlrich Weigand <ulrich.weigand@de.ibm.com>
Thu, 7 Apr 2016 15:45:02 +0000 (15:45 +0000)
committerUlrich Weigand <ulrich.weigand@de.ibm.com>
Thu, 7 Apr 2016 15:45:02 +0000 (15:45 +0000)
commit6e6966460a387724cd87ec92d3a91ecfbee84a24
treed2c3798e109ea82e8a9e66256c9d10899e2a8fc1
parent4701a91e59270639341fde8f34eaf2773e1c74c6
[GVN] Fix handling of sub-byte types in big-endian mode

When GVN wants to re-interpret an already available value in a smaller
type, it needs to right-shift the value on big-endian systems to ensure
the correct bytes are accessed.  The shift value is the difference of
the sizes of the two types.

This is correct as long as both types occupy multiples of full bytes.
However, when one of them is a sub-byte type like i1, this no longer
holds true: we still need to shift, but only to access the correct
*byte*.  Accessing bits within the byte requires no shift in either
endianness; e.g. an i1 resides in the least-significant bit of its
containing byte on both big- and little-endian systems.

Therefore, the appropriate shift value to be used is the difference of
the *storage* sizes of the two types.  This is already handled correctly
in one place where such a shift takes place (GetStoreValueForLoad), but
is incorrect in two other places: GetLoadValueForLoad and
CoerceAvailableValueToLoadType.

This patch changes both places to use the storage size as well.

Differential Revision: http://reviews.llvm.org/D18662

llvm-svn: 265684
llvm/lib/Transforms/Scalar/GVN.cpp
llvm/test/Transforms/GVN/big-endian.ll [new file with mode: 0644]