Debian Codegraph @

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

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