Function() vs Speed

For a simple ISR it is. Take a look here:

For an SPI interrupt it saves and restores 7 registers (not all of them).

But once an ISR calls another function which might call another function it bails out and saves the lot. There is a limit to what the compiler might deduce might happen if function A calls function B which might call function C and so on.

So it's smart. But there gets to be a point where the problem is too undefined to be certain. Like, for example, if an ISR had an "if" in it. Where if the "if" was true it called a function otherwise not.

  1. Is the compiler sophisticated enough to only push/pop the required registers

I believe it is, again bearing in mind the above. A simple function, where it can see what the function does, almost certainly will have limited pushing/popping. But with ifs and branches and sub-function calls it can't be too certain. However from what I am seeing it is probably making some running assumptions. So for example, each function only has to push/pop what it knows it uses.