public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Yet another VN improvement
@ 2019-07-05 10:57 Richard Biener
  0 siblings, 0 replies; only message in thread
From: Richard Biener @ 2019-07-05 10:57 UTC (permalink / raw)
  To: gcc-patches


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.

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" } } */

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2019-07-05 10:50 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-05 10:57 [PATCH] Yet another VN improvement Richard Biener

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).