Skip to content

Comment on When static makes your C code 10 times fasterparent

Comments

Yes, see last few paragraphs of the post, in which I also speculate why GCC doesn't infer that there is only one compilation unit.

How could it ever infer it, given C's compilation model?

The only option is when all TU are given at the same time to the compiler, or when LTO is used (in which case it is actually the linker doing the work).

Even then, this won't apply to libraries.

The only option is when all TU are given at the same time to the compiler

Exactly -- which is the case here. But implementing such a cross cutting implementation would probably be annoying, which is what I wanted to convey with

I think they could concievably assume that the value of modulus won’t be changed in this case, since we’re producing an executable directly, but it’s probably annoying to have an optimization looking so far into the future of the compiler pipeline.
AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.