This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: type based aliasing again


Marcel Cox wrote:
> I know this does not proof it is safe. The fact however that a direct
> typecast to int behaves differently from a union typecast shows that
> the compiler handles this differently.

Although it is not a proof, it should be possible to test the alias
rules using a small program where only the type varies, but not the mode
(size) of the types, and where we can be sure the optimiser will always
reorder or remove memory accesses if type alias analysis permits it.

E.g.

T1 test (T1 val1, T1 * var1, T2 val2, T2 * var2)
{
  *var1 = val1;
  *var2 = val2;
  return *var1;
}

I would confidently expect the optimiser to decide *var1 == val1 at the
return point if T1 and T2 cannot alias.

Unfortunately testing the union hack is more complicated than this,
because the compiler has MEM_IN_STRUCT_P alias tests as well, which are
affected by the union.  This might give misleading results from Marcel's
test.

-- Jamie


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]