Skip to content

[RISCV] Strengthen register usage validation for XTheadMemPair loads #136241

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}

Expand Down
3 changes: 2 additions & 1 deletion llvm/test/MC/RISCV/rv32xtheadmempair-invalid.s
Original file line number Diff line number Diff line change
Expand Up @@ -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{{$}}
3 changes: 2 additions & 1 deletion llvm/test/MC/RISCV/rv64xtheadmempair-invalid.s
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ 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.ldd x6, x6, (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
Loading