[clang] d59bc6b - Clang/MIPS: Add +fp64 if MSA and no explicit -mfp option (#91949)
via cfe-commits
cfe-commits at lists.llvm.org
Sun May 19 23:48:37 PDT 2024
Author: YunQiang Su
Date: 2024-05-20T14:48:34+08:00
New Revision: d59bc6b5c75384aa0b1e78cc85e17e8acaccebaf
URL: https://github.com/llvm/llvm-project/commit/d59bc6b5c75384aa0b1e78cc85e17e8acaccebaf
DIFF: https://github.com/llvm/llvm-project/commit/d59bc6b5c75384aa0b1e78cc85e17e8acaccebaf.diff
LOG: Clang/MIPS: Add +fp64 if MSA and no explicit -mfp option (#91949)
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.
Added:
Modified:
clang/lib/Driver/ToolChains/Arch/Mips.cpp
clang/test/Driver/mips-as.c
clang/test/Driver/mips-features.c
Removed:
################################################################################
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-as.c b/clang/test/Driver/mips-as.c
index 14fbb18c93500..a3399f1078fcd 100644
--- a/clang/test/Driver/mips-as.c
+++ b/clang/test/Driver/mips-as.c
@@ -266,7 +266,7 @@
// RUN: %clang -target mips-linux-gnu -mno-msa -mmsa -### \
// RUN: -no-integrated-as -fno-pic -c %s 2>&1 \
// RUN: | FileCheck -check-prefix=MIPS-MSA %s
-// MIPS-MSA: as{{(.exe)?}}" "-march" "mips32r2" "-mabi" "32" "-mno-shared" "-call_nonpic" "-EB" "-mfpxx" "-mmsa"
+// MIPS-MSA: as{{(.exe)?}}" "-march" "mips32r2" "-mabi" "32" "-mno-shared" "-call_nonpic" "-EB" "-mmsa"
//
// RUN: %clang -target mips-linux-gnu -mmsa -mno-msa -### \
// RUN: -no-integrated-as -fno-pic -c %s 2>&1 \
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 \
More information about the cfe-commits
mailing list