c++/88601 - [C/C++] __builtin_shufflevector support
authorRichard Biener <rguenther@suse.de>
Fri, 21 May 2021 09:33:30 +0000 (11:33 +0200)
committerRichard Biener <rguenther@suse.de>
Mon, 31 May 2021 06:46:04 +0000 (08:46 +0200)
commitef8176e0fac935c095cc39f4ecdfd43cdb8cb3f3
tree89fad1f0a7e3560dc2a1682f62cd2beffe3b9e5d
parentdf4e0359dad239854af0ea9eacb8e7e3719557d0
c++/88601 - [C/C++] __builtin_shufflevector support

This adds support for the clang __builtin_shufflevector extension to
the C and C++ frontends.  The builtin is lowered to VEC_PERM_EXPR.
Because VEC_PERM_EXPR does not support different sized vector inputs
or result or the special permute index of -1 (don't-care)
c_build_shufflevector applies lowering by widening inputs and output
to the widest vector, replacing -1 by a defined index and
subsetting the final vector if we produced a wider result than
desired.

Code generation thus can be sub-optimal, followup patches will
aim to fix that by recovering from part of the missing features
during RTL expansion and by relaxing the constraints of the GIMPLE
IL with regard to VEC_PERM_EXPR.

2021-05-21  Richard Biener  <rguenther@suse.de>

PR c++/88601
gcc/c-family/
* c-common.c: Include tree-vector-builder.h and
vec-perm-indices.h.
(c_common_reswords): Add __builtin_shufflevector.
(c_build_shufflevector): New funtion.
* c-common.h (enum rid): Add RID_BUILTIN_SHUFFLEVECTOR.
(c_build_shufflevector): Declare.

gcc/c/
* c-decl.c (names_builtin_p): Handle RID_BUILTIN_SHUFFLEVECTOR.
* c-parser.c (c_parser_postfix_expression): Likewise.

gcc/cp/
* cp-objcp-common.c (names_builtin_p): Handle
RID_BUILTIN_SHUFFLEVECTOR.
* cp-tree.h (build_x_shufflevector): Declare.
* parser.c (cp_parser_postfix_expression): Handle
RID_BUILTIN_SHUFFLEVECTOR.
* pt.c (tsubst_copy_and_build): Handle IFN_SHUFFLEVECTOR.
* typeck.c (build_x_shufflevector): Build either a lowered
VEC_PERM_EXPR or an unlowered shufflevector via a temporary
internal function IFN_SHUFFLEVECTOR.

gcc/
* internal-fn.c (expand_SHUFFLEVECTOR): Define.
* internal-fn.def (SHUFFLEVECTOR): New.
* internal-fn.h (expand_SHUFFLEVECTOR): Declare.
* doc/extend.texi: Document __builtin_shufflevector.

gcc/testsuite/
* c-c++-common/builtin-shufflevector-2.c: New testcase.
* c-c++-common/torture/builtin-shufflevector-1.c: Likewise.
* g++.dg/ext/builtin-shufflevector-1.C: Likewise.
* g++.dg/ext/builtin-shufflevector-2.C: Likewise.
17 files changed:
gcc/c-family/c-common.c
gcc/c-family/c-common.h
gcc/c/c-decl.c
gcc/c/c-parser.c
gcc/cp/cp-objcp-common.c
gcc/cp/cp-tree.h
gcc/cp/parser.c
gcc/cp/pt.c
gcc/cp/typeck.c
gcc/doc/extend.texi
gcc/internal-fn.c
gcc/internal-fn.def
gcc/internal-fn.h
gcc/testsuite/c-c++-common/builtin-shufflevector-2.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/torture/builtin-shufflevector-1.c [new file with mode: 0644]
gcc/testsuite/g++.dg/ext/builtin-shufflevector-1.C [new file with mode: 0644]
gcc/testsuite/g++.dg/ext/builtin-shufflevector-2.C [new file with mode: 0644]