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

            Bug ID: 72747
           Summary: powerpc: wrong code generated for vec_splats in
                    cascading assignment
           Product: gcc
           Version: 5.3.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: wschmidt at gcc dot gnu.org
  Target Milestone: ---

A statement such as "v = vec_splats (1);" correctly initializes a vector. 
However, a statement such as "v[1] = v[0] = vec_splats (1);" initializes both
v[1] and v[0] to random garbage.  The following code can be used to verify the
problem:

#include <altivec.h>
#include <iostream>
#include <cstdlib>

using std::cout;
using std::endl;

int main (int argc, char *argv[])
{
  int i, j;
  __vector short v1[2];

  v1[1] = v1[0] = vec_splats ((short) 1);

  for (i = 0; i < 2; ++i)
    {
      cout << "v1[" << i << "]: ";
      for (j = 0; j < 8; ++j)
        cout << v1[i][j] << " ";
      cout << endl;
    }

  return EXIT_SUCCESS;
}

Probable cause is the special handling of vec_splats in rs6000-c.c during
parsing.  Compiled at -O0 with current trunk, the "optimized" dump shows:

  <bb 2>:
  _1 = v1[0];
  v1[1] = _1;

where v1[0] is uninitialized.

Reported on GCC 5.3.1, but confirmed to occur also in GCC 6.1 and current
trunk.

Reply via email to