diff mbox

[Committed,PR69108] Handle case that outer phi res is not used in a phi in gather_scalar_reductions

Message ID 56937629.5080307@mentor.com
State New
Headers show

Commit Message

Tom de Vries Jan. 11, 2016, 9:30 a.m. UTC
Hi,

when compiling interchange-2.c with ftree-parallelize-loops=2 we run 
into an ICE:
...
$ gcc -O2 src/gcc/testsuite/gcc.dg/graphite/interchange-2.c -S 
-ftree-parallelize-loops=2
interchange-2.c: In function ‘foo.constprop’:
interchange-2.c:13:1: internal compiler error: in as_a, at is-a.h:192
  foo (int N, int *res)
...


The problem is in the double reduction handling code added in r226300:
...
          bool single_use_p = single_imm_use (res, &use_p, &inner_stmt);
          gcc_assert (single_use_p);
          gphi *inner_phi = as_a <gphi *> (inner_stmt);
...

The code assumes that inner_stmt is a phi, but the ICE shows that it's 
possible that that's not the case.


The patch fixes the problem conservatively by testing if inner_stmt is a 
PHI, and handling the non-phi case.

Bootstrapped and reg-tested on x86_64.

Committed to trunk.

Thanks,
- Tom
diff mbox

Patch

Handle case that outer phi res is not used in a phi in gather_scalar_reductions

2016-01-07  Tom de Vries  <tom@codesourcery.com>

	PR tree-optimization/69108
	* tree-parloops.c (gather_scalar_reductions): Handle case that outer phi
	res is not used in a phi.

	* gcc.dg/autopar/pr69108.c: New test.

---
 gcc/testsuite/gcc.dg/autopar/pr69108.c | 4 ++++
 gcc/tree-parloops.c                    | 2 ++
 2 files changed, 6 insertions(+)

diff --git a/gcc/testsuite/gcc.dg/autopar/pr69108.c b/gcc/testsuite/gcc.dg/autopar/pr69108.c
new file mode 100644
index 0000000..39fc07e
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/autopar/pr69108.c
@@ -0,0 +1,4 @@ 
+/* { dg-do compile } */
+/* { dg-options "-O2 -ftree-parallelize-loops=2" } */
+
+#include "../graphite/interchange-2.c"
diff --git a/gcc/tree-parloops.c b/gcc/tree-parloops.c
index e05cc47..d683704 100644
--- a/gcc/tree-parloops.c
+++ b/gcc/tree-parloops.c
@@ -2474,6 +2474,8 @@  gather_scalar_reductions (loop_p loop, reduction_info_table_type *reduction_list
 	  gimple *inner_stmt;
 	  bool single_use_p = single_imm_use (res, &use_p, &inner_stmt);
 	  gcc_assert (single_use_p);
+	  if (gimple_code (inner_stmt) != GIMPLE_PHI)
+	    continue;
 	  gphi *inner_phi = as_a <gphi *> (inner_stmt);
 	  if (simple_iv (loop->inner, loop->inner, PHI_RESULT (inner_phi),
 			 &iv, true))