[llvm] [RISCV] Strengthen register usage validation for XTheadMemPair loads (PR #136241)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 17 19:27:58 PDT 2025
https://github.com/el-ev created https://github.com/llvm/llvm-project/pull/136241
Closes #136087
https://github.com/XUANTIE-RV/thead-extension-spec/blob/master/xtheadmempair/lwd.adoc
>From 93b41b7107934416a5184cea1a60c469ee5e84f0 Mon Sep 17 00:00:00 2001
From: Iris Shi <0.0 at owo.li>
Date: Fri, 18 Apr 2025 10:24:03 +0800
Subject: [PATCH] [RISCV] Strengthen register usage validation for
XTheadMemPair loads
---
llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp | 4 ++--
llvm/test/MC/RISCV/rv32xtheadmempair-invalid.s | 3 ++-
2 files changed, 4 insertions(+), 3 deletions(-)
diff --git a/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp b/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
index 7e2821404ef95..4178e29b81976 100644
--- a/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
+++ b/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
@@ -3648,9 +3648,9 @@ bool RISCVAsmParser::validateInstruction(MCInst &Inst,
MCRegister Rd2 = Inst.getOperand(1).getReg();
MCRegister Rs1 = Inst.getOperand(2).getReg();
// The encoding with rd1 == rd2 == rs1 is reserved for XTHead load pair.
- if (Rs1 == Rd1 && Rs1 == Rd2) {
+ if (Rs1 == Rd1 || Rs1 == Rd2 || Rd1 == Rd2) {
SMLoc Loc = Operands[1]->getStartLoc();
- return Error(Loc, "rs1, rd1, and rd2 cannot all be the same");
+ return Error(Loc, "rs1, rd1, and rd2 cannot overlap");
}
}
diff --git a/llvm/test/MC/RISCV/rv32xtheadmempair-invalid.s b/llvm/test/MC/RISCV/rv32xtheadmempair-invalid.s
index 9124218c1f8f5..6b95b3dc66b43 100644
--- a/llvm/test/MC/RISCV/rv32xtheadmempair-invalid.s
+++ b/llvm/test/MC/RISCV/rv32xtheadmempair-invalid.s
@@ -15,6 +15,7 @@ th.lwd a3, a4, (a5), 3, 5 # CHECK: [[@LINE]]:25: error: operand must be consta
th.swd t3, t4, (t5), 5, 4 # CHECK: [[@LINE]]:22: error: immediate must be an integer in the range [0, 3]
th.swd t3, t4, (t5) # CHECK: [[@LINE]]:1: error: too few operands for instruction
th.swd t3, t4, (t5), 3, 5 # CHECK: [[@LINE]]:25: error: operand must be constant 3
-th.lwud x6, x6, (x6), 2, 3 # CHECK: [[@LINE]]:9: error: rs1, rd1, and rd2 cannot all be the same
+th.lwd x6, x7, (x7), 2, 3 # CHECK: [[@LINE]]:8: error: rs1, rd1, and rd2 cannot overlap
+th.lwud x6, x6, (x6), 2, 3 # CHECK: [[@LINE]]:9: error: rs1, rd1, and rd2 cannot overlap
th.ldd t0, t1, (t2), 2, 4 # CHECK: [[@LINE]]:1: error: instruction requires the following: RV64I Base Instruction Set{{$}}
th.sdd t0, t1, (t2), 2, 4 # CHECK: [[@LINE]]:1: error: instruction requires the following: RV64I Base Instruction Set{{$}}
More information about the llvm-commits
mailing list