Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions clang/lib/Basic/Targets/X86.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,14 @@ bool X86TargetInfo::initFeatureMap(
if (getTriple().getArch() == llvm::Triple::x86_64)
setFeatureEnabled(Features, "sse2", true);

// Enable SSE4.1 for Windows MSVC targets to support SIMD intrinsics like
// _mm_mullo_epi32 without requiring explicit /arch: flags.
if ((getTriple().getArch() == llvm::Triple::x86_64 ||
getTriple().getArch() == llvm::Triple::x86) &&
getTriple().isWindowsMSVCEnvironment()) {
setFeatureEnabled(Features, "sse4.1", true);
}

using namespace llvm::X86;

SmallVector<StringRef, 16> CPUFeatures;
Expand Down
18 changes: 18 additions & 0 deletions clang/test/CodeGen/x86-sse41-windows-msvc.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// RUN: %clang_cc1 -triple x86_64-pc-windows-msvc -emit-llvm %s -o - | FileCheck %s
// RUN: %clang_cc1 -triple i386-pc-windows-msvc -emit-llvm %s -o - | FileCheck %s
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm %s -o - | FileCheck %s --check-prefix=LINUX
// RUN: %clang_cc1 -triple i386-unknown-linux-gnu -emit-llvm %s -o - | FileCheck %s --check-prefix=LINUX

// This test verifies that SSE4.1 is enabled by default for Windows MSVC targets
// to support SIMD intrinsics like _mm_mullo_epi32

#include <immintrin.h>

__m128i test_sse41(void) {
__m128i a = _mm_set1_epi32(5);
__m128i b = _mm_set1_epi32(3);
return _mm_mullo_epi32(a, b);
}

// CHECK: "target-features"="+sse4.1"
// LINUX-NOT: "target-features"="+sse4.1"