Am 27.07.23 um 15:43 schrieb Michael Matz:

I've recently submitted a patch that adds some attributes that basically
say "these-and-those regs aren't clobbered by this function" (I did them
for not clobbered xmm8-15).  Something similar could be used for the new
GPRs as well.  Then it would be a matter of ensuring that the interesting
functions are marked with that attributes (and then of course do the
necessary call-save/restore).

Interesting.

Taking this a bit further: The compiler knows which registers it used
(and which ones might get clobbered by called functions) and could
generate such information automatically and embed it in the assembly
file, and the assembler could, in turn, put it into the object file.

A linker (or LTO) could then check this and elide save/restore pairs
where they are not needed.

Now, I know that removing instructions during linking is a dangerous
business, and is a source of hard-to-find and rare bugs (the worst kind)
if not done right; a bullet-proof algorithm would be needed for that.

It would probably be impossible for calls into shared libraries, since
the saved registers might change from version to version.  It also would
probably not work for virtual member functions which are not found by
devirtualitzation.

Still, potential gains could be substantial, and it could have an
effect which could come close to inlining, while actually saving space
instead of using extra.

Comments?

Reply via email to