https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85799
Bug ID: 85799 Summary: __builin_expect doesn't propagate through inlined functions Product: gcc Version: 8.1.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: redbeard0531 at gmail dot com Target Milestone: --- It seems like __builtin_expect doesn't propagate to conditions when inlined. This is unfortunate because in some cases it would be nice to be able to put the expectation into methods so that every user doesn't need to do their own hinting. Currently we need to use macros to achieve this. See https://godbolt.org/g/MuPM77 for full example inline bool expect_false(bool b) { return __builtin_expect(b, false); } void inline_func_hint(bool b) { if (expect_false(b)) { unlikely(); // treated as more likely!!! } else { likely(); } } inline_func_hint(bool): test dil, dil je .L11 jmp unlikely() .L11: jmp likely()