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]

Fix ICE in predictive commoning


This patch fixes an ICE in predictive commoning seen on
arm-none-linux-gnueabi.  (I do not know why it is target-dependent.)

The ICE arises from simple_iv being passed a NULL statement from
first_stmt (loop->header) called in ref_at_iteration, because the
block loop->header is empty.  In the 087t.loopinit dump we have

;; Loop 1
;;  header 4, latch 12

with nonempty block 4, but the next dump (088t.copyprop4) has empty
block 4, and this persists through the 089t.dceloop1 and 090t.lim
dumps before leading to the ICE.

As far as I can tell it's valid for basic blocks to be empty, so this
patch (which should only affect cases that previously ICEd) makes this
code pass from an empty block to its successor as many times as
needed.  Tested with no regressions with cross to
arm-none-linux-gnueabi.  OK to commit?

2009-02-14  Joseph Myers  <joseph@codesourcery.com>

	* tree-predcom.c (ref_at_iteration): Look for successor of empty
	loop header rather than passing NULL statement to simple_iv.

testsuite:
2009-02-14  Nathan Sidwell  <nathan@codesourcery.com>

	* g++.dg/torture/predcom-1.C: New test.

Index: tree-predcom.c
===================================================================
--- tree-predcom.c	(revision 144159)
+++ tree-predcom.c	(working copy)
@@ -1327,6 +1327,8 @@ ref_at_iteration (struct loop *loop, tre
 {
   tree idx, *idx_p, type, val, op0 = NULL_TREE, ret;
   affine_iv iv;
+  basic_block header;
+  gimple fs;
   bool ok;
 
   if (handled_component_p (ref))
@@ -1374,7 +1376,14 @@ ref_at_iteration (struct loop *loop, tre
   else
     return NULL_TREE;
 
-  ok = simple_iv (loop, first_stmt (loop->header), idx, &iv, true);
+  header = loop->header;
+  while ((fs = first_stmt (header)) == NULL)
+    {
+      if (!single_succ_p (header))
+	return NULL_TREE;
+      header = single_succ (header);
+    }
+  ok = simple_iv (loop, fs, idx, &iv, true);
   if (!ok)
     return NULL_TREE;
   iv.base = expand_simple_operations (iv.base);
Index: testsuite/g++.dg/torture/predcom-1.C
===================================================================
--- testsuite/g++.dg/torture/predcom-1.C	(revision 0)
+++ testsuite/g++.dg/torture/predcom-1.C	(revision 0)
@@ -0,0 +1,29 @@
+/* Test for ICE in predictive commoning with empty loop header block
+   on arm-none-linux-gnueabi.  */
+
+struct Foo
+{
+  double *ptr;
+  
+  Foo (double *ptr_)
+    : ptr (ptr_)
+  {
+  }
+  
+  Foo PostInc ()
+  {
+    return Foo (ptr++);
+  }
+};
+
+bool Baz (Foo first, double *last)
+{
+  Foo prev (first.ptr);
+  
+  first.ptr++;
+
+  while (first.ptr != last)
+    if (*first.PostInc ().ptr < *prev.PostInc ().ptr)
+      return false;
+}
+

-- 
Joseph S. Myers
joseph@codesourcery.com


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