<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 --- - Combine consecutive fences & atomic-related optimisations"
   href="https://llvm.org/bugs/show_bug.cgi?id=31736">31736</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Combine consecutive fences & atomic-related optimisations
          </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>normal
          </td>
        </tr>

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

        <tr>
          <th>Component</th>
          <td>Scalar Optimizations
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>davide@freebsd.org
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>chandlerc@gmail.com, filcab@gmail.com, hboehm@google.com, llvm-bugs@lists.llvm.org, llvm-bugzilla@jfbastien.com, llvm-dev@redking.me.uk, simon.f.whittaker@gmail.com
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>The following function:

int tinkywinky(void) {
    __sync_synchronize();
      __sync_synchronize();__sync_synchronize();
      __sync_synchronize();__sync_synchronize();
      __sync_synchronize();__sync_synchronize();
      __sync_synchronize();__sync_synchronize();
      __sync_synchronize();__sync_synchronize();
      __sync_synchronize();__sync_synchronize();
      __sync_synchronize();__sync_synchronize();
      __sync_synchronize();
    return 15;
}

gets lowered into:

tinkywinky():                        # @tinkywinky()
        mfence
        mfence
        mfence
        mfence
        mfence
        mfence
        mfence
        mfence
        mfence
        mfence
        mfence
        mfence
        mfence
        mfence
        mfence
        mfence
        mov     eax, 15
        ret

by clang-3.9

and 

tinkywinky():
        mfence
        mov     eax, 15
        mfence
        mfence
        mfence
        mfence
        mfence
        mfence
        mfence
        mfence
        mfence
        mfence
        mfence
        mfence
        mfence
        mfence
        mfence
        ret

by gcc-6.3 (interesting the different position of the `mov` in the final
relocatable.

This is because InstCombine/InstSimplify/* don't combine adjacent fences. The
real question here is if it's legal to do this (i.e. has no obvservable
behaviour). I had a quick chat about this with Chandler yesterday night and he
asked to open a bug & cc: some people so we can all discuss about this).

Probably it's worth starting a discussion in the standard (if there's not
already one) about the guarantees provided in this case (if any).</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>