diff options
author | Richard Biener <rguenther@suse.de> | 2025-08-11 10:42:47 +0200 |
---|---|---|
committer | Richard Biener <rguenth@gcc.gnu.org> | 2025-08-12 08:36:56 +0200 |
commit | 5294840e3c7bf9bd98016dec07f54ee8dc71714a (patch) | |
tree | 29124263c561e2724db2882e12fb09d4a9de0bd0 /gcc | |
parent | 6d9c1aad2c46092ac0e5adcaad2ea5af57fad180 (diff) | |
download | gcc-5294840e3c7bf9bd98016dec07f54ee8dc71714a.zip gcc-5294840e3c7bf9bd98016dec07f54ee8dc71714a.tar.gz gcc-5294840e3c7bf9bd98016dec07f54ee8dc71714a.tar.bz2 |
tree-optimization/121493 - another missed VN with aggregate copy
This is another case where opportunistically handling a first
aggregate copy where we failed to match up the refs exactly
(as we don't insert missing handling components) yields to a
failure in the second aggregate copy that we visit. Add another
fixup to deal with such situations, in-line with that present
opportunistic handling.
PR tree-optimization/121493
* tree-ssa-sccvn.cc (vn_reference_lookup_3): Opportunistically
strip components with known offset.
* gcc.dg/tree-ssa/ssa-fre-109.c: New testcase.
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-109.c | 23 | ||||
-rw-r--r-- | gcc/tree-ssa-sccvn.cc | 11 |
2 files changed, 34 insertions, 0 deletions
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-109.c b/gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-109.c new file mode 100644 index 0000000..f04e033c --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-109.c @@ -0,0 +1,23 @@ +/* { dg-do compile } */ +/* { dg-options "-O -fno-tree-sra -fdump-tree-fre1" } */ + +struct s1 +{ + int t; +}; + +struct s2 +{ + struct s1 t; +}; + +int f1(int a) +{ + struct s1 t = (struct s1){a}; + struct s2 tt = (struct s2){t}; + struct s2 ttt = tt; + struct s1 *t0 = &ttt.t; + return t0->t; +} + +/* { dg-final { scan-tree-dump "return a" "fre1" } } */ diff --git a/gcc/tree-ssa-sccvn.cc b/gcc/tree-ssa-sccvn.cc index cdd7c05..0f6760d 100644 --- a/gcc/tree-ssa-sccvn.cc +++ b/gcc/tree-ssa-sccvn.cc @@ -3650,6 +3650,17 @@ vn_reference_lookup_3 (ao_ref *ref, tree vuse, void *data_, j--; } + /* When we still didn't manage to strip off all components from + lhs_op, opportunistically continue for those we can handle + 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)) + { + extra_off += -lhs_ops[j].off; + j--; + } + /* i now points to the first additional op. ??? LHS may not be completely contained in VR, one or more VIEW_CONVERT_EXPRs could be in its way. We could at least |