This is an archive of the discontinued LLVM Phabricator instance.

[X86] __builtin_cpu_supports: support x86-64{,-v2,-v3,-v4}
ClosedPublic

Authored by MaskRay on Aug 24 2023, 9:34 PM.

Details

Summary

GCC 12 (https://gcc.gnu.org/PR101696) allows
__builtin_cpu_supports("x86-64") (and -v2 -v3 -v4).
This patch ports the feature.

  • Add FEATURE_X86_64_{BASELINE,V2,V3,V4} to enum ProcessorFeatures, but keep CPU_FEATURE_MAX unchanged to make FeatureInfos/FeatureInfos_WithPLUS happy.
  • Change validateCpuSupports to allow x86-64{,-v2,-v3,-v4}
  • Change getCpuSupportsMask to return std::array<uint32_t, 4> where x86-64{,-v2,-v3,-v4} set bits FEATURE_X86_64_{BASELINE,V2,V3,V4}.
  • target("x86-64") and cpu_dispatch(x86_64) are invalid. Tested by commit 9de3b35ac9159d5bae6e6796cb91e4f877a07189

Close https://github.com/llvm/llvm-project/issues/59961

Diff Detail

Event Timeline

MaskRay created this revision.Aug 24 2023, 9:34 PM
Herald added a project: Restricted Project. · View Herald Transcript
Herald added a subscriber: hiraditya. · View Herald Transcript
MaskRay requested review of this revision.Aug 24 2023, 9:34 PM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptAug 24 2023, 9:34 PM
MaskRay edited the summary of this revision. (Show Details)Aug 24 2023, 9:36 PM
MaskRay edited the summary of this revision. (Show Details)
pengfei added inline comments.Aug 25 2023, 1:31 AM
llvm/include/llvm/TargetParser/X86TargetParser.h
63

Not needed.

llvm/lib/TargetParser/X86TargetParser.cpp
718–719

Should we use vector for future expansion, or add an assert to make sure it won't exceed current limitation?

MaskRay updated this revision to Diff 553524.Aug 25 2023, 10:07 AM
MaskRay marked 2 inline comments as done.

add assert

pengfei accepted this revision.Aug 25 2023, 8:22 PM

LGTM.

This revision is now accepted and ready to land.Aug 25 2023, 8:22 PM
MaskRay updated this revision to Diff 553698.Aug 25 2023, 8:52 PM
MaskRay edited the summary of this revision. (Show Details)

rebase after precommitting target("x86-64") and cpu_specific(x86_64) attributes tests
add __builtin_cpu_supports x86-64-v5 test

This revision was landed with ongoing or failed builds.Aug 25 2023, 8:56 PM
This revision was automatically updated to reflect the committed changes.
MaskRay added inline comments.Aug 25 2023, 8:58 PM
llvm/lib/TargetParser/X86TargetParser.cpp
718–719

A resizable vector does not simplify code here. I've added an assert.