Skip to content

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

Closed

Description

@hdevalence

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.

Activity

  1. added
    C-feature-requestCategory: A feature request, i.e: not implemented / a PR.
    on Dec 9, 2019
  2. josephlr commented on Jun 1, 2020

    @josephlr
    Contributor

    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.

  3. josephlr commented on Jun 1, 2020

    @josephlr
    Contributor

    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

  4. hdevalence commented on Jun 3, 2020

    @hdevalence
    ContributorAuthor

    That sounds fine to me!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-codegenArea: Code generationC-feature-requestCategory: A feature request, i.e: not implemented / a PR.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions