[Passes] Run sinking/hoisting in SimplifyCFG earlier.
authorFlorian Hahn <flo@fhahn.com>
Fri, 30 Apr 2021 08:39:34 +0000 (09:39 +0100)
committerFlorian Hahn <flo@fhahn.com>
Fri, 30 Apr 2021 11:23:57 +0000 (12:23 +0100)
commited9df5bd2f50b2199204cc6e50910ba52dd5e93e
tree1fd213544b28e5b7c8b5736bf9f113d7ba83efb3
parentb310dd15017f9aecd1ecc84b896d346075282a34
[Passes] Run sinking/hoisting in SimplifyCFG earlier.

Hoisting and sinking instructions out of conditional blocks enables
additional vectorization by:

1. Executing memory accesses unconditionally.
2. Reducing the number of instructions that need predication.

After disabling early hoisting / sinking, we miss out on a few
vectorization opportunities. One of those is causing a ~10% performance
regression in one of the Geekbench benchmarks on AArch64.

This patch tires to recover the regression by running hoisting/sinking
as part of a SimplifyCFG run after LoopRotate and before LoopVectorize.

Note that in the legacy pass-manager, we run LoopRotate just before
vectorization again and there's no SimplifyCFG run in between, so the
sinking/hoisting may impact the later run on LoopRotate. But the impact
should be limited and the benefit of hosting/sinking at this stage
should outweigh the risk of not rotating.

Compile-time impact looks slightly positive for most cases.
http://llvm-compile-time-tracker.com/compare.php?from=2ea7fb7b1c045a7d60fcccf3df3ebb26aa3699e5&to=e58b4a763c691da651f25996aad619cb3d946faf&stat=instructions

NewPM-O3: geomean -0.19%
NewPM-ReleaseThinLTO: geoman -0.54%
NewPM-ReleaseLTO-g: geomean -0.03%

With a few benchmarks seeing a notable increase, but also some
improvements.

Alternative to D101290.

Reviewed By: lebedev.ri

Differential Revision: https://reviews.llvm.org/D101468
llvm/lib/Passes/PassBuilder.cpp
llvm/lib/Transforms/IPO/PassManagerBuilder.cpp
llvm/test/Transforms/PGOProfile/Inputs/thinlto_cspgo_bar_use.ll
llvm/test/Transforms/PGOProfile/cspgo_profile_summary.ll
llvm/test/Transforms/PGOProfile/thinlto_cspgo_use.ll
llvm/test/Transforms/PhaseOrdering/AArch64/hoisting-sinking-required-for-vectorization.ll