Skip to content

[RISCV] Limit VLEN in getOptimalMemOpType to prevent creating invalid MVTs. #139116

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

Merged
merged 3 commits into from
May 8, 2025

Conversation

topperc
Copy link
Collaborator

@topperc topperc commented May 8, 2025

We only guarantee that types that are 1024 bytes or smaller exist in the MVT enum.

Fixes #139075.

… MVTs.

We only guarantee that types that are 1024 bytes or smaller exist
in the MVT enum.

Fixes llvm#139075.
@llvmbot
Copy link
Member

llvmbot commented May 8, 2025

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

Author: Craig Topper (topperc)

Changes

We only guarantee that types that are 1024 bytes or smaller exist in the MVT enum.

Fixes #139075.


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

1 Files Affected:

  • (modified) llvm/lib/Target/RISCV/RISCVISelLowering.cpp (+3-1)
diff --git a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
index f2bc1765bc4c6..1bc601a0c399d 100644
--- a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
+++ b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
@@ -23487,7 +23487,9 @@ EVT RISCVTargetLowering::getOptimalMemOpType(const MemOp &Op,
   // combining will typically form larger LMUL operations from the LMUL1
   // operations emitted here, and that's okay because combining isn't
   // introducing new memory operations; it's just merging existing ones.
-  const unsigned MinVLenInBytes = Subtarget.getRealMinVLen()/8;
+  // NOTE: We limit to 1024 bytes to avoid creating an invalid MVT.
+  const unsigned MinVLenInBytes = std::min(Subtarget.getRealMinVLen()/8, 1024U);
+
   if (Op.size() < MinVLenInBytes)
     // TODO: Figure out short memops.  For the moment, do the default thing
     // which ends up using scalar sequences.

Copy link

github-actions bot commented May 8, 2025

✅ With the latest revision this PR passed the C/C++ code formatter.

Copy link
Collaborator

@preames preames left a comment

Choose a reason for hiding this comment

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

LGTM.

Please add a test if you can reduce one.

@topperc
Copy link
Collaborator Author

topperc commented May 8, 2025

LGTM.

Please add a test if you can reduce one.

I made one, but I forgot git add. Brain fog from moving I guess.

@topperc topperc merged commit 501dcab into llvm:main May 8, 2025
9 of 10 checks passed
@topperc topperc deleted the pr/memoptype branch May 8, 2025 23:27
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.

Crash when lowering memcpy for RISC-V with long vectors
3 participants