Skip to content

Commit 3e71357

Browse files
authored
[PPC] Disable vsx and altivec when -msoft-float is used (llvm#100450)
We emit an error when -msoft-float and -maltivec/-mvsx is used together, but when -msoft-float is used on its own, there is still +altivec and +vsx in the IR attributes. This patch disables altivec and vsx and all related sub features when -msoft-float is used.
1 parent a262ac0 commit 3e71357

File tree

3 files changed

+107
-33
lines changed

3 files changed

+107
-33
lines changed

clang/lib/Basic/Targets/PPC.cpp

Lines changed: 41 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -469,21 +469,36 @@ void PPCTargetInfo::getTargetDefines(const LangOptions &Opts,
469469
// set of options.
470470
static bool ppcUserFeaturesCheck(DiagnosticsEngine &Diags,
471471
const std::vector<std::string> &FeaturesVec) {
472-
// Cannot allow soft-float with Altivec.
473-
if (llvm::is_contained(FeaturesVec, "-hard-float") &&
474-
llvm::is_contained(FeaturesVec, "+altivec")) {
475-
Diags.Report(diag::err_opt_not_valid_with_opt) << "-msoft-float"
476-
<< "-maltivec";
472+
auto FindVSXSubfeature = [&](StringRef Feature, StringRef SubOption,
473+
StringRef Option) {
474+
if (llvm::is_contained(FeaturesVec, Feature)) {
475+
Diags.Report(diag::err_opt_not_valid_with_opt) << SubOption << Option;
476+
return true;
477+
}
477478
return false;
478-
}
479+
};
479480

480-
// Cannot allow soft-float with VSX.
481-
if (llvm::is_contained(FeaturesVec, "-hard-float") &&
482-
llvm::is_contained(FeaturesVec, "+vsx")) {
483-
Diags.Report(diag::err_opt_not_valid_with_opt) << "-msoft-float"
484-
<< "-mvsx";
485-
return false;
481+
// Cannot allow soft-float with VSX, Altivec, or any
482+
// VSX subfeatures.
483+
bool Found = false;
484+
if (llvm::is_contained(FeaturesVec, "-hard-float")) {
485+
Found |= FindVSXSubfeature("+vsx", "-mvsx", "-msoft-float");
486+
Found |= FindVSXSubfeature("+altivec", "-maltivec", "-msoft-float");
487+
Found |=
488+
FindVSXSubfeature("+power8-vector", "-mpower8-vector", "-msoft-float");
489+
Found |= FindVSXSubfeature("+direct-move", "-mdirect-move", "-msoft-float");
490+
Found |= FindVSXSubfeature("+float128", "-mfloat128", "-msoft-float");
491+
Found |=
492+
FindVSXSubfeature("+power9-vector", "-mpower9-vector", "-msoft-float");
493+
Found |= FindVSXSubfeature("+paired-vector-memops",
494+
"-mpaired-vector-memops", "-msoft-float");
495+
Found |= FindVSXSubfeature("+mma", "-mmma", "-msoft-float");
496+
Found |= FindVSXSubfeature("+crypto", "-mcrypto", "-msoft-float");
497+
Found |= FindVSXSubfeature("+power10-vector", "-mpower10-vector",
498+
"-msoft-float");
486499
}
500+
if (Found)
501+
return false;
487502

488503
// Cannot allow VSX with no Altivec.
489504
if (llvm::is_contained(FeaturesVec, "+vsx") &&
@@ -497,21 +512,14 @@ static bool ppcUserFeaturesCheck(DiagnosticsEngine &Diags,
497512
if (!llvm::is_contained(FeaturesVec, "-vsx"))
498513
return true;
499514

500-
auto FindVSXSubfeature = [&](StringRef Feature, StringRef Option) {
501-
if (llvm::is_contained(FeaturesVec, Feature)) {
502-
Diags.Report(diag::err_opt_not_valid_with_opt) << Option << "-mno-vsx";
503-
return true;
504-
}
505-
return false;
506-
};
507-
508-
bool Found = FindVSXSubfeature("+power8-vector", "-mpower8-vector");
509-
Found |= FindVSXSubfeature("+direct-move", "-mdirect-move");
510-
Found |= FindVSXSubfeature("+float128", "-mfloat128");
511-
Found |= FindVSXSubfeature("+power9-vector", "-mpower9-vector");
512-
Found |= FindVSXSubfeature("+paired-vector-memops", "-mpaired-vector-memops");
513-
Found |= FindVSXSubfeature("+mma", "-mmma");
514-
Found |= FindVSXSubfeature("+power10-vector", "-mpower10-vector");
515+
Found = FindVSXSubfeature("+power8-vector", "-mpower8-vector", "-mno-vsx");
516+
Found |= FindVSXSubfeature("+direct-move", "-mdirect-move", "-mno-vsx");
517+
Found |= FindVSXSubfeature("+float128", "-mfloat128", "-mno-vsx");
518+
Found |= FindVSXSubfeature("+power9-vector", "-mpower9-vector", "-mno-vsx");
519+
Found |= FindVSXSubfeature("+paired-vector-memops", "-mpaired-vector-memops",
520+
"-mno-vsx");
521+
Found |= FindVSXSubfeature("+mma", "-mmma", "-mno-vsx");
522+
Found |= FindVSXSubfeature("+power10-vector", "-mpower10-vector", "-mno-vsx");
515523

516524
// Return false if any vsx subfeatures was found.
517525
return !Found;
@@ -693,7 +701,6 @@ bool PPCTargetInfo::initFeatureMap(
693701
Diags.Report(diag::err_opt_not_valid_with_opt) << "-mprivileged" << CPU;
694702
return false;
695703
}
696-
697704
return TargetInfo::initFeatureMap(Features, Diags, CPU, FeaturesVec);
698705
}
699706

@@ -783,13 +790,16 @@ void PPCTargetInfo::setFeatureEnabled(llvm::StringMap<bool> &Features,
783790
} else {
784791
if (Name == "spe")
785792
Features["efpu2"] = false;
786-
// If we're disabling altivec or vsx go ahead and disable all of the vsx
787-
// features.
788-
if ((Name == "altivec") || (Name == "vsx"))
793+
// If we're disabling altivec, hard-float, or vsx go ahead and disable all
794+
// of the vsx features.
795+
if ((Name == "altivec") || (Name == "vsx") || (Name == "hard-float")) {
796+
if (Name != "vsx")
797+
Features["altivec"] = Features["crypto"] = false;
789798
Features["vsx"] = Features["direct-move"] = Features["power8-vector"] =
790799
Features["float128"] = Features["power9-vector"] =
791800
Features["paired-vector-memops"] = Features["mma"] =
792801
Features["power10-vector"] = false;
802+
}
793803
if (Name == "power8-vector")
794804
Features["power9-vector"] = Features["paired-vector-memops"] =
795805
Features["mma"] = Features["power10-vector"] = false;

clang/test/Driver/ppc-dependent-options.cpp

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,34 @@
8989
// RUN: -std=c++11 -msoft-float -mvsx %s 2>&1 | \
9090
// RUN: FileCheck %s -check-prefix=CHECK-SOFTFLT-VSX
9191

92+
// RUN: not %clang -target powerpc64le-unknown-unknown -fsyntax-only \
93+
// RUN: -std=c++11 -msoft-float -mpower8-vector %s 2>&1 | \
94+
// RUN: FileCheck %s -check-prefix=CHECK-SOFTFLT-P8VEC
95+
96+
// RUN: not %clang -target powerpc64le-unknown-unknown -fsyntax-only \
97+
// RUN: -std=c++11 -msoft-float -mpower9-vector %s 2>&1 | \
98+
// RUN: FileCheck %s -check-prefix=CHECK-SOFTFLT-P9VEC
99+
100+
// RUN: not %clang -target powerpc64le-unknown-unknown -fsyntax-only \
101+
// RUN: -std=c++11 -msoft-float -mpower10-vector %s 2>&1 | \
102+
// RUN: FileCheck %s -check-prefix=CHECK-SOFTFLT-P10VEC
103+
104+
// RUN: not %clang -target powerpc64le-unknown-unknown -fsyntax-only \
105+
// RUN: -std=c++11 -msoft-float -mdirect-move %s 2>&1 | \
106+
// RUN: FileCheck %s -check-prefix=CHECK-SOFTFLT-DIRECTMOVE
107+
108+
// RUN: not %clang -target powerpc64le-unknown-unknown -fsyntax-only \
109+
// RUN: -std=c++11 -msoft-float -mmma %s 2>&1 | \
110+
// RUN: FileCheck %s -check-prefix=CHECK-SOFTFLT-MMA
111+
112+
// RUN: not %clang -target powerpc64le-unknown-unknown -fsyntax-only \
113+
// RUN: -std=c++11 -msoft-float -mpaired-vector-memops %s 2>&1 | \
114+
// RUN: FileCheck %s -check-prefix=CHECK-SOFTFLT-PAIREDVECMEMOP
115+
116+
// RUN: not %clang -target powerpc64le-unknown-unknown -fsyntax-only \
117+
// RUN: -std=c++11 -msoft-float -mcrypto %s 2>&1 | \
118+
// RUN: FileCheck %s -check-prefix=CHECK-SOFTFLT-CRYPTO
119+
92120
#ifdef __VSX__
93121
static_assert(false, "VSX enabled");
94122
#endif
@@ -126,5 +154,13 @@ static_assert(false, "Neither enabled");
126154
// CHECK-NVSX: Neither enabled
127155
// CHECK-VSX: VSX enabled
128156
// CHECK-NALTI-VSX: error: option '-mvsx' cannot be specified with '-mno-altivec'
129-
// CHECK-SOFTFLT-ALTI: error: option '-msoft-float' cannot be specified with '-maltivec'
130-
// CHECK-SOFTFLT-VSX: error: option '-msoft-float' cannot be specified with '-mvsx'
157+
// CHECK-SOFTFLT-ALTI: error: option '-maltivec' cannot be specified with '-msoft-float'
158+
// CHECK-SOFTFLT-VSX: error: option '-mvsx' cannot be specified with '-msoft-float'
159+
// CHECK-SOFTFLT-FLOAT128: error: option '-mfloat128' cannot be specified with '-msoft-float'
160+
// CHECK-SOFTFLT-P8VEC: error: option '-mpower8-vector' cannot be specified with '-msoft-float'
161+
// CHECK-SOFTFLT-P9VEC: error: option '-mpower9-vector' cannot be specified with '-msoft-float'
162+
// CHECK-SOFTFLT-P10VEC: error: option '-mpower10-vector' cannot be specified with '-msoft-float'
163+
// CHECK-SOFTFLT-DIRECTMOVE: error: option '-mdirect-move' cannot be specified with '-msoft-float'
164+
// CHECK-SOFTFLT-MMA: error: option '-mmma' cannot be specified with '-msoft-float'
165+
// CHECK-SOFTFLT-PAIREDVECMEMOP: error: option '-mpaired-vector-memops' cannot be specified with '-msoft-float'
166+
// CHECK-SOFTFLT-CRYPTO: error: option '-mcrypto' cannot be specified with '-msoft-float'

clang/test/Driver/ppc-soft-float.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// RUN: %clang -target powerpc64-unknown-unknown -mcpu=pwr10 -msoft-float -S -emit-llvm %s -o - | FileCheck %s -check-prefix=CHECKSOFT
2+
// RUN: %clang -target powerpc64-unknown-unknown -mcpu=pwr10 -S -emit-llvm %s -o - | FileCheck %s -check-prefix=CHECKNOSOFT
3+
4+
int main () {
5+
return 0;
6+
}
7+
8+
// CHECKSOFT-DAG: -hard-float
9+
// CHECKSOFT-DAG: -vsx
10+
// CHECKSOFT-DAG: -altivec
11+
// CHECKSOFT-DAG: -direct-move
12+
// CHECKSOFT-DAG: -float128
13+
// CHECKSOFT-DAG: -mma
14+
// CHECKSOFT-DAG: -paired-vector-memops
15+
// CHECKSOFT-DAG: -power10-vector
16+
// CHECKSOFT-DAG: -power9-vector
17+
// CHECKSOFT-DAG: -power8-vector
18+
// CHECKSOFT-DAG: -crypto
19+
20+
// CHECKNOSOFT-DAG: +vsx
21+
// CHECKNOSOFT-DAG: +altivec
22+
// CHECKNOSOFT-DAG: +direct-move
23+
// CHECKNOSOFT-DAG: +mma
24+
// CHECKNOSOFT-DAG: +paired-vector-memops
25+
// CHECKNOSOFT-DAG: +power10-vector
26+
// CHECKNOSOFT-DAG: +power9-vector
27+
// CHECKNOSOFT-DAG: +power8-vector
28+
// CHECKNOSOFT-DAG: +crypto

0 commit comments

Comments
 (0)