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

            Bug ID: 87434
           Summary: LTO corrupts code
           Product: gcc
           Version: 9.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: lto
          Assignee: unassigned at gcc dot gnu.org
          Reporter: kelvin at gcc dot gnu.org
                CC: marxin at gcc dot gnu.org
  Target Milestone: ---

Created attachment 44748
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=44748&action=edit
reproducer source code including draft patch

In the attached sample program, the code generated for the following loop is
corrupted by the lto pass.

  for (i = 0; i < N; i++)
    {
      /* the -flto optimization corrupts the following assignments.  */
      dst[i] = 0;
      src[i] = i;
    }

When -flto optimization is enabled, the loop behaves as if it had been written
as shown below, with the source values swapped during assignments to the
respective array slots:

  for (i = 0; i < N; i++)
    {
      dst[i] = i;
      src[i] = 0;
    }

This problem has only been seen in the context of a draft patch which has the
effect of replacing Power X-form addresses with D-form addresses, also
attached.  In this particular test program, the compiler discovers that src is
512 bytes from dst, and uses the same pointer for both assignments, using a
512-byte immediate-mode offset to distinguish the two assignments.

Draft patch and test programs are attached.

Reply via email to