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 83615edeeb2ea5dea70d7e53e3dac4b4506aae04..15129d98b53a1d9b7a6fa84e9d80c8c55940a7da 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 0374608b554e03995882494d07944150ab385d40..8535df42f0cd56cc3b0ec8c8c598fb65b8257f10 100644 (file)
@@ -1,3 +1,8 @@
+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
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 f89da708f42e4e2d1555e9db0b27cd25e657977c..084b2e1dace4baf3ceeeb57f6b99c25c24d4cbcf 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)