[llvm] [RISCV] Limit VLEN in getOptimalMemOpType to prevent creating invalid MVTs. (PR #139116)
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Thu May 8 11:39:00 PDT 2025
https://github.com/topperc updated https://github.com/llvm/llvm-project/pull/139116
>From d3b19aee05f40dbe46c783fe8f8c034c0a5408de Mon Sep 17 00:00:00 2001
From: Craig Topper <craig.topper at sifive.com>
Date: Thu, 8 May 2025 10:39:25 -0700
Subject: [PATCH 1/3] [RISCV] Limit VLEN in getOptimalMemOpType to prevent
creating invalid MVTs.
We only guarantee that types that are 1024 bytes or smaller exist
in the MVT enum.
Fixes #139075.
---
llvm/lib/Target/RISCV/RISCVISelLowering.cpp | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
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.
>From dfb9d8338326662bb0453ce22d90bc28459d1eb3 Mon Sep 17 00:00:00 2001
From: Craig Topper <craig.topper at sifive.com>
Date: Thu, 8 May 2025 10:46:41 -0700
Subject: [PATCH 2/3] fixup! clang-format/
---
llvm/lib/Target/RISCV/RISCVISelLowering.cpp | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
index 1bc601a0c399d..d1c8de754b8b3 100644
--- a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
+++ b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
@@ -23488,7 +23488,8 @@ EVT RISCVTargetLowering::getOptimalMemOpType(const MemOp &Op,
// operations emitted here, and that's okay because combining isn't
// introducing new memory operations; it's just merging existing ones.
// NOTE: We limit to 1024 bytes to avoid creating an invalid MVT.
- const unsigned MinVLenInBytes = std::min(Subtarget.getRealMinVLen()/8, 1024U);
+ 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
>From ea2628701aca2ca17ff0555a647916106ac9a55b Mon Sep 17 00:00:00 2001
From: Craig Topper <craig.topper at sifive.com>
Date: Thu, 8 May 2025 11:34:21 -0700
Subject: [PATCH 3/3] fixup! test case
---
llvm/test/CodeGen/RISCV/rvv/pr139075.ll | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
create mode 100644 llvm/test/CodeGen/RISCV/rvv/pr139075.ll
diff --git a/llvm/test/CodeGen/RISCV/rvv/pr139075.ll b/llvm/test/CodeGen/RISCV/rvv/pr139075.ll
new file mode 100644
index 0000000000000..33e8e13a21588
--- /dev/null
+++ b/llvm/test/CodeGen/RISCV/rvv/pr139075.ll
@@ -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
+}
More information about the llvm-commits
mailing list