re PR tree-optimization/79740 (ICE on -Os and above in both 32-bit and 64-bit modes...
authorRichard Biener <rguenther@suse.de>
Tue, 28 Feb 2017 15:32:24 +0000 (15:32 +0000)
committerRichard Biener <rguenth@gcc.gnu.org>
Tue, 28 Feb 2017 15:32:24 +0000 (15:32 +0000)
2017-02-28  Richard Biener  <rguenther@suse.de>

PR tree-optimization/79740
* tree-ssa-sccvn.c (vn_nary_op_insert_into): Allow redundant
inserts.
(visit_nary_op): Insert the nary into the hashtable if we
pattern-matched sth.
* tree-ssa-pre.c (eliminate_insert): Robustify.

* gcc.dg/torture/pr79740.c: New testcase.

From-SVN: r245780

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/torture/pr79740.c [new file with mode: 0644]
gcc/tree-ssa-pre.c
gcc/tree-ssa-sccvn.c

index b65f820950f7bcbe28e62581a929a930f028a9e9..17acce53557e9e1e71a33a4b3304c233b6283cf4 100644 (file)
@@ -1,3 +1,12 @@
+2017-02-28  Richard Biener  <rguenther@suse.de>
+
+       PR tree-optimization/79740
+       * tree-ssa-sccvn.c (vn_nary_op_insert_into): Allow redundant
+       inserts.
+       (visit_nary_op): Insert the nary into the hashtable if we
+       pattern-matched sth.
+       * tree-ssa-pre.c (eliminate_insert): Robustify.
+
 2017-02-28  Richard Biener  <rguenther@suse.de>
 
        PR middle-end/79731
index 82933d379f034fc513869ad2a677fef7b3c6e329..a09eb286c97d2fde30cc280a5d6b824b094b8273 100644 (file)
@@ -1,3 +1,8 @@
+2017-02-28  Richard Biener  <rguenther@suse.de>
+
+       PR tree-optimization/79740
+       * gcc.dg/torture/pr79740.c: New testcase.
+
 2017-02-28  Richard Biener  <rguenther@suse.de>
 
        PR middle-end/79731
diff --git a/gcc/testsuite/gcc.dg/torture/pr79740.c b/gcc/testsuite/gcc.dg/torture/pr79740.c
new file mode 100644 (file)
index 0000000..25b8de5
--- /dev/null
@@ -0,0 +1,19 @@
+/* { dg-do compile } */
+
+int a;
+short b;
+short fn1(unsigned short p1) { return p1 << a; }
+
+int main()
+{
+  short c;
+  int d = 4;
+  for (; b;)
+    {
+      c = d + 1;
+      fn1(c);
+      d = 0;
+    }
+  d++;
+  return 0;
+}
index a1d76774fae7adb1c2c01911799f8985f74f9f78..bdf48ad7d8a1f8c0d92f3330a06689a739bbdc34 100644 (file)
@@ -4099,8 +4099,12 @@ eliminate_push_avail (tree op)
 static tree
 eliminate_insert (gimple_stmt_iterator *gsi, tree val)
 {
-  gimple *stmt = gimple_seq_first_stmt (VN_INFO (val)->expr);
-  if (!is_gimple_assign (stmt)
+  /* We can insert a sequence with a single assignment only.  */
+  gimple_seq stmts = VN_INFO (val)->expr;
+  if (!gimple_seq_singleton_p (stmts))
+    return NULL_TREE;
+  gassign *stmt = dyn_cast <gassign *> (gimple_seq_first_stmt (stmts));
+  if (!stmt
       || (!CONVERT_EXPR_CODE_P (gimple_assign_rhs_code (stmt))
          && gimple_assign_rhs_code (stmt) != VIEW_CONVERT_EXPR
          && gimple_assign_rhs_code (stmt) != BIT_FIELD_REF
@@ -4116,8 +4120,8 @@ eliminate_insert (gimple_stmt_iterator *gsi, tree val)
   if (!leader)
     return NULL_TREE;
 
-  gimple_seq stmts = NULL;
   tree res;
+  stmts = NULL;
   if (gimple_assign_rhs_code (stmt) == BIT_FIELD_REF)
     res = gimple_build (&stmts, BIT_FIELD_REF,
                        TREE_TYPE (val), leader,
index 4f5e85243bde2279d2e52a8b15facf48e0bad2a1..e7502de790ded9167ee68ee863f9c332b38c781d 100644 (file)
@@ -2820,6 +2820,15 @@ vn_nary_op_insert_into (vn_nary_op_t vno, vn_nary_op_table_type *table,
     vno->hashcode = vn_nary_op_compute_hash (vno);
 
   slot = table->find_slot_with_hash (vno, vno->hashcode, INSERT);
+  /* While we do not want to insert things twice it's awkward to
+     avoid it in the case where visit_nary_op pattern-matches stuff
+     and ends up simplifying the replacement to itself.  We then
+     get two inserts, one from visit_nary_op and one from
+     vn_nary_build_or_lookup.
+     So allow inserts with the same value number.  */
+  if (*slot && (*slot)->result == vno->result)
+    return *slot;
+
   gcc_assert (!*slot);
 
   *slot = vno;
@@ -3544,7 +3553,11 @@ visit_nary_op (tree lhs, gassign *stmt)
                          result = vn_nary_build_or_lookup (NOP_EXPR,
                                                            type, ops);
                          if (result)
-                           return set_ssa_val_to (lhs, result);
+                           {
+                             bool changed = set_ssa_val_to (lhs, result);
+                             vn_nary_op_insert_stmt (stmt, result);
+                             return changed;
+                           }
                        }
                      else
                        {
@@ -3555,7 +3568,11 @@ visit_nary_op (tree lhs, gassign *stmt)
                                                            TREE_TYPE (lhs),
                                                            ops);
                          if (result)
-                           return set_ssa_val_to (lhs, result);
+                           {
+                             bool changed = set_ssa_val_to (lhs, result);
+                             vn_nary_op_insert_stmt (stmt, result);
+                             return changed;
+                           }
                        }
                    }
                }