/* Dead store elimination
- Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010
- Free Software Foundation, Inc.
+ Copyright (C) 2004-2013 Free Software Foundation, Inc.
This file is part of GCC.
#include "tree.h"
#include "tm_p.h"
#include "basic-block.h"
-#include "timevar.h"
#include "gimple-pretty-print.h"
#include "tree-flow.h"
#include "tree-pass.h"
-#include "tree-dump.h"
#include "domwalk.h"
#include "flags.h"
#include "langhooks.h"
temp = stmt;
do
{
- gimple use_stmt;
+ gimple use_stmt, defvar_def;
imm_use_iterator ui;
bool fail = false;
tree defvar;
defvar = PHI_RESULT (temp);
else
defvar = gimple_vdef (temp);
+ defvar_def = temp;
temp = NULL;
FOR_EACH_IMM_USE_STMT (use_stmt, ui, defvar)
{
fail = true;
BREAK_FROM_IMM_USE_STMT (ui);
}
- temp = use_stmt;
+ /* Do not consider the PHI as use if it dominates the
+ stmt defining the virtual operand we are processing,
+ we have processed it already in this case. */
+ if (gimple_bb (defvar_def) != gimple_bb (use_stmt)
+ && !dominated_by_p (CDI_DOMINATORS,
+ gimple_bb (defvar_def),
+ gimple_bb (use_stmt)))
+ temp = use_stmt;
}
/* If the statement is a use the store is not dead. */
else if (ref_maybe_used_by_stmt_p (use_stmt,
just pretend the stmt makes itself dead. Otherwise fail. */
if (!temp)
{
- if (is_hidden_global_store (stmt))
+ if (stmt_may_clobber_global_p (stmt))
return false;
temp = stmt;
post dominates the first store, then the first store is dead. */
static void
-dse_optimize_stmt (gimple_stmt_iterator gsi)
+dse_optimize_stmt (gimple_stmt_iterator *gsi)
{
- gimple stmt = gsi_stmt (gsi);
+ gimple stmt = gsi_stmt (*gsi);
/* If this statement has no virtual defs, then there is nothing
to do. */
gimple_get_lhs (use_stmt), 0)))
|| stmt_kills_ref_p (use_stmt, gimple_assign_lhs (stmt)))
{
+ basic_block bb;
+
/* If use_stmt is or might be a nop assignment, e.g. for
struct { ... } S a, b, *p; ...
b = a; b = b;
if (dump_file && (dump_flags & TDF_DETAILS))
{
fprintf (dump_file, " Deleted dead store '");
- print_gimple_stmt (dump_file, gsi_stmt (gsi), dump_flags, 0);
+ print_gimple_stmt (dump_file, gsi_stmt (*gsi), dump_flags, 0);
fprintf (dump_file, "'\n");
}
/* Then we need to fix the operand of the consuming stmt. */
unlink_stmt_vdef (stmt);
- bitmap_set_bit (need_eh_cleanup, gimple_bb (stmt)->index);
-
/* Remove the dead store. */
- gsi_remove (&gsi, true);
+ bb = gimple_bb (stmt);
+ if (gsi_remove (gsi, true))
+ bitmap_set_bit (need_eh_cleanup, bb->index);
/* And release any SSA_NAMEs set in this statement back to the
SSA_NAME manager. */
{
gimple_stmt_iterator gsi;
- for (gsi = gsi_last (bb_seq (bb)); !gsi_end_p (gsi); gsi_prev (&gsi))
- dse_optimize_stmt (gsi);
+ for (gsi = gsi_last_bb (bb); !gsi_end_p (gsi);)
+ {
+ dse_optimize_stmt (&gsi);
+ if (gsi_end_p (gsi))
+ gsi = gsi_last_bb (bb);
+ else
+ gsi_prev (&gsi);
+ }
}
/* Main entry point. */
{
GIMPLE_PASS,
"dse", /* name */
+ OPTGROUP_NONE, /* optinfo_flags */
gate_dse, /* gate */
tree_ssa_dse, /* execute */
NULL, /* sub */