Skip to content

Commit 2ca9097

Browse files
[clang] Enable SSE4.1 intrinsics for 32-bit x86 by default - Issue #172104
1 parent eb942b2 commit 2ca9097

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

clang/lib/Basic/Targets/X86.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,13 @@ bool X86TargetInfo::initFeatureMap(
153153
llvm::StringMap<bool> &Features, DiagnosticsEngine &Diags, StringRef CPU,
154154
const std::vector<std::string> &FeaturesVec) const {
155155
// FIXME: This *really* should not be here.
156-
// X86_64 always has SSE2.
157-
if (getTriple().getArch() == llvm::Triple::x86_64)
156+
// X86_64 always has SSE2 and SSE4.1 to support common SIMD intrinsics.
157+
// Also enable these for 32-bit x86 to ensure MSVC-compatible SIMD support.
158+
if (getTriple().getArch() == llvm::Triple::x86_64 ||
159+
getTriple().getArch() == llvm::Triple::x86) {
158160
setFeatureEnabled(Features, "sse2", true);
161+
setFeatureEnabled(Features, "sse4.1", true);
162+
}
159163

160164
using namespace llvm::X86;
161165

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// RUN: %clang_cc1 -x c -triple i386-pc-windows-msvc -fsyntax-only %s
2+
// RUN: %clang_cc1 -x c -triple x86_64-pc-windows-msvc -fsyntax-only %s
3+
// RUN: %clang_cc1 -x c -triple i386-unknown-linux-gnu -fsyntax-only %s
4+
// RUN: %clang_cc1 -x c -triple x86_64-unknown-linux-gnu -fsyntax-only %s
5+
6+
// This test verifies that SSE4.1 intrinsics are available by default
7+
// without requiring explicit /arch: or -msse4.1 flags.
8+
9+
#include <immintrin.h>
10+
11+
void test_sse41_intrinsics(void) {
12+
__m128i a = _mm_set1_epi32(1);
13+
__m128i b = _mm_set1_epi32(2);
14+
__m128i result = _mm_mullo_epi32(a, b);
15+
(void)result;
16+
}

0 commit comments

Comments
 (0)