tree-ssa-sccvn.c (vn_reference_lookup_3): Valueize RHS when comparing against a store...
authorRichard Biener <rguenther@suse.de>
Fri, 5 Jul 2019 12:53:19 +0000 (12:53 +0000)
committerRichard Biener <rguenth@gcc.gnu.org>
Fri, 5 Jul 2019 12:53:19 +0000 (12:53 +0000)
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.

From-SVN: r273136

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-77.c [new file with mode: 0644]
gcc/tree-ssa-sccvn.c

index 6dd97ab13e684243f09d992935c737b3928ce62d..15d79199705423831028abf777dd611e8e3347d1 100644 (file)
@@ -1,3 +1,8 @@
+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.
+
 2019-07-05  Richard Biener  <rguenther@suse.de>
 
        PR tree-optimization/91091
index 5656a5b2e48ba47ace5dac10b021754142d9d0a9..a57c230d57d8b99ca48dea177cc939edb0fe36e6 100644 (file)
@@ -1,3 +1,7 @@
+2019-07-05  Richard Biener  <rguenther@suse.de>
+
+       * gcc.dg/tree-ssa/ssa-fre-77.c: New testcase.
+
 2019-07-05  Richard Biener  <rguenther@suse.de>
 
        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 (file)
index 0000000..115f277
--- /dev/null
@@ -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" } } */
index 6d4ad7558636eae0b1a13ffd28588117e944aed8..67d51bfd5c9f94dcbffd810c7ebde6219a7f4488 100644 (file)
@@ -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;
            }
        }