[all-commits] [llvm/llvm-project] d53b4b: [LoopFlatten] Add a loop-flattening pass
sjoerdmeijer via All-commits
all-commits at lists.llvm.org
Thu Oct 1 05:56:05 PDT 2020
Branch: refs/heads/master
Home: https://github.com/llvm/llvm-project
Commit: d53b4bee0ccd408cfe6e592540858046244e74ce
https://github.com/llvm/llvm-project/commit/d53b4bee0ccd408cfe6e592540858046244e74ce
Author: Sjoerd Meijer <sjoerd.meijer at arm.com>
Date: 2020-10-01 (Thu, 01 Oct 2020)
Changed paths:
M llvm/include/llvm/InitializePasses.h
M llvm/include/llvm/LinkAllPasses.h
M llvm/include/llvm/Transforms/Scalar.h
A llvm/include/llvm/Transforms/Scalar/LoopFlatten.h
M llvm/lib/Passes/PassBuilder.cpp
M llvm/lib/Passes/PassRegistry.def
M llvm/lib/Transforms/IPO/PassManagerBuilder.cpp
M llvm/lib/Transforms/Scalar/CMakeLists.txt
A llvm/lib/Transforms/Scalar/LoopFlatten.cpp
M llvm/lib/Transforms/Scalar/Scalar.cpp
A llvm/test/Transforms/LoopFlatten/loop-flatten-negative.ll
A llvm/test/Transforms/LoopFlatten/loop-flatten.ll
A llvm/test/Transforms/LoopFlatten/pr40581.ll
Log Message:
-----------
[LoopFlatten] Add a loop-flattening pass
This is a simple pass that flattens nested loops. The intention is to optimise
loop nests like this, which together access an array linearly:
for (int i = 0; i < N; ++i)
for (int j = 0; j < M; ++j)
f(A[i*M+j]);
into one loop:
for (int i = 0; i < (N*M); ++i)
f(A[i]);
It can also flatten loops where the induction variables are not used in the
loop. This can help with codesize and runtime, especially on simple cpus
without advanced branch prediction.
This is only worth flattening if the induction variables are only used in an
expression like i*M+j. If they had any other uses, we would have to insert a
div/mod to reconstruct the original values, so this wouldn't be profitable.
This partially fixes PR40581 as this pass triggers on one of the two cases. I
will follow up on this to learn LoopFlatten a few more (small) tricks. Please
note that LoopFlatten is not yet enabled by default.
Patch by Oliver Stannard, with minor tweaks from Dave Green and myself.
Differential Revision: https://reviews.llvm.org/D42365
More information about the All-commits
mailing list