diff mbox

[Committed,trunk/6] Handle NULL def in build_cross_bb_scalars_def

Message ID 572D95CB.9020908@mentor.com
State New
Headers show

Commit Message

Tom de Vries May 7, 2016, 7:14 a.m. UTC
Hi,

Attached patch fixes a graphite 6/7 regression.

[ found regression by doing an fgraphite-identity on-by-default 
bootstrap and regtest on x86_64. ]

When compiling gcc.dg/tree-ssa/vrp66.c with -O2 fgraphite-identity, we 
arrive at graphite_find_cross_bb_scalar_vars:
...
static void
graphite_find_cross_bb_scalar_vars (scop_p scop, gimple *stmt,
                                     vec<scalar_use> *reads, vec<tree> 
*writes)
{
   tree def;

   if (gimple_code (stmt) == GIMPLE_ASSIGN)
     def = gimple_assign_lhs (stmt);
   else if (gimple_code (stmt) == GIMPLE_CALL)
     def = gimple_call_lhs (stmt);
   else if (gimple_code (stmt) == GIMPLE_PHI)
     def = gimple_phi_result (stmt);
   else
     return;


   build_cross_bb_scalars_def (scop, def, gimple_bb (stmt), writes);
   ...
...


with as stmt a resultless call:
...
(gdb) call debug_gimple_stmt (stmt)
# VUSE <.MEM_10(D)>
f2 (_1);
...

Consequently, def becomes NULL_TREE and we run into an assert at the 
start of build_cross_bb_scalars_def that asserts that def is not NULL_TREE.

This patch fixes the ICE by handling a NULL_TREE def in 
build_cross_bb_scalars_def.

Bootstrapped and reg-tested on x86_64.

Approved at https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70956#c2 .

Committed to trunk, backported to 6 branch.

Thanks,
- Tom
diff mbox

Patch

Handle NULL def in build_cross_bb_scalars_def

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

	PR tree-optimization/70956
	* graphite-scop-detection.c (build_cross_bb_scalars_def): Handle NULL
	def.

	* gcc.dg/graphite/pr70956.c: New test.

---
 gcc/graphite-scop-detection.c           | 3 +--
 gcc/testsuite/gcc.dg/graphite/pr70956.c | 4 ++++
 2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/gcc/graphite-scop-detection.c b/gcc/graphite-scop-detection.c
index 7615842..dd50a1e 100644
--- a/gcc/graphite-scop-detection.c
+++ b/gcc/graphite-scop-detection.c
@@ -1722,8 +1722,7 @@  static void
 build_cross_bb_scalars_def (scop_p scop, tree def, basic_block def_bb,
 			     vec<tree> *writes)
 {
-  gcc_assert (def);
-  if (!is_gimple_reg (def))
+  if (!def || !is_gimple_reg (def))
     return;
 
   /* Do not gather scalar variables that can be analyzed by SCEV as they can be
diff --git a/gcc/testsuite/gcc.dg/graphite/pr70956.c b/gcc/testsuite/gcc.dg/graphite/pr70956.c
new file mode 100644
index 0000000..31fc25f
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/graphite/pr70956.c
@@ -0,0 +1,4 @@ 
+/* { dg-do compile } */
+/* { dg-options "-O2 -fgraphite-identity" } */
+
+#include "../tree-ssa/vrp66.c"