BasicAliasAnalysis tends to give up on proving no-aliasing between
two memory accesses when they share the same underlying object (e.g
when they are fields of the same structure). Such simplified approach
results in losing optimization opportunities that competing compilers
are able to exploit. Namely, when a loop invariant is loaded from the
i-th element of some array being a field of some global structure and
on each iteration i-th element of another array being a different
field of the same global structure is written to, the load is not
hoisted resulting in tragic performance at -O3 comparing to what
other compiler can achieve at the same optimization level.
This patch adds some additional logic that checks just for that:
it returns NoAlias when accessed elements of the same underlying
object are two different fields of the same structure.
Some of the test cases had to be modified in global_alias.ll which
represented the situation addressed by this patch.
This patch may seem somewhat constrained as it was focused on
improving performance of the particular loop I was working with. Doing
it any more general results in a certain number of failing test cases.
clang-tidy: warning: invalid case style for variable 'i' [readability-identifier-naming]
not useful