<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - __builin_expect doesn't propagate through inlined functions"
   href="https://bugs.llvm.org/show_bug.cgi?id=37476">37476</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>__builin_expect doesn't propagate through inlined functions
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>6.0
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>-New Bugs
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>redbeard0531@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>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 <a href="https://godbolt.org/g/MuPM77">https://godbolt.org/g/MuPM77</a> 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: <a href="https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85799">https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85799</a></pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>