https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113847
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |hubicka at gcc dot gnu.org
--- Comment #4 from Richard Biener <rguenth at gcc dot gnu.org> ---
Hmm, the important one is actually MEM[ptr + CST] vs MEM[ptr].component. But
those are not semantically equivalent, even when the same TBAA type is in
effect.
_31 = MEM <int> [(struct quantum_reg *)reg_3(D)];
_33 = MEM <int> [(struct quantum_reg *)reg_3(D) + 8B];
_34 = MEM <struct quantum_reg_node *> [(struct quantum_reg *)reg_3(D) + 16B];
_35 = MEM <int *> [(struct quantum_reg *)reg_3(D) + 24B];
out = quantum_state_collapse.isra (pos_1(D), result_22, _31, _32, _33, _34,
_35); [return slot optimization]
this is from inlined quantum_state_collapse where IPA SRA is eventually
applied producing the above.
That we do produce those might hint at that we can't really assume the
dynamic type quantum_reg is at offset 8 but that was the original intent.
What we are left with is the special-case where typeof (MEM[ptr + CST])
== typeof (alias-pointed-to-type) (with CST == 0). For any other case
what we know is only that the access MEM[ptr + CST] is to somewhere
inside an object of dynamic type quantum_reg?
I'm not sure that's not less than we make use of in the alias-oracle,
esp. aliasing_component_refs_walk and friends? We might be fine in
practice for "bare" MEM_REFs like the above, but if we ever fold only
part of the access path into the constant offset funny things may happen?
So I think IPA SRA does wrong here (and maybe GCC in other places as well),
possibly only pessimizing and possibly creating latent wrong-code.
Note quantum_state_collapse has
reg$size_62 = reg.size;
reg$node_75 = reg.node;
...
pre-IPA.
Honza, any opinion?