| 1 |
/* { dg-do run } */ |
| 2 |
/* { dg-require-effective-target store_merge } */ |
| 3 |
/* { dg-options "-O2 -fdump-tree-store-merging" } */ |
| 4 |
|
| 5 |
struct bar |
| 6 |
{ |
| 7 |
int a; |
| 8 |
unsigned char b; |
| 9 |
unsigned char c; |
| 10 |
short d; |
| 11 |
unsigned char e; |
| 12 |
unsigned char f; |
| 13 |
unsigned char g; |
| 14 |
}; |
| 15 |
|
| 16 |
__attribute__ ((noinline)) void |
| 17 |
foozero (struct bar *p) |
| 18 |
{ |
| 19 |
p->b = 0; |
| 20 |
p->a = 0; |
| 21 |
p->c = 0; |
| 22 |
p->d = 0; |
| 23 |
p->e = 0; |
| 24 |
p->f = 0; |
| 25 |
p->g = 0; |
| 26 |
} |
| 27 |
|
| 28 |
__attribute__ ((noinline)) void |
| 29 |
foo1 (struct bar *p) |
| 30 |
{ |
| 31 |
p->b = 1; |
| 32 |
p->a = 2; |
| 33 |
p->c = 3; |
| 34 |
p->d = 4; |
| 35 |
p->e = 5; |
| 36 |
p->f = 0; |
| 37 |
p->g = 0xff; |
| 38 |
} |
| 39 |
|
| 40 |
__attribute__ ((noinline)) void |
| 41 |
foo2 (struct bar *p, struct bar *p2) |
| 42 |
{ |
| 43 |
p->b = 0xff; |
| 44 |
p2->b = 0xa; |
| 45 |
p->a = 0xfffff; |
| 46 |
p2->c = 0xc; |
| 47 |
p->c = 0xff; |
| 48 |
p2->d = 0xbf; |
| 49 |
p->d = 0xfff; |
| 50 |
} |
| 51 |
|
| 52 |
int |
| 53 |
main (void) |
| 54 |
{ |
| 55 |
struct bar b1, b2; |
| 56 |
foozero (&b1); |
| 57 |
foozero (&b2); |
| 58 |
|
| 59 |
foo1 (&b1); |
| 60 |
if (b1.b != 1 || b1.a != 2 || b1.c != 3 || b1.d != 4 || b1.e != 5 |
| 61 |
|| b1.f != 0 || b1.g != 0xff) |
| 62 |
__builtin_abort (); |
| 63 |
|
| 64 |
foozero (&b1); |
| 65 |
/* Make sure writes to aliasing struct pointers preserve the |
| 66 |
correct order. */ |
| 67 |
foo2 (&b1, &b1); |
| 68 |
if (b1.b != 0xa || b1.a != 0xfffff || b1.c != 0xff || b1.d != 0xfff) |
| 69 |
__builtin_abort (); |
| 70 |
|
| 71 |
foozero (&b1); |
| 72 |
foo2 (&b1, &b2); |
| 73 |
if (b1.a != 0xfffff || b1.b != 0xff || b1.c != 0xff || b1.d != 0xfff |
| 74 |
|| b2.b != 0xa || b2.c != 0xc || b2.d != 0xbf) |
| 75 |
__builtin_abort (); |
| 76 |
|
| 77 |
return 0; |
| 78 |
} |
| 79 |
|
| 80 |
/* { dg-final { scan-tree-dump-times "Merging successful" 2 "store-merging" } } */ |