This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] PR middle-end/17055: Casting integer zero to a vector


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



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]