On Wed, Jul 31, 2024 at 8:12 PM Ilija Tovilo via Gcc <gcc@gcc.gnu.org> wrote: > > Hi everyone > > I'm new here. I read the mailing list policy, but please correct me if > I'm doing anything wrong. > > In our C codebase, we're using a fair amount of static inline > __attribute__((always_inline)). This is arguably not a great decision, > because it forces inlining under questionable conditions, i.e. in cold > functions and unlikely branches. We're looking into switching some > non-trivial functions to extern inline instead. > > When testing I noticed that GCC avoids inlining in > __attribute__((cold)) functions, but not in unlikely branches, as > signaled by __builtin_expect(cond, 0), even if the caller is hot. See > https://godbolt.org/z/sxnYh5PsE. The unlikely branch is moved to the > bottom, but it still seems beneficial to avoid inlining to reduce > instruction cache pressure for the rest of the hot functions. I wasn't > able to achieve this behavior with __builtin_expect or > __builtin_expect_with_probability with a very high probability. > > Coincidentally, Clang does the exact opposite, inlining in cold > functions, but not in unlikely branches. > > This is just one example, and I don't know anything about the > heuristics GCC uses to determine if some function is inlined. I wanted > to bring this up nonetheless to see if this situation may be improved. > > I wasn't sure if this belongs in the bug tracker, let me know if I > should move it there instead.
Please file a bugreport with a testcase, the outcome and your expectation. Thanks, Richard. > Thank you. > > Ilija