possible negative patch for gcc/tree-ssa-loop-im.c (or removal of an assert)

Gaius Mulley gaius.mulley@southwales.ac.uk
Fri Jul 11 16:53:00 GMT 2014



Hello,

I've been looking through tree-ssa-loop-im.c (while hunting down a bug
in the modula-2 front end) and found a curiosity in
gcc/tree-ssa-loop-im.c.

It seems that there is dead code in function determine_max_movement
as mem_ref_in_stmt can never return NULL.


static mem_ref_p
mem_ref_in_stmt (gimple stmt)
{
  ...

  gcc_assert (ref != NULL);
  return ref;
}

so the patch below could logically be applied as the else statement is
currently unreachable.



--- tree-ssa-loop-im.c.orig	2014-07-11 16:54:41.000000000 +0100
+++ tree-ssa-loop-im.c	2014-07-11 16:55:38.000000000 +0100
@@ -798,21 +798,11 @@
     {
       mem_ref_p ref = mem_ref_in_stmt (stmt);
 
-      if (ref)
-	{
-	  lim_data->max_loop
-		  = outermost_indep_loop (lim_data->max_loop, loop, ref);
-	  if (!lim_data->max_loop)
-	    return false;
-	}
-      else
-	{
-	  if ((val = gimple_vuse (stmt)) != NULL_TREE)
-	    {
-	      if (!add_dependency (val, lim_data, loop, false))
-		return false;
-	    }
-	}
+      gcc_assert (ref != NULL);
+      lim_data->max_loop
+	= outermost_indep_loop (lim_data->max_loop, loop, ref);
+      if (!lim_data->max_loop)
+	return false;
     }
 
   lim_data->cost += stmt_cost (stmt);


However my question is whether the assert in mem_ref_in_stmt is correct?
Since the author of determine_max_movement must have thought ref could
be NULL.

Anyhow, it seems that either the above patch should be applied or the
'gcc_assert (ref != NULL);' from mem_ref_p should be removed.

regards,
Gaius



More information about the Gcc-patches mailing list