Skip to content

Commit c688d64

Browse files
[clang] Enable SSE4.1 intrinsics for Windows MSVC targets - Issue #172104
1 parent f3c1645 commit c688d64

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

clang/lib/Basic/Targets/X86.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,14 @@ bool X86TargetInfo::initFeatureMap(
157157
if (getTriple().getArch() == llvm::Triple::x86_64)
158158
setFeatureEnabled(Features, "sse2", true);
159159

160+
// Enable SSE4.1 for Windows MSVC targets to support SIMD intrinsics like
161+
// _mm_mullo_epi32 without requiring explicit /arch: flags.
162+
if ((getTriple().getArch() == llvm::Triple::x86_64 ||
163+
getTriple().getArch() == llvm::Triple::x86) &&
164+
getTriple().isWindowsMSVCEnvironment()) {
165+
setFeatureEnabled(Features, "sse4.1", true);
166+
}
167+
160168
using namespace llvm::X86;
161169

162170
SmallVector<StringRef, 16> CPUFeatures;
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// RUN: %clang_cc1 -triple x86_64-pc-windows-msvc -emit-llvm %s -o - | FileCheck %s
2+
// RUN: %clang_cc1 -triple i386-pc-windows-msvc -emit-llvm %s -o - | FileCheck %s
3+
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm %s -o - | FileCheck %s --check-prefix=LINUX
4+
// RUN: %clang_cc1 -triple i386-unknown-linux-gnu -emit-llvm %s -o - | FileCheck %s --check-prefix=LINUX
5+
6+
// This test verifies that SSE4.1 is enabled by default for Windows MSVC targets
7+
// to support SIMD intrinsics like _mm_mullo_epi32
8+
9+
#include <immintrin.h>
10+
11+
__m128i test_sse41(void) {
12+
__m128i a = _mm_set1_epi32(5);
13+
__m128i b = _mm_set1_epi32(3);
14+
return _mm_mullo_epi32(a, b);
15+
}
16+
17+
// CHECK: "target-features"="+sse4.1"
18+
// LINUX-NOT: "target-features"="+sse4.1"

0 commit comments

Comments
 (0)