summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.dg/vect/pr65947-5.c
blob: 709f17f80a46f442446017d5433dc7069258253d (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
/* { dg-require-effective-target vect_condition } */

#include "tree-vect.h"

extern void abort (void) __attribute__ ((noreturn));

#if VECTOR_BITS > 256
#define N (VECTOR_BITS / 8)
#else
#define N 32
#endif

/* Condition reduction where loop size is not known at compile time.  Will fail
   to vectorize.  Version inlined into main loop will vectorize.  */

unsigned char
condition_reduction (unsigned char *a, unsigned char min_v, int count)
{
  unsigned char last = 65;

  for (int i = 0; i < count; i++)
    if (a[i] < min_v)
      last = a[i];

  return last;
}

int
main (void)
{
  unsigned char a[N] = {
  11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
  1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
  21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
  31, 32
  };
  for (int i = 32; i < N; ++i)
    {
      a[i] = 70 + (i & 3);
      asm volatile ("" ::: "memory");
    }

  check_vect ();

  unsigned char ret = condition_reduction (a, 16, N);

  if (ret != 10)
    abort ();

  return 0;
}

/* { dg-final { scan-tree-dump-times "LOOP VECTORIZED" 1 "vect" { target { ! vect_last_reduc } } } } */
/* { dg-final { scan-tree-dump-times "LOOP VECTORIZED" 2 "vect" { target vect_last_reduc } } } */
/* { dg-final { scan-tree-dump "loop size is greater than data size" "vect" { xfail vect_last_reduc } } } */
/* { dg-final { scan-tree-dump-times "Optimizing condition reduction with CLASTB" 4 "vect" { target vect_last_reduc } } } */
/* { dg-final { scan-tree-dump-not "Optimizing condition reduction" "vect" { target { ! vect_last_reduc } } } } */