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 PR46177 - 2nd try


This fixes PR46177, this time for real (hopefully).  We can simply
re-use the loop exit edge for jumping around the loop and thus do
not need to mess with phi nodes at all.

Bootstrapped and tested on x86_64-unknown-linux-gnu, applied.

Richard.

2010-11-09  Richard Guenther  <rguenther@suse.de>

	PR tree-optimization/46177
	* tree-loop-distribution.c (prop_phis): Remove.
	(generate_builtin): Re-use the old loop exit edge to avoid
	needing to update PHI nodes.

	* gcc.dg/pr46177-2.c: New testcase.

Index: gcc/tree-loop-distribution.c
===================================================================
*** gcc/tree-loop-distribution.c	(revision 166482)
--- gcc/tree-loop-distribution.c	(working copy)
*************** generate_memset_zero (gimple stmt, tree
*** 311,341 ****
    return res;
  }
  
- /* Propagate phis in BB b to their uses and remove them.  */
- 
- static void
- prop_phis (basic_block b)
- {
-   gimple_stmt_iterator psi;
- 
-   for (psi = gsi_start_phis (b); !gsi_end_p (psi); )
-     {
-       gimple phi = gsi_stmt (psi);
-       tree def = gimple_phi_result (phi);
- 
-       if (!is_gimple_reg (def))
- 	mark_virtual_phi_result_for_renaming (phi);
-       else
- 	{
- 	  tree use = gimple_phi_arg_def (phi, 0);
- 	  gcc_assert (gimple_phi_num_args (phi) == 1);
- 	  replace_uses_by (def, use);
- 	}
- 
-       remove_phi_node (&psi, true);
-     }
- }
- 
  /* Tries to generate a builtin function for the instructions of LOOP
     pointed to by the bits set in PARTITION.  Returns true when the
     operation succeeded.  */
--- 311,316 ----
*************** generate_builtin (struct loop *loop, bit
*** 405,415 ****
    if (res && !copy_p)
      {
        unsigned nbbs = loop->num_nodes;
!       basic_block src = loop_preheader_edge (loop)->src;
!       basic_block dest = single_exit (loop)->dest;
!       prop_phis (dest);
!       make_edge (src, dest, EDGE_FALLTHRU);
        cancel_loop_tree (loop);
  
        for (i = 0; i < nbbs; i++)
  	delete_basic_block (bbs[i]);
--- 380,392 ----
    if (res && !copy_p)
      {
        unsigned nbbs = loop->num_nodes;
!       edge exit = single_exit (loop);
!       basic_block src = loop_preheader_edge (loop)->src, dest = exit->dest;
!       redirect_edge_pred (exit, src);
!       exit->flags &= ~(EDGE_TRUE_VALUE|EDGE_FALSE_VALUE);
!       exit->flags |= EDGE_FALLTHRU;
        cancel_loop_tree (loop);
+       rescan_loop_exit (exit, false, true);
  
        for (i = 0; i < nbbs; i++)
  	delete_basic_block (bbs[i]);
Index: gcc/testsuite/gcc.dg/pr46177-2.c
===================================================================
*** gcc/testsuite/gcc.dg/pr46177-2.c	(revision 0)
--- gcc/testsuite/gcc.dg/pr46177-2.c	(revision 0)
***************
*** 0 ****
--- 1,18 ----
+ /* { dg-do compile } */
+ /* { dg-options "-O -fno-tree-copy-prop -ftree-loop-distribution" } */
+ 
+ int A[30], B[30];
+ 
+ void
+ foo (int j)
+ {
+   int i, k;
+   for (k = 0; k < 10; k++)
+     if (j)
+       {
+ 	for (; j < k; j++)
+ 	  ;
+ 	for (i = 0; i < k; i++)
+ 	  A[i] = B[i] = 0;
+       }
+ }


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