(root)/
gcc-13.2.0/
gcc/
testsuite/
gcc.dg/
vect/
slp-perm-7.c
       1  /* { dg-require-effective-target vect_int } */
       2  
       3  #include <stdarg.h>
       4  #include "tree-vect.h"
       5  
       6  #define M00 100
       7  #define M10 216
       8  #define M20 23
       9  #define M01 1322
      10  #define M11 13
      11  #define M21 27271
      12  #define M02 74
      13  #define M12 191
      14  #define M22 500
      15  
      16  #define K00 405
      17  #define K10 112
      18  #define K01 4322
      19  #define K11 135
      20  
      21  #if VECTOR_BITS > 128
      22  #define N (VECTOR_BITS * 3 / 32 + 4)
      23  #else
      24  #define N 16
      25  #endif
      26  
      27  /* SLP with load permutation and loop-based vectorization.  */
      28  void foo (int *__restrict__ pInput, int *__restrict__ pOutput,
      29            int *__restrict__ pInput2, int *__restrict__ pOutput2)
      30  {
      31    int i, a, b, c, d;
      32  
      33    for (i = 0; i < N / 3; i++)
      34      {
      35         a = *pInput++;
      36         b = *pInput++;
      37         c = *pInput++;
      38         d = *pInput2++;
      39  
      40         *pOutput++ = M00 * a + M01 * b + M02 * c;
      41         *pOutput++ = M10 * a + M11 * b + M12 * c;
      42         *pOutput++ = M20 * a + M21 * b + M22 * c;
      43  
      44         /* Loop-based vectorization.  */
      45         *pOutput2++ = K00 * d;
      46      }
      47  }
      48  
      49  int main (int argc, const char* argv[])
      50  {
      51    int input[N], output[N], i;
      52    int input2[N], output2[N];
      53  
      54    check_vect ();
      55  
      56    for (i = 0; i < N; i++)
      57      {
      58        input[i] = i%256;
      59        input2[i] = i%256;
      60        output[i] = 0;
      61        output2[i] = 0;
      62        asm volatile ("" ::: "memory");
      63      }
      64  
      65  #if N == 16
      66    int check_results[N] = {1470, 395, 28271, 5958, 1655, 111653, 10446, 2915, 195035, 14934, 4175, 278417, 19422, 5435, 361799, 0};
      67    int check_results2[N] = {0, 405, 810, 1215, 1620, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
      68  #else
      69    volatile int check_results[N] = {};
      70    volatile int check_results2[N] = {};
      71  
      72    for (int i = 0; i < N / 3; i++)
      73      {
      74        int a = input[i * 3];
      75        int b = input[i * 3 + 1];
      76        int c = input[i * 3 + 2];
      77        int d = input2[i];
      78  
      79        check_results[i * 3] = M00 * a + M01 * b + M02 * c;
      80        check_results[i * 3 + 1] = M10 * a + M11 * b + M12 * c;
      81        check_results[i * 3 + 2] = M20 * a + M21 * b + M22 * c;
      82  
      83        check_results2[i] = K00 * d;
      84  
      85        asm volatile ("" ::: "memory");
      86      }
      87  #endif
      88  
      89    foo (input, output, input2, output2);
      90  
      91    for (i = 0; i < N; i++)
      92       if (output[i] != check_results[i] || output2[i] != check_results2[i])
      93         abort ();
      94  
      95    return 0;
      96  }
      97  
      98  /* { dg-final { scan-tree-dump-times "vectorized 1 loops" 1 "vect"  { target vect_perm } } } */
      99  /* { dg-final { scan-tree-dump-times "vectorizing stmts using SLP" 1 "vect" { target { vect_perm3_int && { ! vect_load_lanes } } } } } */
     100  /* { dg-final { scan-tree-dump-times "vectorizing stmts using SLP" 0 "vect" { target vect_load_lanes } } } */
     101  /* { dg-final { scan-tree-dump "Built SLP cancelled: can use load/store-lanes" "vect" { target { vect_perm3_int && vect_load_lanes } } } } */
     102  /* { dg-final { scan-tree-dump "LOAD_LANES" "vect" { target vect_load_lanes } } } */
     103  /* { dg-final { scan-tree-dump "STORE_LANES" "vect" { target vect_load_lanes } } } */