[tree-ssa] Removing conditionals patch.

Andrew MacLeod amacleod@redhat.com
Fri May 16 17:57:00 GMT 2003


Since we've reworked cleanup_cfg and DCE to only remove a conditional statement
if there are no PHI nodes in the post dominator, remove_conditional no longer 
has to deal with fixing the phi node in post dominator blocks.   

This patch rips out that code. Note there is no functional difference except
that we don't try to update PHI nodes which are marked to be deleted, which
we sometimes do now.

Bootstrapped, etc.


Andrew

Eventually we'll have to have something in the SSA->Normal pass which does
a little DCE on the partitioning. Any PHI's whose arguments all coalesce
with the result can be eliminated, and that may expose conditionals and 
feeding instructions which can be deleted just before we go out of SSA form.  
I'll revisit this later.


2003-05-16  Andrew MacLeod  <amacleod@redhat.com>

	* tree-ssa-dce.c (remove_dead_stmt): Change comment about removing 
	conditionals.
	(remove_conditional): Don't update PHI nodes or call ssa_make_edge.
	* tree-ssa.c (ssa_make_edge): Remove.

Index: tree-ssa-dce.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/tree-ssa-dce.c,v
retrieving revision 1.1.2.36
diff -c -p -r1.1.2.36 tree-ssa-dce.c
*** tree-ssa-dce.c	8 May 2003 20:29:30 -0000	1.1.2.36
--- tree-ssa-dce.c	16 May 2003 15:12:18 -0000
*************** remove_dead_stmt (i, bb)
*** 531,541 ****
       post-dominator.  This prevents us from having to add any branch
       instuctions to replace the conditional statement.
  
