On Fri, May 13, 2022 at 12:23:01PM +0200, Richard Biener wrote:
> 2022-05-13 Richard Biener <[email protected]>
>
> * omp-expand.cc (expand_omp_atomic_cas): Do not short-cut
> computation of the new value.
Ok, thanks.
Though, depending on what exactly you allow or disallow, maybe even
the im != 0 might not be acceptable.
Oh, and if COND_EXPRs can only use some limited set of comparisons, we might
need to adjust e.g. arith_overflow_check_p and various other spots in
tree-ssa-math-opts.cc and other passes.
> diff --git a/gcc/omp-expand.cc b/gcc/omp-expand.cc
> index ee708314793..9fcc67a3448 100644
> --- a/gcc/omp-expand.cc
> +++ b/gcc/omp-expand.cc
> @@ -9092,16 +9092,17 @@ expand_omp_atomic_cas (basic_block load_bb, tree addr,
>
> if (cond_stmt)
> {
> - g = gimple_build_assign (gimple_assign_lhs (cond_stmt),
> - NOP_EXPR, im);
> + g = gimple_build_assign (cond, NOP_EXPR, im);
> gimple_set_location (g, loc);
> gsi_insert_before (&gsi, g, GSI_SAME_STMT);
> }
> - else if (need_new)
> +
> + if (need_new)
> {
> g = gimple_build_assign (create_tmp_reg (itype), COND_EXPR,
> - build2 (NE_EXPR, boolean_type_node,
> - im, build_zero_cst (itype)),
> + cond_stmt
> + ? cond : build2 (NE_EXPR, boolean_type_node,
> + im, build_zero_cst (itype)),
> d, re);
> gimple_set_location (g, loc);
> gsi_insert_before (&gsi, g, GSI_SAME_STMT);
> --
> 2.35.3
Jakub