re PR tree-optimization/86062 (Missed redundancy elimination with struct and array)
authorRichard Biener <rguenther@suse.de>
Wed, 6 Jun 2018 13:03:29 +0000 (13:03 +0000)
committerRichard Biener <rguenth@gcc.gnu.org>
Wed, 6 Jun 2018 13:03:29 +0000 (13:03 +0000)
2018-06-06  Richard Biener  <rguenther@suse.de>

PR tree-optimization/86062
* tree-ssa-sccvn.c (vn_reference_lookup_3): Handle arbitrary
component refs ontop
of to be offsetted base.

* g++.dg/tree-ssa/pr86062.C: New testcase.

From-SVN: r261231

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/tree-ssa/pr86062.C [new file with mode: 0644]
gcc/tree-ssa-sccvn.c

index 85515d98f98ee1292ccb1681a93e81e7dcba14ea..18280e8a0410db00324a6e36a4da577b904d5f15 100644 (file)
@@ -1,3 +1,10 @@
+2018-06-06  Richard Biener  <rguenther@suse.de>
+
+       PR tree-optimization/86062
+       * tree-ssa-sccvn.c (vn_reference_lookup_3): Handle arbitrary
+       component refs ontop
+       of to be offsetted base.
+
 2018-06-06  Jozef Lawrynowicz  <jozef.l@mittosystems.com>
 
        * gcc/config/msp430/msp430.c (msp430_attr): Allow interrupt handlers
index 22ed1e03f22989c7d1fb2d0b1fd098583df37390..095cae3f972dd3853e5d4ba156609d9bd938a963 100644 (file)
@@ -1,3 +1,8 @@
+2018-06-06  Richard Biener  <rguenther@suse.de>
+
+       PR tree-optimization/86062
+       * g++.dg/tree-ssa/pr86062.C: New testcase.
+
 2018-06-05  Steve Ellcey  <sellcey@cavium.com>
 
        PR target/79924
diff --git a/gcc/testsuite/g++.dg/tree-ssa/pr86062.C b/gcc/testsuite/g++.dg/tree-ssa/pr86062.C
new file mode 100644 (file)
index 0000000..d62bdf6
--- /dev/null
@@ -0,0 +1,23 @@
+// { dg-do compile }
+// { dg-require-effective-target c++14 }
+// { dg-options "-O2 -ffinite-math-only -fdump-tree-fre1" }
+
+#include <array>
+
+struct I { double i,s; I(double d):i(d),s(d){} };
+typedef std::array<double,3> P;
+typedef std::array<I,3> AP;
+
+static AP c(P const&p){
+      return {p[0],p[1],p[2]};
+}
+template<class T> auto const& ac(T const&p, int n){return p[n];}
+static double g(P const&p, int n)
+{
+    I res = ac(c(p),n);
+      return res.s-res.i;
+}
+
+__attribute__((flatten)) double fff(P p){ return g(p,1); }
+
+// { dg-final { scan-tree-dump "return 0.0;" "fre1" } }
index 4e946ba7bafe754d815ff72e79001c65b0e004dd..4aec41e96c18df1d93866215b617c43ce3731221 100644 (file)
@@ -2270,14 +2270,16 @@ vn_reference_lookup_3 (ao_ref *ref, tree vuse, void *vr_,
       /* Apply an extra offset to the inner MEM_REF of the RHS.  */
       if (maybe_ne (extra_off, 0))
        {
-         if (rhs.length () < 2
-             || rhs[0].opcode != MEM_REF
-             || known_eq (rhs[0].off, -1))
+         if (rhs.length () < 2)
            return (void *)-1;
-         rhs[0].off += extra_off;
-         rhs[0].op0 = int_const_binop (PLUS_EXPR, rhs[0].op0,
-                                       build_int_cst (TREE_TYPE (rhs[0].op0),
-                                                      extra_off));
+         int ix = rhs.length () - 2;
+         if (rhs[ix].opcode != MEM_REF
+             || known_eq (rhs[ix].off, -1))
+           return (void *)-1;
+         rhs[ix].off += extra_off;
+         rhs[ix].op0 = int_const_binop (PLUS_EXPR, rhs[ix].op0,
+                                        build_int_cst (TREE_TYPE (rhs[ix].op0),
+                                                       extra_off));
        }
 
       /* We need to pre-pend vr->operands[0..i] to rhs.  */