When having a _BitInt induction we should make sure to not create the step vector elements as _BitInts but as vector element typed.
Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed. Richard. 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 | 21 +++++++++++++++++++++ gcc/tree-vect-loop.cc | 1 + 2 files changed, 22 insertions(+) create mode 100644 gcc/testsuite/gcc.dg/torture/pr121116.c diff --git a/gcc/testsuite/gcc.dg/torture/pr121116.c b/gcc/testsuite/gcc.dg/torture/pr121116.c new file mode 100644 index 00000000000..637324fb4fd --- /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 ddd98e0c354..461c8403770 100644 --- a/gcc/tree-vect-loop.cc +++ b/gcc/tree-vect-loop.cc @@ -9832,6 +9832,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) -- 2.43.0