<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 - unexpected codegen for inline asm"
   href="https://bugs.llvm.org/show_bug.cgi?id=42762">42762</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>unexpected codegen for inline asm
          </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>Backend: PowerPC
          </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>hfinkel@anl.gov, kit.barton@gmail.com, llvm-bugs@lists.llvm.org, nemanja.i.ibm@gmail.com
          </td>
        </tr>

        <tr>
          <th>Blocks</th>
          <td>4068
          </td>
        </tr></table>
      <p>
        <div>
        <pre>The powerpc (32b) Linux kernel started panicing at runtime recently when built
with LLVM due to a change in the kernel sources.  We narrowed it down to
commit, and a single call site of a static inline function containing extended
inline assembly with constraints.

I think this concise test case distills this issue:
<a href="https://godbolt.org/z/E4f1Us">https://godbolt.org/z/E4f1Us</a>

Basically, we had:

// from arch/powerpc/include/asm/cache.h
// pre-commit 6c5875843b87 ("powerpc: slightly improve cache helpers")
void dcbz_old(void* addr)
{
    asm volatile ("dcbz 0, %0" : : "r"(addr) : "memory");
}

then moved to:

// from arch/powerpc/include/asm/cache.h
// post-commit 6c5875843b87 ("powerpc: slightly improve cache helpers")
void dcbz_current(void* addr)
{
    asm volatile ("dcbz %y0" :: "Z"(*(unsigned char*)addr) : "memory");
}

It seems that GCC generates the same code for both cases, and LLVM matches GCC
for the first case.  In the second case, the codegen is wildly different, which
seems like what's leading to our panic at runtime.

I'm not super familiar with the "Z" constraint and "%y" output format, but they
might be related?</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>
          </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>