| 1 |
/* { dg-do run { target lp64 } } */ |
| 2 |
/* This is a test exercising peeling for alignment for a positive step |
| 3 |
vector loop. We're forcing atom tuning here because that has a higher |
| 4 |
unaligned vs aligned cost unlike most other archs. */ |
| 5 |
/* { dg-options "-O3 -march=x86-64 -mtune=atom -fdump-tree-vect-details -save-temps" } */ |
| 6 |
|
| 7 |
float a[1024], b[1024]; |
| 8 |
|
| 9 |
void __attribute__((noipa)) foo1 () |
| 10 |
{ |
| 11 |
for (int i = 2; i < 508; ++i) |
| 12 |
a[i] = b[i] * 2.; |
| 13 |
} |
| 14 |
void __attribute__((noipa)) foo2 () |
| 15 |
{ |
| 16 |
for (int i = 3; i < 508; ++i) |
| 17 |
a[i] = b[i] * 2.; |
| 18 |
} |
| 19 |
void __attribute__((noipa)) foo3 () |
| 20 |
{ |
| 21 |
for (int i = 4; i < 508; ++i) |
| 22 |
a[i] = b[i] * 2.; |
| 23 |
} |
| 24 |
void __attribute__((noipa)) foo4 () |
| 25 |
{ |
| 26 |
for (int i = 5; i < 508; ++i) |
| 27 |
a[i] = b[i] * 2.; |
| 28 |
} |
| 29 |
void __attribute__((noipa)) foo5 (int start) |
| 30 |
{ |
| 31 |
for (int i = start; i < 508; ++i) |
| 32 |
a[i] = b[i] * 2.; |
| 33 |
} |
| 34 |
|
| 35 |
int main() |
| 36 |
{ |
| 37 |
for (int i = 2; i < 508; ++i) |
| 38 |
{ |
| 39 |
__asm__ volatile ("" : : : "memory"); |
| 40 |
b[i] = i; |
| 41 |
} |
| 42 |
foo1 (); |
| 43 |
#pragma GCC novector |
| 44 |
for (int i = 2; i < 508; ++i) |
| 45 |
if (a[i] != 2*i) |
| 46 |
__builtin_abort (); |
| 47 |
|
| 48 |
for (int i = 3; i < 508; ++i) |
| 49 |
{ |
| 50 |
__asm__ volatile ("" : : : "memory"); |
| 51 |
b[i] = i; |
| 52 |
} |
| 53 |
foo2 (); |
| 54 |
#pragma GCC novector |
| 55 |
for (int i = 3; i < 508; ++i) |
| 56 |
if (a[i] != 2*i) |
| 57 |
__builtin_abort (); |
| 58 |
|
| 59 |
for (int i = 4; i < 508; ++i) |
| 60 |
{ |
| 61 |
__asm__ volatile ("" : : : "memory"); |
| 62 |
b[i] = i; |
| 63 |
} |
| 64 |
foo3 (); |
| 65 |
#pragma GCC novector |
| 66 |
for (int i = 4; i < 508; ++i) |
| 67 |
if (a[i] != 2*i) |
| 68 |
__builtin_abort (); |
| 69 |
|
| 70 |
for (int i = 5; i < 508; ++i) |
| 71 |
{ |
| 72 |
__asm__ volatile ("" : : : "memory"); |
| 73 |
b[i] = i; |
| 74 |
} |
| 75 |
foo4 (); |
| 76 |
#pragma GCC novector |
| 77 |
for (int i = 5; i < 508; ++i) |
| 78 |
if (a[i] != 2*i) |
| 79 |
__builtin_abort (); |
| 80 |
|
| 81 |
for (int i = 3; i < 508; ++i) |
| 82 |
{ |
| 83 |
__asm__ volatile ("" : : : "memory"); |
| 84 |
b[i] = i; |
| 85 |
} |
| 86 |
foo5 (3); |
| 87 |
#pragma GCC novector |
| 88 |
for (int i = 3; i < 508; ++i) |
| 89 |
if (a[i] != 2*i) |
| 90 |
__builtin_abort (); |
| 91 |
} |
| 92 |
|
| 93 |
/* { dg-final { scan-tree-dump-times "Alignment of access forced using peeling" 4 "vect" } } */ |
| 94 |
/* Verify all vector accesses are emitted as aligned. */ |
| 95 |
/* { dg-final { scan-assembler-not "movup" } } */ |