https://gcc.gnu.org/g:6225251b90056f21b5896be46ed2c3c5a823a848
commit r16-6577-g6225251b90056f21b5896be46ed2c3c5a823a848 Author: Richard Biener <[email protected]> Date: Thu Jan 8 13:08:57 2026 +0100 tree-optimization/123310 - wrong aggregate copy VN There's a typo in the check against unknown offset when processing an aggregate copy during VN, leading to wrong lookup. PR tree-optimization/123310 * tree-ssa-sccvn.cc (vn_reference_lookup_3): Properly test against unknown offset. * gcc.dg/torture/pr123310.c: New testcase. Diff: --- gcc/testsuite/gcc.dg/torture/pr123310.c | 21 +++++++++++++++++++++ gcc/tree-ssa-sccvn.cc | 2 +- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/gcc/testsuite/gcc.dg/torture/pr123310.c b/gcc/testsuite/gcc.dg/torture/pr123310.c new file mode 100644 index 000000000000..1c2dee65c8d7 --- /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 6fda0ef60440..16343d2a407f 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--;
