[llvm-bugs] [Bug 45854] New: code moved out of omp critical region

via llvm-bugs llvm-bugs at lists.llvm.org
Fri May 8 16:21:34 PDT 2020


https://bugs.llvm.org/show_bug.cgi?id=45854

            Bug ID: 45854
           Summary: code moved out of omp critical region
           Product: OpenMP
           Version: unspecified
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: Clang Compiler Support
          Assignee: unassignedclangbugs at nondot.org
          Reporter: michael.p.rice at intel.com
                CC: llvm-bugs at lists.llvm.org

After the recent changes to capture fewer globals this test started failing
possibly due to an optimization firing that wasn't before:

extern void omp_set_num_threads (int);
extern void omp_set_dynamic (int);
extern int omp_get_max_threads (void);

int     errors = 0;
int     thds;
int     shrd;

int main ()
{
  int i;
  omp_set_num_threads(2);
  thds = omp_get_max_threads();
  omp_set_dynamic(0);

  shrd = 0;
  #pragma omp parallel for default(shared) schedule(static)
  for (i=0; i<thds; i++) {
    #pragma omp critical
    shrd += 1;
  }
  if (shrd != thds) errors += 1;

  return errors;
}

It appears an optimization pass has moved some of the increment of 'shrd'
outside the critical region.

# %bb.2:                                # %omp.inner.for.body.preheader
        cmpl    %eax, %ebp
        cmovll  %eax, %ebp
        movl    .Lshrd$local(%rip), %ebx
        addl    $1, %ebx
        subl    %eax, %ebp
        addl    $1, %ebp
        .p2align        4, 0x90
.LBB1_3:                                # %omp.inner.for.body
                                        # =>This Inner Loop Header: Depth=1
        movl    $.L__unnamed_1, %edi
        movl    $.gomp_critical_user_.var, %edx
        movl    %r14d, %esi
        callq   __kmpc_critical
        movl    %ebx, .Lshrd$local(%rip)
        movl    $.L__unnamed_1, %edi
        movl    $.gomp_critical_user_.var, %edx
        movl    %r14d, %esi
        callq   __kmpc_end_critical
        addl    $1, %ebx
        addl    $-1, %ebp
        jne     .LBB1_3
.LBB1_4:                                # %omp.loop.exit


Also here:
https://godbolt.org/z/2YPJ4P

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20200508/163e6232/attachment.html>


More information about the llvm-bugs mailing list