| 1 |
/* { dg-require-effective-target vect_int } */ |
| 2 |
/* { dg-require-effective-target vect_shift } */ |
| 3 |
/* { dg-require-effective-target vect_pack_trunc } */ |
| 4 |
/* { dg-require-effective-target vect_unpack } */ |
| 5 |
|
| 6 |
#include "tree-vect.h" |
| 7 |
|
| 8 |
#ifndef SIGNEDNESS |
| 9 |
#define SIGNEDNESS signed |
| 10 |
#define BASE_B -128 |
| 11 |
#define BASE_C -100 |
| 12 |
#endif |
| 13 |
|
| 14 |
#define N 50 |
| 15 |
|
| 16 |
/* Both range analysis and backward propagation from the truncation show |
| 17 |
that these calculations can be done in SIGNEDNESS short. */ |
| 18 |
void __attribute__ ((noipa)) |
| 19 |
f (SIGNEDNESS char *restrict a, SIGNEDNESS char *restrict b, |
| 20 |
SIGNEDNESS char *restrict c) |
| 21 |
{ |
| 22 |
/* Deliberate use of signed >>. */ |
| 23 |
for (int i = 0; i < N; ++i) |
| 24 |
a[i] = (b[i] + c[i]) >> 1; |
| 25 |
} |
| 26 |
|
| 27 |
int |
| 28 |
main (void) |
| 29 |
{ |
| 30 |
check_vect (); |
| 31 |
|
| 32 |
SIGNEDNESS char a[N], b[N], c[N]; |
| 33 |
for (int i = 0; i < N; ++i) |
| 34 |
{ |
| 35 |
b[i] = BASE_B + i * 5; |
| 36 |
c[i] = BASE_C + i * 4; |
| 37 |
asm volatile ("" ::: "memory"); |
| 38 |
} |
| 39 |
f (a, b, c); |
| 40 |
#pragma GCC novector |
| 41 |
for (int i = 0; i < N; ++i) |
| 42 |
if (a[i] != (BASE_B + BASE_C + i * 9) >> 1) |
| 43 |
__builtin_abort (); |
| 44 |
|
| 45 |
return 0; |
| 46 |
} |
| 47 |
|
| 48 |
/* { dg-final { scan-tree-dump {Splitting statement} "vect" } } */ |
| 49 |
/* { dg-final { scan-tree-dump {vect_recog_over_widening_pattern: detected:[^\n]* \+ } "vect" } } */ |
| 50 |
/* { dg-final { scan-tree-dump {vect_recog_over_widening_pattern: detected:[^\n]* >> 1} "vect" } } */ |
| 51 |
/* { dg-final { scan-tree-dump {vect_recog_cast_forwprop_pattern: detected:[^\n]* \(signed char\)} "vect" } } */ |
| 52 |
/* { dg-final { scan-tree-dump-not {vector[^ ]* int} "vect" } } */ |
| 53 |
/* { dg-final { scan-tree-dump-times "vectorized 1 loop" 1 "vect" } } */ |