https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79981

--- Comment #4 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
(In reply to Dominik Vogt from comment #3)
> (In reply to Richard Biener from comment #2)
> > of course needs to be conditional on oldlhs being bool and lhs being
> > integral.
> 
> Like so?
> 
> --
> diff --git a/gcc/gimple-fold.c b/gcc/gimple-fold.c
> index 9fd45d1..e5e448e 100644
> --- a/gcc/gimple-fold.c
> +++ b/gcc/gimple-fold.c
> @@ -3581,7 +3581,12 @@ fold_builtin_atomic_compare_exchange
> (gimple_stmt_iterator *gsi)
>       }
>        else
>       gsi_insert_after (gsi, g, GSI_NEW_STMT);
> -      g = gimple_build_assign (oldlhs, NOP_EXPR, gimple_assign_lhs (g));
> +      if (TREE_CODE (TREE_TYPE (oldlhs)) == BOOLEAN_TYPE
> +       && INTEGRAL_TYPE_P (itype))
> +     g = gimple_build_assign (oldlhs, NE_EXPR, gimple_assign_lhs (g),
> +                              build_zero_cst (TREE_TYPE (gimple_assign_lhs 
> (g))));
> +      else
> +     g = gimple_build_assign (oldlhs, NOP_EXPR, gimple_assign_lhs (g));
>        gsi_insert_after (gsi, g, GSI_NEW_STMT);
>      }
>    g = gimple_build_assign (make_ssa_name (itype), REALPART_EXPR,

That looks like a pessimization instead of optimization, perhaps optimizers
then do a better job at that, but maybe in other cases don't.
Wouldn't it be better to look after building the NOP_EXPR at the immediate
uses of oldlhs and if any of them is oldlhs != 0 or oldlhs == 0 comparison,
forward propagate there immediately the rhs1 of the nop and adjust the other
operand?

Reply via email to