by uyt · 4y ago · 0 comments
I've never messed with calling convention for the sake of performance before so I found this bit interesting. I found more info about it at: https://en.wikipedia.org/wiki/X86_calling_conventions#Borlan...
Does anyone have benchmarks? Assuming I don't care about ABI stability, what's the fastest calling convention?
I'd assume a modern optimizing compiler will, in situations where it's permitted, create completely novel calling conventions depending on the situation. Whole program optimization is one area you might see this.
Whole program optimization gives the compiler some ways around that. I am not sure how much freedom it gives the compiler.
Here is GCC doing that optimization for a static noinline function: https://godbolt.org/z/cn6Wz9Kvn
Similarly, compilers can also clone functions if it makes sense to propagate constants from call sites into the function. Example: https://godbolt.org/z/59z6xT75n
I'm sure there is more room for improvement. A perfect compiler would always optimized programs as a whole and only regard function boundaries as hints at best. In practice, you have to keep complexity in check somehow.