[LoopUnroll] Separate peeling from unrolling
authorNikita Popov <nikita.ppv@gmail.com>
Sat, 29 May 2021 16:33:31 +0000 (18:33 +0200)
committerNikita Popov <nikita.ppv@gmail.com>
Sat, 5 Jun 2021 08:32:00 +0000 (10:32 +0200)
commitdb45746821ab01a54f8df033991c3280c4284e3b
tree8d2716659ed2ad20dacff7f82e95e364f86fcef2
parentcf29a92b9026a901855ce6998dc96d796c24c57e
[LoopUnroll] Separate peeling from unrolling

Loop peeling is currently performed as part of UnrollLoop().
Outside test scenarios, it is always performed with an unroll
count of 1. This means that unrolling doesn't actually do anything
apart from performing post-unroll simplification.

When testing, it's currently possible to specify both an explicit
peel count and an explicit unroll count. This doesn't perform any
sensible operation and may result in miscompiles, see
https://bugs.llvm.org/show_bug.cgi?id=45939.

This patch moves peeling from UnrollLoop() into tryToUnrollLoop(),
so that peeling does not also perform a susequent unroll. We only
run the post-unroll simplifications. Specifying both an explicit
peel count and unroll count is forbidden.

In the future, we may want to support both (non-PGO) peeling a
loop and unrolling it, but this needs to be done by first performing
the peel and then recalculating unrolling heuristics on a now
possibly analyzable loop.

Differential Revision: https://reviews.llvm.org/D103362
llvm/include/llvm/Transforms/Utils/UnrollLoop.h
llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp
llvm/lib/Transforms/Utils/LoopUnroll.cpp
llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp
llvm/test/Transforms/LoopUnroll/peel-loop-and-unroll.ll [new file with mode: 0644]
llvm/test/Transforms/LoopUnroll/pr33437.ll
llvm/test/Transforms/LoopUnroll/pr45939-peel-count-and-complete-unroll.ll
llvm/test/Transforms/LoopUnroll/wrong_assert_in_peeling.ll