This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Bugs in SSA-CCP and SSA-PRE optimizers
- From: Steven Bosscher <s dot bosscher at student dot tudelft dot nl>
- To: Daniel Berlin <dberlin at dberlin dot org>
- Cc: gcc at gcc dot gnu dot org
- Date: 17 Sep 2002 21:58:15 +0200
- Subject: Bugs in SSA-CCP and SSA-PRE optimizers
Hello,
Consider:
int main()
{
int bla, foo, bar;
bla = 1;
foo = 2*bla;
bar = 2*bla+1;
goto waffle;
return bar;
waffle:
bla = 1;
return bar;
}
Obviously quite simple to do CCP and PRE on (and DCE but that's not in
CVS yet).
So I tried to compile it and see what the optimized tree looks like. I
applied a patch to dump the optimized tree after the SSA optimizations
are done.
Compiler is this mornings tree-ssa-branch.
Left hand side is: gcc -fdump-tree-all-ssa t.c
Right hand side is:
gcc -fdump-tree-all-ssa -ftree-ssa -ftree-ssa-pre -ftree-ssa-ccp t.c
diff -y 1/t.c.t10.optimized 3/t.c.t10.optimized
main() main()
{ {
int bla; int bla;
int foo; int foo;
int bar; int bar;
int T.1; int T.1;
> int pretmp.2;
bla = 1; bla = 1;
foo = bla * 2; | foo = pretmp.2 = 1 * 2;
T.1 = bla * 2; | T.1 = pretmp.2;
bar = T.1 + 1; bar = T.1 + 1;
goto waffle; goto waffle;
return bar; return bar;
waffle: waffle:
bla = 1; bla = 1;
return bar; return bar;
} }
Note the redundant assignment to T.1. It seems PRE doesn't kill those
T.[0-9*] variables (both uses and it declarations). We're generating (a
lot of?) useless RTL here.
Also, why is "foo = pretmp.2 = 1 * 2" not folded?
Greetz
Steven
Index: c-decl.c
===================================================================
RCS file: /cvsroot/gcc/gcc/gcc/c-decl.c,v
retrieving revision 1.334.2.11
diff -c -r1.334.2.11 c-decl.c
*** c-decl.c 26 Aug 2002 01:34:49 -0000 1.334.2.11
--- c-decl.c 16 Sep 2002 23:40:20 -0000
***************
*** 6520,6525 ****
--- 6520,6528 ----
if (!flag_disable_simple
&& simplify_function_tree (fndecl))
{
+ FILE *dump_file;
+ int dump_flags;
+
if (flag_mudflap)
{
mudflap_c_function (fndecl);
***************
*** 6531,6536 ****
--- 6534,6559 ----
/* Invoke the SSA tree optimizer. */
if (flag_tree_ssa)
optimize_function_tree (fndecl);
+
+ /* Debugging dump after optimization. */
+ dump_file = dump_begin (TDI_optimized, &dump_flags);
+ if (dump_file)
+ {
+ tree fnbody;
+
+ /* We never get here if the function body is empty,
+ see simplify_function_tree(). */
+ fnbody = COMPOUND_BODY (DECL_SAVED_TREE (fndecl));
+ fprintf (dump_file, "%s()\n", IDENTIFIER_POINTER (DECL_NAME (fndecl)));
+
+ if (dump_flags & TDF_RAW)
+ dump_node (fnbody, TDF_SLIM | dump_flags, dump_file);
+ else
+ print_c_tree (dump_file, fnbody);
+ fprintf (dump_file, "\n");
+
+ dump_end (TDI_optimized, dump_file);
+ }
}
/* Set up parameters and prepare for return, for the function. */