https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117650
Bug ID: 117650 Summary: __glibcxx_assert_fail should be marked __attribute__((cold)) Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: libstdc++ Assignee: unassigned at gcc dot gnu.org Reporter: redbeard0531 at gmail dot com Target Milestone: --- The cold attribute marks incoming edges much more strongly cold than __builtin_expect (which IIRC currently assumes only a 90/10 bias). It even appears to be stronger than __builtin_expect_with_probability when passed 0/100, and is treated closer to how a thrown exception is, eg by splitting the function into hot and cold parts, so that the cold part doesn't waste icache and iTLB space that could go to another function. Since __glibcxx_assert_fail should be even less frequent than a thrown exception (ideally never, if software didn't have all those pesky bugs...), it should be optimized against at least as strongly. https://godbolt.org/z/svjPzrf5z Shows the impact on codegen by making __GLIBCXX_NORETURN imply cold in addition to noreturn. This seemed like the easiest way to demonstrate this. It also might be worth considering since noreturn functions tend to be cold ones. We have noreturn imply cold in our codebase, FWIW. PS- ABI concerns may make it too late to change this, but it may also be worth considering having the fail function take a single pointer to a statically allocated struct with all of the arguments, rather than generating them as separate arguments. As you can see, there are 4 instructions filling in the arguments where it could just be 1. Ideally there would be some way to encode the string addresses such that they don't need runtime relocations at startup, eg, by encoding them as the offset from the static struct pointer to the string, then decoding them only in the fail function.