How to use the pass 'Unroll and Jam'

Dear LLVM developers,

Recently I want to try the pass ‘-loop-unroll-and-jam’ to observe how the IR is transformed, but I don’t see the IR changed after doing the following steps.

Here are the details for preparing my experiment and I have tried the LLVM 6, 7 and 8:

  1. Simple 2D array source code (loop.c) is given

#define M 32768
#define N 32768

double a[M][N], b[M][N], c[M][N];

int main() {
for (int i = 0; i < M; i++) {
for (int j = 0; j < N; j++) {
c[i][j] = a[i][j] + b[i][j];
}
}
return 0;

}
  1. Create an LLVM IR file
    ./bin/clang -O1 loop.c -emit-llvm -S -o loop.ll

  2. Run the ‘unroll-and-jam’ pass
    ./bin/opt -loop-unroll-and-jam loop.ll -S -o loop-unrolljam.ll

I added the option ‘–debug-pass=Structure’ to the opt, and I can see the ‘Unroll and Jam loops’ indeed executed by the Loop Pass Manager.


ModulePass Manager
FunctionPass Manager
Dominator Tree Construction
Basic Alias Analysis (stateless AA impl)
Function Alias Analysis Results
Natural Loop Information
Scalar Evolution Analysis
Dependence Analysis
Canonicalize natural loops
LCSSA Verifier
Loop-Closed SSA Form Pass
Loop Pass Manager
Unroll and Jam loops
Module Verifier
Print Module IR

I also tried to add the option ‘-debug’ to the opt to see if there is the debug information printed by LoopUnrollAndJam, but nothing.

Thank you very much.

Try the combo:

-enable-unroll-and-jam -allow-unroll-and-jam -unroll-and-jam-count=4

Hi Das,

Thanks for your reply! I have received similar responses from @LebedevRI on the IRC.

After I modified the arguments for opt as the following, my loops can be unroll-and-jam successfully:
-loop-unroll-and-jam -allow-unroll-and-jam -unroll-and-jam-count=2

‘loop-unroll-and-jam’ and ‘allow-unroll-and-jam’ are both needed to turn on the functionality.

Thanks again. Have a nice day.

Das, Dibyendu <Dibyendu.Das@amd.com> 於 2019年4月25日 週四 下午4:24寫道: