[llvm-commits] [PATCH] Fix big-endian codegen bug in DAGTypeLegalizer::ExpandRes_BITCAST

Ulrich Weigand Ulrich.Weigand at de.ibm.com
Fri Oct 12 06:07:06 PDT 2012


Hello,

once the four AltiVec test-suite patches I just posted are applied, I'm
still seeing one failure in the AltiVec tests:
SingleSource/UnitTests/Vector/Altivec/2007-01-07-lvsl-lvsr-Regression

It turns out that this is a real code generation bug, triggering not in the
lvsl/lvsr builtins that the test intends to verify, but in the code used to
output the resulting vector ...  This code overlays a <16 x i8> vector with
an i128 using bitcast, and subsequently accesses the subwords of this i128
to print them.  This exposed a bug in how this bitcast is expanded in
ExpandRes_BITCAST on big-endian systems.

Since i128 is not directly legal, that routine attempts to do an
intermediate bitcast to a <4 x i32> vector, and then construct the Hi and
Lo parts of the resulting i128 by pairing up two of those i32 vector
elements each.  The code already recognizes that on a big-endian system,
the first two vector elements form the Hi part, and the final two vector
elements form the Lo part (vice-versa from the little-endian situation).

However, we also need to take endianness into account when forming each of
those separate pairs:  on a big-endian system, vector element 0 is the
*high* part of the pair making up the Hi part of the result, and vector
element 1 is the low part of the pair.  The code currently always uses
vector element 0 as the low part and vector element 1 as the high part, as
is appropriate for little-endian platforms only.

The patch below fixes this by swapping the vector elements as they are
paired up as appropriate.  This fixes the 2007-01-07-lvsl-lvsr-Regression
test case.  In addition, the patch also adds a .ll test case under tests/
that checks directly for the correct behavior of the bitcast.  (This new
also likewise fails without the ExpandRes_BITCAST change, and passes once
it is applied.)

OK to commit?

Bye,
Ulrich
(See attached file: diff-llvm-expandres-bitcast)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: diff-llvm-expandres-bitcast
Type: application/octet-stream
Size: 1513 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20121012/eaebe785/attachment.obj>


More information about the llvm-commits mailing list