Skip to content

[Driver] Default to -mv8plus on 32-bit Solaris/SPARC #150176

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 23, 2025

Conversation

rorth
Copy link
Collaborator

@rorth rorth commented Jul 23, 2025

While investigating PR #149990, I noticed that while both the Oracle Studio compilers and GCC default to -mv8plus on 32-bit Solaris/SPARC, Clang does not.

This patch fixes this by enabling the v8plus feature.

Tested on sparcv9-sun-solaris2.11 and sparc64-unknown-linux-gnu.

While investigating PR llvm#149990, I noticed that while both the Oracle Studio
compilers and GCC default to `-mv8plus` on 32-bit Solaris/SPARC, Clang
does not.

This patch fixes this by enabling the `v8plus` feature.

Tested on `sparcv9-sun-solaris2.11` and `sparc64-unknown-linux-gnu`.
@rorth rorth requested review from MaskRay and koachan July 23, 2025 07:12
@rorth rorth added clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl' platform:solaris labels Jul 23, 2025
@llvmbot llvmbot added clang Clang issues not falling into any other category backend:Sparc labels Jul 23, 2025
@llvmbot
Copy link
Member

llvmbot commented Jul 23, 2025

@llvm/pr-subscribers-clang
@llvm/pr-subscribers-backend-sparc

@llvm/pr-subscribers-clang-driver

Author: Rainer Orth (rorth)

Changes

While investigating PR #149990, I noticed that while both the Oracle Studio compilers and GCC default to -mv8plus on 32-bit Solaris/SPARC, Clang does not.

This patch fixes this by enabling the v8plus feature.

Tested on sparcv9-sun-solaris2.11 and sparc64-unknown-linux-gnu.


Full diff: https://github.com/llvm/llvm-project/pull/150176.diff

2 Files Affected:

  • (modified) clang/lib/Driver/ToolChains/Arch/Sparc.cpp (+12-1)
  • (modified) clang/test/Driver/sparc-target-features.c (+4)
diff --git a/clang/lib/Driver/ToolChains/Arch/Sparc.cpp b/clang/lib/Driver/ToolChains/Arch/Sparc.cpp
index 33331351244e1..94a94f1e9c487 100644
--- a/clang/lib/Driver/ToolChains/Arch/Sparc.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/Sparc.cpp
@@ -37,6 +37,13 @@ const char *sparc::getSparcAsmModeForCPU(StringRef Name,
         .Case("niagara4", "-Av9d")
         .Default(DefV9CPU);
   } else {
+    const char *DefV8CPU;
+
+    if (Triple.isOSSolaris())
+      DefV8CPU = "-Av8plus";
+    else
+      DefV8CPU = "-Av8";
+
     return llvm::StringSwitch<const char *>(Name)
         .Case("v8", "-Av8")
         .Case("supersparc", "-Av8")
@@ -72,7 +79,7 @@ const char *sparc::getSparcAsmModeForCPU(StringRef Name,
         .Case("gr712rc", "-Aleon")
         .Case("leon4", "-Aleon")
         .Case("gr740", "-Aleon")
-        .Default("-Av8");
+        .Default(DefV8CPU);
   }
 }
 
@@ -160,6 +167,8 @@ void sparc::getSparcTargetFeatures(const Driver &D, const llvm::Triple &Triple,
       (Triple.getArch() == llvm::Triple::sparcv9) &&
       (Triple.isOSLinux() || Triple.isOSFreeBSD() || Triple.isOSOpenBSD());
   bool IsSparcV9BTarget = Triple.isOSSolaris();
+  bool IsSparcV8PlusTarget =
+      Triple.getArch() == llvm::Triple::sparc && Triple.isOSSolaris();
   if (Arg *A = Args.getLastArg(options::OPT_mvis, options::OPT_mno_vis)) {
     if (A->getOption().matches(options::OPT_mvis))
       Features.push_back("+vis");
@@ -196,6 +205,8 @@ void sparc::getSparcTargetFeatures(const Driver &D, const llvm::Triple &Triple,
   if (Arg *A = Args.getLastArg(options::OPT_mv8plus, options::OPT_mno_v8plus)) {
     if (A->getOption().matches(options::OPT_mv8plus))
       Features.push_back("+v8plus");
+  } else if (IsSparcV8PlusTarget) {
+    Features.push_back("+v8plus");
   }
 
   if (Args.hasArg(options::OPT_ffixed_g1))
diff --git a/clang/test/Driver/sparc-target-features.c b/clang/test/Driver/sparc-target-features.c
index 48a180caf259b..bd17da112bbd2 100644
--- a/clang/test/Driver/sparc-target-features.c
+++ b/clang/test/Driver/sparc-target-features.c
@@ -39,4 +39,8 @@
 // SOFT-QUAD-FLOAT: "-target-feature" "-hard-quad-float"
 
 // RUN: %clang --target=sparc -mv8plus %s -### 2>&1 | FileCheck -check-prefix=V8PLUS %s
+/// 32-bit Solaris/SPARC defaults to -mv8plus
+// RUN: %clang --target=sparc-sun-solaris2.11 %s -### 2>&1 | FileCheck -check-prefix=V8PLUS %s
+// RUN: %clang --target=sparc-sun-solaris2.11 -mno-v8plus %s -### 2>&1 | FileCheck -check-prefix=NO-V8PLUS %s
 // V8PLUS: "-target-feature" "+v8plus"
+// NO-V8PLUS-NOT: "-target-feature" "+v8plus"

@rorth rorth merged commit 0623389 into llvm:main Jul 23, 2025
14 checks passed
mahesh-attarde pushed a commit to mahesh-attarde/llvm-project that referenced this pull request Jul 28, 2025
While investigating PR llvm#149990, I noticed that while both the Oracle
Studio compilers and GCC default to `-mv8plus` on 32-bit Solaris/SPARC,
Clang does not.

This patch fixes this by enabling the `v8plus` feature.

Tested on `sparcv9-sun-solaris2.11` and `sparc64-unknown-linux-gnu`.
tru pushed a commit to llvmbot/llvm-project that referenced this pull request Jul 28, 2025
While investigating PR llvm#149990, I noticed that while both the Oracle
Studio compilers and GCC default to `-mv8plus` on 32-bit Solaris/SPARC,
Clang does not.

This patch fixes this by enabling the `v8plus` feature.

Tested on `sparcv9-sun-solaris2.11` and `sparc64-unknown-linux-gnu`.

(cherry picked from commit 0623389)
tru pushed a commit to llvmbot/llvm-project that referenced this pull request Jul 29, 2025
While investigating PR llvm#149990, I noticed that while both the Oracle
Studio compilers and GCC default to `-mv8plus` on 32-bit Solaris/SPARC,
Clang does not.

This patch fixes this by enabling the `v8plus` feature.

Tested on `sparcv9-sun-solaris2.11` and `sparc64-unknown-linux-gnu`.

(cherry picked from commit 0623389)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend:Sparc clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl' clang Clang issues not falling into any other category platform:solaris
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants