Open llvmbot opened 5 years ago
Oh yes. I was wrong. Only if we can omit the ret and just branch to the other function.
Okay, for a tail-call, placing the callee immediately after the caller could have a benefit from icache etc. Thanks for clarifying!
The other case is what I was talking about with memmove----you can have a function wrap another function (or multiple), if the calls look like this
return call();
Oh yes. I was wrong. Only if we can omit the ret and just branch to the other function.
If a function is only called by a single other function in the same shared library, it should always be after the function that calls it.
Sorry, not following why this would be universally true, which is what you seem to be suggesting.
For a target with a big enough icache and small enough functions, I could see the icache hit being a win; but this varies depending on the target and the size of the functions.
I can see avoiding a TLB miss by putting the functions on the same memory page, but that requires only being on the same page, not relative order.
Can you explain the thinking behind "it should always be after" the caller? Thanks!
Extended Description
I am reporting this here so that I might get some technical feed-back on how this will interact with ldd.
There are many cases where function can be optimized by ordering them in a specific way. If a function is only called by a single other function in the same shared library, it should always be after the function that calls it.
There are fancier optimizations possible too, such as having memmove be both before and after memcpy, split on the branch, or jumping into the middle of a function when they do identical calculations (the function merger could probably be adapted to help with this), but this bug is only for simple re-ordering (more bugs can be opened when this is fixed).