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

            Bug ID: 113424
           Summary: lim fails to notice possible aliasing
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: kristerw at gcc dot gnu.org
  Target Milestone: ---

The lim pass miscompiles the following C++ program when compiled as -O3 for
x86_64 (note: it works as intended when compiled as a C program)

struct { char elt1; char bits; } *a;
char
bar (char *x, char b)
{
  if (0)
  next_bit:
    return 1;
  while (1)
    {
      if (b)
        if (a->bits)
          goto next_bit;
      *x = b;
      if (a->elt1)
        return 0;
      a = 0;
    }
}

The loop lim gets as input looks as following

  <bb 3>
  if (b_9(D) != 0)
    goto <bb 4>;
  else
    goto <bb 5>;

  <bb 4>
  a.0_1 = a;
  _2 = a.0_1->bits;
  if (_2 != 0)
    goto <bb 7>;
  else
    goto <bb 5>;

  <bb 5>
  *x_10(D) = b_9(D);
  a.1_3 = a;
  _4 = a.1_3->elt1;
  if (_4 != 0)
    goto <bb 7>; [5.50%]
  else
    goto <bb 6>; [94.50%]

  <bb 6>
  a = 0B;
  goto <bb 3>; [100.00%]

The lim pass changes this to load `a` before the loop and uses the same value
of `a` for both accesses in bb4 and bb5, which is not correct as the store
`*x_10(D)` may have modified `a` before the access in bb5.

Reply via email to