https://gcc.gnu.org/g:39ba01fe70c77e70a00ed65a1e6bac8350479f4d
commit r16-2295-g39ba01fe70c77e70a00ed65a1e6bac8350479f4d Author: Richard Biener <rguent...@suse.de> Date: Wed Jul 16 14:07:48 2025 +0200 tree-optimization/121116 - avoid _BitInt for vector element init 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. Diff: --- gcc/testsuite/gcc.dg/torture/pr121116.c | 21 +++++++++++++++++++++ gcc/tree-vect-loop.cc | 1 + 2 files changed, 22 insertions(+) diff --git a/gcc/testsuite/gcc.dg/torture/pr121116.c b/gcc/testsuite/gcc.dg/torture/pr121116.c new file mode 100644 index 000000000000..637324fb4fde --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr121116.c @@ -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; +} diff --git a/gcc/tree-vect-loop.cc b/gcc/tree-vect-loop.cc index 734b7ef52e7b..edad40cef302 100644 --- a/gcc/tree-vect-loop.cc +++ b/gcc/tree-vect-loop.cc @@ -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)