This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: [RFC] Vectorization of indexed elements
- From: Vidya Praveen <vidyapraveen at arm dot com>
- To: Jakub Jelinek <jakub at redhat dot com>
- Cc: Richard Biener <rguenther at suse dot de>, "gcc at gcc dot gnu dot org" <gcc at gcc dot gnu dot org>, "ook at ucw dot cz" <ook at ucw dot cz>, "marc dot glisse at inria dot fr" <marc dot glisse at inria dot fr>
- Date: Wed, 4 Dec 2013 17:07:21 +0000
- Subject: Re: [RFC] Vectorization of indexed elements
- Authentication-results: sourceware.org; auth=none
- References: <20130924150425 dot GE22907 at e103625-lin dot cambridge dot arm dot com> <alpine dot LNX dot 2 dot 00 dot 1309251123490 dot 29411 at zhemvz dot fhfr dot qr> <20130927145008 dot GA861 at e103625-lin dot cambridge dot arm dot com> <20130927151945 dot GB861 at e103625-lin dot cambridge dot arm dot com> <20130930125454 dot GD3460 at e103625-lin dot cambridge dot arm dot com> <alpine dot LNX dot 2 dot 00 dot 1309301504120 dot 5759 at zhemvz dot fhfr dot qr> <20130930140001 dot GF3460 at e103625-lin dot cambridge dot arm dot com> <alpine dot LNX dot 2 dot 00 dot 1310011022420 dot 5759 at zhemvz dot fhfr dot qr> <20131011145408 dot GB23850 at e103625-lin dot cambridge dot arm dot com> <20131011150524 dot GX30970 at tucnak dot zalov dot cz>
Hi Jakub,
Apologies for the late response.
On Fri, Oct 11, 2013 at 04:05:24PM +0100, Jakub Jelinek wrote:
> On Fri, Oct 11, 2013 at 03:54:08PM +0100, Vidya Praveen wrote:
> > Here's a compilable example:
> >
> > void
> > foo (int *__restrict__ a,
> > int *__restrict__ b,
> > int *__restrict__ c)
> > {
> > int i;
> >
> > for (i = 0; i < 8; i++)
> > a[i] = b[i] * c[2];
> > }
> >
> > This is vectorized by duplicating c[2] now. But I'm trying to take advantage
> > of target instructions that can take a vector register as second argument but
> > use only one element (by using the same value for all the lanes) of the
> > vector register.
> >
> > Eg. mul <vec-reg>, <vec-reg>, <vec-reg>[index]
> > mla <vec-reg>, <vec-reg>, <vec-reg>[index] // multiply and add
> >
> > But for a loop like the one in the C example given, I will have to load the
> > c[2] in one element of the vector register (leaving the remaining unused)
> > rather. This is why I was proposing to load just one element in a vector
> > register (what I meant as "lane specific load"). The benefit of doing this is
> > that we avoid explicit duplication, however such a simplification can only
> > be done where such support is available - the reason why I was thinking in
> > terms of optional standard pattern name. Another benefit is we will also be
> > able to support scalars in the expression like in the following example:
> >
> > void
> > foo (int *__restrict__ a,
> > int *__restrict__ b,
> > int c)
> > {
> > int i;
> >
> > for (i = 0; i < 8; i++)
> > a[i] = b[i] * c;
> > }
>
> So just during combine let the broadcast operation be combined with the
> arithmetics?
Yes. I can do that. But I always want it to be possible to recognize and load
directly to the indexed vector register from memory.
> Intel AVX512 ISA has similar feature, not sure what exactly
> they are doing for this.
Thanks. I'll try to go through the code to understand.
> That said, the broadcast is likely going to be
> hoisted before the loop, and in that case is it really cheaper to have
> it unbroadcasted in a vector register rather than to broadcast it before the
> loop and just use there?
Could you explain what do you mean by unbroadcast? The constructor needs to be
expanded in one way or another, isn't it? I thought expanding to vec_duplicate
when the values are uniform is the most efficient when vec_duplicate could be
supported by the target. If you had meant that each element of vector is loaded
separately, I am thinking how can I combine such an operation with the arithmetic
operation.
Thanks
VP.