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]

PR tree-optimization/37102 patch checked in to 4.3 branch


This seems to have caused no problems in mainline, so here it is backported to the 4.3 branch.

Bootstrapped and no new regressions on x86_64-unknown-linux-gnu.

Andrew
2008-10-17  Andrew MacLeod  <amacleod@redhat.com>

	PR tree-optimization/37102
	* tree-outof-ssa.c (remove_gimple_phi_args): Remove all the PHI args  
	from a node. Check to see if another PHI is dead.
	(eliminate_useless_phis): Rename from eliminate_virtual_phis and remove
	real PHIs which have no uses.
	(rewrite_out_of_ssa): Call eliminate_useless_phis.

2008-10-17  Andrew MacLeod  <amacleod@redhat.com>

	PR tree-optimization/37102
	* gcc.c-torture/execute/pr37102.c: New Test.


Index: tree-outof-ssa.c
===================================================================
*** tree-outof-ssa.c	(revision 141136)
--- tree-outof-ssa.c	(working copy)
*************** replace_def_variable (var_map map, def_o
*** 606,630 ****
  }
  
  
! /* Remove any PHI node which is a virtual PHI.  */
  
  static void
! eliminate_virtual_phis (void)
  {
    basic_block bb;
!   tree phi, next;
  
    FOR_EACH_BB (bb)
      {
!       for (phi = phi_nodes (bb); phi; phi = next)
          {
  	  next = PHI_CHAIN (phi);
! 	  if (!is_gimple_reg (SSA_NAME_VAR (PHI_RESULT (phi))))
  	    {
  #ifdef ENABLE_CHECKING
  	      int i;
! 	      /* There should be no arguments of this PHI which are in
! 		 the partition list, or we get incorrect results.  */
  	      for (i = 0; i < PHI_NUM_ARGS (phi); i++)
  	        {
  		  tree arg = PHI_ARG_DEF (phi, i);
--- 606,669 ----
  }
  
  
! /* Remove each argument from PHI.  If an arg was the last use of an SSA_NAME, 
!    check to see if this allows another PHI node to be removed.  */
  
  static void
! remove_tree_phi_args (tree phi)
! {
!   use_operand_p arg_p;
!   ssa_op_iter iter;
! 
!   if (dump_file && (dump_flags & TDF_DETAILS))
!     {
!       fprintf (dump_file, "Removing Dead PHI definition: ");
!       print_generic_stmt (dump_file, phi, TDF_SLIM);
!     }
! 
!   FOR_EACH_PHI_ARG (arg_p, phi, iter, SSA_OP_USE)
!     {
!       tree arg = USE_FROM_PTR (arg_p);
!       if (TREE_CODE (arg) == SSA_NAME)
!         {
! 	  /* Remove the reference to the existing argument.  */
! 	  SET_USE (arg_p, NULL_TREE);
! 	  if (has_zero_uses (arg))
! 	    {
! 	      tree stmt = SSA_NAME_DEF_STMT (arg);
! 
! 	      /* Also remove the def if it is a PHI node.  */
! 	      if (TREE_CODE (stmt) == PHI_NODE)
! 		{
! 		  remove_tree_phi_args (stmt);
! 		  remove_phi_node (stmt, NULL_TREE, true);
! 		}
! 	    }
! 	}
!     }
! }
! 
! 
! /* Remove any PHI node which is a virtual PHI, or a PHI with no uses.  */
! 
! static void
! eliminate_useless_phis (void)
  {
    basic_block bb;
!   tree result, next, phi;
  
    FOR_EACH_BB (bb)
      {
!       for (phi = phi_nodes (bb); phi; phi = next) 
          {
  	  next = PHI_CHAIN (phi);
! 	  result = PHI_RESULT (phi);
! 	  if (!is_gimple_reg (SSA_NAME_VAR (result)))
  	    {
  #ifdef ENABLE_CHECKING
  	      int i;
! 	      /* There should be no arguments which are not virtual, or the
! 	         results will be incorrect.  */
  	      for (i = 0; i < PHI_NUM_ARGS (phi); i++)
  	        {
  		  tree arg = PHI_ARG_DEF (phi, i);
*************** eliminate_virtual_phis (void)
*** 639,645 ****
  		    }
  		}
  #endif
! 	      remove_phi_node (phi, NULL_TREE, true);
  	    }
  	}
      }
--- 678,693 ----
  		    }
  		}
  #endif
! 	      remove_phi_node (phi, NULL_TREE , true);
! 	    }
!           else
! 	    {
! 	      /* Also remove real PHIs with no uses.  */
! 	      if (has_zero_uses (result))
! 	        {
! 		  remove_tree_phi_args (phi);
! 		  remove_phi_node (phi, NULL_TREE, true);
! 		}
  	    }
  	}
      }
*************** rewrite_out_of_ssa (void)
*** 1449,1455 ****
       copies into the loop itself.  */
    insert_backedge_copies ();
  
!   eliminate_virtual_phis ();
  
    if (dump_file && (dump_flags & TDF_DETAILS))
      dump_tree_cfg (dump_file, dump_flags & ~TDF_DETAILS);
--- 1497,1505 ----
       copies into the loop itself.  */
    insert_backedge_copies ();
  
! 
!   /* Eliminate PHIs which are of no use, such as virtual or dead phis.  */
!   eliminate_useless_phis ();
  
    if (dump_file && (dump_flags & TDF_DETAILS))
      dump_tree_cfg (dump_file, dump_flags & ~TDF_DETAILS);

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