From 1652f14cf6756c39f650e35bb214ffac7f956108 Mon Sep 17 00:00:00 2001
From: David Malcolm <dmalcolm@redhat.com>
Date: Wed, 18 Jul 2018 11:30:48 -0400
Subject: [PATCH 33/66] FIXME: the code I'm testing against

---
 vect-test.c | 344 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 344 insertions(+)
 create mode 100644 vect-test.c

diff --git a/vect-test.c b/vect-test.c
new file mode 100644
index 0000000..acb3c60
--- /dev/null
+++ b/vect-test.c
@@ -0,0 +1,344 @@
+void
+my_example (int n, int *a, int *b, int *c)
+{
+  int i;
+
+  for (i=0; i<n; i++) {
+    a[i] = b[i] + c[i];
+  }
+}
+
+#define M 256
+#define N 256
+
+int a[256], b[256], c[256];
+
+#if 0
+void
+example_1 () {
+  int i;
+
+  for (i=0; i<256; i++){
+    a[i] = b[i] + c[i];
+  }
+}
+
+void
+example_2 (int n, int x) {
+   int i;
+
+   /* feature: support for unknown loop bound  */
+   /* feature: support for loop invariants  */
+   for (i=0; i<n; i++) {
+      b[i] = x;
+   }
+
+   /* feature: general loop exit condition  */
+   /* feature: support for bitwise operations  */
+   while (n--){
+      a[i] = b[i]&c[i]; i++;
+   }
+}
+
+typedef int aint __attribute__ ((__aligned__(16)));
+
+void
+example_3 (int n, aint * __restrict__ p, aint * __restrict q) {
+
+   /* feature: support for (aligned) pointer accesses.  */
+   while (n--){
+      *p++ = *q++;
+   }
+}
+
+#define MAX 42
+
+void
+example_4 (int n, aint * __restrict__ p, aint * __restrict__ q) {
+   int i, j;
+
+   /* feature: support for (aligned) pointer accesses  */
+   /* feature: support for constants  */
+   int iter = n;
+   while (iter--){
+      *p++ = *q++ + 5;
+   }
+
+   /* feature: support for read accesses with a compile time known misalignment  */
+   for (i=0; i<n; i++){
+      a[i] = b[i+1] + c[i+3];
+   }
+
+   /* feature: support for if-conversion  */
+   for (i=0; i<n; i++){
+      j = a[i];
+      b[i] = (j > MAX ? MAX : 0);
+   }
+}
+
+struct a {
+  int ca[N];
+} s;
+
+void
+example_5 (void)
+{
+  int i;
+  for (i = 0; i < N; i++)
+  {
+    /* feature: support for alignable struct access  */
+    s.ca[i] = 5;
+  }
+}
+
+#endif
+
+#if 0
+example6 (gfortran):
+DIMENSION A(1000000), B(1000000), C(1000000)
+READ*, X, Y
+A = LOG(X); B = LOG(Y); C = A + B
+PRINT*, C(500000)
+END
+#endif
+
+#if 0
+// FIXME:
+// This one gets turned by loop distribution into a memcpy,
+// and hence is not vectorized
+
+void
+example_7 (int x)
+{
+  int i;
+
+  /* feature: support for read accesses with an unknown misalignment  */
+  for (i=0; i<N; i++){
+    a[i] = b[i+x];
+  }
+}
+
+int example_8_a[M][N];
+void
+example_8 (int x) {
+   int i,j;
+
+   /* feature: support for multidimensional arrays  */
+   for (i=0; i<M; i++) {
+     for (j=0; j<N; j++) {
+       example_8_a[i][j] = x;
+     }
+   }
+}
+#endif
+
+#if 0
+example9:
+unsigned int ub[N], uc[N];
+foo () {
+  int i;
+
+  /* feature: support summation reduction.
+     note: in case of floats use -funsafe-math-optimizations  */
+  unsigned int diff = 0;
+  for (i = 0; i < N; i++) {
+    udiff += (ub[i] - uc[i]);
+  }
+example10:
+/* feature: support data-types of different sizes.
+   Currently only a single vector-size per target is supported; 
+   it can accommodate n elements such that n = vector-size/element-size 
+   (e.g, 4 ints, 8 shorts, or 16 chars for a vector of size 16 bytes). 
+   A combination of data-types of different sizes in the same loop 
+   requires special handling. This support is now present in mainline,
+   and also includes support for type conversions.  */
+
+short *sa, *sb, *sc;
+int *ia, *ib, *ic;
+for (i = 0; i < N; i++) {
+  ia[i] = ib[i] + ic[i];
+  sa[i] = sb[i] + sc[i];
+}
+
+for (i = 0; i < N; i++) {
+  ia[i] = (int) sb[i];
+}
+example11:
+/* feature: support strided accesses - the data elements
+   that are to be operated upon in parallel are not consecutive - they
+   are accessed with a stride > 1 (in the example, the stride is 2):  */
+
+for (i = 0; i < N/2; i++){
+  a[i] = b[2*i+1] * c[2*i+1] - b[2*i] * c[2*i];
+  d[i] = b[2*i] * c[2*i+1] + b[2*i+1] * c[2*i];
+}
+example12: induction:
+for (i = 0; i < N; i++) {
+  a[i] = i;
+}
+example13: outer-loop:
+  for (i = 0; i < M; i++) {
+    diff = 0;
+    for (j = 0; j < N; j+=8) {
+      diff += (a[i][j] - b[i][j]);
+    }
+    out[i] = diff;
+  }
+}
+example14: double reduction:
+  for (k = 0; k < K; k++) {
+    sum = 0;
+    for (j = 0; j < M; j++)
+      for (i = 0; i < N; i++)
+          sum += in[i+k][j] * coeff[i][j];
+
+    out[k] = sum;
+  }
+example15: condition in nested loop:
+  for (j = 0; j < M; j++)
+    {
+      x = x_in[j];
+      curr_a = a[0];
+
+      for (i = 0; i < N; i++)
+        {
+          next_a = a[i+1];
+          curr_a = x > c[i] ? curr_a : next_a;
+        }
+
+      x_out[j] = curr_a;
+    }
+example16: load permutation in loop-aware SLP:
+  for (i = 0; i < N; i++)
+    {
+       a = *pInput++;
+       b = *pInput++;
+       c = *pInput++;
+
+       *pOutput++ = M00 * a + M01 * b + M02 * c;
+       *pOutput++ = M10 * a + M11 * b + M12 * c;
+       *pOutput++ = M20 * a + M21 * b + M22 * c;
+    }
+example17: basic block SLP:
+void foo ()
+{
+  unsigned int *pin = &in[0];
+  unsigned int *pout = &out[0];
+
+  *pout++ = *pin++;
+  *pout++ = *pin++;
+  *pout++ = *pin++;
+  *pout++ = *pin++;
+}
+example18: Simple reduction in SLP:
+int sum1;
+int sum2;
+int a[128];
+void foo (void)
+{
+  int i;
+
+  for (i = 0; i < 64; i++)
+    {
+      sum1 += a[2*i];
+      sum2 += a[2*i+1];
+    }
+}
+example19: Reduction chain in SLP:
+int sum;
+int a[128];
+void foo (void)
+{
+  int i;
+
+  for (i = 0; i < 64; i++)
+    {
+      sum += a[2*i];
+      sum += a[2*i+1];
+    }
+}
+example20: Basic block SLP with multiple types, loads with different offsets, misaligned load, and not-affine accesses:
+void foo (int * __restrict__ dst, short * __restrict__ src,
+          int h, int stride, short A, short B)
+{
+  int i;
+  for (i = 0; i < h; i++)
+    {
+      dst[0] += A*src[0] + B*src[1];
+      dst[1] += A*src[1] + B*src[2];
+      dst[2] += A*src[2] + B*src[3];
+      dst[3] += A*src[3] + B*src[4];
+      dst[4] += A*src[4] + B*src[5];
+      dst[5] += A*src[5] + B*src[6];
+      dst[6] += A*src[6] + B*src[7];
+      dst[7] += A*src[7] + B*src[8];
+      dst += stride;
+      src += stride;
+    }
+}
+example21: Backward access:
+int foo (int *b, int n)
+{
+  int i, a = 0;
+
+  for (i = n-1; i ≥ 0; i--)
+    a += b[i];
+
+  return a;
+}
+example22: Alignment hints:
+void foo (int *out1, int *in1, int *in2, int n)
+{
+  int i;
+
+  out1 = __builtin_assume_aligned (out1, 32, 16);
+  in1 = __builtin_assume_aligned (in1, 32, 16);
+  in2 = __builtin_assume_aligned (in2, 32, 0);
+
+  for (i = 0; i < n; i++)
+    out1[i] = in1[i] * in2[i];
+}
+example23: Widening shift:
+void foo (unsigned short *src, unsigned int *dst)
+{
+  int i;
+
+  for (i = 0; i < 256; i++)
+    *dst++ = *src++ << 7;
+}
+example24: Condition with mixed types:
+#define N 1024
+float a[N], b[N];
+int c[N];
+
+void foo (short x, short y)
+{
+  int i;
+  for (i = 0; i < N; i++)
+    c[i] = a[i] < b[i] ? x : y;
+}
+example25: Loop with bool:
+#define N 1024
+float a[N], b[N], c[N], d[N];
+int j[N];
+
+void foo (void)
+{
+  int i;
+  _Bool x, y;
+  for (i = 0; i < N; i++)
+    {
+      x = (a[i] < b[i]);
+      y = (c[i] < d[i]);
+      j[i] = x & y;
+    }
+}
+
+/* Unvectorizable Loops
+   Examples of loops that currently cannot be vectorized: */
+
+example1: uncountable loop:
+while (*p != NULL) {
+  *q++ = *p++;
+}
+#endif
-- 
1.8.5.3

