How can I generate SVE vectors with LLVM

659 views Asked by At

clang version 11.0.0

example.c:

#define ARRAYSIZE 1024
int a[ARRAYSIZE];
int b[ARRAYSIZE];
int c[ARRAYSIZE];
void subtract_arrays(int *restrict a, int *restrict b, int *restrict c)
{
    for (int i = 0; i < ARRAYSIZE; i++)
    {
        a[i] = b[i] - c[i];
    }
}

int main()
{
    subtract_arrays(a, b, c);
}

command:

clang --target=aarch64-linux-gnu -march=armv8-a+sve -O3 -S example.c

LLVM always generate NEON vectors, but I want it generate SVE vectors. How can I do this?

1

There are 1 answers

0
Bine Brank On

Unfortunately Clang version 11 does not support SVE auto-vectorization.

This will come with LLVM 13: Architecture support in LLVM

You can however generate SVE code with intrinsic functions or inline assembly. Your code with intrinsic functions would look something along the lines of:

#include <arm_sve.h>
  
void subtract_arrays(int *restrict a, int *restrict b, int *restrict c) {
       int i = 0;
       svbool_t pg = svwhilelt_b32(i, ARRAYSIZE);                                           
       do
       {
           svint32_t db_vec = svld1(pg, &b[i]);                  
           svint32_t dc_vec = svld1(pg, &c[i]);                 
           svint32_t da_vec = svsub_z(pg, db_vec, dc_vec);
           svst1(pg, &a[i], da_vec);                              
           i += svcntw();                                      
           pg = svwhilelt_b32(i, ARRAYSIZE);                  
       }
       while (svptest_any(svptrue_b32(), pg));  
}

I had a similar problem thinking that SVE auto-vectorization is supported. When targeting SVE with Clang, optimization reports show successful vectorization despite only vectorizing for Neon.