[clang] [PPC] Disable vsx and altivec when -msoft-float is used (PR #100450)

Zaara Syeda via cfe-commits cfe-commits at lists.llvm.org
Mon Jul 29 10:56:58 PDT 2024


https://github.com/syzaara updated https://github.com/llvm/llvm-project/pull/100450

>From eac208b559feb3ccdfbd1d2ee6bcdd20db32f6a7 Mon Sep 17 00:00:00 2001
From: Zaara Syeda <syzaara at cpap8104.rtp.raleigh.ibm.com>
Date: Wed, 24 Jul 2024 14:58:53 -0400
Subject: [PATCH 1/2] [PPC] Disable vsx and altivec when -msoft-float is used

---
 clang/lib/Basic/Targets/PPC.cpp    |  5 +++++
 clang/test/Driver/ppc-soft-float.c | 13 +++++++++++++
 2 files changed, 18 insertions(+)
 create mode 100644 clang/test/Driver/ppc-soft-float.c

diff --git a/clang/lib/Basic/Targets/PPC.cpp b/clang/lib/Basic/Targets/PPC.cpp
index 9ff54083c923b..2b25cb189279a 100644
--- a/clang/lib/Basic/Targets/PPC.cpp
+++ b/clang/lib/Basic/Targets/PPC.cpp
@@ -690,6 +690,11 @@ bool PPCTargetInfo::initFeatureMap(
     return false;
   }
 
+  if (llvm::is_contained(FeaturesVec, "-hard-float")) {
+    Features["altivec"] = false;
+    Features["vsx"] = false;
+  }
+
   return TargetInfo::initFeatureMap(Features, Diags, CPU, FeaturesVec);
 }
 
diff --git a/clang/test/Driver/ppc-soft-float.c b/clang/test/Driver/ppc-soft-float.c
new file mode 100644
index 0000000000000..7b9205662ffeb
--- /dev/null
+++ b/clang/test/Driver/ppc-soft-float.c
@@ -0,0 +1,13 @@
+// RUN: %clang -target powerpc64-unknown-unknown -mcpu=pwr10 -msoft-float -S -emit-llvm %s -o - | FileCheck %s -check-prefix=CHECKSOFT
+// RUN: %clang -target powerpc64-unknown-unknown -mcpu=pwr10 -S -emit-llvm %s -o - | FileCheck %s -check-prefix=CHECKNOSOFT
+
+int main () {
+  return 0;
+}
+
+// CHECKSOFT-DAG: -hard-float
+// CHECKSOFT-DAG: -vsx
+// CHECKSOFT-DAG: -altivec
+
+// CHECKNOSOFT-DAG: +vsx
+// CHECKNOSOFT-DAG: +altivec

>From 6f1f08ef804fb4730c1a406afcdfd5494c79faea Mon Sep 17 00:00:00 2001
From: Zaara Syeda <syzaara at cpap8104.rtp.raleigh.ibm.com>
Date: Mon, 29 Jul 2024 13:50:52 -0400
Subject: [PATCH 2/2] Address review comments

---
 clang/lib/Basic/Targets/PPC.cpp             | 68 +++++++++++++--------
 clang/test/Driver/ppc-dependent-options.cpp | 35 ++++++++++-
 clang/test/Driver/ppc-soft-float.c          | 13 ++++
 3 files changed, 87 insertions(+), 29 deletions(-)

