<html>
    <head>
      <base href="https://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 --- - [aarch64][inline assembler] Clang should turn add into sub when necessary."
   href="https://llvm.org/bugs/show_bug.cgi?id=23575">23575</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>[aarch64][inline assembler] Clang should turn add into sub when necessary.
          </td>
        </tr>

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

        <tr>
          <th>Version</th>
          <td>3.6
          </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>-New Bugs
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>jacob.bramley@arm.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvmbugs@cs.uiuc.edu
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>(Using Clang 3.6 as packaged in Ubuntu 14.04.)

GNU as will assemble `add w0, w0, #-1` into `sub w0, w0, #1`. This feature is
very useful, and indeed it is the only reasonable use for the "J" constraint.

Here's a simple use-case:

----

int add(int a, int b) {
  int result;

  __asm__ __volatile__ (
    "add %w[result], %w[a], %w[b]\n\t"
    : [result]"=&r" (result), [a]"=r" (a)
    : [b]"IJr" (b)
  );

  return result;
}


int test(int a) {
  return add(a, -1);   // Should be inlined as `sub w0, w0, #1`.
}


----

test.cc:7:5: error: expected compatible register, symbol or integer in range
[0, 4095]
    "add %w[result], %w[a], %w[b]\n\t"
    ^
<inline asm>:1:14: note: instantiated into assembly here
        add w0, w8, #-1

----

We found this problem trying to compile Google V8 using Clang.

I think this is related to <a class="bz_bug_link 
          bz_status_NEW "
   title="NEW --- - [Inline ASM][AArch64] Integer exceeds imm range"
   href="show_bug.cgi?id=20456">bug 20456</a>, but it seems to be slightly different.</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>