Patchwork Fix PR48186

login
register
mail settings
Submitter Marek Polacek
Date April 4, 2013, 2 p.m.
Message ID <20130404140048.GC24873@redhat.com>
Download mbox | patch
Permalink /patch/233830/
State New
Headers show

Comments

Marek Polacek - April 4, 2013, 2 p.m.
Another case where we got a SIGFPE if HOT_BB_FREQUENCY_FRACTION
is 0 - in that case we divide by zero.

Regtested/bootstrapped on x86_64-linux, ok for trunk/4.8?

2013-04-04  Marek Polacek  <polacek@redhat.com>

	PR tree-optimization/48186
	* predict.c (maybe_hot_frequency_p): Return false if
	HOT_BB_FREQUENCY_FRACTION is 0.
	(cgraph_maybe_hot_edge_p): Likewise.

	* gcc.dg/pr48186.c: New test.


	Marek
Jakub Jelinek - April 4, 2013, 2:06 p.m.
On Thu, Apr 04, 2013 at 04:00:48PM +0200, Marek Polacek wrote:
> --- gcc/predict.c.mp	2013-04-04 15:04:29.925685185 +0200
> +++ gcc/predict.c	2013-04-04 15:04:33.123696281 +0200
> @@ -122,6 +122,8 @@ maybe_hot_frequency_p (struct function *
>    if (node->frequency == NODE_FREQUENCY_EXECUTED_ONCE
>        && freq < (ENTRY_BLOCK_PTR_FOR_FUNCTION (fun)->frequency * 2 / 3))
>      return false;
> +  if (PARAM_VALUE (HOT_BB_FREQUENCY_FRACTION) == 0)
> +    return false;
>    if (freq < (ENTRY_BLOCK_PTR_FOR_FUNCTION (fun)->frequency
>  	      / PARAM_VALUE (HOT_BB_FREQUENCY_FRACTION)))
>      return false;
> @@ -202,6 +204,8 @@ cgraph_maybe_hot_edge_p (struct cgraph_e
>    if (edge->caller->frequency == NODE_FREQUENCY_EXECUTED_ONCE
>        && edge->frequency < CGRAPH_FREQ_BASE * 3 / 2)
>      return false;
> +  if (PARAM_VALUE (HOT_BB_FREQUENCY_FRACTION) == 0)
> +    return false;
>    if (flag_guess_branch_prob
>        && edge->frequency <= (CGRAPH_FREQ_BASE
>        			     / PARAM_VALUE (HOT_BB_FREQUENCY_FRACTION)))

In this second hunk the division is done only for flag_guess_branch_prob,
so shouldn't it be
  if (flag_guess_branch_prob)
    {
      if (PARAM_VALUE (HOT_BB_FREQUENCY_FRACTION) == 0
	  || edge->frequency <= (CGRAPH_FREQ_BASE
				 / PARAM_VALUE (HOT_BB_FREQUENCY_FRACTION)))
	return false;
    }
  return true;
instead?

> --- gcc/testsuite/gcc.dg/pr48186.c.mp	2013-04-04 15:04:20.775652932 +0200
> +++ gcc/testsuite/gcc.dg/pr48186.c	2013-04-04 14:58:08.038050087 +0200
> @@ -0,0 +1,5 @@
> +/* PR tree-optimization/48186 */
> +/* { dg-do compile } */
> +/* { dg-options "-O --param hot-bb-frequency-fraction=0" } */
> +
> +void foo (void) { }
> 
> 	Marek

	Jakub

Patch

--- gcc/predict.c.mp	2013-04-04 15:04:29.925685185 +0200
+++ gcc/predict.c	2013-04-04 15:04:33.123696281 +0200
@@ -122,6 +122,8 @@  maybe_hot_frequency_p (struct function *
   if (node->frequency == NODE_FREQUENCY_EXECUTED_ONCE
       && freq < (ENTRY_BLOCK_PTR_FOR_FUNCTION (fun)->frequency * 2 / 3))
     return false;
+  if (PARAM_VALUE (HOT_BB_FREQUENCY_FRACTION) == 0)
+    return false;
   if (freq < (ENTRY_BLOCK_PTR_FOR_FUNCTION (fun)->frequency
 	      / PARAM_VALUE (HOT_BB_FREQUENCY_FRACTION)))
     return false;
@@ -202,6 +204,8 @@  cgraph_maybe_hot_edge_p (struct cgraph_e
   if (edge->caller->frequency == NODE_FREQUENCY_EXECUTED_ONCE
       && edge->frequency < CGRAPH_FREQ_BASE * 3 / 2)
     return false;
+  if (PARAM_VALUE (HOT_BB_FREQUENCY_FRACTION) == 0)
+    return false;
   if (flag_guess_branch_prob
       && edge->frequency <= (CGRAPH_FREQ_BASE
       			     / PARAM_VALUE (HOT_BB_FREQUENCY_FRACTION)))
--- gcc/testsuite/gcc.dg/pr48186.c.mp	2013-04-04 15:04:20.775652932 +0200
+++ gcc/testsuite/gcc.dg/pr48186.c	2013-04-04 14:58:08.038050087 +0200
@@ -0,0 +1,5 @@ 
+/* PR tree-optimization/48186 */
+/* { dg-do compile } */
+/* { dg-options "-O --param hot-bb-frequency-fraction=0" } */
+
+void foo (void) { }