[DAGCombine] Fix alias analysis for unaligned accesses
authorDavid Green <david.green@arm.com>
Fri, 28 Feb 2020 18:31:45 +0000 (18:31 +0000)
committerDavid Green <david.green@arm.com>
Fri, 28 Feb 2020 18:44:36 +0000 (18:44 +0000)
commit1de10705594c7a2c9b8fde901c391bd84062ae04
tree9c9ff57660924115dce2dc7bd5bb1315c68baaf1
parent4fa63fd4524c9818dab2fc0d3ea3a8d65d3bc22b
[DAGCombine] Fix alias analysis for unaligned accesses

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.

Differential Revision: https://reviews.llvm.org/D75238
llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
llvm/test/CodeGen/ARM/memset-align.ll [new file with mode: 0644]