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

__builtin_cpu_supports doesn't understand x86-64 micro-architecture levels #59961

Closed
chfast opened this issue Jan 12, 2023 · 4 comments
Closed
Labels
backend:X86 clang:frontend Language frontend issues, e.g. anything involving "Sema"

Comments

@chfast
Copy link
Member

chfast commented Jan 12, 2023

This does not work: __builtin_cpu_supports("x86-64-v2").

@RKSimon RKSimon added backend:X86 clang:frontend Language frontend issues, e.g. anything involving "Sema" and removed new issue labels Jan 12, 2023
@llvmbot
Copy link
Collaborator

llvmbot commented Jan 12, 2023

@llvm/issue-subscribers-backend-x86

@llvmbot
Copy link
Collaborator

llvmbot commented Jan 12, 2023

@llvm/issue-subscribers-clang-frontend

chfast referenced this issue Aug 24, 2023
GCC 12 (https://gcc.gnu.org/PR101696) allows `arch=x86-64`
`arch=x86-64-v2` `arch=x86-64-v3` `arch=x86-64-v4` in the
target_clones function attribute. This patch ports the feature.

* Set KeyFeature to `x86-64{,-v2,-v3,-v4}` in `Processors[]`, to be used
  by X86TargetInfo::multiVersionSortPriority
* builtins: change `__cpu_features2` to an array like libgcc. Define
  `FEATURE_X86_64_{BASELINE,V2,V3,V4}` and depended ISA feature bits.
* CGBuiltin.cpp: update EmitX86CpuSupports to handle `arch=x86-64*`.

Close #55830

Reviewed By: pengfei

Differential Revision: https://reviews.llvm.org/D158329
@MaskRay
Copy link
Member

MaskRay commented Aug 25, 2023

Patch: https://reviews.llvm.org/D158811

@ecatmur
Copy link

ecatmur commented Dec 25, 2023

This PR appears to imply that [[gnu::target("x86-64-v2")]] should work:

// If arch= specifies an x86-64 micro-architecture level, test the feature
// with __builtin_cpu_supports, otherwise use __builtin_cpu_is.
if (Arch.starts_with("x86-64"))
Condition = EmitX86CpuSupports({Arch});

However this is not tested, and current trunk does not accept:

<source>:3:36: error: function multiversioning doesn't support architecture 'x86-64'
    3 | [[gnu::target("arch=x86-64")]] int f() { return 2; }
      |                                    ^

This appears to be rejected at

if (!ParseInfo.CPU.empty() && !TargetInfo.validateCpuIs(ParseInfo.CPU)) {
S.Diag(FD->getLocation(), diag::err_bad_multiversion_option)
<< Architecture << ParseInfo.CPU;
Should I report a new issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend:X86 clang:frontend Language frontend issues, e.g. anything involving "Sema"
Projects
None yet
Development

No branches or pull requests

5 participants