Skip to content

Commit 155fc76

Browse files
el-evtopperc
authored andcommitted
Recommit "[RISCV] Strengthen register usage validation for XTheadMemPair loads (#136241)"
With test fix. Closes #136087 https://github.com/XUANTIE-RV/thead-extension-spec/blob/master/xtheadmempair/lwd.adoc
1 parent b07ee6a commit 155fc76

File tree

3 files changed

+6
-4
lines changed

3 files changed

+6
-4
lines changed

llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3656,9 +3656,9 @@ bool RISCVAsmParser::validateInstruction(MCInst &Inst,
36563656
MCRegister Rd2 = Inst.getOperand(1).getReg();
36573657
MCRegister Rs1 = Inst.getOperand(2).getReg();
36583658
// The encoding with rd1 == rd2 == rs1 is reserved for XTHead load pair.
3659-
if (Rs1 == Rd1 && Rs1 == Rd2) {
3659+
if (Rs1 == Rd1 || Rs1 == Rd2 || Rd1 == Rd2) {
36603660
SMLoc Loc = Operands[1]->getStartLoc();
3661-
return Error(Loc, "rs1, rd1, and rd2 cannot all be the same");
3661+
return Error(Loc, "rs1, rd1, and rd2 cannot overlap");
36623662
}
36633663
}
36643664

llvm/test/MC/RISCV/rv32xtheadmempair-invalid.s

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ th.lwd a3, a4, (a5), 3, 5 # CHECK: [[@LINE]]:25: error: operand must be consta
1515
th.swd t3, t4, (t5), 5, 4 # CHECK: [[@LINE]]:22: error: immediate must be an integer in the range [0, 3]
1616
th.swd t3, t4, (t5) # CHECK: [[@LINE]]:1: error: too few operands for instruction
1717
th.swd t3, t4, (t5), 3, 5 # CHECK: [[@LINE]]:25: error: operand must be constant 3
18-
th.lwud x6, x6, (x6), 2, 3 # CHECK: [[@LINE]]:9: error: rs1, rd1, and rd2 cannot all be the same
18+
th.lwd x6, x7, (x7), 2, 3 # CHECK: [[@LINE]]:8: error: rs1, rd1, and rd2 cannot overlap
19+
th.lwud x6, x6, (x6), 2, 3 # CHECK: [[@LINE]]:9: error: rs1, rd1, and rd2 cannot overlap
1920
th.ldd t0, t1, (t2), 2, 4 # CHECK: [[@LINE]]:1: error: instruction requires the following: RV64I Base Instruction Set{{$}}
2021
th.sdd t0, t1, (t2), 2, 4 # CHECK: [[@LINE]]:1: error: instruction requires the following: RV64I Base Instruction Set{{$}}

llvm/test/MC/RISCV/rv64xtheadmempair-invalid.s

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,5 @@ th.lwd a3, a4, (a5), 3, 5 # CHECK: [[@LINE]]:25: error: operand must be consta
1515
th.swd t3, t4, (t5), 5, 4 # CHECK: [[@LINE]]:22: error: immediate must be an integer in the range [0, 3]
1616
th.swd t3, t4, (t5) # CHECK: [[@LINE]]:1: error: too few operands for instruction
1717
th.swd t3, t4, (t5), 3, 5 # CHECK: [[@LINE]]:25: error: operand must be constant 3
18-
th.lwud x6, x6, (x6), 2, 3 # CHECK: [[@LINE]]:9: error: rs1, rd1, and rd2 cannot all be the same
18+
th.ldd x6, x6, (x7), 2, 4 # CHECK: [[@LINE]]:8: error: rs1, rd1, and rd2 cannot overlap
19+
th.lwud x6, x6, (x6), 2, 3 # CHECK: [[@LINE]]:9: error: rs1, rd1, and rd2 cannot overlap

0 commit comments

Comments
 (0)