diff mbox

Fix segfault in param_change_prob

Message ID 10302256.3lkbZ9nWaB@arcturus.home
State New
Headers show

Commit Message

Eric Botcazou Sept. 1, 2016, 1:17 p.m. UTC
> So I think it's better to apply get_base_address here rather than only
> stripping VIEW_CONVERT_EXRPs.
> (beware of it returning NULL_TREE for WITH_SIZE_EXPRs, thus maybe
> strip those first as well)

Something like this?  The testsuite is still clean with it.


	* ipa-inline-analysis.c (param_change_prob): Get to the base object
	first in all cases.

Comments

Richard Biener Sept. 1, 2016, 1:37 p.m. UTC | #1
On Thu, Sep 1, 2016 at 3:17 PM, Eric Botcazou <ebotcazou@adacore.com> wrote:
>> So I think it's better to apply get_base_address here rather than only
>> stripping VIEW_CONVERT_EXRPs.
>> (beware of it returning NULL_TREE for WITH_SIZE_EXPRs, thus maybe
>> strip those first as well)
>
> Something like this?  The testsuite is still clean with it.

Yes.

Thanks,
Richard.

>
>         * ipa-inline-analysis.c (param_change_prob): Get to the base object
>         first in all cases.
>
> --
> Eric Botcazou
diff mbox

Patch

Index: ipa-inline-analysis.c
===================================================================
--- ipa-inline-analysis.c	(revision 239842)
+++ ipa-inline-analysis.c	(working copy)
@@ -2183,11 +2183,16 @@  param_change_prob (gimple *stmt, int i)
 {
   tree op = gimple_call_arg (stmt, i);
   basic_block bb = gimple_bb (stmt);
-  tree base;
 
-  /* Global invariants neve change.  */
-  if (is_gimple_min_invariant (op))
+  if (TREE_CODE (op) == WITH_SIZE_EXPR)
+    op = TREE_OPERAND (op, 0);
+
+  tree base = get_base_address (op);
+
+  /* Global invariants never change.  */
+  if (is_gimple_min_invariant (base))
     return 0;
+
   /* We would have to do non-trivial analysis to really work out what
      is the probability of value to change (i.e. when init statement
      is in a sibling loop of the call). 
@@ -2194,7 +2199,7 @@  param_change_prob (gimple *stmt, int i)
 
      We do an conservative estimate: when call is executed N times more often
      than the statement defining value, we take the frequency 1/N.  */
-  if (TREE_CODE (op) == SSA_NAME)
+  if (TREE_CODE (base) == SSA_NAME)
     {
       int init_freq;
 
@@ -2201,10 +2206,10 @@  param_change_prob (gimple *stmt, int i)
       if (!bb->frequency)
 	return REG_BR_PROB_BASE;
 
-      if (SSA_NAME_IS_DEFAULT_DEF (op))
+      if (SSA_NAME_IS_DEFAULT_DEF (base))
 	init_freq = ENTRY_BLOCK_PTR_FOR_FN (cfun)->frequency;
       else
-	init_freq = gimple_bb (SSA_NAME_DEF_STMT (op))->frequency;
+	init_freq = gimple_bb (SSA_NAME_DEF_STMT (base))->frequency;
 
       if (!init_freq)
 	init_freq = 1;
@@ -2213,9 +2218,7 @@  param_change_prob (gimple *stmt, int i)
       else
 	return REG_BR_PROB_BASE;
     }
-
-  base = get_base_address (op);
-  if (base)
+  else
     {
       ao_ref refd;
       int max;
@@ -2256,7 +2259,6 @@  param_change_prob (gimple *stmt, int i)
       else
 	return REG_BR_PROB_BASE;
     }
-  return REG_BR_PROB_BASE;
 }
 
 /* Find whether a basic block BB is the final block of a (half) diamond CFG