PR tree-optimization/81303
[official-gcc.git] / gcc / testsuite / gcc.dg / tree-ssa / loadpre6.c
blob22248910086c3a795f272d0f001b5090e1eb43f7
1 /* { dg-do compile { target nonpic } } */
2 /* { dg-options "-O2 -fdump-tree-pre-stats -fdump-tree-fre1" } */
3 #include <stddef.h>
5 union tree_node;
6 typedef union tree_node *tree;
8 struct tree_common
10 tree chain;
13 struct tree_list
15 struct tree_common common;
16 tree value;
19 union tree_node
22 struct tree_common common;
23 struct tree_list list;
26 extern void abort (void) __attribute__((noreturn));
28 void __attribute__((noinline))
29 foo (void)
31 abort ();
34 /* There are some reloaded loads of *cell, and cell->common.chain on various
35 branches. */
36 void __attribute__((noinline))
37 remove_useless_vars (tree *unexpanded_var_list, int dump_file)
39 tree var, *cell;
40 int c = 0;
41 for (cell = unexpanded_var_list; *cell; )
43 var = (*cell)->list.value;
44 if (var)
46 if (dump_file)
47 foo ();
49 *cell = ((*cell)->common.chain);
50 continue;
53 cell = &((*cell)->common.chain);
56 extern void *malloc (__SIZE_TYPE__) __attribute__ ((malloc));
58 int
59 main (void)
61 int i;
62 tree unexpanded_var_list, last = (tree) 0;
64 for (i = 0; i < 2; i++)
66 unexpanded_var_list = malloc (sizeof (struct tree_list));
67 unexpanded_var_list->list.value = (tree) (ptrdiff_t) (i & 1);
68 unexpanded_var_list->common.chain = last;
69 last = unexpanded_var_list;
72 remove_useless_vars (&unexpanded_var_list, 0);
73 return 0;
76 /* { dg-final { scan-tree-dump-not "= unexpanded_var_list;" "fre1" } } */
77 /* { dg-final { scan-tree-dump-times "Eliminated: 1" 1 "pre" } } */
78 /* { dg-final { scan-tree-dump-times "Insertions: 2" 1 "pre" } } */