[LICM] Allow load-only scalar promotion in the presence of aliasing loads
authorNikita Popov <npopov@redhat.com>
Thu, 1 Sep 2022 10:45:40 +0000 (12:45 +0200)
committerNikita Popov <npopov@redhat.com>
Tue, 20 Dec 2022 09:02:46 +0000 (10:02 +0100)
commit88419a30a02de3a35db990399315b0b3e329627e
tree50e71b4bc9c160c9616704c7dc925a925ac55dcb
parent301f3da5162499965287338a0cd52309fb28e8b8
[LICM] Allow load-only scalar promotion in the presence of aliasing loads

During scalar promotion, if there are additional potentially-aliasing
loads outside the promoted set, we can still perform a load-only
promotion. As the stores are retained, any potentially-aliasing
loads will still read the correct value.

This increases the number of load promotions in llvm-test-suite by
a factor of two:

                                |  Old |  New
    licm.NumPromotionCandidates | 4448 | 6038
    licm.NumLoadPromoted        |  479 | 1069
    licm.NumLoadStorePromoted   | 1459 | 1459

Unfortunately, this does have some impact on compile-time:
http://llvm-compile-time-tracker.com/compare.php?from=57f7f0d6cf0706a88e1ecb74f3d3e8891cceabfa&to=72b811738148aab399966a0435f13b695da1c1c8&stat=instructions
In part this is because we now have less early bailouts from
promotion, but also due to second order effects (e.g. for one case
I looked at we spend more time in SLP now).

Differential Revision: https://reviews.llvm.org/D133192
llvm/include/llvm/Analysis/AliasSetTracker.h
llvm/include/llvm/Transforms/Utils/LoopUtils.h
llvm/lib/Analysis/AliasSetTracker.cpp
llvm/lib/Transforms/Scalar/LICM.cpp
llvm/lib/Transforms/Scalar/LoopRerollPass.cpp
llvm/test/Transforms/LICM/guards.ll
llvm/test/Transforms/LICM/invariant.start.ll
llvm/test/Transforms/LICM/promote-unknown-load.ll
llvm/test/Transforms/LoopVectorize/invariant-store-vectorization.ll
llvm/unittests/Analysis/AliasSetTrackerTest.cpp