| 1 |
/* { dg-options "-O3 -fdump-tree-lversion-details" } */ |
| 2 |
|
| 3 |
/* Test that we can version a gather-like operation in which a variable |
| 4 |
stride is applied to the index. */ |
| 5 |
|
| 6 |
int |
| 7 |
f1 (int *x, int *index, int step, int n) |
| 8 |
{ |
| 9 |
int res = 0; |
| 10 |
for (int i = 0; i < n; ++i) |
| 11 |
res += x[index[i] * step]; |
| 12 |
return res; |
| 13 |
} |
| 14 |
|
| 15 |
int |
| 16 |
f2 (int *x, int *index, int step, int n) |
| 17 |
{ |
| 18 |
int res = 0; |
| 19 |
for (int i = 0; i < n; ++i) |
| 20 |
{ |
| 21 |
int *ptr = x + index[i] * step; |
| 22 |
res += *ptr; |
| 23 |
} |
| 24 |
return res; |
| 25 |
} |
| 26 |
|
| 27 |
int x[1000]; |
| 28 |
|
| 29 |
int |
| 30 |
g1 (int *index, int step, int n) |
| 31 |
{ |
| 32 |
int res = 0; |
| 33 |
for (int i = 0; i < n; ++i) |
| 34 |
res += x[index[i] * step]; |
| 35 |
return res; |
| 36 |
} |
| 37 |
|
| 38 |
int |
| 39 |
g2 (int *index, int step, int n) |
| 40 |
{ |
| 41 |
int res = 0; |
| 42 |
for (int i = 0; i < n; ++i) |
| 43 |
{ |
| 44 |
int *ptr = x + index[i] * step; |
| 45 |
res += *ptr; |
| 46 |
} |
| 47 |
return res; |
| 48 |
} |
| 49 |
|
| 50 |
/* { dg-final { scan-tree-dump-times {address term [^\n]* \* loop-invariant} 4 "lversion" } } */ |
| 51 |
/* { dg-final { scan-tree-dump-times {want to version containing loop} 4 "lversion" } } */ |
| 52 |
/* { dg-final { scan-tree-dump-times {versioned this loop} 4 "lversion" } } */ |