https://gcc.gnu.org/g:9af2878b87da1f7890c17c50680fb8390936e38a

commit r17-4277-g9af2878b87da1f7890c17c50680fb8390936e38a
Author: Richard Biener <[email protected]>
Date:   Tue Sep 15 13:22:57 2026 +0200

    _BitInt and conversion vectorization
    
    The following adds a missing check to prevent vectorizing conversions
    from _BitInt values which are not appropriately sign-/zero-extended
    to their mode.
    
            * tree-vect-stmts.cc (vectorizable_conversion): Prevent
            conversions from non-mode-precision _BitInt.
    
            * gcc.dg/vect/vect-bitint-1.c: New testcase.

Diff:
---
 gcc/testsuite/gcc.dg/vect/vect-bitint-1.c | 40 +++++++++++++++++++++++++++++++
 gcc/tree-vect-stmts.cc                    | 11 +++++++++
 2 files changed, 51 insertions(+)

diff --git a/gcc/testsuite/gcc.dg/vect/vect-bitint-1.c 
b/gcc/testsuite/gcc.dg/vect/vect-bitint-1.c
new file mode 100644
index 000000000000..106ecd500f7c
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/vect/vect-bitint-1.c
@@ -0,0 +1,40 @@
+/* { dg-require-effective-target bitint } */
+
+#include <stdint.h>
+#include "tree-vect.h"
+
+void __attribute__((noipa))
+foo (int64_t *a, signed _BitInt(17) *b)
+{
+  for (int i = 0; i < 32; i++)
+    a[i] = b[i];
+}
+
+int
+main ()
+{
+  int64_t a[32];
+  _BitInt(17) b[32];
+
+  check_vect ();
+
+#pragma GCC novector
+  for (int i = 0; i < 32; ++i)
+    b[i] = i;
+  /* Now set all padding bits in b[] to 1.  */
+  _BitInt(17) z = ~0;
+  __builtin_clear_padding (&z);
+#pragma GCC novector
+  for (int i = 0; i < 32; ++i)
+    for (int j = 0; j < sizeof (z); ++j)
+      ((char *)&b[i])[j] |= ~(((char *)&z)[j]);
+
+  foo (a, b);
+
+#pragma GCC novector
+  for (int i = 0; i < 32; ++i)
+    if (a[i] != i)
+      __builtin_abort ();
+
+  return 0;
+}
diff --git a/gcc/tree-vect-stmts.cc b/gcc/tree-vect-stmts.cc
index 8cd5fb2001e3..eb78fd2eba39 100644
--- a/gcc/tree-vect-stmts.cc
+++ b/gcc/tree-vect-stmts.cc
@@ -5389,6 +5389,17 @@ vectorizable_conversion (vec_info *vinfo,
       return false;
     }
 
+  /* _BitInt values are not sign-/zero-extended to mode precision.  */
+  if (!VECTOR_BOOLEAN_TYPE_P (vectype_out)
+      && TREE_CODE (rhs_type) == BITINT_TYPE
+      && !type_has_mode_precision_p (rhs_type))
+    {
+      if (dump_enabled_p ())
+       dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
+                        "type conversion from _BitInt unsupported\n");
+      return false;
+    }
+
   if (op_type == binary_op)
     {
       gcc_assert (code == WIDEN_MULT_EXPR

Reply via email to