This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[rtl, patch] combine concat+shuffle
- From: Marc Glisse <marc dot glisse at inria dot fr>
- To: gcc-patches at gcc dot gnu dot org
- Date: Mon, 7 May 2012 22:16:24 +0200 (CEST)
- Subject: [rtl, patch] combine concat+shuffle
Hello,
this patch combines for vectors a concat and a shuffle. An example on x86
would be:
__m128d f(double d){
__m128d x=_mm_setr_pd(-d,d);
return _mm_shuffle_pd(x,x,1);
}
which was compiled as:
vmovsd .LC0(%rip), %xmm1
vxorpd %xmm0, %xmm1, %xmm1
vunpcklpd %xmm0, %xmm1, %xmm0
vshufpd $1, %xmm0, %xmm0, %xmm0
and with the patch:
vmovsd .LC0(%rip), %xmm1
vxorpd %xmm0, %xmm1, %xmm1
vunpcklpd %xmm1, %xmm0, %xmm0
This happens a lot in my code, for interval arithmetics, where I have a
number d, build an interval (-d,d) from it, then subtract that interval
from an other one, and subtraction is implemented as shufpd+addpd.
The patch is quite specialized, but I guessed I could start there, and it
can always be generalized later.
For the testsuite, since the patch is not in a particular target, it would
be better to have a generic test (in gcc.dg?), but I don't really know how
to write a generic one, so would a test in gcc.target/i386 that scans
the asm for shuf or perm be ok?
Ah, and if I use __builtin_shuffle instead of _mm_shuffle_pd, the patch
works without -mavx, but -mavx uses vpermilpd (ie a vec_select:V2DF
(reg:V2DF) ...) instead of a vshufpd, so I'll probably want to handle that
too later. I thought about doing a general transformation from
vec_select(vec_concat(x,x),*) to vec_select(x,*) (reducing the indexes in
* so they fit), but that seemed way too dangerous.
--
Marc Glisse
Attachment:
P2
Description: Text document