[PATCH] PR tree-optimization/101895: Fold VEC_PERM to help recognize FMA.
Roger Sayle
roger@nextmovesoftware.com
Fri Mar 11 23:48:34 GMT 2022
This patch resolves PR tree-optimization/101895 a missed optimization
regression, by adding a constant folding simplification to match.pd to
simplify the transform "mult; vec_perm; plus" into "vec_perm; mult; plus"
with the aim that keeping the multiplication and addition next to each
other allows them to be recognized as fused-multiply-add on suitable
targets. This transformation requires a tweak to match.pd's
vec_same_elem_p predicate to handle CONSTRUCTOR_EXPRs using the same
SSA_NAME_DEF_STMT idiom used for constructors elsewhere in match.pd.
The net effect is that the following code example:
void foo(float * __restrict__ a, float b, float *c) {
a[0] = c[0]*b + a[0];
a[1] = c[2]*b + a[1];
a[2] = c[1]*b + a[2];
a[3] = c[3]*b + a[3];
}
when compiled on x86_64-pc-linux-gnu with -O2 -march=cascadelake
currently generates:
vbroadcastss %xmm0, %xmm0
vmulps (%rsi), %xmm0, %xmm0
vpermilps $216, %xmm0, %xmm0
vaddps (%rdi), %xmm0, %xmm0
vmovups %xmm0, (%rdi)
ret
but with this patch now generates the improved:
vpermilps $216, (%rsi), %xmm1
vbroadcastss %xmm0, %xmm0
vfmadd213ps (%rdi), %xmm0, %xmm1
vmovups %xmm1, (%rdi)
ret
This patch has been tested on x86_64-pc-linux-gnu with make bootstrap
and make -k check with no new failures. Ok for mainline?
2022-03-11 Roger Sayle <roger@nextmovesoftware.com>
gcc/ChangeLog
PR tree-optimization/101895
* match.pd (vec_same_elem_p): Handle CONSTRUCTOR_EXPR def.
(plus (vec_perm (mult ...) ...) ...): New reordering simplification.
gcc/testsuite/ChangeLog
* gcc.target/i386/pr101895.c: New test case.
Thanks in advance,
Roger
--
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: patchvp.txt
URL: <https://gcc.gnu.org/pipermail/gcc-patches/attachments/20220311/6542016c/attachment.txt>
More information about the Gcc-patches
mailing list