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

            Bug ID: 85636
           Summary: Tree if-conversion inserts bogus loads
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: rsandifo at gcc dot gnu.org
  Target Milestone: ---

Compiling this at -O3 on aarch64-linux-gnu:

void f (int *a, int *b, int *c, int x, int y)
{
  for (int i = 0; i < 100; ++i)
    {
      int v = c[i];
      a[i] = (v == 20 ? x : y);
      b[i] = (v != 20 ? x : y);
    }
}

gives the following basic block after if-conversion:

  _1 = (long unsigned int) i_31;
  _2 = _1 * 4;
  _3 = c_11(D) + _2;
  v_12 = *_3;
  _21 = a_15(D) + _2;
  _ifc__41 = *_21;
  _ifc__42 = x_13(D);
  _ifc__43 = v_12 == 20 ? _ifc__42 : _ifc__41;
  *_21 = _ifc__43;
  _ifc__44 = *_21;
  _ifc__45 = y_14(D);
  _ifc__46 = v_12 == 20 ? _ifc__44 : _ifc__45;
  *_21 = _ifc__46;
  iftmp.1_8 = v_12 != 20 ? x_13(D) : y_14(D);
  _5 = b_17(D) + _2;
  *_5 = iftmp.1_8;

Note the two extra loads from a[i] (_21), which didn't occur in the original
source.  The handling of b[i] is fine.

Reply via email to