Skip to content

Commit bb63ca6

Browse files
committed
tree-optimization/95045 - fix SM with exit exiting multiple loops
Since we apply SM to an edge which exits multiple loops we have to make sure to commit insertions on it immediately since otherwise store order is not preserved. 2020-05-12 Richard Biener <[email protected]> PR tree-optimization/95045 * dbgcnt.def (lim): Add debug-counter. * tree-ssa-loop-im.c: Include dbgcnt.h. (find_refs_for_sm): Use lim debug counter for store motion candidates. (do_store_motion): Rename form store_motion. Commit edge insertions... (store_motion_loop): ... here. (tree_ssa_lim): Adjust.
1 parent 7a2e715 commit bb63ca6

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed

gcc/ChangeLog

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
2020-05-12 Richard Biener <[email protected]>
2+
3+
PR tree-optimization/95045
4+
* dbgcnt.def (lim): Add debug-counter.
5+
* tree-ssa-loop-im.c: Include dbgcnt.h.
6+
(find_refs_for_sm): Use lim debug counter for store motion
7+
candidates.
8+
(do_store_motion): Rename form store_motion. Commit edge
9+
insertions...
10+
(store_motion_loop): ... here.
11+
(tree_ssa_lim): Adjust.
12+
113
2020-05-11 Kelvin Nilsen <[email protected]>
214

315
* config/rs6000/altivec.h (vec_clzm): Rename to vec_cntlzm.

gcc/dbgcnt.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ DEBUG_COUNTER (ipa_sra_params)
174174
DEBUG_COUNTER (ipa_sra_retvalues)
175175
DEBUG_COUNTER (ira_move)
176176
DEBUG_COUNTER (ivopts_loop)
177+
DEBUG_COUNTER (lim)
177178
DEBUG_COUNTER (local_alloc_for_sched)
178179
DEBUG_COUNTER (match)
179180
DEBUG_COUNTER (merged_ipa_icf)

gcc/tree-ssa-loop-im.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ along with GCC; see the file COPYING3. If not see
4747
#include "alias.h"
4848
#include "builtins.h"
4949
#include "tree-dfa.h"
50+
#include "dbgcnt.h"
5051

5152
/* TODO: Support for predicated code motion. I.e.
5253
@@ -2862,7 +2863,7 @@ find_refs_for_sm (class loop *loop, bitmap sm_executed, bitmap refs_to_sm)
28622863
EXECUTE_IF_AND_COMPL_IN_BITMAP (refs, sm_executed, 0, i, bi)
28632864
{
28642865
ref = memory_accesses.refs_list[i];
2865-
if (can_sm_ref_p (loop, ref))
2866+
if (can_sm_ref_p (loop, ref) && dbg_cnt (lim))
28662867
bitmap_set_bit (refs_to_sm, i);
28672868
}
28682869
}
@@ -2900,7 +2901,12 @@ store_motion_loop (class loop *loop, bitmap sm_executed)
29002901
{
29012902
find_refs_for_sm (loop, sm_executed, sm_in_loop);
29022903
if (!bitmap_empty_p (sm_in_loop))
2903-
hoist_memory_references (loop, sm_in_loop, exits);
2904+
{
2905+
hoist_memory_references (loop, sm_in_loop, exits);
2906+
/* Commit edge inserts here to preserve the order of stores
2907+
when an exit exits multiple loops. */
2908+
gsi_commit_edge_inserts ();
2909+
}
29042910
}
29052911
exits.release ();
29062912

@@ -2915,7 +2921,7 @@ store_motion_loop (class loop *loop, bitmap sm_executed)
29152921
loops. */
29162922

29172923
static void
2918-
store_motion (void)
2924+
do_store_motion (void)
29192925
{
29202926
class loop *loop;
29212927
bitmap sm_executed = BITMAP_ALLOC (&lim_bitmap_obstack);
@@ -2924,7 +2930,6 @@ store_motion (void)
29242930
store_motion_loop (loop, sm_executed);
29252931

29262932
BITMAP_FREE (sm_executed);
2927-
gsi_commit_edge_inserts ();
29282933
}
29292934

29302935
/* Fills ALWAYS_EXECUTED_IN information for basic blocks of LOOP, i.e.
@@ -3141,7 +3146,7 @@ tree_ssa_lim (void)
31413146

31423147
/* Execute store motion. Force the necessary invariants to be moved
31433148
out of the loops as well. */
3144-
store_motion ();
3149+
do_store_motion ();
31453150

31463151
/* Move the expressions that are expensive enough. */
31473152
todo = move_computations ();

0 commit comments

Comments
 (0)