Skip to content

Commit d59bc6b

Browse files
authored
Clang/MIPS: Add +fp64 if MSA and no explicit -mfp option (llvm#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.
1 parent eac743d commit d59bc6b

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

clang/lib/Driver/ToolChains/Arch/Mips.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,9 @@ void mips::getMIPSTargetFeatures(const Driver &D, const llvm::Triple &Triple,
369369
} else if (mips::isFP64ADefault(Triple, CPUName)) {
370370
Features.push_back("+fp64");
371371
Features.push_back("+nooddspreg");
372+
} else if (Arg *A = Args.getLastArg(options::OPT_mmsa)) {
373+
if (A->getOption().matches(options::OPT_mmsa))
374+
Features.push_back("+fp64");
372375
}
373376

374377
AddTargetFeature(Args, Features, options::OPT_mno_odd_spreg,
@@ -499,6 +502,13 @@ bool mips::shouldUseFPXX(const ArgList &Args, const llvm::Triple &Triple,
499502
options::OPT_mdouble_float))
500503
if (A->getOption().matches(options::OPT_msingle_float))
501504
UseFPXX = false;
505+
// FP64 should be used for MSA.
506+
if (Arg *A = Args.getLastArg(options::OPT_mmsa))
507+
if (A->getOption().matches(options::OPT_mmsa))
508+
UseFPXX = llvm::StringSwitch<bool>(CPUName)
509+
.Cases("mips32r2", "mips32r3", "mips32r5", false)
510+
.Cases("mips64r2", "mips64r3", "mips64r5", false)
511+
.Default(UseFPXX);
502512

503513
return UseFPXX;
504514
}

clang/test/Driver/mips-as.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@
266266
// RUN: %clang -target mips-linux-gnu -mno-msa -mmsa -### \
267267
// RUN: -no-integrated-as -fno-pic -c %s 2>&1 \
268268
// RUN: | FileCheck -check-prefix=MIPS-MSA %s
269-
// MIPS-MSA: as{{(.exe)?}}" "-march" "mips32r2" "-mabi" "32" "-mno-shared" "-call_nonpic" "-EB" "-mfpxx" "-mmsa"
269+
// MIPS-MSA: as{{(.exe)?}}" "-march" "mips32r2" "-mabi" "32" "-mno-shared" "-call_nonpic" "-EB" "-mmsa"
270270
//
271271
// RUN: %clang -target mips-linux-gnu -mmsa -mno-msa -### \
272272
// RUN: -no-integrated-as -fno-pic -c %s 2>&1 \

clang/test/Driver/mips-features.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,12 @@
163163
// RUN: | FileCheck --check-prefix=CHECK-NOMMSA %s
164164
// CHECK-NOMMSA: "-target-feature" "-msa"
165165
//
166+
// -mmsa
167+
// RUN: %clang -target mips-linux-gnu -### -c %s \
168+
// RUN: -mmsa 2>&1 \
169+
// RUN: | FileCheck --check-prefix=CHECK-MMSA-MFP64 %s
170+
// CHECK-MMSA-MFP64: "-target-feature" "+msa" "-target-feature" "+fp64"
171+
//
166172
// -mmt
167173
// RUN: %clang -target mips-linux-gnu -### -c %s \
168174
// RUN: -mno-mt -mmt 2>&1 \

0 commit comments

Comments
 (0)