On Wed, 10 Jun 2026, Tamar Christina wrote:
> This replaces the gimple_build_nop () used for making loop control mask
> variable
> with an IFN_VARYING and then actually adding the statement to the IL.
>
> The bug happens because the mask def statement itself is not in the IL but
> computations that use it are. As such dataflow analysis fails as it tries to
> analyze the use/def chain of these expressions.
>
> When the value if known we replace the IFN_VARYING with the final statement.
>
> Bootstrapped Regtested on aarch64-none-linux-gnu,
> arm-none-linux-gnueabihf, x86_64-pc-linux-gnu
> -m32, -m64 and no issues.
>
> Any comments? Does this do what you expected Richi?
Yes, this is what I had in mind.
Thanks,
Richard.
> Thanks,
> Tamar
>
> gcc/ChangeLog:
>
> PR tree-optimization/125597
> (vect_do_peeling): Create IFN_VARYING for masks.
> * tree-vect-loop-manip.cc (vect_set_loop_condition): Replace the
> IFN_VARYING.
>
> gcc/testsuite/ChangeLog:
>
> PR tree-optimization/125597
> * gcc.target/aarch64/pr125597.c: New test.
>
> ---
> diff --git a/gcc/testsuite/gcc.target/aarch64/pr125597.c
> b/gcc/testsuite/gcc.target/aarch64/pr125597.c
> new file mode 100644
> index
> 0000000000000000000000000000000000000000..895ecfa0f9baa6f5a04b083cf9da1dff28a975fa
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/aarch64/pr125597.c
> @@ -0,0 +1,11 @@
> +/* { dg-do compile } */
> +/* { dg-options "-O3 -mcpu=c1-ultra -mautovec-preference=sve-only" } */
> +
> +_BitInt(256) b;
> +
> +void
> +foo()
> +{
> + for (;;)
> + b ^= 0x100000000020000000000000000000000000000000000wb;
> +}
> diff --git a/gcc/tree-vect-loop-manip.cc b/gcc/tree-vect-loop-manip.cc
> index
> 584d243a403b2534d9c70d6e5ed480fc88a520c4..4a3444966acf5d66394196caf24dc3ba2fa63ec3
> 100644
> --- a/gcc/tree-vect-loop-manip.cc
> +++ b/gcc/tree-vect-loop-manip.cc
> @@ -1402,6 +1402,19 @@ vect_set_loop_condition (class loop *loop, edge
> loop_e, loop_vec_info loop_vinfo
> gcond *orig_cond = get_loop_exit_condition (loop_e);
> gimple_stmt_iterator loop_cond_gsi = gsi_for_stmt (orig_cond);
>
> + /* Check to see whether we will be replacing final_IV below. Because of
> the
> + various replacement strategies (assign vs PHI) just remove it now and
> + leave the SSA name to be rebuild below. */
> + if (final_iv && TREE_CODE (final_iv) == SSA_NAME)
> + {
> + gimple *def = SSA_NAME_DEF_STMT (final_iv);
> + if (gimple_call_internal_p (def, IFN_VARYING))
> + {
> + gimple_stmt_iterator gsi = gsi_for_stmt (def);
> + gsi_remove (&gsi, true);
> + }
> + }
> +
> if (loop_vinfo && LOOP_VINFO_USING_PARTIAL_VECTORS_P (loop_vinfo))
> {
> if (LOOP_VINFO_PARTIAL_VECTORS_STYLE (loop_vinfo) ==
> vect_partial_vectors_avx512)
> @@ -3743,7 +3756,13 @@ vect_do_peeling (loop_vec_info loop_vinfo, tree
> niters, tree nitersm1,
> until then. */
> niters_vector_mult_vf
> = make_ssa_name (TREE_TYPE (*niters_vector));
> - SSA_NAME_DEF_STMT (niters_vector_mult_vf) = gimple_build_nop ();
> + edge exit_e = LOOP_VINFO_MAIN_EXIT (loop_vinfo);
> + gimple_stmt_iterator loop_cond_gsi
> + = gsi_after_labels (exit_e->dest);
> +
> + gcall *tmp = gimple_build_call_internal (IFN_VARYING, 0);
> + gimple_call_set_lhs (tmp, niters_vector_mult_vf);
> + gsi_insert_before (&loop_cond_gsi, tmp, GSI_SAME_STMT);
> *niters_vector_mult_vf_var = niters_vector_mult_vf;
> }
> else
>
>
>
--
Richard Biener <[email protected]>
SUSE Software Solutions Germany GmbH,
Frankenstrasse 146, 90461 Nuernberg, Germany;
GF: Jochen Jaser, Andrew McDonald, Werner Knoblich; (HRB 36809, AG Nuernberg)