https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65443

--- Comment #1 from vries at gcc dot gnu.org ---
Consider test.c, compiled with -O2 -tree-parallelize-loops=2:
...
#include <stdio.h>

extern unsigned int *a;

void
f (unsigned int n)
{
  int i;
  unsigned int sum = 1;

#pragma omp parallel
  {
#pragma omp for
    for (i = 0; i < n; ++i)
      sum += a[i];
  }

  printf ("%u\n", sum);
}
...

Before tranform_to_exit_first_loop, the loop looks like this:
...
  <bb 4>:
  # sum_18 = PHI <1(11), sum_11(6)>
  # ivtmp_25 = PHI <0(11), ivtmp_6(6)>
  i_17 = (int) ivtmp_25;
  _7 = (long unsigned int) i_17;
  _8 = _7 * 4;
  _9 = pretmp_24 + _8;
  _10 = *_9;
  sum_11 = _10 + sum_18;
  i_12 = i_17 + 1;
  i.1_3 = (unsigned int) i_12;
  if (ivtmp_25 < _20)
    goto <bb 6>;
  else
    goto <bb 5>;

  <bb 5>:
  # sum_21 = PHI <sum_11(4), sum_26(8)>
  goto <bb 7>;

  <bb 6>:
  ivtmp_6 = ivtmp_25 + 1;
  goto <bb 4>;
...

You might say that the transformation applied by tranform_to_exit_first_loop is
that all the statements in bb4 before the if are moved past the if, into both
bb5 and bb6.

After, it looks like:
...
  <bb 4>:
  # sum_28 = PHI <1(11), sum_11(6)>
  # ivtmp_29 = PHI <0(11), ivtmp_6(6)>
  if (ivtmp_29 < _20)
    goto <bb 13>;
  else
    goto <bb 14>;

  <bb 13>:
  # sum_18 = PHI <sum_28(4)>
  # ivtmp_25 = PHI <ivtmp_29(4)>
  i_17 = (int) ivtmp_25;
  _7 = (long unsigned int) i_17;
  _8 = _7 * 4;
  _9 = pretmp_24 + _8;
  _10 = *_9;
  sum_11 = _10 + sum_18;
  i_12 = i_17 + 1;
  i.1_3 = (unsigned int) i_12;
  goto <bb 6>;

  <bb 14>:
  # sum_30 = PHI <sum_28(4)>
  ivtmp_31 = _20;
  i_32 = (int) ivtmp_31;
  _33 = (long unsigned int) i_32;
  _34 = _33 * 4;
  _35 = pretmp_24 + _34;
  _36 = *_35;
  sum_37 = _36 + sum_30;
  i_38 = i_32 + 1;
  i.1_39 = (unsigned int) i_38;

  <bb 5>:
  # sum_21 = PHI <sum_37(14), sum_26(8)>
  goto <bb 7>;

  <bb 6>:
  ivtmp_6 = ivtmp_25 + 1;
  goto <bb 4>;
...

Reply via email to