It’s Not Always iCache
matklad.github.io
matklad.github.io
You can measure frontend stalls on many recent intel chips by
IDQ_UOPS_NOT_DELIVERED.CORE
https://perfmon-events.intel.com/
Neoverse N1 from Arm has STALL_FRONTEND; see
https://developer.arm.com/documentation/PJDOC-466751330-5476...
For frontend you can guess that PGO, BOLT, huge tables might probably help but it's still a blind guess without knowing what to look at next.
Intel's TMA is the only helpful thing here really. Bit sad that AMD and ARM don't provide a way to calculate something TMA-like themselves.
Because of branch prediction and deep instruction windows, the instruction prefetcher is significantly more effective than the data prefetcher.
There are of course second order effects of code bloat: L2 for example is typically shared with data and wasting more of it for code can have negative effects.
I could only find references to ICache or ICACHE via quick search.
This is a follow up to Inline in Rust[0] which was submitted a couple times earlier this week.
[0] https://matklad.github.io//2021/07/09/inline-in-rust.html
See https://github.com/gcc-mirror/gcc/blob/master/gcc/shrink-wra... or https://llvm.org/doxygen/ShrinkWrap_8cpp_source.html.
https://godbolt.org/z/rvx36sM74
What I would like to like is something like the generated call of `call_foo1` substituted verbatim into the generated code of `baz1` in the place of the function call. That way at the point of calling `bar` there is much less stack space allocated, minimizing stack usage.
But maybe this would pessimize other things, or for some weird reason is actually incorrect.
gcc at least deallocates the stack before tail-calling `baz`, I don't know if that is "shrink wrapping" or just plain TCO.
LLVM has bugs in this regard with calls to variadic calls, since after a certain number of arguments have been passed in registers, you start pushing parameters on the stack (ABI dependant).
The data shows that this is the other way around: inline_always executes 6,396,754,995 instr and inline_never 5,597,215,493 .