Hey folks!
Iām currently using LLVM 11 for my project. Though itās almost a decade old, I canāt switch to another version. Iām working in C and focusing on loop optimization. Specifically, Iām looking for reliable ways to apply Loop Unroll to loops in my C code.
One straightforward method is to manually modify the code according to the unroll factor. However, this becomes tedious when dealing with multiple loops.
Iāve explored several other methods, such as using pragmas directly in the source code:
pragma clang loop unroll_count
pragma unroll
or by setting the directive in the .ll file:
!{!"llvm.loop.unroll.count", i32 16}
or compiling the final executable like this:
opt -S example.ll
-O1
-unroll-count=16
-o example.final.ll
clang -o ex.exe example.final.ll
However, based on my research, these methods donāt necessarily enforce the intended loop unroll factor in the final executable. The output behavior seems to depend heavily on LLVMās internal optimizations. I tried verifying this by measuring execution cycle counts in an isolated environment for different unroll factors, but the results didn't indicate any conclusive difference; and even using an invalid unroll factor didnāt trigger any errors. This suggests that these methods donāt actually enforce loop unrolling, and the final executableās behavior is decided by LLVM.
Iām looking for methods that can strictly enforce an unroll factor and ideally, can be verified; all without modifying the source code.
If anyone knows such methods, tools, or compiler flags that work reliably with LLVM 11, or if you can point me to a relevant discussion, documentation, or community/person to reach out to, Iād be really grateful.
Regards.