Big endian vector elements

Hal Finkel hfinkel at anl.gov
Mon Mar 3 12:29:42 PST 2014


----- Original Message -----
> From: "Tim Northover" <t.p.northover at gmail.com>
> To: "llvm-commits" <llvm-commits at cs.uiuc.edu>
> Cc: "Hal Finkel" <hfinkel at anl.gov>, "Chandler Carruth" <chandlerc at google.com>
> Sent: Monday, March 3, 2014 9:21:10 AM
> Subject: Big endian vector elements
> 
> Hi all,
> 
> What's LLVM's position on where element 0 exists when a vector is
> stored on a big-endian machine? As far as I can see there are three
> choices:
> 1. At the high address.
> 2. At the low address.
> 3. Target decision, no opts that depend on it happen.
> 
> I think there's code assuming both 1 and 2.:
> 
> 1. In DAGCombiner.cpp, visitEXTRACT_VECTOR_ELT counts lanes backwards
> for addressing purposes.
> 2. SROA converts the attached .ll file (union type-punning,
> essentially) into an insertvector on element 1.
> 
> One of those has to be a bug (and the documentation should probably
> be
> clarified), but I'm not sure which. Any hints?

(1) sounds wrong. I remember looking at this when working on the vectorizers, and we decided to match the convention used by gcc/xlc on PowerPC. Under this convention, the first vector lane is the one that overlaps the base address of the vector in memory. As a quick example:

$ cat /tmp/tv.c 
#include <stdio.h>

typedef int v4si __attribute__ ((vector_size (16)));

int main() {
  v4si a = { 0, 1, 2, 3} , b;
  b[0] = 0;
  b[1] = 1;
  b[2] = 2;
  b[3] = 3;

  for (int i = 0; i < 4; ++i) {
    printf("i = %d: a[i] = %d, b[i] = %d, cast(a)[i] = %d, cast(b)[i] = %d\n",
           a[i], b[i], ((int*) &a)[i], ((int*) &b)[i]);
  }

  return 0;
}

$ /opt/at6.0/bin/gcc -O0 -std=c99 -o /tmp/tv /tmp/tv.c 
[hfinkel at harvey ~]$ /tmp/tv
i = 0: a[i] = 0, b[i] = 0, cast(a)[i] = 0, cast(b)[i] = 0
i = 1: a[i] = 1, b[i] = 1, cast(a)[i] = 1, cast(b)[i] = 1
i = 2: a[i] = 2, b[i] = 2, cast(a)[i] = 2, cast(b)[i] = 2
i = 3: a[i] = 3, b[i] = 3, cast(a)[i] = 3, cast(b)[i] = 3

$ /opt/at6.0/bin/gcc -dumpmachine
powerpc64-linux
$ /opt/at6.0/bin/gcc -dumpversion
4.7.3

 -Hal

> 
> Cheers.
> 
> Tim.
> 

-- 
Hal Finkel
Assistant Computational Scientist
Leadership Computing Facility
Argonne National Laboratory



More information about the llvm-commits mailing list