[llvm] [TargetParser][AArch64] Believe runtime feature detection (PR #95694)
via llvm-commits
llvm-commits at lists.llvm.org
Sun Jun 16 02:12:33 PDT 2024
https://github.com/workingjubilee created https://github.com/llvm/llvm-project/pull/95694
In https://github.com/llvm/llvm-project/issues/90365 it was reported that TargetParser.cpp arrives at the wrong conclusion regarding what features are enabled when attempting to detect "native" features on the Raspberry Pi 4, because it (correctly) detects it as a Cortex-A72, but LLVM (incorrectly) believes all Cortex-A72s have crypto enabled. Attempt to help ourselves by allowing runtime information derived from the host to contradict whatever we believe is "true" about the architecture.
>From 1c8afcccf57b0d9336c0468fba68c1e0449736c4 Mon Sep 17 00:00:00 2001
From: Jubilee Young <workingjubilee at gmail.com>
Date: Sun, 16 Jun 2024 01:59:59 -0700
Subject: [PATCH] [TargetParser][AArch64] Believe runtime feature detection
---
llvm/lib/TargetParser/Host.cpp | 16 +++++++---------
1 file changed, 7 insertions(+), 9 deletions(-)
diff --git a/llvm/lib/TargetParser/Host.cpp b/llvm/lib/TargetParser/Host.cpp
index 2ea56746aff24..163a1262e2c59 100644
--- a/llvm/lib/TargetParser/Host.cpp
+++ b/llvm/lib/TargetParser/Host.cpp
@@ -1967,21 +1967,19 @@ bool sys::getHostCPUFeatures(StringMap<bool> &Features) {
}
#if defined(__aarch64__)
- // If we have all crypto bits we can add the feature
- if (crypto == (CAP_AES | CAP_PMULL | CAP_SHA1 | CAP_SHA2))
- Features["crypto"] = true;
+ // LLVM has decided some AArch64 CPUs have all the instructions they _may_ have, as opposed to
+ // all the instructions they _must_ have, so allow runtime information to correct us on that.
+ Features["crypto"] = (crypto == (CAP_AES | CAP_PMULL | CAP_SHA1 | CAP_SHA2));
#endif
return true;
}
#elif defined(_WIN32) && (defined(__aarch64__) || defined(_M_ARM64))
bool sys::getHostCPUFeatures(StringMap<bool> &Features) {
- if (IsProcessorFeaturePresent(PF_ARM_NEON_INSTRUCTIONS_AVAILABLE))
- Features["neon"] = true;
- if (IsProcessorFeaturePresent(PF_ARM_V8_CRC32_INSTRUCTIONS_AVAILABLE))
- Features["crc"] = true;
- if (IsProcessorFeaturePresent(PF_ARM_V8_CRYPTO_INSTRUCTIONS_AVAILABLE))
- Features["crypto"] = true;
+ // If we're asking the OS at runtime, believe what the OS says
+ Features["neon"] = IsProcessorFeaturePresent(PF_ARM_NEON_INSTRUCTIONS_AVAILABLE);
+ Features["crc"] = IsProcessorFeaturePresent(PF_ARM_V8_CRC32_INSTRUCTIONS_AVAILABLE);
+ Features["crypto"] = IsProcessorFeaturePresent(PF_ARM_V8_CRYPTO_INSTRUCTIONS_AVAILABLE);
return true;
}
More information about the llvm-commits
mailing list