[llvm] [RISCV] Make RISCVISAInfo::updateMaxELen extension checking more robust. Add inference from V extension. (PR #90650)

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 30 12:21:12 PDT 2024


https://github.com/topperc created https://github.com/llvm/llvm-project/pull/90650

We weren't fully checking that we parsed Zve*x/f/d correctly. This could break if new extension is added that starts with Zve.

We also were assuming the Zve64d is present whenever V is so we only inferred from Zve*. It's more correct to infer ELEN from V itself too.

>From 9d221e2774365cd3a92227def61dacf69d559ac3 Mon Sep 17 00:00:00 2001
From: Craig Topper <craig.topper at sifive.com>
Date: Tue, 30 Apr 2024 11:46:36 -0700
Subject: [PATCH] [RISCV] Make RISCVISAInfo::updateMaxELen extension chekcing
 more robust. Add inference from V extension.

We weren't fully checking that we parsed Zve*x/f/d correctly. This
could break if new extension is added that starts with Zve.

We also were assuming the Zve64d is present whenever V is so we only
inferred from Zve*. It's more correct to infer ELEN from V itself too.
---
 llvm/lib/TargetParser/RISCVISAInfo.cpp | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/llvm/lib/TargetParser/RISCVISAInfo.cpp b/llvm/lib/TargetParser/RISCVISAInfo.cpp
index 5aff936dd993fb..3b0cf8fab25f46 100644
--- a/llvm/lib/TargetParser/RISCVISAInfo.cpp
+++ b/llvm/lib/TargetParser/RISCVISAInfo.cpp
@@ -929,6 +929,12 @@ void RISCVISAInfo::updateMinVLen() {
 }
 
 void RISCVISAInfo::updateMaxELen() {
+  assert(MaxELenFp == 0 && MaxELen == 0);
+  if (Exts.count("v")) {
+    MaxELenFp = std::max(MaxELenFp, 64u);
+    MaxELen = std::max(MaxELen, 64u);
+  }
+
   // handles EEW restriction by sub-extension zve
   for (auto const &Ext : Exts) {
     StringRef ExtName = Ext.first;
@@ -936,12 +942,15 @@ void RISCVISAInfo::updateMaxELen() {
     if (IsZveExt) {
       if (ExtName.back() == 'f')
         MaxELenFp = std::max(MaxELenFp, 32u);
-      if (ExtName.back() == 'd')
+      else if (ExtName.back() == 'd')
         MaxELenFp = std::max(MaxELenFp, 64u);
+      else if (ExtName.back() != 'x')
+        continue;
+
       ExtName = ExtName.drop_back();
       unsigned ZveELen;
-      ExtName.getAsInteger(10, ZveELen);
-      MaxELen = std::max(MaxELen, ZveELen);
+      if (!ExtName.getAsInteger(10, ZveELen))
+        MaxELen = std::max(MaxELen, ZveELen);
     }
   }
 }



More information about the llvm-commits mailing list