Skip to content

Clang/MIPS: Add +fp64 if MSA and no explicit -mfp option #91949

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 2 commits into from
May 20, 2024

Conversation

wzssyqa
Copy link
Contributor

@wzssyqa wzssyqa commented May 13, 2024

MSA requires -mfp64. If FP64 is supported by CPU (mips32r2+), and no -mfp32/-mfpxx is explicitly given, let's add +fp64. Otherwise some cmd like
clang --target=mips -mips32r5 -mmsa
will issue LLVM backend ICE.

MSA requires -mfp64. If FP64 is supported by CPU (mips32r2+),
and no -mfp32/-mfpxx is explicitly given, let's add +fp64.
Otherwise some cmd like
   clang --target=mips -mips32r5 -mmsa
will issue LLVM backend ICE.
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl' labels May 13, 2024
@llvmbot
Copy link
Member

llvmbot commented May 13, 2024

@llvm/pr-subscribers-clang-driver

@llvm/pr-subscribers-clang

Author: YunQiang Su (wzssyqa)

Changes

MSA requires -mfp64. If FP64 is supported by CPU (mips32r2+), and no -mfp32/-mfpxx is explicitly given, let's add +fp64. Otherwise some cmd like
clang --target=mips -mips32r5 -mmsa
will issue LLVM backend ICE.


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

2 Files Affected:

  • (modified) clang/lib/Driver/ToolChains/Arch/Mips.cpp (+10)
  • (modified) clang/test/Driver/mips-features.c (+6)
diff --git a/clang/lib/Driver/ToolChains/Arch/Mips.cpp b/clang/lib/Driver/ToolChains/Arch/Mips.cpp
index 74a8874a3ea2b..79a00711e6f53 100644
--- a/clang/lib/Driver/ToolChains/Arch/Mips.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/Mips.cpp
@@ -369,6 +369,9 @@ void mips::getMIPSTargetFeatures(const Driver &D, const llvm::Triple &Triple,
   } else if (mips::isFP64ADefault(Triple, CPUName)) {
     Features.push_back("+fp64");
     Features.push_back("+nooddspreg");
+  } else if (Arg *A = Args.getLastArg(options::OPT_mmsa)) {
+    if (A->getOption().matches(options::OPT_mmsa))
+      Features.push_back("+fp64");
   }
 
   AddTargetFeature(Args, Features, options::OPT_mno_odd_spreg,
@@ -499,6 +502,13 @@ bool mips::shouldUseFPXX(const ArgList &Args, const llvm::Triple &Triple,
                                options::OPT_mdouble_float))
     if (A->getOption().matches(options::OPT_msingle_float))
       UseFPXX = false;
+  // FP64 should be used for MSA.
+  if (Arg *A = Args.getLastArg(options::OPT_mmsa))
+    if (A->getOption().matches(options::OPT_mmsa))
+      UseFPXX = llvm::StringSwitch<bool>(CPUName)
+                    .Cases("mips32r2", "mips32r3", "mips32r5", false)
+                    .Cases("mips64r2", "mips64r3", "mips64r5", false)
+                    .Default(UseFPXX);
 
   return UseFPXX;
 }
diff --git a/clang/test/Driver/mips-features.c b/clang/test/Driver/mips-features.c
index 5e92dccaa02ab..8b8db4c4a341b 100644
--- a/clang/test/Driver/mips-features.c
+++ b/clang/test/Driver/mips-features.c
@@ -163,6 +163,12 @@
 // RUN:   | FileCheck --check-prefix=CHECK-NOMMSA %s
 // CHECK-NOMMSA: "-target-feature" "-msa"
 //
+// -mmsa
+// RUN: %clang -target mips-linux-gnu -### -c %s \
+// RUN:     -mmsa 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-MMSA-MFP64 %s
+// CHECK-MMSA-MFP64: "-target-feature" "+msa" "-target-feature" "+fp64"
+//
 // -mmt
 // RUN: %clang -target mips-linux-gnu -### -c %s \
 // RUN:     -mno-mt -mmt 2>&1 \

@wzssyqa wzssyqa requested a review from jrtc27 May 15, 2024 02:56
@wzssyqa wzssyqa merged commit d59bc6b into llvm:main May 20, 2024
wzssyqa added a commit to wzssyqa/llvm-project that referenced this pull request May 20, 2024
Commit: d59bc6b
        Clang/MIPS: Add +fp64 if MSA and no explicit -mfp option (llvm#91949)
added +fp64 for `clang`, while not for `clang -cc1`. So

   clang -cc1 -triple=mips -target-feature +msa -S

will emit an asm source file without ".module fp=64".
wzssyqa added a commit that referenced this pull request May 21, 2024
…#92728)

Commit: d59bc6b
Clang/MIPS: Add +fp64 if MSA and no explicit -mfp option (#91949)
added +fp64 for `clang`, while not for `clang -cc1`. So

   clang -cc1 -triple=mips -target-feature +msa -S

will emit an asm source file without ".module fp=64".
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl' clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants