The following two testcases should produce the same code after forwprop1:

struct foo { int i[3]; };

void bar (void)
{
  struct foo Foo;
  int i;

  for (i=0; i<3; ++i)
    {
      void *p = &Foo.i[i];
      int *pi = (int *)p;
      if (pi != 0)
        {
          *pi = 0;
        }
    }
}

---

struct foo { int i[3]; };

void bar (void)
{
  struct foo Foo;
  int i;

  for (i=0; i<3; ++i)
    {
      void *p = &Foo.i[i];
      int *pi = (int *)p;
      if (p != 0)
        {
          *pi = 0;
        }
    }
}


(the difference is testing p != 0 vs. pi != 0)

This happens in tramp3d-v4 via placement new:

  for (i=0; i<3; ++i)
    new (&a[i]) double;

where placement new expands to the "wrong" test sequence.

Mine.


-- 
           Summary: forwprop does not look through casts
           Product: gcc
           Version: 4.3.0
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: enhancement
          Priority: P3
         Component: tree-optimization
        AssignedTo: rguenth at gcc dot gnu dot org
        ReportedBy: rguenth at gcc dot gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31146

Reply via email to