[llvm-bugs] [Bug 37476] New: __builin_expect doesn't propagate through inlined functions

via llvm-bugs llvm-bugs at lists.llvm.org
Tue May 15 13:33:27 PDT 2018


https://bugs.llvm.org/show_bug.cgi?id=37476

            Bug ID: 37476
           Summary: __builin_expect doesn't propagate through inlined
                    functions
           Product: clang
           Version: 6.0
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: -New Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: redbeard0531 at gmail.com
                CC: llvm-bugs at lists.llvm.org

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): # @inline_func_hint(bool)
  test edi, edi
  je .LBB3_2
  jmp unlikely() # TAILCALL
.LBB3_2:
  jmp likely() # TAILCALL

GCC bug: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85799

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20180515/d5679293/attachment.html>


More information about the llvm-bugs mailing list