+2018-05-17 Richard Biener <rguenther@suse.de>
+
+ 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 <jimw@sifive.com>
* config/riscv/riscv.md (<optab>si3_mask, <optab>si3_mask_1): Prepend
--- /dev/null
+/* { 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" } } */
else
defvar = gimple_vdef (temp);
auto_vec<gimple *, 10> defs;
+ gimple *phi_def = NULL;
FOR_EACH_IMM_USE_STMT (use_stmt, ui, defvar)
{
/* Limit stmt walking. */
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))
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 ())