diff mbox

Fix PR78542

Message ID alpine.LSU.2.11.1611281343270.5294@t29.fhfr.qr
State New
Headers show

Commit Message

Richard Biener Nov. 28, 2016, 12:47 p.m. UTC
The following fixes another issue with marrying the SSA propagator
and match-and-simplify during propagation (which is tricky at best).

Bootstrap and regtest running on x86_64-unknown-linux-gnu, I've
applied the VRP patch below as well to see if the theory works
out (VRP misses to handle simplifications to copies during
propagation).  I'm considering that change for and the fix
for GCC 6 where the issue is latent.

Richard.

2016-11-28  Richard Biener  <rguenther@suse.de>

	PR tree-optimization/78542
	* tree-ssa-ccp.c (evaluate_stmt): Only valueize simplification
	if allowed.

	* gcc.dg/torture/pr78542.c: New testcase.
diff mbox

Patch

Index: gcc/tree-ssa-ccp.c
===================================================================
--- gcc/tree-ssa-ccp.c	(revision 242913)
+++ gcc/tree-ssa-ccp.c	(working copy)
@@ -1744,7 +1744,12 @@  evaluate_stmt (gimple *stmt)
     {
       fold_defer_overflow_warnings ();
       simplified = ccp_fold (stmt);
-      if (simplified && TREE_CODE (simplified) == SSA_NAME)
+      if (simplified
+	  && TREE_CODE (simplified) == SSA_NAME
+	  /* We may not use values of something that may be simulated again,
+	     see valueize_op_1.  */
+	  && (SSA_NAME_IS_DEFAULT_DEF (simplified)
+	      || ! prop_simulate_again_p (SSA_NAME_DEF_STMT (simplified))))
 	{
 	  ccp_prop_value_t *val = get_value (simplified);
 	  if (val && val->lattice_val != VARYING)
Index: gcc/testsuite/gcc.dg/torture/pr78542.c
===================================================================
--- gcc/testsuite/gcc.dg/torture/pr78542.c	(revision 0)
+++ gcc/testsuite/gcc.dg/torture/pr78542.c	(revision 0)
@@ -0,0 +1,23 @@ 
+/* { dg-do run } */
+/* { dg-additional-options "-w -Wno-psabi" } */
+
+typedef unsigned V __attribute__ ((vector_size (16)));
+
+V
+foo (unsigned x, V v)
+{
+  do {
+      v %= x;
+      x = 1;
+  } while (v[1]);
+  return v;
+}
+
+int
+main ()
+{
+  V x = foo (5, (V) { 0, 1 });
+  if (x[0] || x[1] || x[2] || x[3])
+    __builtin_abort();
+  return 0;
+}



2016-11-28  Richard Biener  <rguenther@suse.de>

	* tree-vrp.c (vrp_visit_assignment_or_call): Handle
	simplifications to SSA names via extract_range_from_ssa_name
	if allowed.

Index: gcc/tree-vrp.c
===================================================================
--- gcc/tree-vrp.c	(revision 242913)
+++ gcc/tree-vrp.c	(working copy)
@@ -7132,17 +7132,31 @@  vrp_visit_assignment_or_call (gimple *st
 	   && TYPE_MAX_VALUE (TREE_TYPE (lhs)))
 	  || POINTER_TYPE_P (TREE_TYPE (lhs))))
     {
+      *output_p = lhs;
+
       /* Try folding the statement to a constant first.  */
       tree tem = gimple_fold_stmt_to_constant_1 (stmt, vrp_valueize,
 						 vrp_valueize_1);
-      if (tem && is_gimple_min_invariant (tem))
-	set_value_range_to_value (vr, tem, NULL);
+      if (tem)
+	{
+	  if (TREE_CODE (tem) == SSA_NAME
+	      && (SSA_NAME_IS_DEFAULT_DEF (tem)
+		  || ! prop_simulate_again_p (SSA_NAME_DEF_STMT (tem))))
+	    {
+	      extract_range_from_ssa_name (vr, tem);
+	      return;
+	    }
+	  else if (is_gimple_min_invariant (tem))
+	    {
+	      set_value_range_to_value (vr, tem, NULL);
+	      return;
+	    }
+	}
       /* Then dispatch to value-range extracting functions.  */
-      else if (code == GIMPLE_CALL)
+      if (code == GIMPLE_CALL)
 	extract_range_basic (vr, stmt);
       else
 	extract_range_from_assignment (vr, as_a <gassign *> (stmt));
-      *output_p = lhs;
     }
 }