Debian Codegraph @

gcc/testsuite/gcc.dg/tree-ssa/sra-13.c

raw
1 /* Test that SRA replacement can deal with assignments that have
2 sub-replacements on one side and a single scalar replacement on another. */
3 /* { dg-do run } */
4 /* { dg-options "-O1" } */
5
6 struct A
7 {
8 int i1, i2;
9 };
10
11 struct B
12 {
13 long long int l;
14 };
15
16 union U
17 {
18 struct A a;
19 struct B b;
20 };
21
22 int b, gi;
23 long gl;
24 union U gu1, gu2;
25
26 int __attribute__ ((noinline, noclone))
27 foo (void)
28 {
29 union U x, y;
30 int r;
31
32 y = gu1;
33 if (b)
34 y.b.l = gl;
35
36 x = y;
37
38 if (!b)
39 r = x.a.i1;
40 else
41 r = 0;
42
43 gu2 = x;
44 return r;
45 }
46
47 long long int __attribute__ ((noinline, noclone))
48 bar (void)
49 {
50 union U x, y;
51 int r;
52
53 y = gu1;
54 if (b)
55 y.a.i1 = gi;
56
57 x = y;
58
59 if (!b)
60 r = x.b.l;
61 else
62 r = 0;
63
64 gu2 = x;
65 return r;
66 }
67
68
69 int
70 main (void)
71 {
72 int r;
73 long long int s;
74
75 b = 0;
76 gu1.a.i1 = 123;
77 gu1.a.i2 = 234;
78 r = foo ();
79 if (r != 123)
80 __builtin_abort ();
81 if (gu2.a.i1 != 123)
82 __builtin_abort ();
83 if (gu2.a.i2 != 234)
84 __builtin_abort ();
85
86 b = 1;
87 gl = 10000001;
88 gu1.b.l = 10000000;
89 r = foo ();
90 if (r != 0)
91 __builtin_abort ();
92 if (gu2.b.l != 10000001)
93 __builtin_abort ();
94
95 b = 0;
96 gu1.b.l = 20000000;
97 s = bar ();
98 if (s != (int)20000000)
99 __builtin_abort ();
100 if (gu2.b.l != 20000000)
101 __builtin_abort ();
102
103 b = 1;
104 gi = 456;
105 gu1.a.i1 = 123;
106 gu1.a.i2 = 234;
107 s = bar ();
108 if (s != 0)
109 __builtin_abort ();
110 if (gu2.a.i1 != 456)
111 __builtin_abort ();
112
113 return 0;
114 }