From 92590cd35f5e7b1c02a928069e54683f2e815914 Mon Sep 17 00:00:00 2001 From: Richard Biener Date: Mon, 2 Jul 2018 13:32:26 +0000 Subject: [PATCH] re PR tree-optimization/86363 (wrong code with __builtin_memset() at -O1) 2018-07-02 Richard Biener PR tree-optimization/86363 * tree-ssa-sccvn.c (vn_reference_lookup_3): Check the memset argument refers to a non-variable address. * gcc.dg/torture/pr86363.c: New testcase. From-SVN: r262307 --- gcc/ChangeLog | 6 ++++++ gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gcc.dg/torture/pr86363.c | 25 +++++++++++++++++++++++++ gcc/tree-ssa-sccvn.c | 1 + 4 files changed, 37 insertions(+) create mode 100644 gcc/testsuite/gcc.dg/torture/pr86363.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 15f2749d492..dc90e39d078 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2018-07-02 Richard Biener + + PR tree-optimization/86363 + * tree-ssa-sccvn.c (vn_reference_lookup_3): Check the + memset argument refers to a non-variable address. + 2018-07-02 Aldy Hernandez * tree-vrp.c (extract_range_from_binary_expr_1): Abstract a lot of the diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index cc94d3bf740..8b091305b95 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2018-07-02 Richard Biener + + PR tree-optimization/86363 + * gcc.dg/torture/pr86363.c: New testcase. + 2018-07-02 Martin Liska * gcc.dg/completion-1.c: New test. diff --git a/gcc/testsuite/gcc.dg/torture/pr86363.c b/gcc/testsuite/gcc.dg/torture/pr86363.c new file mode 100644 index 00000000000..154f9386e05 --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr86363.c @@ -0,0 +1,25 @@ +/* { dg-do run } */ +/* { dg-additional-options "-w -Wno-psabi" } */ + +typedef char U __attribute__ ((vector_size (16))); +typedef unsigned V __attribute__ ((vector_size (16))); + +V g; + +V +f (V v, U u) +{ + __builtin_memset (&u[v[0]], 0, 1); + g ^= u[0]; + return g; +} + +int +main (void) +{ + V x = f ((V) { 5 }, (U) { 1 }); + + if (x[0] != 1 || x[1] != 1 || x[2] != 1 || x[3] != 1) + __builtin_abort (); + return 0; +} diff --git a/gcc/tree-ssa-sccvn.c b/gcc/tree-ssa-sccvn.c index e5eddf902b8..1e16e13cfa1 100644 --- a/gcc/tree-ssa-sccvn.c +++ b/gcc/tree-ssa-sccvn.c @@ -1988,6 +1988,7 @@ vn_reference_lookup_3 (ao_ref *ref, tree vuse, void *vr_, base2 = get_ref_base_and_extent (ref2, &offset2, &size2, &maxsize2, &reverse); if (!known_size_p (maxsize2) + || !known_eq (maxsize2, size2) || !operand_equal_p (base, base2, OEP_ADDRESS_OF)) return (void *)-1; } -- 2.30.2