<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/60911>60911</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [flang] [OpenMP] compilation failed with error "failed to legalize operation 'cf.br'"
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          k-arrows
      </td>
    </tr>
</table>

<pre>
    The test code is as follows: (reduced from omp-validation) (https://github.com/uhhpctools/omp-validation)
```console
$ cat test.f90
program test_omp_critical
  implicit none
  integer known_sum
  integer i,j,myi,myj,sum

  sum = 0
  myi = 0
  myj = 500

!$omp parallel
!$omp sections

!$omp section
  do i = 0 , 499
  !$omp critical
    sum = sum + myi
    myi = myi + 1
 !$omp end critical
  end do

!$omp section
  do j = 500 , 999
  !$omp critical
    sum = sum + myj
    myj = myj + 1
 !$omp end critical
  end do

!$omp end sections
!$omp end parallel

  known_sum = 999 * 1000 / 2
  if ( known_sum .eq. sum ) then
     write (*,*) "pass", sum, known_sum
  else
     write (*,*) "not pass", sum, known_sum
  end if
end program
```

Compiling and execution with gfortran succeeded.
```console
$ gfortran -fopenmp test.f90
$ ./a.out
 pass      499500      499500
```

Compiling with flang-new failed with error "failed to legalize operation 'cf.br'".
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJysVUuPszYU_TVmcxVkbkgyLFjMJMquahfdj4y5gPMZm9rmS6e_vrJDHs1U7aj9pCiGcx-cc_wS3qveENVs88Y2h0zMYbCu_rYSztmzzxrbftS_DgSBfABpWwLlQXjorNb27Nn6FRi-OGpnSS10zo5gx2n1XWjViqCsYVjFjCGEKWYzPDI89ioMc5NLOzI8zsMwyWCt9gyPn4oZPzD-yrb88pPWeKtpQbEEKUIil3cVv6CTs70TY0Lf7Ti9S6eCkkJfwgBqnLSSKoCxhm6gCdSTg2_Gns27n8fngGK4PzHcjx8q_cfnW9o12c8jsPUB-BUYP9QzcErAhvPHUoYFw9KOE0zCCa1JP-OeZLTE_33VEr1-pbWwfBcY7qGsqmvkXvJsy519GvEtkr8Hr0rSiG9QLKF7QzLtp6YRa-1XOd-sSayr_8r69Mj6tLA-_SDWMfY0F3-JPc3f0vG2rBKbqoqb4hUKnqQeAW-rrYu75SE9p9_yRVoFYSBz1wZnpwLFfIavDPfpPzbGSXjPEKOJcYni_vOyJu3pK62MDfCVdqYF1V3ekguXTfi0ex892dtxUlqZHoRpgX4nOUdP4azCAH1nXXDCgJ-lJGqpzf_tILiVrDo7kRmnp2Mh5uQMjyK3c1hoR2FJftwhcdk9PH-JeiLbaWH6laEzdEJpai8oOWdddHABgwVNvdDqDwI7kUsHHDDcyS5vHMMdQ8yztl631boSGdXFdrfj5bbcFdlQi5eqLBvi_GVDJNZF1zVFWciiFSU2RbXLVI0c1xwR-bYo1zynnVzjhoqXzVY0kjgrOY1C6Vzr72NuXZ8p72eqt7wqikyLhrRP1wBilJKCcdI3h8zVsWbVzL1nJdfKB3_vElTQ6f5INrDNAdjm7eeJzE-_xBeZvLqI_b_2ZLPT9T_cJJHTMqwmZ08kA8NjUhLvlqT0zwAAAP__-80Hww">