Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable loop unrolling in Rust?

I am looking at Rust to rewrite a C++ codebase and I would like to know how to disable loop unrolling/vectorizing and control unroll count as well. In Clang we would use:

#pragma clang loop unroll(disable)
#pragma clang loop unroll(disable) vectorize(disable)
#pragma clang loop unroll_count(2)

It is highly performance sensitive code and not having control over loop codegen could be a showstopper.

like image 486
Stringer Avatar asked Jul 24 '19 12:07

Stringer


1 Answers

You cannot control how a given loop is/is not unrolled. It has been proposed, but no real progress has been made on considering such an RFC, much less accepting and implementing it.


If you are looking for very broad capabilities, you can pass -C llvm-args=... to the compiler to influence LLVM. If there's a way to disable loop unrolling completely, that might do what you want.

Pragmatically, I'd encourage you to get a walking skeleton of your code in Rust and see if the performance is acceptable. My personal experience has shown that "general" Rust code is more performant because of

  • The borrow checker making it safe to be aggressive about using references instead of copies
  • Comparatively easy usage of multithreading
  • A strong type system that can help avoid performing work multiple times
like image 140
Shepmaster Avatar answered Oct 12 '22 01:10

Shepmaster