From: Tom de Vries <vries@codesourcery.com>
To: Zdenek Dvorak <rakdver@kam.mff.cuni.cz>
Cc: gcc-patches@gcc.gnu.org
Subject: Re: [PATCH PR45098, 7/10] Nowrap limits iterations
Date: Sat, 21 May 2011 22:53:00 -0000 [thread overview]
Message-ID: <4DD7FD8F.20909@codesourcery.com> (raw)
In-Reply-To: <20110521122407.GA22860@kam.mff.cuni.cz>
On 05/21/2011 02:24 PM, Zdenek Dvorak wrote:
>> * tree-ssa-loop-ivopts.c (may_eliminate_iv): Fix
>> estimated_loop_iterations comparison.
>
> I don't think this part is correct, though:
>
>> Index: gcc/tree-ssa-loop-ivopts.c
>> ===================================================================
>> --- gcc/tree-ssa-loop-ivopts.c (revision 173734)
>> +++ gcc/tree-ssa-loop-ivopts.c (working copy)
>> @@ -4391,8 +4391,13 @@ may_eliminate_iv (struct ivopts_data *da
>> {
>> if (!estimated_loop_iterations (loop, true, &max_niter))
>> return false;
>> - /* The loop bound is already adjusted by adding 1. */
>> - if (double_int_ucmp (max_niter, period_value) > 0)
>> + /* The max iterations applies also to the number of times the loop
>> + exit condition is executed. The number of distinct values of
>> + the cand is period_value + 1. So, test for
>> + 'period_value + 1 >= max_iterations'.
>> + */
>> + period_value = double_int_add (period_value, double_int_one);
>> + if (double_int_ucmp (max_niter, period_value) > 0)
>> return false;
>> }
>> else
>
> max_niter is the upper bound on the number of iterations of the loop, i.e., the number
> of executions of its latch edge.
max_niter is set from estimated_loop_iterations, meaning from
loop->nb_iterations_upper_bound.
consider:
...
void f(int *a)
{
int i;
for (i = 0; i < 10; ++i)
a[i] = 0;
}
...
at ivopts, it looks like this (compiled with -Os -fno-tree-vrp
-fno-tree-dominator-opts -fno-tree-loop-ivcanon, to get a source-like
representation)
...
f (int * a)
{
int i;
int * D.2009;
unsigned int D.2008;
unsigned int i.0;
<bb 2>:
goto <bb 4>;
<bb 3>:
i.0_3 = (unsigned int) i_1;
D.2008_4 = i.0_3 * 4;
D.2009_6 = a_5(D) + D.2008_4;
*D.2009_6 = 0;
i_7 = i_1 + 1;
<bb 4>:
# i_1 = PHI <0(2), i_7(3)>
if (i_1 <= 9)
goto <bb 3>;
else
goto <bb 5>;
<bb 5>:
return;
}
...
The header block of the loop is bb 4, the latch block is bb 3:
...
(gdb) p loop.header.index
$4 = 4
(gdb) p loop.latch.index
$5 = 3
...
The number of times the latch edge is executed, is 10.
But loop->nb_iterations_upper_bound, or max_niter is 11:
...
(gdb) p *loop
$1 = {num = 1, ninsns = 0, header = 0xf7dc2440, latch = 0xf7dc2400, lpt_decision
= {decision = LPT_NONE, times = 0}, av_ninsns = 0, num_nodes = 2, superloops =
0xf7db6ee8, inner = 0x0, next = 0x0,
aux = 0x0, nb_iterations = 0xf7d3d540, nb_iterations_upper_bound = {low = 11,
high = 0}, nb_iterations_estimate = {low = 11, high = 0}, any_upper_bound = 1
'\001', any_estimate = 1 '\001',
can_be_parallel = 0 '\000', estimate_state = EST_AVAILABLE, bounds =
0xf7d3da2c, exits = 0xf7dc3d70}
...
> Therefore, the control induction variable of the loop
> will (at the exit statement) achieve at most max_niter + 1 different values.
Based on what I observe, I'd say the control induction variable of the loop will
achieve at most max_niter different values.
> Conversely,
> the number of distinct values that the control iv can represent is period + 1 (naming of
> the "period" variable is a bit missleading).
agree.
Thanks,
- Tom
next prev parent reply other threads:[~2011-05-21 18:01 UTC|newest]
Thread overview: 46+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-05-17 7:23 [PATCH, PR45098] Tom de Vries
2011-05-17 7:25 ` [PATCH, PR45098, 1/10] Tom de Vries
2011-05-19 11:17 ` [PATCH PR45098, 1/10] Proc object-size fix Tom de Vries
2011-05-17 8:12 ` [PATCH, PR45098, 2/10] Tom de Vries
2011-05-18 9:39 ` Zdenek Dvorak
2011-05-17 8:30 ` [PATCH, PR45098, 3/10] Tom de Vries
2011-05-18 10:10 ` Zdenek Dvorak
2011-05-18 13:00 ` Tom de Vries
[not found] ` <20110518152457.GA13360@kam.mff.cuni.cz>
2011-05-18 19:30 ` Tom de Vries
2011-05-17 8:32 ` [PATCH, PR45098, 4/10] Tom de Vries
2011-05-18 17:46 ` [PATCH PR45098, 4/10] Iv init cost Tom de Vries
2011-05-18 22:59 ` Zdenek Dvorak
2011-05-25 14:20 ` Richard Sandiford
2011-05-26 12:24 ` Tom de Vries
2011-05-31 15:22 ` Richard Sandiford
2011-05-17 8:37 ` [PATCH, PR45098, 5/10] Tom de Vries
2011-05-18 17:48 ` [PATCH PR45098, 5/10] Bound cost Tom de Vries
2011-05-19 4:45 ` Zdenek Dvorak
2011-05-17 8:42 ` [PATCH, PR45098, 6/10] Tom de Vries
2011-05-18 17:48 ` [PATCH PR45098, 6/10] Bound cost - test cases Tom de Vries
2011-05-17 8:58 ` [PATCH, PR45098, 7/10] Tom de Vries
2011-05-18 17:52 ` [PATCH PR45098, 7/10] Nowrap limits iterations Tom de Vries
2011-05-19 4:45 ` Zdenek Dvorak
2011-05-20 12:22 ` Tom de Vries
2011-05-21 18:54 ` Zdenek Dvorak
2011-05-21 22:53 ` Tom de Vries [this message]
2011-05-28 17:58 ` Tom de Vries
2011-05-30 15:12 ` Zdenek Dvorak
2011-05-31 9:07 ` Tom de Vries
2011-05-31 9:11 ` Zdenek Dvorak
2011-06-11 10:13 ` Tom de Vries
2011-06-12 1:17 ` Zdenek Dvorak
2011-05-23 14:50 ` H.J. Lu
2011-05-17 9:03 ` [PATCH, PR45098, 8/10] Tom de Vries
2011-05-18 18:23 ` [PATCH PR45098, 8/10] Nowrap limits iterations - test cases Tom de Vries
2011-05-18 18:27 ` [PATCH PR45098, 9/10] Cheap shift-add Tom de Vries
2011-05-19 5:33 ` Zdenek Dvorak
2011-05-20 11:32 ` Tom de Vries
2011-05-20 20:09 ` Zdenek Dvorak
2011-05-21 15:05 ` Eric Botcazou
2011-05-22 19:33 ` Tom de Vries
2011-05-22 20:22 ` Richard Guenther
2011-05-22 21:11 ` Eric Botcazou
2011-05-17 10:03 ` [PATCH, PR45098, 9/10] Tom de Vries
2011-05-17 10:30 ` [PATCH, PR45098, 10/10] Tom de Vries
2011-05-18 18:30 ` [PATCH PR45098, 10/10] Cheap shift-add - test case Tom de Vries
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=4DD7FD8F.20909@codesourcery.com \
--to=vries@codesourcery.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=rakdver@kam.mff.cuni.cz \
/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).