From: "Kewen.Lin" <linkw@linux.ibm.com>
To: GCC Patches <gcc-patches@gcc.gnu.org>
Cc: Segher Boessenkool <segher@kernel.crashing.org>,
Bill Schmidt <wschmidt@linux.ibm.com>,
"bin.cheng" <bin.cheng@linux.alibaba.com>,
Richard Guenther <rguenther@suse.de>
Subject: [PATCH 3/4 V2 GCC11] IVOPTs Consider cost_step on different forms during unrolling
Date: Tue, 25 Feb 2020 09:48:00 -0000 [thread overview]
Message-ID: <3e4c7f3f-a16b-3a4b-6452-15b129ff3393@linux.ibm.com> (raw)
In-Reply-To: <a4ea0512-1e2f-0e88-005b-e874a3aac6fe@linux.ibm.com>
[-- Attachment #1: Type: text/plain, Size: 1109 bytes --]
Hi,
As the proposed hook changes, updated this with main changes:
1) Check with addr_offset_valid_p instead.
2) Check the 1st and the last use for the whole address group.
3) Scale up group costs accordingly.
Bootstrapped/regtested on powerpc64le-linux-gnu (LE).
BR,
Kewen
-----------
gcc/ChangeLog
2020-02-25 Kewen Lin <linkw@gcc.gnu.org>
* tree-ssa-loop-ivopts.c (struct iv_group): New field reg_offset_p.
(struct iv_cand): New field reg_offset_p.
(struct ivopts_data): New field consider_reg_offset_for_unroll_p.
(dump_groups): Dump group with reg_offset_p.
(record_group): Initialize reg_offset_p.
(mark_reg_offset_groups): New function.
(find_interesting_uses): Call mark_reg_offset_groups.
(add_candidate_1): Update reg_offset_p if derived from reg_offset_p group.
(set_group_iv_cost): Scale up group cost with estimate_unroll_factor if
consider_reg_offset_for_unroll_p.
(determine_iv_cost): Increase step cost with estimate_unroll_factor if
consider_reg_offset_for_unroll_p.
(tree_ssa_iv_optimize_loop): Call estimate_unroll_factor, update
consider_reg_offset_for_unroll_p.
[-- Attachment #2: ivopts_v2.diff --]
[-- Type: text/plain, Size: 7017 bytes --]
diff --git a/gcc/tree-ssa-loop-ivopts.c b/gcc/tree-ssa-loop-ivopts.c
index 1ce6d8b..c01fd76 100644
--- a/gcc/tree-ssa-loop-ivopts.c
+++ b/gcc/tree-ssa-loop-ivopts.c
@@ -429,6 +429,8 @@ struct iv_group
struct iv_cand *selected;
/* To indicate this is a doloop use group. */
bool doloop_p;
+ /* To indicate this group is reg_offset valid. */
+ bool reg_offset_p;
/* Uses in the group. */
vec<struct iv_use *> vuses;
};
@@ -470,6 +472,7 @@ struct iv_cand
struct iv *orig_iv; /* The original iv if this cand is added from biv with
smaller type. */
bool doloop_p; /* Whether this is a doloop candidate. */
+ bool reg_offset_p; /* Derived from one reg_offset valid group. */
};
/* Hashtable entry for common candidate derived from iv uses. */
@@ -650,6 +653,10 @@ struct ivopts_data
/* Whether the loop has doloop comparison use. */
bool doloop_use_p;
+
+ /* Whether need to consider register offset addressing mode for the loop with
+ upcoming unrolling by estimated unroll factor. */
+ bool consider_reg_offset_for_unroll_p;
};
/* An assignment of iv candidates to uses. */
@@ -837,6 +844,11 @@ dump_groups (FILE *file, struct ivopts_data *data)
gcc_assert (group->type == USE_COMPARE);
fprintf (file, " Type:\tCOMPARE\n");
}
+ if (group->reg_offset_p)
+ {
+ gcc_assert (address_p (group->type));
+ fprintf (file, " reg_offset_p: true\n");
+ }
for (j = 0; j < group->vuses.length (); j++)
dump_use (file, group->vuses[j]);
}
@@ -1579,6 +1591,7 @@ record_group (struct ivopts_data *data, enum use_type type)
group->related_cands = BITMAP_ALLOC (NULL);
group->vuses.create (1);
group->doloop_p = false;
+ group->reg_offset_p = false;
data->vgroups.safe_push (group);
return group;
@@ -2728,6 +2741,60 @@ split_address_groups (struct ivopts_data *data)
}
}
+/* Go through all address type groups, check and mark reg_offset addressing mode
+ valid groups. */
+
+static void
+mark_reg_offset_groups (struct ivopts_data *data)
+{
+ class loop *loop = data->current_loop;
+ gcc_assert (data->current_loop->estimated_unroll > 1);
+ bool any_reg_offset_p = false;
+
+ for (unsigned i = 0; i < data->vgroups.length (); i++)
+ {
+ struct iv_group *group = data->vgroups[i];
+ if (address_p (group->type))
+ {
+ struct iv_use *head_use = group->vuses[0];
+ if (!tree_fits_poly_int64_p (head_use->iv->step))
+ continue;
+
+ bool found = true;
+ poly_int64 step = tree_to_poly_int64 (head_use->iv->step);
+ /* Max extra offset to fill for head of group. */
+ poly_int64 max_increase = (loop->estimated_unroll - 1) * step;
+ /* Check whether this increment still valid. */
+ if (!addr_offset_valid_p (head_use, max_increase))
+ found = false;
+
+ unsigned group_size = group->vuses.length ();
+ /* Check the whole group further. */
+ if (group_size > 1)
+ {
+ /* Only need to check the last one in the group, both the head and
+ the last is valid, the others should be fine. */
+ struct iv_use *last_use = group->vuses[group_size - 1];
+ poly_int64 max_delta
+ = last_use->addr_offset - head_use->addr_offset;
+ poly_int64 max_offset = max_delta + max_increase;
+ if (maybe_ne (max_delta, 0)
+ && !addr_offset_valid_p (head_use, max_offset))
+ found = false;
+ }
+
+ if (found)
+ {
+ group->reg_offset_p = true;
+ any_reg_offset_p = true;
+ }
+ }
+ }
+
+ if (!any_reg_offset_p)
+ data->consider_reg_offset_for_unroll_p = false;
+}
+
/* Finds uses of the induction variables that are interesting. */
static void
@@ -2759,6 +2826,9 @@ find_interesting_uses (struct ivopts_data *data)
split_address_groups (data);
+ if (data->consider_reg_offset_for_unroll_p)
+ mark_reg_offset_groups (data);
+
if (dump_file && (dump_flags & TDF_DETAILS))
{
fprintf (dump_file, "\n<IV Groups>:\n");
@@ -3144,6 +3214,7 @@ add_candidate_1 (struct ivopts_data *data, tree base, tree step, bool important,
cand->important = important;
cand->incremented_at = incremented_at;
cand->doloop_p = doloop;
+ cand->reg_offset_p = false;
data->vcands.safe_push (cand);
if (!poly_int_tree_p (step))
@@ -3180,7 +3251,11 @@ add_candidate_1 (struct ivopts_data *data, tree base, tree step, bool important,
/* Relate candidate to the group for which it is added. */
if (use)
- bitmap_set_bit (data->vgroups[use->group_id]->related_cands, i);
+ {
+ bitmap_set_bit (data->vgroups[use->group_id]->related_cands, i);
+ if (data->vgroups[use->group_id]->reg_offset_p)
+ cand->reg_offset_p = true;
+ }
return cand;
}
@@ -3638,6 +3713,14 @@ set_group_iv_cost (struct ivopts_data *data,
return;
}
+ /* Since we priced more on non reg_offset IV cand step cost, we should scale
+ up the appropriate IV group costs. Simply consider USE_COMPARE at the
+ loop exit, FIXME if multiple exits supported or no loop exit comparisons
+ matter. */
+ if (data->consider_reg_offset_for_unroll_p
+ && group->vuses[0]->type != USE_COMPARE)
+ cost *= (HOST_WIDE_INT) data->current_loop->estimated_unroll;
+
if (data->consider_all_candidates)
{
group->cost_map[cand->id].cand = cand;
@@ -5874,6 +5957,10 @@ determine_iv_cost (struct ivopts_data *data, struct iv_cand *cand)
cost_step = add_cost (data->speed, TYPE_MODE (TREE_TYPE (base)));
cost = cost_step + adjust_setup_cost (data, cost_base.cost);
+ /* Consider additional step updates during unrolling. */
+ if (data->consider_reg_offset_for_unroll_p && !cand->reg_offset_p)
+ cost += (data->current_loop->estimated_unroll - 1) * cost_step;
+
/* Prefer the original ivs unless we may gain something by replacing it.
The reason is to make debugging simpler; so this is not relevant for
artificial ivs created by other optimization passes. */
@@ -7960,6 +8047,7 @@ tree_ssa_iv_optimize_loop (struct ivopts_data *data, class loop *loop,
data->current_loop = loop;
data->loop_loc = find_loop_location (loop).get_location_t ();
data->speed = optimize_loop_for_speed_p (loop);
+ data->consider_reg_offset_for_unroll_p = false;
if (dump_file && (dump_flags & TDF_DETAILS))
{
@@ -7992,6 +8080,16 @@ tree_ssa_iv_optimize_loop (struct ivopts_data *data, class loop *loop,
if (!find_induction_variables (data))
goto finish;
+ if (targetm.consider_reg_offset_for_unroll_p && exit)
+ {
+ tree_niter_desc *desc = niter_for_exit (data, exit);
+ estimate_unroll_factor (loop, desc);
+ data->consider_reg_offset_for_unroll_p = loop->estimated_unroll > 1;
+ if (dump_file && (dump_flags & TDF_DETAILS)
+ && data->consider_reg_offset_for_unroll_p)
+ fprintf (dump_file, "estimated_unroll:%u\n", loop->estimated_unroll);
+ }
+
/* Finds interesting uses (item 1). */
find_interesting_uses (data);
if (data->vgroups.length () > MAX_CONSIDERED_GROUPS)
next prev parent reply other threads:[~2020-02-25 9:48 UTC|newest]
Thread overview: 45+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-01-16 9:41 [PATCH 0/4 GCC11] IVOPTs consider step cost for different forms when unrolling Kewen.Lin
2020-01-16 9:43 ` [PATCH 1/4 GCC11] Add middle-end unroll factor estimation Kewen.Lin
2020-01-20 13:12 ` Segher Boessenkool
2020-02-10 6:20 ` [PATCH 1/4 v2 " Kewen.Lin
2020-02-10 23:34 ` Segher Boessenkool
2020-02-11 6:51 ` [PATCH 1/4 v3 " Kewen.Lin
2020-02-11 7:00 ` Segher Boessenkool
2020-02-11 2:15 ` [PATCH 1/4 v2 " Jiufu Guo
2020-02-11 3:04 ` Kewen.Lin
2020-01-16 10:02 ` [PATCH 2/4 GCC11] Add target hook stride_dform_valid_p Kewen.Lin
2020-01-20 10:53 ` Richard Sandiford
2020-01-20 11:47 ` Richard Biener
2020-01-20 13:20 ` Segher Boessenkool
2020-02-25 9:46 ` Kewen.Lin
2020-03-02 11:09 ` Richard Sandiford
2020-03-03 12:26 ` Kewen.Lin
2020-05-13 5:50 ` Kewen.Lin
2020-05-28 2:17 ` Ping^1 [PATCH 2/4 V3] " Kewen.Lin
2020-05-28 10:54 ` Richard Sandiford
2020-01-16 10:06 ` [PATCH 3/4 GCC11] IVOPTs Consider cost_step on different forms during unrolling Kewen.Lin
2020-02-25 9:48 ` Kewen.Lin [this message]
2020-05-13 5:42 ` [PATCH 3/4 V3 " Kewen.Lin
2020-01-16 10:12 ` [PATCH 4/4 GCC11] rs6000: P9 D-form test cases Kewen.Lin
2020-01-20 13:37 ` Segher Boessenkool
2020-02-10 6:25 ` [PATCH 4/4 v2 " Kewen.Lin
2020-02-10 23:51 ` Segher Boessenkool
2020-01-20 13:03 ` [PATCH 0/4 GCC11] IVOPTs consider step cost for different forms when unrolling Segher Boessenkool
2020-02-10 6:17 ` Kewen.Lin
2020-02-10 21:29 ` Segher Boessenkool
2020-02-11 2:56 ` Kewen.Lin
2020-02-11 7:34 ` Richard Biener
2020-02-11 7:49 ` Segher Boessenkool
2020-02-11 8:01 ` Richard Biener
2020-02-11 12:46 ` Roman Zhuykov
2020-02-11 13:58 ` Richard Biener
2020-02-11 18:00 ` Segher Boessenkool
2020-02-12 8:07 ` Richard Biener
2020-02-12 21:53 ` Segher Boessenkool
2020-02-11 18:12 ` Segher Boessenkool
2020-02-12 8:13 ` Richard Biener
2020-02-12 10:02 ` Segher Boessenkool
2020-02-12 10:53 ` Richard Biener
2020-02-12 22:05 ` Segher Boessenkool
2020-02-13 7:48 ` Richard Biener
2020-02-13 9:02 ` Segher Boessenkool
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=3e4c7f3f-a16b-3a4b-6452-15b129ff3393@linux.ibm.com \
--to=linkw@linux.ibm.com \
--cc=bin.cheng@linux.alibaba.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=rguenther@suse.de \
--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).