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]

[tree-ssa] Improve jump threading


Using the components of cc1 test, the tree-ssa optimizers are currently
missing 53 jump threading opportunities.

This patch gets that down to 13 :-)

When I added the code to record equivalences for PHIs in blocks we're
threading through, I failed to move the code which records those
equivalences to a point before walking the statements in the block.

This meant that the PHI equivalences were only used for proving an
IF statement had a known value when the block was reached from a
particular edge -- we really want to also use those PHI equivalences
to help determine that statements at the start of the block are
NOPs.

Bootstrapped and regression tested on i686-pc-linux-gnu.

	* tree-ssa-dom.c (thread_across_edge): Create equivalences for
	PHIs before looking at the statements in the destination
	block.

Index: tree-ssa-dom.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/tree-ssa-dom.c,v
retrieving revision 1.1.2.115
diff -c -p -r1.1.2.115 tree-ssa-dom.c
*** tree-ssa-dom.c	19 Jan 2004 23:21:42 -0000	1.1.2.115
--- tree-ssa-dom.c	21 Jan 2004 07:04:01 -0000
*************** thread_across_edge (struct dom_walk_data
*** 629,634 ****
--- 629,658 ----
      = VARRAY_TOP_GENERIC_PTR (walk_data->block_data_stack);
    block_stmt_iterator bsi;
    tree stmt = NULL;
+   tree phi;
+ 
+   /* Each PHI creates a temporary equivalence, record them.  */
+   for (phi = phi_nodes (e->dest); phi; phi = TREE_CHAIN (phi))
+     {
+       tree src = PHI_ARG_DEF (phi, phi_arg_from_edge (phi, e));
+       tree dst = PHI_RESULT (phi);
+       tree prev_value = get_value_for (dst, const_and_copies);
+ 
+       if (TREE_CODE (src) == SSA_NAME)
+ 	{
+ 	  tree tmp = get_value_for (src, const_and_copies);
+ 
+ 	  if (tmp)
+ 	    src = tmp;
+ 	}
+ 	  
+       set_value_for (dst, src, const_and_copies);
+ 
+       if (! bd->const_and_copies)
+         VARRAY_TREE_INIT (bd->const_and_copies, 2, "block_const_and_copies");
+       VARRAY_PUSH_TREE (bd->const_and_copies, dst);
+       VARRAY_PUSH_TREE (bd->const_and_copies, prev_value);
+     }
  
    for (bsi = bsi_start (e->dest); ! bsi_end_p (bsi); bsi_next (&bsi))
      {
*************** thread_across_edge (struct dom_walk_data
*** 763,769 ****
       be taken.  */
    if (stmt && TREE_CODE (stmt) == COND_EXPR)
      {
!       tree cached_lhs, phi;
        edge e1;
  
        /* Do not forward a back edge in the CFG.  This avoids short circuiting
--- 787,793 ----
       be taken.  */
    if (stmt && TREE_CODE (stmt) == COND_EXPR)
      {
!       tree cached_lhs;
        edge e1;
  
        /* Do not forward a back edge in the CFG.  This avoids short circuiting
*************** thread_across_edge (struct dom_walk_data
*** 783,813 ****
  	      break;
  	  if (e1)
  	    return;
- 	}
- 
-       /* Each PHI creates a temporary equivalence, record them.  */
-       for (phi = phi_nodes (e->dest); phi; phi = TREE_CHAIN (phi))
- 	{
- 	  tree src = PHI_ARG_DEF (phi, phi_arg_from_edge (phi, e));
- 	  tree dst = PHI_RESULT (phi);
- 	  tree prev_value = get_value_for (dst, const_and_copies);
- 
- 	  if (TREE_CODE (src) == SSA_NAME)
- 	    {
- 	      tree tmp = get_value_for (src, const_and_copies);
- 
- 	      if (tmp)
- 		src = tmp;
- 	    }
- 	  
- 	  set_value_for (dst, src, const_and_copies);
- 
- 	  if (! bd->const_and_copies)
- 	    VARRAY_TREE_INIT (bd->const_and_copies, 2,
- 			      "block_const_and_copies");
- 	  VARRAY_PUSH_TREE (bd->const_and_copies, dst);
- 	  VARRAY_PUSH_TREE (bd->const_and_copies, prev_value);
- 
  	}
  
        /* Now temporarily cprop the operands and try to find the resulting
--- 807,812 ----





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