This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug middle-end/35196] New: [4.3 Regression] lastprivate broken for static non-ordered loops


extern void abort (void);
extern void omp_set_dynamic (int);

int
main (void)
{
  int i, j;
  omp_set_dynamic (0);
#pragma omp parallel for lastprivate (i, j) num_threads (8)
  for (i = 0; i < 5; i++)
    j = i;
  if (i != 5 || j != 4)
    abort ();
  return 0;
}

fails with -fopenmp since
http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=128223
sporadically.  If some thread is assigned no iterations of the loop and is
scheduled after the thread which invokes last iteration, lastprivate vars other
than the loop counter will have wrong values.

Before that commit we ompexped:
  i = 0;
  D.1566 = __builtin_omp_get_num_threads ();
  D.1567 = __builtin_omp_get_thread_num ();
  D.1568 = 5 / D.1566;
  D.1569 = D.1568 * D.1566;
  D.1570 = D.1569 != 5;
  D.1571 = D.1568 + D.1570;
  D.1572 = D.1571 * D.1567;
  D.1573 = D.1572 + D.1571;
  D.1574 = MIN_EXPR <D.1573, 5>;
  if (D.1572 >= D.1574)
    goto <bb 3>;
  else
    goto <bb 6>;

<bb 3>:
  if (i == 5)
    goto <bb 5>;
  else
    goto <bb 4>;

<bb 4>:
  return;

<bb 5>:
  .omp_data_i->i = i;
  .omp_data_i->j = j;
  goto <bb 4>;

<bb 6>:
  D.1575 = D.1572 * 1;
  i = D.1575 + 0;
  D.1576 = D.1574 * 1;
  D.1577 = D.1576 + 0;

<bb 7>:
  j = i;
  i = i + 1;
  D.1578 = i < D.1577;
  if (D.1578)
    goto <bb 7>;
  else
    goto <bb 3>;

i.e. if no iterations are given to the thread, the counter will have a value
different from the final value.
After the commit we have:
  i = 0;
  D.1576 = __builtin_omp_get_num_threads ();
  D.1577 = __builtin_omp_get_thread_num ();
  D.1578 = 5 / D.1576;
  D.1579 = D.1578 * D.1576;
  D.1580 = D.1579 != 5;
  D.1581 = D.1580 + D.1578;
  D.1582 = D.1581 * D.1577;
  D.1583 = D.1582 + D.1581;
  D.1584 = MIN_EXPR <D.1583, 5>;
  i = D.1582;
  if (D.1582 >= D.1584)
    goto <bb 4>;
  else
    goto <bb 3>;

<bb 3>:
  j = i;
  i = i + 1;
  if (i < D.1584)
    goto <bb 3>;
  else
    goto <bb 4>;

<bb 4>:
  if (i == 5)
    goto <bb 6>;
  else
    goto <bb 5>;

<bb 5>:
  return;

<bb 6>:
  .omp_data_i->i = i;
  .omp_data_i->j = j;
  goto <bb 5>;

where the iteration var is set already right after MIN_EXPR, rather than only
if some iterations were given to the thread.


-- 
           Summary: [4.3 Regression] lastprivate broken for static non-
                    ordered loops
           Product: gcc
           Version: 4.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: jakub at gcc dot gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35196


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]