[2/2] forwprop: Ensure that shuffle masks are VECTOR_CSTs
Checks
| Context |
Check |
Description |
| linaro-tcwg-bot/tcwg_gcc_build--master-arm |
success
|
Build passed
|
| linaro-tcwg-bot/tcwg_gcc_check--master-arm |
success
|
Test passed
|
| linaro-tcwg-bot/tcwg_gcc_build--master-aarch64 |
success
|
Build passed
|
Commit Message
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 | 18 ++++++++++++++++++
gcc/tree-ssa-forwprop.cc | 7 +++++--
2 files changed, 23 insertions(+), 2 deletions(-)
create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/pr118487.c
Comments
On Wed, 15 Jan 2025, Christoph Müllner wrote:
> 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.
OK.
Thanks,
Richard.
> 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 | 18 ++++++++++++++++++
> gcc/tree-ssa-forwprop.cc | 7 +++++--
> 2 files changed, 23 insertions(+), 2 deletions(-)
> create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/pr118487.c
>
> diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr118487.c b/gcc/testsuite/gcc.dg/tree-ssa/pr118487.c
> new file mode 100644
> index 00000000000..aa8038a5cb9
> --- /dev/null
> +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr118487.c
> @@ -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" } } */
> diff --git a/gcc/tree-ssa-forwprop.cc b/gcc/tree-ssa-forwprop.cc
> index 2f82f063388..9474682152a 100644
> --- a/gcc/tree-ssa-forwprop.cc
> +++ b/gcc/tree-ssa-forwprop.cc
> @@ -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;
>
>
new file mode 100644
@@ -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" } } */
@@ -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;