[llvm-branch-commits] [clang] 006720b - [AArch64] Handle negative architecture features

Tobias Hieta via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Thu Feb 2 23:34:50 PST 2023


Author: David Green
Date: 2023-02-03T08:34:34+01:00
New Revision: 006720b9947e2cf4a485c18e1faf84cd948841f5

URL: https://github.com/llvm/llvm-project/commit/006720b9947e2cf4a485c18e1faf84cd948841f5
DIFF: https://github.com/llvm/llvm-project/commit/006720b9947e2cf4a485c18e1faf84cd948841f5.diff

LOG: [AArch64] Handle negative architecture features

Currently negative architecture features passes to clang like -Xclang
-target-feature -Xclang -v9.3a will end up _enabling_ dependant target
features (like FEAT_MOPS). This patch fixes that by ensuring we don't
enable dependant target features when !Enabled.

Fixes #60375

Differential Revision: https://reviews.llvm.org/D142963

Added: 
    

Modified: 
    clang/lib/Basic/Targets/AArch64.cpp
    clang/test/CodeGen/aarch64-targetattr.c
    clang/test/Preprocessor/aarch64-target-features.c

Removed: 
    


################################################################################
diff  --git a/clang/lib/Basic/Targets/AArch64.cpp b/clang/lib/Basic/Targets/AArch64.cpp
index dfed95f0513f0..997398da7972c 100644
--- a/clang/lib/Basic/Targets/AArch64.cpp
+++ b/clang/lib/Basic/Targets/AArch64.cpp
@@ -687,9 +687,13 @@ void AArch64TargetInfo::setFeatureEnabled(llvm::StringMap<bool> &Features,
   if (ArchInfo == llvm::AArch64::INVALID)
     return; // Not an architecure, nothing more to do.
 
+  // Disabling an architecture feature does not affect dependent features
+  if (!Enabled)
+    return;
+
   for (const auto *OtherArch : llvm::AArch64::ArchInfos)
     if (ArchInfo.implies(*OtherArch))
-      Features[OtherArch->getSubArch()] = Enabled;
+      Features[OtherArch->getSubArch()] = true;
 
   // Set any features implied by the architecture
   uint64_t Extensions =

diff  --git a/clang/test/CodeGen/aarch64-targetattr.c b/clang/test/CodeGen/aarch64-targetattr.c
index cc697b8894acf..d2a903a5e9830 100644
--- a/clang/test/CodeGen/aarch64-targetattr.c
+++ b/clang/test/CodeGen/aarch64-targetattr.c
@@ -89,6 +89,11 @@ void noneon() {}
 __attribute__((target("no-simd")))
 void nosimd() {}
 
+// This isn't part of the standard interface, but test that -arch features should not apply anything else.
+// CHECK-LABEL: @minusarch() #18
+__attribute__((target("no-v9.3a")))
+void minusarch() {}
+
 // CHECK: attributes #0 = { {{.*}} "target-features"="+crc,+fp-armv8,+lse,+neon,+ras,+rdm,+v8.1a,+v8.2a,+v8a" }
 // CHECK: attributes #1 = { {{.*}} "target-features"="+crc,+fp-armv8,+fullfp16,+lse,+neon,+ras,+rdm,+sve,+v8.1a,+v8.2a,+v8a" }
 // CHECK: attributes #2 = { {{.*}} "target-features"="+crc,+fp-armv8,+fullfp16,+lse,+neon,+ras,+rdm,+sve,+sve2,+v8.1a,+v8.2a,+v8a" }
@@ -107,3 +112,4 @@ void nosimd() {}
 // CHECK: attributes #15 = { {{.*}} "target-cpu"="neoverse-n1" "target-features"="+bf16,+crc,+crypto,+dotprod,+fp-armv8,+fullfp16,+i8mm,+lse,+neon,+ras,+rcpc,+rdm,+spe,+ssbs,+sve,+sve2,+v8.1a,+v8.2a,+v8.3a,+v8.4a,+v8.5a,+v8.6a,+v8a" "tune-cpu"="cortex-a710" }
 // CHECK: attributes #16 = { {{.*}} "branch-target-enforcement"="true" {{.*}} "target-features"="+bf16,+crc,+crypto,+dotprod,+fp-armv8,+fullfp16,+i8mm,+lse,+neon,+ras,+rcpc,+rdm,+spe,+ssbs,+sve,+sve2,+v8.1a,+v8.2a,+v8.3a,+v8.4a,+v8.5a,+v8.6a,+v8a" "tune-cpu"="cortex-a710" }
 // CHECK: attributes #17 = { {{.*}} "target-features"="-neon" }
+// CHECK: attributes #18 = { {{.*}} "target-features"="-v9.3a" }

diff  --git a/clang/test/Preprocessor/aarch64-target-features.c b/clang/test/Preprocessor/aarch64-target-features.c
index ba1b56c492067..a96e0442a9ff5 100644
--- a/clang/test/Preprocessor/aarch64-target-features.c
+++ b/clang/test/Preprocessor/aarch64-target-features.c
@@ -569,6 +569,8 @@
 // RUN: %clang -target aarch64-arm-none-eabi -march=armv9.3-a             -x c -E -dM %s -o - | FileCheck --check-prefix=CHECK-MOPS   %s
 // RUN: %clang -target aarch64-arm-none-eabi -march=armv9.3-a+nomops      -x c -E -dM %s -o - | FileCheck --check-prefix=CHECK-NOMOPS %s
 // RUN: %clang -target aarch64-arm-none-eabi -march=armv9.3-a+mops        -x c -E -dM %s -o - | FileCheck --check-prefix=CHECK-MOPS   %s
+// Check that -target-feature -v9.3a doesn't enable dependant features
+// RUN: %clang -target aarch64-arm-none-eabi -Xclang -target-feature -Xclang -v9.3a  -x c -E -dM %s -o - | FileCheck --check-prefix=CHECK-NOMOPS   %s
 // CHECK-MOPS: __ARM_FEATURE_MOPS 1
 // CHECK-NOMOPS-NOT: __ARM_FEATURE_MOPS 1
 


        


More information about the llvm-branch-commits mailing list