[PATCH] AArch64: big endian constant vector pools

Christian Pirker cpirker at a-bix.com
Fri Apr 11 02:07:02 PDT 2014


  Hi Tim,

  I believe your example should read as follows:

    @var =  global <4 x i16> <i16 32, i16 33, i16 34, i16 35>
    define <4 x i16> @foo() {
      %val = load <4 x i16>* @var
      %diff = sub <4 x i16> %val, < i16 32, i16 33, i16 34, i16 35 >
      ret <4 x i16> %diff
    }

  The problem here lies in the ldr load of the variable, which is then used as a vector (that would be a separate issue).
  The initialization of the immediate vector is also done via ldr, however on a reversed stored memory vector.
  This leaves a value in q0 that can be later operated via vector instructions. That is a result of this patch.

  You may check the following c-test case that gets vectorized by clang, thus generating vector instructions:

    #include <stdlib.h>
    #include <stdio.h>
    #define SIZE (26)

    __attribute__ ((noinline)) int SumArray(int Array[][SIZE], unsigned int NumI, unsigned int NumJ) {
      unsigned i, j;
      int Result = 0;
      for (i = 0; i < NumI; i++)
        for (j = 0; j < NumJ; j++)
          Result += Array[i][j];
      return Result;
    }

    __attribute__ ((noinline)) void Init1(int Array[][SIZE] ) {
      unsigned i;
      for (i = 0; i < SIZE; i++)
        Array[i][i] = -i;
    }

    __attribute__ ((noinline)) void Init2(int Array[][SIZE]) {
      unsigned int i, j;
      for (i = 0; i < SIZE; i++)
        for (j = 0; j < SIZE; j++)
          if (j != i)
            Array[i][j] = i+j;
    }

    int main() {
      int Array[SIZE][SIZE];
      unsigned int i, j;

      Init1( Array );
      Init2( Array );

      printf("Sum(Array[%d,%d]) = %d\n", SIZE, SIZE, SumArray(Array, SIZE, SIZE));
      return 0;
    }

  Thanks,
  Christian

http://reviews.llvm.org/D3305






More information about the llvm-commits mailing list