From: Richard Biener <rguenther@suse.de>
To: Xionghu Luo <luoxhu@linux.ibm.com>
Cc: gcc-patches@gcc.gnu.org, segher@kernel.crashing.org,
dje.gcc@gmail.com, wschmidt@linux.ibm.com,
guojiufu@linux.ibm.com, linkw@gcc.gnu.org,
hubicka@kam.mff.cuni.cz
Subject: Re: [PATCH v2 3/4] Rename loop_version to clone_loop_to_header_edge.
Date: Wed, 3 Nov 2021 14:36:15 +0100 (CET) [thread overview]
Message-ID: <5q7275p-51p7-n1qp-23n7-157446289o3@fhfr.qr> (raw)
In-Reply-To: <20211027063448.1844771-4-luoxhu@linux.ibm.com>
On Wed, 27 Oct 2021, Xionghu Luo wrote:
> Name loop_copy is used in gcc/cfg.c already.
But it's not actually cloning the loop to the header edge but doing
more - adding a condition and re-wiring edges so the cloned loop
is no longer on the header edge.
So no, I don't think this is good to go. If we can make use
of the part of loop_version that does this we should instead
split out a new API but keep loop_version with its name but
using clone_loop_to_header_edge then.
But we can leave that when we have use of such API. I originally
thought loop splitting might be able to use such API to make
the transform it does clearer - but whether that's the case is
left as an exercise to the reader.
Thanks,
Richard.
> gcc/ChangeLog:
>
> * cfgloopmanip.c (force_single_succ_latches): Rename
> loop_version to clone_loop_to_header_edge.
> (lv_adjust_loop_entry_edge): Likewise.
> (loop_version): Likewise.
> (clone_loop_to_header_edge): Likewise.
> * cfgloopmanip.h (class loop): Likewise.
> (clone_loop_to_header_edge): Likewise.
> * gimple-loop-versioning.cc (loop_versioning::version_loop): Likewise.
> * modulo-sched.c (sms_schedule): Likewise.
> * tree-if-conv.c (version_loop_for_if_conversion): Likewise.
> * tree-loop-distribution.c (version_loop_by_alias_check): Likewise.
> * tree-parloops.c (gen_parallel_loop): Likewise.
> * tree-ssa-loop-manip.c (tree_transform_and_unroll_loop): Likewise.
> * tree-ssa-loop-split.c (split_loop): Likewise.
> (get_cond_branch_to_split_loop): Likewise.
> (do_split_loop_on_cond): Likewise.
> * tree-ssa-loop-unswitch.c (tree_unswitch_loop): Likewise.
> * tree-vect-loop-manip.c (vect_loop_versioning): Likewise.
> ---
> gcc/cfgloopmanip.c | 22 +++++++++++-----------
> gcc/cfgloopmanip.h | 8 ++++----
> gcc/gimple-loop-versioning.cc | 11 ++++++-----
> gcc/modulo-sched.c | 6 +++---
> gcc/tree-if-conv.c | 13 +++++++------
> gcc/tree-loop-distribution.c | 4 ++--
> gcc/tree-parloops.c | 10 +++++-----
> gcc/tree-ssa-loop-manip.c | 9 +++++----
> gcc/tree-ssa-loop-split.c | 30 +++++++++++++++---------------
> gcc/tree-ssa-loop-unswitch.c | 8 +++-----
> gcc/tree-vect-loop-manip.c | 5 +++--
> 11 files changed, 64 insertions(+), 62 deletions(-)
>
> diff --git a/gcc/cfgloopmanip.c b/gcc/cfgloopmanip.c
> index a30ebe1cdb4..066fbddbcfe 100644
> --- a/gcc/cfgloopmanip.c
> +++ b/gcc/cfgloopmanip.c
> @@ -1535,11 +1535,10 @@ force_single_succ_latches (void)
> loops_state_set (LOOPS_HAVE_SIMPLE_LATCHES);
> }
>
> -/* This function is called from loop_version. It splits the entry edge
> - of the loop we want to version, adds the versioning condition, and
> - adjust the edges to the two versions of the loop appropriately.
> - e is an incoming edge. Returns the basic block containing the
> - condition.
> +/* This function is called from clone_loop_to_header_edge. It splits the entry
> + edge of the loop we want to version, adds the versioning condition, and adjust
> + the edges to the two versions of the loop appropriately. e is an incoming
> + edge. Returns the basic block containing the condition.
>
> --- edge e ---- > [second_head]
>
> @@ -1588,7 +1587,7 @@ lv_adjust_loop_entry_edge (basic_block first_head, basic_block second_head,
> return new_head;
> }
>
> -/* Main entry point for Loop Versioning transformation.
> +/* Main entry point for Loop copy transformation.
>
> This transformation given a condition and a loop, creates
> -if (condition) { loop_copy1 } else { loop_copy2 },
> @@ -1609,11 +1608,12 @@ lv_adjust_loop_entry_edge (basic_block first_head, basic_block second_head,
> instruction stream, otherwise it is placed before LOOP. */
>
> class loop *
> -loop_version (class loop *loop,
> - void *cond_expr, basic_block *condition_bb,
> - profile_probability then_prob, profile_probability else_prob,
> - profile_probability then_scale, profile_probability else_scale,
> - bool place_after)
> +clone_loop_to_header_edge (class loop *loop, void *cond_expr,
> + basic_block *condition_bb,
> + profile_probability then_prob,
> + profile_probability else_prob,
> + profile_probability then_scale,
> + profile_probability else_scale, bool place_after)
> {
> basic_block first_head, second_head;
> edge entry, latch_edge;
> diff --git a/gcc/cfgloopmanip.h b/gcc/cfgloopmanip.h
> index 312a3b48d05..eac09518702 100644
> --- a/gcc/cfgloopmanip.h
> +++ b/gcc/cfgloopmanip.h
> @@ -55,9 +55,9 @@ extern bool mfb_keep_just (edge);
> basic_block create_preheader (class loop *, int);
> extern void create_preheaders (int);
> extern void force_single_succ_latches (void);
> -class loop * loop_version (class loop *, void *,
> - basic_block *,
> - profile_probability, profile_probability,
> - profile_probability, profile_probability, bool);
> +class loop *
> +clone_loop_to_header_edge (class loop *, void *, basic_block *,
> + profile_probability, profile_probability,
> + profile_probability, profile_probability, bool);
>
> #endif /* GCC_CFGLOOPMANIP_H */
> diff --git a/gcc/gimple-loop-versioning.cc b/gcc/gimple-loop-versioning.cc
> index 15e0803dc29..c0fa60b91f8 100644
> --- a/gcc/gimple-loop-versioning.cc
> +++ b/gcc/gimple-loop-versioning.cc
> @@ -1686,11 +1686,12 @@ loop_versioning::version_loop (class loop *loop)
> /* Version the loop. */
> initialize_original_copy_tables ();
> basic_block cond_bb;
> - li.optimized_loop = loop_version (loop, cond, &cond_bb,
> - profile_probability::unlikely (),
> - profile_probability::likely (),
> - profile_probability::unlikely (),
> - profile_probability::likely (), true);
> + li.optimized_loop
> + = clone_loop_to_header_edge (loop, cond, &cond_bb,
> + profile_probability::unlikely (),
> + profile_probability::likely (),
> + profile_probability::unlikely (),
> + profile_probability::likely (), true);
> free_original_copy_tables ();
> if (!li.optimized_loop)
> {
> diff --git a/gcc/modulo-sched.c b/gcc/modulo-sched.c
> index 1c1b459d34f..26cd76a279c 100644
> --- a/gcc/modulo-sched.c
> +++ b/gcc/modulo-sched.c
> @@ -1737,9 +1737,9 @@ sms_schedule (void)
> profile_probability prob = profile_probability::guessed_always ()
> .apply_scale (PROB_SMS_ENOUGH_ITERATIONS, 100);
>
> - loop_version (loop, comp_rtx, &condition_bb,
> - prob, prob.invert (),
> - prob, prob.invert (), true);
> + clone_loop_to_header_edge (loop, comp_rtx, &condition_bb, prob,
> + prob.invert (), prob, prob.invert (),
> + true);
> }
>
> /* Now apply the scheduled kernel to the RTL of the loop. */
> diff --git a/gcc/tree-if-conv.c b/gcc/tree-if-conv.c
> index d7b7b309309..893231a2d16 100644
> --- a/gcc/tree-if-conv.c
> +++ b/gcc/tree-if-conv.c
> @@ -2871,7 +2871,8 @@ version_loop_for_if_conversion (class loop *loop, vec<gimple *> *preds)
> integer_zero_node);
> gimple_call_set_lhs (g, cond);
>
> - /* Save BB->aux around loop_version as that uses the same field. */
> + /* Save BB->aux around clone_loop_to_header_edge as that uses the same field.
> + */
> save_length = loop->inner ? loop->inner->num_nodes : loop->num_nodes;
> void **saved_preds = XALLOCAVEC (void *, save_length);
> for (unsigned i = 0; i < save_length; i++)
> @@ -2880,11 +2881,11 @@ version_loop_for_if_conversion (class loop *loop, vec<gimple *> *preds)
> initialize_original_copy_tables ();
> /* At this point we invalidate porfile confistency until IFN_LOOP_VECTORIZED
> is re-merged in the vectorizer. */
> - new_loop = loop_version (loop, cond, &cond_bb,
> - profile_probability::always (),
> - profile_probability::always (),
> - profile_probability::always (),
> - profile_probability::always (), true);
> + new_loop = clone_loop_to_header_edge (loop, cond, &cond_bb,
> + profile_probability::always (),
> + profile_probability::always (),
> + profile_probability::always (),
> + profile_probability::always (), true);
> free_original_copy_tables ();
>
> for (unsigned i = 0; i < save_length; i++)
> diff --git a/gcc/tree-loop-distribution.c b/gcc/tree-loop-distribution.c
> index 2df762c8aa8..ae543fa022d 100644
> --- a/gcc/tree-loop-distribution.c
> +++ b/gcc/tree-loop-distribution.c
> @@ -2705,8 +2705,8 @@ version_loop_by_alias_check (vec<struct partition *> *partitions,
>
> prob = profile_probability::guessed_always ().apply_scale (9, 10);
> initialize_original_copy_tables ();
> - nloop = loop_version (loop, lhs, &cond_bb, prob, prob.invert (),
> - prob, prob.invert (), true);
> + nloop = clone_loop_to_header_edge (loop, lhs, &cond_bb, prob, prob.invert (),
> + prob, prob.invert (), true);
> free_original_copy_tables ();
> /* Record the original loop number in newly generated loops. In case of
> distribution, the original loop will be distributed and the new loop
> diff --git a/gcc/tree-parloops.c b/gcc/tree-parloops.c
> index 5e64d5ed7a3..e19fc52f38b 100644
> --- a/gcc/tree-parloops.c
> +++ b/gcc/tree-parloops.c
> @@ -3083,11 +3083,11 @@ gen_parallel_loop (class loop *loop,
> initialize_original_copy_tables ();
>
> /* We assume that the loop usually iterates a lot. */
> - loop_version (loop, many_iterations_cond, NULL,
> - profile_probability::likely (),
> - profile_probability::unlikely (),
> - profile_probability::likely (),
> - profile_probability::unlikely (), true);
> + clone_loop_to_header_edge (loop, many_iterations_cond, NULL,
> + profile_probability::likely (),
> + profile_probability::unlikely (),
> + profile_probability::likely (),
> + profile_probability::unlikely (), true);
> update_ssa (TODO_update_ssa);
> free_original_copy_tables ();
> }
> diff --git a/gcc/tree-ssa-loop-manip.c b/gcc/tree-ssa-loop-manip.c
> index c7a2f67b129..350e25bb8d2 100644
> --- a/gcc/tree-ssa-loop-manip.c
> +++ b/gcc/tree-ssa-loop-manip.c
> @@ -1282,10 +1282,11 @@ tree_transform_and_unroll_loop (class loop *loop, unsigned factor,
> frequencies in its body because of this change (scale the frequencies
> of blocks before and after the exit by appropriate factors). */
> profile_probability scale_unrolled = prob_entry;
> - new_loop = loop_version (loop, enter_main_cond, NULL, prob_entry,
> - prob_entry.invert (), scale_unrolled,
> - profile_probability::guessed_always (),
> - true);
> + new_loop
> + = clone_loop_to_header_edge (loop, enter_main_cond, NULL, prob_entry,
> + prob_entry.invert (), scale_unrolled,
> + profile_probability::guessed_always (),
> + true);
> gcc_assert (new_loop != NULL);
> update_ssa (TODO_update_ssa);
>
> diff --git a/gcc/tree-ssa-loop-split.c b/gcc/tree-ssa-loop-split.c
> index d30782888f3..5bc9c0f6443 100644
> --- a/gcc/tree-ssa-loop-split.c
> +++ b/gcc/tree-ssa-loop-split.c
> @@ -586,12 +586,12 @@ split_loop (class loop *loop1)
> initialize_original_copy_tables ();
> basic_block cond_bb;
>
> - class loop *loop2 = loop_version (loop1, cond, &cond_bb,
> - true_edge->probability,
> - true_edge->probability.invert (),
> - true_edge->probability,
> - true_edge->probability.invert (),
> - true);
> + class loop *loop2
> + = clone_loop_to_header_edge (loop1, cond, &cond_bb,
> + true_edge->probability,
> + true_edge->probability.invert (),
> + true_edge->probability,
> + true_edge->probability.invert (), true);
> gcc_assert (loop2);
>
> edge new_e = connect_loops (loop1, loop2);
> @@ -1465,9 +1465,9 @@ get_cond_branch_to_split_loop (struct loop *loop, gcond *cond)
> exits
>
> In the graph, loop1 represents the part derived from original one, and
> - loop2 is duplicated using loop_version (), which corresponds to the part
> - of original one being splitted out. In original latch edge of loop1, we
> - insert a new conditional statement duplicated from the semi-invariant cond,
> + loop2 is duplicated using clone_loop_to_header_edge (), which corresponds to
> + the part of original one being splitted out. In original latch edge of loop1,
> + we insert a new conditional statement duplicated from the semi-invariant cond,
> and one of its branch goes back to loop1 header as a latch edge, and the
> other branch goes to loop2 pre-header as an entry edge. And also in loop2,
> we abandon the variant branch of the conditional statement by setting a
> @@ -1489,12 +1489,12 @@ do_split_loop_on_cond (struct loop *loop1, edge invar_branch)
>
> initialize_original_copy_tables ();
>
> - struct loop *loop2 = loop_version (loop1, boolean_true_node, NULL,
> - invar_branch->probability.invert (),
> - invar_branch->probability,
> - invar_branch->probability.invert (),
> - invar_branch->probability,
> - true);
> + struct loop *loop2
> + = clone_loop_to_header_edge (loop1, boolean_true_node, NULL,
> + invar_branch->probability.invert (),
> + invar_branch->probability,
> + invar_branch->probability.invert (),
> + invar_branch->probability, true);
> if (!loop2)
> {
> free_original_copy_tables ();
> diff --git a/gcc/tree-ssa-loop-unswitch.c b/gcc/tree-ssa-loop-unswitch.c
> index fe4dacc0833..6beebe368a7 100644
> --- a/gcc/tree-ssa-loop-unswitch.c
> +++ b/gcc/tree-ssa-loop-unswitch.c
> @@ -488,11 +488,9 @@ tree_unswitch_loop (class loop *loop,
>
> extract_true_false_edges_from_block (unswitch_on, &edge_true, &edge_false);
> prob_true = edge_true->probability;
> - return loop_version (loop, unshare_expr (cond),
> - NULL, prob_true,
> - prob_true.invert (),
> - prob_true, prob_true.invert (),
> - false);
> + return clone_loop_to_header_edge (loop, unshare_expr (cond), NULL, prob_true,
> + prob_true.invert (), prob_true,
> + prob_true.invert (), false);
> }
>
> /* Unswitch outer loops by hoisting invariant guard on
> diff --git a/gcc/tree-vect-loop-manip.c b/gcc/tree-vect-loop-manip.c
> index 4988c93fdb6..ebc013f195e 100644
> --- a/gcc/tree-vect-loop-manip.c
> +++ b/gcc/tree-vect-loop-manip.c
> @@ -3558,8 +3558,9 @@ vect_loop_versioning (loop_vec_info loop_vinfo,
> loop_to_version->num);
>
> initialize_original_copy_tables ();
> - nloop = loop_version (loop_to_version, cond_expr, &condition_bb,
> - prob, prob.invert (), prob, prob.invert (), true);
> + nloop = clone_loop_to_header_edge (loop_to_version, cond_expr,
> + &condition_bb, prob, prob.invert (),
> + prob, prob.invert (), true);
> gcc_assert (nloop);
> nloop = get_loop_copy (loop);
>
>
--
Richard Biener <rguenther@suse.de>
SUSE Software Solutions Germany GmbH, Maxfeldstrasse 5, 90409 Nuernberg,
Germany; GF: Ivo Totev; HRB 36809 (AG Nuernberg)
next prev parent reply other threads:[~2021-11-03 13:36 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-10-27 6:34 [PATCH v2 0/4] loop split fix and functions renaming Xionghu Luo
2021-10-27 6:34 ` [PATCH v2 1/4] Fix loop split incorrect count and probability Xionghu Luo
2021-10-27 7:07 ` Jan Hubicka
2021-10-27 7:23 ` Jan Hubicka
2021-10-27 7:29 ` Richard Biener
2021-10-27 7:44 ` Jan Hubicka
2021-11-08 6:09 ` [PATCH v3 " Xionghu Luo
2021-11-24 5:11 ` Xionghu Luo
2021-10-27 6:34 ` [PATCH v2 2/4] Refactor loop_version Xionghu Luo
2021-10-29 11:52 ` Richard Biener
2021-11-01 5:28 ` Xionghu Luo
2021-10-27 6:34 ` [PATCH v2 3/4] Rename loop_version to clone_loop_to_header_edge Xionghu Luo
2021-11-03 13:36 ` Richard Biener [this message]
2021-10-27 6:34 ` [PATCH v2 4/4] Rename duplicate_loop_to_header_edge to duplicate_loop_body_to_header_edge Xionghu Luo
2021-10-29 11:50 ` Richard Biener
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=5q7275p-51p7-n1qp-23n7-157446289o3@fhfr.qr \
--to=rguenther@suse.de \
--cc=dje.gcc@gmail.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=guojiufu@linux.ibm.com \
--cc=hubicka@kam.mff.cuni.cz \
--cc=linkw@gcc.gnu.org \
--cc=luoxhu@linux.ibm.com \
--cc=segher@kernel.crashing.org \
--cc=wschmidt@linux.ibm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).