This is an archive of the discontinued LLVM Phabricator instance.

[WIP][X86] Update CPU_SPECIFIC list.
Needs ReviewPublic

Authored by FreddyYe on Oct 13 2021, 11:40 PM.

Details

Summary

[Notice] This is a work in progress patch.

This patch is to support cpu_specific() function multiversioning for the latest X86 cpu.
Meanwhile update attr-target-mv.c with missing cpu test.

Diff Detail

Event Timeline

FreddyYe requested review of this revision.Oct 13 2021, 11:40 PM
FreddyYe created this revision.
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptOct 13 2021, 11:40 PM
FreddyYe retitled this revision from [X86] Update CPU_SPECIFIC list. to [WIP][X86] Update CPU_SPECIFIC list..Oct 13 2021, 11:43 PM
FreddyYe edited the summary of this revision. (Show Details)

As mentioned before:

There's nothing later than CannonLake here - does Intel need to at least reference up to Tiger/Rocketlake?

I met some issues to discuss with you.

  1. The feature list now I added is got from the output of -march=XXX. This version should work right with many cpus added above. But some of them don't(Functional issue). I dig a little and found it's caused beyond this table. And the issue already exists in the old CPU added before. For example, "core_i7_sse4_2" and "goldmont" only has one feature differs: which is "movbe", but "movebe" is not included in the table of __cpu_features in libgcc (The table is the same as the one in compiler-rt, which is enum ProcessorFeatures), so these two CPU_SPECIFIC won't be classified on run time.
  2. Naming convention issue. -march=goldmont-plus v.s cpu_specific(goldmont_plus). From my test, CPU_SPECIFIC probably needs other changes to support "goldmont-plus".
  3. We probably need to document somewhere for all the supported CPU names on this function multiversioning.
  4. CPU_SPECIFIC_ALIAS() issue. For now, CPUs defined by CPU_SPECIFIC_ALIAS is not allowed to used together with original CPU(e.g. __attribute__((cpu_specific(sandybridge))) and __attribute__((cpu_specific(core_2nd_gen_avx)))), which introduces compile error. Not sure if it is expected.

Supporting these types requires changes to the library so that we can check these, right? Do you have the library changes for these as well? The constants used to check for these features/etc needs to be present in the glibc library.

Supporting these types requires changes to the library so that we can check these, right? Do you have the library changes for these as well? The constants used to check for these features/etc needs to be present in the glibc library.

Yes. It's highly related to the ProcessorFeatures I mentioned above. Does the library changes refer to the compiler-rt/cpu_model.c? I think that change depends on libgcc. For now libgcc has no strong will to update that table.

Supporting these types requires changes to the library so that we can check these, right? Do you have the library changes for these as well? The constants used to check for these features/etc needs to be present in the glibc library.

Yes. It's highly related to the ProcessorFeatures I mentioned above. Does the library changes refer to the compiler-rt/cpu_model.c? I think that change depends on libgcc. For now libgcc has no strong will to update that table.

Every feature gcc knows about should be in libgcc. The unfortunate problem now is that cpu_features2 in libgcc is an array thats size may be different with every version of gcc. Clang can’t know how big that array is without reading the libgcc.a symbol table at compile time. Without knowing the size we can’t access any bits past the first 32 bits of cpu_features2.

Supporting these types requires changes to the library so that we can check these, right? Do you have the library changes for these as well? The constants used to check for these features/etc needs to be present in the glibc library.

Yes. It's highly related to the ProcessorFeatures I mentioned above. Does the library changes refer to the compiler-rt/cpu_model.c? I think that change depends on libgcc. For now libgcc has no strong will to update that table.

Every feature gcc knows about should be in libgcc. The unfortunate problem now is that cpu_features2 in libgcc is an array thats size may be different with every version of gcc. Clang can’t know how big that array is without reading the libgcc.a symbol table at compile time. Without knowing the size we can’t access any bits past the first 32 bits of cpu_features2.

libgcc entries are the ones I was concerned about. We need to make sure this list matches that one (and we don't generate checks that it does not have). @craig.topper can better clarify what needs to happen with the library lookup, but I THINK we keep a version of this in compiler-rt instead of using libgcc?

Supporting these types requires changes to the library so that we can check these, right? Do you have the library changes for these as well? The constants used to check for these features/etc needs to be present in the glibc library.

Yes. It's highly related to the ProcessorFeatures I mentioned above. Does the library changes refer to the compiler-rt/cpu_model.c? I think that change depends on libgcc. For now libgcc has no strong will to update that table.

Every feature gcc knows about should be in libgcc. The unfortunate problem now is that cpu_features2 in libgcc is an array thats size may be different with every version of gcc. Clang can’t know how big that array is without reading the libgcc.a symbol table at compile time. Without knowing the size we can’t access any bits past the first 32 bits of cpu_features2.

libgcc entries are the ones I was concerned about. We need to make sure this list matches that one (and we don't generate checks that it does not have). @craig.topper can better clarify what needs to happen with the library lookup, but I THINK we keep a version of this in compiler-rt instead of using libgcc?

I don't know what needs to be done for the library lookup. I'm not sure if the compiler knows whether we are linking with compiler-rt or libgcc. That information is on the linker command line not necessarily the compiler command line.

Matt added a subscriber: Matt.Oct 19 2022, 4:59 PM
Herald added a project: Restricted Project. · View Herald TranscriptOct 19 2022, 4:59 PM
Herald added a subscriber: StephenFan. · View Herald Transcript

It seems @craig.topper supported __cpu_features2 in compiler-rt revision 94ccb2acbf2c5. Anything else that we need to address before landing the patch?