From 75fad0a98919da8212be4efc479d098499f4f1c3 Mon Sep 17 00:00:00 2001 From: Richard Biener Date: Fri, 5 Jul 2019 12:48:42 +0000 Subject: [PATCH] re PR tree-optimization/91091 ([missed optimization] Missing optimization in unaliased pointers) 2019-07-05 Richard Biener PR tree-optimization/91091 * tree-ssa-sccvn.c (vn_reference_lookup_3): Overlap of accesses can happen with -fno-strict-aliasing. * gcc.dg/tree-ssa/pr91091-1.c: New testcase. * gcc.dg/tree-ssa/ssa-fre-61.c: Adjust. From-SVN: r273134 --- gcc/ChangeLog | 6 ++++++ gcc/testsuite/ChangeLog | 6 ++++++ gcc/testsuite/gcc.dg/tree-ssa/pr91091-1.c | 23 ++++++++++++++++++++++ gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-61.c | 2 +- gcc/tree-ssa-sccvn.c | 3 ++- 5 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/pr91091-1.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index d568b08e3a4..25e539fbf32 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2019-07-05 Richard Biener + + PR tree-optimization/91091 + * tree-ssa-sccvn.c (vn_reference_lookup_3): Overlap of + accesses can happen with -fno-strict-aliasing. + 2019-07-05 Jan Hubicka * tree-ssa-alias.c (alias_stats): Add diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 53d79948979..6c049d0f484 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2019-07-05 Richard Biener + + PR tree-optimization/91091 + * gcc.dg/tree-ssa/pr91091-1.c: New testcase. + * gcc.dg/tree-ssa/ssa-fre-61.c: Adjust. + 2019-07-05 Eric Botcazou * gnat.dg/pack23.adb, gnat.dg/pack23_pkg.ads: New testcase. diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr91091-1.c b/gcc/testsuite/gcc.dg/tree-ssa/pr91091-1.c new file mode 100644 index 00000000000..2ee75d9804a --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr91091-1.c @@ -0,0 +1,23 @@ +/* { dg-do run } */ +/* { dg-options "-O3 -fno-strict-aliasing" } */ + +struct s { int x; } __attribute__((packed)); +struct t { int x; }; + +void __attribute__((noinline,noipa)) +swap(struct s* p, struct t* q) +{ + p->x = q->x; + q->x = p->x; +} + +int main() +{ + struct t a[2]; + a[0].x = 0x12345678; + a[1].x = 0x98765432; + swap ((struct s *)((char *)a + 1), a); + if (a[0].x != 0x12345678) + __builtin_abort (); + return 0; +} diff --git a/gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-61.c b/gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-61.c index a4d9a7194bf..eae4b15b7f2 100644 --- a/gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-61.c +++ b/gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-61.c @@ -1,5 +1,5 @@ /* { dg-do link } */ -/* { dg-options "-O -fdump-tree-fre1-details" } */ +/* { dg-options "-O -fstrict-aliasing -fdump-tree-fre1-details" } */ void link_error (void); diff --git a/gcc/tree-ssa-sccvn.c b/gcc/tree-ssa-sccvn.c index 22dd8015e9d..2cc76d89bd4 100644 --- a/gcc/tree-ssa-sccvn.c +++ b/gcc/tree-ssa-sccvn.c @@ -1996,7 +1996,8 @@ vn_reference_lookup_3 (ao_ref *ref, tree vuse, void *data_, activation of a union member via a store makes the values of untouched bytes unspecified. */ && (known_eq (ref->size, BITS_PER_UNIT) - || (get_alias_set (lhs) != 0 + || (flag_strict_aliasing + && get_alias_set (lhs) != 0 && ao_ref_alias_set (ref) != 0))) { tree *saved_last_vuse_ptr = data->last_vuse_ptr; -- 2.30.2