[llvm] 2623044 - [RISCV] Use vlenb CSR to set Zvl*b feature getHostCPUFeatures. (#225486)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 23 21:18:12 PDT 2026
Author: Craig Topper
Date: 2026-09-23T21:18:05-07:00
New Revision: 262304409c301410d92b50b394aaabc85fab20f8
URL: https://github.com/llvm/llvm-project/commit/262304409c301410d92b50b394aaabc85fab20f8
DIFF: https://github.com/llvm/llvm-project/commit/262304409c301410d92b50b394aaabc85fab20f8.diff
LOG: [RISCV] Use vlenb CSR to set Zvl*b feature getHostCPUFeatures. (#225486)
Zvl*b features aren't exposed in HwProbe, probably because the vlenb CSR
exists.
Added:
Modified:
llvm/lib/TargetParser/Host.cpp
Removed:
################################################################################
diff --git a/llvm/lib/TargetParser/Host.cpp b/llvm/lib/TargetParser/Host.cpp
index d89133d534b56..56f2757d3fd3a 100644
--- a/llvm/lib/TargetParser/Host.cpp
+++ b/llvm/lib/TargetParser/Host.cpp
@@ -2618,6 +2618,22 @@ StringMap<bool> sys::getHostCPUFeatures() {
Query[2].Value == /*RISCV_HWPROBE_MISALIGNED_SCALAR_FAST=*/3)
Features["unaligned-scalar-mem"] = true;
+ // Infer Zvl from vlenb CSR.
+ if (Features["v"] || Features["zve32x"]) {
+#if __riscv_xlen == 64
+ uint64_t VLen;
+#elif __riscv_xlen == 32
+ uint32_t VLen;
+#else
+#error "Unknown XLEN"
+#endif
+ // Use the raw CSR number in case assembler doesn't know vlenb.
+ __asm__ volatile("csrr %0, 0xc22" : "=r"(VLen));
+ VLen *= 8;
+ std::string ZvlFeature = (Twine("zvl") + Twine(VLen) + "b").str();
+ Features[ZvlFeature] = true;
+ }
+
return Features;
}
#else
More information about the llvm-commits
mailing list