<html>
    <head>
      <base href="https://llvm.org/bugs/" />
    </head>
    <body><span class="vcard"><a class="email" href="mailto:echristo@gmail.com" title="Eric Christopher <echristo@gmail.com>"> <span class="fn">Eric Christopher</span></a>
</span> changed
              <a class="bz_bug_link 
          bz_status_RESOLVED  bz_closed"
   title="RESOLVED WORKSFORME - 65536 out of the range of constraint 'I'"
   href="https://llvm.org/bugs/show_bug.cgi?id=26874">bug 26874</a>
        <br>
             <table border="1" cellspacing="0" cellpadding="8">
          <tr>
            <th>What</th>
            <th>Removed</th>
            <th>Added</th>
          </tr>

         <tr>
           <td style="text-align:right;">Status</td>
           <td>NEW
           </td>
           <td>RESOLVED
           </td>
         </tr>

         <tr>
           <td style="text-align:right;">CC</td>
           <td>
                
           </td>
           <td>echristo@gmail.com
           </td>
         </tr>

         <tr>
           <td style="text-align:right;">Resolution</td>
           <td>---
           </td>
           <td>WORKSFORME
           </td>
         </tr></table>
      <p>
        <div>
            <b><a class="bz_bug_link 
          bz_status_RESOLVED  bz_closed"
   title="RESOLVED WORKSFORME - 65536 out of the range of constraint 'I'"
   href="https://llvm.org/bugs/show_bug.cgi?id=26874#c2">Comment # 2</a>
              on <a class="bz_bug_link 
          bz_status_RESOLVED  bz_closed"
   title="RESOLVED WORKSFORME - 65536 out of the range of constraint 'I'"
   href="https://llvm.org/bugs/show_bug.cgi?id=26874">bug 26874</a>
              from <span class="vcard"><a class="email" href="mailto:echristo@gmail.com" title="Eric Christopher <echristo@gmail.com>"> <span class="fn">Eric Christopher</span></a>
</span></b>
        <pre>With the testcase I've created from your report and current ToT it works for
me:

dzur:~/tmp> ~/builds/build-llvm/bin/clang -target aarch64-linux-gnu -S foo.c
-O0 -o -
    .text
    .file    "foo.c"
    .globl    arch_spin_trylock
    .p2align    2
    .type    arch_spin_trylock,@function
arch_spin_trylock:                      // @arch_spin_trylock
// BB#0:                                // %entry
    sub    sp, sp, #16             // =16
    str    x0, [sp, #8]
    ldr    x0, [sp, #8]
    //APP
.Ltmp1:
    ldaxr    w8, [x0]
    eor    w9, w8, w8, ror #16
    cbnz    w9, .Ltmp2
    add    w8, w8, #16, lsl #12    // =65536
    stxr    w9, w8, [x0]
    cbnz    w9, .Ltmp1
.Ltmp2:
    //NO_APP
    str        w8, [sp]
    str    w9, [sp, #4]
    ldr    w8, [sp, #4]
    cmp        w8, #0          // =0
    cset     w8, ne
    eor    w8, w8, #0x1
    and    w0, w8, #0x1
    add    sp, sp, #16             // =16
    ret
.Lfunc_end0:
    .size    arch_spin_trylock, .Lfunc_end0-arch_spin_trylock


    .ident    "clang version 3.9.0 (trunk 262996) (llvm/trunk 262998)"
    .section    ".note.GNU-stack","",@progbits
dzur:~/tmp> ~/builds/build-llvm/bin/clang -target aarch64-linux-gnu -S foo.c
-O3 -o -
    .text
    .file    "foo.c"
    .globl    arch_spin_trylock
    .p2align    2
    .type    arch_spin_trylock,@function
arch_spin_trylock:                      // @arch_spin_trylock
// BB#0:                                // %entry
    sub    sp, sp, #16             // =16
    //APP
.Ltmp1:
    ldaxr    w8, [x0]
    eor    w9, w8, w8, ror #16
    cbnz    w9, .Ltmp2
    add    w8, w8, #16, lsl #12    // =65536
    stxr    w9, w8, [x0]
    cbnz    w9, .Ltmp1
.Ltmp2:
    //NO_APP
    cmp        w9, #0          // =0
    cset     w0, eq
    str    w8, [sp, #8]
    add    sp, sp, #16             // =16
    ret
.Lfunc_end0:
    .size    arch_spin_trylock, .Lfunc_end0-arch_spin_trylock


    .ident    "clang version 3.9.0 (trunk 262996) (llvm/trunk 262998)"
    .section    ".note.GNU-stack","",@progbits
dzur:~/tmp> cat foo.c
#include <inttypes.h>

#define TICKET_SHIFT 16

typedef struct {
  uint16_t owner;
  uint16_t next;
} __attribute__((aligned(4))) arch_spinlock_t;

int arch_spin_trylock(arch_spinlock_t *lock) {
  unsigned int tmp;
  arch_spinlock_t lockval;

  asm volatile(
      "1:     ldaxr   %w0, %2\n"
      "       eor     %w1, %w0, %w0, ror #16\n"
      "       cbnz    %w1, 2f\n"
      "       add     %w0, %w0, %3\n"
      "       stxr    %w1, %w0, %2\n"
      "       cbnz    %w1, 1b\n"
      "2:"
      : "=&r"(lockval), "=&r"(tmp), "+Q"(*lock)
      : "I"(1 << TICKET_SHIFT)
      : "memory");

  return !tmp;
}</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>