This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: How to avoid constant propagation into functions?


* Alexander Monakov:

> On Fri, 9 Dec 2016, Richard Biener wrote:
>> Right, 'used' thwarts IPA on the callee side only.  noclone and noinline are
>> attributes affecting the caller side but we indeed miss attributes for the
>> properties you mention above.  I suppose adding a catch-all attribute for
>> caller side effects (like we have 'used' for the callee side) would be a good
>> idea.
>
> For general uses, i.e. for testcases that ought to be portable
> across different compilers, I believe making a call through a
> volatile pointer already places a sufficient compiler barrier to
> prevent both caller- and callee-side analysis.  That is, where you
> have
>
>   int foo(int);
>   foo(arg);
>
> you could transform it to
>
>   int foo(int);
>   int (* volatile vpfoo)(int) = foo;
>   vpfoo(arg);
>
> While this also has an effect of forcing the call to be indirect, I think
> usually that should be acceptable.

It does not force the call to be indirect.  The compiler can look at
the function pointer, check that it is equal to foo, and call it using
a direct call.

With whole-program optimization, the compiler could even assume that
if it has only one function definition with the right prototype, only
that function can be called, and eliminate the check altogether.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]