From: Stamatis Markianos-Wright <stam.markianos-wright@arm.com>
To: Stamatis Markianos-Wright via Gcc-patches
<gcc-patches@gcc.gnu.org>,
Richard Earnshaw <Richard.Earnshaw@arm.com>,
richard.sandiford@arm.com
Subject: Re: [PING][PATCH 2/2] arm: Add support for MVE Tail-Predicated Low Overhead Loops
Date: Mon, 6 Nov 2023 17:29:48 +0000 [thread overview]
Message-ID: <5793c5af-9c01-48a8-9bf3-f289e7f32640@arm.com> (raw)
In-Reply-To: <mptedh3ceg1.fsf@arm.com>
On 06/11/2023 11:24, Richard Sandiford wrote:
> Stamatis Markianos-Wright <stam.markianos-wright@arm.com> writes:
>>> One of the main reasons for reading the arm bits was to try to answer
>>> the question: if we switch to a downcounting loop with a GE condition,
>>> how do we make sure that the start value is not a large unsigned
>>> number that is interpreted as negative by GE? E.g. if the loop
>>> originally counted up in steps of N and used an LTU condition,
>>> it could stop at a value in the range [INT_MAX + 1, UINT_MAX].
>>> But the loop might never iterate if we start counting down from
>>> most values in that range.
>>>
>>> Does the patch handle that?
>> So AFAICT this is actually handled in the generic code in `doloop_valid_p`:
>>
>> This kind of loops fail because of they are "desc->infinite", then no
>> loop-doloop conversion is attempted at all (even for standard dls/le loops)
>>
>> Thanks to that check I haven't been able to trigger anything like the
>> behaviour you describe, do you think the doloop_valid_p checks are
>> robust enough?
> The loops I was thinking of are provably not infinite though. E.g.:
>
> for (unsigned int i = 0; i < UINT_MAX - 100; ++i)
> ...
>
> is known to terminate. And doloop conversion is safe with the normal
> count-down-by-1 approach, so I don't think current code would need
> to reject it. I.e. a conversion to:
>
> unsigned int i = UINT_MAX - 101;
> do
> ...
> while (--i != ~0U);
>
> would be safe, but a conversion to:
>
> int i = UINT_MAX - 101;
> do
> ...
> while ((i -= step, i > 0));
>
> wouldn't, because the loop body would only be executed once.
>
> I'm only going off the name "infinite" though :) It's possible that
> it has more connotations than that.
>
> Thanks,
> Richard
Ack, yep, I see what you mean now, and yep, that kind of loop does
indeed pass through doloop_valid_p
Interestingly , in the v8-M Arm ARM this is done with:
```
boolean IsLastLowOverheadLoop(INSTR_EXEC_STATE_Type state)
// This does not check whether a loop is currently active.
// If the PE were in a loop, would this be the last one?
return UInt(state.LoopCount) <= (1 << (4 - LTPSIZE));
```
So architecturally the asm we output would be ok (except maybe the
"branch too far subs;bgt;lctp" fallback at
`predicated_doloop_end_internal` (maybe that should be `bhi`))... But
now GE: isn't looking like an accurate representation of this operation
in the compiler.
I'm wondering if I should try to make `predicated_doloop_end_internal`
contain a comparison along the lines of:
(gtu: (plus: (LR) (const_int -num_lanes)) (const_int num_lanes_minus_1))
I'll give that a try :)
The only reason I'd chosen to go with GE earlier, tbh, was because of
the existing handling of GE in loop-doloop.cc
Let me know if any other ideas come to your mind!
Cheers,
Stam
next prev parent reply other threads:[~2023-11-06 17:30 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-17 10:31 [PATCH " Stamatis Markianos-Wright
2023-09-06 17:19 ` [PING][PATCH " Stamatis Markianos-Wright
2023-09-14 12:10 ` Kyrylo Tkachov
2023-09-28 12:51 ` Andre Vieira (lists)
2023-10-11 11:34 ` Stamatis Markianos-Wright
2023-10-23 10:16 ` Andre Vieira (lists)
2023-10-24 15:11 ` Richard Sandiford
2023-11-06 11:03 ` Stamatis Markianos-Wright
2023-11-06 11:24 ` Richard Sandiford
2023-11-06 17:29 ` Stamatis Markianos-Wright [this message]
2023-11-10 12:41 ` Stamatis Markianos-Wright
2023-11-16 11:36 ` Stamatis Markianos-Wright
2023-11-27 12:47 ` Andre Vieira (lists)
2023-11-30 12:55 ` Stamatis Markianos-Wright
2023-12-07 18:08 ` Andre Vieira (lists)
2023-12-09 18:31 ` Richard Sandiford
2023-12-12 17:56 ` Richard Earnshaw
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=5793c5af-9c01-48a8-9bf3-f289e7f32640@arm.com \
--to=stam.markianos-wright@arm.com \
--cc=Richard.Earnshaw@arm.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=richard.sandiford@arm.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).