Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing codegen option corresponding to clang's prefer-vector-width #53312

Closed
hdevalence opened this issue Aug 13, 2018 · 3 comments
Closed

Missing codegen option corresponding to clang's prefer-vector-width #53312

hdevalence opened this issue Aug 13, 2018 · 3 comments
Labels
A-codegen Area: Code generation C-feature-request Category: A feature request, i.e: not implemented / a PR.

Comments

@hdevalence
Copy link

Clang 7 added a codegen option, -mprefer-vector-width=, which allows specifying the preferred vector width for autovectorization. This allows preventing wide vector operations in codegen. Why? Because eagerly using wide vector operations can hurt performance on Intel CPUs in at least two ways:

  1. Wide vector operations can knock the CPU out of the highest turbo states, reducing the frequency for the next few million cycles;
  2. Some CPUs implement wide operations by fusing execution ports, so interspersing wider operations with narrower ones can reduce overall throughput.

On the other hand, AVX512 doubles the number of vector registers, so it's useful for performance to enable target_cpu=skylake-avx512, even without using 512-bit operations.

Unfortunately, there doesn't seem to be a way to use this option with rustc: it's not one of the -C codegen options, and passing -C llvm-args=-prefer-vector-width=256 gives

rustc: Unknown command line argument '-prefer-vector-width=256'.  Try: 'rustc -help'
rustc: Did you mean '-force-vector-width=256'?

It would be great if rustc had a way to set the preferred vector width.

@memoryruins memoryruins added the A-codegen Area: Code generation label Sep 15, 2018
@hdhoang hdhoang added the C-feature-request Category: A feature request, i.e: not implemented / a PR. label Dec 9, 2019
@josephlr
Copy link
Contributor

josephlr commented Jun 1, 2020

With https://reviews.llvm.org/D67259 now merged as part of LLVM 10 (#67759), there is now the inverse problem, there is no way to tell rustc to prever AVX-512 instructions, even on CPU targets that support it.

As this is a very uncommon use case, a llvm-args would be fine.

@josephlr
Copy link
Contributor

josephlr commented Jun 1, 2020

So the reason that llvm-args doesn't work is that prefer-vector-width in LLVM is a function attribute not a global attribute (which llvm-args correspond to). Clang's prefer-vector-width exposes a global flag that just changes the default set of function attributes.

Given the fact that:

I think that this issue can be closed

@hdevalence
Copy link
Author

That sounds fine to me!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-codegen Area: Code generation C-feature-request Category: A feature request, i.e: not implemented / a PR.
Projects
None yet
Development

No branches or pull requests

4 participants