From aa4de160ccafb70787013aaa540375aaac0056da Mon Sep 17 00:00:00 2001 From: Bin Cheng Date: Fri, 28 Jul 2017 14:55:49 +0000 Subject: [PATCH] tree-predcom.c (struct chain): New field init_seq. * tree-predcom.c (struct chain): New field init_seq. (release_chain): Release init_seq. (prepare_initializers_chain): Record intialization stmts in above field. (insert_init_seqs): New function. (tree_predictive_commoning_loop): Call insert_init_seqs. From-SVN: r250666 --- gcc/ChangeLog | 9 +++++++++ gcc/tree-predcom.c | 25 ++++++++++++++++++++++++- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 0419984fdf5..53634027279 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,12 @@ +2017-07-28 Bin Cheng + + * tree-predcom.c (struct chain): New field init_seq. + (release_chain): Release init_seq. + (prepare_initializers_chain): Record intialization stmts in above + field. + (insert_init_seqs): New function. + (tree_predictive_commoning_loop): Call insert_init_seqs. + 2017-07-28 Bin Cheng * tree-predcom.c (determine_roots_comp): Skip trivial components. diff --git a/gcc/tree-predcom.c b/gcc/tree-predcom.c index 536fe349436..089d3c674a4 100644 --- a/gcc/tree-predcom.c +++ b/gcc/tree-predcom.c @@ -294,6 +294,9 @@ typedef struct chain /* Initializers for the variables. */ vec inits; + /* gimple stmts intializing the initial variables of the chain. */ + gimple_seq init_seq; + /* True if there is a use of a variable with the maximal distance that comes after the root in the loop. */ unsigned has_max_use_after : 1; @@ -511,6 +514,8 @@ release_chain (chain_p chain) chain->refs.release (); chain->vars.release (); chain->inits.release (); + if (chain->init_seq) + gimple_seq_discard (chain->init_seq); free (chain); } @@ -2457,7 +2462,7 @@ prepare_initializers_chain (struct loop *loop, chain_p chain) } if (stmts) - gsi_insert_seq_on_edge_immediate (entry, stmts); + gimple_seq_add_seq_without_update (&chain->init_seq, stmts); chain->inits[i] = init; } @@ -2487,6 +2492,22 @@ prepare_initializers (struct loop *loop, vec chains) } } +/* Insert all initializing gimple stmts into loop's entry edge. */ + +static void +insert_init_seqs (struct loop *loop, vec chains) +{ + unsigned i; + edge entry = loop_preheader_edge (loop); + + for (i = 0; i < chains.length (); ++i) + if (chains[i]->init_seq) + { + gsi_insert_seq_on_edge_immediate (entry, chains[i]->init_seq); + chains[i]->init_seq = NULL; + } +} + /* Performs predictive commoning for LOOP. Returns true if LOOP was unrolled. */ @@ -2568,6 +2589,8 @@ tree_predictive_commoning_loop (struct loop *loop) /* Try to combine the chains that are always worked with together. */ try_combine_chains (&chains); + insert_init_seqs (loop, chains); + if (dump_file && (dump_flags & TDF_DETAILS)) { fprintf (dump_file, "Before commoning:\n\n"); -- 2.30.2