<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 --- - Code generation for __atomic_and_fetch() contains duplicates"
   href="https://llvm.org/bugs/show_bug.cgi?id=30621">30621</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Code generation for __atomic_and_fetch() contains duplicates
          </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>Yunzhong_Gao@playstation.sony.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>I was testing with trunk r283366.

Here is the test program (atomic.c)
short test(short *ptr, short val, int model) {
  return __atomic_and_fetch(ptr, val, model);
}

=========================================
Here is the code generated by GCC 4.8.4
test:
    movzwl    (%rdi), %eax
    movzwl    %si, %esi
.L2:
    movl    %eax, %edx
    andl    %esi, %edx
    lock cmpxchgw    %dx, (%rdi)
    jne    .L2
    movl  %edx, %eax
    ret

=========================================
Here is the code generated by clang:
test:                                   # @test
    decl    %edx
    cmpl    $4, %edx
    ja    .LBB0_2
    jmpq    *.LJTI0_0(,%rdx,8)
.LBB0_4:                                # %acquire
    movw    (%rdi), %ax
    .p2align    4, 0x90
.LBB0_5:                                # %atomicrmw.start6
                                        # =>This Inner Loop Header: Depth=1
    movl    %eax, %ecx
    andl    %esi, %ecx
                                        # kill: %AX<def> %AX<kill> %EAX<kill>
    lock    cmpxchgw    %cx, (%rdi)
                                        # kill: %AX<def> %AX<kill> %EAX<def>
    jne    .LBB0_5
    jmp    .LBB0_12
.LBB0_2:                                # %monotonic
    movw    (%rdi), %ax
    .p2align    4, 0x90
.LBB0_3:                                # %atomicrmw.start
                                        # =>This Inner Loop Header: Depth=1
    movl    %eax, %ecx
    andl    %esi, %ecx
                                        # kill: %AX<def> %AX<kill> %EAX<kill>
    lock    cmpxchgw    %cx, (%rdi)
                                        # kill: %AX<def> %AX<kill> %EAX<def>
    jne    .LBB0_3
    jmp    .LBB0_12
.LBB0_6:                                # %release
    movw    (%rdi), %ax
    .p2align    4, 0x90
.LBB0_7:                                # %atomicrmw.start12
                                        # =>This Inner Loop Header: Depth=1
    movl    %eax, %ecx
    andl    %esi, %ecx
                                        # kill: %AX<def> %AX<kill> %EAX<kill>
    lock    cmpxchgw    %cx, (%rdi)
                                        # kill: %AX<def> %AX<kill> %EAX<def>
    jne    .LBB0_7
    jmp    .LBB0_12
.LBB0_8:                                # %acqrel
    movw    (%rdi), %ax
    .p2align    4, 0x90
.LBB0_9:                                # %atomicrmw.start18
                                        # =>This Inner Loop Header: Depth=1
    movl    %eax, %ecx
    andl    %esi, %ecx
                                        # kill: %AX<def> %AX<kill> %EAX<kill>
    lock    cmpxchgw    %cx, (%rdi)
                                        # kill: %AX<def> %AX<kill> %EAX<def>
    jne    .LBB0_9
    jmp    .LBB0_12
.LBB0_10:                               # %seqcst
    movw    (%rdi), %ax
    .p2align    4, 0x90
.LBB0_11:                               # %atomicrmw.start24
                                        # =>This Inner Loop Header: Depth=1
    movl    %eax, %ecx
    andl    %esi, %ecx
                                        # kill: %AX<def> %AX<kill> %EAX<kill>
    lock    cmpxchgw    %cx, (%rdi)
                                        # kill: %AX<def> %AX<kill> %EAX<def>
    jne    .LBB0_11
.LBB0_12:                               # %atomic.continue
    andl    %esi, %eax
    retq


It looks to me that many of these loop bodies are identical and can
be merged? For example, the .LBB0_5 block, the .LBB0_3 block, the
.LBB0_7 block, the .LBB0_9 block and the .LBB0_11 block.

Using a size optimization switch like -Os or -Oz does not seem to help.</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>