[Bug tree-optimization/57359] store motion causes wrong code for union access at -O3

rguenth at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Mon Apr 27 12:48:32 GMT 2020


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

--- Comment #30 from Richard Biener <rguenth at gcc dot gnu.org> ---
Created attachment 48381
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=48381&action=edit
more complex approach, POC

Another testcase, this time for store ordering (IIRC we may have a duplicate
for
this).  We currently use a fixed order of *p and *r for _both_ exits which
is of course wrong.

POC patch fixing all issues attached, it needs to be enhanced to not give
up when not all stores we want to move are stored in the exit block.  Also
some memory leaks need fixing and we need to avoid doing redundant work when
enhancing the scheme and eventually enhance it to prune SMs we cannot perform.


extern void abort();

typedef int A;
typedef float B;

void __attribute__((noinline,noclone))
foo(A * p, B *r, long unk, long oh)
{
  for (long i = 0; i < unk; ++i) {
      *p = 1;
      *r = 2;
      if (oh & i)
        break;
      *r = 3;
      *p = 4;
  }
}

int main(void)
{
  union { A x; B f; } u;
  foo(&u.x, &u.f, 1, 1);
  if (u.x != 4) abort();
  foo(&u.x, &u.f, 2, 1);
  if (u.f != 2) abort ();
  return 0;
}


More information about the Gcc-bugs mailing list