Skip to content

Commit a8fdd09

Browse files
committed
[Exegesis][RISCV] Support C_LDSP for llvm-exegesis
Fix error: ``` *** Bad machine code: Illegal physical register for instruction *** - function: foo - basic block: %bb.0 (0x5e2262bd3f20) - instruction: $x10 = C_LDSP $x10, 0 - operand 1: $x10 $x10 is not a SP register. llvm-exegesis error: The machine function failed verification. ```
1 parent 04bddda commit a8fdd09

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

llvm/test/tools/llvm-exegesis/RISCV/latency-by-extension-C.s

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,12 @@ C_SRLI-NEXT: key:
4646
C_SRLI-NEXT: instructions:
4747
C_SRLI-NEXT: - 'C_SRLI [[REG101:X[0-9]+]] [[REG102:X[0-9]+]] [[IMM10:i_0x[0-9]+]]'
4848
C_SRLI-DAG: ...
49+
50+
# RUN: llvm-exegesis -mode=latency -mtriple=riscv64-unknown-linux-gnu --mcpu=generic --benchmark-phase=assemble-measured-code -opcode-name=C_LDSP -mattr=+c | FileCheck --check-prefix=C_LDSP %s
51+
52+
C_LDSP: ---
53+
C_LDSP-NEXT: mode: latency
54+
C_LDSP-NEXT: key:
55+
C_LDSP-NEXT: instructions:
56+
C_LDSP-NEXT: - 'C_LDSP [[REG101:X[0-9]+]] [[REG102:X[0-9]+]] [[IMM10:i_0x[0-9]+]]'
57+
C_LDSP-DAG: ...

llvm/tools/llvm-exegesis/lib/RISCV/Target.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -819,6 +819,14 @@ void ExegesisRISCVTarget::fillMemoryOperands(InstructionTemplate &IT,
819819

820820
assert(MemOp.isReg() && "Memory operand expected to be register");
821821

822+
unsigned Opcode = I.getOpcode();
823+
if (Opcode == RISCV::C_LDSP || Opcode == RISCV::C_LWSP ||
824+
Opcode == RISCV::C_SDSP || Opcode == RISCV::C_SWSP) {
825+
// Force base register to SP (X2)
826+
IT.getValueFor(MemOp) = MCOperand::createReg(RISCV::X2);
827+
return;
828+
}
829+
822830
IT.getValueFor(MemOp) = MCOperand::createReg(Reg);
823831
}
824832

0 commit comments

Comments
 (0)