Skip to content

Commit 20a60f4

Browse files
committed
[X86] Explicitly add popcnt feature to Intel CPUs with SSE4.2 in the frontend.
Previously we inferred it if sse4.2 ended up being enabled after all feature processing. But writing -march=nehalem -mno-sse4.2 should have popcnt enabled.
1 parent b07feef commit 20a60f4

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

clang/lib/Basic/Targets/X86.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ bool X86TargetInfo::initFeatureMap(
224224
LLVM_FALLTHROUGH;
225225
case CK_Nehalem:
226226
setFeatureEnabledImpl(Features, "sse4.2", true);
227+
setFeatureEnabledImpl(Features, "popcnt", true);
227228
LLVM_FALLTHROUGH;
228229
case CK_Penryn:
229230
setFeatureEnabledImpl(Features, "sse4.1", true);
@@ -281,6 +282,7 @@ bool X86TargetInfo::initFeatureMap(
281282
setFeatureEnabledImpl(Features, "rdrnd", true);
282283
setFeatureEnabledImpl(Features, "pclmul", true);
283284
setFeatureEnabledImpl(Features, "sse4.2", true);
285+
setFeatureEnabledImpl(Features, "popcnt", true);
284286
setFeatureEnabledImpl(Features, "prfchw", true);
285287
LLVM_FALLTHROUGH;
286288
case CK_Bonnell:
@@ -307,6 +309,7 @@ bool X86TargetInfo::initFeatureMap(
307309
setFeatureEnabledImpl(Features, "rdseed", true);
308310
setFeatureEnabledImpl(Features, "adx", true);
309311
setFeatureEnabledImpl(Features, "lzcnt", true);
312+
setFeatureEnabledImpl(Features, "popcnt", true);
310313
setFeatureEnabledImpl(Features, "bmi", true);
311314
setFeatureEnabledImpl(Features, "bmi2", true);
312315
setFeatureEnabledImpl(Features, "fma", true);

clang/test/Preprocessor/x86_target_features.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,12 @@
269269

270270
// NOSSE42POPCNT: #define __POPCNT__ 1
271271

272+
// RUN: %clang -target i386-unknown-unknown -march=nehalem -mno-sse4.2 -x c -E -dM -o - %s | FileCheck -match-full-lines --check-prefix=CPUPOPCNT %s
273+
// RUN: %clang -target i386-unknown-unknown -march=silvermont -mno-sse4.2 -x c -E -dM -o - %s | FileCheck -match-full-lines --check-prefix=CPUPOPCNT %s
274+
// RUN: %clang -target i386-unknown-unknown -march=knl -mno-sse4.2 -x c -E -dM -o - %s | FileCheck -match-full-lines --check-prefix=CPUPOPCNT %s
275+
276+
// CPUPOPCNT: #define __POPCNT__ 1
277+
272278
// RUN: %clang -target i386-unknown-unknown -march=pentium -msse -x c -E -dM -o - %s | FileCheck -match-full-lines --check-prefix=SSEMMX %s
273279

274280
// SSEMMX: #define __MMX__ 1

0 commit comments

Comments
 (0)