[llvm] [RISCV] Use vlenb CSR to set Zvl*b feature getHostCPUFeatures. (PR #225486)
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 22 11:57:21 PDT 2026
https://github.com/topperc created https://github.com/llvm/llvm-project/pull/225486
Zvl*b features aren't exposed in HwProbe, probably because the vlenb CSR exists.
>From 88924330c727e810e7811bc85f1c0d1d3e651d0d Mon Sep 17 00:00:00 2001
From: Craig Topper <craig.topper at sifive.com>
Date: Mon, 21 Sep 2026 17:39:42 -0700
Subject: [PATCH] [RISCV] Use vlenb CSR to set Zvl*b feature
getHostCPUFeatures.
Zvl*b features aren't exposed in HwProbe, probably because the
vlenb CSR exists.
---
llvm/lib/TargetParser/Host.cpp | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
diff --git a/llvm/lib/TargetParser/Host.cpp b/llvm/lib/TargetParser/Host.cpp
index d89133d534b56..dac9cb12036e2 100644
--- a/llvm/lib/TargetParser/Host.cpp
+++ b/llvm/lib/TargetParser/Host.cpp
@@ -2618,6 +2618,24 @@ 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));
+ if (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