File: store_merging_2.c

package info (click to toggle)
gcc-riscv64-unknown-elf 8.3.0.2019.08%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 680,956 kB
  • sloc: ansic: 3,237,715; cpp: 896,882; ada: 772,854; f90: 144,254; asm: 68,788; makefile: 67,456; sh: 29,743; exp: 28,045; objc: 15,273; fortran: 11,885; python: 7,369; pascal: 5,375; awk: 3,725; perl: 2,872; yacc: 316; xml: 311; ml: 285; lex: 198; haskell: 122
file content (80 lines) | stat: -rw-r--r-- 1,449 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/* { dg-do run } */
/* { dg-require-effective-target store_merge } */
/* { dg-options "-O2 -fdump-tree-store-merging" } */

struct bar
{
  int a;
  unsigned char b;
  unsigned char c;
  short d;
  unsigned char e;
  unsigned char f;
  unsigned char g;
};

__attribute__ ((noinline)) void
foozero (struct bar *p)
{
  p->b = 0;
  p->a = 0;
  p->c = 0;
  p->d = 0;
  p->e = 0;
  p->f = 0;
  p->g = 0;
}

__attribute__ ((noinline)) void
foo1 (struct bar *p)
{
  p->b = 1;
  p->a = 2;
  p->c = 3;
  p->d = 4;
  p->e = 5;
  p->f = 0;
  p->g = 0xff;
}

__attribute__ ((noinline)) void
foo2 (struct bar *p, struct bar *p2)
{
  p->b = 0xff;
  p2->b = 0xa;
  p->a = 0xfffff;
  p2->c = 0xc;
  p->c = 0xff;
  p2->d = 0xbf;
  p->d = 0xfff;
}

int
main (void)
{
  struct bar b1, b2;
  foozero (&b1);
  foozero (&b2);

  foo1 (&b1);
  if (b1.b != 1 || b1.a != 2 || b1.c != 3 || b1.d != 4 || b1.e != 5
      || b1.f != 0 || b1.g != 0xff)
    __builtin_abort ();

  foozero (&b1);
  /* Make sure writes to aliasing struct pointers preserve the
     correct order.  */
  foo2 (&b1, &b1);
  if (b1.b != 0xa || b1.a != 0xfffff || b1.c != 0xff || b1.d != 0xfff)
    __builtin_abort ();

  foozero (&b1);
  foo2 (&b1, &b2);
  if (b1.a != 0xfffff || b1.b != 0xff || b1.c != 0xff || b1.d != 0xfff
      || b2.b != 0xa || b2.c != 0xc || b2.d != 0xbf)
    __builtin_abort ();

  return 0;
}

/* { dg-final { scan-tree-dump-times "Merging successful" 2 "store-merging" } } */