3

Does Rust have an equivalent of GCC's C CFLAGS="-Ofast -march=native" compiler optimizations?                                                                                                                                                                               

belteshazzar
  • 2,163
  • 2
  • 21
  • 30

1 Answers1

5

To optimise for the native CPU, you can use

RUSTFLAGS="-C target-cpu=native"

I think LLVM optimises for speed (or more specifically, throughput) by default; I couldn't really find documentation on this, but this is what the source code suggests.

You should be able to select a different cost model using e.g.

RUSTFLAGS="-C target-cpu=native -C llvm-args='-cost-kind=latency'"

but I haven't tried this, nor do I know any details about the effect of this switch.

Sven Marnach
  • 574,206
  • 118
  • 941
  • 841
  • I believe the `'` around `-cost-kind=latency` have to be removed. At least with my tests, I got `unknown commandline argument if I included the single quotation marks. – Philipp Ludwig Jun 10 '21 at 07:05