<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 - Parallelism breaks alias analysis assumptions"
   href="https://bugs.llvm.org/show_bug.cgi?id=41781">41781</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Parallelism breaks alias analysis assumptions
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>new-bugs
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>6.0
          </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>enhancement
          </td>
        </tr>

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

        <tr>
          <th>Component</th>
          <td>new bugs
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>jdoerfert@anl.gov
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>htmldeveloper@gmail.com, llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=21902" name="attach_21902" title="7 test cases to check various alterations of the same concurrent access scenario">attachment 21902</a> <a href="attachment.cgi?id=21902&action=edit" title="7 test cases to check various alterations of the same concurrent access scenario">[details]</a></span>
7 test cases to check various alterations of the same concurrent access
scenario

Parallelism, regardless of the source, breaks with assumptions various parts of
the alias analyses have wrt. the invariance of memory.

In a nutshell, the problem is that parallel executing threads can synchronize,
e.g., through barriers, atomics, etc., which causes memory state to
"conceptually change", even if the memory is inaccessible to the synchronizing
event.

As an example, take the code below (also test 6 in the attached file). It shows
how a static global variable G1, which doesn't have its address taken*, can
change its value at a synchronization point without it being a race. This is
problematic because from a "sequential execution standpoint" the value of the
global cannot change. Though, because multiple threads execute the same code
concurrently, it can.

*So all uses of G6 are shown below.

---------------------------------------------------------

static int G6 = -1;

void test_6(void) {
#pragma omp parallel num_threads(2)
  {
    int tid = omp_get_thread_num();

                  // G6 = -1

    if (tid == 0)
      G6 = 0;

    barrier();    // G6 = 0

    if (tid == 1)
      G6 = 1;

    barrier();    // G6 = 1

    if (tid == 0)
      print(G6);  // expected: 1, got 0
  }
}


---------------------------------------------------------


I attached 7 individual tests out of which clang fails the last three. (gcc
only fails the last, which is the one shown above.) However, the others only
"pass" because of the inability of the GlobalsModRef analysis to distinguish
accesses with a constant offset into a constant size internal array, something
we could reasonably add at any point in time.

The tests use OpenMP but there should not be a difference even if the source of
parallelism is pthreads, CUDA, OpenCL, ...

The only solution we came up with so far is to make the alias analysis aware
that "potentially synchronizing" instructions affect everything except
identified local objects that haven't escaped yet. 

(Given that there are also other reasons to derive "no-synchronize" as an
attribute, we will now look into that now and start a discussion on potential
fixes for this problem.)</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>