summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCraig Topper <craig.topper@gmail.com>2013-09-10 06:55:47 +0000
committerCraig Topper <craig.topper@gmail.com>2013-09-10 06:55:47 +0000
commit7481d8aa17d2dbdaee878aeab34ea8e4fa38ae32 (patch)
tree553d6af4e9c0a3fdcad2da921a1dcb80ca6e836a
parent0229e3557ee3e430c09709ecebf2c0b25bfb41e4 (diff)
downloadbcm5719-llvm-7481d8aa17d2dbdaee878aeab34ea8e4fa38ae32.tar.gz
bcm5719-llvm-7481d8aa17d2dbdaee878aeab34ea8e4fa38ae32.zip
Separate popcnt and sse4.2 feature control somewhat to match gcc behavior.
Enabling sse4.2 will implicitly enable popcnt unless popcnt is explicitly disabled. Disabling sse4.2 will not disable popcnt if popcnt is explicitly enabled. llvm-svn: 190387
-rw-r--r--clang/lib/Basic/Targets.cpp13
-rw-r--r--clang/test/Preprocessor/x86_target_features.c12
2 files changed, 23 insertions, 2 deletions
diff --git a/clang/lib/Basic/Targets.cpp b/clang/lib/Basic/Targets.cpp
index 64b00d7fae3..665f1016334 100644
--- a/clang/lib/Basic/Targets.cpp
+++ b/clang/lib/Basic/Targets.cpp
@@ -2133,7 +2133,7 @@ void X86TargetInfo::setSSELevel(llvm::StringMap<bool> &Features,
case AVX:
Features["avx"] = true;
case SSE42:
- Features["popcnt"] = Features["sse4.2"] = true;
+ Features["sse4.2"] = true;
case SSE41:
Features["sse4.1"] = true;
case SSSE3:
@@ -2166,7 +2166,7 @@ void X86TargetInfo::setSSELevel(llvm::StringMap<bool> &Features,
case SSE41:
Features["sse4.1"] = false;
case SSE42:
- Features["popcnt"] = Features["sse4.2"] = false;
+ Features["sse4.2"] = false;
case AVX:
Features["fma"] = Features["avx"] = false;
setXOPLevel(Features, FMA4, false);
@@ -2406,6 +2406,15 @@ bool X86TargetInfo::HandleTargetFeatures(std::vector<std::string> &Features,
XOPLevel = std::max(XOPLevel, XLevel);
}
+ // Enable popcnt if sse4.2 is enabled and popcnt is not explicitly disabled.
+ // Can't do this earlier because we need to be able to explicitly enable
+ // popcnt and still disable sse4.2.
+ if (!HasPOPCNT && SSELevel >= SSE42 &&
+ std::find(Features.begin(), Features.end(), "-popcnt") == Features.end()){
+ HasPOPCNT = true;
+ Features.push_back("+popcnt");
+ }
+
// LLVM doesn't have a separate switch for fpmath, so only accept it if it
// matches the selected sse level.
if (FPMath == FP_SSE && SSELevel < SSE1) {
diff --git a/clang/test/Preprocessor/x86_target_features.c b/clang/test/Preprocessor/x86_target_features.c
index d6ddc01b53e..48d5bcb65b9 100644
--- a/clang/test/Preprocessor/x86_target_features.c
+++ b/clang/test/Preprocessor/x86_target_features.c
@@ -128,3 +128,15 @@
// AVX512F2: #define __SSE_MATH__ 1
// AVX512F2: #define __SSE__ 1
// AVX512F2: #define __SSSE3__ 1
+
+// RUN: %clang -target i386-unknown-unknown -march=atom -msse4.2 -x c -E -dM -o - %s | FileCheck --check-prefix=SSE42POPCNT %s
+
+// SSE42POPCNT: #define __POPCNT__ 1
+
+// RUN: %clang -target i386-unknown-unknown -march=atom -mno-popcnt -msse4.2 -x c -E -dM -o - %s | FileCheck --check-prefix=SSE42NOPOPCNT %s
+
+// SSE42NOPOPCNT-NOT: #define __POPCNT__ 1
+
+// RUN: %clang -target i386-unknown-unknown -march=atom -mpopcnt -mno-sse4.2 -x c -E -dM -o - %s | FileCheck --check-prefix=NOSSE42POPCNT %s
+
+// NOSSE42POPCNT: #define __POPCNT__ 1
OpenPOWER on IntegriCloud