From 18eb304e5f35d745dcb1a9bb41a2879a364f59fe Mon Sep 17 00:00:00 2001 From: Jeff Law Date: Wed, 22 Feb 2017 22:47:43 -0700 Subject: [PATCH] re PR tree-optimization/79578 (Unnecessary instructions in generated code) PR tree-optimization/79578 * tree-ssa-dse.c (clear_bytes_written_by): Use operand_equal_p to compare base operands. PR tree-optimization/79578 * g++.dg/tree-ssa/ssa-dse-3.C: New test. From-SVN: r245675 --- gcc/ChangeLog | 6 +++++ gcc/testsuite/ChangeLog | 5 ++++ gcc/testsuite/g++.dg/tree-ssa/ssa-dse-3.C | 28 +++++++++++++++++++++++ gcc/tree-ssa-dse.c | 2 +- 4 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/tree-ssa/ssa-dse-3.C diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 7155850e3a9..6da1d74115f 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2017-02-22 Jeff Law + + PR tree-optimization/79578 + * tree-ssa-dse.c (clear_bytes_written_by): Use operand_equal_p + to compare base operands. + 2017-02-22 Segher Boessenkool PR target/79211 diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index ea5e2515d86..d900cc3496b 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2017-02-22 Jeff Law + + PR tree-optimization/79578 + * g++.dg/tree-ssa/ssa-dse-3.C: New test. + 2017-02-22 Sameera Deshpande * gcc.target/mips/msa-fp-cc.c: New test. diff --git a/gcc/testsuite/g++.dg/tree-ssa/ssa-dse-3.C b/gcc/testsuite/g++.dg/tree-ssa/ssa-dse-3.C new file mode 100644 index 00000000000..fe8f309ac22 --- /dev/null +++ b/gcc/testsuite/g++.dg/tree-ssa/ssa-dse-3.C @@ -0,0 +1,28 @@ +/* { dg-do compile } */ +/* { dg-options "-std=c++14 -O3 -fdump-tree-dse1-details" } */ + +#include +#include + +struct A +{ + std::uint16_t a, b; +}; + +A* f(char* b) __attribute__((noinline)); + +A* f(char* b) { + auto a = new(b) A{}; + a->a = 1; + a->b = 2; + return a; +} + +int main() { + char b[sizeof(A)] alignas(A); + f(b); +} + + +/* { dg-final { scan-tree-dump "Deleted dead store: " "dse1" } } */ + diff --git a/gcc/tree-ssa-dse.c b/gcc/tree-ssa-dse.c index 84c0b11f53b..a82e16449c4 100644 --- a/gcc/tree-ssa-dse.c +++ b/gcc/tree-ssa-dse.c @@ -176,7 +176,7 @@ clear_bytes_written_by (sbitmap live_bytes, gimple *stmt, ao_ref *ref) /* Verify we have the same base memory address, the write has a known size and overlaps with REF. */ if (valid_ao_ref_for_dse (&write) - && write.base == ref->base + && operand_equal_p (write.base, ref->base, 0) && write.size == write.max_size && ((write.offset < ref->offset && write.offset + write.size > ref->offset) -- 2.30.2