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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion llvm/lib/Target/RISCV/RISCVISelLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23487,7 +23487,10 @@ 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.
Expand Down
18 changes: 18 additions & 0 deletions llvm/test/CodeGen/RISCV/rvv/pr139075.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5
; RUN: llc < %s -mtriple=riscv64 -mattr=+v,+zvl16384b | FileCheck %s

define void @a(ptr %0, ptr %1) {
; CHECK-LABEL: a:
; CHECK: # %bb.0:
; CHECK-NEXT: li a2, 1024
; CHECK-NEXT: vsetvli zero, a2, e8, mf2, ta, ma
; CHECK-NEXT: vle8.v v8, (a1)
; CHECK-NEXT: vse8.v v8, (a0)
; CHECK-NEXT: addi a1, a1, 1024
; CHECK-NEXT: vle8.v v8, (a1)
; CHECK-NEXT: addi a0, a0, 1024
; CHECK-NEXT: vse8.v v8, (a0)
; CHECK-NEXT: ret
call void @llvm.memcpy.p0.p0.i64(ptr align 1 %0, ptr align 4 %1, i64 2048, i1 false)
ret void
}
Loading