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-vrp.c: Don't insert ASSERT_EXPRs for single-usevariables.


Hi,

Attached is a patch to teach maybe_add_assert_expr not to insert
ASSERT_EXPRs for single-use variables.

If we add an ASSERT_EXPR for a variable that has a single use, that
means that the use must happen in the statement that is used to deduce
an ASSERT_EXPR, which in turn means that the range that is picked up
from the ASSERT_EXPR will be totally useless because there is no use
of the asserted variable except in the statement preceding the
ASSERT_EXPR.  Worse yet, adding an ASSERT_EXPR, updating the SSA form,
turning an ASSERT_EXPR back to a copy statement all take time.

The patch fixes this problem by using has_single_use on the variable
that we are considering to add an ASSERT_EXPR for.  (Thanks Andrew
MacLeod!)

I looked at how many ASSERT_EXPRs we add for single use variables.
That was mind boggling.  For cc1-i files, 21% of ASSERT_EXPRs deduced
from non-COND_EXPR statements were for single-use variables.  For MICO
files, 39% of ASSERT_EXPRs deduced from non-COND_EXPR statements were
for single-use variables.

Wondering if running FRE might change these numbers significantly by
making the result of non-redundant computation used in more places, I
inserted ccp, copy_prop, fre, dce, and forwprop (in this order)
immediately before VRP, but doing so hardly changed the numbers above.
The difference was less than 1%.

Without this patch, it takes 181.890 seconds to compile cc1-i files,
whereas with this patch, it takes 180.713 seconds, so we have a 0.647%
improvement.

Using rdtsc instruction for VRP shows that this patch shaves a few
milliseconds for each cc1-i file.  Since I have 220 of them, the total
saving of one second is more or less consistent with the measurement
done with rdtsc instruction.

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

Kazu Hirata

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

	* tree-vrp.c (maybe_add_assert_expr): Don't assert
	ASSERT_EXPRs for single-use variable.

Index: tree-vrp.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree-vrp.c,v
retrieving revision 2.8
diff -u -d -p -r2.8 tree-vrp.c
--- tree-vrp.c	15 Apr 2005 01:29:29 -0000	2.8
+++ tree-vrp.c	17 Apr 2005 06:26:37 -0000
@@ -1454,6 +1454,14 @@ maybe_add_assert_expr (basic_block bb)
 	{
 	  tree cond;
 
+	  /* If OP is used only once, namely in this STMT, don't
+	     bother inserting an ASSERT_EXPR for it.  Such an
+	     ASSERT_EXPR would do nothing but increase compile time.
+	     Experiments show that with this simple check, we can save
+	     more than 20% of ASSERT_EXPRs.  */
+	  if (has_single_use (op))
+	    continue;
+
 	  SET_BIT (found, SSA_NAME_VERSION (op));
 
 	  cond = infer_value_range (stmt, op);


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