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.
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.
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.