There's a typo in the check against unknown offset when processing
an aggregate copy during VN, leading to wrong lookup.

Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed.

        PR tree-optimization/123310
        * tree-ssa-sccvn.cc (vn_reference_lookup_3): Properly
        test against unknown offset.

        * gcc.dg/torture/pr123310.c: New testcase.
---
 gcc/testsuite/gcc.dg/torture/pr123310.c | 21 +++++++++++++++++++++
 gcc/tree-ssa-sccvn.cc                   |  2 +-
 2 files changed, 22 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/gcc.dg/torture/pr123310.c

diff --git a/gcc/testsuite/gcc.dg/torture/pr123310.c 
b/gcc/testsuite/gcc.dg/torture/pr123310.c
new file mode 100644
index 00000000000..1c2dee65c8d
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr123310.c
@@ -0,0 +1,21 @@
+/* { dg-do run } */
+
+struct a {
+    short b;
+} c[7], e;
+int d;
+static struct a f[3][2] = {{}, {}, 5, 5};
+void __attribute__((noipa)) g()
+{
+  for (; e.b >= 0; e.b--)
+    {
+      c[e.b + 6] = f[2][1];
+      d = c[6].b;
+    }
+}
+int main()
+{
+  g();
+  if (d != 5)
+    __builtin_abort ();
+}
diff --git a/gcc/tree-ssa-sccvn.cc b/gcc/tree-ssa-sccvn.cc
index 6fda0ef6044..16343d2a407 100644
--- a/gcc/tree-ssa-sccvn.cc
+++ b/gcc/tree-ssa-sccvn.cc
@@ -3694,7 +3694,7 @@ vn_reference_lookup_3 (ao_ref *ref, tree vuse, void 
*data_,
         via extra_off.  Note this is an attempt to fixup secondary
         copies after we hit the !found && j == 0 case above.  */
       while (j != -1
-            && known_ne (lhs_ops[j].off, -1U))
+            && known_ne (lhs_ops[j].off, -1))
        {
          extra_off += -lhs_ops[j].off;
          j--;
-- 
2.51.0

Reply via email to