The alias analysis in DAG Combine looks at the BaseAlign, the Offset and the Size of two accesses, and determines if they are known to access different parts of memory by the fact that they are different offsets from inside that "alignment window". It does not seem to account for accesses that are not a multiple of the size, and may overflow from one alignment window into another.
For example in the test case we have a 19byte memset that is splits into a 16 byte neon store and an unaligned 4 byte store with a 15 byte offset. This 15byte offset (with a base align of 8) wraps around to the next alignment windows. When compared to an access that is a 16byte offset (of the same 4byte size and 8byte basealign), the two accesses are said not to alias.
I've fixed this here by just ensuring that the offsets are a multiple of the size, ensuring that they don't overlap by wrapping. Fixes PR45035, which was exposed by the UseAA changes in the arm backend.
The hunk you modify on L21156-L21157 highlights was looks like maybe a pre-existing incorrect usage of Optional::operator*; there's no check that MUC0.NumBytes hasValue before making use of the value (which may not exist). In particular, I'm concerned what the value of -1 might do in those expressions.
Or you could do:
Though I'm not sure whether the lower hunk should have a guard as well vs use a value of 0. Using -1 for a possible value of the Optional<int64_t> might be problematic, though I assume the number of bytes in a "memory use characteristic" is unlikely. (I wish the "LLVM Programmers Manual" had a section on llvm::Optional). So maybe it's ok to keep as is, but then I really think the lower hunk should also have some kind of guard.