From 2bf8ae1b3d539eb7170eba9336d06b8383c3eba2 Mon Sep 17 00:00:00 2001 From: Richard Biener Date: Wed, 28 Nov 2018 13:51:42 +0000 Subject: [PATCH] re PR tree-optimization/88223 (Wrong code for intrinsic memmove) 2018-11-28 Richard Biener PR tree-optimization/88223 * tree-ssa-sccvn.c (vn_reference_lookup_3): When skipping over a stored-same value may-alias store make sure to consider partial overlaps which are valid when TBAA reasonings do not apply and byte-granular overlaps are possible at all. * gcc.dg/torture/pr88223.c: New testcase. From-SVN: r266560 --- gcc/ChangeLog | 8 ++++++++ gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gcc.dg/torture/pr88223.c | 16 ++++++++++++++++ gcc/tree-ssa-sccvn.c | 11 ++++++++++- 4 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.dg/torture/pr88223.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 2c5bfffb5ec..695c1ff6093 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,11 @@ +2018-11-28 Richard Biener + + PR tree-optimization/88223 + * tree-ssa-sccvn.c (vn_reference_lookup_3): When skipping + over a stored-same value may-alias store make sure to consider + partial overlaps which are valid when TBAA reasonings do not + apply and byte-granular overlaps are possible at all. + 2018-11-28 Richard Biener PR tree-optimization/88217 diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 9f2383a38c3..52feffa476e 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2018-11-28 Richard Biener + + PR tree-optimization/88223 + * gcc.dg/torture/pr88223.c: New testcase. + 2018-11-28 Richard Biener PR tree-optimization/88217 diff --git a/gcc/testsuite/gcc.dg/torture/pr88223.c b/gcc/testsuite/gcc.dg/torture/pr88223.c new file mode 100644 index 00000000000..37df1cd6b74 --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr88223.c @@ -0,0 +1,16 @@ +/* { dg-do run } */ + +extern void *memmove(void *, const void *, __SIZE_TYPE__); +extern void abort(void); + +extern int +main(void) +{ + char s[] = "12345"; + memmove(s + 1, s, 4); + memmove(s + 1, s, 4); + memmove(s + 1, s, 4); + if (s[0] != '1' || s[1] != '1' || s[2] != '1' || s[3] != '1' || s[4] != '2') + abort (); + return (0); +} diff --git a/gcc/tree-ssa-sccvn.c b/gcc/tree-ssa-sccvn.c index b0b9d5221f4..8f2b4608b5c 100644 --- a/gcc/tree-ssa-sccvn.c +++ b/gcc/tree-ssa-sccvn.c @@ -1927,7 +1927,16 @@ vn_reference_lookup_3 (ao_ref *ref, tree vuse, void *vr_, VN_WALKREWRITE guard). */ if (vn_walk_kind == VN_WALKREWRITE && is_gimple_reg_type (TREE_TYPE (lhs)) - && types_compatible_p (TREE_TYPE (lhs), vr->type)) + && types_compatible_p (TREE_TYPE (lhs), vr->type) + /* The overlap restriction breaks down when either access + alias-set is zero. Still for accesses of the size of + an addressable unit there can be no overlaps. Overlaps + between different union members are not an issue since + 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 + && ao_ref_alias_set (ref) != 0))) { tree *saved_last_vuse_ptr = last_vuse_ptr; /* Do not update last_vuse_ptr in vn_reference_lookup_2. */ -- 2.30.2