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

Zaara Syeda via cfe-commits cfe-commits at lists.llvm.org
Wed Aug 7 08:49:21 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/4] [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 9ff54083c923b1..2b25cb189279ab 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 00000000000000..7b9205662ffeb2
--- /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/4] 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 2b25cb189279ab..3b3aec4c414eb5 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 414ed1e70bb305..b62ed399054af5 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 7b9205662ffeb2..2fac9f4035f9dc 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

>From b61eee912b0400d94b8b450cff5b82be461f70ed Mon Sep 17 00:00:00 2001
From: Zaara Syeda <syzaara at cpap8104.rtp.raleigh.ibm.com>
Date: Wed, 31 Jul 2024 15:49:23 -0400
Subject: [PATCH 3/4] Address review

---
 clang/lib/Basic/Targets/PPC.cpp             | 2 ++
 clang/test/Driver/ppc-dependent-options.cpp | 5 +++++
 clang/test/Driver/ppc-soft-float.c          | 6 ++++--
 3 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Basic/Targets/PPC.cpp b/clang/lib/Basic/Targets/PPC.cpp
index 3b3aec4c414eb5..a34be7f50efbaa 100644
--- a/clang/lib/Basic/Targets/PPC.cpp
+++ b/clang/lib/Basic/Targets/PPC.cpp
@@ -489,6 +489,7 @@ static bool ppcUserFeaturesCheck(DiagnosticsEngine &Diags,
     Found |= FindVSXSubfeature("+paired-vector-memops",
                                "-mpaired-vector-memops", "-msoft-float");
     Found |= FindVSXSubfeature("+mma", "-mmma", "-msoft-float");
+    Found |= FindVSXSubfeature("+crypto", "-mcrypto", "-msoft-float");
     Found |= FindVSXSubfeature("+power10-vector", "-mpower10-vector",
                                "-msoft-float");
   }
@@ -707,6 +708,7 @@ bool PPCTargetInfo::initFeatureMap(
     Features["power10-vector"] = false;
     Features["float128"] = false;
     Features["mma"] = false;
+    Features["crypto"] = 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 b62ed399054af5..46d6beafbc174c 100644
--- a/clang/test/Driver/ppc-dependent-options.cpp
+++ b/clang/test/Driver/ppc-dependent-options.cpp
@@ -113,6 +113,10 @@
 // RUN: -std=c++11 -msoft-float -mpaired-vector-memops %s 2>&1 | \
 // RUN: FileCheck %s -check-prefix=CHECK-SOFTFLT-PAIREDVECMEMOP
 
+// RUN: not %clang -target powerpc64le-unknown-unknown -fsyntax-only \
+// RUN: -std=c++11 -msoft-float -mcrypto %s 2>&1 | \
+// RUN: FileCheck %s -check-prefix=CHECK-SOFTFLT-CRYPTO
+
 #ifdef __VSX__
 static_assert(false, "VSX enabled");
 #endif
@@ -159,3 +163,4 @@ static_assert(false, "Neither enabled");
 // 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'
+// CHECK-SOFTFLT-CRYPTO: error: option '-mcrypto' 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 2fac9f4035f9dc..18d768aec0dedc 100644
--- a/clang/test/Driver/ppc-soft-float.c
+++ b/clang/test/Driver/ppc-soft-float.c
@@ -8,19 +8,21 @@ int main () {
 // CHECKSOFT-DAG: -hard-float
 // CHECKSOFT-DAG: -vsx
 // CHECKSOFT-DAG: -altivec
-// CHECKSOFT-DAG: -direct-move,
+// 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
+// CHECKSOFT-DAG: -crypto
 
 // CHECKNOSOFT-DAG: +vsx
 // CHECKNOSOFT-DAG: +altivec
-// CHECKNOSOFT-DAG: +direct-move,
+// CHECKNOSOFT-DAG: +direct-move
 // CHECKNOSOFT-DAG: +mma
 // CHECKNOSOFT-DAG: +paired-vector-memops
 // CHECKNOSOFT-DAG: +power10-vector
 // CHECKNOSOFT-DAG: +power9-vector
 // CHECKNOSOFT-DAG: +power8-vector
+// CHECKNOSOFT-DAG: +crypto

>From e7b9974f7080ecaff69222e8806738226d2c9629 Mon Sep 17 00:00:00 2001
From: Zaara Syeda <syzaara at cpap8104.rtp.raleigh.ibm.com>
Date: Wed, 7 Aug 2024 11:48:52 -0400
Subject: [PATCH 4/4] Address review

---
 clang/lib/Basic/Targets/PPC.cpp | 19 ++++---------------
 1 file changed, 4 insertions(+), 15 deletions(-)

diff --git a/clang/lib/Basic/Targets/PPC.cpp b/clang/lib/Basic/Targets/PPC.cpp
index a34be7f50efbaa..4bb686b6d38155 100644
--- a/clang/lib/Basic/Targets/PPC.cpp
+++ b/clang/lib/Basic/Targets/PPC.cpp
@@ -697,20 +697,6 @@ bool PPCTargetInfo::initFeatureMap(
     Diags.Report(diag::err_opt_not_valid_with_opt) << "-mprivileged" << CPU;
     return false;
   }
-
-  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;
-    Features["crypto"] = false;
-  }
-
   return TargetInfo::initFeatureMap(Features, Diags, CPU, FeaturesVec);
 }
 
@@ -802,11 +788,14 @@ void PPCTargetInfo::setFeatureEnabled(llvm::StringMap<bool> &Features,
       Features["efpu2"] = false;
     // If we're disabling altivec or vsx go ahead and disable all of the vsx
     // features.
-    if ((Name == "altivec") || (Name == "vsx"))
+    if ((Name == "altivec") || (Name == "vsx") || (Name == "hard-float")) {
+      if (Name != "vsx")
+        Features["altivec"] = Features["crypto"] = false;
       Features["vsx"] = Features["direct-move"] = Features["power8-vector"] =
           Features["float128"] = Features["power9-vector"] =
               Features["paired-vector-memops"] = Features["mma"] =
                   Features["power10-vector"] = false;
+    }
     if (Name == "power8-vector")
       Features["power9-vector"] = Features["paired-vector-memops"] =
           Features["mma"] = Features["power10-vector"] = false;



More information about the cfe-commits mailing list