[gcc r13-10028] isel: Check bounds before converting VIEW_CONVERT to VEC_SET.
Avinash Jayakar
avinashd@gcc.gnu.org
Tue Jan 6 06:27:24 GMT 2026
https://gcc.gnu.org/g:0fe9607591c911d1f6b807e5353a1e1a99d249ca
commit r13-10028-g0fe9607591c911d1f6b807e5353a1e1a99d249ca
Author: Avinash Jayakar <avinashd@linux.ibm.com>
Date: Sat Nov 8 09:57:59 2025 +0530
isel: Check bounds before converting VIEW_CONVERT to VEC_SET.
The function gimple_expand_vec_set_expr in the isel pass, converted
VIEW_CONVERT_EXPR to VEC_SET_EXPR without checking the bounds on the index,
which cause ICE on targets that supported VEC_SET_EXPR like x86 and powerpc.
This patch adds a bound check on the index operand and rejects the conversion
if index is out of bound.
2026-01-05 Avinash Jayakar <avinashd@linux.ibm.com>
gcc/ChangeLog:
PR tree-optimization/122126
* gimple-isel.cc (gimple_expand_vec_set_extract_expr): Add bound check.
gcc/testsuite/ChangeLog:
PR tree-optimization/122126
* gcc.dg/pr122126_vextr.c: New test.
* gcc.dg/pr122126_vset.c: New test.
Diff:
---
gcc/gimple-isel.cc | 9 +++++++++
gcc/testsuite/gcc.dg/pr122126_vextr.c | 9 +++++++++
gcc/testsuite/gcc.dg/pr122126_vset.c | 9 +++++++++
3 files changed, 27 insertions(+)
diff --git a/gcc/gimple-isel.cc b/gcc/gimple-isel.cc
index 760029d27c97..f7eabeca6475 100644
--- a/gcc/gimple-isel.cc
+++ b/gcc/gimple-isel.cc
@@ -76,6 +76,15 @@ gimple_expand_vec_set_expr (struct function *fun, gimple_stmt_iterator *gsi)
{
tree pos = TREE_OPERAND (lhs, 1);
tree view_op0 = TREE_OPERAND (op0, 0);
+
+ // if index is a constant, then check the bounds
+ poly_uint64 idx_poly;
+ if (poly_int_tree_p (pos, &idx_poly))
+ {
+ poly_uint64 nelts = TYPE_VECTOR_SUBPARTS (TREE_TYPE (view_op0));
+ if (known_gt (idx_poly, nelts))
+ return false;
+ }
machine_mode outermode = TYPE_MODE (TREE_TYPE (view_op0));
if ((auto_var_in_fn_p (view_op0, fun->decl)
|| (VAR_P (view_op0) && DECL_HARD_REGISTER (view_op0)))
diff --git a/gcc/testsuite/gcc.dg/pr122126_vextr.c b/gcc/testsuite/gcc.dg/pr122126_vextr.c
new file mode 100644
index 000000000000..b598aa01091d
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr122126_vextr.c
@@ -0,0 +1,9 @@
+/* { dg-do compile } */
+/* { dg-options "-O2" } */
+/* { dg-additional-options "-mavx2" { target avx2 } } */
+
+#define vect16 __attribute__((vector_size(16)))
+void ub_set() {
+ volatile vect16 unsigned BS_VAR_0;
+ unsigned a = BS_VAR_0[12];
+}
diff --git a/gcc/testsuite/gcc.dg/pr122126_vset.c b/gcc/testsuite/gcc.dg/pr122126_vset.c
new file mode 100644
index 000000000000..85b2c68247b6
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr122126_vset.c
@@ -0,0 +1,9 @@
+/* { dg-do compile } */
+/* { dg-options "-O2" } */
+/* { dg-additional-options "-mavx2" { target avx2 } } */
+
+#define vect16 __attribute__((vector_size(16)))
+void ub_set() {
+ volatile vect16 unsigned BS_VAR_0;
+ BS_VAR_0[12] = 4;
+}
More information about the Gcc-cvs
mailing list