llvmorg-github-actions[bot] wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang-driver

Author: yamash-fj

<details>
<summary>Changes</summary>

Fix #<!-- -->192186.

An explicit ``+nofeat`` of ``-mcpu`` option is ignored when the feature is 
implied by the base-architecture. Two approaches were considerd:
1. include architechture-implied features in the ``CPUExtension`` set
2. preserve explicit user ``+nofeat`` even for architecture-implied features , 
and this patch implements the latter.

When checking CPU extensions, simultaneously set ``Enabled`` flags for the 
base-architecture's default extensions. By setting ``Enabled``, an explicit 
+nofeat disables the feature and marks it as ``Touched``, and it prevents 
``-feat`` from going away.

Behaivior changes:
For architecuture-default features:
- preserve explicit ``+nofeat``(#<!-- -->192186).
- remove redundant ``+feat``.

I'm not sure whether this behaivior is intentional. Please tell me if I 
misunderstand.

---
Full diff: https://github.com/llvm/llvm-project/pull/203458.diff


2 Files Affected:

- (added) clang/test/Driver/aarch64-no-feat.c (+31) 
- (modified) llvm/lib/TargetParser/AArch64TargetParser.cpp (+8-1) 


``````````diff
diff --git a/clang/test/Driver/aarch64-no-feat.c 
b/clang/test/Driver/aarch64-no-feat.c
new file mode 100644
index 0000000000000..ef3472b3a63e0
--- /dev/null
+++ b/clang/test/Driver/aarch64-no-feat.c
@@ -0,0 +1,31 @@
+// RUN: %clang --target=aarch64-linux-gnu -mcpu=neoverse-v2 %s -### 2>&1 | 
FileCheck %s --check-prefix=NEOVERSE-V2-DEFAULT
+// NEOVERSE-V2-DEFAULT-NOT: "-target-feature" "+sb"
+// NEOVERSE-V2-DEFAULT-NOT: "-target-feature" "-sb"
+// NEOVERSE-V2-DEFAULT: "-target-feature" "+rand"
+// NEOVERSE-V2-DEFAULT-SAME: "-target-feature" "+sve"
+// NEOVERSE-V2-DEFAULT-NOT: "-target-feature" "+sha2"
+
+// RUN: %clang --target=aarch64-linux-gnu -mcpu=neoverse-v2+nosb %s -### 2>&1 
| FileCheck %s --check-prefix=NEOVERSE-V2-NOSB
+// NEOVERSE-V2-NOSB: "-target-feature" "-sb"
+
+// RUN: %clang --target=aarch64-linux-gnu -mcpu=neoverse-v2+sb %s -### 2>&1 | 
FileCheck %s --check-prefix=NEOVERSE-V2-SB
+// NEOVERSE-V2-SB-NOT: "-target-feature" "+sb"
+
+// RUN: %clang --target=aarch64-linux-gnu -mcpu=neoverse-v2+nosve %s -### 2>&1 
| FileCheck %s --check-prefix=NEOVERSE-V2-NOSVE
+// NEOVERSE-V2-NOSVE: "-target-feature" "-sve"
+
+// RUN: %clang --target=aarch64-linux-gnu -mcpu=neoverse-v2+sve %s -### 2>&1 | 
FileCheck %s --check-prefix=NEOVERSE-V2-SVE
+// NEOVERSE-V2-SVE: "-target-feature" "+sve"
+
+// RUN: %clang --target=aarch64-linux-gnu -mcpu=neoverse-v2+norng %s -### 2>&1 
| FileCheck %s --check-prefix=NEOVERSE-V2-NORNG
+// NEOVERSE-V2-NORNG: "-target-feature" "-rand"
+
+// RUN: %clang --target=aarch64-linux-gnu -mcpu=neoverse-v2+rng %s -### 2>&1 | 
FileCheck %s --check-prefix=NEOVERSE-V2-RNG
+// NEOVERSE-V2-RNG: "-target-feature" "+rand"
+
+// RUN: %clang --target=aarch64-linux-gnu -mcpu=neoverse-v2+nosha2 %s -### 
2>&1 | FileCheck %s --check-prefix=NEOVERSE-V2-NOSHA2
+// NEOVERSE-V2-NOSHA2-NOT: "-target-feature" "+sha2"
+// NEOVERSE-V2-NOSHA2-NOT: "-target-feature" "-sha2"
+
+// RUN: %clang --target=aarch64-linux-gnu -mcpu=neoverse-v2+sha2 %s -### 2>&1 
| FileCheck %s --check-prefix=NEOVERSE-V2-SHA2
+// NEOVERSE-V2-SHA2: "-target-feature" "+sha2"
diff --git a/llvm/lib/TargetParser/AArch64TargetParser.cpp 
b/llvm/lib/TargetParser/AArch64TargetParser.cpp
index 2c0211b3a2919..2938c40139eb7 100644
--- a/llvm/lib/TargetParser/AArch64TargetParser.cpp
+++ b/llvm/lib/TargetParser/AArch64TargetParser.cpp
@@ -340,14 +340,21 @@ void AArch64::ExtensionSet::disable(ArchExtKind E) {
       disable(Dep.Later);
 }
 
+static void setEnableIfMandatory(AArch64::ExtensionSet &Exts, 
AArch64::ExtensionInfo E) {
+    if (Exts.BaseArch->DefaultExts.test(E.ID))
+      Exts.Enabled.set(E.ID);
+}
+
 void AArch64::ExtensionSet::addCPUDefaults(const CpuInfo &CPU) {
   LLVM_DEBUG(llvm::dbgs() << "addCPUDefaults(" << CPU.Name << ")\n");
   BaseArch = &CPU.Arch;
 
   AArch64::ExtensionBitset CPUExtensions = CPU.getImpliedExtensions();
-  for (const auto &E : Extensions)
+  for (const auto &E : Extensions) {
     if (CPUExtensions.test(E.ID))
       enable(E.ID);
+    setEnableIfMandatory(*this, E);
+  }
 }
 
 void AArch64::ExtensionSet::addArchDefaults(const ArchInfo &Arch) {

``````````

</details>


https://github.com/llvm/llvm-project/pull/203458
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to