diff --git a/clang/lib/Basic/Targets/PPC.cpp b/clang/lib/Basic/Targets/PPC.cpp
index 2b25cb189279a..3b3aec4c414eb 100644
--- a/clang/lib/Basic/Targets/PPC.cpp
+++ b/clang/lib/Basic/Targets/PPC.cpp
@@ -465,21 +465,35 @@ void PPCTargetInfo::getTargetDefines(const LangOptions &Opts,
 // set of options.
 static bool ppcUserFeaturesCheck(DiagnosticsEngine &Diags,
                                  const std::vector<std::string> &FeaturesVec) {
-  // Cannot allow soft-float with Altivec.
-  if (llvm::is_contained(FeaturesVec, "-hard-float") &&
-      llvm::is_contained(FeaturesVec, "+altivec")) {
-    Diags.Report(diag::err_opt_not_valid_with_opt) << "-msoft-float"
-                                                   << "-maltivec";
+  auto FindVSXSubfeature = [&](StringRef Feature, StringRef SubOption,
+                               StringRef Option) {
+    if (llvm::is_contained(FeaturesVec, Feature)) {
+      Diags.Report(diag::err_opt_not_valid_with_opt) << SubOption << Option;
+      return true;
+    }
     return false;
-  }
+  };
 
-  // Cannot allow soft-float with VSX.
-  if (llvm::is_contained(FeaturesVec, "-hard-float") &&
-      llvm::is_contained(FeaturesVec, "+vsx")) {
-    Diags.Report(diag::err_opt_not_valid_with_opt) << "-msoft-float"
-                                                   << "-mvsx";
-    return false;
+  // Cannot allow soft-float with VSX, Altivec, or any
+  // VSX subfeatures.
+  bool Found = false;
+  if (llvm::is_contained(FeaturesVec, "-hard-float")) {
+    Found |= FindVSXSubfeature("+vsx", "-mvsx", "-msoft-float");
+    Found |= FindVSXSubfeature("+altivec", "-maltivec", "-msoft-float");
+    Found |=
+        FindVSXSubfeature("+power8-vector", "-mpower8-vector", "-msoft-float");
+    Found |= FindVSXSubfeature("+direct-move", "-mdirect-move", "-msoft-float");
+    Found |= FindVSXSubfeature("+float128", "-mfloat128", "-msoft-float");
+    Found |=
+        FindVSXSubfeature("+power9-vector", "-mpower9-vector", "-msoft-float");
+    Found |= FindVSXSubfeature("+paired-vector-memops",
+                               "-mpaired-vector-memops", "-msoft-float");
+    Found |= FindVSXSubfeature("+mma", "-mmma", "-msoft-float");
+    Found |= FindVSXSubfeature("+power10-vector", "-mpower10-vector",
+                               "-msoft-float");
   }
+  if (Found)
+    return false;
 
   // Cannot allow VSX with no Altivec.
   if (llvm::is_contained(FeaturesVec, "+vsx") &&
@@ -493,21 +507,14 @@ static bool ppcUserFeaturesCheck(DiagnosticsEngine &Diags,
   if (!llvm::is_contained(FeaturesVec, "-vsx"))
     return true;
 
-  auto FindVSXSubfeature = [&](StringRef Feature, StringRef Option) {
-    if (llvm::is_contained(FeaturesVec, Feature)) {
-      Diags.Report(diag::err_opt_not_valid_with_opt) << Option << "-mno-vsx";
-      return true;
-    }
-    return false;
-  };
-
-  bool Found = FindVSXSubfeature("+power8-vector", "-mpower8-vector");
-  Found |= FindVSXSubfeature("+direct-move", "-mdirect-move");
-  Found |= FindVSXSubfeature("+float128", "-mfloat128");
-  Found |= FindVSXSubfeature("+power9-vector", "-mpower9-vector");
-  Found |= FindVSXSubfeature("+paired-vector-memops", "-mpaired-vector-memops");
-  Found |= FindVSXSubfeature("+mma", "-mmma");
-  Found |= FindVSXSubfeature("+power10-vector", "-mpower10-vector");
+  Found = FindVSXSubfeature("+power8-vector", "-mpower8-vector", "-mno-vsx");
+  Found |= FindVSXSubfeature("+direct-move", "-mdirect-move", "-mno-vsx");
+  Found |= FindVSXSubfeature("+float128", "-mfloat128", "-mno-vsx");
+  Found |= FindVSXSubfeature("+power9-vector", "-mpower9-vector", "-mno-vsx");
+  Found |= FindVSXSubfeature("+paired-vector-memops", "-mpaired-vector-memops",
+                             "-mno-vsx");
+  Found |= FindVSXSubfeature("+mma", "-mmma", "-mno-vsx");
+  Found |= FindVSXSubfeature("+power10-vector", "-mpower10-vector", "-mno-vsx");
 
   // Return false if any vsx subfeatures was found.
   return !Found;
@@ -693,6 +700,13 @@ bool PPCTargetInfo::initFeatureMap(
   if (llvm::is_contained(FeaturesVec, "-hard-float")) {
     Features["altivec"] = false;
     Features["vsx"] = false;
+    Features["direct-move"] = false;
+    Features["power8-vector"] = false;
+    Features["power9-vector"] = false;
+    Features["paired-vector-memops"] = false;
+    Features["power10-vector"] = false;
+    Features["float128"] = false;
+    Features["mma"] = false;
   }
 
   return TargetInfo::initFeatureMap(Features, Diags, CPU, FeaturesVec);
diff --git a/clang/test/Driver/ppc-dependent-options.cpp b/clang/test/Driver/ppc-dependent-options.cpp
index 414ed1e70bb30..b62ed399054af 100644
--- a/clang/test/Driver/ppc-dependent-options.cpp
+++ b/clang/test/Driver/ppc-dependent-options.cpp
@@ -89,6 +89,30 @@
 // RUN: -std=c++11 -msoft-float -mvsx %s 2>&1 | \
 // RUN: FileCheck %s -check-prefix=CHECK-SOFTFLT-VSX
 
+// RUN: not %clang -target powerpc64le-unknown-unknown -fsyntax-only \
+// RUN: -std=c++11 -msoft-float -mpower8-vector %s 2>&1 | \
+// RUN: FileCheck %s -check-prefix=CHECK-SOFTFLT-P8VEC
+
+// RUN: not %clang -target powerpc64le-unknown-unknown -fsyntax-only \
+// RUN: -std=c++11 -msoft-float -mpower9-vector %s 2>&1 | \
+// RUN: FileCheck %s -check-prefix=CHECK-SOFTFLT-P9VEC
+
+// RUN: not %clang -target powerpc64le-unknown-unknown -fsyntax-only \
+// RUN: -std=c++11 -msoft-float -mpower10-vector %s 2>&1 | \
+// RUN: FileCheck %s -check-prefix=CHECK-SOFTFLT-P10VEC
+
+// RUN: not %clang -target powerpc64le-unknown-unknown -fsyntax-only \
+// RUN: -std=c++11 -msoft-float -mdirect-move %s 2>&1 | \
+// RUN: FileCheck %s -check-prefix=CHECK-SOFTFLT-DIRECTMOVE
+
+// RUN: not %clang -target powerpc64le-unknown-unknown -fsyntax-only \
+// RUN: -std=c++11 -msoft-float -mmma %s 2>&1 | \
+// RUN: FileCheck %s -check-prefix=CHECK-SOFTFLT-MMA
+
+// RUN: not %clang -target powerpc64le-unknown-unknown -fsyntax-only \
+// RUN: -std=c++11 -msoft-float -mpaired-vector-memops %s 2>&1 | \
+// RUN: FileCheck %s -check-prefix=CHECK-SOFTFLT-PAIREDVECMEMOP
+
 #ifdef __VSX__
 static_assert(false, "VSX enabled");
 #endif
@@ -126,5 +150,12 @@ static_assert(false, "Neither enabled");
 // CHECK-NVSX: Neither enabled
 // CHECK-VSX: VSX enabled
 // CHECK-NALTI-VSX: error: option '-mvsx' cannot be specified with '-mno-altivec'
-// CHECK-SOFTFLT-ALTI: error: option '-msoft-float' cannot be specified with '-maltivec'
-// CHECK-SOFTFLT-VSX: error: option '-msoft-float' cannot be specified with '-mvsx'
+// CHECK-SOFTFLT-ALTI: error: option '-maltivec' cannot be specified with '-msoft-float'
+// CHECK-SOFTFLT-VSX: error: option '-mvsx' cannot be specified with '-msoft-float'
+// CHECK-SOFTFLT-FLOAT128: error: option '-mfloat128' cannot be specified with '-msoft-float'
+// CHECK-SOFTFLT-P8VEC: error: option '-mpower8-vector' cannot be specified with '-msoft-float'
+// CHECK-SOFTFLT-P9VEC: error: option '-mpower9-vector' cannot be specified with '-msoft-float'
+// CHECK-SOFTFLT-P10VEC: error: option '-mpower10-vector' cannot be specified with '-msoft-float'
+// CHECK-SOFTFLT-DIRECTMOVE: error: option '-mdirect-move' cannot be specified with '-msoft-float'
+// CHECK-SOFTFLT-MMA: error: option '-mmma' cannot be specified with '-msoft-float'
+// CHECK-SOFTFLT-PAIREDVECMEMOP: error: option '-mpaired-vector-memops' cannot be specified with '-msoft-float'
diff --git a/clang/test/Driver/ppc-soft-float.c b/clang/test/Driver/ppc-soft-float.c
index 7b9205662ffeb..2fac9f4035f9d 100644
--- a/clang/test/Driver/ppc-soft-float.c
+++ b/clang/test/Driver/ppc-soft-float.c
@@ -8,6 +8,19 @@ int main () {
 // CHECKSOFT-DAG: -hard-float
 // CHECKSOFT-DAG: -vsx
 // CHECKSOFT-DAG: -altivec
+// CHECKSOFT-DAG: -direct-move,
+// CHECKSOFT-DAG: -float128
+// CHECKSOFT-DAG: -mma
+// CHECKSOFT-DAG: -paired-vector-memops
+// CHECKSOFT-DAG: -power10-vector
+// CHECKSOFT-DAG: -power9-vector
+// CHECKSOFT-DAG: -power8-vector
 
 // CHECKNOSOFT-DAG: +vsx
 // CHECKNOSOFT-DAG: +altivec
+// CHECKNOSOFT-DAG: +direct-move,
+// CHECKNOSOFT-DAG: +mma
+// CHECKNOSOFT-DAG: +paired-vector-memops
+// CHECKNOSOFT-DAG: +power10-vector
+// CHECKNOSOFT-DAG: +power9-vector
+// CHECKNOSOFT-DAG: +power8-vector



More information about the cfe-commits mailing list