diff options
author | alalaw01 <alalaw01@138bc75d-0d04-0410-961f-82ee72b054a4> | 2015-07-02 11:47:31 +0000 |
---|---|---|
committer | alalaw01 <alalaw01@138bc75d-0d04-0410-961f-82ee72b054a4> | 2015-07-02 11:47:31 +0000 |
commit | e7f9a223d5858f6be027ca5c434ad908ca494e5c (patch) | |
tree | 03b839a9ffb0c5708c3e05e1fbf436749d1db944 /gcc/tree-ssa-loop-ch.c | |
parent | 906a94039a0d9dc5c525d9be56c73b42d7a9e39c (diff) | |
download | gcc-e7f9a223d5858f6be027ca5c434ad908ca494e5c.tar.gz |
gcc/:
* tree-pass.h (make_pass_ch_vect): New.
* passes.def: Add pass_ch_vect just before pass_if_conversion.
* tree-ssa-loop-ch.c (ch_base, pass_ch_vect, pass_data_ch_vect,
pass_ch::process_loop_p, pass_ch_vect::process_loop_p,
make_pass_ch_vect): New.
(pass_ch): Extend ch_base.
(pass_ch::execute): Move all but loop_optimizer_init/finalize to...
(ch_base::copy_headers): ...here.
gcc/testsuite/:
* gcc.dg/vect/vect-strided-a-u16-i4.c (main1): Narrow scope of x,y,z,w.
* gcc.dg/vect/vect-ifcvt-11.c: New testcase.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@225311 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/tree-ssa-loop-ch.c')
-rw-r--r-- | gcc/tree-ssa-loop-ch.c | 154 |
1 files changed, 139 insertions, 15 deletions
diff --git a/gcc/tree-ssa-loop-ch.c b/gcc/tree-ssa-loop-ch.c index 98534ba8f6c..121e3d80bd3 100644 --- a/gcc/tree-ssa-loop-ch.c +++ b/gcc/tree-ssa-loop-ch.c @@ -135,12 +135,23 @@ do_while_loop_p (struct loop *loop) return true; } -/* For all loops, copy the condition at the end of the loop body in front - of the loop. This is beneficial since it increases efficiency of - code motion optimizations. It also saves one jump on entry to the loop. */ - namespace { +/* Common superclass for both header-copying phases. */ +class ch_base : public gimple_opt_pass +{ + protected: + ch_base (pass_data data, gcc::context *ctxt) + : gimple_opt_pass (data, ctxt) + {} + + /* Copies headers of all loops in FUN for which process_loop_p is true. */ + unsigned int copy_headers (function *fun); + + /* Return true to copy headers of LOOP or false to skip. */ + virtual bool process_loop_p (struct loop *loop) = 0; +}; + const pass_data pass_data_ch = { GIMPLE_PASS, /* type */ @@ -154,21 +165,68 @@ const pass_data pass_data_ch = 0, /* todo_flags_finish */ }; -class pass_ch : public gimple_opt_pass +class pass_ch : public ch_base { public: pass_ch (gcc::context *ctxt) - : gimple_opt_pass (pass_data_ch, ctxt) + : ch_base (pass_data_ch, ctxt) {} /* opt_pass methods: */ virtual bool gate (function *) { return flag_tree_ch != 0; } + + /* Initialize and finalize loop structures, copying headers inbetween. */ virtual unsigned int execute (function *); +protected: + /* ch_base method: */ + virtual bool process_loop_p (struct loop *loop); }; // class pass_ch +const pass_data pass_data_ch_vect = +{ + GIMPLE_PASS, /* type */ + "ch_vect", /* name */ + OPTGROUP_LOOP, /* optinfo_flags */ + TV_TREE_CH, /* tv_id */ + ( PROP_cfg | PROP_ssa ), /* properties_required */ + 0, /* properties_provided */ + 0, /* properties_destroyed */ + 0, /* todo_flags_start */ + 0, /* todo_flags_finish */ +}; + +/* This is a more aggressive version of the same pass, designed to run just + before if-conversion and vectorization, to put more loops into the form + required for those phases. */ +class pass_ch_vect : public ch_base +{ +public: + pass_ch_vect (gcc::context *ctxt) + : ch_base (pass_data_ch_vect, ctxt) + {} + + /* opt_pass methods: */ + virtual bool gate (function *fun) + { + return flag_tree_ch != 0 + && (flag_tree_loop_vectorize != 0 || fun->has_force_vectorize_loops); + } + + /* Just copy headers, no initialization/finalization of loop structures. */ + virtual unsigned int execute (function *); + +protected: + /* ch_base method: */ + virtual bool process_loop_p (struct loop *loop); +}; // class pass_ch_vect + +/* For all loops, copy the condition at the end of the loop body in front + of the loop. This is beneficial since it increases efficiency of + code motion optimizations. It also saves one jump on entry to the loop. */ + unsigned int -pass_ch::execute (function *fun) +ch_base::copy_headers (function *fun) { struct loop *loop; basic_block header; @@ -178,13 +236,8 @@ pass_ch::execute (function *fun) unsigned bbs_size; bool changed = false; - loop_optimizer_init (LOOPS_HAVE_PREHEADERS - | LOOPS_HAVE_SIMPLE_LATCHES); if (number_of_loops (fun) <= 1) - { - loop_optimizer_finalize (); return 0; - } bbs = XNEWVEC (basic_block, n_basic_blocks_for_fn (fun)); copied_bbs = XNEWVEC (basic_block, n_basic_blocks_for_fn (fun)); @@ -201,7 +254,7 @@ pass_ch::execute (function *fun) written as such, or because jump threading transformed it into one), we might be in fact peeling the first iteration of the loop. This in general is not a good idea. */ - if (do_while_loop_p (loop)) + if (!process_loop_p (loop)) continue; /* Iterate the header copying up to limit; this takes care of the cases @@ -288,17 +341,88 @@ pass_ch::execute (function *fun) changed = true; } - update_ssa (TODO_update_ssa); + if (changed) + update_ssa (TODO_update_ssa); free (bbs); free (copied_bbs); - loop_optimizer_finalize (); return changed ? TODO_cleanup_cfg : 0; } +/* Initialize the loop structures we need, and finalize after. */ + +unsigned int +pass_ch::execute (function *fun) +{ + loop_optimizer_init (LOOPS_HAVE_PREHEADERS + | LOOPS_HAVE_SIMPLE_LATCHES); + + unsigned int res = copy_headers (fun); + + loop_optimizer_finalize (); + return res; +} + +/* Assume an earlier phase has already initialized all the loop structures that + we need here (and perhaps others too), and that these will be finalized by + a later phase. */ + +unsigned int +pass_ch_vect::execute (function *fun) +{ + return copy_headers (fun); +} + +/* Apply header copying according to a very simple test of do-while shape. */ + +bool +pass_ch::process_loop_p (struct loop *loop) +{ + return !do_while_loop_p (loop); +} + +/* Apply header-copying to loops where we might enable vectorization. */ + +bool +pass_ch_vect::process_loop_p (struct loop *loop) +{ + if (!flag_tree_vectorize && !loop->force_vectorize) + return false; + + if (loop->dont_vectorize) + return false; + + if (!do_while_loop_p (loop)) + return true; + + /* The vectorizer won't handle anything with multiple exits, so skip. */ + edge exit = single_exit (loop); + if (!exit) + return false; + + /* Copy headers iff there looks to be code in the loop after the exit block, + i.e. the exit block has an edge to another block (besides the latch, + which should be empty). */ + edge_iterator ei; + edge e; + FOR_EACH_EDGE (e, ei, exit->src->succs) + if (!loop_exit_edge_p (loop, e) + && e->dest != loop->header + && e->dest != loop->latch) + return true; + + return false; +} + } // anon namespace gimple_opt_pass * +make_pass_ch_vect (gcc::context *ctxt) +{ + return new pass_ch_vect (ctxt); +} + +gimple_opt_pass * make_pass_ch (gcc::context *ctxt) { return new pass_ch (ctxt); |