<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 - Issue with passing expression to inline assembly in Linux kernel"
   href="https://bugs.llvm.org/show_bug.cgi?id=51634">51634</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Issue with passing expression to inline assembly in Linux kernel
          </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>Windows NT
          </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>natechancellor@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org, nemanja.i.ibm@gmail.com
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=25195" name="attach_25195" title="Reduced program">attachment 25195</a> <a href="attachment.cgi?id=25195&action=edit" title="Reduced program">[details]</a></span>
Reduced program

Initial explanation of the issue by Michael Ellerman:
<a href="https://lore.kernel.org/r/87h7fcc2m4.fsf@mpe.ellerman.id.au/">https://lore.kernel.org/r/87h7fcc2m4.fsf@mpe.ellerman.id.au/</a>

clang does not emit a clrlwi instruction for the attached program, resulting in
incorrect behavior at runtime, as noted in the above post.

$ clang -O2 --target=powerpc64-linux-gnu -c -o warn_on.o warn_on.c

$ llvm-objdump -dr warn_on.o

warn_on.o:      file format elf64-powerpc

Disassembly of section .text:

0000000000000000 <.text>:
       0: f8 83 00 00   std 4, 0(3)
       4: 0b 04 00 00   tdnei   4, 0
       8: 4e 80 00 20   blr
       c: 4e 80 00 20   blr
                ...

Compared to GCC 11.2.0:

$ powerpc64-linux-gcc -O2 -c -o warn_on.o warn_on.c

$ llvm-objdump -dr warn_on.o

warn_on.o:      file format elf64-powerpc

Disassembly of section .text:

0000000000000000 <.text>:
       0: 54 89 07 fe   clrlwi  9, 4, 31
       4: f8 83 00 00   std 4, 0(3)
       8: 0b 09 00 00   tdnei   9, 0
       c: 4e 80 00 20   blr
                ...

Changing

"r"(knode_dead(knode))

to

"r"(!!knode_dead(knode)

does make clang emit the clrlwi instruction:

$ clang -O2 --target=powerpc64-linux-gnu -c -o warn_on.o warn_on.c

$ llvm-objdump -dr warn_on.o

warn_on.o:      file format elf64-powerpc

Disassembly of section .text:

0000000000000000 <.text>:
       0: 54 85 07 fe   clrlwi  5, 4, 31
       4: f8 83 00 00   std 4, 0(3)
       8: 0b 05 00 00   tdnei   5, 0
       c: 4e 80 00 20   blr
      10: 4e 80 00 20   blr
                ...

but that seems to be more of a workaround than addressing the root cause?</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>