| 1 |
/* { dg-add-options vect_early_break } */ |
| 2 |
/* { dg-require-effective-target vect_early_break_hw } */ |
| 3 |
/* { dg-require-effective-target vect_long_long } */ |
| 4 |
/* { dg-additional-options "-mtune=generic-ooo" { target riscv*-*-* } } */ |
| 5 |
|
| 6 |
/* { dg-final { scan-tree-dump "LOOP VECTORIZED" "vect" } } */ |
| 7 |
|
| 8 |
#include "tree-vect.h" |
| 9 |
|
| 10 |
typedef unsigned long PV; |
| 11 |
typedef struct _buff_t { |
| 12 |
int foo; |
| 13 |
PV Val; |
| 14 |
} buff_t; |
| 15 |
|
| 16 |
#define NUM 9 |
| 17 |
#define SZ NUM * sizeof (PV) |
| 18 |
char buffer[SZ]; |
| 19 |
|
| 20 |
__attribute__ ((noipa)) |
| 21 |
buff_t *copy (buff_t *first, buff_t *last) |
| 22 |
{ |
| 23 |
char *buffer_ptr = buffer; |
| 24 |
char *const buffer_end = &buffer[SZ-1]; |
| 25 |
int store_size = sizeof(first->Val); |
| 26 |
while (first != last && (buffer_ptr + store_size) <= buffer_end) |
| 27 |
{ |
| 28 |
const char *value_data = (const char *)(&first->Val); |
| 29 |
__builtin_memcpy(buffer_ptr, value_data, store_size); |
| 30 |
buffer_ptr += store_size; |
| 31 |
++first; |
| 32 |
} |
| 33 |
|
| 34 |
if (first == last) |
| 35 |
return 0; |
| 36 |
|
| 37 |
return first; |
| 38 |
} |
| 39 |
|
| 40 |
int main () |
| 41 |
{ |
| 42 |
|
| 43 |
check_vect (); |
| 44 |
|
| 45 |
/* Copy an ascii buffer. We need to trigger the loop to exit from |
| 46 |
the condition where we have more data to copy but not enough space. |
| 47 |
For this test that means that OVL must be > SZ. */ |
| 48 |
#define OVL NUM*2 |
| 49 |
char str[OVL]="abcdefghiabcdefgh\0"; |
| 50 |
buff_t tmp[OVL]; |
| 51 |
|
| 52 |
#pragma GCC novector |
| 53 |
for (int i = 0; i < OVL; i++) |
| 54 |
tmp[i].Val = str[i]; |
| 55 |
|
| 56 |
buff_t *start = &tmp[0]; |
| 57 |
buff_t *last = &tmp[OVL-1]; |
| 58 |
buff_t *res = 0; |
| 59 |
|
| 60 |
/* This copy should exit on the early exit, in which case we know |
| 61 |
that start != last as we had more data to copy but the buffer |
| 62 |
was full. */ |
| 63 |
if (!(res = copy (start, last))) |
| 64 |
__builtin_abort (); |
| 65 |
|
| 66 |
/* Check if we have the right reduction value. */ |
| 67 |
if (res != &tmp[NUM-1]) |
| 68 |
__builtin_abort (); |
| 69 |
|
| 70 |
int store_size = sizeof(PV); |
| 71 |
#pragma GCC novector |
| 72 |
for (int i = 0; i < NUM - 1; i++) |
| 73 |
if (0 != __builtin_memcmp (buffer+(i*store_size), (char*)&tmp[i].Val, store_size)) |
| 74 |
__builtin_abort (); |
| 75 |
|
| 76 |
return 0; |
| 77 |
} |