Debian Codegraph @

gcc/testsuite/gcc.dg/tree-ssa/pr110539-4.c

raw
1 /* { dg-do compile } */
2 /* { dg-options "-O1 -fstrict-aliasing -fdump-tree-optimized" } */
3
4 /* This is a small variant of pr110539-3.c using -O1 -fstrict-aliasing
5 rather than -O2. Just to show VRP and PRE is not needed to optimize
6 the call to foo away. */
7
8
9 void foo(void);
10 static int a, c = 1;
11 static short b;
12 static int *d = &c, *e = &a;
13 static int **f = &d;
14 void __assert_fail() __attribute__((__noreturn__));
15 static void g(int h) {
16 if (*d)
17 ;
18 else {
19 if (e) __assert_fail();
20 if (a) {
21 __builtin_unreachable();
22 } else
23 __assert_fail();
24 }
25 if (((h!=0) == h) + b) *f = 0;
26 }
27
28 int main() {
29 int i = 0 != 10 & a;
30 g(i);
31 *e = 9;
32 e = 0;
33 if (d == 0)
34 ;
35 else
36 foo();
37 ;
38 }
39
40 /* The call to foo should be optimized away. */
41 /* The missed optimization at -O1 here was:
42 int b = a & 1;
43 int c = b != 0;
44 int d = c == b;
45 not being optimized to 1 early enough, it is done in vrp2 but
46 that is too late.
47 In phiopt2 we got:
48 _17 = i_7 != 0;
49 _12 = (int) _17;
50 if (i_7 == _12)
51 goto <bb 9>; [50.00%]
52 else
53 goto <bb 10>; [50.00%]
54
55 <bb 9> [local count: 268435456]:
56 d = 0B;
57
58 <bb 10> [local count: 536870913]:
59 e.1_3 = e;
60 *e.1_3 = 9;
61 e = 0B;
62 d.2_4 = d;
63 if (d.2_4 == 0B)
64
65 The first if is not optimized before, until vrp2 which is
66 too late as there are no passes which will then find the
67 load of d in `d.2_4 = d;` was `0B` after vrp2.
68
69 Now in forwprop3 (after phiopt2), we optimize:
70 _17 = i_7 != 0;
71 _12 = (int) _17;
72 if (i_7 == _12)
73 into just:
74 _t = (unsigned)i_7;
75 if (_t <= 1)
76
77 And then during ccp3, that is optimized away and that is optimized
78 early enough now that the load `d.2_4 = d;` is optimizd to just
79 `d.2_4 = 0B;`
80 */
81
82 /* { dg-final { scan-tree-dump-not "foo \\(\\)" "optimized"} } */