[PATCH] D108108: [LoopPeel] Allow peeling with multiple unreachable-terminated exit blocks.
Florian Hahn via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 16 02:09:04 PDT 2021
fhahn created this revision.
fhahn added reviewers: reames, efriedma, skatkov, mkazantsev.
Herald added subscribers: wenlei, zzheng, hiraditya, kristof.beyls.
fhahn requested review of this revision.
Herald added a project: LLVM.
Support for peeling with multiple exit blocks was added in D63921 <https://reviews.llvm.org/D63921>/77bb3a486fa6.
So far it has only been enabled for loops where all non-latch exits are
'de-optimizing' exits (D63923 <https://reviews.llvm.org/D63923>). But peeling of multi-exit loops can be
highly beneficial in other cases too, like if all non-latch exiting
blocks are unreachable.
The motivating case are loops with runtime checks, like the C++ example
below. The main issue preventing vectorization is that the invariant
accesses to load the bounds of B is conditionally executed in the loop
and cannot be hoisted out. If we peel off the first iteration, they
become dereferenceable in the loop, because they must execute before the
loop is executed, as all non-latch exits are terminated with
unreachable. This subsequently allows hoisting the loads and runtime
checks out of the loop, allowing vectorization of the loop.
int sum(std::vector<int> *A, std::vector<int> *B, int N) {
int cost = 0;
for (int i = 0; i < N; ++i)
cost += A->at(i) + B->at(i);
return cost;
}
This gives a ~20-30% increase of score for Geekbench5/HDR on AArch64.
Note that this requires a follow-up improvement to the peeling cost
model to actually peel iterations off loops as above. I will share that
shortly.
Also, peeling of multi-exits might be beneficial for exit blocks with
other terminators, but I would like to keep the scope limited to known
high-reward cases for now.
I removed the option to disable peeling for multi-deopt exits because
the code is more general now. Alternatively, the option could also be
generalized, but I am not sure if there's much value in the option?
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D108108
Files:
llvm/lib/Transforms/Utils/LoopPeel.cpp
llvm/test/Transforms/LoopUnroll/peel-loop-pgo-deopt-idom-2.ll
llvm/test/Transforms/LoopUnroll/peel-loop-pgo-deopt-idom.ll
llvm/test/Transforms/LoopUnroll/peel-loop-pgo-deopt.ll
llvm/test/Transforms/LoopUnroll/peel-multiple-unreachable-exits.ll
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D108108.366569.patch
Type: text/x-patch
Size: 9291 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210816/3b831622/attachment.bin>
More information about the llvm-commits
mailing list