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]

Value profiling testcase and fixes for the failures


Hi,
since value profiling seems to break at regular basis without anyone
noticing it (it is broken in 4.0 now too), I am adding a testcases for
it.  I've also found couple of problems while preparing them so they 
are fixed as well.

Bootstrapped/regtested i686-pc-gnu-linux, going to commit it shortly.

Honza

2005-05-28  Jan Hubicka  <jh@suse.cz>
	* tree-ssa-threadupdate.c: (create_edge_and_update_destination_phis):
	Update profile.
	* value-prof.c (tree_divmod_fixed_value_transform): Be more verbose in
	debug output.
	(tree_mod_subtract): Fix profile updating code.
	(tree_divmod_values_to_profile): Do not produce useless value profilers
	for divisions.

	* tree-prof.exp: Fix comment.
	* value-prof-1.c: New.
	* value-prof-2.c: New.
	* value-prof-3.c: New.
	* value-prof-4.c: New.
Index: tree-ssa-threadupdate.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree-ssa-threadupdate.c,v
retrieving revision 2.27
diff -c -3 -p -r2.27 tree-ssa-threadupdate.c
*** tree-ssa-threadupdate.c	27 May 2005 22:06:46 -0000	2.27
--- tree-ssa-threadupdate.c	28 May 2005 14:34:00 -0000
*************** create_edge_and_update_destination_phis 
*** 299,304 ****
--- 299,307 ----
    edge e = make_edge (rd->dup_block, rd->outgoing_edge->dest, EDGE_FALLTHRU);
    tree phi;
  
+   e->probability = REG_BR_PROB_BASE;
+   e->count = rd->dup_block->count;
+ 
    /* If there are any PHI nodes at the destination of the outgoing edge
       from the duplicate block, then we will need to add a new argument
       to them.  The argument should have the same value as the argument
Index: value-prof.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/value-prof.c,v
retrieving revision 1.28
diff -c -3 -p -r1.28 value-prof.c
*** value-prof.c	28 Apr 2005 05:03:09 -0000	1.28
--- value-prof.c	28 May 2005 14:34:00 -0000
*************** tree_divmod_fixed_value_transform (tree 
*** 1221,1232 ****
    if (simple_cst_equal (op2, value) != 1 || 2 * count < all)
      return false;
  
-   if (dump_file)
-     {
-       fprintf (dump_file, "Div/mod by constant transformation on insn ");
-       print_generic_stmt (dump_file, stmt, TDF_SLIM);
-     }
- 
    /* Compute probability of taking the optimal path.  */
    prob = (count * REG_BR_PROB_BASE + all / 2) / all;
  
--- 1221,1226 ----
*************** tree_divmod_fixed_value_transform (tree 
*** 1235,1240 ****
--- 1229,1244 ----
  				 val >> (HOST_BITS_PER_WIDE_INT - 1) >> 1);
    result = tree_divmod_fixed_value (stmt, op, op1, op2, tree_val, prob, count, all);
  
+   if (dump_file)
+     {
+       fprintf (dump_file, "Div/mod by constant ");
+       print_generic_expr (dump_file, value, TDF_SLIM);
+       fprintf (dump_file, "=");
+       print_generic_expr (dump_file, tree_val, TDF_SLIM);
+       fprintf (dump_file, " transformation on insn ");
+       print_generic_stmt (dump_file, stmt, TDF_SLIM);
+     }
+ 
    TREE_OPERAND (modify, 1) = result;
  
    return true;
