From: Richard Biener <richard.guenther@gmail.com>
To: Alan Hayward <alan.hayward@arm.com>
Cc: "gcc-patches@gcc.gnu.org" <gcc-patches@gcc.gnu.org>
Subject: Re: [Patch] Optimize condition reductions where the result is an integer induction variable
Date: Wed, 11 Nov 2015 13:25:00 -0000 [thread overview]
Message-ID: <CAFiYyc0Vuohrj0VU98Hx9abp9ybrw+5cbBvsRv2F1DRNGC+Z-g@mail.gmail.com> (raw)
In-Reply-To: <D268E36F.98B3%alan.hayward@arm.com>
On Wed, Nov 11, 2015 at 1:22 PM, Alan Hayward <alan.hayward@arm.com> wrote:
> Hi,
> I hoped to post this in time for Monday’s cut off date, but circumstances
> delayed me until today. Hoping if possible this patch will still be able
> to go in.
>
>
> This patch builds upon the change for PR65947, and reduces the amount of
> code produced in a vectorized condition reduction where operand 2 of the
> COND_EXPR is an assignment of a increasing integer induction variable that
> won't wrap.
>
>
> For example (assuming all types are ints), this is a match:
>
> last = 5;
> for (i = 0; i < N; i++)
> if (a[i] < min_v)
> last = i;
>
> Whereas, this is not because the result is based off a memory access:
> last = 5;
> for (i = 0; i < N; i++)
> if (a[i] < min_v)
> last = a[i];
>
> In the integer induction variable case we can just use a MAX reduction and
> skip all the code I added in my vectorized condition reduction patch - the
> additional induction variables in vectorizable_reduction () and the
> additional checks in vect_create_epilog_for_reduction (). From the patch
> diff only, it's not immediately obvious that those parts will be skipped
> as there is no code changes in those areas.
>
> The initial value of the induction variable is force set to zero, as any
> other value could effect the result of the induction. At the end of the
> loop, if the result is zero, then we restore the original initial value.
+static bool
+is_integer_induction (gimple *stmt, struct loop *loop)
is_nonwrapping_integer_induction?
+ tree lhs_max = TYPE_MAX_VALUE (TREE_TYPE (gimple_phi_result (stmt)));
don't use TYPE_MAX_VALUE.
+ /* Check that the induction increments. */
+ if (tree_int_cst_compare (step, size_zero_node) <= 0)
+ return false;
tree_int_cst_sgn (step) == -1
+ /* Check that the max size of the loop will not wrap. */
+
+ if (! max_loop_iterations (loop, &ni))
+ return false;
+ /* Convert backedges to iterations. */
+ ni += 1;
just use max_stmt_executions (loop, &ni) which properly checks for overflow
of the +1.
+ max_loop_value = wi::add (wi::to_widest (base),
+ wi::mul (wi::to_widest (step), ni));
+
+ if (wi::gtu_p (max_loop_value, wi::to_widest (lhs_max)))
+ return false;
you miss a check for the wi::add / wi::mul to overflow. You can use
extra args to determine this.
Instead of TYPE_MAX_VALUE use wi::max_value (precision, sign).
I wonder if you want to skip all the overflow checks for TYPE_OVERFLOW_UNDEFINED
IV types?
Thanks,
Richard.
>
>
>
> Cheers,
> Alan.
>
next prev parent reply other threads:[~2015-11-11 13:25 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-11-11 12:22 Alan Hayward
2015-11-11 13:25 ` Richard Biener [this message]
2015-11-11 18:54 ` Alan Hayward
2015-11-12 10:54 ` Richard Biener
2015-11-13 10:52 ` Alan Hayward
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=CAFiYyc0Vuohrj0VU98Hx9abp9ybrw+5cbBvsRv2F1DRNGC+Z-g@mail.gmail.com \
--to=richard.guenther@gmail.com \
--cc=alan.hayward@arm.com \
--cc=gcc-patches@gcc.gnu.org \
/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).