<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </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 - InstCombine propagates values across omp barrier, after D75010"
   href="https://bugs.llvm.org/show_bug.cgi?id=45635">45635</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>InstCombine propagates values across omp barrier, after D75010
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>OpenMP
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>unspecified
          </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>Clang Compiler Support
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>chang-sun.lin.jr@intel.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=23394" name="attach_23394" title="test case">attachment 23394</a> <a href="attachment.cgi?id=23394&action=edit" title="test case">[details]</a></span>
test case

The attached test started giving different results @ O2, after commit
D75010/rG72b51d6f93b5. It has a code sequence like this:

  #pragma omp critical
  shared_var++; 
  #pragma omp barrier
  printf("expecting 2: %d\n", shared_var);

D75010 marks the kmpc_barrier function with inaccessiblemem_or_argmemonly,
which allows InstCombine to propagate the local thread's shared_var value
across the barrier, to the printf. The different threads print different values
of shared_var. The standard seems to say that barrier implies a flush of the
data visible to the thread, ensuring that all threads see the same view of
memory after the barrier.

Compiled with:
clang -fopenmp -O2 barrier.c
Expecting this output:

expecting 2: 2
expecting 2: 2

Got this output:

expecting 2: 2
expecting 2: 1</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>