Skip to content

Commit c6d9b04

Browse files
committedJun 7, 2017
[mips] Add runtime options to enable/disable madd.fmt and msub.fmt
Add options to clang: -mmadd4 and -mno-madd4, use it to enable or disable generation of madd.fmt and similar instructions respectively, as per GCC. Patch by Stefan Maksimovic. Differential Revision: https://reviews.llvm.org/D33401 llvm-svn: 304929
1 parent 4b38652 commit c6d9b04

File tree

5 files changed

+114
-1
lines changed

5 files changed

+114
-1
lines changed
 

‎clang/include/clang/Driver/Options.td

+4
Original file line numberDiff line numberDiff line change
@@ -2001,6 +2001,10 @@ def mdspr2 : Flag<["-"], "mdspr2">, Group<m_Group>;
20012001
def mno_dspr2 : Flag<["-"], "mno-dspr2">, Group<m_Group>;
20022002
def msingle_float : Flag<["-"], "msingle-float">, Group<m_Group>;
20032003
def mdouble_float : Flag<["-"], "mdouble-float">, Group<m_Group>;
2004+
def mmadd4 : Flag<["-"], "mmadd4">, Group<m_Group>,
2005+
HelpText<"Enable the generation of 4-operand madd.s, madd.d and related instructions.">;
2006+
def mno_madd4 : Flag<["-"], "mno-madd4">, Group<m_Group>,
2007+
HelpText<"Disable the generation of 4-operand madd.s, madd.d and related instructions.">;
20042008
def mmsa : Flag<["-"], "mmsa">, Group<m_Group>,
20052009
HelpText<"Enable MSA ASE (MIPS only)">;
20062010
def mno_msa : Flag<["-"], "mno-msa">, Group<m_Group>,

‎clang/lib/Basic/Targets.cpp

+7-1
Original file line numberDiff line numberDiff line change
@@ -7737,6 +7737,7 @@ class MipsTargetInfo : public TargetInfo {
77377737
NoDSP, DSP1, DSP2
77387738
} DspRev;
77397739
bool HasMSA;
7740+
bool DisableMadd4;
77407741

