View | Details | Return to bug 60517 | Differences between
and this patch

Collapse All | Expand All

(-)gcc/tree-ssa-dse.c (-6 / +23 lines)
Lines 38-57 along with GCC; see the file COPYING3. Link Here
38
#include "ssa-iterators.h"
38
#include "ssa-iterators.h"
39
#include "stringpool.h"
39
#include "stringpool.h"
40
#include "tree-ssanames.h"
40
#include "tree-ssanames.h"
41
#include "expr.h"
41
#include "expr.h"
42
#include "tree-dfa.h"
42
#include "tree-dfa.h"
43
#include "tree-pass.h"
43
#include "tree-pass.h"
44
#include "domwalk.h"
44
#include "domwalk.h"
45
#include "flags.h"
45
#include "flags.h"
46
#include "langhooks.h"
46
#include "langhooks.h"
47
#include "tree-cfgcleanup.h"
47
#include "tree-cfgcleanup.h"
48
#include "diagnostic-core.h"
48
49
49
/* This file implements dead store elimination.
50
/* This file implements dead store elimination.
50
51
51
   A dead store is a store into a memory location which will later be
52
   A dead store is a store into a memory location which will later be
52
   overwritten by another store without any intervening loads.  In this
53
   overwritten by another store without any intervening loads.  In this
53
   case the earlier store can be deleted.
54
   case the earlier store can be deleted.
54
55
55
   In our SSA + virtual operand world we use immediate uses of virtual
56
   In our SSA + virtual operand world we use immediate uses of virtual
56
   operands to detect dead stores.  If a store's virtual definition
57
   operands to detect dead stores.  If a store's virtual definition
57
   is used precisely once by a later store to the same location which
58
   is used precisely once by a later store to the same location which
Lines 83-113 static bitmap need_eh_cleanup; Link Here
83
static bool gate_dse (void);
84
static bool gate_dse (void);
84
static unsigned int tree_ssa_dse (void);
85
static unsigned int tree_ssa_dse (void);
85
86
86
87
87
/* A helper of dse_optimize_stmt.
88
/* A helper of dse_optimize_stmt.
88
   Given a GIMPLE_ASSIGN in STMT, find a candidate statement *USE_STMT that
89
   Given a GIMPLE_ASSIGN in STMT, find a candidate statement *USE_STMT that
89
   may prove STMT to be dead.
90
   may prove STMT to be dead.
90
   Return TRUE if the above conditions are met, otherwise FALSE.  */
91
   Return TRUE if the above conditions are met, otherwise FALSE.  */
