[clang] [PowerPC] Diagnose invalid combination with Altivec, VSX and soft-float (PR #79109)

Chen Zheng via cfe-commits cfe-commits at lists.llvm.org
Thu Jan 25 05:34:44 PST 2024


https://github.com/chenzheng1030 updated https://github.com/llvm/llvm-project/pull/79109

>From 014b10f43e2d3f8564940e21033cee77c3c0c10e Mon Sep 17 00:00:00 2001
From: Nemanja Ivanovic <nemanja.i.ibm at gmail.com>
Date: Tue, 23 Jan 2024 03:25:01 -0500
Subject: [PATCH 1/2] [PowerPC] Diagnose invalid combination with Altivec, VSX
 and soft-float

---
 clang/lib/Basic/Targets/PPC.cpp              | 43 ++++++++++++++++----
 clang/test/CodeGen/PowerPC/attr-target-ppc.c |  3 ++
 clang/test/Driver/ppc-dependent-options.cpp  | 15 +++++++
 3 files changed, 52 insertions(+), 9 deletions(-)

diff --git a/clang/lib/Basic/Targets/PPC.cpp b/clang/lib/Basic/Targets/PPC.cpp
index 41935abfb65d3b..1341bf8b99c506 100644
--- a/clang/lib/Basic/Targets/PPC.cpp
+++ b/clang/lib/Basic/Targets/PPC.cpp
@@ -442,19 +442,44 @@ void PPCTargetInfo::getTargetDefines(const LangOptions &Opts,
   //   _CALL_DARWIN
 }
 
-// Handle explicit options being passed to the compiler here: if we've
-// explicitly turned off vsx and turned on any of:
-// - power8-vector
-// - direct-move
-// - float128
-// - power9-vector
-// - paired-vector-memops
-// - mma
-// - power10-vector
+// Handle explicit options being passed to the compiler here:
+// - if we've explicitly turned off vsx and turned on any of:
+//   - power8-vector
+//   - direct-move
+//   - float128
+//   - power9-vector
+//   - paired-vector-memops
+//   - mma
+//   - power10-vector
+// - if we've explicitly turned on vsx and turned off altivec.
+// - if we've explicitly turned on soft-float and altivec.
 // then go ahead and error since the customer has expressed an incompatible
 // 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";
+    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 VSX with no Altivec.
+  if (llvm::is_contained(FeaturesVec, "+vsx") &&
+      llvm::is_contained(FeaturesVec, "-altivec")) {
+    Diags.Report(diag::err_opt_not_valid_with_opt) << "-mvsx"
+                                                   << "-mno-altivec";
+    return false;
+  }
 
   // vsx was not explicitly turned off.
   if (!llvm::is_contained(FeaturesVec, "-vsx"))
diff --git a/clang/test/CodeGen/PowerPC/attr-target-ppc.c b/clang/test/CodeGen/PowerPC/attr-target-ppc.c
index d2901748b37cb9..f185a0e6f49a05 100644
--- a/clang/test/CodeGen/PowerPC/attr-target-ppc.c
+++ b/clang/test/CodeGen/PowerPC/attr-target-ppc.c
@@ -1,4 +1,7 @@
 // RUN: not %clang_cc1 -triple powerpc64le-linux-gnu -emit-llvm %s -o -
 
 long __attribute__((target("power8-vector,no-vsx"))) foo (void) { return 0; }  // expected-error {{option '-mpower8-vector' cannot be specified with '-mno-vsx'}}
+long __attribute__((target("no-altivec,vsx"))) foo2(void) { return 0; }        // expected-error {{option '-mvsx' cannot be specified with '-mno-altivec'}}
+long __attribute__((target("no-hard-float,altivec"))) foo3(void) { return 0; } // expected-error {{option '-msoft-float' cannot be specified with '-maltivec'}}
+long __attribute__((target("no-hard-float,vsx"))) foo3(void) { return 0; } // expected-error {{option '-msoft-float' cannot be specified with '-mvsx'}}
 
diff --git a/clang/test/Driver/ppc-dependent-options.cpp b/clang/test/Driver/ppc-dependent-options.cpp
index 65c40e9ce70f65..8286422185cad6 100644
--- a/clang/test/Driver/ppc-dependent-options.cpp
+++ b/clang/test/Driver/ppc-dependent-options.cpp
@@ -78,6 +78,18 @@
 // RUN: -mcpu=power10 -std=c++11 -mno-vsx -mpower10-vector %s 2>&1 | \
 // RUN: FileCheck %s -check-prefix=CHECK-NVSX-P10V
 
+// RUN: not %clang -target powerpc64le-unknown-unknown -fsyntax-only \
+// RUN: -std=c++11 -mvsx -mno-altivec %s 2>&1 | \
+// RUN: FileCheck %s -check-prefix=CHECK-NALTI-VSX
+
+// RUN: not %clang -target powerpc64le-unknown-unknown -fsyntax-only \
+// RUN: -std=c++11 -msoft-float -maltivec %s 2>&1 | \
+// RUN: FileCheck %s -check-prefix=CHECK-SOFTFLT-ALTI
+
+// RUN: not %clang -target powerpc64le-unknown-unknown -fsyntax-only \
+// RUN: -std=c++11 -msoft-float -mvsx %s 2>&1 | \
+// RUN: FileCheck %s -check-prefix=CHECK-SOFTFLT-VSX
+
 #ifdef __VSX__
 static_assert(false, "VSX enabled");
 #endif
@@ -114,3 +126,6 @@ static_assert(false, "Neither enabled");
 // CHECK-NVSX-MMA: error: option '-mmma' cannot be specified with '-mno-vsx'
 // 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'

>From ea79bd6263211c1240446108c817b54e6e93a37b Mon Sep 17 00:00:00 2001
From: Chen Zheng <czhengsz at cn.ibm.com>
Date: Thu, 25 Jan 2024 08:34:26 -0500
Subject: [PATCH 2/2] address comments

---
 clang/lib/Basic/Targets/PPC.cpp              | 2 +-
 clang/test/CodeGen/PowerPC/attr-target-ppc.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Basic/Targets/PPC.cpp b/clang/lib/Basic/Targets/PPC.cpp
index 1341bf8b99c506..65909eb79fa7f5 100644
--- a/clang/lib/Basic/Targets/PPC.cpp
+++ b/clang/lib/Basic/Targets/PPC.cpp
@@ -452,7 +452,7 @@ void PPCTargetInfo::getTargetDefines(const LangOptions &Opts,
 //   - mma
 //   - power10-vector
 // - if we've explicitly turned on vsx and turned off altivec.
-// - if we've explicitly turned on soft-float and altivec.
+// - if we've explicitly turned off hard-float and turned on altivec.
 // then go ahead and error since the customer has expressed an incompatible
 // set of options.
 static bool ppcUserFeaturesCheck(DiagnosticsEngine &Diags,
diff --git a/clang/test/CodeGen/PowerPC/attr-target-ppc.c b/clang/test/CodeGen/PowerPC/attr-target-ppc.c
index f185a0e6f49a05..46732cfe896f60 100644
--- a/clang/test/CodeGen/PowerPC/attr-target-ppc.c
+++ b/clang/test/CodeGen/PowerPC/attr-target-ppc.c
@@ -3,5 +3,5 @@
 long __attribute__((target("power8-vector,no-vsx"))) foo (void) { return 0; }  // expected-error {{option '-mpower8-vector' cannot be specified with '-mno-vsx'}}
 long __attribute__((target("no-altivec,vsx"))) foo2(void) { return 0; }        // expected-error {{option '-mvsx' cannot be specified with '-mno-altivec'}}
 long __attribute__((target("no-hard-float,altivec"))) foo3(void) { return 0; } // expected-error {{option '-msoft-float' cannot be specified with '-maltivec'}}
-long __attribute__((target("no-hard-float,vsx"))) foo3(void) { return 0; } // expected-error {{option '-msoft-float' cannot be specified with '-mvsx'}}
+long __attribute__((target("no-hard-float,vsx"))) foo4(void) { return 0; } // expected-error {{option '-msoft-float' cannot be specified with '-mvsx'}}
 



More information about the cfe-commits mailing list