On Tue, Nov 21, 2023 at 10:46:13AM +0100, Sebastian Huber wrote:
> > > --- a/gcc/tree-profile.cc
> > > +++ b/gcc/tree-profile.cc
> > > @@ -284,7 +284,9 @@ gen_assign_counter_update (gimple_stmt_iterator *gsi, 
> > > gcall *call, tree 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, tmp);
> > > +      gassign *assign = gimple_build_assign (result,
> > > +                                      build_int_cst (TREE_TYPE (result),
> > > +                                                     tmp));
> > This can't be correct.
> > tmp is a SSA_NAME, so calling build_int_cst on it is not appropriate, the
> > second argument should be some unsigned HOST_WIDE_INT value.
> > If result_type is different type from TREE_TYPE (result), but both are
> > integer types, then you want
> >        gassign *assing = gimple_build_assign (result, NOP_EXPR, tmp);
> > or so.
> 
> I really don't know what I am doing here, so a lot of guess work is involved
> from my side. The change fixed at least the failing test case. When I use
> the NOP_EXPR
> 
> 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, if it is sometimes the types are compatible and sometimes they
are not but result never is_gimple_reg, perhaps
        gimple_set_lhs (call, tmp);
        gsi_insert_after (gsi, call, GSI_NEW_STMT);
        if (!useless_type_conversion_p (TREE_TYPE (result), result_type))
          {
            gassign *assign
              = gimple_build_assign (make_ssa_name (TREE_TYPE (result)),
                                     NOP_EXPR, tmp);
            gsi_insert_after (gsi, assign, GSI_NEW_STMT);
            tmp = gimple_assign_lhs (assign);
          }
        gassign *assign = gimple_build_assign (result, tmp);
        gsi_insert_after (gsi, assign, GSI_NEW_STMT);
etc.

        Jakub

Reply via email to