!      Note that the call to remove_conditional can be relatively
!      expensive because of all the PHI node manipulation it needs to do.
!      Therefore, we only remove a conditional if its parent statement is
!      live.  This avoid unnecessary calls to remove_conditional in the
!      event of dead nested conditionals.  */
    if (TREE_CODE (t) == COND_EXPR || TREE_CODE (t) == SWITCH_EXPR)
      {
        tree parent = parent_stmt (t);
--- 531,540 ----
       post-dominator.  This prevents us from having to add any branch
       instuctions to replace the conditional statement.
  
!      Only remove a conditional if its parent statement is live.  This avoids
!      unnecessary calls to remove_conditional in the event of dead nested 
!      conditionals.  */
! 
    if (TREE_CODE (t) == COND_EXPR || TREE_CODE (t) == SWITCH_EXPR)
      {
        tree parent = parent_stmt (t);
*************** static void
*** 601,607 ****
  remove_conditional (basic_block bb)
  {
    basic_block pdom_bb;
-   tree phi, phi_arg_list;
    edge e;
  
    /* Calculate dominance info, if it hasn't been computed yet.  */
--- 600,605 ----
*************** remove_conditional (basic_block bb)
*** 629,709 ****
    if (bb->succ)
      return;
  
!   /* For every PHI node V_i at PDOM_BB, find the first argument V_j coming
!      from a node dominated by BB.  That argument V_j will be used as the
!      new argument for V_i, coming from the new edge BB -> PDOM_BB.
! 
! 			+----------+
! 			| ...      |
! 			| if (...) | BB
! 			+----------+
! 			  /      \
! 			 /        \
! 			...       ...
! 		       +---+     +---+
! 		       |   | N   |   | M
! 		       +---+     +---+
! 			 \        /
! 			  \      /
! 	    +------------------------------------+
! 	    | V_i = PHI <..., V_j(N), V_j(M)...> | PDOM_BB
! 	    +------------------------------------+
! 
!      Notice that since the whole conditional structure is dead, it is
!      impossible for V_j to have originated inside the conditional.
!      Otherwise, the conditional would have live statements (namely, the
!      statements that generate V_j).
! 
!      Therefore, the PHI node V_i is guaranteed to have up to two identical
!      arguments V_j coming from inside the conditional.  Since V_j cannot
!      have been generated inside the conditional, when we add a new edge
!      BB->PDOM_BB, we can make V_j come from the new edge.  The transformed
!      flowgraph will look as follows (after the call to cleanup_tree_cfg):
! 
! 			+---------+
! 			| ...     |
! 			| (void)0 | BB
! 			+---------+
! 			     |
! 			     |
! 	    +-------------------------------+
! 	    | V_i = PHI <..., V_j(BB), ...> | PDOM_BB
! 	    +-------------------------------+
! 
!      The same property applies for SWITCH_EXPR conditionals.  */
!   phi_arg_list = NULL_TREE;
!   for (phi = phi_nodes (pdom_bb); phi; phi = TREE_CHAIN (phi))
!     {
!       int found, i;
!       for (found = i = 0; i < PHI_NUM_ARGS (phi); i++)
! 	{
! 	  basic_block arg_bb = PHI_ARG_EDGE (phi, i)->src;
! 
! 	  if (dominated_by_p (dom_info, arg_bb, bb))
! 	    {
! 	      tree arg = build_tree_list (NULL_TREE, PHI_ARG_DEF (phi, i));
! 
! 	      if (phi_arg_list )
! 		chainon (phi_arg_list, arg);
! 	      else
! 		phi_arg_list = arg;
! 
! 	      remove_phi_arg_num (phi, i);
! 	      found = 1;
! 	      break;
! 	    }
! 	}
! 
! #if defined ENABLE_CHECKING
!       /* If we didn't find an argument coming from a block dominated by BB,
! 	 something is wrong.  */
!       if (!found)
! 	abort ();
  #endif
-     }
  
!   /* Add an edge to BB's post dominator.  Add PHI arguments to every PHI
!      node at PDOM_BB from the list of arguments computed above..  */
    if (bb->succ == NULL)
!     ssa_make_edge (bb, pdom_bb, EDGE_FALLTHRU, phi_arg_list);
  }
--- 627,647 ----
    if (bb->succ)
      return;
  
!   /* If the post dominator has any PHI nodes in it at all, the 
!      conditional has been marked as necessary. This means no PHI
!      node updating is required. If there are any PHI nodes, its a bug
!      in DCE.  */
! 
! #ifdef ENABLE_CHECKING
!   {
!     tree phi;
!     for (phi = phi_nodes (pdom_bb); phi; phi = TREE_CHAIN (phi))
!       if (necessary_p (phi))
!         abort ();
!   }
  #endif
  
!   /* Add an edge to BB's post dominator.  */
    if (bb->succ == NULL)
!     make_edge (bb, pdom_bb,  EDGE_FALLTHRU);
  }
Index: tree-ssa.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/tree-ssa.c,v
retrieving revision 1.1.4.79
diff -c -p -r1.1.4.79 tree-ssa.c
*** tree-ssa.c	15 May 2003 13:35:08 -0000	1.1.4.79
--- tree-ssa.c	16 May 2003 15:12:19 -0000
*************** ssa_remove_edge (edge e)
*** 1725,1770 ****
    remove_edge (e);
  }
  
- 
- /* Make a new edge between BB1 and BB2.  All the PHI nodes at BB2 will
-    receive a new argument that should be provided in PHI_ARG_LIST.  */
- 
- edge
- ssa_make_edge (basic_block bb1, basic_block bb2, int flags, tree phi_arg_list)
- {
-   tree phi;
-   edge e;
-   
-   e = make_edge (bb1, bb2, flags);
- 
-   /* Add a new argument to every PHI node in BB2.  FIXME: Hmm, double
-      linear scan.  This may slow things down.  */
-   if (phi_arg_list)
-     for (phi = phi_nodes (bb2); phi; phi = TREE_CHAIN (phi))
-       {
- 	/* Look for the new argument to add in PHI_ARG_LIST.  */
- 	tree node;
- 
- 	for (node = phi_arg_list; node; node = TREE_CHAIN (node))
- 	  {
- 	    tree arg = TREE_VALUE (node);
- 	    if (SSA_NAME_VAR (arg) == SSA_NAME_VAR (PHI_RESULT (phi)))
- 	      {
- 		add_phi_arg (phi, arg, e);
- 		break;
- 	      }
- 	  }
- 
- 	/* If we didn't find an argument for the PHI node, then PHI_ARG_LIST
- 	  is wrong.  */
- 	if (node == NULL_TREE)
- 	  abort ();
-       }
- 
-   return e;
- }
- 
- 
  /*---------------------------------------------------------------------------
  			       Debugging support
  ---------------------------------------------------------------------------*/
--- 1725,1730 ----




More information about the Gcc-patches mailing list