> > +/* FIELD1 and FIELD2 are two component refs whose bases are either
> > + both at the same address or completely disjoint.
> > + Return 1 if FIELD1 and FIELD2 are non-overlapping
> > + Return 0 if FIELD1 and FIELD2 are having same addresses or are
> > + completely disjoint.
>
> completely disjoint? I guess
>
> Return 0 if accesses to FIELD1 and FIELD2 are possibly overlapping.
>
> is better matching actual behavior. Likewise mentioning 'accesses'
> in the first because of the bitfield treatment (the fields may
> be non-overlapping but actual accesses might be).
I was trying to describe difference between 0 and -1.
We return 0 when we fully structurally matched the path and we know it
is same. -1 means that we arrived to somehting we can not handle (union,
mismatched offsets) and it would make sense to try disambiguating
further.
Currently it means that in addition to
nonoverlapping_component_refs_since_match_p we also do
nonoverlapping_component_refs_p which has some chance to recover from
the mismatched REF pair, match the types later on path and still
disambiguate. It seem to happen very rarely though.
>
> > + /* Different fields of the same record type cannot overlap.
> > + ??? Bitfields can overlap at RTL level so punt on them. */
> > + if (DECL_BIT_FIELD (field1) && DECL_BIT_FIELD (field2))
> > + return -1;
>
> This is similar as the DECL_BIT_FIELD_REPRESENTATIVE check so why
> return -1 instead of 0?
Well, my plan is to put this test before ref_and_offset which still have
chace to suceed if fields are far away. But i am happy to return 0 here
and mess with that later.
> > + else
> > + {
> > + if (operand_equal_p (DECL_FIELD_BIT_OFFSET (field1),
> > + DECL_FIELD_BIT_OFFSET (field2), 0))
> > + return 0;
>
> I think this is overly pessimistic - the offset of a field
> is DECL_FIELD_OFFSET + DECL_FIELD_BIT_OFFSET (the latter is
> only up to DECL_OFFSET_ALIGN, the rest of the constant
> offset spills into DECL_FIELD_OFFSET). Which also means ...
>
> > +
> > + /* Different fields of the same record type cannot overlap.
> > + ??? Bitfields can overlap at RTL level so punt on them. */
> > + if (DECL_BIT_FIELD (field1) && DECL_BIT_FIELD (field2))
> > + return -1;
> > +
> > + poly_uint64 offset1;
> > + poly_uint64 offset2;
> > + poly_uint64 size1;
> > + poly_uint64 size2;
> > + if (!poly_int_tree_p (DECL_FIELD_BIT_OFFSET (field1), &offset1)
> > + || !poly_int_tree_p (DECL_FIELD_BIT_OFFSET (field2), &offset2)
> > + || !poly_int_tree_p (DECL_SIZE (field1), &size1)
> > + || !poly_int_tree_p (DECL_SIZE (field2), &size2)
> > + || ranges_maybe_overlap_p (offset1, size1, offset2, size2))
>
> this is technically wrong in case we had DECL_FIELD_OFFSETs 4 and 8
> and DECL_FIELD_BIT_OFFSETs 32 and 0.
>
> So you have to compute the combined offsets first.
OK, I guess I can take look at the get_base_ref_and_offset there. Thanks
for pointing this out.
>
> > + return -1;
>
> I think it may make sense to return -1 if any of the !poly_int_tree_p
> tests fire, but otherwise? I'm not actually sure what -1 vs. 0
> means here - is 0 a must exactly overlap and -1 is a may overlap
> somehow?
Well, we have two fields that overlap partly from two different types
in >nonoverlapping_component_refs_since_match_p so it can not
continue walking (since the main invariant is broken)
we may still suceed with the nonoverlaping_component_refs
Thanks, I will update the patch.
Honza