[PATCH] D126302: [PowerPC] Diagnose invalid combination with Altivec, VSX and soft-float

Nemanja Ivanovic via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue May 24 07:24:49 PDT 2022


nemanjai created this revision.
nemanjai added reviewers: Laurentiu, PowerPC.
Herald added subscribers: shchenz, kbarton.
Herald added a project: All.
nemanjai requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

The current behaviour with these three options is quite undesirable:
`-mno-altivec -mvsx` allows VSX to override no Altivec, thereby turning on both
`-msoft-float -maltivec` causes a crash if an actual Altivec instruction is required because soft float turns of Altivec
`-msoft-float -mvsx` is also accepted with both Altivec and VSX turned off (potentially causing crashes as above)

This patch diagnoses these impossible combinations in the driver so the user does not end up with surprises in terms of their options being ignored or silently overridden.

Inspired by https://github.com/llvm/llvm-project/issues/55556


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D126302

Files:
  clang/lib/Basic/Targets/PPC.cpp
  clang/test/CodeGen/PowerPC/attr-target-ppc.c
  clang/test/Driver/ppc-dependent-options.cpp


Index: clang/test/Driver/ppc-dependent-options.cpp
===================================================================
--- clang/test/Driver/ppc-dependent-options.cpp
+++ clang/test/Driver/ppc-dependent-options.cpp
@@ -78,6 +78,14 @@
 // 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
+
 #ifdef __VSX__
 static_assert(false, "VSX enabled");
 #endif
@@ -112,5 +120,7 @@
 // CHECK-NVSX-MULTI: error: option '-mfloat128' cannot be specified with '-mno-vsx'
 // CHECK-NVSX-MULTI: error: option '-mpower9-vector' cannot be specified with '-mno-vsx'
 // CHECK-NVSX-MMA: error: option '-mmma' cannot be specified with '-mno-vsx'
+// 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-NVSX: Neither enabled
 // CHECK-VSX: VSX enabled
Index: clang/test/CodeGen/PowerPC/attr-target-ppc.c
===================================================================
--- clang/test/CodeGen/PowerPC/attr-target-ppc.c
+++ clang/test/CodeGen/PowerPC/attr-target-ppc.c
@@ -1,4 +1,5 @@
 // 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'}}
Index: clang/lib/Basic/Targets/PPC.cpp
===================================================================
--- clang/lib/Basic/Targets/PPC.cpp
+++ clang/lib/Basic/Targets/PPC.cpp
@@ -447,6 +447,18 @@
 static bool ppcUserFeaturesCheck(DiagnosticsEngine &Diags,
                                  const std::vector<std::string> &FeaturesVec) {
 
+  // Cannot allow VSX with no 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";
+
+  // Cannot allow soft-float with Altivec.
+  if (llvm::is_contained(FeaturesVec, "+vsx") &&
+      llvm::is_contained(FeaturesVec, "-altivec"))
+    Diags.Report(diag::err_opt_not_valid_with_opt) << "-mvsx"
+                                                   << "-mno-altivec";
+
   // vsx was not explicitly turned off.
   if (!llvm::is_contained(FeaturesVec, "-vsx"))
     return true;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D126302.431672.patch
Type: text/x-patch
Size: 3102 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220524/58d72982/attachment.bin>


More information about the llvm-commits mailing list