On Thu, Mar 16, 2023 at 02:11:01PM +0000, Richard Biener wrote:
> > Let's wait for Honzas opinion.
> 
> The following is what I profile-bootstrapped and tested on 
> x86_64-unknown-linux-gnu.
> 
> Richard.
> 
> >From d438a0d84cafced85c90204cba81de0f60ad0073 Mon Sep 17 00:00:00 2001
> From: Richard Biener <rguent...@suse.de>
> Date: Thu, 16 Mar 2023 13:51:19 +0100
> Subject: [PATCH] tree-optimization/106912 - clear const attribute from fntype
> To: gcc-patches@gcc.gnu.org
> 
> The following makes sure that after clearing pure/const from
> instrumented function declarations we are adjusting call statements
> fntype as well to handle indirect calls and because gimple_call_flags
> looks at both decl and fntype.
> 
> Like the pure/const flag clearing on decls we refrain from touching
> calls to known functions that do not have a body in the current TU.
> 
>       PR tree-optimization/106912
>       * tree-profile.cc (tree_profiling): Update stmts only when
>       profiling or testing coverage.  Make sure to update calls
>       fntype, stripping 'const' there.
> 
>       * gcc.dg/profile-generate-4.c: New testcase.

> +             if (fntype && TYPE_READONLY (fntype))
> +               gimple_call_set_fntype
> +                 (call, build_qualified_type (fntype, (TYPE_QUALS (fntype)
> +                                                       & ~TYPE_QUAL_CONST)));

I think
                if (fntype && TYPE_READONLY (fntype))
                  {
                    int quals = TYPE_QUALS (fntype) & ~TYPE_QUAL_CONST;
                    fntype = build_qualified_type (fntype, quals);
                    gimple_call_set_fntype (call, fntype);
                  }
would be nicer formatting for it.

Anyway, let's wait for Honza, LGTM.

> +
> +             /* Update virtual operands of calls to no longer const/pure
> +                functions.  */
> +             update_stmt (call);
> +           }
> +       }
>  
>        /* re-merge split blocks.  */
>        cleanup_tree_cfg ();

        Jakub

Reply via email to