Skip to content

Commit a354564

Browse files
authored
[RISCV] Strengthen register usage validation for XTheadMemPair loads (#136241)
Closes #136087 https://github.com/XUANTIE-RV/thead-extension-spec/blob/master/xtheadmempair/lwd.adoc
1 parent 5b2c743 commit a354564

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
@@ -3648,9 +3648,9 @@ bool RISCVAsmParser::validateInstruction(MCInst &Inst,
36483648
MCRegister Rd2 = Inst.getOperand(1).getReg();
36493649
MCRegister Rs1 = Inst.getOperand(2).getReg();
36503650
// The encoding with rd1 == rd2 == rs1 is reserved for XTHead load pair.
3651-
if (Rs1 == Rd1 && Rs1 == Rd2) {
3651+
if (Rs1 == Rd1 || Rs1 == Rd2 || Rd1 == Rd2) {
36523652
SMLoc Loc = Operands[1]->getStartLoc();
3653-
return Error(Loc, "rs1, rd1, and rd2 cannot all be the same");
3653+
return Error(Loc, "rs1, rd1, and rd2 cannot overlap");
36543654
}
36553655
}
36563656

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, 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

0 commit comments

Comments
 (0)