PR middle-end/37414
authorjakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 8 Sep 2008 21:30:23 +0000 (21:30 +0000)
committerjakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 8 Sep 2008 21:30:23 +0000 (21:30 +0000)
* 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.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@140122 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ChangeLog
gcc/fold-const.c
gcc/predict.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/opt/init2.C [new file with mode: 0644]

index 2242afc..60ff6e9 100644 (file)
@@ -1,3 +1,12 @@
+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.
+
 2008-09-08  Eric Botcazou  <ebotcazou@adacore.com>
 
        * ira-color.c (ira_reuse_stack_slot): Set slot_num on success at the
index 7c4c522..aea7a65 100644 (file)
@@ -5110,7 +5110,7 @@ fold_cond_expr_with_comparison (tree type, tree arg0, tree arg1, tree arg2)
 \f
 #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 truth_type, tree lhs, tree rhs)
      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, const_tree arg1, bool reorder)
   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
index b69934f..5ed6c43 100644 (file)
@@ -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.  */
index dc19015..f5aec00 100644 (file)
@@ -1,5 +1,8 @@
 2008-09-08  Jakub Jelinek  <jakub@redhat.com>
 
+       PR middle-end/37414
+       * g++.dg/opt/init2.C: New test.
+
        PR middle-end/37337
        * g++.dg/tree-ssa/pr37337.C: New test.
 
diff --git a/gcc/testsuite/g++.dg/opt/init2.C b/gcc/testsuite/g++.dg/opt/init2.C
new file mode 100644 (file)
index 0000000..3c3bc93
--- /dev/null
@@ -0,0 +1,6 @@
+// PR middle-end/37414
+// { dg-do compile }
+// { dg-options "-O2 -ffast-math" }
+
+double x = 6.0;
+double y = x * x;