]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
tree-optimization/121116 - avoid _BitInt for vector element init
authorRichard Biener <rguenther@suse.de>
Wed, 16 Jul 2025 12:07:48 +0000 (14:07 +0200)
committerRichard Biener <rguenth@gcc.gnu.org>
Wed, 16 Jul 2025 13:34:16 +0000 (15:34 +0200)
When having a _BitInt induction we should make sure to not create
the step vector elements as _BitInts but as vector element typed.

PR tree-optimization/121116
* tree-vect-loop.cc (vectorizable_induction): Use the
step vector element type for further processing.

* gcc.dg/torture/pr121116.c: New testcase.

gcc/testsuite/gcc.dg/torture/pr121116.c [new file with mode: 0644]
gcc/tree-vect-loop.cc

diff --git a/gcc/testsuite/gcc.dg/torture/pr121116.c b/gcc/testsuite/gcc.dg/torture/pr121116.c
new file mode 100644 (file)
index 0000000..637324f
--- /dev/null
@@ -0,0 +1,21 @@
+/* { dg-do run { target bitint } } */
+
+#include <stdlib.h>
+#include <stdckdint.h>
+#include <string.h>
+typedef _BitInt(16) bit16;
+[[nodiscard]] static bit16 process_data(bit16 input) {
+    _Static_assert(sizeof(bit16) == 2, "Unexpected size of bit16");
+    return (input << 5) | (input >> 9);
+}
+int main(void) {
+    const bit16 data = 0b101'0101'0000'0000;
+    bit16 result = 0;
+    for (bit16 i = 0; i < 0b1000; ++i) {
+        result ^= process_data(data ^ i);
+    }
+    if (ckd_add(&result, result, 0x1234)) {
+        return EXIT_FAILURE;
+    }
+    return (result & 0xFF00) ? 0 : 1;
+}
index 734b7ef52e7b5b6dfa6e52af9585532538208203..edad40cef302aeb86062436ae5499e3f27f585da 100644 (file)
@@ -9831,6 +9831,7 @@ vectorizable_induction (loop_vec_info loop_vinfo,
     }
   tree stept = TREE_TYPE (step_expr);
   tree step_vectype = get_same_sized_vectype (stept, vectype);
+  stept = TREE_TYPE (step_vectype);
 
   /* Check for target support of the vectorized arithmetic used here.  */
   if (!target_supports_op_p (step_vectype, PLUS_EXPR, optab_default)