<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 - callbr is not inlined"
   href="https://bugs.llvm.org/show_bug.cgi?id=40722">40722</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>callbr is not inlined
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libraries
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </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>Interprocedural Optimizations
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>ndesaulniers@google.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr>

        <tr>
          <th>Depends on</th>
          <td>9295
          </td>
        </tr>

        <tr>
          <th>Blocks</th>
          <td>4068
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=21475" name="attach_21475" title="test.c">attachment 21475</a> <a href="attachment.cgi?id=21475&action=edit" title="test.c">[details]</a></span>
test.c

The recently added callbr IR instruction for supporting asm goto currently is
not inlined.  The x86 Linux kernel currently makes use of code that requires
asm goto to be inline-able to be semantically valid.

Attached is a simple test case.  To observe the inlining occuring when
compiling with GCC and not with Clang:

$ clang -O2 -no-integrated-as test.c
$ gdb -batch -ex 'file a.out' -ex 'disassemble t32' -ex 'disassemble main'
$ gcc -O2 test.c
$ gdb -batch -ex 'file a.out' -ex 'disassemble t32' -ex 'disassemble main'

Will show that GCC is able in inline this construct.

Instrumenting
llvm/lib/Transforms/Utils/InlineFunction.cpp#llvm::InlineFunction() it seems
that the functions I expect to be evaluated for inlining are not even
considered.  It seems that checks for basic blocks having their address taken
are preventing code in llvm/lib/Analysis/InlineCost.cpp
(CallAnalyzer::analyzeCall() and llvm::isInlineViable()) from considering these
functions for inlining.

Simply removing these "early bailouts" allows my simple attached test case to
be inlined, compilation of my kernel translation units to proceed, but
eventually we crash in a later translation unit while performing loop rotation
(not sure if that's an unrelated bug, or my "patch" is not conservative
enough).  This crash is also observed when running the llvm-lit test
llvm/test/Transforms/Inline/blockaddress.ll.  Attached is my basic "early
bailouts" patch.</pre>
        </div>
      </p>

        <div id="referenced">
          <hr style="border: 1px dashed #969696">
          <b>Referenced Bugs:</b>
          <ul>
              <li>
                [<a class="bz_bug_link 
          bz_status_CONFIRMED "
   title="CONFIRMED - [Meta] Compiling the Linux kernel with clang"
   href="https://bugs.llvm.org/show_bug.cgi?id=4068">Bug 4068</a>] [Meta] Compiling the Linux kernel with clang
              </li>
              <li>
                [<a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - Support for "asm goto""
   href="https://bugs.llvm.org/show_bug.cgi?id=9295">Bug 9295</a>] Support for "asm goto"
              </li>
          </ul>
        </div>
        <br>

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

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