This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Fix ICE caused by calling optimize_function_for_speed_p (NULL) (PR middle-end/37414)
- From: Jakub Jelinek <jakub at redhat dot com>
- To: Jan Hubicka <jh at suse dot cz>
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Mon, 8 Sep 2008 09:17:48 -0400
- Subject: [PATCH] Fix ICE caused by calling optimize_function_for_speed_p (NULL) (PR middle-end/37414)
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
Hi!
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.
2008-09-08 Jakub Jelinek <jakub@redhat.com>
PR middle-end/37414
* fold-const.c (fold_binary): Don't call optimize_function_for_speed_p
if cfun == NULL.
--- gcc/fold-const.c.jj 2008-09-05 12:56:31.000000000 +0200
+++ gcc/fold-const.c 2008-09-08 15:07:26.000000000 +0200
@@ -10411,7 +10411,7 @@ fold_binary (enum tree_code code, tree t
}
/* Optimize x*x as pow(x,2.0), which is expanded as x*x. */
- if (optimize_function_for_speed_p (cfun)
+ if ((!cfun || optimize_function_for_speed_p (cfun))
&& operand_equal_p (arg0, arg1, 0))
{
tree powfn = mathfn_built_in (type, BUILT_IN_POW);
--- 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