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]

[committed] Fix ICE in slsr (PR tree-optimization/83293)


Hi!

We don't really care about gsi after this statement, and GSI_SAME_STMT
on gsi_insert_after is wrong if the bb we're inserting into is empty.
So, either we'd need to use the gsi_insert_before with GSI_SAME_STMT in that
case by tweaking the if, or we just tweak the last argument.

Bootstrapped/regtested on x86_64-linux and i686-linux, acked by Richard in
the PR, committed to trunk.

2017-12-06  Jakub Jelinek  <jakub@redhat.com>

	PR tree-optimization/83293
	* gimple-ssa-strength-reduction.c (insert_initializers): Use
	GSI_NEW_STMT instead of GSI_SAME_STMT in gsi_insert_after that
	might insert into empty bb.

	* g++.dg/torture/pr83293.C: New test.

--- gcc/gimple-ssa-strength-reduction.c.jj	2017-09-29 19:43:49.000000000 +0200
+++ gcc/gimple-ssa-strength-reduction.c	2017-12-06 09:59:37.297580426 +0100
@@ -3418,7 +3418,7 @@ insert_initializers (slsr_cand_t c)
 		  gsi_insert_after (&gsi, cast_stmt, GSI_NEW_STMT);
 		  gimple_set_location (cast_stmt, loc);
 		}
-	      gsi_insert_after (&gsi, init_stmt, GSI_SAME_STMT);
+	      gsi_insert_after (&gsi, init_stmt, GSI_NEW_STMT);
 	    }
 
 	  gimple_set_location (init_stmt, gimple_location (basis_stmt));
--- gcc/testsuite/g++.dg/torture/pr83293.C.jj	2017-12-06 10:05:50.540961244 +0100
+++ gcc/testsuite/g++.dg/torture/pr83293.C	2017-12-06 10:05:24.000000000 +0100
@@ -0,0 +1,39 @@
+// PR tree-optimization/83293
+
+typedef __SIZE_TYPE__ size_t;
+template <typename T, typename> struct A {
+  T a;
+  A (T x) : a(x) {}
+  T foo () { return a; }
+};
+
+template <typename T, typename U, typename V>
+int
+operator==(A<T, V> x, A<U, V> p2)
+{
+  return x.foo () == p2.foo ();
+}
+
+struct B { struct { int *b, *c; } d; };
+struct C : B {
+  A<int *, int> bar () { return d.b; }
+  A<int *, int> baz () { return d.c; }
+  size_t boo () { return d.c - d.b; }
+  int zoo () { return bar () == baz (); }
+};
+struct D { C e; } a;
+size_t b;
+
+size_t
+test (int x)
+{
+  size_t c (x * b);
+  if (!a.e.zoo ())
+    {
+      x += 2;
+      for (size_t d = 0, e = a.e.boo (); d < e; ++d)
+	c += test (0);
+    }
+  c += (x - 1) * b;
+  return c;
+}

	Jakub


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