Skip to content

Commit 945ed22

Browse files
committed
[X86] Move the implicit enabling of sse2 for 64-bit mode from X86Subtarget::initSubtargetFeatures to X86_MC::ParseX86Triple.
ParseX86Triple already checks for 64-bit mode and produces a static string. We can just add +sse2 to the end of that static string. This avoids a potential reallocation when appending it to the std::string at runtime. This is a slight change to the behavior of tools that only use MC layer which weren't implicitly enabling sse2 before, but will now. I don't think we check for sse2 explicitly in any MC layer components so this shouldn't matter in practice. And if it did matter the new behavior is more correct.
1 parent 809600d commit 945ed22

File tree

2 files changed

+4
-7
lines changed

2 files changed

+4
-7
lines changed

llvm/lib/Target/X86/MCTargetDesc/X86MCTargetDesc.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,10 @@ using namespace llvm;
4444

4545
std::string X86_MC::ParseX86Triple(const Triple &TT) {
4646
std::string FS;
47-
if (TT.getArch() == Triple::x86_64)
48-
FS = "+64bit-mode,-32bit-mode,-16bit-mode";
47+
// SSE2 should default to enabled in 64-bit mode, but can be turned off
48+
// explicitly.
49+
if (TT.isArch64Bit())
50+
FS = "+64bit-mode,-32bit-mode,-16bit-mode,+sse2";
4951
else if (TT.getEnvironment() != Triple::CODE16)
5052
FS = "-64bit-mode,+32bit-mode,-16bit-mode";
5153
else

llvm/lib/Target/X86/X86Subtarget.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -234,11 +234,6 @@ void X86Subtarget::initSubtargetFeatures(StringRef CPU, StringRef FS) {
234234
std::string FullFS = X86_MC::ParseX86Triple(TargetTriple);
235235
assert(!FullFS.empty() && "Failed to parse X86 triple");
236236

237-
// SSE2 should default to enabled in 64-bit mode, but can be turned off
238-
// explicitly.
239-
if (TargetTriple.isArch64Bit())
240-
FullFS += ",+sse2";
241-
242237
if (!FS.empty())
243238
FullFS = (Twine(FullFS) + "," + FS).str();
244239

0 commit comments

Comments
 (0)