From c2851dc2896bfc0d27b32c90cafc873f67cd6727 Mon Sep 17 00:00:00 2001 From: Richard Biener Date: Tue, 9 Jul 2019 08:04:37 +0000 Subject: [PATCH] tree-ssa-sccvn.c (struct vn_walk_cb_data): Add orig_ref member. 2019-07-09 Richard Biener * tree-ssa-sccvn.c (struct vn_walk_cb_data): Add orig_ref member. (vn_reference_lookup_3): If the main ref has no access path recorded but orig_ref has use it to do access-path based disambiguation. (vn_reference_lookup_pieces): Adjust. (vn_reference_lookup): Pass down original ref if we valueized. * gcc.dg/tree-ssa/alias-access-path-1.c: Scan fre1 dump. * gcc.dg/tree-ssa/alias-access-path-2.c: Likewise. * gcc.dg/tree-ssa/alias-access-path-8.c: Likewise. From-SVN: r273294 --- gcc/ChangeLog | 8 ++++ gcc/testsuite/ChangeLog | 6 +++ .../gcc.dg/tree-ssa/alias-access-path-1.c | 4 +- .../gcc.dg/tree-ssa/alias-access-path-2.c | 4 +- .../gcc.dg/tree-ssa/alias-access-path-8.c | 4 +- gcc/tree-ssa-sccvn.c | 44 ++++++++++++++++--- 6 files changed, 58 insertions(+), 12 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index a3c7971d643..8fccc6bdab5 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,11 @@ +2019-07-09 Richard Biener + + * tree-ssa-sccvn.c (struct vn_walk_cb_data): Add orig_ref member. + (vn_reference_lookup_3): If the main ref has no access path recorded + but orig_ref has use it to do access-path based disambiguation. + (vn_reference_lookup_pieces): Adjust. + (vn_reference_lookup): Pass down original ref if we valueized. + 2019-07-09 Martin Liska * lto-compress.c (lto_normalized_zstd_level): Do not use diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 91fa381708b..e9d01950ea3 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2019-07-09 Richard Biener + + * gcc.dg/tree-ssa/alias-access-path-1.c: Scan fre1 dump. + * gcc.dg/tree-ssa/alias-access-path-2.c: Likewise. + * gcc.dg/tree-ssa/alias-access-path-8.c: Likewise. + 2019-07-09 Ed Schonberg * gnat.dg/predicate10.adb, gnat.dg/predicate10_pkg.adb, diff --git a/gcc/testsuite/gcc.dg/tree-ssa/alias-access-path-1.c b/gcc/testsuite/gcc.dg/tree-ssa/alias-access-path-1.c index ba90b56fe5c..7676aa6b285 100644 --- a/gcc/testsuite/gcc.dg/tree-ssa/alias-access-path-1.c +++ b/gcc/testsuite/gcc.dg/tree-ssa/alias-access-path-1.c @@ -1,5 +1,5 @@ /* { dg-do compile } */ -/* { dg-options "-O2 -fdump-tree-fre3" } */ +/* { dg-options "-O2 -fdump-tree-fre1" } */ struct foo { int val; @@ -18,4 +18,4 @@ test () return barptr->val2; } -/* { dg-final { scan-tree-dump-times "return 123" 1 "fre3"} } */ +/* { dg-final { scan-tree-dump-times "return 123" 1 "fre1"} } */ diff --git a/gcc/testsuite/gcc.dg/tree-ssa/alias-access-path-2.c b/gcc/testsuite/gcc.dg/tree-ssa/alias-access-path-2.c index 974cdb0ee00..fdc30551617 100644 --- a/gcc/testsuite/gcc.dg/tree-ssa/alias-access-path-2.c +++ b/gcc/testsuite/gcc.dg/tree-ssa/alias-access-path-2.c @@ -1,5 +1,5 @@ /* { dg-do compile } */ -/* { dg-options "-O2 -fdump-tree-fre3" } */ +/* { dg-options "-O2 -fdump-tree-fre1" } */ struct a { int val; }; @@ -19,4 +19,4 @@ test (int i, int j, int k, int l) dptr->c.b[k].a2[l].val=2; return cptr->b[i].a[j].val; } -/* { dg-final { scan-tree-dump-times "return 123" 1 "fre3"} } */ +/* { dg-final { scan-tree-dump-times "return 123" 1 "fre1"} } */ diff --git a/gcc/testsuite/gcc.dg/tree-ssa/alias-access-path-8.c b/gcc/testsuite/gcc.dg/tree-ssa/alias-access-path-8.c index 1d5b57ab729..85f2c6a37e4 100644 --- a/gcc/testsuite/gcc.dg/tree-ssa/alias-access-path-8.c +++ b/gcc/testsuite/gcc.dg/tree-ssa/alias-access-path-8.c @@ -1,5 +1,5 @@ /* { dg-do compile } */ -/* { dg-options "-O2 -fdump-tree-fre3" } */ +/* { dg-options "-O2 -fdump-tree-fre1" } */ struct a { int val; }; @@ -18,4 +18,4 @@ test (int i, int j, int k, int l) cptr2->b[k].a2[l].val=2; return cptr->b[i].a[j].val; } -/* { dg-final { scan-tree-dump-times "return 123" 1 "fre3"} } */ +/* { dg-final { scan-tree-dump-times "return 123" 1 "fre1"} } */ diff --git a/gcc/tree-ssa-sccvn.c b/gcc/tree-ssa-sccvn.c index 854222a0cc2..627ee8fecb2 100644 --- a/gcc/tree-ssa-sccvn.c +++ b/gcc/tree-ssa-sccvn.c @@ -1670,15 +1670,18 @@ struct pd_data struct vn_walk_cb_data { - vn_walk_cb_data (vn_reference_t vr_, tree *last_vuse_ptr_, + vn_walk_cb_data (vn_reference_t vr_, tree orig_ref_, tree *last_vuse_ptr_, vn_lookup_kind vn_walk_kind_, bool tbaa_p_) - : vr (vr_), last_vuse_ptr (last_vuse_ptr_), vn_walk_kind (vn_walk_kind_), - tbaa_p (tbaa_p_), known_ranges (NULL) - {} + : vr (vr_), last_vuse_ptr (last_vuse_ptr_), + vn_walk_kind (vn_walk_kind_), tbaa_p (tbaa_p_), known_ranges (NULL) + { + ao_ref_init (&orig_ref, orig_ref_); + } ~vn_walk_cb_data (); void *push_partial_def (const pd_data& pd, tree, HOST_WIDE_INT); vn_reference_t vr; + ao_ref orig_ref; tree *last_vuse_ptr; vn_lookup_kind vn_walk_kind; bool tbaa_p; @@ -2246,6 +2249,28 @@ vn_reference_lookup_3 (ao_ref *ref, tree vuse, void *data_, lhs_ref_ok = true; } + /* Besides valueizing the LHS we can also use access-path based + disambiguation on the original non-valueized ref. */ + if (!ref->ref + && lhs_ref_ok + && data->orig_ref.ref) + { + /* We want to use the non-valueized LHS for this, but avoid redundant + work. */ + ao_ref *lref = &lhs_ref; + ao_ref lref_alt; + if (valueized_anything) + { + ao_ref_init (&lref_alt, lhs); + lref = &lref_alt; + } + if (!refs_may_alias_p_1 (&data->orig_ref, lref, data->tbaa_p)) + { + *disambiguate_only = true; + return NULL; + } + } + /* If we reach a clobbering statement try to skip it and see if we find a VN result with exactly the same value as the possible clobber. In this case we can ignore the clobber @@ -2763,6 +2788,9 @@ vn_reference_lookup_3 (ao_ref *ref, tree vuse, void *data_, /* Do not update last seen VUSE after translating. */ data->last_vuse_ptr = NULL; + /* Invalidate the original access path since it now contains + the wrong base. */ + data->orig_ref.ref = NULL_TREE; /* Keep looking for the adjusted *REF / VR pair. */ return NULL; @@ -2923,6 +2951,9 @@ vn_reference_lookup_3 (ao_ref *ref, tree vuse, void *data_, /* Do not update last seen VUSE after translating. */ data->last_vuse_ptr = NULL; + /* Invalidate the original access path since it now contains + the wrong base. */ + data->orig_ref.ref = NULL_TREE; /* Keep looking for the adjusted *REF / VR pair. */ return NULL; @@ -2983,7 +3014,7 @@ vn_reference_lookup_pieces (tree vuse, alias_set_type set, tree type, { ao_ref r; unsigned limit = PARAM_VALUE (PARAM_SCCVN_MAX_ALIAS_QUERIES_PER_ACCESS); - vn_walk_cb_data data (&vr1, NULL, kind, true); + vn_walk_cb_data data (&vr1, NULL_TREE, NULL, kind, true); if (ao_ref_init_from_vn_reference (&r, set, type, vr1.operands)) *vnresult = (vn_reference_t)walk_non_aliased_vuses (&r, vr1.vuse, true, @@ -3040,7 +3071,8 @@ vn_reference_lookup (tree op, tree vuse, vn_lookup_kind kind, || !ao_ref_init_from_vn_reference (&r, vr1.set, vr1.type, vr1.operands)) ao_ref_init (&r, op); - vn_walk_cb_data data (&vr1, last_vuse_ptr, kind, tbaa_p); + vn_walk_cb_data data (&vr1, r.ref ? NULL_TREE : op, + last_vuse_ptr, kind, tbaa_p); wvnresult = (vn_reference_t)walk_non_aliased_vuses (&r, vr1.vuse, tbaa_p, vn_reference_lookup_2, -- 2.30.2