<html>
    <head>
      <base href="http://llvm.org/bugs/" />
    </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 --- - Inline asm constraint alternatives ignored"
   href="http://llvm.org/bugs/show_bug.cgi?id=20197">20197</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Inline asm constraint alternatives ignored
          </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>normal
          </td>
        </tr>

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

        <tr>
          <th>Component</th>
          <td>Common Code Generator Code
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>benny.kra@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>echristo@gmail.com, llvmbugs@cs.uiuc.edu
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>When multiple alternatives in an inline asm constraint are given we ignore all
of them but the most "general". This gives nasty artifacts in the code.

int bsr(unsigned v) {
  int ret;
  __asm__("bsr %1, %0" : "=&r"(ret) : "rm"(v) : "cc");
  return ret;
}

$ clang -O3 -S -o - t.c
bsr:
    movl    %edi, -4(%rsp)
    #APP
    bsrl    -4(%rsp), %eax
    #NO_APP
    retq

The spilling is totally unnecessary. GCC gets this one right. On 32 bit x86
it's even worse:

$ clang -O3 -S -o - t.c -m32
bsr:
    pushl    %eax
    movl    8(%esp), %eax
    movl    %eax, (%esp)
    #APP
    bsrl    (%esp), %eax
    #NO_APP
    popl    %edx
    retl

GCC knows a better way:
$ gcc-4.8 -O3 -S -o - t.c -m32
bsr:
#APP
    bsr 4(%esp), %eax
#NO_APP
    ret

The constraint "g" is just as bad, being translated into "imr" internally.</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>