2015-06-23 Paolo Carlini <paolo.carlini@oracle.com>
[official-gcc.git] / gcc / dse.c
blob508ec006fc3819dd9b73dca275cf4a3e07bdf419
1 /* RTL dead store elimination.
2 Copyright (C) 2005-2015 Free Software Foundation, Inc.
4 Contributed by Richard Sandiford <rsandifor@codesourcery.com>
5 and Kenneth Zadeck <zadeck@naturalbridge.com>
7 This file is part of GCC.
9 GCC is free software; you can redistribute it and/or modify it under
10 the terms of the GNU General Public License as published by the Free
11 Software Foundation; either version 3, or (at your option) any later
12 version.
14 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
15 WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 for more details.
19 You should have received a copy of the GNU General Public License
20 along with GCC; see the file COPYING3. If not see
21 <http://www.gnu.org/licenses/>. */
23 #undef BASELINE
25 #include "config.h"
26 #include "system.h"
27 #include "coretypes.h"
28 #include "tm.h"
29 #include "rtl.h"
30 #include "alias.h"
31 #include "symtab.h"
32 #include "tree.h"
33 #include "fold-const.h"
34 #include "stor-layout.h"
35 #include "tm_p.h"
36 #include "regs.h"
37 #include "hard-reg-set.h"
38 #include "regset.h"
39 #include "flags.h"
40 #include "dominance.h"
41 #include "cfg.h"
42 #include "cfgrtl.h"
43 #include "predict.h"
44 #include "basic-block.h"
45 #include "df.h"
46 #include "cselib.h"
47 #include "tree-pass.h"
48 #include "alloc-pool.h"
49 #include "insn-config.h"
50 #include "function.h"
51 #include "expmed.h"
52 #include "dojump.h"
53 #include "explow.h"
54 #include "calls.h"
55 #include "emit-rtl.h"
56 #include "varasm.h"
57 #include "stmt.h"
58 #include "expr.h"
59 #include "recog.h"
60 #include "insn-codes.h"
61 #include "optabs.h"
62 #include "dbgcnt.h"
63 #include "target.h"
64 #include "params.h"
65 #include "tree-ssa-alias.h"
66 #include "internal-fn.h"
67 #include "gimple-expr.h"
68 #include "gimple.h"
69 #include "gimple-ssa.h"
70 #include "rtl-iter.h"
71 #include "cfgcleanup.h"
73 /* This file contains three techniques for performing Dead Store
74 Elimination (dse).
76 * The first technique performs dse locally on any base address. It
77 is based on the cselib which is a local value numbering technique.
78 This technique is local to a basic block but deals with a fairly
79 general addresses.
81 * The second technique performs dse globally but is restricted to
82 base addresses that are either constant or are relative to the
83 frame_pointer.
85 * The third technique, (which is only done after register allocation)
86 processes the spill spill slots. This differs from the second
87 technique because it takes advantage of the fact that spilling is
88 completely free from the effects of aliasing.
90 Logically, dse is a backwards dataflow problem. A store can be
91 deleted if it if cannot be reached in the backward direction by any
92 use of the value being stored. However, the local technique uses a
93 forwards scan of the basic block because cselib requires that the
94 block be processed in that order.
96 The pass is logically broken into 7 steps:
98 0) Initialization.
100 1) The local algorithm, as well as scanning the insns for the two
101 global algorithms.
103 2) Analysis to see if the global algs are necessary. In the case
104 of stores base on a constant address, there must be at least two
105 stores to that address, to make it possible to delete some of the
106 stores. In the case of stores off of the frame or spill related
107 stores, only one store to an address is necessary because those
108 stores die at the end of the function.
110 3) Set up the global dataflow equations based on processing the
111 info parsed in the first step.
113 4) Solve the dataflow equations.
115 5) Delete the insns that the global analysis has indicated are
116 unnecessary.
118 6) Delete insns that store the same value as preceding store
119 where the earlier store couldn't be eliminated.
121 7) Cleanup.
123 This step uses cselib and canon_rtx to build the largest expression
124 possible for each address. This pass is a forwards pass through
125 each basic block. From the point of view of the global technique,
126 the first pass could examine a block in either direction. The
127 forwards ordering is to accommodate cselib.
129 We make a simplifying assumption: addresses fall into four broad
130 categories:
132 1) base has rtx_varies_p == false, offset is constant.
133 2) base has rtx_varies_p == false, offset variable.
134 3) base has rtx_varies_p == true, offset constant.
135 4) base has rtx_varies_p == true, offset variable.
137 The local passes are able to process all 4 kinds of addresses. The
138 global pass only handles 1).
140 The global problem is formulated as follows:
142 A store, S1, to address A, where A is not relative to the stack
143 frame, can be eliminated if all paths from S1 to the end of the
144 function contain another store to A before a read to A.
146 If the address A is relative to the stack frame, a store S2 to A
147 can be eliminated if there are no paths from S2 that reach the
148 end of the function that read A before another store to A. In
149 this case S2 can be deleted if there are paths from S2 to the
150 end of the function that have no reads or writes to A. This
151 second case allows stores to the stack frame to be deleted that
152 would otherwise die when the function returns. This cannot be
153 done if stores_off_frame_dead_at_return is not true. See the doc
154 for that variable for when this variable is false.
156 The global problem is formulated as a backwards set union
157 dataflow problem where the stores are the gens and reads are the
158 kills. Set union problems are rare and require some special
159 handling given our representation of bitmaps. A straightforward
160 implementation requires a lot of bitmaps filled with 1s.
161 These are expensive and cumbersome in our bitmap formulation so
162 care has been taken to avoid large vectors filled with 1s. See
163 the comments in bb_info and in the dataflow confluence functions
164 for details.
166 There are two places for further enhancements to this algorithm:
168 1) The original dse which was embedded in a pass called flow also
169 did local address forwarding. For example in
171 A <- r100
172 ... <- A
174 flow would replace the right hand side of the second insn with a
175 reference to r100. Most of the information is available to add this
176 to this pass. It has not done it because it is a lot of work in
177 the case that either r100 is assigned to between the first and
178 second insn and/or the second insn is a load of part of the value
179 stored by the first insn.
181 insn 5 in gcc.c-torture/compile/990203-1.c simple case.
182 insn 15 in gcc.c-torture/execute/20001017-2.c simple case.
183 insn 25 in gcc.c-torture/execute/20001026-1.c simple case.
184 insn 44 in gcc.c-torture/execute/20010910-1.c simple case.
186 2) The cleaning up of spill code is quite profitable. It currently
187 depends on reading tea leaves and chicken entrails left by reload.
188 This pass depends on reload creating a singleton alias set for each
189 spill slot and telling the next dse pass which of these alias sets
190 are the singletons. Rather than analyze the addresses of the
191 spills, dse's spill processing just does analysis of the loads and
192 stores that use those alias sets. There are three cases where this
193 falls short:
195 a) Reload sometimes creates the slot for one mode of access, and
196 then inserts loads and/or stores for a smaller mode. In this
197 case, the current code just punts on the slot. The proper thing
198 to do is to back out and use one bit vector position for each
199 byte of the entity associated with the slot. This depends on
200 KNOWING that reload always generates the accesses for each of the
201 bytes in some canonical (read that easy to understand several
202 passes after reload happens) way.
204 b) Reload sometimes decides that spill slot it allocated was not
205 large enough for the mode and goes back and allocates more slots
206 with the same mode and alias set. The backout in this case is a
207 little more graceful than (a). In this case the slot is unmarked
208 as being a spill slot and if final address comes out to be based
209 off the frame pointer, the global algorithm handles this slot.
211 c) For any pass that may prespill, there is currently no
212 mechanism to tell the dse pass that the slot being used has the
213 special properties that reload uses. It may be that all that is
214 required is to have those passes make the same calls that reload
215 does, assuming that the alias sets can be manipulated in the same
216 way. */
218 /* There are limits to the size of constant offsets we model for the
219 global problem. There are certainly test cases, that exceed this
220 limit, however, it is unlikely that there are important programs
221 that really have constant offsets this size. */
222 #define MAX_OFFSET (64 * 1024)
224 /* Obstack for the DSE dataflow bitmaps. We don't want to put these
225 on the default obstack because these bitmaps can grow quite large
226 (~2GB for the small (!) test case of PR54146) and we'll hold on to
227 all that memory until the end of the compiler run.
228 As a bonus, delete_tree_live_info can destroy all the bitmaps by just
229 releasing the whole obstack. */
230 static bitmap_obstack dse_bitmap_obstack;
232 /* Obstack for other data. As for above: Kinda nice to be able to
233 throw it all away at the end in one big sweep. */
234 static struct obstack dse_obstack;
236 /* Scratch bitmap for cselib's cselib_expand_value_rtx. */
237 static bitmap scratch = NULL;
239 struct insn_info_type;
241 /* This structure holds information about a candidate store. */
242 struct store_info
245 /* False means this is a clobber. */
246 bool is_set;
248 /* False if a single HOST_WIDE_INT bitmap is used for positions_needed. */
249 bool is_large;
251 /* The id of the mem group of the base address. If rtx_varies_p is
252 true, this is -1. Otherwise, it is the index into the group
253 table. */
254 int group_id;
256 /* This is the cselib value. */
257 cselib_val *cse_base;
259 /* This canonized mem. */
260 rtx mem;
262 /* Canonized MEM address for use by canon_true_dependence. */
263 rtx mem_addr;
265 /* If this is non-zero, it is the alias set of a spill location. */
266 alias_set_type alias_set;
268 /* The offset of the first and byte before the last byte associated
269 with the operation. */
270 HOST_WIDE_INT begin, end;
272 union
274 /* A bitmask as wide as the number of bytes in the word that
275 contains a 1 if the byte may be needed. The store is unused if
276 all of the bits are 0. This is used if IS_LARGE is false. */
277 unsigned HOST_WIDE_INT small_bitmask;
279 struct
281 /* A bitmap with one bit per byte. Cleared bit means the position
282 is needed. Used if IS_LARGE is false. */
283 bitmap bmap;
285 /* Number of set bits (i.e. unneeded bytes) in BITMAP. If it is
286 equal to END - BEGIN, the whole store is unused. */
287 int count;
288 } large;
289 } positions_needed;
291 /* The next store info for this insn. */
292 struct store_info *next;
294 /* The right hand side of the store. This is used if there is a
295 subsequent reload of the mems address somewhere later in the
296 basic block. */
297 rtx rhs;
299 /* If rhs is or holds a constant, this contains that constant,
300 otherwise NULL. */
301 rtx const_rhs;
303 /* Set if this store stores the same constant value as REDUNDANT_REASON
304 insn stored. These aren't eliminated early, because doing that
305 might prevent the earlier larger store to be eliminated. */
306 struct insn_info_type *redundant_reason;
309 /* Return a bitmask with the first N low bits set. */
311 static unsigned HOST_WIDE_INT
312 lowpart_bitmask (int n)
314 unsigned HOST_WIDE_INT mask = ~(unsigned HOST_WIDE_INT) 0;
315 return mask >> (HOST_BITS_PER_WIDE_INT - n);
318 typedef struct store_info *store_info_t;
319 static pool_allocator<store_info> cse_store_info_pool ("cse_store_info_pool",
320 100);
322 static pool_allocator<store_info> rtx_store_info_pool ("rtx_store_info_pool",
323 100);
325 /* This structure holds information about a load. These are only
326 built for rtx bases. */
327 struct read_info_type
329 /* The id of the mem group of the base address. */
330 int group_id;
332 /* If this is non-zero, it is the alias set of a spill location. */
333 alias_set_type alias_set;
335 /* The offset of the first and byte after the last byte associated
336 with the operation. If begin == end == 0, the read did not have
337 a constant offset. */
338 int begin, end;
340 /* The mem being read. */
341 rtx mem;
343 /* The next read_info for this insn. */
344 struct read_info_type *next;
346 /* Pool allocation new operator. */
347 inline void *operator new (size_t)
349 return pool.allocate ();
352 /* Delete operator utilizing pool allocation. */
353 inline void operator delete (void *ptr)
355 pool.remove ((read_info_type *) ptr);
358 /* Memory allocation pool. */
359 static pool_allocator<read_info_type> pool;
361 typedef struct read_info_type *read_info_t;
363 pool_allocator<read_info_type> read_info_type::pool ("read_info_pool", 100);
365 /* One of these records is created for each insn. */
367 struct insn_info_type
369 /* Set true if the insn contains a store but the insn itself cannot
370 be deleted. This is set if the insn is a parallel and there is
371 more than one non dead output or if the insn is in some way
372 volatile. */
373 bool cannot_delete;
375 /* This field is only used by the global algorithm. It is set true
376 if the insn contains any read of mem except for a (1). This is
377 also set if the insn is a call or has a clobber mem. If the insn
378 contains a wild read, the use_rec will be null. */
379 bool wild_read;
381 /* This is true only for CALL instructions which could potentially read
382 any non-frame memory location. This field is used by the global
383 algorithm. */
384 bool non_frame_wild_read;
386 /* This field is only used for the processing of const functions.
387 These functions cannot read memory, but they can read the stack
388 because that is where they may get their parms. We need to be
389 this conservative because, like the store motion pass, we don't
390 consider CALL_INSN_FUNCTION_USAGE when processing call insns.
391 Moreover, we need to distinguish two cases:
392 1. Before reload (register elimination), the stores related to
393 outgoing arguments are stack pointer based and thus deemed
394 of non-constant base in this pass. This requires special
395 handling but also means that the frame pointer based stores
396 need not be killed upon encountering a const function call.
397 2. After reload, the stores related to outgoing arguments can be
398 either stack pointer or hard frame pointer based. This means
399 that we have no other choice than also killing all the frame
400 pointer based stores upon encountering a const function call.
401 This field is set after reload for const function calls and before
402 reload for const tail function calls on targets where arg pointer
403 is the frame pointer. Having this set is less severe than a wild
404 read, it just means that all the frame related stores are killed
405 rather than all the stores. */
406 bool frame_read;
408 /* This field is only used for the processing of const functions.
409 It is set if the insn may contain a stack pointer based store. */
410 bool stack_pointer_based;
412 /* This is true if any of the sets within the store contains a
413 cselib base. Such stores can only be deleted by the local
414 algorithm. */
415 bool contains_cselib_groups;
417 /* The insn. */
418 rtx_insn *insn;
420 /* The list of mem sets or mem clobbers that are contained in this
421 insn. If the insn is deletable, it contains only one mem set.
422 But it could also contain clobbers. Insns that contain more than
423 one mem set are not deletable, but each of those mems are here in
424 order to provide info to delete other insns. */
425 store_info_t store_rec;
427 /* The linked list of mem uses in this insn. Only the reads from
428 rtx bases are listed here. The reads to cselib bases are
429 completely processed during the first scan and so are never
430 created. */
431 read_info_t read_rec;
433 /* The live fixed registers. We assume only fixed registers can
434 cause trouble by being clobbered from an expanded pattern;
435 storing only the live fixed registers (rather than all registers)
436 means less memory needs to be allocated / copied for the individual
437 stores. */
438 regset fixed_regs_live;
440 /* The prev insn in the basic block. */
441 struct insn_info_type * prev_insn;
443 /* The linked list of insns that are in consideration for removal in
444 the forwards pass through the basic block. This pointer may be
445 trash as it is not cleared when a wild read occurs. The only
446 time it is guaranteed to be correct is when the traversal starts
447 at active_local_stores. */
448 struct insn_info_type * next_local_store;
450 /* Pool allocation new operator. */
451 inline void *operator new (size_t)
453 return pool.allocate ();
456 /* Delete operator utilizing pool allocation. */
457 inline void operator delete (void *ptr)
459 pool.remove ((insn_info_type *) ptr);
462 /* Memory allocation pool. */
463 static pool_allocator<insn_info_type> pool;
465 typedef struct insn_info_type *insn_info_t;
467 pool_allocator<insn_info_type> insn_info_type::pool ("insn_info_pool", 100);
469 /* The linked list of stores that are under consideration in this
470 basic block. */
471 static insn_info_t active_local_stores;
472 static int active_local_stores_len;
474 struct dse_bb_info_type
476 /* Pointer to the insn info for the last insn in the block. These
477 are linked so this is how all of the insns are reached. During
478 scanning this is the current insn being scanned. */
479 insn_info_t last_insn;
481 /* The info for the global dataflow problem. */
484 /* This is set if the transfer function should and in the wild_read
485 bitmap before applying the kill and gen sets. That vector knocks
486 out most of the bits in the bitmap and thus speeds up the
487 operations. */
488 bool apply_wild_read;
490 /* The following 4 bitvectors hold information about which positions
491 of which stores are live or dead. They are indexed by
492 get_bitmap_index. */
494 /* The set of store positions that exist in this block before a wild read. */
495 bitmap gen;
497 /* The set of load positions that exist in this block above the
498 same position of a store. */
499 bitmap kill;
501 /* The set of stores that reach the top of the block without being
502 killed by a read.
504 Do not represent the in if it is all ones. Note that this is
505 what the bitvector should logically be initialized to for a set
506 intersection problem. However, like the kill set, this is too
507 expensive. So initially, the in set will only be created for the
508 exit block and any block that contains a wild read. */
509 bitmap in;
511 /* The set of stores that reach the bottom of the block from it's
512 successors.
514 Do not represent the in if it is all ones. Note that this is
515 what the bitvector should logically be initialized to for a set
516 intersection problem. However, like the kill and in set, this is
517 too expensive. So what is done is that the confluence operator
518 just initializes the vector from one of the out sets of the
519 successors of the block. */
520 bitmap out;
522 /* The following bitvector is indexed by the reg number. It
523 contains the set of regs that are live at the current instruction
524 being processed. While it contains info for all of the
525 registers, only the hard registers are actually examined. It is used
526 to assure that shift and/or add sequences that are inserted do not
527 accidentally clobber live hard regs. */
528 bitmap regs_live;
530 /* Pool allocation new operator. */
531 inline void *operator new (size_t)
533 return pool.allocate ();
536 /* Delete operator utilizing pool allocation. */
537 inline void operator delete (void *ptr)
539 pool.remove ((dse_bb_info_type *) ptr);
542 /* Memory allocation pool. */
543 static pool_allocator<dse_bb_info_type> pool;
546 typedef struct dse_bb_info_type *bb_info_t;
547 pool_allocator<dse_bb_info_type> dse_bb_info_type::pool ("bb_info_pool", 100);
549 /* Table to hold all bb_infos. */
550 static bb_info_t *bb_table;
552 /* There is a group_info for each rtx base that is used to reference
553 memory. There are also not many of the rtx bases because they are
554 very limited in scope. */
556 struct group_info
558 /* The actual base of the address. */
559 rtx rtx_base;
561 /* The sequential id of the base. This allows us to have a
562 canonical ordering of these that is not based on addresses. */
563 int id;
565 /* True if there are any positions that are to be processed
566 globally. */
567 bool process_globally;
569 /* True if the base of this group is either the frame_pointer or
570 hard_frame_pointer. */
571 bool frame_related;
573 /* A mem wrapped around the base pointer for the group in order to do
574 read dependency. It must be given BLKmode in order to encompass all
575 the possible offsets from the base. */
576 rtx base_mem;
578 /* Canonized version of base_mem's address. */
579 rtx canon_base_addr;
581 /* These two sets of two bitmaps are used to keep track of how many
582 stores are actually referencing that position from this base. We
583 only do this for rtx bases as this will be used to assign
584 positions in the bitmaps for the global problem. Bit N is set in
585 store1 on the first store for offset N. Bit N is set in store2
586 for the second store to offset N. This is all we need since we
587 only care about offsets that have two or more stores for them.
589 The "_n" suffix is for offsets less than 0 and the "_p" suffix is
590 for 0 and greater offsets.
592 There is one special case here, for stores into the stack frame,
593 we will or store1 into store2 before deciding which stores look
594 at globally. This is because stores to the stack frame that have
595 no other reads before the end of the function can also be
596 deleted. */
597 bitmap store1_n, store1_p, store2_n, store2_p;
599 /* These bitmaps keep track of offsets in this group escape this function.
600 An offset escapes if it corresponds to a named variable whose
601 addressable flag is set. */
602 bitmap escaped_n, escaped_p;
604 /* The positions in this bitmap have the same assignments as the in,
605 out, gen and kill bitmaps. This bitmap is all zeros except for
606 the positions that are occupied by stores for this group. */
607 bitmap group_kill;
609 /* The offset_map is used to map the offsets from this base into
610 positions in the global bitmaps. It is only created after all of
611 the all of stores have been scanned and we know which ones we
612 care about. */
613 int *offset_map_n, *offset_map_p;
614 int offset_map_size_n, offset_map_size_p;
616 /* Pool allocation new operator. */
617 inline void *operator new (size_t)
619 return pool.allocate ();
622 /* Delete operator utilizing pool allocation. */
623 inline void operator delete (void *ptr)
625 pool.remove ((group_info *) ptr);
628 /* Memory allocation pool. */
629 static pool_allocator<group_info> pool;
631 typedef struct group_info *group_info_t;
632 typedef const struct group_info *const_group_info_t;
634 pool_allocator<group_info> group_info::pool ("rtx_group_info_pool", 100);
636 /* Index into the rtx_group_vec. */
637 static int rtx_group_next_id;
640 static vec<group_info_t> rtx_group_vec;
643 /* This structure holds the set of changes that are being deferred
644 when removing read operation. See replace_read. */
645 struct deferred_change
648 /* The mem that is being replaced. */
649 rtx *loc;
651 /* The reg it is being replaced with. */
652 rtx reg;
654 struct deferred_change *next;
656 /* Pool allocation new operator. */
657 inline void *operator new (size_t)
659 return pool.allocate ();
662 /* Delete operator utilizing pool allocation. */
663 inline void operator delete (void *ptr)
665 pool.remove ((deferred_change *) ptr);
668 /* Memory allocation pool. */
669 static pool_allocator<deferred_change> pool;
672 typedef struct deferred_change *deferred_change_t;
674 pool_allocator<deferred_change> deferred_change::pool
675 ("deferred_change_pool", 10);
677 static deferred_change_t deferred_change_list = NULL;
679 /* The group that holds all of the clear_alias_sets. */
680 static group_info_t clear_alias_group;
682 /* The modes of the clear_alias_sets. */
683 static htab_t clear_alias_mode_table;
685 /* Hash table element to look up the mode for an alias set. */
686 struct clear_alias_mode_holder
688 alias_set_type alias_set;
689 machine_mode mode;
692 /* This is true except if cfun->stdarg -- i.e. we cannot do
693 this for vararg functions because they play games with the frame. */
694 static bool stores_off_frame_dead_at_return;
696 /* Counter for stats. */
697 static int globally_deleted;
698 static int locally_deleted;
699 static int spill_deleted;
701 static bitmap all_blocks;
703 /* Locations that are killed by calls in the global phase. */
704 static bitmap kill_on_calls;
706 /* The number of bits used in the global bitmaps. */
707 static unsigned int current_position;
709 /*----------------------------------------------------------------------------
710 Zeroth step.
712 Initialization.
713 ----------------------------------------------------------------------------*/
716 /* Find the entry associated with ALIAS_SET. */
718 static struct clear_alias_mode_holder *
719 clear_alias_set_lookup (alias_set_type alias_set)
721 struct clear_alias_mode_holder tmp_holder;
722 void **slot;
724 tmp_holder.alias_set = alias_set;
725 slot = htab_find_slot (clear_alias_mode_table, &tmp_holder, NO_INSERT);
726 gcc_assert (*slot);
728 return (struct clear_alias_mode_holder *) *slot;
732 /* Hashtable callbacks for maintaining the "bases" field of
733 store_group_info, given that the addresses are function invariants. */
735 struct invariant_group_base_hasher : typed_noop_remove <group_info>
737 typedef group_info *value_type;
738 typedef group_info *compare_type;
739 static inline hashval_t hash (const group_info *);
740 static inline bool equal (const group_info *, const group_info *);
743 inline bool
744 invariant_group_base_hasher::equal (const group_info *gi1,
745 const group_info *gi2)
747 return rtx_equal_p (gi1->rtx_base, gi2->rtx_base);
750 inline hashval_t
751 invariant_group_base_hasher::hash (const group_info *gi)
753 int do_not_record;
754 return hash_rtx (gi->rtx_base, Pmode, &do_not_record, NULL, false);
757 /* Tables of group_info structures, hashed by base value. */
758 static hash_table<invariant_group_base_hasher> *rtx_group_table;
761 /* Get the GROUP for BASE. Add a new group if it is not there. */
763 static group_info_t
764 get_group_info (rtx base)
766 struct group_info tmp_gi;
767 group_info_t gi;
768 group_info **slot;
770 if (base)
772 /* Find the store_base_info structure for BASE, creating a new one
773 if necessary. */
774 tmp_gi.rtx_base = base;
775 slot = rtx_group_table->find_slot (&tmp_gi, INSERT);
776 gi = (group_info_t) *slot;
778 else
780 if (!clear_alias_group)
782 clear_alias_group = gi = new group_info;
783 memset (gi, 0, sizeof (struct group_info));
784 gi->id = rtx_group_next_id++;
785 gi->store1_n = BITMAP_ALLOC (&dse_bitmap_obstack);
786 gi->store1_p = BITMAP_ALLOC (&dse_bitmap_obstack);
787 gi->store2_n = BITMAP_ALLOC (&dse_bitmap_obstack);
788 gi->store2_p = BITMAP_ALLOC (&dse_bitmap_obstack);
789 gi->escaped_p = BITMAP_ALLOC (&dse_bitmap_obstack);
790 gi->escaped_n = BITMAP_ALLOC (&dse_bitmap_obstack);
791 gi->group_kill = BITMAP_ALLOC (&dse_bitmap_obstack);
792 gi->process_globally = false;
793 gi->offset_map_size_n = 0;
794 gi->offset_map_size_p = 0;
795 gi->offset_map_n = NULL;
796 gi->offset_map_p = NULL;
797 rtx_group_vec.safe_push (gi);
799 return clear_alias_group;
802 if (gi == NULL)
804 *slot = gi = new group_info;
805 gi->rtx_base = base;
806 gi->id = rtx_group_next_id++;
807 gi->base_mem = gen_rtx_MEM (BLKmode, base);
808 gi->canon_base_addr = canon_rtx (base);
809 gi->store1_n = BITMAP_ALLOC (&dse_bitmap_obstack);
810 gi->store1_p = BITMAP_ALLOC (&dse_bitmap_obstack);
811 gi->store2_n = BITMAP_ALLOC (&dse_bitmap_obstack);
812 gi->store2_p = BITMAP_ALLOC (&dse_bitmap_obstack);
813 gi->escaped_p = BITMAP_ALLOC (&dse_bitmap_obstack);
814 gi->escaped_n = BITMAP_ALLOC (&dse_bitmap_obstack);
815 gi->group_kill = BITMAP_ALLOC (&dse_bitmap_obstack);
816 gi->process_globally = false;
817 gi->frame_related =
818 (base == frame_pointer_rtx) || (base == hard_frame_pointer_rtx);
819 gi->offset_map_size_n = 0;
820 gi->offset_map_size_p = 0;
821 gi->offset_map_n = NULL;
822 gi->offset_map_p = NULL;
823 rtx_group_vec.safe_push (gi);
826 return gi;
830 /* Initialization of data structures. */
832 static void
833 dse_step0 (void)
835 locally_deleted = 0;
836 globally_deleted = 0;
837 spill_deleted = 0;
839 bitmap_obstack_initialize (&dse_bitmap_obstack);
840 gcc_obstack_init (&dse_obstack);
842 scratch = BITMAP_ALLOC (&reg_obstack);
843 kill_on_calls = BITMAP_ALLOC (&dse_bitmap_obstack);
846 rtx_group_table = new hash_table<invariant_group_base_hasher> (11);
848 bb_table = XNEWVEC (bb_info_t, last_basic_block_for_fn (cfun));
849 rtx_group_next_id = 0;
851 stores_off_frame_dead_at_return = !cfun->stdarg;
853 init_alias_analysis ();
855 clear_alias_group = NULL;
860 /*----------------------------------------------------------------------------
861 First step.
863 Scan all of the insns. Any random ordering of the blocks is fine.
864 Each block is scanned in forward order to accommodate cselib which
865 is used to remove stores with non-constant bases.
866 ----------------------------------------------------------------------------*/
868 /* Delete all of the store_info recs from INSN_INFO. */
870 static void
871 free_store_info (insn_info_t insn_info)
873 store_info_t store_info = insn_info->store_rec;
874 while (store_info)
876 store_info_t next = store_info->next;
877 if (store_info->is_large)
878 BITMAP_FREE (store_info->positions_needed.large.bmap);
879 if (store_info->cse_base)
880 cse_store_info_pool.remove (store_info);
881 else
882 rtx_store_info_pool.remove (store_info);
883 store_info = next;
886 insn_info->cannot_delete = true;
887 insn_info->contains_cselib_groups = false;
888 insn_info->store_rec = NULL;
891 typedef struct
893 rtx_insn *first, *current;
894 regset fixed_regs_live;
895 bool failure;
896 } note_add_store_info;
898 /* Callback for emit_inc_dec_insn_before via note_stores.
899 Check if a register is clobbered which is live afterwards. */
901 static void
902 note_add_store (rtx loc, const_rtx expr ATTRIBUTE_UNUSED, void *data)
904 rtx_insn *insn;
905 note_add_store_info *info = (note_add_store_info *) data;
907 if (!REG_P (loc))
908 return;
910 /* If this register is referenced by the current or an earlier insn,
911 that's OK. E.g. this applies to the register that is being incremented
912 with this addition. */
913 for (insn = info->first;
914 insn != NEXT_INSN (info->current);
915 insn = NEXT_INSN (insn))
916 if (reg_referenced_p (loc, PATTERN (insn)))
917 return;
919 /* If we come here, we have a clobber of a register that's only OK
920 if that register is not live. If we don't have liveness information
921 available, fail now. */
922 if (!info->fixed_regs_live)
924 info->failure = true;
925 return;
927 /* Now check if this is a live fixed register. */
928 unsigned int end_regno = END_REGNO (loc);
929 for (unsigned int regno = REGNO (loc); regno < end_regno; ++regno)
930 if (REGNO_REG_SET_P (info->fixed_regs_live, regno))
931 info->failure = true;
934 /* Callback for for_each_inc_dec that emits an INSN that sets DEST to
935 SRC + SRCOFF before insn ARG. */
937 static int
938 emit_inc_dec_insn_before (rtx mem ATTRIBUTE_UNUSED,
939 rtx op ATTRIBUTE_UNUSED,
940 rtx dest, rtx src, rtx srcoff, void *arg)
942 insn_info_t insn_info = (insn_info_t) arg;
943 rtx_insn *insn = insn_info->insn, *new_insn, *cur;
944 note_add_store_info info;
946 /* We can reuse all operands without copying, because we are about
947 to delete the insn that contained it. */
948 if (srcoff)
950 start_sequence ();
951 emit_insn (gen_add3_insn (dest, src, srcoff));
952 new_insn = get_insns ();
953 end_sequence ();
955 else
956 new_insn = gen_move_insn (dest, src);
957 info.first = new_insn;
958 info.fixed_regs_live = insn_info->fixed_regs_live;
959 info.failure = false;
960 for (cur = new_insn; cur; cur = NEXT_INSN (cur))
962 info.current = cur;
963 note_stores (PATTERN (cur), note_add_store, &info);
966 /* If a failure was flagged above, return 1 so that for_each_inc_dec will
967 return it immediately, communicating the failure to its caller. */
968 if (info.failure)
969 return 1;
971 emit_insn_before (new_insn, insn);
973 return 0;
976 /* Before we delete INSN_INFO->INSN, make sure that the auto inc/dec, if it
977 is there, is split into a separate insn.
978 Return true on success (or if there was nothing to do), false on failure. */
980 static bool
981 check_for_inc_dec_1 (insn_info_t insn_info)
983 rtx_insn *insn = insn_info->insn;
984 rtx note = find_reg_note (insn, REG_INC, NULL_RTX);
985 if (note)
986 return for_each_inc_dec (PATTERN (insn), emit_inc_dec_insn_before,
987 insn_info) == 0;
988 return true;
992 /* Entry point for postreload. If you work on reload_cse, or you need this
993 anywhere else, consider if you can provide register liveness information
994 and add a parameter to this function so that it can be passed down in
995 insn_info.fixed_regs_live. */
996 bool
997 check_for_inc_dec (rtx_insn *insn)
999 insn_info_type insn_info;
1000 rtx note;
1002 insn_info.insn = insn;
1003 insn_info.fixed_regs_live = NULL;
1004 note = find_reg_note (insn, REG_INC, NULL_RTX);
1005 if (note)
1006 return for_each_inc_dec (PATTERN (insn), emit_inc_dec_insn_before,
1007 &insn_info) == 0;
1008 return true;
1011 /* Delete the insn and free all of the fields inside INSN_INFO. */
1013 static void
1014 delete_dead_store_insn (insn_info_t insn_info)
1016 read_info_t read_info;
1018 if (!dbg_cnt (dse))
1019 return;
1021 if (!check_for_inc_dec_1 (insn_info))
1022 return;
1023 if (dump_file && (dump_flags & TDF_DETAILS))
1025 fprintf (dump_file, "Locally deleting insn %d ",
1026 INSN_UID (insn_info->insn));
1027 if (insn_info->store_rec->alias_set)
1028 fprintf (dump_file, "alias set %d\n",
1029 (int) insn_info->store_rec->alias_set);
1030 else
1031 fprintf (dump_file, "\n");
1034 free_store_info (insn_info);
1035 read_info = insn_info->read_rec;
1037 while (read_info)
1039 read_info_t next = read_info->next;
1040 delete read_info;
1041 read_info = next;
1043 insn_info->read_rec = NULL;
1045 delete_insn (insn_info->insn);
1046 locally_deleted++;
1047 insn_info->insn = NULL;
1049 insn_info->wild_read = false;
1052 /* Return whether DECL, a local variable, can possibly escape the current
1053 function scope. */
1055 static bool
1056 local_variable_can_escape (tree decl)
1058 if (TREE_ADDRESSABLE (decl))
1059 return true;
1061 /* If this is a partitioned variable, we need to consider all the variables
1062 in the partition. This is necessary because a store into one of them can
1063 be replaced with a store into another and this may not change the outcome
1064 of the escape analysis. */
1065 if (cfun->gimple_df->decls_to_pointers != NULL)
1067 tree *namep = cfun->gimple_df->decls_to_pointers->get (decl);
1068 if (namep)
1069 return TREE_ADDRESSABLE (*namep);
1072 return false;
1075 /* Return whether EXPR can possibly escape the current function scope. */
1077 static bool
1078 can_escape (tree expr)
1080 tree base;
1081 if (!expr)
1082 return true;
1083 base = get_base_address (expr);
1084 if (DECL_P (base)
1085 && !may_be_aliased (base)
1086 && !(TREE_CODE (base) == VAR_DECL
1087 && !DECL_EXTERNAL (base)
1088 && !TREE_STATIC (base)
1089 && local_variable_can_escape (base)))
1090 return false;
1091 return true;
1094 /* Set the store* bitmaps offset_map_size* fields in GROUP based on
1095 OFFSET and WIDTH. */
1097 static void
1098 set_usage_bits (group_info_t group, HOST_WIDE_INT offset, HOST_WIDE_INT width,
1099 tree expr)
1101 HOST_WIDE_INT i;
1102 bool expr_escapes = can_escape (expr);
1103 if (offset > -MAX_OFFSET && offset + width < MAX_OFFSET)
1104 for (i=offset; i<offset+width; i++)
1106 bitmap store1;
1107 bitmap store2;
1108 bitmap escaped;
1109 int ai;
1110 if (i < 0)
1112 store1 = group->store1_n;
1113 store2 = group->store2_n;
1114 escaped = group->escaped_n;
1115 ai = -i;
1117 else
1119 store1 = group->store1_p;
1120 store2 = group->store2_p;
1121 escaped = group->escaped_p;
1122 ai = i;
1125 if (!bitmap_set_bit (store1, ai))
1126 bitmap_set_bit (store2, ai);
1127 else
1129 if (i < 0)
1131 if (group->offset_map_size_n < ai)
1132 group->offset_map_size_n = ai;
1134 else
1136 if (group->offset_map_size_p < ai)
1137 group->offset_map_size_p = ai;
1140 if (expr_escapes)
1141 bitmap_set_bit (escaped, ai);
1145 static void
1146 reset_active_stores (void)
1148 active_local_stores = NULL;
1149 active_local_stores_len = 0;
1152 /* Free all READ_REC of the LAST_INSN of BB_INFO. */
1154 static void
1155 free_read_records (bb_info_t bb_info)
1157 insn_info_t insn_info = bb_info->last_insn;
1158 read_info_t *ptr = &insn_info->read_rec;
1159 while (*ptr)
1161 read_info_t next = (*ptr)->next;
1162 if ((*ptr)->alias_set == 0)
1164 delete *ptr;
1165 *ptr = next;
1167 else
1168 ptr = &(*ptr)->next;
1172 /* Set the BB_INFO so that the last insn is marked as a wild read. */
1174 static void
1175 add_wild_read (bb_info_t bb_info)
1177 insn_info_t insn_info = bb_info->last_insn;
1178 insn_info->wild_read = true;
1179 free_read_records (bb_info);
1180 reset_active_stores ();
1183 /* Set the BB_INFO so that the last insn is marked as a wild read of
1184 non-frame locations. */
1186 static void
1187 add_non_frame_wild_read (bb_info_t bb_info)
1189 insn_info_t insn_info = bb_info->last_insn;
1190 insn_info->non_frame_wild_read = true;
1191 free_read_records (bb_info);
1192 reset_active_stores ();
1195 /* Return true if X is a constant or one of the registers that behave
1196 as a constant over the life of a function. This is equivalent to
1197 !rtx_varies_p for memory addresses. */
1199 static bool
1200 const_or_frame_p (rtx x)
1202 if (CONSTANT_P (x))
1203 return true;
1205 if (GET_CODE (x) == REG)
1207 /* Note that we have to test for the actual rtx used for the frame
1208 and arg pointers and not just the register number in case we have
1209 eliminated the frame and/or arg pointer and are using it
1210 for pseudos. */
1211 if (x == frame_pointer_rtx || x == hard_frame_pointer_rtx
1212 /* The arg pointer varies if it is not a fixed register. */
1213 || (x == arg_pointer_rtx && fixed_regs[ARG_POINTER_REGNUM])
1214 || x == pic_offset_table_rtx)
1215 return true;
1216 return false;
1219 return false;
1222 /* Take all reasonable action to put the address of MEM into the form
1223 that we can do analysis on.
1225 The gold standard is to get the address into the form: address +
1226 OFFSET where address is something that rtx_varies_p considers a
1227 constant. When we can get the address in this form, we can do
1228 global analysis on it. Note that for constant bases, address is
1229 not actually returned, only the group_id. The address can be
1230 obtained from that.
1232 If that fails, we try cselib to get a value we can at least use
1233 locally. If that fails we return false.
1235 The GROUP_ID is set to -1 for cselib bases and the index of the
1236 group for non_varying bases.
1238 FOR_READ is true if this is a mem read and false if not. */
1240 static bool
1241 canon_address (rtx mem,
1242 alias_set_type *alias_set_out,
1243 int *group_id,
1244 HOST_WIDE_INT *offset,
1245 cselib_val **base)
1247 machine_mode address_mode = get_address_mode (mem);
1248 rtx mem_address = XEXP (mem, 0);
1249 rtx expanded_address, address;
1250 int expanded;
1252 *alias_set_out = 0;
1254 cselib_lookup (mem_address, address_mode, 1, GET_MODE (mem));
1256 if (dump_file && (dump_flags & TDF_DETAILS))
1258 fprintf (dump_file, " mem: ");
1259 print_inline_rtx (dump_file, mem_address, 0);
1260 fprintf (dump_file, "\n");
1263 /* First see if just canon_rtx (mem_address) is const or frame,
1264 if not, try cselib_expand_value_rtx and call canon_rtx on that. */
1265 address = NULL_RTX;
1266 for (expanded = 0; expanded < 2; expanded++)
1268 if (expanded)
1270 /* Use cselib to replace all of the reg references with the full
1271 expression. This will take care of the case where we have
1273 r_x = base + offset;
1274 val = *r_x;
1276 by making it into
1278 val = *(base + offset); */
1280 expanded_address = cselib_expand_value_rtx (mem_address,
1281 scratch, 5);
1283 /* If this fails, just go with the address from first
1284 iteration. */
1285 if (!expanded_address)
1286 break;
1288 else
1289 expanded_address = mem_address;
1291 /* Split the address into canonical BASE + OFFSET terms. */
1292 address = canon_rtx (expanded_address);
1294 *offset = 0;
1296 if (dump_file && (dump_flags & TDF_DETAILS))
1298 if (expanded)
1300 fprintf (dump_file, "\n after cselib_expand address: ");
1301 print_inline_rtx (dump_file, expanded_address, 0);
1302 fprintf (dump_file, "\n");
1305 fprintf (dump_file, "\n after canon_rtx address: ");
1306 print_inline_rtx (dump_file, address, 0);
1307 fprintf (dump_file, "\n");
1310 if (GET_CODE (address) == CONST)
1311 address = XEXP (address, 0);
1313 if (GET_CODE (address) == PLUS
1314 && CONST_INT_P (XEXP (address, 1)))
1316 *offset = INTVAL (XEXP (address, 1));
1317 address = XEXP (address, 0);
1320 if (ADDR_SPACE_GENERIC_P (MEM_ADDR_SPACE (mem))
1321 && const_or_frame_p (address))
1323 group_info_t group = get_group_info (address);
1325 if (dump_file && (dump_flags & TDF_DETAILS))
1326 fprintf (dump_file, " gid=%d offset=%d \n",
1327 group->id, (int)*offset);
1328 *base = NULL;
1329 *group_id = group->id;
1330 return true;
1334 *base = cselib_lookup (address, address_mode, true, GET_MODE (mem));
1335 *group_id = -1;
1337 if (*base == NULL)
1339 if (dump_file && (dump_flags & TDF_DETAILS))
1340 fprintf (dump_file, " no cselib val - should be a wild read.\n");
1341 return false;
1343 if (dump_file && (dump_flags & TDF_DETAILS))
1344 fprintf (dump_file, " varying cselib base=%u:%u offset = %d\n",
1345 (*base)->uid, (*base)->hash, (int)*offset);
1346 return true;
1350 /* Clear the rhs field from the active_local_stores array. */
1352 static void
1353 clear_rhs_from_active_local_stores (void)
1355 insn_info_t ptr = active_local_stores;
1357 while (ptr)
1359 store_info_t store_info = ptr->store_rec;
1360 /* Skip the clobbers. */
1361 while (!store_info->is_set)
1362 store_info = store_info->next;
1364 store_info->rhs = NULL;
1365 store_info->const_rhs = NULL;
1367 ptr = ptr->next_local_store;
1372 /* Mark byte POS bytes from the beginning of store S_INFO as unneeded. */
1374 static inline void
1375 set_position_unneeded (store_info_t s_info, int pos)
1377 if (__builtin_expect (s_info->is_large, false))
1379 if (bitmap_set_bit (s_info->positions_needed.large.bmap, pos))
1380 s_info->positions_needed.large.count++;
1382 else
1383 s_info->positions_needed.small_bitmask
1384 &= ~(((unsigned HOST_WIDE_INT) 1) << pos);
1387 /* Mark the whole store S_INFO as unneeded. */
1389 static inline void
1390 set_all_positions_unneeded (store_info_t s_info)
1392 if (__builtin_expect (s_info->is_large, false))
1394 int pos, end = s_info->end - s_info->begin;
1395 for (pos = 0; pos < end; pos++)
1396 bitmap_set_bit (s_info->positions_needed.large.bmap, pos);
1397 s_info->positions_needed.large.count = end;
1399 else
1400 s_info->positions_needed.small_bitmask = (unsigned HOST_WIDE_INT) 0;
1403 /* Return TRUE if any bytes from S_INFO store are needed. */
1405 static inline bool
1406 any_positions_needed_p (store_info_t s_info)
1408 if (__builtin_expect (s_info->is_large, false))
1409 return (s_info->positions_needed.large.count
1410 < s_info->end - s_info->begin);
1411 else
1412 return (s_info->positions_needed.small_bitmask
1413 != (unsigned HOST_WIDE_INT) 0);
1416 /* Return TRUE if all bytes START through START+WIDTH-1 from S_INFO
1417 store are needed. */
1419 static inline bool
1420 all_positions_needed_p (store_info_t s_info, int start, int width)
1422 if (__builtin_expect (s_info->is_large, false))
1424 int end = start + width;
1425 while (start < end)
1426 if (bitmap_bit_p (s_info->positions_needed.large.bmap, start++))
1427 return false;
1428 return true;
1430 else
1432 unsigned HOST_WIDE_INT mask = lowpart_bitmask (width) << start;
1433 return (s_info->positions_needed.small_bitmask & mask) == mask;
1438 static rtx get_stored_val (store_info_t, machine_mode, HOST_WIDE_INT,
1439 HOST_WIDE_INT, basic_block, bool);
1442 /* BODY is an instruction pattern that belongs to INSN. Return 1 if
1443 there is a candidate store, after adding it to the appropriate
1444 local store group if so. */
1446 static int
1447 record_store (rtx body, bb_info_t bb_info)
1449 rtx mem, rhs, const_rhs, mem_addr;
1450 HOST_WIDE_INT offset = 0;
1451 HOST_WIDE_INT width = 0;
1452 alias_set_type spill_alias_set;
1453 insn_info_t insn_info = bb_info->last_insn;
1454 store_info_t store_info = NULL;
1455 int group_id;
1456 cselib_val *base = NULL;
1457 insn_info_t ptr, last, redundant_reason;
1458 bool store_is_unused;
1460 if (GET_CODE (body) != SET && GET_CODE (body) != CLOBBER)
1461 return 0;
1463 mem = SET_DEST (body);
1465 /* If this is not used, then this cannot be used to keep the insn
1466 from being deleted. On the other hand, it does provide something
1467 that can be used to prove that another store is dead. */
1468 store_is_unused
1469 = (find_reg_note (insn_info->insn, REG_UNUSED, mem) != NULL);
1471 /* Check whether that value is a suitable memory location. */
1472 if (!MEM_P (mem))
1474 /* If the set or clobber is unused, then it does not effect our
1475 ability to get rid of the entire insn. */
1476 if (!store_is_unused)
1477 insn_info->cannot_delete = true;
1478 return 0;
1481 /* At this point we know mem is a mem. */
1482 if (GET_MODE (mem) == BLKmode)
1484 if (GET_CODE (XEXP (mem, 0)) == SCRATCH)
1486 if (dump_file && (dump_flags & TDF_DETAILS))
1487 fprintf (dump_file, " adding wild read for (clobber (mem:BLK (scratch))\n");
1488 add_wild_read (bb_info);
1489 insn_info->cannot_delete = true;
1490 return 0;
1492 /* Handle (set (mem:BLK (addr) [... S36 ...]) (const_int 0))
1493 as memset (addr, 0, 36); */
1494 else if (!MEM_SIZE_KNOWN_P (mem)
1495 || MEM_SIZE (mem) <= 0
1496 || MEM_SIZE (mem) > MAX_OFFSET
1497 || GET_CODE (body) != SET
1498 || !CONST_INT_P (SET_SRC (body)))
1500 if (!store_is_unused)
1502 /* If the set or clobber is unused, then it does not effect our
1503 ability to get rid of the entire insn. */
1504 insn_info->cannot_delete = true;
1505 clear_rhs_from_active_local_stores ();
1507 return 0;
1511 /* We can still process a volatile mem, we just cannot delete it. */
1512 if (MEM_VOLATILE_P (mem))
1513 insn_info->cannot_delete = true;
1515 if (!canon_address (mem, &spill_alias_set, &group_id, &offset, &base))
1517 clear_rhs_from_active_local_stores ();
1518 return 0;
1521 if (GET_MODE (mem) == BLKmode)
1522 width = MEM_SIZE (mem);
1523 else
1524 width = GET_MODE_SIZE (GET_MODE (mem));
1526 if (spill_alias_set)
1528 bitmap store1 = clear_alias_group->store1_p;
1529 bitmap store2 = clear_alias_group->store2_p;
1531 gcc_assert (GET_MODE (mem) != BLKmode);
1533 if (!bitmap_set_bit (store1, spill_alias_set))
1534 bitmap_set_bit (store2, spill_alias_set);
1536 if (clear_alias_group->offset_map_size_p < spill_alias_set)
1537 clear_alias_group->offset_map_size_p = spill_alias_set;
1539 store_info = rtx_store_info_pool.allocate ();
1541 if (dump_file && (dump_flags & TDF_DETAILS))
1542 fprintf (dump_file, " processing spill store %d(%s)\n",
1543 (int) spill_alias_set, GET_MODE_NAME (GET_MODE (mem)));
1545 else if (group_id >= 0)
1547 /* In the restrictive case where the base is a constant or the
1548 frame pointer we can do global analysis. */
1550 group_info_t group
1551 = rtx_group_vec[group_id];
1552 tree expr = MEM_EXPR (mem);
1554 store_info = rtx_store_info_pool.allocate ();
1555 set_usage_bits (group, offset, width, expr);
1557 if (dump_file && (dump_flags & TDF_DETAILS))
1558 fprintf (dump_file, " processing const base store gid=%d[%d..%d)\n",
1559 group_id, (int)offset, (int)(offset+width));
1561 else
1563 if (may_be_sp_based_p (XEXP (mem, 0)))
1564 insn_info->stack_pointer_based = true;
1565 insn_info->contains_cselib_groups = true;
1567 store_info = cse_store_info_pool.allocate ();
1568 group_id = -1;
1570 if (dump_file && (dump_flags & TDF_DETAILS))
1571 fprintf (dump_file, " processing cselib store [%d..%d)\n",
1572 (int)offset, (int)(offset+width));
1575 const_rhs = rhs = NULL_RTX;
1576 if (GET_CODE (body) == SET
1577 /* No place to keep the value after ra. */
1578 && !reload_completed
1579 && (REG_P (SET_SRC (body))
1580 || GET_CODE (SET_SRC (body)) == SUBREG
1581 || CONSTANT_P (SET_SRC (body)))
1582 && !MEM_VOLATILE_P (mem)
1583 /* Sometimes the store and reload is used for truncation and
1584 rounding. */
1585 && !(FLOAT_MODE_P (GET_MODE (mem)) && (flag_float_store)))
1587 rhs = SET_SRC (body);
1588 if (CONSTANT_P (rhs))
1589 const_rhs = rhs;
1590 else if (body == PATTERN (insn_info->insn))
1592 rtx tem = find_reg_note (insn_info->insn, REG_EQUAL, NULL_RTX);
1593 if (tem && CONSTANT_P (XEXP (tem, 0)))
1594 const_rhs = XEXP (tem, 0);
1596 if (const_rhs == NULL_RTX && REG_P (rhs))
1598 rtx tem = cselib_expand_value_rtx (rhs, scratch, 5);
1600 if (tem && CONSTANT_P (tem))
1601 const_rhs = tem;
1605 /* Check to see if this stores causes some other stores to be
1606 dead. */
1607 ptr = active_local_stores;
1608 last = NULL;
1609 redundant_reason = NULL;
1610 mem = canon_rtx (mem);
1611 /* For alias_set != 0 canon_true_dependence should be never called. */
1612 if (spill_alias_set)
1613 mem_addr = NULL_RTX;
1614 else
1616 if (group_id < 0)
1617 mem_addr = base->val_rtx;
1618 else
1620 group_info_t group
1621 = rtx_group_vec[group_id];
1622 mem_addr = group->canon_base_addr;
1624 /* get_addr can only handle VALUE but cannot handle expr like:
1625 VALUE + OFFSET, so call get_addr to get original addr for
1626 mem_addr before plus_constant. */
1627 mem_addr = get_addr (mem_addr);
1628 if (offset)
1629 mem_addr = plus_constant (get_address_mode (mem), mem_addr, offset);
1632 while (ptr)
1634 insn_info_t next = ptr->next_local_store;
1635 store_info_t s_info = ptr->store_rec;
1636 bool del = true;
1638 /* Skip the clobbers. We delete the active insn if this insn
1639 shadows the set. To have been put on the active list, it
1640 has exactly on set. */
1641 while (!s_info->is_set)
1642 s_info = s_info->next;
1644 if (s_info->alias_set != spill_alias_set)
1645 del = false;
1646 else if (s_info->alias_set)
1648 struct clear_alias_mode_holder *entry
1649 = clear_alias_set_lookup (s_info->alias_set);
1650 /* Generally, spills cannot be processed if and of the
1651 references to the slot have a different mode. But if
1652 we are in the same block and mode is exactly the same
1653 between this store and one before in the same block,
1654 we can still delete it. */
1655 if ((GET_MODE (mem) == GET_MODE (s_info->mem))
1656 && (GET_MODE (mem) == entry->mode))
1658 del = true;
1659 set_all_positions_unneeded (s_info);
1661 if (dump_file && (dump_flags & TDF_DETAILS))
1662 fprintf (dump_file, " trying spill store in insn=%d alias_set=%d\n",
1663 INSN_UID (ptr->insn), (int) s_info->alias_set);
1665 else if ((s_info->group_id == group_id)
1666 && (s_info->cse_base == base))
1668 HOST_WIDE_INT i;
1669 if (dump_file && (dump_flags & TDF_DETAILS))
1670 fprintf (dump_file, " trying store in insn=%d gid=%d[%d..%d)\n",
1671 INSN_UID (ptr->insn), s_info->group_id,
1672 (int)s_info->begin, (int)s_info->end);
1674 /* Even if PTR won't be eliminated as unneeded, if both
1675 PTR and this insn store the same constant value, we might
1676 eliminate this insn instead. */
1677 if (s_info->const_rhs
1678 && const_rhs
1679 && offset >= s_info->begin
1680 && offset + width <= s_info->end
1681 && all_positions_needed_p (s_info, offset - s_info->begin,
1682 width))
1684 if (GET_MODE (mem) == BLKmode)
1686 if (GET_MODE (s_info->mem) == BLKmode
1687 && s_info->const_rhs == const_rhs)
1688 redundant_reason = ptr;
1690 else if (s_info->const_rhs == const0_rtx
1691 && const_rhs == const0_rtx)
1692 redundant_reason = ptr;
1693 else
1695 rtx val;
1696 start_sequence ();
1697 val = get_stored_val (s_info, GET_MODE (mem),
1698 offset, offset + width,
1699 BLOCK_FOR_INSN (insn_info->insn),
1700 true);
1701 if (get_insns () != NULL)
1702 val = NULL_RTX;
1703 end_sequence ();
1704 if (val && rtx_equal_p (val, const_rhs))
1705 redundant_reason = ptr;
1709 for (i = MAX (offset, s_info->begin);
1710 i < offset + width && i < s_info->end;
1711 i++)
1712 set_position_unneeded (s_info, i - s_info->begin);
1714 else if (s_info->rhs)
1715 /* Need to see if it is possible for this store to overwrite
1716 the value of store_info. If it is, set the rhs to NULL to
1717 keep it from being used to remove a load. */
1719 if (canon_true_dependence (s_info->mem,
1720 GET_MODE (s_info->mem),
1721 s_info->mem_addr,
1722 mem, mem_addr))
1724 s_info->rhs = NULL;
1725 s_info->const_rhs = NULL;
1729 /* An insn can be deleted if every position of every one of
1730 its s_infos is zero. */
1731 if (any_positions_needed_p (s_info))
1732 del = false;
1734 if (del)
1736 insn_info_t insn_to_delete = ptr;
1738 active_local_stores_len--;
1739 if (last)
1740 last->next_local_store = ptr->next_local_store;
1741 else
1742 active_local_stores = ptr->next_local_store;
1744 if (!insn_to_delete->cannot_delete)
1745 delete_dead_store_insn (insn_to_delete);
1747 else
1748 last = ptr;
1750 ptr = next;
1753 /* Finish filling in the store_info. */
1754 store_info->next = insn_info->store_rec;
1755 insn_info->store_rec = store_info;
1756 store_info->mem = mem;
1757 store_info->alias_set = spill_alias_set;
1758 store_info->mem_addr = mem_addr;
1759 store_info->cse_base = base;
1760 if (width > HOST_BITS_PER_WIDE_INT)
1762 store_info->is_large = true;
1763 store_info->positions_needed.large.count = 0;
1764 store_info->positions_needed.large.bmap = BITMAP_ALLOC (&dse_bitmap_obstack);
1766 else
1768 store_info->is_large = false;
1769 store_info->positions_needed.small_bitmask = lowpart_bitmask (width);
1771 store_info->group_id = group_id;
1772 store_info->begin = offset;
1773 store_info->end = offset + width;
1774 store_info->is_set = GET_CODE (body) == SET;
1775 store_info->rhs = rhs;
1776 store_info->const_rhs = const_rhs;
1777 store_info->redundant_reason = redundant_reason;
1779 /* If this is a clobber, we return 0. We will only be able to
1780 delete this insn if there is only one store USED store, but we
1781 can use the clobber to delete other stores earlier. */
1782 return store_info->is_set ? 1 : 0;
1786 static void
1787 dump_insn_info (const char * start, insn_info_t insn_info)
1789 fprintf (dump_file, "%s insn=%d %s\n", start,
1790 INSN_UID (insn_info->insn),
1791 insn_info->store_rec ? "has store" : "naked");
1795 /* If the modes are different and the value's source and target do not
1796 line up, we need to extract the value from lower part of the rhs of
1797 the store, shift it, and then put it into a form that can be shoved
1798 into the read_insn. This function generates a right SHIFT of a
1799 value that is at least ACCESS_SIZE bytes wide of READ_MODE. The
1800 shift sequence is returned or NULL if we failed to find a
1801 shift. */
1803 static rtx
1804 find_shift_sequence (int access_size,
1805 store_info_t store_info,
1806 machine_mode read_mode,
1807 int shift, bool speed, bool require_cst)
1809 machine_mode store_mode = GET_MODE (store_info->mem);
1810 machine_mode new_mode;
1811 rtx read_reg = NULL;
1813 /* Some machines like the x86 have shift insns for each size of
1814 operand. Other machines like the ppc or the ia-64 may only have
1815 shift insns that shift values within 32 or 64 bit registers.
1816 This loop tries to find the smallest shift insn that will right
1817 justify the value we want to read but is available in one insn on
1818 the machine. */
1820 for (new_mode = smallest_mode_for_size (access_size * BITS_PER_UNIT,
1821 MODE_INT);
1822 GET_MODE_BITSIZE (new_mode) <= BITS_PER_WORD;
1823 new_mode = GET_MODE_WIDER_MODE (new_mode))
1825 rtx target, new_reg, new_lhs;
1826 rtx_insn *shift_seq, *insn;
1827 int cost;
1829 /* If a constant was stored into memory, try to simplify it here,
1830 otherwise the cost of the shift might preclude this optimization
1831 e.g. at -Os, even when no actual shift will be needed. */
1832 if (store_info->const_rhs)
1834 unsigned int byte = subreg_lowpart_offset (new_mode, store_mode);
1835 rtx ret = simplify_subreg (new_mode, store_info->const_rhs,
1836 store_mode, byte);
1837 if (ret && CONSTANT_P (ret))
1839 ret = simplify_const_binary_operation (LSHIFTRT, new_mode,
1840 ret, GEN_INT (shift));
1841 if (ret && CONSTANT_P (ret))
1843 byte = subreg_lowpart_offset (read_mode, new_mode);
1844 ret = simplify_subreg (read_mode, ret, new_mode, byte);
1845 if (ret && CONSTANT_P (ret)
1846 && set_src_cost (ret, speed) <= COSTS_N_INSNS (1))
1847 return ret;
1852 if (require_cst)
1853 return NULL_RTX;
1855 /* Try a wider mode if truncating the store mode to NEW_MODE
1856 requires a real instruction. */
1857 if (GET_MODE_BITSIZE (new_mode) < GET_MODE_BITSIZE (store_mode)
1858 && !TRULY_NOOP_TRUNCATION_MODES_P (new_mode, store_mode))
1859 continue;
1861 /* Also try a wider mode if the necessary punning is either not
1862 desirable or not possible. */
1863 if (!CONSTANT_P (store_info->rhs)
1864 && !MODES_TIEABLE_P (new_mode, store_mode))
1865 continue;
1867 new_reg = gen_reg_rtx (new_mode);
1869 start_sequence ();
1871 /* In theory we could also check for an ashr. Ian Taylor knows
1872 of one dsp where the cost of these two was not the same. But
1873 this really is a rare case anyway. */
1874 target = expand_binop (new_mode, lshr_optab, new_reg,
1875 GEN_INT (shift), new_reg, 1, OPTAB_DIRECT);
1877 shift_seq = get_insns ();
1878 end_sequence ();
1880 if (target != new_reg || shift_seq == NULL)
1881 continue;
1883 cost = 0;
1884 for (insn = shift_seq; insn != NULL_RTX; insn = NEXT_INSN (insn))
1885 if (INSN_P (insn))
1886 cost += insn_rtx_cost (PATTERN (insn), speed);
1888 /* The computation up to here is essentially independent
1889 of the arguments and could be precomputed. It may
1890 not be worth doing so. We could precompute if
1891 worthwhile or at least cache the results. The result
1892 technically depends on both SHIFT and ACCESS_SIZE,
1893 but in practice the answer will depend only on ACCESS_SIZE. */
1895 if (cost > COSTS_N_INSNS (1))
1896 continue;
1898 new_lhs = extract_low_bits (new_mode, store_mode,
1899 copy_rtx (store_info->rhs));
1900 if (new_lhs == NULL_RTX)
1901 continue;
1903 /* We found an acceptable shift. Generate a move to
1904 take the value from the store and put it into the
1905 shift pseudo, then shift it, then generate another
1906 move to put in into the target of the read. */
1907 emit_move_insn (new_reg, new_lhs);
1908 emit_insn (shift_seq);
1909 read_reg = extract_low_bits (read_mode, new_mode, new_reg);
1910 break;
1913 return read_reg;
1917 /* Call back for note_stores to find the hard regs set or clobbered by
1918 insn. Data is a bitmap of the hardregs set so far. */
1920 static void
1921 look_for_hardregs (rtx x, const_rtx pat ATTRIBUTE_UNUSED, void *data)
1923 bitmap regs_set = (bitmap) data;
1925 if (REG_P (x)
1926 && HARD_REGISTER_P (x))
1927 bitmap_set_range (regs_set, REGNO (x), REG_NREGS (x));
1930 /* Helper function for replace_read and record_store.
1931 Attempt to return a value stored in STORE_INFO, from READ_BEGIN
1932 to one before READ_END bytes read in READ_MODE. Return NULL
1933 if not successful. If REQUIRE_CST is true, return always constant. */
1935 static rtx
1936 get_stored_val (store_info_t store_info, machine_mode read_mode,
1937 HOST_WIDE_INT read_begin, HOST_WIDE_INT read_end,
1938 basic_block bb, bool require_cst)
1940 machine_mode store_mode = GET_MODE (store_info->mem);
1941 int shift;
1942 int access_size; /* In bytes. */
1943 rtx read_reg;
1945 /* To get here the read is within the boundaries of the write so
1946 shift will never be negative. Start out with the shift being in
1947 bytes. */
1948 if (store_mode == BLKmode)
1949 shift = 0;
1950 else if (BYTES_BIG_ENDIAN)
1951 shift = store_info->end - read_end;
1952 else
1953 shift = read_begin - store_info->begin;
1955 access_size = shift + GET_MODE_SIZE (read_mode);
1957 /* From now on it is bits. */
1958 shift *= BITS_PER_UNIT;
1960 if (shift)
1961 read_reg = find_shift_sequence (access_size, store_info, read_mode, shift,
1962 optimize_bb_for_speed_p (bb),
1963 require_cst);
1964 else if (store_mode == BLKmode)
1966 /* The store is a memset (addr, const_val, const_size). */
1967 gcc_assert (CONST_INT_P (store_info->rhs));
1968 store_mode = int_mode_for_mode (read_mode);
1969 if (store_mode == BLKmode)
1970 read_reg = NULL_RTX;
1971 else if (store_info->rhs == const0_rtx)
1972 read_reg = extract_low_bits (read_mode, store_mode, const0_rtx);
1973 else if (GET_MODE_BITSIZE (store_mode) > HOST_BITS_PER_WIDE_INT
1974 || BITS_PER_UNIT >= HOST_BITS_PER_WIDE_INT)
1975 read_reg = NULL_RTX;
1976 else
1978 unsigned HOST_WIDE_INT c
1979 = INTVAL (store_info->rhs)
1980 & (((HOST_WIDE_INT) 1 << BITS_PER_UNIT) - 1);
1981 int shift = BITS_PER_UNIT;
1982 while (shift < HOST_BITS_PER_WIDE_INT)
1984 c |= (c << shift);
1985 shift <<= 1;
1987 read_reg = gen_int_mode (c, store_mode);
1988 read_reg = extract_low_bits (read_mode, store_mode, read_reg);
1991 else if (store_info->const_rhs
1992 && (require_cst
1993 || GET_MODE_CLASS (read_mode) != GET_MODE_CLASS (store_mode)))
1994 read_reg = extract_low_bits (read_mode, store_mode,
1995 copy_rtx (store_info->const_rhs));
1996 else
1997 read_reg = extract_low_bits (read_mode, store_mode,
1998 copy_rtx (store_info->rhs));
1999 if (require_cst && read_reg && !CONSTANT_P (read_reg))
2000 read_reg = NULL_RTX;
2001 return read_reg;
2004 /* Take a sequence of:
2005 A <- r1
2007 ... <- A
2009 and change it into
2010 r2 <- r1
2011 A <- r1
2013 ... <- r2
2017 r3 <- extract (r1)
2018 r3 <- r3 >> shift
2019 r2 <- extract (r3)
2020 ... <- r2
2024 r2 <- extract (r1)
2025 ... <- r2
2027 Depending on the alignment and the mode of the store and
2028 subsequent load.
2031 The STORE_INFO and STORE_INSN are for the store and READ_INFO
2032 and READ_INSN are for the read. Return true if the replacement
2033 went ok. */
2035 static bool
2036 replace_read (store_info_t store_info, insn_info_t store_insn,
2037 read_info_t read_info, insn_info_t read_insn, rtx *loc,
2038 bitmap regs_live)
2040 machine_mode store_mode = GET_MODE (store_info->mem);
2041 machine_mode read_mode = GET_MODE (read_info->mem);
2042 rtx_insn *insns, *this_insn;
2043 rtx read_reg;
2044 basic_block bb;
2046 if (!dbg_cnt (dse))
2047 return false;
2049 /* Create a sequence of instructions to set up the read register.
2050 This sequence goes immediately before the store and its result
2051 is read by the load.
2053 We need to keep this in perspective. We are replacing a read
2054 with a sequence of insns, but the read will almost certainly be
2055 in cache, so it is not going to be an expensive one. Thus, we
2056 are not willing to do a multi insn shift or worse a subroutine
2057 call to get rid of the read. */
2058 if (dump_file && (dump_flags & TDF_DETAILS))
2059 fprintf (dump_file, "trying to replace %smode load in insn %d"
2060 " from %smode store in insn %d\n",
2061 GET_MODE_NAME (read_mode), INSN_UID (read_insn->insn),
2062 GET_MODE_NAME (store_mode), INSN_UID (store_insn->insn));
2063 start_sequence ();
2064 bb = BLOCK_FOR_INSN (read_insn->insn);
2065 read_reg = get_stored_val (store_info,
2066 read_mode, read_info->begin, read_info->end,
2067 bb, false);
2068 if (read_reg == NULL_RTX)
2070 end_sequence ();
2071 if (dump_file && (dump_flags & TDF_DETAILS))
2072 fprintf (dump_file, " -- could not extract bits of stored value\n");
2073 return false;
2075 /* Force the value into a new register so that it won't be clobbered
2076 between the store and the load. */
2077 read_reg = copy_to_mode_reg (read_mode, read_reg);
2078 insns = get_insns ();
2079 end_sequence ();
2081 if (insns != NULL_RTX)
2083 /* Now we have to scan the set of new instructions to see if the
2084 sequence contains and sets of hardregs that happened to be
2085 live at this point. For instance, this can happen if one of
2086 the insns sets the CC and the CC happened to be live at that
2087 point. This does occasionally happen, see PR 37922. */
2088 bitmap regs_set = BITMAP_ALLOC (&reg_obstack);
2090 for (this_insn = insns; this_insn != NULL_RTX; this_insn = NEXT_INSN (this_insn))
2091 note_stores (PATTERN (this_insn), look_for_hardregs, regs_set);
2093 bitmap_and_into (regs_set, regs_live);
2094 if (!bitmap_empty_p (regs_set))
2096 if (dump_file && (dump_flags & TDF_DETAILS))
2098 fprintf (dump_file,
2099 "abandoning replacement because sequence clobbers live hardregs:");
2100 df_print_regset (dump_file, regs_set);
2103 BITMAP_FREE (regs_set);
2104 return false;
2106 BITMAP_FREE (regs_set);
2109 if (validate_change (read_insn->insn, loc, read_reg, 0))
2111 deferred_change_t change = new deferred_change;
2113 /* Insert this right before the store insn where it will be safe
2114 from later insns that might change it before the read. */
2115 emit_insn_before (insns, store_insn->insn);
2117 /* And now for the kludge part: cselib croaks if you just
2118 return at this point. There are two reasons for this:
2120 1) Cselib has an idea of how many pseudos there are and
2121 that does not include the new ones we just added.
2123 2) Cselib does not know about the move insn we added
2124 above the store_info, and there is no way to tell it
2125 about it, because it has "moved on".
2127 Problem (1) is fixable with a certain amount of engineering.
2128 Problem (2) is requires starting the bb from scratch. This
2129 could be expensive.
2131 So we are just going to have to lie. The move/extraction
2132 insns are not really an issue, cselib did not see them. But
2133 the use of the new pseudo read_insn is a real problem because
2134 cselib has not scanned this insn. The way that we solve this
2135 problem is that we are just going to put the mem back for now
2136 and when we are finished with the block, we undo this. We
2137 keep a table of mems to get rid of. At the end of the basic
2138 block we can put them back. */
2140 *loc = read_info->mem;
2141 change->next = deferred_change_list;
2142 deferred_change_list = change;
2143 change->loc = loc;
2144 change->reg = read_reg;
2146 /* Get rid of the read_info, from the point of view of the
2147 rest of dse, play like this read never happened. */
2148 read_insn->read_rec = read_info->next;
2149 delete read_info;
2150 if (dump_file && (dump_flags & TDF_DETAILS))
2152 fprintf (dump_file, " -- replaced the loaded MEM with ");
2153 print_simple_rtl (dump_file, read_reg);
2154 fprintf (dump_file, "\n");
2156 return true;
2158 else
2160 if (dump_file && (dump_flags & TDF_DETAILS))
2162 fprintf (dump_file, " -- replacing the loaded MEM with ");
2163 print_simple_rtl (dump_file, read_reg);
2164 fprintf (dump_file, " led to an invalid instruction\n");
2166 return false;
2170 /* Check the address of MEM *LOC and kill any appropriate stores that may
2171 be active. */
2173 static void
2174 check_mem_read_rtx (rtx *loc, bb_info_t bb_info)
2176 rtx mem = *loc, mem_addr;
2177 insn_info_t insn_info;
2178 HOST_WIDE_INT offset = 0;
2179 HOST_WIDE_INT width = 0;
2180 alias_set_type spill_alias_set = 0;
2181 cselib_val *base = NULL;
2182 int group_id;
2183 read_info_t read_info;
2185 insn_info = bb_info->last_insn;
2187 if ((MEM_ALIAS_SET (mem) == ALIAS_SET_MEMORY_BARRIER)
2188 || (MEM_VOLATILE_P (mem)))
2190 if (dump_file && (dump_flags & TDF_DETAILS))
2191 fprintf (dump_file, " adding wild read, volatile or barrier.\n");
2192 add_wild_read (bb_info);
2193 insn_info->cannot_delete = true;
2194 return;
2197 /* If it is reading readonly mem, then there can be no conflict with
2198 another write. */
2199 if (MEM_READONLY_P (mem))
2200 return;
2202 if (!canon_address (mem, &spill_alias_set, &group_id, &offset, &base))
2204 if (dump_file && (dump_flags & TDF_DETAILS))
2205 fprintf (dump_file, " adding wild read, canon_address failure.\n");
2206 add_wild_read (bb_info);
2207 return;
2210 if (GET_MODE (mem) == BLKmode)
2211 width = -1;
2212 else
2213 width = GET_MODE_SIZE (GET_MODE (mem));
2215 read_info = new read_info_type;
2216 read_info->group_id = group_id;
2217 read_info->mem = mem;
2218 read_info->alias_set = spill_alias_set;
2219 read_info->begin = offset;
2220 read_info->end = offset + width;
2221 read_info->next = insn_info->read_rec;
2222 insn_info->read_rec = read_info;
2223 /* For alias_set != 0 canon_true_dependence should be never called. */
2224 if (spill_alias_set)
2225 mem_addr = NULL_RTX;
2226 else
2228 if (group_id < 0)
2229 mem_addr = base->val_rtx;
2230 else
2232 group_info_t group
2233 = rtx_group_vec[group_id];
2234 mem_addr = group->canon_base_addr;
2236 /* get_addr can only handle VALUE but cannot handle expr like:
2237 VALUE + OFFSET, so call get_addr to get original addr for
2238 mem_addr before plus_constant. */
2239 mem_addr = get_addr (mem_addr);
2240 if (offset)
2241 mem_addr = plus_constant (get_address_mode (mem), mem_addr, offset);
2244 /* We ignore the clobbers in store_info. The is mildly aggressive,
2245 but there really should not be a clobber followed by a read. */
2247 if (spill_alias_set)
2249 insn_info_t i_ptr = active_local_stores;
2250 insn_info_t last = NULL;
2252 if (dump_file && (dump_flags & TDF_DETAILS))
2253 fprintf (dump_file, " processing spill load %d\n",
2254 (int) spill_alias_set);
2256 while (i_ptr)
2258 store_info_t store_info = i_ptr->store_rec;
2260 /* Skip the clobbers. */
2261 while (!store_info->is_set)
2262 store_info = store_info->next;
2264 if (store_info->alias_set == spill_alias_set)
2266 if (dump_file && (dump_flags & TDF_DETAILS))
2267 dump_insn_info ("removing from active", i_ptr);
2269 active_local_stores_len--;
2270 if (last)
2271 last->next_local_store = i_ptr->next_local_store;
2272 else
2273 active_local_stores = i_ptr->next_local_store;
2275 else
2276 last = i_ptr;
2277 i_ptr = i_ptr->next_local_store;
2280 else if (group_id >= 0)
2282 /* This is the restricted case where the base is a constant or
2283 the frame pointer and offset is a constant. */
2284 insn_info_t i_ptr = active_local_stores;
2285 insn_info_t last = NULL;
2287 if (dump_file && (dump_flags & TDF_DETAILS))
2289 if (width == -1)
2290 fprintf (dump_file, " processing const load gid=%d[BLK]\n",
2291 group_id);
2292 else
2293 fprintf (dump_file, " processing const load gid=%d[%d..%d)\n",
2294 group_id, (int)offset, (int)(offset+width));
2297 while (i_ptr)
2299 bool remove = false;
2300 store_info_t store_info = i_ptr->store_rec;
2302 /* Skip the clobbers. */
2303 while (!store_info->is_set)
2304 store_info = store_info->next;
2306 /* There are three cases here. */
2307 if (store_info->group_id < 0)
2308 /* We have a cselib store followed by a read from a
2309 const base. */
2310 remove
2311 = canon_true_dependence (store_info->mem,
2312 GET_MODE (store_info->mem),
2313 store_info->mem_addr,
2314 mem, mem_addr);
2316 else if (group_id == store_info->group_id)
2318 /* This is a block mode load. We may get lucky and
2319 canon_true_dependence may save the day. */
2320 if (width == -1)
2321 remove
2322 = canon_true_dependence (store_info->mem,
2323 GET_MODE (store_info->mem),
2324 store_info->mem_addr,
2325 mem, mem_addr);
2327 /* If this read is just reading back something that we just
2328 stored, rewrite the read. */
2329 else
2331 if (store_info->rhs
2332 && offset >= store_info->begin
2333 && offset + width <= store_info->end
2334 && all_positions_needed_p (store_info,
2335 offset - store_info->begin,
2336 width)
2337 && replace_read (store_info, i_ptr, read_info,
2338 insn_info, loc, bb_info->regs_live))
2339 return;
2341 /* The bases are the same, just see if the offsets
2342 overlap. */
2343 if ((offset < store_info->end)
2344 && (offset + width > store_info->begin))
2345 remove = true;
2349 /* else
2350 The else case that is missing here is that the
2351 bases are constant but different. There is nothing
2352 to do here because there is no overlap. */
2354 if (remove)
2356 if (dump_file && (dump_flags & TDF_DETAILS))
2357 dump_insn_info ("removing from active", i_ptr);
2359 active_local_stores_len--;
2360 if (last)
2361 last->next_local_store = i_ptr->next_local_store;
2362 else
2363 active_local_stores = i_ptr->next_local_store;
2365 else
2366 last = i_ptr;
2367 i_ptr = i_ptr->next_local_store;
2370 else
2372 insn_info_t i_ptr = active_local_stores;
2373 insn_info_t last = NULL;
2374 if (dump_file && (dump_flags & TDF_DETAILS))
2376 fprintf (dump_file, " processing cselib load mem:");
2377 print_inline_rtx (dump_file, mem, 0);
2378 fprintf (dump_file, "\n");
2381 while (i_ptr)
2383 bool remove = false;
2384 store_info_t store_info = i_ptr->store_rec;
2386 if (dump_file && (dump_flags & TDF_DETAILS))
2387 fprintf (dump_file, " processing cselib load against insn %d\n",
2388 INSN_UID (i_ptr->insn));
2390 /* Skip the clobbers. */
2391 while (!store_info->is_set)
2392 store_info = store_info->next;
2394 /* If this read is just reading back something that we just
2395 stored, rewrite the read. */
2396 if (store_info->rhs
2397 && store_info->group_id == -1
2398 && store_info->cse_base == base
2399 && width != -1
2400 && offset >= store_info->begin
2401 && offset + width <= store_info->end
2402 && all_positions_needed_p (store_info,
2403 offset - store_info->begin, width)
2404 && replace_read (store_info, i_ptr, read_info, insn_info, loc,
2405 bb_info->regs_live))
2406 return;
2408 if (!store_info->alias_set)
2409 remove = canon_true_dependence (store_info->mem,
2410 GET_MODE (store_info->mem),
2411 store_info->mem_addr,
2412 mem, mem_addr);
2414 if (remove)
2416 if (dump_file && (dump_flags & TDF_DETAILS))
2417 dump_insn_info ("removing from active", i_ptr);
2419 active_local_stores_len--;
2420 if (last)
2421 last->next_local_store = i_ptr->next_local_store;
2422 else
2423 active_local_stores = i_ptr->next_local_store;
2425 else
2426 last = i_ptr;
2427 i_ptr = i_ptr->next_local_store;
2432 /* A note_uses callback in which DATA points the INSN_INFO for
2433 as check_mem_read_rtx. Nullify the pointer if i_m_r_m_r returns
2434 true for any part of *LOC. */
2436 static void
2437 check_mem_read_use (rtx *loc, void *data)
2439 subrtx_ptr_iterator::array_type array;
2440 FOR_EACH_SUBRTX_PTR (iter, array, loc, NONCONST)
2442 rtx *loc = *iter;
2443 if (MEM_P (*loc))
2444 check_mem_read_rtx (loc, (bb_info_t) data);
2449 /* Get arguments passed to CALL_INSN. Return TRUE if successful.
2450 So far it only handles arguments passed in registers. */
2452 static bool
2453 get_call_args (rtx call_insn, tree fn, rtx *args, int nargs)
2455 CUMULATIVE_ARGS args_so_far_v;
2456 cumulative_args_t args_so_far;
2457 tree arg;
2458 int idx;
2460 INIT_CUMULATIVE_ARGS (args_so_far_v, TREE_TYPE (fn), NULL_RTX, 0, 3);
2461 args_so_far = pack_cumulative_args (&args_so_far_v);
2463 arg = TYPE_ARG_TYPES (TREE_TYPE (fn));
2464 for (idx = 0;
2465 arg != void_list_node && idx < nargs;
2466 arg = TREE_CHAIN (arg), idx++)
2468 machine_mode mode = TYPE_MODE (TREE_VALUE (arg));
2469 rtx reg, link, tmp;
2470 reg = targetm.calls.function_arg (args_so_far, mode, NULL_TREE, true);
2471 if (!reg || !REG_P (reg) || GET_MODE (reg) != mode
2472 || GET_MODE_CLASS (mode) != MODE_INT)
2473 return false;
2475 for (link = CALL_INSN_FUNCTION_USAGE (call_insn);
2476 link;
2477 link = XEXP (link, 1))
2478 if (GET_CODE (XEXP (link, 0)) == USE)
2480 args[idx] = XEXP (XEXP (link, 0), 0);
2481 if (REG_P (args[idx])
2482 && REGNO (args[idx]) == REGNO (reg)
2483 && (GET_MODE (args[idx]) == mode
2484 || (GET_MODE_CLASS (GET_MODE (args[idx])) == MODE_INT
2485 && (GET_MODE_SIZE (GET_MODE (args[idx]))
2486 <= UNITS_PER_WORD)
2487 && (GET_MODE_SIZE (GET_MODE (args[idx]))
2488 > GET_MODE_SIZE (mode)))))
2489 break;
2491 if (!link)
2492 return false;
2494 tmp = cselib_expand_value_rtx (args[idx], scratch, 5);
2495 if (GET_MODE (args[idx]) != mode)
2497 if (!tmp || !CONST_INT_P (tmp))
2498 return false;
2499 tmp = gen_int_mode (INTVAL (tmp), mode);
2501 if (tmp)
2502 args[idx] = tmp;
2504 targetm.calls.function_arg_advance (args_so_far, mode, NULL_TREE, true);
2506 if (arg != void_list_node || idx != nargs)
2507 return false;
2508 return true;
2511 /* Return a bitmap of the fixed registers contained in IN. */
2513 static bitmap
2514 copy_fixed_regs (const_bitmap in)
2516 bitmap ret;
2518 ret = ALLOC_REG_SET (NULL);
2519 bitmap_and (ret, in, fixed_reg_set_regset);
2520 return ret;
2523 /* Apply record_store to all candidate stores in INSN. Mark INSN
2524 if some part of it is not a candidate store and assigns to a
2525 non-register target. */
2527 static void
2528 scan_insn (bb_info_t bb_info, rtx_insn *insn)
2530 rtx body;
2531 insn_info_type *insn_info = new insn_info_type;
2532 int mems_found = 0;
2533 memset (insn_info, 0, sizeof (struct insn_info_type));
2535 if (dump_file && (dump_flags & TDF_DETAILS))
2536 fprintf (dump_file, "\n**scanning insn=%d\n",
2537 INSN_UID (insn));
2539 insn_info->prev_insn = bb_info->last_insn;
2540 insn_info->insn = insn;
2541 bb_info->last_insn = insn_info;
2543 if (DEBUG_INSN_P (insn))
2545 insn_info->cannot_delete = true;
2546 return;
2549 /* Look at all of the uses in the insn. */
2550 note_uses (&PATTERN (insn), check_mem_read_use, bb_info);
2552 if (CALL_P (insn))
2554 bool const_call;
2555 tree memset_call = NULL_TREE;
2557 insn_info->cannot_delete = true;
2559 /* Const functions cannot do anything bad i.e. read memory,
2560 however, they can read their parameters which may have
2561 been pushed onto the stack.
2562 memset and bzero don't read memory either. */
2563 const_call = RTL_CONST_CALL_P (insn);
2564 if (!const_call)
2566 rtx call = get_call_rtx_from (insn);
2567 if (call && GET_CODE (XEXP (XEXP (call, 0), 0)) == SYMBOL_REF)
2569 rtx symbol = XEXP (XEXP (call, 0), 0);
2570 if (SYMBOL_REF_DECL (symbol)
2571 && TREE_CODE (SYMBOL_REF_DECL (symbol)) == FUNCTION_DECL)
2573 if ((DECL_BUILT_IN_CLASS (SYMBOL_REF_DECL (symbol))
2574 == BUILT_IN_NORMAL
2575 && (DECL_FUNCTION_CODE (SYMBOL_REF_DECL (symbol))
2576 == BUILT_IN_MEMSET))
2577 || SYMBOL_REF_DECL (symbol) == block_clear_fn)
2578 memset_call = SYMBOL_REF_DECL (symbol);
2582 if (const_call || memset_call)
2584 insn_info_t i_ptr = active_local_stores;
2585 insn_info_t last = NULL;
2587 if (dump_file && (dump_flags & TDF_DETAILS))
2588 fprintf (dump_file, "%s call %d\n",
2589 const_call ? "const" : "memset", INSN_UID (insn));
2591 /* See the head comment of the frame_read field. */
2592 if (reload_completed
2593 /* Tail calls are storing their arguments using
2594 arg pointer. If it is a frame pointer on the target,
2595 even before reload we need to kill frame pointer based
2596 stores. */
2597 || (SIBLING_CALL_P (insn)
2598 && HARD_FRAME_POINTER_IS_ARG_POINTER))
2599 insn_info->frame_read = true;
2601 /* Loop over the active stores and remove those which are
2602 killed by the const function call. */
2603 while (i_ptr)
2605 bool remove_store = false;
2607 /* The stack pointer based stores are always killed. */
2608 if (i_ptr->stack_pointer_based)
2609 remove_store = true;
2611 /* If the frame is read, the frame related stores are killed. */
2612 else if (insn_info->frame_read)
2614 store_info_t store_info = i_ptr->store_rec;
2616 /* Skip the clobbers. */
2617 while (!store_info->is_set)
2618 store_info = store_info->next;
2620 if (store_info->group_id >= 0
2621 && rtx_group_vec[store_info->group_id]->frame_related)
2622 remove_store = true;
2625 if (remove_store)
2627 if (dump_file && (dump_flags & TDF_DETAILS))
2628 dump_insn_info ("removing from active", i_ptr);
2630 active_local_stores_len--;
2631 if (last)
2632 last->next_local_store = i_ptr->next_local_store;
2633 else
2634 active_local_stores = i_ptr->next_local_store;
2636 else
2637 last = i_ptr;
2639 i_ptr = i_ptr->next_local_store;
2642 if (memset_call)
2644 rtx args[3];
2645 if (get_call_args (insn, memset_call, args, 3)
2646 && CONST_INT_P (args[1])
2647 && CONST_INT_P (args[2])
2648 && INTVAL (args[2]) > 0)
2650 rtx mem = gen_rtx_MEM (BLKmode, args[0]);
2651 set_mem_size (mem, INTVAL (args[2]));
2652 body = gen_rtx_SET (mem, args[1]);
2653 mems_found += record_store (body, bb_info);
2654 if (dump_file && (dump_flags & TDF_DETAILS))
2655 fprintf (dump_file, "handling memset as BLKmode store\n");
2656 if (mems_found == 1)
2658 if (active_local_stores_len++
2659 >= PARAM_VALUE (PARAM_MAX_DSE_ACTIVE_LOCAL_STORES))
2661 active_local_stores_len = 1;
2662 active_local_stores = NULL;
2664 insn_info->fixed_regs_live
2665 = copy_fixed_regs (bb_info->regs_live);
2666 insn_info->next_local_store = active_local_stores;
2667 active_local_stores = insn_info;
2672 else if (SIBLING_CALL_P (insn) && reload_completed)
2673 /* Arguments for a sibling call that are pushed to memory are passed
2674 using the incoming argument pointer of the current function. After
2675 reload that might be (and likely is) frame pointer based. */
2676 add_wild_read (bb_info);
2677 else
2678 /* Every other call, including pure functions, may read any memory
2679 that is not relative to the frame. */
2680 add_non_frame_wild_read (bb_info);
2682 return;
2685 /* Assuming that there are sets in these insns, we cannot delete
2686 them. */
2687 if ((GET_CODE (PATTERN (insn)) == CLOBBER)
2688 || volatile_refs_p (PATTERN (insn))
2689 || (!cfun->can_delete_dead_exceptions && !insn_nothrow_p (insn))
2690 || (RTX_FRAME_RELATED_P (insn))
2691 || find_reg_note (insn, REG_FRAME_RELATED_EXPR, NULL_RTX))
2692 insn_info->cannot_delete = true;
2694 body = PATTERN (insn);
2695 if (GET_CODE (body) == PARALLEL)
2697 int i;
2698 for (i = 0; i < XVECLEN (body, 0); i++)
2699 mems_found += record_store (XVECEXP (body, 0, i), bb_info);
2701 else
2702 mems_found += record_store (body, bb_info);
2704 if (dump_file && (dump_flags & TDF_DETAILS))
2705 fprintf (dump_file, "mems_found = %d, cannot_delete = %s\n",
2706 mems_found, insn_info->cannot_delete ? "true" : "false");
2708 /* If we found some sets of mems, add it into the active_local_stores so
2709 that it can be locally deleted if found dead or used for
2710 replace_read and redundant constant store elimination. Otherwise mark
2711 it as cannot delete. This simplifies the processing later. */
2712 if (mems_found == 1)
2714 if (active_local_stores_len++
2715 >= PARAM_VALUE (PARAM_MAX_DSE_ACTIVE_LOCAL_STORES))
2717 active_local_stores_len = 1;
2718 active_local_stores = NULL;
2720 insn_info->fixed_regs_live = copy_fixed_regs (bb_info->regs_live);
2721 insn_info->next_local_store = active_local_stores;
2722 active_local_stores = insn_info;
2724 else
2725 insn_info->cannot_delete = true;
2729 /* Remove BASE from the set of active_local_stores. This is a
2730 callback from cselib that is used to get rid of the stores in
2731 active_local_stores. */
2733 static void
2734 remove_useless_values (cselib_val *base)
2736 insn_info_t insn_info = active_local_stores;
2737 insn_info_t last = NULL;
2739 while (insn_info)
2741 store_info_t store_info = insn_info->store_rec;
2742 bool del = false;
2744 /* If ANY of the store_infos match the cselib group that is
2745 being deleted, then the insn can not be deleted. */
2746 while (store_info)
2748 if ((store_info->group_id == -1)
2749 && (store_info->cse_base == base))
2751 del = true;
2752 break;
2754 store_info = store_info->next;
2757 if (del)
2759 active_local_stores_len--;
2760 if (last)
2761 last->next_local_store = insn_info->next_local_store;
2762 else
2763 active_local_stores = insn_info->next_local_store;
2764 free_store_info (insn_info);
2766 else
2767 last = insn_info;
2769 insn_info = insn_info->next_local_store;
2774 /* Do all of step 1. */
2776 static void
2777 dse_step1 (void)
2779 basic_block bb;
2780 bitmap regs_live = BITMAP_ALLOC (&reg_obstack);
2782 cselib_init (0);
2783 all_blocks = BITMAP_ALLOC (NULL);
2784 bitmap_set_bit (all_blocks, ENTRY_BLOCK);
2785 bitmap_set_bit (all_blocks, EXIT_BLOCK);
2787 FOR_ALL_BB_FN (bb, cfun)
2789 insn_info_t ptr;
2790 bb_info_t bb_info = new dse_bb_info_type;
2792 memset (bb_info, 0, sizeof (dse_bb_info_type));
2793 bitmap_set_bit (all_blocks, bb->index);
2794 bb_info->regs_live = regs_live;
2796 bitmap_copy (regs_live, DF_LR_IN (bb));
2797 df_simulate_initialize_forwards (bb, regs_live);
2799 bb_table[bb->index] = bb_info;
2800 cselib_discard_hook = remove_useless_values;
2802 if (bb->index >= NUM_FIXED_BLOCKS)
2804 rtx_insn *insn;
2806 active_local_stores = NULL;
2807 active_local_stores_len = 0;
2808 cselib_clear_table ();
2810 /* Scan the insns. */
2811 FOR_BB_INSNS (bb, insn)
2813 if (INSN_P (insn))
2814 scan_insn (bb_info, insn);
2815 cselib_process_insn (insn);
2816 if (INSN_P (insn))
2817 df_simulate_one_insn_forwards (bb, insn, regs_live);
2820 /* This is something of a hack, because the global algorithm
2821 is supposed to take care of the case where stores go dead
2822 at the end of the function. However, the global
2823 algorithm must take a more conservative view of block
2824 mode reads than the local alg does. So to get the case
2825 where you have a store to the frame followed by a non
2826 overlapping block more read, we look at the active local
2827 stores at the end of the function and delete all of the
2828 frame and spill based ones. */
2829 if (stores_off_frame_dead_at_return
2830 && (EDGE_COUNT (bb->succs) == 0
2831 || (single_succ_p (bb)
2832 && single_succ (bb) == EXIT_BLOCK_PTR_FOR_FN (cfun)
2833 && ! crtl->calls_eh_return)))
2835 insn_info_t i_ptr = active_local_stores;
2836 while (i_ptr)
2838 store_info_t store_info = i_ptr->store_rec;
2840 /* Skip the clobbers. */
2841 while (!store_info->is_set)
2842 store_info = store_info->next;
2843 if (store_info->alias_set && !i_ptr->cannot_delete)
2844 delete_dead_store_insn (i_ptr);
2845 else
2846 if (store_info->group_id >= 0)
2848 group_info_t group
2849 = rtx_group_vec[store_info->group_id];
2850 if (group->frame_related && !i_ptr->cannot_delete)
2851 delete_dead_store_insn (i_ptr);
2854 i_ptr = i_ptr->next_local_store;
2858 /* Get rid of the loads that were discovered in
2859 replace_read. Cselib is finished with this block. */
2860 while (deferred_change_list)
2862 deferred_change_t next = deferred_change_list->next;
2864 /* There is no reason to validate this change. That was
2865 done earlier. */
2866 *deferred_change_list->loc = deferred_change_list->reg;
2867 delete deferred_change_list;
2868 deferred_change_list = next;
2871 /* Get rid of all of the cselib based store_infos in this
2872 block and mark the containing insns as not being
2873 deletable. */
2874 ptr = bb_info->last_insn;
2875 while (ptr)
2877 if (ptr->contains_cselib_groups)
2879 store_info_t s_info = ptr->store_rec;
2880 while (s_info && !s_info->is_set)
2881 s_info = s_info->next;
2882 if (s_info
2883 && s_info->redundant_reason
2884 && s_info->redundant_reason->insn
2885 && !ptr->cannot_delete)
2887 if (dump_file && (dump_flags & TDF_DETAILS))
2888 fprintf (dump_file, "Locally deleting insn %d "
2889 "because insn %d stores the "
2890 "same value and couldn't be "
2891 "eliminated\n",
2892 INSN_UID (ptr->insn),
2893 INSN_UID (s_info->redundant_reason->insn));
2894 delete_dead_store_insn (ptr);
2896 free_store_info (ptr);
2898 else
2900 store_info_t s_info;
2902 /* Free at least positions_needed bitmaps. */
2903 for (s_info = ptr->store_rec; s_info; s_info = s_info->next)
2904 if (s_info->is_large)
2906 BITMAP_FREE (s_info->positions_needed.large.bmap);
2907 s_info->is_large = false;
2910 ptr = ptr->prev_insn;
2913 cse_store_info_pool.release ();
2915 bb_info->regs_live = NULL;
2918 BITMAP_FREE (regs_live);
2919 cselib_finish ();
2920 rtx_group_table->empty ();
2924 /*----------------------------------------------------------------------------
2925 Second step.
2927 Assign each byte position in the stores that we are going to
2928 analyze globally to a position in the bitmaps. Returns true if
2929 there are any bit positions assigned.
2930 ----------------------------------------------------------------------------*/
2932 static void
2933 dse_step2_init (void)
2935 unsigned int i;
2936 group_info_t group;
2938 FOR_EACH_VEC_ELT (rtx_group_vec, i, group)
2940 /* For all non stack related bases, we only consider a store to
2941 be deletable if there are two or more stores for that
2942 position. This is because it takes one store to make the
2943 other store redundant. However, for the stores that are
2944 stack related, we consider them if there is only one store
2945 for the position. We do this because the stack related
2946 stores can be deleted if their is no read between them and
2947 the end of the function.
2949 To make this work in the current framework, we take the stack
2950 related bases add all of the bits from store1 into store2.
2951 This has the effect of making the eligible even if there is
2952 only one store. */
2954 if (stores_off_frame_dead_at_return && group->frame_related)
2956 bitmap_ior_into (group->store2_n, group->store1_n);
2957 bitmap_ior_into (group->store2_p, group->store1_p);
2958 if (dump_file && (dump_flags & TDF_DETAILS))
2959 fprintf (dump_file, "group %d is frame related ", i);
2962 group->offset_map_size_n++;
2963 group->offset_map_n = XOBNEWVEC (&dse_obstack, int,
2964 group->offset_map_size_n);
2965 group->offset_map_size_p++;
2966 group->offset_map_p = XOBNEWVEC (&dse_obstack, int,
2967 group->offset_map_size_p);
2968 group->process_globally = false;
2969 if (dump_file && (dump_flags & TDF_DETAILS))
2971 fprintf (dump_file, "group %d(%d+%d): ", i,
2972 (int)bitmap_count_bits (group->store2_n),
2973 (int)bitmap_count_bits (group->store2_p));
2974 bitmap_print (dump_file, group->store2_n, "n ", " ");
2975 bitmap_print (dump_file, group->store2_p, "p ", "\n");
2981 /* Init the offset tables for the normal case. */
2983 static bool
2984 dse_step2_nospill (void)
2986 unsigned int i;
2987 group_info_t group;
2988 /* Position 0 is unused because 0 is used in the maps to mean
2989 unused. */
2990 current_position = 1;
2991 FOR_EACH_VEC_ELT (rtx_group_vec, i, group)
2993 bitmap_iterator bi;
2994 unsigned int j;
2996 if (group == clear_alias_group)
2997 continue;
2999 memset (group->offset_map_n, 0, sizeof (int) * group->offset_map_size_n);
3000 memset (group->offset_map_p, 0, sizeof (int) * group->offset_map_size_p);
3001 bitmap_clear (group->group_kill);
3003 EXECUTE_IF_SET_IN_BITMAP (group->store2_n, 0, j, bi)
3005 bitmap_set_bit (group->group_kill, current_position);
3006 if (bitmap_bit_p (group->escaped_n, j))
3007 bitmap_set_bit (kill_on_calls, current_position);
3008 group->offset_map_n[j] = current_position++;
3009 group->process_globally = true;
3011 EXECUTE_IF_SET_IN_BITMAP (group->store2_p, 0, j, bi)
3013 bitmap_set_bit (group->group_kill, current_position);
3014 if (bitmap_bit_p (group->escaped_p, j))
3015 bitmap_set_bit (kill_on_calls, current_position);
3016 group->offset_map_p[j] = current_position++;
3017 group->process_globally = true;
3020 return current_position != 1;
3025 /*----------------------------------------------------------------------------
3026 Third step.
3028 Build the bit vectors for the transfer functions.
3029 ----------------------------------------------------------------------------*/
3032 /* Look up the bitmap index for OFFSET in GROUP_INFO. If it is not
3033 there, return 0. */
3035 static int
3036 get_bitmap_index (group_info_t group_info, HOST_WIDE_INT offset)
3038 if (offset < 0)
3040 HOST_WIDE_INT offset_p = -offset;
3041 if (offset_p >= group_info->offset_map_size_n)
3042 return 0;
3043 return group_info->offset_map_n[offset_p];
3045 else
3047 if (offset >= group_info->offset_map_size_p)
3048 return 0;
3049 return group_info->offset_map_p[offset];
3054 /* Process the STORE_INFOs into the bitmaps into GEN and KILL. KILL
3055 may be NULL. */
3057 static void
3058 scan_stores_nospill (store_info_t store_info, bitmap gen, bitmap kill)
3060 while (store_info)
3062 HOST_WIDE_INT i;
3063 group_info_t group_info
3064 = rtx_group_vec[store_info->group_id];
3065 if (group_info->process_globally)
3066 for (i = store_info->begin; i < store_info->end; i++)
3068 int index = get_bitmap_index (group_info, i);
3069 if (index != 0)
3071 bitmap_set_bit (gen, index);
3072 if (kill)
3073 bitmap_clear_bit (kill, index);
3076 store_info = store_info->next;
3081 /* Process the STORE_INFOs into the bitmaps into GEN and KILL. KILL
3082 may be NULL. */
3084 static void
3085 scan_stores_spill (store_info_t store_info, bitmap gen, bitmap kill)
3087 while (store_info)
3089 if (store_info->alias_set)
3091 int index = get_bitmap_index (clear_alias_group,
3092 store_info->alias_set);
3093 if (index != 0)
3095 bitmap_set_bit (gen, index);
3096 if (kill)
3097 bitmap_clear_bit (kill, index);
3100 store_info = store_info->next;
3105 /* Process the READ_INFOs into the bitmaps into GEN and KILL. KILL
3106 may be NULL. */
3108 static void
3109 scan_reads_nospill (insn_info_t insn_info, bitmap gen, bitmap kill)
3111 read_info_t read_info = insn_info->read_rec;
3112 int i;
3113 group_info_t group;
3115 /* If this insn reads the frame, kill all the frame related stores. */
3116 if (insn_info->frame_read)
3118 FOR_EACH_VEC_ELT (rtx_group_vec, i, group)
3119 if (group->process_globally && group->frame_related)
3121 if (kill)
3122 bitmap_ior_into (kill, group->group_kill);
3123 bitmap_and_compl_into (gen, group->group_kill);
3126 if (insn_info->non_frame_wild_read)
3128 /* Kill all non-frame related stores. Kill all stores of variables that
3129 escape. */
3130 if (kill)
3131 bitmap_ior_into (kill, kill_on_calls);
3132 bitmap_and_compl_into (gen, kill_on_calls);
3133 FOR_EACH_VEC_ELT (rtx_group_vec, i, group)
3134 if (group->process_globally && !group->frame_related)
3136 if (kill)
3137 bitmap_ior_into (kill, group->group_kill);
3138 bitmap_and_compl_into (gen, group->group_kill);
3141 while (read_info)
3143 FOR_EACH_VEC_ELT (rtx_group_vec, i, group)
3145 if (group->process_globally)
3147 if (i == read_info->group_id)
3149 if (read_info->begin > read_info->end)
3151 /* Begin > end for block mode reads. */
3152 if (kill)
3153 bitmap_ior_into (kill, group->group_kill);
3154 bitmap_and_compl_into (gen, group->group_kill);
3156 else
3158 /* The groups are the same, just process the
3159 offsets. */
3160 HOST_WIDE_INT j;
3161 for (j = read_info->begin; j < read_info->end; j++)
3163 int index = get_bitmap_index (group, j);
3164 if (index != 0)
3166 if (kill)
3167 bitmap_set_bit (kill, index);
3168 bitmap_clear_bit (gen, index);
3173 else
3175 /* The groups are different, if the alias sets
3176 conflict, clear the entire group. We only need
3177 to apply this test if the read_info is a cselib
3178 read. Anything with a constant base cannot alias
3179 something else with a different constant
3180 base. */
3181 if ((read_info->group_id < 0)
3182 && canon_true_dependence (group->base_mem,
3183 GET_MODE (group->base_mem),
3184 group->canon_base_addr,
3185 read_info->mem, NULL_RTX))
3187 if (kill)
3188 bitmap_ior_into (kill, group->group_kill);
3189 bitmap_and_compl_into (gen, group->group_kill);
3195 read_info = read_info->next;
3199 /* Process the READ_INFOs into the bitmaps into GEN and KILL. KILL
3200 may be NULL. */
3202 static void
3203 scan_reads_spill (read_info_t read_info, bitmap gen, bitmap kill)
3205 while (read_info)
3207 if (read_info->alias_set)
3209 int index = get_bitmap_index (clear_alias_group,
3210 read_info->alias_set);
3211 if (index != 0)
3213 if (kill)
3214 bitmap_set_bit (kill, index);
3215 bitmap_clear_bit (gen, index);
3219 read_info = read_info->next;
3224 /* Return the insn in BB_INFO before the first wild read or if there
3225 are no wild reads in the block, return the last insn. */
3227 static insn_info_t
3228 find_insn_before_first_wild_read (bb_info_t bb_info)
3230 insn_info_t insn_info = bb_info->last_insn;
3231 insn_info_t last_wild_read = NULL;
3233 while (insn_info)
3235 if (insn_info->wild_read)
3237 last_wild_read = insn_info->prev_insn;
3238 /* Block starts with wild read. */
3239 if (!last_wild_read)
3240 return NULL;
3243 insn_info = insn_info->prev_insn;
3246 if (last_wild_read)
3247 return last_wild_read;
3248 else
3249 return bb_info->last_insn;
3253 /* Scan the insns in BB_INFO starting at PTR and going to the top of
3254 the block in order to build the gen and kill sets for the block.
3255 We start at ptr which may be the last insn in the block or may be
3256 the first insn with a wild read. In the latter case we are able to
3257 skip the rest of the block because it just does not matter:
3258 anything that happens is hidden by the wild read. */
3260 static void
3261 dse_step3_scan (bool for_spills, basic_block bb)
3263 bb_info_t bb_info = bb_table[bb->index];
3264 insn_info_t insn_info;
3266 if (for_spills)
3267 /* There are no wild reads in the spill case. */
3268 insn_info = bb_info->last_insn;
3269 else
3270 insn_info = find_insn_before_first_wild_read (bb_info);
3272 /* In the spill case or in the no_spill case if there is no wild
3273 read in the block, we will need a kill set. */
3274 if (insn_info == bb_info->last_insn)
3276 if (bb_info->kill)
3277 bitmap_clear (bb_info->kill);
3278 else
3279 bb_info->kill = BITMAP_ALLOC (&dse_bitmap_obstack);
3281 else
3282 if (bb_info->kill)
3283 BITMAP_FREE (bb_info->kill);
3285 while (insn_info)
3287 /* There may have been code deleted by the dce pass run before
3288 this phase. */
3289 if (insn_info->insn && INSN_P (insn_info->insn))
3291 /* Process the read(s) last. */
3292 if (for_spills)
3294 scan_stores_spill (insn_info->store_rec, bb_info->gen, bb_info->kill);
3295 scan_reads_spill (insn_info->read_rec, bb_info->gen, bb_info->kill);
3297 else
3299 scan_stores_nospill (insn_info->store_rec, bb_info->gen, bb_info->kill);
3300 scan_reads_nospill (insn_info, bb_info->gen, bb_info->kill);
3304 insn_info = insn_info->prev_insn;
3309 /* Set the gen set of the exit block, and also any block with no
3310 successors that does not have a wild read. */
3312 static void
3313 dse_step3_exit_block_scan (bb_info_t bb_info)
3315 /* The gen set is all 0's for the exit block except for the
3316 frame_pointer_group. */
3318 if (stores_off_frame_dead_at_return)
3320 unsigned int i;
3321 group_info_t group;
3323 FOR_EACH_VEC_ELT (rtx_group_vec, i, group)
3325 if (group->process_globally && group->frame_related)
3326 bitmap_ior_into (bb_info->gen, group->group_kill);
3332 /* Find all of the blocks that are not backwards reachable from the
3333 exit block or any block with no successors (BB). These are the
3334 infinite loops or infinite self loops. These blocks will still
3335 have their bits set in UNREACHABLE_BLOCKS. */
3337 static void
3338 mark_reachable_blocks (sbitmap unreachable_blocks, basic_block bb)
3340 edge e;
3341 edge_iterator ei;
3343 if (bitmap_bit_p (unreachable_blocks, bb->index))
3345 bitmap_clear_bit (unreachable_blocks, bb->index);
3346 FOR_EACH_EDGE (e, ei, bb->preds)
3348 mark_reachable_blocks (unreachable_blocks, e->src);
3353 /* Build the transfer functions for the function. */
3355 static void
3356 dse_step3 (bool for_spills)
3358 basic_block bb;
3359 sbitmap unreachable_blocks = sbitmap_alloc (last_basic_block_for_fn (cfun));
3360 sbitmap_iterator sbi;
3361 bitmap all_ones = NULL;
3362 unsigned int i;
3364 bitmap_ones (unreachable_blocks);
3366 FOR_ALL_BB_FN (bb, cfun)
3368 bb_info_t bb_info = bb_table[bb->index];
3369 if (bb_info->gen)
3370 bitmap_clear (bb_info->gen);
3371 else
3372 bb_info->gen = BITMAP_ALLOC (&dse_bitmap_obstack);
3374 if (bb->index == ENTRY_BLOCK)
3376 else if (bb->index == EXIT_BLOCK)
3377 dse_step3_exit_block_scan (bb_info);
3378 else
3379 dse_step3_scan (for_spills, bb);
3380 if (EDGE_COUNT (bb->succs) == 0)
3381 mark_reachable_blocks (unreachable_blocks, bb);
3383 /* If this is the second time dataflow is run, delete the old
3384 sets. */
3385 if (bb_info->in)
3386 BITMAP_FREE (bb_info->in);
3387 if (bb_info->out)
3388 BITMAP_FREE (bb_info->out);
3391 /* For any block in an infinite loop, we must initialize the out set
3392 to all ones. This could be expensive, but almost never occurs in
3393 practice. However, it is common in regression tests. */
3394 EXECUTE_IF_SET_IN_BITMAP (unreachable_blocks, 0, i, sbi)
3396 if (bitmap_bit_p (all_blocks, i))
3398 bb_info_t bb_info = bb_table[i];
3399 if (!all_ones)
3401 unsigned int j;
3402 group_info_t group;
3404 all_ones = BITMAP_ALLOC (&dse_bitmap_obstack);
3405 FOR_EACH_VEC_ELT (rtx_group_vec, j, group)
3406 bitmap_ior_into (all_ones, group->group_kill);
3408 if (!bb_info->out)
3410 bb_info->out = BITMAP_ALLOC (&dse_bitmap_obstack);
3411 bitmap_copy (bb_info->out, all_ones);
3416 if (all_ones)
3417 BITMAP_FREE (all_ones);
3418 sbitmap_free (unreachable_blocks);
3423 /*----------------------------------------------------------------------------
3424 Fourth step.
3426 Solve the bitvector equations.
3427 ----------------------------------------------------------------------------*/
3430 /* Confluence function for blocks with no successors. Create an out
3431 set from the gen set of the exit block. This block logically has
3432 the exit block as a successor. */
3436 static void
3437 dse_confluence_0 (basic_block bb)
3439 bb_info_t bb_info = bb_table[bb->index];
3441 if (bb->index == EXIT_BLOCK)
3442 return;
3444 if (!bb_info->out)
3446 bb_info->out = BITMAP_ALLOC (&dse_bitmap_obstack);
3447 bitmap_copy (bb_info->out, bb_table[EXIT_BLOCK]->gen);
3451 /* Propagate the information from the in set of the dest of E to the
3452 out set of the src of E. If the various in or out sets are not
3453 there, that means they are all ones. */
3455 static bool
3456 dse_confluence_n (edge e)
3458 bb_info_t src_info = bb_table[e->src->index];
3459 bb_info_t dest_info = bb_table[e->dest->index];
3461 if (dest_info->in)
3463 if (src_info->out)
3464 bitmap_and_into (src_info->out, dest_info->in);
3465 else
3467 src_info->out = BITMAP_ALLOC (&dse_bitmap_obstack);
3468 bitmap_copy (src_info->out, dest_info->in);
3471 return true;
3475 /* Propagate the info from the out to the in set of BB_INDEX's basic
3476 block. There are three cases:
3478 1) The block has no kill set. In this case the kill set is all
3479 ones. It does not matter what the out set of the block is, none of
3480 the info can reach the top. The only thing that reaches the top is
3481 the gen set and we just copy the set.
3483 2) There is a kill set but no out set and bb has successors. In
3484 this case we just return. Eventually an out set will be created and
3485 it is better to wait than to create a set of ones.
3487 3) There is both a kill and out set. We apply the obvious transfer
3488 function.
3491 static bool
3492 dse_transfer_function (int bb_index)
3494 bb_info_t bb_info = bb_table[bb_index];
3496 if (bb_info->kill)
3498 if (bb_info->out)
3500 /* Case 3 above. */
3501 if (bb_info->in)
3502 return bitmap_ior_and_compl (bb_info->in, bb_info->gen,
3503 bb_info->out, bb_info->kill);
3504 else
3506 bb_info->in = BITMAP_ALLOC (&dse_bitmap_obstack);
3507 bitmap_ior_and_compl (bb_info->in, bb_info->gen,
3508 bb_info->out, bb_info->kill);
3509 return true;
3512 else
3513 /* Case 2 above. */
3514 return false;
3516 else
3518 /* Case 1 above. If there is already an in set, nothing
3519 happens. */
3520 if (bb_info->in)
3521 return false;
3522 else
3524 bb_info->in = BITMAP_ALLOC (&dse_bitmap_obstack);
3525 bitmap_copy (bb_info->in, bb_info->gen);
3526 return true;
3531 /* Solve the dataflow equations. */
3533 static void
3534 dse_step4 (void)
3536 df_simple_dataflow (DF_BACKWARD, NULL, dse_confluence_0,
3537 dse_confluence_n, dse_transfer_function,
3538 all_blocks, df_get_postorder (DF_BACKWARD),
3539 df_get_n_blocks (DF_BACKWARD));
3540 if (dump_file && (dump_flags & TDF_DETAILS))
3542 basic_block bb;
3544 fprintf (dump_file, "\n\n*** Global dataflow info after analysis.\n");
3545 FOR_ALL_BB_FN (bb, cfun)
3547 bb_info_t bb_info = bb_table[bb->index];
3549 df_print_bb_index (bb, dump_file);
3550 if (bb_info->in)
3551 bitmap_print (dump_file, bb_info->in, " in: ", "\n");
3552 else
3553 fprintf (dump_file, " in: *MISSING*\n");
3554 if (bb_info->gen)
3555 bitmap_print (dump_file, bb_info->gen, " gen: ", "\n");
3556 else
3557 fprintf (dump_file, " gen: *MISSING*\n");
3558 if (bb_info->kill)
3559 bitmap_print (dump_file, bb_info->kill, " kill: ", "\n");
3560 else
3561 fprintf (dump_file, " kill: *MISSING*\n");
3562 if (bb_info->out)
3563 bitmap_print (dump_file, bb_info->out, " out: ", "\n");
3564 else
3565 fprintf (dump_file, " out: *MISSING*\n\n");
3572 /*----------------------------------------------------------------------------
3573 Fifth step.
3575 Delete the stores that can only be deleted using the global information.
3576 ----------------------------------------------------------------------------*/
3579 static void
3580 dse_step5_nospill (void)
3582 basic_block bb;
3583 FOR_EACH_BB_FN (bb, cfun)
3585 bb_info_t bb_info = bb_table[bb->index];
3586 insn_info_t insn_info = bb_info->last_insn;
3587 bitmap v = bb_info->out;
3589 while (insn_info)
3591 bool deleted = false;
3592 if (dump_file && insn_info->insn)
3594 fprintf (dump_file, "starting to process insn %d\n",
3595 INSN_UID (insn_info->insn));
3596 bitmap_print (dump_file, v, " v: ", "\n");
3599 /* There may have been code deleted by the dce pass run before
3600 this phase. */
3601 if (insn_info->insn
3602 && INSN_P (insn_info->insn)
3603 && (!insn_info->cannot_delete)
3604 && (!bitmap_empty_p (v)))
3606 store_info_t store_info = insn_info->store_rec;
3608 /* Try to delete the current insn. */
3609 deleted = true;
3611 /* Skip the clobbers. */
3612 while (!store_info->is_set)
3613 store_info = store_info->next;
3615 if (store_info->alias_set)
3616 deleted = false;
3617 else
3619 HOST_WIDE_INT i;
3620 group_info_t group_info
3621 = rtx_group_vec[store_info->group_id];
3623 for (i = store_info->begin; i < store_info->end; i++)
3625 int index = get_bitmap_index (group_info, i);
3627 if (dump_file && (dump_flags & TDF_DETAILS))
3628 fprintf (dump_file, "i = %d, index = %d\n", (int)i, index);
3629 if (index == 0 || !bitmap_bit_p (v, index))
3631 if (dump_file && (dump_flags & TDF_DETAILS))
3632 fprintf (dump_file, "failing at i = %d\n", (int)i);
3633 deleted = false;
3634 break;
3638 if (deleted)
3640 if (dbg_cnt (dse)
3641 && check_for_inc_dec_1 (insn_info))
3643 delete_insn (insn_info->insn);
3644 insn_info->insn = NULL;
3645 globally_deleted++;
3649 /* We do want to process the local info if the insn was
3650 deleted. For instance, if the insn did a wild read, we
3651 no longer need to trash the info. */
3652 if (insn_info->insn
3653 && INSN_P (insn_info->insn)
3654 && (!deleted))
3656 scan_stores_nospill (insn_info->store_rec, v, NULL);
3657 if (insn_info->wild_read)
3659 if (dump_file && (dump_flags & TDF_DETAILS))
3660 fprintf (dump_file, "wild read\n");
3661 bitmap_clear (v);
3663 else if (insn_info->read_rec
3664 || insn_info->non_frame_wild_read)
3666 if (dump_file && !insn_info->non_frame_wild_read)
3667 fprintf (dump_file, "regular read\n");
3668 else if (dump_file && (dump_flags & TDF_DETAILS))
3669 fprintf (dump_file, "non-frame wild read\n");
3670 scan_reads_nospill (insn_info, v, NULL);
3674 insn_info = insn_info->prev_insn;
3681 /*----------------------------------------------------------------------------
3682 Sixth step.
3684 Delete stores made redundant by earlier stores (which store the same
3685 value) that couldn't be eliminated.
3686 ----------------------------------------------------------------------------*/
3688 static void
3689 dse_step6 (void)
3691 basic_block bb;
3693 FOR_ALL_BB_FN (bb, cfun)
3695 bb_info_t bb_info = bb_table[bb->index];
3696 insn_info_t insn_info = bb_info->last_insn;
3698 while (insn_info)
3700 /* There may have been code deleted by the dce pass run before
3701 this phase. */
3702 if (insn_info->insn
3703 && INSN_P (insn_info->insn)
3704 && !insn_info->cannot_delete)
3706 store_info_t s_info = insn_info->store_rec;
3708 while (s_info && !s_info->is_set)
3709 s_info = s_info->next;
3710 if (s_info
3711 && s_info->redundant_reason
3712 && s_info->redundant_reason->insn
3713 && INSN_P (s_info->redundant_reason->insn))
3715 rtx_insn *rinsn = s_info->redundant_reason->insn;
3716 if (dump_file && (dump_flags & TDF_DETAILS))
3717 fprintf (dump_file, "Locally deleting insn %d "
3718 "because insn %d stores the "
3719 "same value and couldn't be "
3720 "eliminated\n",
3721 INSN_UID (insn_info->insn),
3722 INSN_UID (rinsn));
3723 delete_dead_store_insn (insn_info);
3726 insn_info = insn_info->prev_insn;
3731 /*----------------------------------------------------------------------------
3732 Seventh step.
3734 Destroy everything left standing.
3735 ----------------------------------------------------------------------------*/
3737 static void
3738 dse_step7 (void)
3740 bitmap_obstack_release (&dse_bitmap_obstack);
3741 obstack_free (&dse_obstack, NULL);
3743 end_alias_analysis ();
3744 free (bb_table);
3745 delete rtx_group_table;
3746 rtx_group_table = NULL;
3747 rtx_group_vec.release ();
3748 BITMAP_FREE (all_blocks);
3749 BITMAP_FREE (scratch);
3751 rtx_store_info_pool.release ();
3752 read_info_type::pool.release ();
3753 insn_info_type::pool.release ();
3754 dse_bb_info_type::pool.release ();
3755 group_info::pool.release ();
3756 deferred_change::pool.release ();
3760 /* -------------------------------------------------------------------------
3762 ------------------------------------------------------------------------- */
3764 /* Callback for running pass_rtl_dse. */
3766 static unsigned int
3767 rest_of_handle_dse (void)
3769 df_set_flags (DF_DEFER_INSN_RESCAN);
3771 /* Need the notes since we must track live hardregs in the forwards
3772 direction. */
3773 df_note_add_problem ();
3774 df_analyze ();
3776 dse_step0 ();
3777 dse_step1 ();
3778 dse_step2_init ();
3779 if (dse_step2_nospill ())
3781 df_set_flags (DF_LR_RUN_DCE);
3782 df_analyze ();
3783 if (dump_file && (dump_flags & TDF_DETAILS))
3784 fprintf (dump_file, "doing global processing\n");
3785 dse_step3 (false);
3786 dse_step4 ();
3787 dse_step5_nospill ();
3790 dse_step6 ();
3791 dse_step7 ();
3793 if (dump_file)
3794 fprintf (dump_file, "dse: local deletions = %d, global deletions = %d, spill deletions = %d\n",
3795 locally_deleted, globally_deleted, spill_deleted);
3797 /* DSE can eliminate potentially-trapping MEMs.
3798 Remove any EH edges associated with them. */
3799 if ((locally_deleted || globally_deleted)
3800 && cfun->can_throw_non_call_exceptions
3801 && purge_all_dead_edges ())
3802 cleanup_cfg (0);
3804 return 0;
3807 namespace {
3809 const pass_data pass_data_rtl_dse1 =
3811 RTL_PASS, /* type */
3812 "dse1", /* name */
3813 OPTGROUP_NONE, /* optinfo_flags */
3814 TV_DSE1, /* tv_id */
3815 0, /* properties_required */
3816 0, /* properties_provided */
3817 0, /* properties_destroyed */
3818 0, /* todo_flags_start */
3819 TODO_df_finish, /* todo_flags_finish */
3822 class pass_rtl_dse1 : public rtl_opt_pass
3824 public:
3825 pass_rtl_dse1 (gcc::context *ctxt)
3826 : rtl_opt_pass (pass_data_rtl_dse1, ctxt)
3829 /* opt_pass methods: */
3830 virtual bool gate (function *)
3832 return optimize > 0 && flag_dse && dbg_cnt (dse1);
3835 virtual unsigned int execute (function *) { return rest_of_handle_dse (); }
3837 }; // class pass_rtl_dse1
3839 } // anon namespace
3841 rtl_opt_pass *
3842 make_pass_rtl_dse1 (gcc::context *ctxt)
3844 return new pass_rtl_dse1 (ctxt);
3847 namespace {
3849 const pass_data pass_data_rtl_dse2 =
3851 RTL_PASS, /* type */
3852 "dse2", /* name */
3853 OPTGROUP_NONE, /* optinfo_flags */
3854 TV_DSE2, /* tv_id */
3855 0, /* properties_required */
3856 0, /* properties_provided */
3857 0, /* properties_destroyed */
3858 0, /* todo_flags_start */
3859 TODO_df_finish, /* todo_flags_finish */
3862 class pass_rtl_dse2 : public rtl_opt_pass
3864 public:
3865 pass_rtl_dse2 (gcc::context *ctxt)
3866 : rtl_opt_pass (pass_data_rtl_dse2, ctxt)
3869 /* opt_pass methods: */
3870 virtual bool gate (function *)
3872 return optimize > 0 && flag_dse && dbg_cnt (dse2);
3875 virtual unsigned int execute (function *) { return rest_of_handle_dse (); }
3877 }; // class pass_rtl_dse2
3879 } // anon namespace
3881 rtl_opt_pass *
3882 make_pass_rtl_dse2 (gcc::context *ctxt)
3884 return new pass_rtl_dse2 (ctxt);