77417742
protected:
77427743
bool HasFP64;
@@ -7747,7 +7748,7 @@ class MipsTargetInfo : public TargetInfo {
77477748
: TargetInfo(Triple), IsMips16(false), IsMicromips(false),
77487749
IsNan2008(false), IsSingleFloat(false), IsNoABICalls(false),
77497750
CanUseBSDABICalls(false), FloatABI(HardFloat), DspRev(NoDSP),
7750-
HasMSA(false), HasFP64(false) {
7751+
HasMSA(false), DisableMadd4(false), HasFP64(false) {
77517752
TheCXXABI.set(TargetCXXABI::GenericMIPS);
77527753

77537754
setABI((getTriple().getArch() == llvm::Triple::mips ||
@@ -7993,6 +7994,9 @@ class MipsTargetInfo : public TargetInfo {
79937994
if (HasMSA)
79947995
Builder.defineMacro("__mips_msa", Twine(1));
79957996

7997+
if (DisableMadd4)
7998+
Builder.defineMacro("__mips_no_madd4", Twine(1));
7999+
79968000
Builder.defineMacro("_MIPS_SZPTR", Twine(getPointerWidth(0)));
79978001
Builder.defineMacro("_MIPS_SZINT", Twine(getIntWidth()));
79988002
Builder.defineMacro("_MIPS_SZLONG", Twine(getLongWidth()));
@@ -8155,6 +8159,8 @@ class MipsTargetInfo : public TargetInfo {
81558159
DspRev = std::max(DspRev, DSP2);
81568160
else if (Feature == "+msa")
81578161
HasMSA = true;
8162+
else if (Feature == "+nomadd4")
8163+
DisableMadd4 = true;
81588164
else if (Feature == "+fp64")
81598165
HasFP64 = true;
81608166
else if (Feature == "-fp64")

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

+7
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,13 @@ void mips::getMIPSTargetFeatures(const Driver &D, const llvm::Triple &Triple,
298298

299299
AddTargetFeature(Args, Features, options::OPT_mno_odd_spreg,
300300
options::OPT_modd_spreg, "nooddspreg");
301+
302+
if (Arg *A = Args.getLastArg(options::OPT_mmadd4, options::OPT_mno_madd4)) {
303+
if (A->getOption().matches(options::OPT_mmadd4))
304+
Features.push_back("-nomadd4");
305+
else
306+
Features.push_back("+nomadd4");
307+
}
301308
}
302309

303310
mips::NanEncoding mips::getSupportedNanEncoding(StringRef &CPU) {

‎clang/test/CodeGen/mips-madd4.c

+86
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
// RUN: %clang --target=mips64-unknown-linux -S -mmadd4 %s -o -| FileCheck %s -check-prefix=MADD4
2+
// RUN: %clang --target=mips64-unknown-linux -S -mno-madd4 %s -o -| FileCheck %s -check-prefix=NOMADD4
3+
// RUN: %clang --target=mips64-unknown-linux -S -mmadd4 -fno-honor-nans %s -o -| FileCheck %s -check-prefix=MADD4-NONAN
4+
// RUN: %clang --target=mips64-unknown-linux -S -mno-madd4 -fno-honor-nans %s -o -| FileCheck %s -check-prefix=NOMADD4-NONAN
5+
6+
float madd_s (float f, float g, float h)
7+
{
8+
return (f * g) + h;
9+
}
10+
// MADD4: madd.s
11+
// NOMADD4: mul.s
12+
// NOMADD4: add.s
13+
14+
float msub_s (float f, float g, float h)
15+
{
16+
return (f * g) - h;
17+
}
18+
// MADD4: msub.s
19+
// NOMADD4: mul.s
20+
// NOMADD4: sub.s
21+
22+
double madd_d (double f, double g, double h)
23+
{
24+
return (f * g) + h;
25+
}
26+
// MADD4: madd.d
27+
// NOMADD4: mul.d
28+
// NOMADD4: add.d
29+
30+
double msub_d (double f, double g, double h)
31+
{
32+
return (f * g) - h;
33+
}
34+
// MADD4: msub.d
35+
// NOMADD4: mul.d
36+
// NOMADD4: sub.d
37+
38+
39+
float nmadd_s (float f, float g, float h)
40+
{
41+
// FIXME: Zero has been explicitly placed to force generation of a positive
42+
// zero in IR until pattern used to match this instruction is changed to
43+
// comply with negative zero as well.
44+
return 0-((f * g) + h);
45+
}
46+
// MADD4-NONAN: nmadd.s
47+
// NOMADD4-NONAN: mul.s
48+
// NOMADD4-NONAN: add.s
49+
// NOMADD4-NONAN: sub.s
50+
51+
float nmsub_s (float f, float g, float h)
52+
{
53+
// FIXME: Zero has been explicitly placed to force generation of a positive
54+
// zero in IR until pattern used to match this instruction is changed to
55+
// comply with negative zero as well.
56+
return 0-((f * g) - h);
57+
}
58+
// MADD4-NONAN: nmsub.s
59+
// NOMADD4-NONAN: mul.s
60+
// NOMADD4-NONAN: sub.s
61+
// NOMADD4-NONAN: sub.s
62+
63+
double nmadd_d (double f, double g, double h)
64+
{
65+
// FIXME: Zero has been explicitly placed to force generation of a positive
66+
// zero in IR until pattern used to match this instruction is changed to
67+
// comply with negative zero as well.
68+
return 0-((f * g) + h);
69+
}
70+
// MADD4-NONAN: nmadd.d
71+
// NOMADD4-NONAN: mul.d
72+
// NOMADD4-NONAN: add.d
73+
// NOMADD4-NONAN: sub.d
74+
75+
double nmsub_d (double f, double g, double h)
76+
{
77+
// FIXME: Zero has been explicitly placed to force generation of a positive
78+
// zero in IR until pattern used to match this instruction is changed to
79+
// comply with negative zero as well.
80+
return 0-((f * g) - h);
81+
}
82+
// MADD4-NONAN: nmsub.d
83+
// NOMADD4-NONAN: mul.d
84+
// NOMADD4-NONAN: sub.d
85+
// NOMADD4-NONAN: sub.d
86+

‎clang/test/Preprocessor/init.c

+10
Original file line numberDiff line numberDiff line change
@@ -4664,6 +4664,16 @@
46644664
// RUN: | FileCheck -match-full-lines -check-prefix MIPS-MSA %s
46654665
// MIPS-MSA:#define __mips_msa 1
46664666
//
4667+
// RUN: %clang_cc1 -target-feature +nomadd4 \
4668+
// RUN: -E -dM -triple=mips-none-none < /dev/null \
4669+
// RUN: | FileCheck -match-full-lines -check-prefix MIPS-NOMADD4 %s
4670+
// MIPS-NOMADD4:#define __mips_no_madd4 1
4671+
//
4672+
// RUN: %clang_cc1 \
4673+
// RUN: -E -dM -triple=mips-none-none < /dev/null \
4674+
// RUN: | FileCheck -match-full-lines -check-prefix MIPS-MADD4 %s
4675+
// MIPS-MADD4-NOT:#define __mips_no_madd4 1
4676+
//
46674677
// RUN: %clang_cc1 -target-cpu mips32r3 -target-feature +nan2008 \
46684678
// RUN: -E -dM -triple=mips-none-none < /dev/null \
46694679
// RUN: | FileCheck -match-full-lines -check-prefix MIPS-NAN2008 %s

0 commit comments

Comments
 (0)
Please sign in to comment.