From a460bf38dc3582ce1f559cc84084ca27e429b34c Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Thu, 27 Feb 2020 11:21:52 +0100 Subject: [PATCH] sccvn: Punt on ref->size not multiple of 8 for memset (, 123, ) in 9.x [PR93945] And here is the corresponding 9.x change where we the patch just punts if ref->size is not whole bytes, like we already punt if offseti is not byte aligned. 2020-02-27 Jakub Jelinek PR tree-optimization/93945 * tree-ssa-sccvn.c (vn_reference_lookup_3): For memset with non-zero second operand, require ref->size to be a multiple of BITS_PER_UNIT. * gcc.c-torture/execute/pr93945.c: New test. --- gcc/ChangeLog | 6 +++ gcc/testsuite/ChangeLog | 5 +++ gcc/testsuite/gcc.c-torture/execute/pr93945.c | 45 +++++++++++++++++++ gcc/tree-ssa-sccvn.c | 3 +- 4 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.c-torture/execute/pr93945.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index d09456d27fa0..c106e96c9788 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2020-02-27 Jakub Jelinek + + PR tree-optimization/93945 + * tree-ssa-sccvn.c (vn_reference_lookup_3): For memset with non-zero + second operand, require ref->size to be a multiple of BITS_PER_UNIT. + 2020-02-26 Carl Love PR target/91276 diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 845976a9a3df..899b90d2e8c0 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2020-02-27 Jakub Jelinek + + PR tree-optimization/93945 + * gcc.c-torture/execute/pr93945.c: New test. + 2020-02-26 Marek Polacek Jakub Jelinek diff --git a/gcc/testsuite/gcc.c-torture/execute/pr93945.c b/gcc/testsuite/gcc.c-torture/execute/pr93945.c new file mode 100644 index 000000000000..99e455cce521 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/pr93945.c @@ -0,0 +1,45 @@ +/* PR tree-optimization/93945 */ + +union U { char a[8]; struct S { unsigned int b : 8, c : 13, d : 11; } e; } u; + +__attribute__((noipa)) int +foo (void) +{ + __builtin_memset (&u.a, 0xf4, sizeof (u.a)); + return u.e.c; +} + +__attribute__((noipa)) int +bar (void) +{ + asm volatile ("" : : "g" (&u) : "memory"); + return u.e.c; +} + +__attribute__((noipa)) int +baz (void) +{ + __builtin_memset (&u.a, 0xf4, sizeof (u.a)); + return u.e.d; +} + +__attribute__((noipa)) int +qux (void) +{ + asm volatile ("" : : "g" (&u) : "memory"); + return u.e.d; +} + +int +main () +{ + int a = foo (); + int b = bar (); + if (a != b) + __builtin_abort (); + a = baz (); + b = qux (); + if (a != b) + __builtin_abort (); + return 0; +} diff --git a/gcc/tree-ssa-sccvn.c b/gcc/tree-ssa-sccvn.c index aea11bdebba9..32f45c95cdf2 100644 --- a/gcc/tree-ssa-sccvn.c +++ b/gcc/tree-ssa-sccvn.c @@ -2113,7 +2113,8 @@ vn_reference_lookup_3 (ao_ref *ref, tree vuse, void *data_, || (INTEGRAL_TYPE_P (vr->type) && known_eq (ref->size, 8))) && CHAR_BIT == 8 && BITS_PER_UNIT == 8 && offset.is_constant (&offseti) - && offseti % BITS_PER_UNIT == 0)) + && offseti % BITS_PER_UNIT == 0 + && multiple_p (ref->size, BITS_PER_UNIT))) && poly_int_tree_p (gimple_call_arg (def_stmt, 2)) && (TREE_CODE (gimple_call_arg (def_stmt, 0)) == ADDR_EXPR || TREE_CODE (gimple_call_arg (def_stmt, 0)) == SSA_NAME)) -- 2.47.2