profile.c (compute_value_histograms): Fix thinko.
authorJan Hubicka <jh@suse.cz>
Mon, 1 Aug 2005 09:51:17 +0000 (11:51 +0200)
committerJan Hubicka <hubicka@gcc.gnu.org>
Mon, 1 Aug 2005 09:51:17 +0000 (09:51 +0000)
* profile.c (compute_value_histograms): Fix thinko.
* value-prof.c: Include toplev.h
(check_counter): New function.
(tree_divmod_fixed_value_transform, tree_mod_pow2_value_transform,
tree_mod_subtract_transform): Add sanity check.

* val-prof-5.c: New test.

From-SVN: r102629

gcc/ChangeLog
gcc/profile.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/tree-prof/val-prof-5.c [new file with mode: 0644]
gcc/value-prof.c

index a4818a44f709d4b65ca49c545b52f40461d484db..3aeffc077a09c87bc1a1cf8349a03d63e2dd9d68 100644 (file)
@@ -1,3 +1,11 @@
+2005-08-01  Jan Hubicka  <jh@suse.cz>
+
+       * profile.c (compute_value_histograms): Fix thinko.
+       * value-prof.c: Include toplev.h
+       (check_counter): New function.
+       (tree_divmod_fixed_value_transform, tree_mod_pow2_value_transform,
+       tree_mod_subtract_transform): Add sanity check.
+
 2005-08-01  Richard Guenther  <rguenther@suse.de>
 
        PR tree-optimization/23133
index 113927fd44a7d5868027ec32c472832855890501..95448f076ff3b160e36174ccf6c8b991124cdbf8 100644 (file)
@@ -651,14 +651,13 @@ compute_value_histograms (histogram_values values)
   gcov_type *histogram_counts[GCOV_N_VALUE_COUNTERS];
   gcov_type *act_count[GCOV_N_VALUE_COUNTERS];
   gcov_type *aact_count;
-  histogram_value hist = 0;
  
   for (t = 0; t < GCOV_N_VALUE_COUNTERS; t++)
     n_histogram_counters[t] = 0;
 
   for (i = 0; i < VEC_length (histogram_value, values); i++)
     {
-      hist = VEC_index (histogram_value, values, i);
+      histogram_value hist = VEC_index (histogram_value, values, i);
       n_histogram_counters[(int) hist->type] += hist->n_counters;
     }
 
@@ -683,10 +682,10 @@ compute_value_histograms (histogram_values values)
 
   for (i = 0; i < VEC_length (histogram_value, values); i++)
     {
+      histogram_value hist = VEC_index (histogram_value, values, i);
       tree stmt = hist->hvalue.stmt;
       stmt_ann_t ann = get_stmt_ann (stmt);
 
-      hist = VEC_index (histogram_value, values, i);
       t = (int) hist->type;
 
       aact_count = act_count[t];
index 29b67a95024cb8a40820a5b9ec5fb55b1b726fa8..a4dc061c663f9c545831c82d26922d41ab628b72 100644 (file)
@@ -1,3 +1,7 @@
+2005-08-01  Jan Hubicka  <jh@suse.cz>
+
+       * val-prof-5.c: New test.
+
 2005-08-01  Joseph S. Myers  <joseph@codesourcery.com>
 
        PR c/22311
diff --git a/gcc/testsuite/gcc.dg/tree-prof/val-prof-5.c b/gcc/testsuite/gcc.dg/tree-prof/val-prof-5.c
new file mode 100644 (file)
index 0000000..41a43c3
--- /dev/null
@@ -0,0 +1,17 @@
+/* { dg-options "-O2 -fdump-tree-optimized -fdump-tree-tree_profile" } */
+int a[1000];
+int b=997;
+main()
+{
+       int i;
+       for (i = 0; i < 1000; i++)
+               if (a[i])
+                       a[i]/=b;
+               else
+                       a[i]/=b;
+       return 0;
+}
+/* { dg-final-use { scan-tree-dump "Div.mod by constant b..=997 transformation on insn" "tree_profile"} } */
+/* { dg-final-use { scan-tree-dump-not "Invalid sum" "optimized"} } */
+/* { dg-final-use { cleanup-tree-dump "optimized" } } */
+/* { dg-final-use { cleanup-tree-dump "tree_profile" } } */
index b9594f1fbe7ea3f060b948b6db85b602517e28fb..7782fa3786df9e6634d4aff4d132bbb753b632b8 100644 (file)
@@ -42,6 +42,7 @@ Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
 #include "gcov-io.h"
 #include "timevar.h"
 #include "tree-pass.h"
+#include "toplev.h"
 
 static struct value_prof_hooks *value_prof_hooks;
 
@@ -85,6 +86,25 @@ static bool tree_divmod_fixed_value_transform (tree);
 static bool tree_mod_pow2_value_transform (tree);
 static bool tree_mod_subtract_transform (tree);
 
+/* The overall number of invocations of the counter should match execution count
+   of basic block.  Report it as error rather than internal error as it might
+   mean that user has missused the profile somehow.  */
+static bool
+check_counter (tree stmt, const char * name, gcov_type all, gcov_type bb_count)
+{
+  if (all != bb_count)
+    {
+      location_t * locus;
+      locus = (stmt != NULL && EXPR_HAS_LOCATION (stmt)
+              ? EXPR_LOCUS (stmt)
+              : &DECL_SOURCE_LOCATION (current_function_decl));
+      error ("%HCorrupted value profile: %s profiler overall count (%d) does not match BB count (%d)",
+            locus, name, (int)all, (int)bb_count);
+      return true;
+    }
+  return false;
+}
+
 /* Tree based transformations. */
 static bool
 tree_value_profile_transformations (void)
@@ -286,6 +306,9 @@ tree_divmod_fixed_value_transform (tree stmt)
   if (simple_cst_equal (op2, value) != 1 || 2 * count < all)
     return false;
 
+  if (check_counter (stmt, "value", all, bb_for_stmt (stmt)->count))
+    return false;
+
   /* Compute probability of taking the optimal path.  */
   prob = (count * REG_BR_PROB_BASE + all / 2) / all;
 
@@ -457,6 +480,9 @@ tree_mod_pow2_value_transform (tree stmt)
 
   /* Compute probability of taking the optimal path.  */
   all = count + wrong_values;
+  if (check_counter (stmt, "pow2", all, bb_for_stmt (stmt)->count))
+    return false;
+
   prob = (count * REG_BR_PROB_BASE + all / 2) / all;
 
   result = tree_mod_pow2 (stmt, op, op1, op2, prob, count, all);
@@ -631,6 +657,10 @@ tree_mod_subtract_transform (tree stmt)
   wrong_values += histogram->hvalue.counters[i+1];
   all += wrong_values;
 
+  /* Compute probability of taking the optimal path.  */
+  if (check_counter (stmt, "interval", all, bb_for_stmt (stmt)->count))
+    return false;
+
   /* We require that we use just subtractions in at least 50% of all
      evaluations.  */
   count = 0;