]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
forwprop: Ensure that shuffle masks are VECTOR_CSTs
authorChristoph Müllner <christoph.muellner@vrull.eu>
Wed, 15 Jan 2025 16:53:47 +0000 (17:53 +0100)
committerChristoph Müllner <christoph.muellner@vrull.eu>
Thu, 16 Jan 2025 08:51:12 +0000 (09:51 +0100)
As reported in PR118487, it is possible that the mask parameter
of a __builtin_shuffle() is not a VECTOR_CST.
If this is the case and checking is enabled then an ICE is triggered.
Let's add a check to fix this issue.

PR tree-optimization/118487

gcc/ChangeLog:

* tree-ssa-forwprop.cc (recognise_vec_perm_simplify_seq):
Ensure that shuffle masks are VECTOR_CSTs.

gcc/testsuite/ChangeLog:

* gcc.dg/tree-ssa/pr118487.c: New test.

Signed-off-by: Christoph Müllner <christoph.muellner@vrull.eu>
gcc/testsuite/gcc.dg/tree-ssa/pr118487.c [new file with mode: 0644]
gcc/tree-ssa-forwprop.cc

diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr118487.c b/gcc/testsuite/gcc.dg/tree-ssa/pr118487.c
new file mode 100644 (file)
index 0000000..aa8038a
--- /dev/null
@@ -0,0 +1,18 @@
+/* { dg-do compile } */
+/* { dg-options "-O3 -fdump-tree-forwprop1-details -Wno-psabi" } */
+/* { dg-additional-options "-msse2" { target i?86-*-* x86_64-*-* } } */
+
+typedef int vec __attribute__((vector_size(16)));
+vec f1_p_v_in, f1_sel00, f1_sel11, f1_sel, f1_v_out_2;
+void f1() {
+  vec v_1, v_2, v_x, v_y;
+  v_1 = __builtin_shuffle(f1_p_v_in, f1_sel00);
+  v_2 = __builtin_shuffle(f1_p_v_in, f1_sel11);
+  v_x = v_2 - v_1;
+  v_y = v_1 + v_2;
+  f1_v_out_2 = __builtin_shuffle(v_y, v_x, f1_sel);
+}
+
+/* Won't blend because masks (e.g. f1_sel00) are not VECTOR_CSTs.  */
+
+/* { dg-final { scan-tree-dump-not "Vec perm simplify sequences have been merged" "forwprop1" } } */
index 2f82f0633883647ab28d6bd8e5869758d4e61639..9474682152a6d89e20c8cd8b2c9b6a4012a1539d 100644 (file)
@@ -3541,7 +3541,8 @@ recognise_vec_perm_simplify_seq (gassign *stmt, vec_perm_simplify_seq *seq)
   tree v_y = gimple_assign_rhs2 (stmt);
   tree sel = gimple_assign_rhs3 (stmt);
 
-  if (!VECTOR_CST_NELTS (sel).is_constant (&nelts)
+  if (TREE_CODE (sel) != VECTOR_CST
+      || !VECTOR_CST_NELTS (sel).is_constant (&nelts)
       || TREE_CODE (v_x) != SSA_NAME
       || TREE_CODE (v_y) != SSA_NAME
       || !has_single_use (v_x)
@@ -3615,7 +3616,9 @@ recognise_vec_perm_simplify_seq (gassign *stmt, vec_perm_simplify_seq *seq)
     return false;
 
   unsigned HOST_WIDE_INT v_1_nelts, v_2_nelts;
-  if (!VECTOR_CST_NELTS (v_1_sel).is_constant (&v_1_nelts)
+  if (TREE_CODE (v_1_sel) != VECTOR_CST
+      || !VECTOR_CST_NELTS (v_1_sel).is_constant (&v_1_nelts)
+      || TREE_CODE (v_2_sel) != VECTOR_CST
       || !VECTOR_CST_NELTS (v_2_sel).is_constant (&v_2_nelts))
     return false;