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] tree-ssa-phiopt.c: Clean up.


Hi,

Attached is a patch to clean up tree-ssa-phiopt.c.

In general, PHI-OPT replaces constructs like

     bb0:
      if (cond) goto bb2; else goto bb1;
     bb1:
     bb2:
      x = PHI <a (bb1), b (bb0), ...>;

with

     bb0:
      x' = some statement;
      goto bb2;
     bb2:
      x = PHI <x' (bb0), ...>;

Note that the PHI argument is updated.  This update is performed by
replace_phi_edge_with_variable.  To perform the update, the function
takes various arguments, including the PHI node, and the basic block
that the PHI node belongs to.  But note that the basic block that the
PHI node belongs to is redundant because we can easily calculate that
with bb_for_stmt (phi).

Using this idea, the patch eliminates one argument from
replace_phi_edge_with_variable.  Once we eliminate the argument, we
can drop one argument from callers of this function, namely

  conditional_replacement
  value_replacement
  minmax_replacement
  abs_replacement

because all these functions take phi_bb, which is equal to
bb_for_stmt (phi), and do nothing with the argument but pass it to
replace_phi_edge_with_variable.

Tested on i686-pc-linux-gnu.  OK to apply?

Kazu Hirata

2005-04-20  Kazu Hirata  <kazu@cs.umass.edu>

	* tree-ssa-phiopt.c (tree_ssa_phi_opt): Update calls to
	conditional_replacement, value_replacement, abs_replacement,
	minmax_replacement.
	(replace_phi_edge_with_variable): Remove argument BB.
	(conditional_replacement, value_replacement,
	minmax_replacement, abs_replacement): Remove argument PHI_BB.
	Update a call to replace_phi_edge_with_variable.

Index: tree-ssa-phiopt.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree-ssa-phiopt.c,v
retrieving revision 2.33
diff -u -d -p -r2.33 tree-ssa-phiopt.c
--- tree-ssa-phiopt.c	20 Apr 2005 00:45:43 -0000	2.33
+++ tree-ssa-phiopt.c	20 Apr 2005 03:56:11 -0000
@@ -37,16 +37,15 @@ Software Foundation, 59 Temple Place - S
 #include "langhooks.h"
 
 static void tree_ssa_phiopt (void);
-static bool conditional_replacement (basic_block, basic_block, basic_block,
+static bool conditional_replacement (basic_block, basic_block,
 				     edge, edge, tree, tree, tree);
-static bool value_replacement (basic_block, basic_block, basic_block,
+static bool value_replacement (basic_block, basic_block,
 			       edge, edge, tree, tree, tree);
-static bool minmax_replacement (basic_block, basic_block, basic_block,
+static bool minmax_replacement (basic_block, basic_block,
 				edge, edge, tree, tree, tree);
-static bool abs_replacement (basic_block, basic_block, basic_block,
+static bool abs_replacement (basic_block, basic_block,
 			     edge, edge, tree, tree, tree);
-static void replace_phi_edge_with_variable (basic_block, basic_block, edge,
-					    tree, tree);
+static void replace_phi_edge_with_variable (basic_block, edge, tree, tree);
 static basic_block *blocks_in_phiopt_order (void);
 
 /* This pass tries to replaces an if-then-else block with an
@@ -227,14 +226,14 @@ tree_ssa_phiopt (void)
       gcc_assert (arg0 != NULL && arg1 != NULL);
 
       /* Do the replacement of conditional if it can be done.  */
-      if (conditional_replacement (bb, bb1, bb2, e1, e2, phi, arg0, arg1))
+      if (conditional_replacement (bb, bb1, e1, e2, phi, arg0, arg1))
 	;
-      else if (value_replacement (bb, bb1, bb2, e1, e2, phi, arg0, arg1))
+      else if (value_replacement (bb, bb1, e1, e2, phi, arg0, arg1))
 	;
-      else if (abs_replacement (bb, bb1, bb2, e1, e2, phi, arg0, arg1))
+      else if (abs_replacement (bb, bb1, e1, e2, phi, arg0, arg1))
 	;
       else
-	minmax_replacement (bb, bb1, bb2, e1, e2, phi, arg0, arg1);
+	minmax_replacement (bb, bb1, e1, e2, phi, arg0, arg1);
     }
 
   free (bb_order);
@@ -317,9 +316,10 @@ empty_block_p (basic_block bb)
    is known to have two edges, one of which must reach BB).  */
 
 static void
-replace_phi_edge_with_variable (basic_block cond_block, basic_block bb,
+replace_phi_edge_with_variable (basic_block cond_block,
 				edge e, tree phi, tree new)
 {
+  basic_block bb = bb_for_stmt (phi);
   basic_block block_to_remove;
   block_stmt_iterator bsi;
 
@@ -363,7 +363,7 @@ replace_phi_edge_with_variable (basic_bl
 
 static bool
 conditional_replacement (basic_block cond_bb, basic_block middle_bb,
-			 basic_block phi_bb, edge e0, edge e1, tree phi,
+			 edge e0, edge e1, tree phi,
 			 tree arg0, tree arg1)
 {
   tree result;
@@ -495,7 +495,7 @@ conditional_replacement (basic_block con
 
   SSA_NAME_DEF_STMT (new_var1) = new;
 
-  replace_phi_edge_with_variable (cond_bb, phi_bb, e1, phi, new_var1);
+  replace_phi_edge_with_variable (cond_bb, e1, phi, new_var1);
 
   /* Note that we optimized this PHI.  */
   return true;
@@ -509,7 +509,7 @@ conditional_replacement (basic_block con
 
 static bool
 value_replacement (basic_block cond_bb, basic_block middle_bb,
-		   basic_block phi_bb, edge e0, edge e1, tree phi,
+		   edge e0, edge e1, tree phi,
 		   tree arg0, tree arg1)
 {
   tree cond;
@@ -571,7 +571,7 @@ value_replacement (basic_block cond_bb, 
       else
 	arg = arg1;
 
-      replace_phi_edge_with_variable (cond_bb, phi_bb, e1, phi, arg);
+      replace_phi_edge_with_variable (cond_bb, e1, phi, arg);
 
       /* Note that we optimized this PHI.  */
       return true;
@@ -587,7 +587,7 @@ value_replacement (basic_block cond_bb, 
 
 static bool
 minmax_replacement (basic_block cond_bb, basic_block middle_bb,
-		    basic_block phi_bb, edge e0, edge e1, tree phi,
+		    edge e0, edge e1, tree phi,
 		    tree arg0, tree arg1)
 {
   tree result, type;
@@ -826,7 +826,7 @@ minmax_replacement (basic_block cond_bb,
   bsi = bsi_last (cond_bb);
   bsi_insert_before (&bsi, new, BSI_NEW_STMT);
 
-  replace_phi_edge_with_variable (cond_bb, phi_bb, e1, phi, result);
+  replace_phi_edge_with_variable (cond_bb, e1, phi, result);
   return true;
 }
 
@@ -838,7 +838,7 @@ minmax_replacement (basic_block cond_bb,
 
 static bool
 abs_replacement (basic_block cond_bb, basic_block middle_bb,
-		 basic_block phi_bb, edge e0 ATTRIBUTE_UNUSED, edge e1,
+		 edge e0 ATTRIBUTE_UNUSED, edge e1,
 		 tree phi, tree arg0, tree arg1)
 {
   tree result;
@@ -947,7 +947,7 @@ abs_replacement (basic_block cond_bb, ba
     }
 
   SSA_NAME_DEF_STMT (result) = new;
-  replace_phi_edge_with_variable (cond_bb, phi_bb, e1, phi, result);
+  replace_phi_edge_with_variable (cond_bb, e1, phi, result);
 
   /* Note that we optimized this PHI.  */
   return true;


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