| 1 |
/* { dg-do compile { target { i?86-*-* x86_64-*-* } } } */ |
| 2 |
/* { dg-options "-O2 -fno-tree-vectorize -fprefetch-loop-arrays -march=amdfam10 --param simultaneous-prefetches=100 --param min-insn-to-prefetch-ratio=6 -fdump-tree-aprefetch-details" } */ |
| 3 |
|
| 4 |
#define N 1000 |
| 5 |
#define K 900 |
| 6 |
|
| 7 |
double a[N][N]; |
| 8 |
|
| 9 |
double test(void) |
| 10 |
{ |
| 11 |
unsigned i, j; |
| 12 |
double sum = 0; |
| 13 |
|
| 14 |
/* Here, we should use non-temporal prefetch instruction. */ |
| 15 |
for (i = 0; i < K; i++) |
| 16 |
for (j = 0; j < K; j++) |
| 17 |
sum += a[i][j]; |
| 18 |
|
| 19 |
/* Here, we should not use non-temporal prefetch instruction, since the |
| 20 |
value of a[i+10][j] is reused in L2 cache. */ |
| 21 |
for (i = 0; i < K; i++) |
| 22 |
for (j = 0; j < K; j++) |
| 23 |
sum += a[i][j] * a[i + 10][j]; |
| 24 |
|
| 25 |
/* Here, we should use non-temporal prefetch instruction, since the |
| 26 |
value of a[i+100][j] is too far to be reused in L2 cache. */ |
| 27 |
for (i = 0; i < K; i++) |
| 28 |
for (j = 0; j < K; j++) |
| 29 |
sum += a[i][j] * a[i + 100][j]; |
| 30 |
|
| 31 |
/* Here, temporal prefetches should be used, since the volume of the |
| 32 |
memory accesses is smaller than L2 cache. */ |
| 33 |
for (i = 0; i < 100; i++) |
| 34 |
for (j = 0; j < 100; j++) |
| 35 |
sum += a[i][j] * a[i + 100][j]; |
| 36 |
|
| 37 |
/* Temporal prefetches should be used here (even though the accesses to |
| 38 |
a[j][i] are independent, the same cache line is almost always hit |
| 39 |
every N iterations). */ |
| 40 |
for (i = 0; i < N; i++) |
| 41 |
for (j = 0; j < N; j++) |
| 42 |
sum += a[j][i]; |
| 43 |
|
| 44 |
return sum; |
| 45 |
} |
| 46 |
|
| 47 |
/* { dg-final { scan-tree-dump-times "Issued prefetch" 5 "aprefetch" } } */ |
| 48 |
/* { dg-final { scan-tree-dump-times "Issued nontemporal prefetch" 3 "aprefetch" } } */ |