Skip to content

Commit 501dcab

Browse files
authored
[RISCV] Limit VLEN in getOptimalMemOpType to prevent creating invalid MVTs. (#139116)
We only guarantee that types that are 1024 bytes or smaller exist in the MVT enum. Fixes #139075.
1 parent e4b4a93 commit 501dcab

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

llvm/lib/Target/RISCV/RISCVISelLowering.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23380,7 +23380,10 @@ EVT RISCVTargetLowering::getOptimalMemOpType(const MemOp &Op,
2338023380
// combining will typically form larger LMUL operations from the LMUL1
2338123381
// operations emitted here, and that's okay because combining isn't
2338223382
// introducing new memory operations; it's just merging existing ones.
23383-
const unsigned MinVLenInBytes = Subtarget.getRealMinVLen()/8;
23383+
// NOTE: We limit to 1024 bytes to avoid creating an invalid MVT.
23384+
const unsigned MinVLenInBytes =
23385+
std::min(Subtarget.getRealMinVLen() / 8, 1024U);
23386+
2338423387
if (Op.size() < MinVLenInBytes)
2338523388
// TODO: Figure out short memops. For the moment, do the default thing
2338623389
// which ends up using scalar sequences.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5
2+
; RUN: llc < %s -mtriple=riscv64 -mattr=+v,+zvl16384b | FileCheck %s
3+
4+
define void @a(ptr %0, ptr %1) {
5+
; CHECK-LABEL: a:
6+
; CHECK: # %bb.0:
7+
; CHECK-NEXT: li a2, 1024
8+
; CHECK-NEXT: vsetvli zero, a2, e8, mf2, ta, ma
9+
; CHECK-NEXT: vle8.v v8, (a1)
10+
; CHECK-NEXT: vse8.v v8, (a0)
11+
; CHECK-NEXT: addi a1, a1, 1024
12+
; CHECK-NEXT: vle8.v v8, (a1)
13+
; CHECK-NEXT: addi a0, a0, 1024
14+
; CHECK-NEXT: vse8.v v8, (a0)
15+
; CHECK-NEXT: ret
16+
call void @llvm.memcpy.p0.p0.i64(ptr align 1 %0, ptr align 4 %1, i64 2048, i1 false)
17+
ret void
18+
}

0 commit comments

Comments
 (0)