[PATCH] libstdc++: Use canonical loop form in std::reduce
Abhishek Kaushik
abhishek.kaushik@intel.com
Fri Jan 31 15:15:14 GMT 2025
Can we do __first + 4 <= __last?
________________________________
From: Jonathan Wakely <jwakely@redhat.com>
Sent: Friday, January 31, 2025 8:28 PM
To: libstdc++@gcc.gnu.org <libstdc++@gcc.gnu.org>
Cc: Abhishek Kaushik <abhishek.kaushik@intel.com>; gcc-patches@gcc.gnu.org <gcc-patches@gcc.gnu.org>
Subject: Re: [PATCH] libstdc++: Use canonical loop form in std::reduce
On Fri, 31 Jan 2025 at 14:47, Marc Glisse <marc.glisse@inria.fr> wrote:
>
> On Fri, 31 Jan 2025, Abhishek Kaushik wrote:
>
> > The current while loop in std::reduce and related functions is hard to
> > vectorize because the loop control variable is hard to detect in icx.
> >
> > `while ((__last - __first) >= 4)`
> >
> > Changing the loop header to a for loop following the OpenMP canonical
> > form allows easy vectorization, resulting in improved performance.
> >
> > `for (; __first <= __last - 4; __first += 4)`
>
> Is that always legal? If the sequence has size 1, is __last - 4 well
> defined?
No. I thought of that and for some reason assumed that since we're
already doing (last - first) it's OK ... but that's nonsense.
We need to check the size before the stride=4 loop.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://gcc.gnu.org/pipermail/libstdc++/attachments/20250131/15e896ec/attachment.htm>
More information about the Libstdc++
mailing list