From 85353e24ca90282e1d3620682841f524de20475c Mon Sep 17 00:00:00 2001 From: Richard Sandiford Date: Tue, 21 Apr 2020 16:11:07 +0100 Subject: [PATCH] forwprop: Fix ICE when building a VEC_PERM_EXPR [PR94683] The type compatibility handling in simplify_vector_constructor is based on the number of elements and on element type compatibility, but that's no longer enough to ensure that two vector types are compatible. This patch uses a VIEW_CONVERT_EXPR if the permutation type and result type are distinct. 2020-04-21 Richard Sandiford gcc/ PR tree-optimization/94683 * tree-ssa-forwprop.c (simplify_vector_constructor): Use a VIEW_CONVERT_EXPR to handle mixtures of similarly-structured but distinct vector types. gcc/testsuite/ PR tree-optimization/94683 * gcc.target/aarch64/sve/acle/general/pr94683.c: New test. --- gcc/ChangeLog | 7 ++++++ gcc/testsuite/ChangeLog | 5 ++++ .../gcc.target/aarch64/sve/acle/general/pr94683.c | 29 ++++++++++++++++++++++ gcc/tree-ssa-forwprop.c | 5 ++++ 4 files changed, 46 insertions(+) create mode 100644 gcc/testsuite/gcc.target/aarch64/sve/acle/general/pr94683.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 90c13ae..98ad2b2 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,10 @@ +2020-04-21 Richard Sandiford + + PR tree-optimization/94683 + * tree-ssa-forwprop.c (simplify_vector_constructor): Use a + VIEW_CONVERT_EXPR to handle mixtures of similarly-structured + but distinct vector types. + 2020-04-21 Jakub Jelinek PR c/94641 diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 2d5b81f..0c2ae02 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2020-04-21 Richard Sandiford + + PR tree-optimization/94683 + * gcc.target/aarch64/sve/acle/general/pr94683.c: New test. + 2020-04-21 Jakub Jelinek PR c++/94383 diff --git a/gcc/testsuite/gcc.target/aarch64/sve/acle/general/pr94683.c b/gcc/testsuite/gcc.target/aarch64/sve/acle/general/pr94683.c new file mode 100644 index 0000000..fb7c0e4 --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/sve/acle/general/pr94683.c @@ -0,0 +1,29 @@ +/* { dg-options "-O2 -msve-vector-bits=256" } */ +/* { dg-final { check-function-bodies "**" "" } } */ + +#include + +typedef float v8sf __attribute__((vector_size(32))); + +#ifdef __cplusplus +extern "C" { +#endif + +/* +** test: +** fadd z0\.s, p0/m, z0\.s, #1.0 +** trn1 z0\.s, z0\.s, z0\.s +** fdiv z0\.s, p0/m, z0\.s, z1\.s +** ret +*/ +svfloat32_t +test (svbool_t pg, svfloat32_t x, svfloat32_t y) +{ + v8sf a = svadd_x (pg, x, 1); + v8sf b = { a[0], a[0], a[2], a[2], a[4], a[4], a[6], a[6] }; + return svdiv_x (pg, b, y); +} + +#ifdef __cplusplus +} +#endif diff --git a/gcc/tree-ssa-forwprop.c b/gcc/tree-ssa-forwprop.c index 3d8acf7..1a50045 100644 --- a/gcc/tree-ssa-forwprop.c +++ b/gcc/tree-ssa-forwprop.c @@ -2598,6 +2598,11 @@ simplify_vector_constructor (gimple_stmt_iterator *gsi) res, TYPE_SIZE (type), bitsize_zero_node); if (conv_code != ERROR_MARK) res = gimple_build (&stmts, conv_code, type, res); + else if (!useless_type_conversion_p (type, TREE_TYPE (res))) + { + gcc_assert (!targetm.compatible_vector_types_p (type, perm_type)); + res = gimple_build (&stmts, VIEW_CONVERT_EXPR, type, res); + } /* Blend in the actual constant. */ if (converted_orig1) res = gimple_build (&stmts, VEC_PERM_EXPR, type, -- 2.7.4