This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Fix execute_update_addresses_taken for loop closed SSA form (PR tree-optimization/48739)


Hi!

If some variable is optimized from TREE_ADDRESSABLE into a gimple var
during execute_update_addresses_taken while in loop closed SSA form,
it might not be rewritten into loop closed SSA form, thus either fail
verification, or following loop passes might miscompile something.

Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux,
ok for trunk/4.6?

2011-08-19  Jakub Jelinek  <jakub@redhat.com>

	PR tree-optimization/48739
	* tree-ssa.c: Include cfgloop.h.
	(execute_update_addresses_taken): When updating ssa, if in
	loop closed SSA form, call rewrite_into_loop_closed_ssa instead of
	update_ssa.
	* Makefile.in (tree-ssa.o): Depend on $(CFGLOOP_H).

	* gcc.dg/pr48739-1.c: New test.
	* gcc.dg/pr48739-2.c: New test.

--- gcc/tree-ssa.c.jj	2011-08-18 08:36:00.000000000 +0200
+++ gcc/tree-ssa.c	2011-08-19 18:51:18.000000000 +0200
@@ -43,6 +43,7 @@ along with GCC; see the file COPYING3.  
 #include "tree-dump.h"
 #include "tree-pass.h"
 #include "diagnostic-core.h"
+#include "cfgloop.h"
 
 /* Pointer map of variable mappings, keyed by edge.  */
 static struct pointer_map_t *edge_var_maps;
@@ -2208,7 +2209,10 @@ execute_update_addresses_taken (void)
 	  }
 
       /* Update SSA form here, we are called as non-pass as well.  */
-      update_ssa (TODO_update_ssa);
+      if (number_of_loops () > 1 && loops_state_satisfies_p (LOOP_CLOSED_SSA))
+	rewrite_into_loop_closed_ssa (NULL, TODO_update_ssa);
+      else
+	update_ssa (TODO_update_ssa);
     }
 
   BITMAP_FREE (not_reg_needs);
--- gcc/Makefile.in.jj	2011-08-18 08:36:01.000000000 +0200
+++ gcc/Makefile.in	2011-08-19 18:55:17.000000000 +0200
@@ -2405,7 +2405,7 @@ tree-ssa.o : tree-ssa.c $(TREE_FLOW_H) $
    $(TREE_DUMP_H) langhooks.h $(TREE_PASS_H) $(BASIC_BLOCK_H) $(BITMAP_H) \
    $(FLAGS_H) $(GGC_H) $(HASHTAB_H) pointer-set.h \
    $(GIMPLE_H) $(TREE_INLINE_H) $(TARGET_H) tree-pretty-print.h \
-   gimple-pretty-print.h
+   gimple-pretty-print.h $(CFGLOOP_H)
 tree-into-ssa.o : tree-into-ssa.c $(TREE_FLOW_H) $(CONFIG_H) $(SYSTEM_H) \
    $(TREE_H) $(TM_P_H) $(EXPR_H) output.h $(DIAGNOSTIC_H) \
    $(FUNCTION_H) $(TIMEVAR_H) $(TM_H) coretypes.h $(TREE_DUMP_H) \
--- gcc/testsuite/gcc.dg/pr48739-1.c.jj	2011-08-19 18:53:43.000000000 +0200
+++ gcc/testsuite/gcc.dg/pr48739-1.c	2011-08-19 18:53:26.000000000 +0200
@@ -0,0 +1,27 @@
+/* PR tree-optimization/48739 */
+/* { dg-do compile } */
+/* { dg-require-effective-target pthread } */
+/* { dg-options "-O1 -ftree-parallelize-loops=2 -fno-tree-dominator-opts" } */
+
+extern int g;
+extern void bar (void);
+
+int
+foo (int x)
+{
+  int a, b, *c = (int *) 0;
+  for (a = 0; a < 10; ++a)
+    {
+      bar ();
+      for (b = 0; b < 5; ++b)
+	{
+	  x = 0;
+	  c = &x;
+	  g = 1;
+	}
+    }
+  *c = x;
+  for (x = 0; x != 10; x++)
+    ;
+  return g;
+}
--- gcc/testsuite/gcc.dg/pr48739-2.c.jj	2011-08-19 18:53:43.000000000 +0200
+++ gcc/testsuite/gcc.dg/pr48739-2.c	2011-08-19 18:54:00.000000000 +0200
@@ -0,0 +1,27 @@
+/* PR tree-optimization/48739 */
+/* { dg-do compile } */
+/* { dg-require-effective-target pthread } */
+/* { dg-options "-O1 -ftree-parallelize-loops=2 -fno-tree-dominator-opts" } */
+
+extern int g, v[10];
+extern void bar (void);
+
+int
+foo (int x)
+{
+  int a, b, *c = (int *) 0;
+  for (a = 0; a < 10; ++a)
+    {
+      bar ();
+      for (b = 0; b < 5; ++b)
+	{
+	  x = 0;
+	  c = &x;
+	  g = 1;
+	}
+    }
+  *c = x;
+  for (x = 0; x != 10; x++)
+    v[x] = x;
+  return g;
+}

	Jakub


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]