On Tue, Nov 21, 2023 at 11:07:47AM +0100, Jakub Jelinek wrote:
> > static inline void
> > gen_assign_counter_update (gimple_stmt_iterator *gsi, gcall *call, tree
> > func,
> >                        tree result, const char *name)
> > {
> >   if (result)
> >     {
> >       tree result_type = TREE_TYPE (TREE_TYPE (func));
> >       tree tmp = make_temp_ssa_name (result_type, NULL, name);
> >       gimple_set_lhs (call, tmp);
> >       gsi_insert_after (gsi, call, GSI_NEW_STMT);
> >       gassign *assign = gimple_build_assign (result, NOP_EXPR, tmp);
> >       gsi_insert_after (gsi, assign, GSI_NEW_STMT);
> 
> Ah, sure, if result is not is_gimple_reg, then one can't use a cast into
> that directly, needs to use another statement, one for the cast, one for the
> store.
> If you know the types are never compatible and result is never is_gimple_reg,
> then
>         gimple_set_lhs (call, tmp);
>         gsi_insert_after (gsi, call, GSI_NEW_STMT);
>         gassign *assign
>         = gimple_build_assign (make_ssa_name (TREE_TYPE (result)),
>                                NOP_EXPR, tmp);
>         gsi_insert_after (gsi, assign, GSI_NEW_STMT);
>       assign = gimple_build_assign (result, gimple_assign_lhs (assign));
>         gsi_insert_after (gsi, assign, GSI_NEW_STMT);
> would do it

And to answer my own question, seems if result is non-NULL, then it always
has incompatible type and always is ARRAY_REF, i.e. not is_gimple_reg,
because it will have get_gcov_type () which is a signed type and the call
in this case __sync_add_fetch_{4,8} which is unsigned 32-bit or 64-bit
type.  So I'd go with the above.
Another formatting nit:
      tree f = builtin_decl_explicit (TYPE_PRECISION (type) > 32
                                      ? BUILT_IN_ATOMIC_ADD_FETCH_8:
                                      BUILT_IN_ATOMIC_ADD_FETCH_4);
should have been
      tree f = builtin_decl_explicit (TYPE_PRECISION (type) > 32
                                      ? BUILT_IN_ATOMIC_ADD_FETCH_8
                                      : BUILT_IN_ATOMIC_ADD_FETCH_4);
The : shouldn't be at the end of line and there should be space.

        Jakub

Reply via email to