*************** tree_mod_subtract (tree stmt, tree opera
*** 1489,1499 ****
    e12->flags &= ~EDGE_FALLTHRU;
    e12->flags |= EDGE_FALSE_VALUE;
    e12->probability = REG_BR_PROB_BASE - prob1;
!   e12->count = count1;
  
    e14 = make_edge (bb, bb4, EDGE_TRUE_VALUE);
    e14->probability = prob1;
!   e14->count = all - count1;
  
    if (ncounts)  /* Assumed to be 0 or 1.  */
      {
--- 1493,1503 ----
    e12->flags &= ~EDGE_FALLTHRU;
    e12->flags |= EDGE_FALSE_VALUE;
    e12->probability = REG_BR_PROB_BASE - prob1;
!   e12->count = all - count1;
  
    e14 = make_edge (bb, bb4, EDGE_TRUE_VALUE);
    e14->probability = prob1;
!   e14->count = count1;
  
    if (ncounts)  /* Assumed to be 0 or 1.  */
      {
*************** tree_divmod_values_to_profile (tree stmt
*** 1653,1668 ****
  
        if (is_gimple_reg (divisor))
  	{
- 	  /* Check for a special case where the divisor is power(s) of 2.
- 	     This is more aggressive than the RTL version, under the
- 	     assumption that later phases will reduce / or % by power of 2
- 	     to something clever most of the time.  Signed or unsigned.  */
- 	  hist = ggc_alloc (sizeof (*hist));
- 	  hist->hvalue.tree.value = divisor;
- 	  hist->hvalue.tree.stmt = stmt;
- 	  hist->type = HIST_TYPE_POW2;
- 	  VEC_quick_push (histogram_value, *values, hist);
- 
  	  /* Check for the case where the divisor is the same value most
  	     of the time.  */
  	  hist = ggc_alloc (sizeof (*hist));
--- 1657,1662 ----
*************** tree_divmod_values_to_profile (tree stmt
*** 1677,1682 ****
--- 1671,1683 ----
        if (TREE_CODE (rhs) == TRUNC_MOD_EXPR
  	  && TYPE_UNSIGNED (type))
  	{
+           /* Check for a special case where the divisor is power of 2.  */
+ 	  hist = ggc_alloc (sizeof (*hist));
+ 	  hist->hvalue.tree.value = divisor;
+ 	  hist->hvalue.tree.stmt = stmt;
+ 	  hist->type = HIST_TYPE_POW2;
+ 	  VEC_quick_push (histogram_value, *values, hist);
+ 
  	  hist = ggc_alloc (sizeof (*hist));
  	  hist->hvalue.tree.stmt = stmt;
  	  hist->hvalue.tree.value
Index: testsuite/gcc.dg/tree-prof/tree-prof.exp
===================================================================
RCS file: /cvs/gcc/gcc/gcc/testsuite/gcc.dg/tree-prof/tree-prof.exp,v
retrieving revision 1.1
diff -c -3 -p -r1.1 tree-prof.exp
*** testsuite/gcc.dg/tree-prof/tree-prof.exp	25 May 2005 12:34:01 -0000	1.1
--- testsuite/gcc.dg/tree-prof/tree-prof.exp	28 May 2005 14:34:11 -0000
***************
*** 15,21 ****
  # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  
  
  # Test the functionality of programs compiled with profile-directed block
! # ordering using -fprofile-generate followed by -fprofile-use
  
  load_lib target-supports.exp
  
--- 15,21 ----
  # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  
  
  # Test the functionality of programs compiled with profile-directed block
! # ordering using -fprofile-generate followed by -fbranch-use.
  
  load_lib target-supports.exp
  
Index: testsuite/gcc.dg/tree-prof/val-prof-1.c
===================================================================
RCS file: testsuite/gcc.dg/tree-prof/val-prof-1.c
diff -N testsuite/gcc.dg/tree-prof/val-prof-1.c
*** /dev/null	1 Jan 1970 00:00:00 -0000
--- testsuite/gcc.dg/tree-prof/val-prof-1.c	28 May 2005 14:34:11 -0000
***************
*** 0 ****
--- 1,20 ----
+ /* { dg-options "-O2 -fdump-tree-optimized -fdump-tree-tree_profile" } */
+ int a[1000];
+ int b = 256;
+ int c = 257;
+ main ()
+ {
+   int i;
+   int n;
+   for (i = 0; i < 1000; i++)
+     {
+       if (i % 17)
+ 	n = c;
+       else n = b;
+       a[i] /= n;
+     }
+   return 0;
+ }
+ /* { dg-final-use { scan-tree-dump "Div.mod by constant n=257 transformation on insn" "tree_profile"} } */
+ /* { dg-final-use { scan-tree-dump "if \\(n != 257\\)" "optimized"} } */
+ /* { dg-final-use { scan-tree-dump-not "Invalid sum" "optimized"} } */
Index: testsuite/gcc.dg/tree-prof/val-prof-2.c
===================================================================
RCS file: testsuite/gcc.dg/tree-prof/val-prof-2.c
diff -N testsuite/gcc.dg/tree-prof/val-prof-2.c
*** /dev/null	1 Jan 1970 00:00:00 -0000
--- testsuite/gcc.dg/tree-prof/val-prof-2.c	28 May 2005 14:34:11 -0000
***************
*** 0 ****
--- 1,30 ----
+ /* { dg-options "-O2 -fdump-tree-optimized -fdump-tree-tree_profile" } */
+ unsigned int a[1000];
+ unsigned int b = 256;
+ unsigned int c = 1024;
+ unsigned int d = 17;
+ main ()
+ {
+   int i;
+   unsigned int n;
+   for (i = 0; i < 1000; i++)
+     {
+ 	    a[i]=100*i;
+     }
+   for (i = 0; i < 1000; i++)
+     {
+       if (i % 2)
+ 	n = b;
+       else if (i % 3)
+ 	n = c;
+       else
+ 	n = d;
+       a[i] %= n;
+     }
+   return 0;
+ }
+ /* { dg-final-use { scan-tree-dump "Mod power of 2 transformation on insn" "tree_profile"} } */
+ /* This is part of code checking that n is power of 2, so we are sure that the transformation
+    didn't get optimized out.  */
+ /* { dg-final-use { scan-tree-dump "n \\+ \\-1" "optimized"} } */
+ /* { dg-final-use { scan-tree-dump-not "Invalid sum" "optimized"} } */
Index: testsuite/gcc.dg/tree-prof/val-prof-3.c
===================================================================
RCS file: testsuite/gcc.dg/tree-prof/val-prof-3.c
diff -N testsuite/gcc.dg/tree-prof/val-prof-3.c
*** /dev/null	1 Jan 1970 00:00:00 -0000
--- testsuite/gcc.dg/tree-prof/val-prof-3.c	28 May 2005 14:34:11 -0000
***************
*** 0 ****
--- 1,30 ----
+ /* { dg-options "-O2 -fdump-tree-optimized -fdump-tree-tree_profile" } */
+ unsigned int a[1000];
+ unsigned int b = 257;
+ unsigned int c = 1023;
+ unsigned int d = 19;
+ main ()
+ {
+   int i;
+   unsigned int n;
+   for (i = 0; i < 1000; i++)
+     {
+ 	    a[i]=18;
+     }
+   for (i = 0; i < 1000; i++)
+     {
+       if (i % 2)
+ 	n = b;
+       else if (i % 3)
+ 	n = c;
+       else
+ 	n = d;
+       a[i] %= n;
+     }
+   return 0;
+ }
+ /* { dg-final-use { scan-tree-dump "Mod subtract transformation on insn" "tree_profile"} } */
+ /* This is part of code checking that n is greater than the divisor so we are sure that it
+    didn't get optimized out.  */
+ /* { dg-final-use { scan-tree-dump "if \\(n \\>" "optimized"} } */
+ /* { dg-final-use { scan-tree-dump-not "Invalid sum" "optimized"} } */
Index: testsuite/gcc.dg/tree-prof/val-prof-4.c
===================================================================
RCS file: testsuite/gcc.dg/tree-prof/val-prof-4.c
diff -N testsuite/gcc.dg/tree-prof/val-prof-4.c
*** /dev/null	1 Jan 1970 00:00:00 -0000
--- testsuite/gcc.dg/tree-prof/val-prof-4.c	28 May 2005 14:34:11 -0000
***************
*** 0 ****
--- 1,30 ----
+ /* { dg-options "-O2 -fdump-tree-optimized -fdump-tree-tree_profile" } */
+ unsigned int a[1000];
+ unsigned int b = 999;
+ unsigned int c = 1002;
+ unsigned int d = 1003;
+ main ()
+ {
+   int i;
+   unsigned int n;
+   for (i = 0; i < 1000; i++)
+     {
+ 	    a[i]=1000+i;
+     }
+   for (i = 0; i < 1000; i++)
+     {
+       if (i % 2)
+ 	n = b;
+       else if (i % 3)
+ 	n = c;
+       else
+ 	n = d;
+       a[i] %= n;
+     }
+   return 0;
+ }
+ /* { dg-final-use { scan-tree-dump "Mod subtract transformation on insn" "tree_profile"} } */
+ /* This is part of code checking that n is greater than the divisor so we are sure that it
+    didn't get optimized out.  */
+ /* { dg-final-use { scan-tree-dump "if \\(n \\>" "optimized"} } */
+ /* { dg-final-use { scan-tree-dump-not "Invalid sum" "optimized"} } */


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