From: Richard Biener Date: Thu, 17 May 2018 06:57:45 +0000 (+0000) Subject: re PR tree-optimization/85757 (tree optimizers fail to fully clean up fixed-size... X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=773d0331f7456614f9f7e619e642946d9bdc638a;p=gcc.git re PR tree-optimization/85757 (tree optimizers fail to fully clean up fixed-size memcpy) 2018-05-17 Richard Biener PR tree-optimization/85757 * tree-ssa-dse.c (dse_classify_store): Record a PHI def and remove defs that only feed that PHI from further processing. * gcc.dg/tree-ssa/ssa-dse-34.c: New testcase. From-SVN: r260306 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 700ac4a3707..23d13acc522 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2018-05-17 Richard Biener + + PR tree-optimization/85757 + * tree-ssa-dse.c (dse_classify_store): Record a PHI def and + remove defs that only feed that PHI from further processing. + 2018-05-16 Jim Wilson * config/riscv/riscv.md (si3_mask, si3_mask_1): Prepend diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 9eab3adfa40..f52a555a122 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2018-05-17 Richard Biener + + PR tree-optimization/85757 + * gcc.dg/tree-ssa/ssa-dse-34.c: New testcase. + 2018-05-16 Marek Polacek PR c++/85363 diff --git a/gcc/testsuite/gcc.dg/tree-ssa/ssa-dse-34.c b/gcc/testsuite/gcc.dg/tree-ssa/ssa-dse-34.c new file mode 100644 index 00000000000..3016dfecd38 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/ssa-dse-34.c @@ -0,0 +1,15 @@ +/* { dg-do compile } */ +/* { dg-options "-O -fdump-tree-dse1-details" } */ + +void f(int n, char *p0, char *p1, char *p2, char *o) +{ + int t0, t1; + __builtin_memcpy(&t0, p0, 1); + __builtin_memcpy(&t1, p1, 1); + if (n==3) + __builtin_memcpy(o+2, p2, 1); + __builtin_memcpy(o+0, &t0, 1); + __builtin_memcpy(o+1, &t1, 1); +} + +/* { dg-final { scan-tree-dump-times "Deleted dead store" 2 "dse1" } } */ diff --git a/gcc/tree-ssa-dse.c b/gcc/tree-ssa-dse.c index 32a25b9eb1e..589cfef5df5 100644 --- a/gcc/tree-ssa-dse.c +++ b/gcc/tree-ssa-dse.c @@ -577,6 +577,7 @@ dse_classify_store (ao_ref *ref, gimple *stmt, else defvar = gimple_vdef (temp); auto_vec defs; + gimple *phi_def = NULL; FOR_EACH_IMM_USE_STMT (use_stmt, ui, defvar) { /* Limit stmt walking. */ @@ -600,7 +601,10 @@ dse_classify_store (ao_ref *ref, gimple *stmt, processing. */ if (!bitmap_bit_p (visited, SSA_NAME_VERSION (PHI_RESULT (use_stmt)))) - defs.safe_push (use_stmt); + { + defs.safe_push (use_stmt); + phi_def = use_stmt; + } } /* If the statement is a use the store is not dead. */ else if (ref_maybe_used_by_stmt_p (use_stmt, ref)) @@ -657,15 +661,31 @@ dse_classify_store (ao_ref *ref, gimple *stmt, return DSE_STORE_DEAD; } - /* Process defs and remove paths starting with a kill from further - processing. */ + /* Process defs and remove those we need not process further. */ for (unsigned i = 0; i < defs.length (); ++i) - if (stmt_kills_ref_p (defs[i], ref)) - { - if (by_clobber_p && !gimple_clobber_p (defs[i])) - *by_clobber_p = false; + { + gimple *def = defs[i]; + gimple *use_stmt; + use_operand_p use_p; + /* If the path to check starts with a kill we do not need to + process it further. + ??? With byte tracking we need only kill the bytes currently + live. */ + if (stmt_kills_ref_p (def, ref)) + { + if (by_clobber_p && !gimple_clobber_p (def)) + *by_clobber_p = false; + defs.unordered_remove (i); + } + /* In addition to kills we can remove defs whose only use + is another def in defs. That can only ever be PHIs of which + we track a single for simplicity reasons (we fail for multiple + PHIs anyways). */ + else if (gimple_code (def) != GIMPLE_PHI + && single_imm_use (gimple_vdef (def), &use_p, &use_stmt) + && use_stmt == phi_def) defs.unordered_remove (i); - } + } /* If all defs kill the ref we are done. */ if (defs.is_empty ())