Clang: how to see the effect of loop flattening pass?

Viewed 139

Clang has loop flattening pass to transform from nested loops:

 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]);

However, I cannot find how to enable this loop flattening pass. I try to use -Os -S, however, clang still generates nested loops.

Question: how to see the effect of loop flattening pass? Which options to use?

UPD. I use clang version 12.0.0 on Windows.

1 Answers

LoopFlatten has been merged into LLVM since 12.0.0. Make sure you are using the updated version.

Second, it's in the transformation passes, you can't directly compiled with clang options. Use opt to do a transformation pass using LoopFlatten using the options specified in the pass code. If you are not familiar with opt, please refer to here: opt - LLVM optimizer

Related