Yet another VN improvement

Message ID alpine.LSU.2.20.1907051249350.2976@zhemvz.fhfr.qr
State New
Headers show
Series
  • Yet another VN improvement
Related show

Commit Message

Richard Biener July 5, 2019, 10:50 a.m.
I noticed we fail to valueize the RHS when looking for same-valued
stores.

Bootstrap / regtest running on x86_64-unknown-linux-gnu.

Richard.

2019-07-05  Richard Biener  <rguenther@suse.de>

	* tree-ssa-sccvn.c (vn_reference_lookup_3): Valueize RHS
	when comparing against a store with possibly the same value.

	* gcc.dg/tree-ssa/ssa-fre-77.c: New testcase.

Patch

Index: gcc/tree-ssa-sccvn.c
===================================================================
--- gcc/tree-ssa-sccvn.c	(revision 273083)
+++ gcc/tree-ssa-sccvn.c	(working copy)
@@ -2012,9 +2268,11 @@  vn_reference_lookup_3 (ao_ref *ref, tree
 	  if (res && res != (void *)-1)
 	    {
 	      vn_reference_t vnresult = (vn_reference_t) res;
+	      tree rhs = gimple_assign_rhs1 (def_stmt);
+	      if (TREE_CODE (rhs) == SSA_NAME)
+		rhs = SSA_VAL (rhs);
 	      if (vnresult->result
-		  && operand_equal_p (vnresult->result,
-				      gimple_assign_rhs1 (def_stmt), 0))
+		  && operand_equal_p (vnresult->result, rhs, 0))
 		return res;
 	    }
 	}
Index: gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-77.c
===================================================================
--- gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-77.c	(nonexistent)
+++ gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-77.c	(working copy)
@@ -0,0 +1,13 @@ 
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-fre1" } */
+
+int foo (int *p, int *q)
+{
+  int x;
+  *p = 1;
+  x = *p;
+  *q = x;
+  return *p;
+}
+
+/* { dg-final { scan-tree-dump "return 1;" "fre1" } } */