How to avoid constant propagation into functions?

Georg-Johann Lay
Wed Dec 7 12:58:00 GMT 2016

On 07.12.2016 13:42, Segher Boessenkool wrote:
> On Wed, Dec 07, 2016 at 01:35:59PM +0100, Georg-Johann Lay wrote:
>>>> So the constant 317 made its way into the code of mod_mul (insn 14),
>>>> and insn 9 also uses this value.
>>> >From my understanding "noclone" should avoid any such propagations?
>>> noclone prevents cloning the function, and it indeed has not been cloned.
>>> Because the function is static, GCC knows all callers, and it determines
>>> all callers have n=317, so it optimises with that knowledge.
>> I understand this.  What I am after is a means to get a generated
>> code that matches the source, no matter what context.
> Don't make the function static, or preferable compile it completely
> separately (in its own translation unit), and make sure there is no LTO
> done on it either?
>> Imagine you called that function from assembler, then the code
>> would crash.
> You cannot (validly) call it from assembler code the way it is now, the
> function is local to its translation unit.

Ja, I'm aware of this.

I just wrote "imagine".  I'd like to have a means to avoid such
propagations, so that the would would work "even if" it was
called from a different context (like global asm in the same
modul).  Don't misinterpret this as if I'd intend to write
such code, I just tried to describe what I am trying to achieve
by means of noinline + noclone + some-magic-attribute

As I understand you, there is NO such way -- even though the docs
for noclone might lead to the (wrong) conclusion noclone would
avoid inter-procedural of constants or value-ranges.

>> And yes, when I am adding some other usage of
>> mod_mul or let escape its address, then the propagation is not
>> performed.
>> For example, this might have impact on writing test for GCC:
>> When I am writing a test with noinline + noclone then my
>> expectation is that no such propagation happens, because
>> otherwise a test might turn trivial...
> The usual ways to prevent that are to add some volatile, or an
> asm("" : "+g"(some_var));   etc.

Ja, I'm aware of this.

So the bottom line re $subject is:

"No, there is no general way on GCC to avoid inter-procedural constant
propagations for specific functions."



More information about the Gcc-help mailing list