diff mbox

[PR,tree-optimization/65241] Do not modify DOM's hash table if ! inserting

Message ID 54F5A0AF.9020400@redhat.com
State New
Headers show

Commit Message

Jeff Law March 3, 2015, 11:53 a.m. UTC
As outlined in the PR, a relatively recent change to DOM unconditionally 
modifies the available expression hash table after a partial hit, but a 
failure by the alias walker to find an available expression.

This interacts badly with jump threading which modifies gimple 
statements in-place, tries to look them up in the hash table (without 
changing the state of the hash table), then restores the statements to 
their original state.

This patch makes the code which updates the hash table in 
lookup_avail_expr only do so if INSERT is true.

Bootstrapped and regression tested on x86_64-unknown-linux-gnu.  Applied 
on the trunk.

Jeff
commit 99dddeb179c56e8876f6d266829db394c950e2ee
Author: Jeff Law <law@redhat.com>
Date:   Tue Mar 3 04:51:50 2015 -0700

    	PR tree-optimization/65241
    	* tree-ssa-dom.c (lookup_avail_expr): Only modify the avail_expr
    	hash table if INSERT is true.
    
    	PR tree-optimization/65241
    	* gcc.c-torture/compile/pr65241.c: New test.
diff mbox

Patch

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 55c106c..cb42917 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,9 @@ 
+2015-03-23  Jeff Law  <law@redhat.com>
+
+	PR tree-optimization/65241
+	* tree-ssa-dom.c (lookup_avail_expr): Only modify the avail_expr
+	hash table if INSERT is true.
+
 2015-03-03  Georg-Johann Lay  <avr@gjlay.de>
 
 	PR target/65296
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index ecc4cc4..824d256 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@ 
+2015-03-13  Jeff Law  <law@redhat.com>
+
+	PR tree-optimization/65241
+	* gcc.c-torture/compile/pr65241.c: New test.
+
 2015-03-03  Georg-Johann Lay  <avr@gjlay.de>
 
 	PR target/64331
diff --git a/gcc/testsuite/gcc.c-torture/compile/pr65241.c b/gcc/testsuite/gcc.c-torture/compile/pr65241.c
new file mode 100644
index 0000000..dd76ac5
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/compile/pr65241.c
@@ -0,0 +1,26 @@ 
+enum E { A, B, C, D };
+void fn4 (void);
+
+int
+fn1 (enum E p1)
+{
+  static int w[D];
+  if (w[p1])
+    switch (p1)
+      case C:
+      w[p1] = 0;
+}
+
+void
+fn2 (p1)
+{
+  fn1 (p1);
+}
+
+void
+fn3 (enum E p1)
+{
+  fn2 (p1);
+  fn4 ();
+  fn2 (p1);
+}
diff --git a/gcc/tree-ssa-dom.c b/gcc/tree-ssa-dom.c
index 096e471..d230ce1 100644
--- a/gcc/tree-ssa-dom.c
+++ b/gcc/tree-ssa-dom.c
@@ -2649,19 +2649,22 @@  lookup_avail_expr (gimple stmt, bool insert)
 	    && walk_non_aliased_vuses (&ref, vuse2,
 				       vuse_eq, NULL, NULL, vuse1) != NULL))
 	{
-	  struct expr_hash_elt *element2 = XNEW (struct expr_hash_elt);
-	  *element2 = element;
-	  element2->stamp = element2;
-
-	  /* Insert the expr into the hash by replacing the current
-	     entry and recording the value to restore in the
-	     aval_exprs_stack.  */
-	  avail_exprs_stack.safe_push (std::make_pair (element2, *slot));
-	  *slot = element2;
-	  if (dump_file && (dump_flags & TDF_DETAILS))
+	  if (insert)
 	    {
-	      fprintf (dump_file, "2>>> ");
-	      print_expr_hash_elt (dump_file, *slot);
+	      struct expr_hash_elt *element2 = XNEW (struct expr_hash_elt);
+	      *element2 = element;
+	      element2->stamp = element2;
+
+	      /* Insert the expr into the hash by replacing the current
+		 entry and recording the value to restore in the
+		 avail_exprs_stack.  */
+	      avail_exprs_stack.safe_push (std::make_pair (element2, *slot));
+	      *slot = element2;
+	      if (dump_file && (dump_flags & TDF_DETAILS))
+		{
+		  fprintf (dump_file, "2>>> ");
+		  print_expr_hash_elt (dump_file, *slot);
+		}
 	    }
 	  return NULL_TREE;
 	}