From 66076dcb60bee1c3d2c41ced5424ada90149d7fc Mon Sep 17 00:00:00 2001 From: Richard Biener Date: Fri, 5 Jul 2019 12:53:19 +0000 Subject: [PATCH] tree-ssa-sccvn.c (vn_reference_lookup_3): Valueize RHS when comparing against a store with possibly the same value. 2019-07-05 Richard Biener * 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. From-SVN: r273136 --- gcc/ChangeLog | 5 +++++ gcc/testsuite/ChangeLog | 4 ++++ gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-77.c | 13 +++++++++++++ gcc/tree-ssa-sccvn.c | 6 ++++-- 4 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-77.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 6dd97ab13e6..15d79199705 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2019-07-05 Richard Biener + + * tree-ssa-sccvn.c (vn_reference_lookup_3): Valueize RHS + when comparing against a store with possibly the same value. + 2019-07-05 Richard Biener PR tree-optimization/91091 diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 5656a5b2e48..a57c230d57d 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2019-07-05 Richard Biener + + * gcc.dg/tree-ssa/ssa-fre-77.c: New testcase. + 2019-07-05 Richard Biener PR tree-optimization/91091 diff --git a/gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-77.c b/gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-77.c new file mode 100644 index 00000000000..115f277d3d8 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-77.c @@ -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" } } */ diff --git a/gcc/tree-ssa-sccvn.c b/gcc/tree-ssa-sccvn.c index 6d4ad755863..67d51bfd5c9 100644 --- a/gcc/tree-ssa-sccvn.c +++ b/gcc/tree-ssa-sccvn.c @@ -2047,9 +2047,11 @@ vn_reference_lookup_3 (ao_ref *ref, tree vuse, void *data_, 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; } } -- 2.30.2