forwprop: Fix ICE when building an identity constructor [PR94700]
authorRichard Sandiford <richard.sandiford@arm.com>
Wed, 22 Apr 2020 10:05:59 +0000 (11:05 +0100)
committerRichard Sandiford <richard.sandiford@arm.com>
Wed, 22 Apr 2020 10:05:59 +0000 (11:05 +0100)
This is really PR94683 part 2, handling the case in which the vector is
an identity and so doesn't need a VEC_PERM_EXPR.  I should have realised
at the time that the other arm of the "if" would need the same fix.

2020-04-22  Richard Sandiford  <richard.sandiford@arm.com>

gcc/
PR tree-optimization/94700
* tree-ssa-forwprop.c (simplify_vector_constructor): When processing
an identity constructor, use a VIEW_CONVERT_EXPR to handle mixtures
of similarly-structured but distinct vector types.

gcc/testsuite/
PR tree-optimization/94700
* gcc.target/aarch64/sve/acle/general/pr94700.c: New test.

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.target/aarch64/sve/acle/general/pr94700.c [new file with mode: 0644]
gcc/tree-ssa-forwprop.c

index 6e226cc..5cdd4f4 100644 (file)
@@ -1,3 +1,10 @@
+2020-04-22  Richard Sandiford  <richard.sandiford@arm.com>
+
+       PR tree-optimization/94700
+       * tree-ssa-forwprop.c (simplify_vector_constructor): When processing
+       an identity constructor, use a VIEW_CONVERT_EXPR to handle mixtures
+       of similarly-structured but distinct vector types.
+
 2020-04-21  Martin Sebor  <msebor@redhat.com>
 
        PR middle-end/94647
index 4130142..7edcbbf 100644 (file)
@@ -1,3 +1,8 @@
+2020-04-22  Richard Sandiford  <richard.sandiford@arm.com>
+
+       PR tree-optimization/94700
+       * gcc.target/aarch64/sve/acle/general/pr94700.c: New test.
+
 2020-04-22 Iain Sandoe <iain@sandoe.co.uk>
 
        PR c++/94682
diff --git a/gcc/testsuite/gcc.target/aarch64/sve/acle/general/pr94700.c b/gcc/testsuite/gcc.target/aarch64/sve/acle/general/pr94700.c
new file mode 100644 (file)
index 0000000..1feac60
--- /dev/null
@@ -0,0 +1,28 @@
+/* { dg-options "-O2 -msve-vector-bits=256" } */
+/* { dg-final { check-function-bodies "**" "" } } */
+
+#include <arm_sve.h>
+
+typedef float v8sf __attribute__((vector_size(32)));
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+** test:
+**     fadd    z0\.s, p0/m, z0\.s, #1.0
+**     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[1], a[2], a[3], a[4], a[5], a[6], a[7] };
+  return svdiv_x (pg, b, y);
+}
+
+#ifdef __cplusplus
+}
+#endif
index 1a50045..8ee5450 100644 (file)
@@ -2475,7 +2475,18 @@ simplify_vector_constructor (gimple_stmt_iterator *gsi)
          orig[0] = gimple_assign_lhs (lowpart);
        }
       if (conv_code == ERROR_MARK)
-       gimple_assign_set_rhs_from_tree (gsi, orig[0]);
+       {
+         tree src_type = TREE_TYPE (orig[0]);
+         if (!useless_type_conversion_p (type, src_type))
+           {
+             gcc_assert (!targetm.compatible_vector_types_p (type, src_type));
+             tree rhs = build1 (VIEW_CONVERT_EXPR, type, orig[0]);
+             orig[0] = make_ssa_name (type);
+             gassign *assign = gimple_build_assign (orig[0], rhs);
+             gsi_insert_before (gsi, assign, GSI_SAME_STMT);
+           }
+         gimple_assign_set_rhs_from_tree (gsi, orig[0]);
+       }
       else
        gimple_assign_set_rhs_with_ops (gsi, conv_code, orig[0],
                                        NULL_TREE, NULL_TREE);