r190387 - Separate popcnt and sse4.2 feature control somewhat to match gcc behavior.

Craig Topper craig.topper at gmail.com
Mon Sep 9 23:55:47 PDT 2013


Author: ctopper
Date: Tue Sep 10 01:55:47 2013
New Revision: 190387

URL: http://llvm.org/viewvc/llvm-project?rev=190387&view=rev
Log:
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.


Modified:
    cfe/trunk/lib/Basic/Targets.cpp
    cfe/trunk/test/Preprocessor/x86_target_features.c

Modified: cfe/trunk/lib/Basic/Targets.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets.cpp?rev=190387&r1=190386&r2=190387&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/Targets.cpp (original)
+++ cfe/trunk/lib/Basic/Targets.cpp Tue Sep 10 01:55:47 2013
@@ -2133,7 +2133,7 @@ void X86TargetInfo::setSSELevel(llvm::St
     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::St
   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
     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) {

Modified: cfe/trunk/test/Preprocessor/x86_target_features.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/x86_target_features.c?rev=190387&r1=190386&r2=190387&view=diff
==============================================================================
--- cfe/trunk/test/Preprocessor/x86_target_features.c (original)
+++ cfe/trunk/test/Preprocessor/x86_target_features.c Tue Sep 10 01:55:47 2013
@@ -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





More information about the cfe-commits mailing list