On Fri, 17 Mar 2023, Jakub Jelinek wrote: > On Fri, Mar 17, 2023 at 08:40:34PM +0100, Jan Hubicka wrote: > > > + /* Drop the const attribute from the call type (the pure > > > + attribute is not available on types). */ > > > + tree fntype = gimple_call_fntype (call); > > > + if (fntype && TYPE_READONLY (fntype)) > > > + gimple_call_set_fntype > > > + (call, build_qualified_type (fntype, (TYPE_QUALS (fntype) > > > + & ~TYPE_QUAL_CONST))); > > > > Sorry, now I am bit confused on why Jakub's fix did not need similar > > fixup. The flag is only set during the profiling stage and thus I would > > expect it to still run into the problem that VOPs are missing. > > Is it only becuase we do not sanity check? > > My patch started from this point ignoring all TYPE_READONLY bits on > all FUNCTION_TYPE/METHOD_TYPEs, while Richi's patch instead makes it > explicit in the IL, TYPE_READONLY is honored as before but it shouldn't > show up in any of the gimple_call_fntype types unless it is a direct > call to a const function for which we don't have a body. > > In either case, vops are added on the update_stmt a few lines later. > > > Here is a testcase that shows the problem: > > > > include <math.h> > > float c; > > > > __attribute__ ((const)) > > float > > instrument(float v) > > { > > return sin (v); > > } > > __attribute__ ((no_profile_instrument_function,const,noinline)) > > float noinstrument (float v) > > { > > return instrument (v); > > } > > > > m() > > { > > c+=instrument(c); > > if (!__builtin_expect (c,1)) > > { > > c+=noinstrument (c); > > } > > c+=instrument(c); > > } > > main() > > { > > m(); > > } > > > > Compiling > > gcc -O0 t.c -fprofile-arcs -fno-early-inlining --coverage -lm > > -ftest-coverage -S ; gcc t.s -ftest-coverage -lm -fprofile-arcs > > makes gcov to report 3 executions on instrument while with -O3 it is 2.
With my proposed patch it works fine and reports 3 executions on 'instrument' with both -O0 and -O3. I checked it indeed reports only 2 executions with GCC 12. So it seems the patch is a progression in general? Thus, OK? Thanks, Richard.