This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] PR middle-end/17055: Casting integer zero to a vector
- From: James E Wilson <wilson at specifixinc dot com>
- To: Roger Sayle <roger at eyesopen dot com>
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Wed, 08 Sep 2004 16:31:30 -0700
- Subject: Re: [PATCH] PR middle-end/17055: Casting integer zero to a vector
- References: <Pine.LNX.4.44.0409081536120.20912-100000@www.eyesopen.com>
On Wed, 2004-09-08 at 14:41, Roger Sayle wrote:
> It would be nice to add code to "fold_convert_const" that could
> constant fold the non-zero scalar to vector conversions. Currently,
> GCC generates a NOP_EXPR of INTEGER_CST, instead of the ideal
> VECTOR_CST with the appropriate elements. Alas, I'm not sure about
> the integer vs. vector endian issues. I suspect fixing the above
> problem should allow us to optimize ((v4qi)0x12345678)[2] at compile
> time, for example.
I think we should treat vector as a kind of array. So this expression
should give the same result as
union u { int i; char v[4];} u;
u.i = 0x12345678
u.v[2]
which is 0x56 for big-endian and 0x34 for little-endian.
CONST_VECTOR and VECTOR_CST are defined such that the first element is
the element at address zero. For CONST_VECTOR, this is a necessary
consequence of how the simplify-rtx.c support for VEC_SELECT and
VEC_CONCAT was written. Thus I think 0x12345678 should be for
big-endian
(CONST_VECTOR (CONST_INT 0x12) (CONST_INT 0x34)
(CONST_INT 0x56) (CONST_INT 0x78))
and for little-endian
(CONST_VECTOR (CONST_INT 0x78) (CONST_INT 0x56)
(CONST_INT 0x34) (CONST_INT 0x12))
Indexing into a CONST_VECTOR works the same regardless of endianness.
VECTOR_CST should probably be handled the same way.
--
Jim Wilson, GNU Tools Support, http://www.SpecifixInc.com