cap frequency in make_forwarder_block
authorTrevor Saunders <tsaunders@mozilla.com>
Tue, 10 Feb 2015 14:49:07 +0000 (14:49 +0000)
committerTrevor Saunders <tbsaunde@gcc.gnu.org>
Tue, 10 Feb 2015 14:49:07 +0000 (14:49 +0000)
In the testcase the block with problematic frequency has to incoming
edges.  Each edge has probability 1.  The first edge's source bb has
frequency 873/10000, and the second has a frequency of 9409/10000.  So
at least one of those is slightly high probably from some sort of rounding
issue related to fixed point, but in any case make_forwarder_block
should not create basic blocks with frequency greater than BB_FREQ_MAX.

gcc/

PR tree-optimization/64326
* cfghooks.c (make_forwarder_block): Cap frequency of created
basic block.

From-SVN: r220585

gcc/ChangeLog
gcc/cfghooks.c
gcc/testsuite/gcc.dg/torture/pr64326.c [new file with mode: 0644]

index 72fbdd7..50fa380 100644 (file)
@@ -1,3 +1,8 @@
+2015-02-10  Trevor Saunders  <tsaunders@mozilla.com>
+
+       PR tree-optimization/64326
+       * cfghooks.c (make_forwarder_block): Cap frequency of created block.
+
 2015-02-10  Rainer Emrich  <rainer@emrich-ebersheim.de>
 
        PR gcov-profile/61889
index 4b57280..abeab8c 100644 (file)
@@ -863,6 +863,9 @@ make_forwarder_block (basic_block bb, bool (*redirect_edge_p) (edge),
       if (redirect_edge_p (e))
        {
          dummy->frequency += EDGE_FREQUENCY (e);
+         if (dummy->frequency > BB_FREQ_MAX)
+           dummy->frequency = BB_FREQ_MAX;
+
          dummy->count += e->count;
          fallthru->count += e->count;
          ei_next (&ei);
diff --git a/gcc/testsuite/gcc.dg/torture/pr64326.c b/gcc/testsuite/gcc.dg/torture/pr64326.c
new file mode 100644 (file)
index 0000000..88ebf35
--- /dev/null
@@ -0,0 +1,30 @@
+/* { dg-do compile } */
+
+int a, b, c, d, e, f[5][2];
+char g;
+
+int
+fn1 ()
+{
+         return d && c ? 0 : 1;
+}
+
+int
+fn2 ()
+{
+         int h;
+           for (;;)
+                       for (; e;)
+                                     {
+                                                     int i, j;
+                                                             h = a ? 1 : b;
+                                                                     if (h || fn1 () ^ g - 682)
+                                                                                       {
+                                                                                                           for (i = 0; i < 5; i++)
+                                                                                                                                 for (j = 0; j < 2; j++)
+                                                                                                                                                         f[i][j] = 0;
+                                                                                                                       return 0;
+                                                                                                                                 }
+                                                                           }
+}
+