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]

[PATCH, PR 51362] Make IPA-CP not ICE if estimate_ipcp_clone_size_and_time returns zero size


Hi,

IPA-CP currently assumes that cloning estimates always have some
positive size cost.  However, there are apparently situations in which
estimate_ipcp_clone_size_and_time does return zero size and which then
mostly lead to divisions by zero or failed asserts.  This patch avoids
that by simply bumping the sizes to 1 in those cases.

Bootstrapped and tested on x86_64-linux. OK for trunk?

Thanks,

Martin


2011-12-12  Martin Jambor  <mjambor@suse.cz>

	PR tree-optimization/51362
	* ipa-cp.c (estimate_local_effects): When estimated size of a
	specialized clone is zero, bump it to one.

	* testsuite/gcc.dg/ipa/pr51362.c: New test.

Index: src/gcc/ipa-cp.c
===================================================================
--- src.orig/gcc/ipa-cp.c
+++ src/gcc/ipa-cp.c
@@ -1409,6 +1409,14 @@ estimate_local_effects (struct cgraph_no
 	    + devirtualization_time_bonus (node, known_csts, known_binfos)
 	    + removable_params_cost + emc;
 
+	  gcc_checking_assert (size >=0);
+	  /* The inliner-heuristics based estimates may think that in certain
+	     contexts some functions do not have any size at all but we want
+	     all specializations to have at least a tiny cost, not least not to
+	     divide by zero.  */
+	  if (size == 0)
+	    size = 1;
+
 	  if (dump_file && (dump_flags & TDF_DETAILS))
 	    {
 	      fprintf (dump_file, " - estimates for value ");
Index: src/gcc/testsuite/gcc.dg/ipa/pr51362.c
===================================================================
--- /dev/null
+++ src/gcc/testsuite/gcc.dg/ipa/pr51362.c
@@ -0,0 +1,22 @@
+/* { dg-do compile } */
+/* { dg-options "-O -fipa-cp -fipa-cp-clone" } */
+
+int
+baz (void)
+{
+  return 0;
+}
+
+int make_mess;
+
+__attribute__ ((noinline))
+int bar (int x, int (*f) (void))
+{
+  return f ();
+}
+
+int
+foo (void)
+{
+  return bar (1, baz);
+}


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