Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Apr 30, 2024

Conversation

topperc
Copy link
Collaborator

@topperc topperc commented Apr 30, 2024

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.

…st. 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.
@llvmbot
Copy link
Collaborator

llvmbot commented Apr 30, 2024

@llvm/pr-subscribers-backend-risc-v

Author: Craig Topper (topperc)

Changes

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.


Full diff: https://github.com/llvm/llvm-project/pull/90650.diff

1 Files Affected:

  • (modified) llvm/lib/TargetParser/RISCVISAInfo.cpp (+12-3)
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);
     }
   }
 }

Copy link
Contributor

@asb asb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@topperc topperc merged commit 05d04f0 into llvm:main Apr 30, 2024
5 of 6 checks passed
@topperc topperc deleted the pr/elen-infer branch April 30, 2024 20:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants