This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[patch] Specialize operand_equal_p for PHI argument comparisons.
- From: Kazu Hirata <kazu at cs dot umass dot edu>
- To: gcc-patches at gcc dot gnu dot org
- Date: Sat, 27 Nov 2004 10:30:02 -0500 (EST)
- Subject: [patch] Specialize operand_equal_p for PHI argument comparisons.
Hi,
Attached is patch to provide a version of operand_equal_p specialized
for PHI argument comparisons.
Here is a timing in seconds for 5 runs of "./cc1 -quiet -O2
-fomit-frame-pointer -o /dev/null insn-attrtab.i".
original patched
real: 195.931 192.715 (1.668% down)
user: 191.533 189.329 (1.164% down)
Here is a timing in seconds for cc1-i files with the same compiler
options as above.
original patched
real: 235.728 231.640 (1.764% down)
user: 227.874 227.207 (0.293% down)
I also did a coverage test by compiling cc1-i files.
-: 6159:int
-: 6160:operand_equal_for_phi_arg_p (tree arg0, tree arg1)
function operand_equal_for_phi_arg_p called 8770287 returned 100% blocks executed 100%
8770287: 6161:{
8770287: 6162: if (arg0 == arg1)
677505: 6163: return 1;
8092782: 6164: if (TREE_CODE (arg0) == SSA_NAME || TREE_CODE (arg1) == SSA_NAME)
8021001: 6165: return 0;
71781: 6166: return operand_equal_p (arg0, arg1, 0);
-: 6167:}
Note that more than 99% of calls to operand_equal_for_phi_arg_p
complete without resorting to operand_eqaul_p.
Tested on i686-pc-linux-gnu. OK to apply?
Kazu Hirata
2004-11-27 Kazu Hirata <kazu@cs.umass.edu>
* tree.c (operand_equal_for_phi_arg_p): New.
* tree.h: Add a prototype for operand_equal_for_phi_arg_p.
* tree-cfg.c, tree-ssa-dom.c, tree-ssa-phiopt.c, tree-ssa.c:
Replace operand_equal_p with operand_for_phi_arg_p
appropriately.
Index: tree-cfg.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree-cfg.c,v
retrieving revision 2.123
diff -u -d -p -r2.123 tree-cfg.c
--- tree-cfg.c 26 Nov 2004 17:02:49 -0000 2.123
+++ tree-cfg.c 27 Nov 2004 04:02:26 -0000
@@ -2278,7 +2278,7 @@ phi_alternatives_equal (basic_block dest
val1 = PHI_ARG_DEF (phi, n1);
val2 = PHI_ARG_DEF (phi, n2);
- if (!operand_equal_p (val1, val2, 0))
+ if (!operand_equal_for_phi_arg_p (val1, val2))
return false;
}
Index: tree-ssa-dom.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree-ssa-dom.c,v
retrieving revision 2.71
diff -u -d -p -r2.71 tree-ssa-dom.c
--- tree-ssa-dom.c 24 Nov 2004 15:29:44 -0000 2.71
+++ tree-ssa-dom.c 27 Nov 2004 04:02:27 -0000
@@ -1180,7 +1180,7 @@ record_equivalences_from_phis (basic_blo
if (TREE_CODE (t) == SSA_NAME || is_gimple_min_invariant (t))
{
/* Ignore alternatives which are the same as our LHS. */
- if (operand_equal_p (lhs, t, 0))
+ if (operand_equal_for_phi_arg_p (lhs, t))
continue;
/* If we have not processed an alternative yet, then set
@@ -1190,7 +1190,7 @@ record_equivalences_from_phis (basic_blo
/* If we have processed an alternative (stored in RHS), then
see if it is equal to this one. If it isn't, then stop
the search. */
- else if (! operand_equal_p (rhs, t, 0))
+ else if (! operand_equal_for_phi_arg_p (rhs, t))
break;
}
else
Index: tree-ssa-phiopt.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree-ssa-phiopt.c,v
retrieving revision 2.19
diff -u -d -p -r2.19 tree-ssa-phiopt.c
--- tree-ssa-phiopt.c 17 Nov 2004 02:01:35 -0000 2.19
+++ tree-ssa-phiopt.c 27 Nov 2004 04:02:27 -0000
@@ -450,10 +450,10 @@ value_replacement (basic_block bb, tree
We now need to verify that the two arguments in the PHI node match
the two arguments to the equality comparison. */
- if ((operand_equal_p (arg0, TREE_OPERAND (cond, 0), 0)
- && operand_equal_p (arg1, TREE_OPERAND (cond, 1), 0))
- || (operand_equal_p (arg1, TREE_OPERAND (cond, 0), 0)
- && operand_equal_p (arg0, TREE_OPERAND (cond, 1), 0)))
+ if ((operand_equal_for_phi_arg_p (arg0, TREE_OPERAND (cond, 0))
+ && operand_equal_for_phi_arg_p (arg1, TREE_OPERAND (cond, 1)))
+ || (operand_equal_for_phi_arg_p (arg1, TREE_OPERAND (cond, 0))
+ && operand_equal_for_phi_arg_p (arg0, TREE_OPERAND (cond, 1))))
{
edge e;
tree arg;
Index: tree-ssa.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree-ssa.c,v
retrieving revision 2.67
diff -u -d -p -r2.67 tree-ssa.c
--- tree-ssa.c 26 Nov 2004 20:18:34 -0000 2.67
+++ tree-ssa.c 27 Nov 2004 04:02:28 -0000
@@ -1138,7 +1138,7 @@ check_phi_redundancy (tree phi, tree *eq
}
if (val
- && !operand_equal_p (val, def, 0))
+ && !operand_equal_for_phi_arg_p (val, def))
return;
val = def;
Index: tree.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree.c,v
retrieving revision 1.451
diff -u -d -p -r1.451 tree.c
--- tree.c 24 Nov 2004 16:37:02 -0000 1.451
+++ tree.c 27 Nov 2004 04:02:30 -0000
@@ -6150,4 +6150,20 @@ lower_bound_in_type (tree outer, tree in
build_int_cst_wide (inner, lo, hi));
}
+/* Return nonzero if two operands that are suitable for PHI nodes are
+ necessarily equal. Specifically, both ARG0 and ARG1 must be either
+ SSA_NAME or invariant. Note that this is strictly an optimization.
+ That is, callers of this function can directly call operand_equal_p
+ and get the same result, only slower. */
+
+int
+operand_equal_for_phi_arg_p (tree arg0, tree arg1)
+{
+ if (arg0 == arg1)
+ return 1;
+ if (TREE_CODE (arg0) == SSA_NAME || TREE_CODE (arg1) == SSA_NAME)
+ return 0;
+ return operand_equal_p (arg0, arg1, 0);
+}
+
#include "gt-tree.h"
Index: tree.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree.h,v
retrieving revision 1.661
diff -u -d -p -r1.661 tree.h
--- tree.h 24 Nov 2004 11:41:33 -0000 1.661
+++ tree.h 27 Nov 2004 04:02:32 -0000
@@ -3442,6 +3442,7 @@ extern bool commutative_tree_code (enum
extern tree get_case_label (tree);
extern tree upper_bound_in_type (tree, tree);
extern tree lower_bound_in_type (tree, tree);
+extern int operand_equal_for_phi_arg_p (tree, tree);
/* In stmt.c */