Skip to content

Commit d298acd

Browse files
committed
[X86] Don't disable xsave when avx is disabled. Implicitly enable xsave with avx is enabled and xsave wasn't explciitly disabled
CPUs with avx always have xsave, but some CPUs without avx also have xsave. So we shouldn't disable xsave just because avx is disabled. This would prevent xsave from being enabled with -march=native on CPUs with xsave and not avx. But we also don't want -mavx -mno-avx to leave xsave eanabled. So only enable xsave if avx is enabled after processing all features. I thought about just not turning xsave on with avx at all, but there might be someone out there depending on it.
1 parent c918c1a commit d298acd

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

clang/lib/Basic/Targets/X86.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,7 @@ bool X86TargetInfo::initFeatureMap(
360360
setFeatureEnabledImpl(Features, "bmi", true);
361361
setFeatureEnabledImpl(Features, "f16c", true);
362362
setFeatureEnabledImpl(Features, "xsaveopt", true);
363+
setFeatureEnabledImpl(Features, "xsave", true);
363364
setFeatureEnabledImpl(Features, "movbe", true);
364365
LLVM_FALLTHROUGH;
365366
case CK_BTVER1:
@@ -459,6 +460,12 @@ bool X86TargetInfo::initFeatureMap(
459460
llvm::find(FeaturesVec, "-mmx") == FeaturesVec.end())
460461
Features["mmx"] = true;
461462

463+
// Enable xsave if avx is enabled and xsave is not explicitly disabled.
464+
I = Features.find("avx");
465+
if (I != Features.end() && I->getValue() &&
466+
llvm::find(FeaturesVec, "-xsave") == FeaturesVec.end())
467+
Features["xsave"] = true;
468+
462469
return true;
463470
}
464471

@@ -476,7 +483,6 @@ void X86TargetInfo::setSSELevel(llvm::StringMap<bool> &Features,
476483
LLVM_FALLTHROUGH;
477484
case AVX:
478485
Features["avx"] = true;
479-
Features["xsave"] = true;
480486
LLVM_FALLTHROUGH;
481487
case SSE42:
482488
Features["sse4.2"] = true;
@@ -526,8 +532,7 @@ void X86TargetInfo::setSSELevel(llvm::StringMap<bool> &Features,
526532
LLVM_FALLTHROUGH;
527533
case AVX:
528534
Features["fma"] = Features["avx"] = Features["f16c"] = false;
529-
Features["xsave"] = Features["xsaveopt"] = Features["vaes"] = false;
530-
Features["vpclmulqdq"] = false;
535+
Features["vaes"] = Features["vpclmulqdq"] = false;
531536
setXOPLevel(Features, FMA4, false);
532537
LLVM_FALLTHROUGH;
533538
case AVX2:

clang/test/CodeGen/attr-target-x86.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ int __attribute__((target("arch=lakemont,mmx"))) use_before_def(void) {
5050
// CHECK: use_before_def{{.*}} #7
5151
// CHECK: #0 = {{.*}}"target-cpu"="i686" "target-features"="+cx8,+x87"
5252
// CHECK: #1 = {{.*}}"target-cpu"="ivybridge" "target-features"="+avx,+cx16,+cx8,+f16c,+fsgsbase,+fxsr,+mmx,+pclmul,+popcnt,+rdrnd,+sahf,+sse,+sse2,+sse3,+sse4.1,+sse4.2,+ssse3,+x87,+xsave,+xsaveopt"
53-
// CHECK: #2 = {{.*}}"target-cpu"="i686" "target-features"="+cx8,+x87,-aes,-avx,-avx2,-avx512bf16,-avx512bitalg,-avx512bw,-avx512cd,-avx512dq,-avx512er,-avx512f,-avx512ifma,-avx512pf,-avx512vbmi,-avx512vbmi2,-avx512vl,-avx512vnni,-avx512vp2intersect,-avx512vpopcntdq,-f16c,-fma,-fma4,-gfni,-pclmul,-sha,-sse2,-sse3,-sse4.1,-sse4.2,-sse4a,-ssse3,-vaes,-vpclmulqdq,-xop,-xsave,-xsaveopt"
53+
// CHECK: #2 = {{.*}}"target-cpu"="i686" "target-features"="+cx8,+x87,-aes,-avx,-avx2,-avx512bf16,-avx512bitalg,-avx512bw,-avx512cd,-avx512dq,-avx512er,-avx512f,-avx512ifma,-avx512pf,-avx512vbmi,-avx512vbmi2,-avx512vl,-avx512vnni,-avx512vp2intersect,-avx512vpopcntdq,-f16c,-fma,-fma4,-gfni,-pclmul,-sha,-sse2,-sse3,-sse4.1,-sse4.2,-sse4a,-ssse3,-vaes,-vpclmulqdq,-xop"
5454
// CHECK: #3 = {{.*}}"target-cpu"="i686" "target-features"="+cx8,+mmx,+popcnt,+sse,+sse2,+sse3,+sse4.1,+sse4.2,+ssse3,+x87"
55-
// CHECK: #4 = {{.*}}"target-cpu"="i686" "target-features"="+cx8,+x87,-avx,-avx2,-avx512bf16,-avx512bitalg,-avx512bw,-avx512cd,-avx512dq,-avx512er,-avx512f,-avx512ifma,-avx512pf,-avx512vbmi,-avx512vbmi2,-avx512vl,-avx512vnni,-avx512vp2intersect,-avx512vpopcntdq,-f16c,-fma,-fma4,-sse4.1,-sse4.2,-vaes,-vpclmulqdq,-xop,-xsave,-xsaveopt"
55+
// CHECK: #4 = {{.*}}"target-cpu"="i686" "target-features"="+cx8,+x87,-avx,-avx2,-avx512bf16,-avx512bitalg,-avx512bw,-avx512cd,-avx512dq,-avx512er,-avx512f,-avx512ifma,-avx512pf,-avx512vbmi,-avx512vbmi2,-avx512vl,-avx512vnni,-avx512vp2intersect,-avx512vpopcntdq,-f16c,-fma,-fma4,-sse4.1,-sse4.2,-vaes,-vpclmulqdq,-xop"
5656
// CHECK: #5 = {{.*}}"target-cpu"="ivybridge" "target-features"="+avx,+cx16,+cx8,+f16c,+fsgsbase,+fxsr,+mmx,+pclmul,+popcnt,+rdrnd,+sahf,+sse,+sse2,+sse3,+sse4.1,+sse4.2,+ssse3,+x87,+xsave,+xsaveopt,-aes,-vaes"
5757
// CHECK: #6 = {{.*}}"target-cpu"="i686" "target-features"="+cx8,+x87,-3dnow,-3dnowa,-mmx"
5858
// CHECK: #7 = {{.*}}"target-cpu"="lakemont" "target-features"="+cx8,+mmx"

0 commit comments

Comments
 (0)