Add a new pass "Loop Interchange"
authorKarthik Bhat <kv.bhat@samsung.com>
Fri, 6 Mar 2015 10:11:25 +0000 (10:11 +0000)
committerKarthik Bhat <kv.bhat@samsung.com>
Fri, 6 Mar 2015 10:11:25 +0000 (10:11 +0000)
commit88db86dd295a17eb51831b6d9b0d6af5098170a7
tree2fded347abe7180eca6309f6467cca869c72b7cc
parent0fc13a9a8265e16d5f86cfa7f64fa54bb592b14f
Add a new pass "Loop Interchange"
This pass interchanges loops to provide a more cache-friendly memory access.

For e.g. given a loop like -
  for(int i=0;i<N;i++)
    for(int j=0;j<N;j++)
      A[j][i] = A[j][i]+B[j][i];

is interchanged to -
  for(int j=0;j<N;j++)
    for(int i=0;i<N;i++)
      A[j][i] = A[j][i]+B[j][i];

This pass is currently disabled by default.

To give a brief introduction it consists of 3 stages-

LoopInterchangeLegality : Checks the legality of loop interchange based on Dependency matrix.
LoopInterchangeProfitability: A very basic heuristic has been added to check for profitibility. This will evolve over time.
LoopInterchangeTransform : Which does the actual transform.

LNT Performance tests shows improvement in Polybench/linear-algebra/kernels/mvt and Polybench/linear-algebra/kernels/gemver becnmarks.

TODO:
1) Add support for reductions and lcssa phi.
2) Improve profitability model.
3) Improve loop selection algorithm to select best loop for interchange. Currently the innermost loop is selected for interchange.
4) Improve compile time regression found in llvm lnt due to this pass.
5) Fix issues in Dependency Analysis module.

A special thanks to Hal for reviewing this code.
Review: http://reviews.llvm.org/D7499

llvm-svn: 231458
llvm/include/llvm/InitializePasses.h
llvm/include/llvm/LinkAllPasses.h
llvm/include/llvm/Transforms/Scalar.h
llvm/lib/Transforms/IPO/PassManagerBuilder.cpp
llvm/lib/Transforms/Scalar/CMakeLists.txt
llvm/lib/Transforms/Scalar/LoopInterchange.cpp [new file with mode: 0644]
llvm/lib/Transforms/Scalar/Scalar.cpp
llvm/test/Transforms/LoopInterchange/currentLimitation.ll [new file with mode: 0644]
llvm/test/Transforms/LoopInterchange/interchange.ll [new file with mode: 0644]
llvm/test/Transforms/LoopInterchange/profitability.ll [new file with mode: 0644]