summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.dg/vect/vect-outer-simd-2.c
blob: 3ae1020936f960a5e46d6c74bee80d3b52df6db5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/* { dg-require-effective-target vect_simd_clones } */
/* { dg-additional-options "-fopenmp-simd -ffast-math" } */
#include <stdlib.h>
#include "tree-vect.h"
#define N 64

float *px, *py;
float *tx, *ty;
float *x1, *z1, *t1, *t2;

static void inline bar (const float cx, float cy,
                         float *vx, float *vy)
{
  int j;
    for (j = 0; j < N; ++j)
    {
        const float dx  = cx - px[j];
        const float dy  = cy - py[j];
        *vx               -= dx * tx[j];
        *vy               -= dy * ty[j];
    }
}

__attribute__((noinline, noclone)) void foo1 (int n)
{
  int i;
#pragma omp simd
  for (i=0; i<n; i++)
    bar (px[i], py[i], x1+i, z1+i);
}

__attribute__((noinline, noclone)) void foo2 (int n)
{
  volatile int i;
  for (i=0; i<n; i++)
    bar (px[i], py[i], x1+i, z1+i);
}


int main ()
{
  float *X = (float*)malloc (N * 8 * sizeof (float));
  int i;
  int n = N - 1;
  check_vect ();
  px = &X[0];
  py = &X[N * 1];
  tx = &X[N * 2];
  ty = &X[N * 3];
  x1 = &X[N * 4];
  z1 = &X[N * 5];
  t1 = &X[N * 6];
  t2 = &X[N * 7];

  for (i=0; i<N; i++)
    {
      px[i] = (float) (i+2);
      tx[i] = (float) (i+1);
      py[i] = (float) (i+4);
      ty[i] = (float) (i+3);
      x1[i] = z1[i] = 1.0f;
    }
  foo1 (n);  /* vector variant.  */
  for (i=0; i<N;i++)
    {
      t1[i] = x1[i]; x1[i] = 1.0f;
      t2[i] = z1[i]; z1[i] = 1.0f;
    }
  foo2 (n);  /* scalar variant.  */
  for (i=0; i<N; i++)
    if (x1[i] != t1[i] || z1[i] != t2[i])
      abort ();
  return 0;
}
/* { dg-final { scan-tree-dump "OUTER LOOP VECTORIZED" "vect" } } */