[RFC] ignoring type alias conflicts between structures and scalars
Diego Novillo
dnovillo@redhat.com
Thu Nov 25 15:38:00 GMT 2004
Jeff noticed that TBAA was creating some alias relations that don't seem
to make much sense. For instance, given
------------------------------------------------------------------------------------struct int_float_s {
int i;
float f;
};
int X;
foo()
{
struct int_float_s *x = bar();
X = 10;
x->i = 3;
return X;
}
------------------------------------------------------------------------------------
After TBAA, we had
Variable: x, UID 1, struct int_float_s *, type memory tag: TMT.0
Variable: X, UID 2, int, is addressable, is global, call clobbered, default def: X_1
Variable: TMT.0, UID 5, struct int_float_s, is addressable, is global, call clobbered, may aliases: { X }
Jeff's argument is that it's not really possible for a pointer to a
structure to point to a scalar variable. If the structure is not type
compatible with the scalar, then they can't alias. That makes some
sense to me.
However, the front end says that those two types are alias compatible,
meaning that we could store into X via x. So, I'm confused. I
discussed this a bit with Nathan and Joseph on IRC. Nathan pointed me
to some section in the C standard that seems to support the fact that
indeed TMT.0 should alias X.
The attached patch implements the idea of ignoring alias relations
between structures and scalars that are not type compatible. It
survived bootstrap and testing on x86, ia64, x86-64 and ppc. However, I
have zero confidence in it. If the types cannot really conflict,
alias_sets_conflict_p() should tell me so. I shouldn't need to short
circuit it this way.
I'm also attaching a program that breaks this patch. Basically, it
causes 'bar()' to return &X. Since we are now considering that X cannot
alias with TMT.0, we would optimize the function to 'return 10'. The
question is: Is the program well defined?
If the program isn't well defined, why is alias_sets_conflict_p() saying
that 'struct int_float_s' and 'int' have conflicting alias sets?
Thanks. Diego.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 20041125-short-circuit-struct-scalar-alias.diff
Type: text/x-patch
Size: 1265 bytes
Desc: not available
URL: <https://gcc.gnu.org/pipermail/gcc/attachments/20041125/7e5ab4a9/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: b.c
Type: text/x-csrc
Size: 196 bytes
Desc: not available
URL: <https://gcc.gnu.org/pipermail/gcc/attachments/20041125/7e5ab4a9/attachment-0001.bin>
More information about the Gcc
mailing list