91
92
92
static bool
93
static bool
93
dse_possible_dead_store_p (gimple stmt, gimple *use_stmt)
94
dse_possible_dead_store_p (gimple stmt, gimple *use_stmt_p)
94
{
95
{
95
  gimple temp;
96
  gimple temp;
96
  unsigned cnt = 0;
97
  unsigned cnt = 0;
97
98
98
  *use_stmt = NULL;
99
  *use_stmt_p = NULL;
99
100
100
  /* Self-assignments are zombies.  */
101
  /* Self-assignments are zombies.  */
101
  if (operand_equal_p (gimple_assign_rhs1 (stmt), gimple_assign_lhs (stmt), 0))
102
  if (operand_equal_p (gimple_assign_rhs1 (stmt), gimple_assign_lhs (stmt), 0))
102
    {
103
    {
103
      *use_stmt = stmt;
104
      *use_stmt_p = stmt;
104
      return true;
105
      return true;
105
    }
106
    }
106
107
107
  /* Find the first dominated statement that clobbers (part of) the
108
  /* Find the first dominated statement that clobbers (part of) the
108
     memory stmt stores to with no intermediate statement that may use
109
     memory stmt stores to with no intermediate statement that may use
109
     part of the memory stmt stores.  That is, find a store that may
110
     part of the memory stmt stores.  That is, find a store that may
110
     prove stmt to be a dead store.  */
111
     prove stmt to be a dead store.  */
111
  temp = stmt;
112
  temp = stmt;
112
  do
113
  do
113
    {
114
    {
Lines 163-182 dse_possible_dead_store_p (gimple stmt, Link Here
163
	      if (gimple_bb (defvar_def) != gimple_bb (use_stmt)
164
	      if (gimple_bb (defvar_def) != gimple_bb (use_stmt)
164
		  && !dominated_by_p (CDI_DOMINATORS,
165
		  && !dominated_by_p (CDI_DOMINATORS,
165
				      gimple_bb (defvar_def),
166
				      gimple_bb (defvar_def),
166
				      gimple_bb (use_stmt)))
167
				      gimple_bb (use_stmt)))
167
		temp = use_stmt;
168
		temp = use_stmt;
168
	    }
169
	    }
169
	  /* If the statement is a use the store is not dead.  */
170
	  /* If the statement is a use the store is not dead.  */
170
	  else if (ref_maybe_used_by_stmt_p (use_stmt,
171
	  else if (ref_maybe_used_by_stmt_p (use_stmt,
171
					     gimple_assign_lhs (stmt)))
172
					     gimple_assign_lhs (stmt)))
172
	    {
173
	    {
174
	      if (gimple_clobber_p (stmt) && is_gimple_assign (use_stmt))
175
		{
176
		  tree rhs = gimple_assign_rhs1 (use_stmt);
177
		  tree lhs = gimple_assign_lhs (stmt);
178
		  if (operand_equal_p (get_base_address (rhs), lhs, 0))
179
		    {
180
		      if (warning_at (gimple_location (use_stmt),
181
				      OPT_Wreturn_local_addr,
182
				      "variable used after its end of life")
183
			  && DECL_P (lhs))
184
			inform (DECL_SOURCE_LOCATION (lhs), "declared here");
185
		      // Remove the clobber.
186
		      *use_stmt_p = stmt;
187
		      end_imm_use_stmt_traverse (&ui);
188
		      return true;
189
		    }
190
		}
173
	      fail = true;
191
	      fail = true;
174
	      BREAK_FROM_IMM_USE_STMT (ui);
192
	      BREAK_FROM_IMM_USE_STMT (ui);
175
	    }
193
	    }
176
	  /* If this is a store, remember it or bail out if we have
194
	  /* If this is a store, remember it or bail out if we have
177
	     multiple ones (the will be in different CFG parts then).  */
195
	     multiple ones (the will be in different CFG parts then).  */
178
	  else if (gimple_vdef (use_stmt))
196
	  else if (gimple_vdef (use_stmt))
179
	    {
197
	    {
180
	      if (temp)
198
	      if (temp)
181
		{
199
		{
182
		  fail = true;
200
		  fail = true;
Lines 199-219 dse_possible_dead_store_p (gimple stmt, Link Here
199
217
200
	  temp = stmt;
218
	  temp = stmt;
201
	  break;
219
	  break;
202
	}
220
	}
203
    }
221
    }
204
  /* We deliberately stop on clobbering statements and not only on
222
  /* We deliberately stop on clobbering statements and not only on
205
     killing ones to make walking cheaper.  Otherwise we can just
223
     killing ones to make walking cheaper.  Otherwise we can just
206
     continue walking until both stores have equal reference trees.  */
224
     continue walking until both stores have equal reference trees.  */
207
  while (!stmt_may_clobber_ref_p (temp, gimple_assign_lhs (stmt)));
225
  while (!stmt_may_clobber_ref_p (temp, gimple_assign_lhs (stmt)));
208
226
209
  *use_stmt = temp;
227
  *use_stmt_p = temp;
210
228
211
  return true;
229
  return true;
212
}
230
}
213
231
214
232
215
/* Attempt to eliminate dead stores in the statement referenced by BSI.
233
/* Attempt to eliminate dead stores in the statement referenced by BSI.
216
234
217
   A dead store is a store into a memory location which will later be
235
   A dead store is a store into a memory location which will later be
218
   overwritten by another store without any intervening loads.  In this
236
   overwritten by another store without any intervening loads.  In this
219
   case the earlier store can be deleted.
237
   case the earlier store can be deleted.
Lines 233-254 dse_optimize_stmt (gimple_stmt_iterator Link Here
233
  if (!gimple_vdef (stmt))
251
  if (!gimple_vdef (stmt))
234
    return;
252
    return;
235
253
236
  /* We know we have virtual definitions.  If this is a GIMPLE_ASSIGN
254
  /* We know we have virtual definitions.  If this is a GIMPLE_ASSIGN
237
     that's not also a function call, then record it into our table.  */
255
     that's not also a function call, then record it into our table.  */
238
  if (is_gimple_call (stmt) && gimple_call_fndecl (stmt))
256
  if (is_gimple_call (stmt) && gimple_call_fndecl (stmt))
239
    return;
257
    return;
240
258
241
  /* Don't return early on *this_2(D) ={v} {CLOBBER}.  */
259
  /* Don't return early on *this_2(D) ={v} {CLOBBER}.  */
242
  if (gimple_has_volatile_ops (stmt)
260
  if (gimple_has_volatile_ops (stmt)
243
      && (!gimple_clobber_p (stmt)
261
      && !gimple_clobber_p (stmt))
244
	  || TREE_CODE (gimple_assign_lhs (stmt)) != MEM_REF))
245
    return;
262
    return;
246
263
247
  if (is_gimple_assign (stmt))
264
  if (is_gimple_assign (stmt))
248
    {
265
    {
249
      gimple use_stmt;
266
      gimple use_stmt;
250
267
251
      if (!dse_possible_dead_store_p (stmt, &use_stmt))
268
      if (!dse_possible_dead_store_p (stmt, &use_stmt))
252
	return;
269
	return;
253
270
254
      /* But only remove *this_2(D) ={v} {CLOBBER} if killed by
271
      /* But only remove *this_2(D) ={v} {CLOBBER} if killed by

Return to bug 60517