re PR tree-optimization/78542 (wrong code at -Og results in endless loop)
authorRichard Biener <rguenther@suse.de>
Mon, 28 Nov 2016 15:03:55 +0000 (15:03 +0000)
committerRichard Biener <rguenth@gcc.gnu.org>
Mon, 28 Nov 2016 15:03:55 +0000 (15:03 +0000)
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.

From-SVN: r242920

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/torture/pr78542.c [new file with mode: 0644]
gcc/tree-ssa-ccp.c

index 83615ed..15129d9 100644 (file)
@@ -1,3 +1,9 @@
+2016-11-28  Richard Biener  <rguenther@suse.de>
+
+       PR tree-optimization/78542
+       * tree-ssa-ccp.c (evaluate_stmt): Only valueize simplification
+       if allowed.
+
 2016-11-28  Paolo Bonzini  <bonzini@gnu.org>
 
        * combine.c (simplify_if_then_else): Simplify IF_THEN_ELSE
index 0374608..8535df4 100644 (file)
@@ -1,5 +1,10 @@
 2016-11-28  Richard Biener  <rguenther@suse.de>
 
+       PR tree-optimization/78542
+       * gcc.dg/torture/pr78542.c: New testcase.
+
+2016-11-28  Richard Biener  <rguenther@suse.de>
+
        PR tree-optimization/78343
        * gcc.dg/tree-ssa/20030808-1.c: Fix dump to generate.
        * gcc.dg/tree-ssa/20040305-1.c: Likewise.
diff --git a/gcc/testsuite/gcc.dg/torture/pr78542.c b/gcc/testsuite/gcc.dg/torture/pr78542.c
new file mode 100644 (file)
index 0000000..bae42b6
--- /dev/null
@@ -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;
+}
index f89da70..084b2e1 100644 (file)
@@ -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)