summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.dg/store_merging_14.c
blob: 49af24951cb6a435297c26ca29d43877d6cece8f (plain)
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/* { dg-do compile } */
/* { dg-require-effective-target store_merge } */
/* { dg-options "-O2 -fdump-tree-store-merging" } */

struct S { unsigned int i : 8, a : 7, b : 7, j : 10, c : 15, d : 7, e : 10, f : 7, g : 9, k : 16; unsigned long long h; };

__attribute__((noipa)) void
f1 (struct S *p)
{
  p->a = 1;
  p->b = 2;
  p->c = 3;
  p->d = 4;
  p->e = 5;
  p->f = 6;
  p->g = 7;
}

__attribute__((noipa)) void
f2 (struct S *__restrict p, struct S *__restrict q)
{
  p->a = q->a;
  p->b = q->b;
  p->c = q->c;
  p->d = q->d;
  p->e = q->e;
  p->f = q->f;
  p->g = q->g;
}

__attribute__((noipa)) void
f3 (struct S *p, struct S *q)
{
  unsigned char pa = q->a;
  unsigned char pb = q->b;
  unsigned short pc = q->c;
  unsigned char pd = q->d;
  unsigned short pe = q->e;
  unsigned char pf = q->f;
  unsigned short pg = q->g;
  p->a = pa;
  p->b = pb;
  p->c = pc;
  p->d = pd;
  p->e = pe;
  p->f = pf;
  p->g = pg;
}

__attribute__((noipa)) void
f4 (struct S *p, struct S *q)
{
  unsigned char pa = p->a | q->a;
  unsigned char pb = p->b | q->b;
  unsigned short pc = p->c | q->c;
  unsigned char pd = p->d | q->d;
  unsigned short pe = p->e | q->e;
  unsigned char pf = p->f | q->f;
  unsigned short pg = p->g | q->g;
  p->a = pa;
  p->b = pb;
  p->c = pc;
  p->d = pd;
  p->e = pe;
  p->f = pf;
  p->g = pg;
}

__attribute__((noipa)) void
f5 (struct S *p, struct S *q)
{
  unsigned char pa = p->a & q->a;
  unsigned char pb = p->b & q->b;
  unsigned short pc = p->c & q->c;
  unsigned char pd = p->d & q->d;
  unsigned short pe = p->e & q->e;
  unsigned char pf = p->f & q->f;
  unsigned short pg = p->g & q->g;
  p->a = pa;
  p->b = pb;
  p->c = pc;
  p->d = pd;
  p->e = pe;
  p->f = pf;
  p->g = pg;
}

__attribute__((noipa)) void
f6 (struct S *p, struct S *q)
{
  unsigned char pa = p->a ^ q->a;
  unsigned char pb = p->b ^ q->b;
  unsigned short pc = p->c ^ q->c;
  unsigned char pd = p->d ^ q->d;
  unsigned short pe = p->e ^ q->e;
  unsigned char pf = p->f ^ q->f;
  unsigned short pg = p->g ^ q->g;
  p->a = pa;
  p->b = pb;
  p->c = pc;
  p->d = pd;
  p->e = pe;
  p->f = pf;
  p->g = pg;
}

struct S s = { 72, 20, 21, 73, 22, 23, 24, 25, 26, 74, 27 };
struct S t = { 75, 0x71, 0x72, 76, 0x7f04, 0x78, 0x31, 0x32, 0x34, 77, 0xf1f2f3f4f5f6f7f8ULL };
struct S u = { 78, 28, 29, 79, 30, 31, 32, 33, 34, 80, 35 };
struct S v = { 81, 36, 37, 82, 38, 39, 40, 41, 42, 83, 43 };

int
main ()
{
  asm volatile ("" : : : "memory");
  f1 (&s);
  asm volatile ("" : : : "memory");
  if (s.i != 72 || s.a != 1 || s.b != 2 || s.j != 73 || s.c != 3 || s.d != 4
      || s.e != 5 || s.f != 6 || s.g != 7 || s.k != 74 || s.h != 27)
    __builtin_abort ();
  f2 (&s, &u);
  asm volatile ("" : : : "memory");
  if (s.i != 72 || s.a != 28 || s.b != 29 || s.j != 73 || s.c != 30 || s.d != 31
      || s.e != 32 || s.f != 33 || s.g != 34 || s.k != 74 || s.h != 27)
    __builtin_abort ();
  f3 (&s, &v);
  asm volatile ("" : : : "memory");
  if (s.i != 72 || s.a != 36 || s.b != 37 || s.j != 73 || s.c != 38 || s.d != 39
      || s.e != 40 || s.f != 41 || s.g != 42 || s.k != 74 || s.h != 27)
    __builtin_abort ();
  f4 (&s, &t);
  asm volatile ("" : : : "memory");
  if (s.i != 72 || s.a != (36 | 0x71) || s.b != (37 | 0x72) || s.j != 73
      || s.c != (38 | 0x7f04) || s.d != (39 | 0x78)
      || s.e != (40 | 0x31) || s.f != (41 | 0x32)
      || s.g != (42 | 0x34) || s.k != 74 || s.h != 27)
    __builtin_abort ();
  f3 (&s, &u);
  f5 (&s, &t);
  asm volatile ("" : : : "memory");
  if (s.i != 72 || s.a != (28 & 0x71) || s.b != (29 & 0x72) || s.j != 73
      || s.c != (30 & 0x7f04) || s.d != (31 & 0x78)
      || s.e != (32 & 0x31) || s.f != (33 & 0x32)
      || s.g != (34 & 0x34) || s.k != 74 || s.h != 27)
    __builtin_abort ();
  f2 (&s, &v);
  f6 (&s, &t);
  asm volatile ("" : : : "memory");
  if (s.i != 72 || s.a != (36 ^ 0x71) || s.b != (37 ^ 0x72) || s.j != 73
      || s.c != (38 ^ 0x7f04) || s.d != (39 ^ 0x78)
      || s.e != (40 ^ 0x31) || s.f != (41 ^ 0x32)
      || s.g != (42 ^ 0x34) || s.k != 74 || s.h != 27)
    __builtin_abort ();
  return 0;
}

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