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]

Re: [PATCH] Fix ICE caused by calling optimize_function_for_speed_p (NULL) (PR middle-end/37414)


On Mon, Sep 08, 2008 at 09:17:48AM -0400, Jakub Jelinek wrote:
> This patch fixes ICE on the attached testcase the same way other
> places in fold-const.c handle it, namely assuming that cfun == NULL
> implies optimization for speed.  I'm not convinced that is a good idea
> though, IMHO it would be better if optimize_function_for_s{peed,ize}_p
> handled NULL argument and just returned {!,}optimize_size in that case.
> I'm pretty sure one can construct testcases that would ICE e.g. on
> all 3 optimize_function_for_s*_p calls in builtins.c.

Here is an alternative patch that handles fun == NULL in
optimize_function_for_{size,speed}_p instead.  Bootstrapped/regtested on
x86_64-linux, ok for trunk?

2008-09-08  Jakub Jelinek  <jakub@redhat.com>

	PR middle-end/37414
	* predict.c (optimize_function_for_size_p): Don't segfault if
	FUN is NULL.
	* fold-const.c (LOGICAL_OP_NON_SHORT_CIRCUIT, fold_truthop,
	tree_swap_operands_p): Don't test cfun != NULL before calling
	optimize_function_for_s*_p.

	* g++.dg/opt/init2.C: New test.

--- gcc/predict.c.jj	2008-09-05 12:56:32.000000000 +0200
+++ gcc/predict.c	2008-09-08 17:42:25.000000000 +0200
@@ -203,7 +203,8 @@ bool
 optimize_function_for_size_p (struct function *fun)
 {
   return (optimize_size
-	  || fun->function_frequency == FUNCTION_FREQUENCY_UNLIKELY_EXECUTED);
+	  || (fun && (fun->function_frequency
+		      == FUNCTION_FREQUENCY_UNLIKELY_EXECUTED)));
 }
 
 /* Return true when current function should always be optimized for speed.  */
--- gcc/fold-const.c.jj	2008-09-05 12:56:31.000000000 +0200
+++ gcc/fold-const.c	2008-09-08 17:43:33.000000000 +0200
@@ -5110,7 +5110,7 @@ fold_cond_expr_with_comparison (tree typ
 
 #ifndef LOGICAL_OP_NON_SHORT_CIRCUIT
 #define LOGICAL_OP_NON_SHORT_CIRCUIT \
-  (BRANCH_COST (!cfun || optimize_function_for_speed_p (cfun), \
+  (BRANCH_COST (optimize_function_for_speed_p (cfun), \
 		false) >= 2)
 #endif
 
@@ -5359,7 +5359,7 @@ fold_truthop (enum tree_code code, tree 
      that can be merged.  Avoid doing this if the RHS is a floating-point
      comparison since those can trap.  */
 
-  if (BRANCH_COST (!cfun || optimize_function_for_speed_p (cfun),
+  if (BRANCH_COST (optimize_function_for_speed_p (cfun),
 		   false) >= 2
       && ! FLOAT_TYPE_P (TREE_TYPE (rl_arg))
       && simple_operand_p (rl_arg)
@@ -6682,7 +6682,7 @@ tree_swap_operands_p (const_tree arg0, c
   if (TREE_CONSTANT (arg0))
     return 1;
 
-  if (cfun && optimize_function_for_size_p (cfun))
+  if (optimize_function_for_size_p (cfun))
     return 0;
 
   if (reorder && flag_evaluation_order
--- gcc/testsuite/g++.dg/opt/init2.C.jj	2008-09-08 15:03:28.000000000 +0200
+++ gcc/testsuite/g++.dg/opt/init2.C	2008-09-08 15:02:04.000000000 +0200
@@ -0,0 +1,6 @@
+// PR middle-end/37414
+// { dg-do compile }
+// { dg-options "-O2 -ffast-math" }
+
+double x = 6.0;
+double y = x * x;


	Jakub


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