| 1 |
/* { dg-do compile } */ |
| 2 |
/* { dg-require-effective-target vect_int } */ |
| 3 |
|
| 4 |
|
| 5 |
/* The GCC vectorizer generates loop versioning for the following loop |
| 6 |
since there may exist aliasing between A and B. The predicate checks |
| 7 |
if A may alias with B across all iterations. Then for the loop in |
| 8 |
the true body, we can assert that *B is a loop invariant so that |
| 9 |
we can hoist the load of *B before the loop body. */ |
| 10 |
|
| 11 |
void test1 (int* a, int* b) |
| 12 |
{ |
| 13 |
int i; |
| 14 |
for (i = 0; i < 100000; ++i) |
| 15 |
a[i] = *b + 1; |
| 16 |
} |
| 17 |
|
| 18 |
/* A test case with nested loops. The load of b[j+1] in the inner |
| 19 |
loop should be hoisted. */ |
| 20 |
|
| 21 |
void test2 (int* a, int* b) |
| 22 |
{ |
| 23 |
int i, j; |
| 24 |
for (j = 0; j < 100000; ++j) |
| 25 |
for (i = 0; i < 100000; ++i) |
| 26 |
a[i] = b[j+1] + 1; |
| 27 |
} |
| 28 |
|
| 29 |
/* A test case with ifcvt transformation. */ |
| 30 |
|
| 31 |
void test3 (int* a, int* b) |
| 32 |
{ |
| 33 |
int i, t; |
| 34 |
for (i = 0; i < 10000; ++i) |
| 35 |
{ |
| 36 |
if (*b > 0) |
| 37 |
t = *b * 2; |
| 38 |
else |
| 39 |
t = *b / 2; |
| 40 |
a[i] = t; |
| 41 |
} |
| 42 |
} |
| 43 |
|
| 44 |
/* A test case in which the store in the loop can be moved outside |
| 45 |
in the versioned loop with alias checks. Note this loop won't |
| 46 |
be vectorized. */ |
| 47 |
|
| 48 |
void test4 (int* a, int* b) |
| 49 |
{ |
| 50 |
int i; |
| 51 |
for (i = 0; i < 100000; ++i) |
| 52 |
*a += b[i]; |
| 53 |
} |
| 54 |
|
| 55 |
/* A test case in which the load and store in the loop to b |
| 56 |
can be moved outside in the versioned loop with alias checks. |
| 57 |
Note this loop won't be vectorized. */ |
| 58 |
|
| 59 |
void test5 (int* a, int* b) |
| 60 |
{ |
| 61 |
int i; |
| 62 |
for (i = 0; i < 100000; ++i) |
| 63 |
{ |
| 64 |
*b += a[i]; |
| 65 |
a[i] = *b; |
| 66 |
} |
| 67 |
} |
| 68 |
|
| 69 |
/* { dg-final { scan-tree-dump-times "hoist" 8 "vect" { xfail *-*-* } } } */ |
| 70 |
/* { dg-final { scan-tree-dump-times "hoist" 3 "vect" { xfail { vect_no_align && { ! vect_hw_misalign } } } } } */ |