Add a compatible_vector_types_p target hook

Programming / Compilers / GCC - rsandifo [138bc75d-0d04-0410-961f-82ee72b054a4] - 9 January 2020 15:08 EST

One problem with adding an N-bit vector extension to an existing architecture is to decide how N-bit vectors should be passed to functions and returned from functions. Allowing all N-bit vector types to be passed in registers breaks backwards compatibility, since N-bit vectors could be used (and emulated) before the vector extension was added. But always passing N-bit vectors on the stack would be inefficient for things like vector libm functions.

For SVE we took the compromise position of predefining new SVE vector types that are distinct from all existing vector types, including GNU-style vectors. The new types are passed and returned in an efficient way while existing vector types are passed and returned in the traditional way. In the right circumstances, the two types are inter-convertible.

The SVE types are created using:

vectype = build_distinct_type_copy (vectype); SET_TYPE_STRUCTURAL_EQUALITY (vectype); TYPE_ARTIFICIAL (vectype) = 1;

The C frontend maintains this distinction, using VIEW_CONVERT_EXPR to convert from one type to the other. However, the distinction can be lost during gimple, which treats two vector types with the same mode, number of elements, and element type as equivalent. And for most targets that's the right thing to do.

This patch therefore adds a hook that lets the target choose whether such vector types are indeed equivalent.

Note that the new tests fail for -mabi=ilp32 in the same way as other ACLE-based tests. I'm still planning to fix that as a follow-on.

2020-01-09 Richard Sandiford

gcc/
- target.def (compatible_vector_types_p): New target hook.
- hooks.h (hook_bool_const_tree_const_tree_true): Declare.
- hooks.c (hook_bool_const_tree_const_tree_true): New function.
- doc/tm.texi.in (TARGET_COMPATIBLE_VECTOR_TYPES_P): New hook.
- doc/tm.texi: Regenerate.
- gimple-expr.c: Include target.h. (useless_type_conversion_p): Use targetm.compatible_vector_types_p.
- config/aarch64/aarch64.c (aarch64_compatible_vector_types_p): New function. (TARGET_COMPATIBLE_VECTOR_TYPES_P): Define.
- config/aarch64/aarch64-sve-builtins.cc (gimple_folder::convert_pred): Use the original predicate if it already has a suitable type.

gcc/testsuite/
- gcc.target/aarch64/sve/pcs/gnu_vectors_1.c: New test.
- gcc.target/aarch64/sve/pcs/gnu_vectors_2.c: Likewise.

bc8e94e7791 Add a compatible_vector_types_p target hook
gcc/ChangeLog | 15 ++++
gcc/config/aarch64/aarch64-sve-builtins.cc | 8 +-
gcc/config/aarch64/aarch64.c | 12 +++
gcc/doc/tm.texi | 21 +++++
gcc/doc/tm.texi.in | 2 +
gcc/gimple-expr.c | 11 ++-
gcc/hooks.c | 6 ++
gcc/hooks.h | 1 +
gcc/target.def | 23 +++++
gcc/testsuite/ChangeLog | 5 ++
.../gcc.target/aarch64/sve/pcs/gnu_vectors_1.c | 99 ++++++++++++++++++++++
.../gcc.target/aarch64/sve/pcs/gnu_vectors_2.c | 99 ++++++++++++++++++++++
12 files changed, 296 insertions(+), 6 deletions(-)

Upstream: gcc.gnu.org


  • Share