This patch implements relaxation for RISCV in the MC layer. The following relaxations are currently handled: 1) Relax C_BEQZ to BEQ and C_BNEZ to BNEZ in RISCV. 2) Relax and C_J $imm to JAL x0, $imm and CJAL to JAL ra, $imm.
Details
Diff Detail
Event Timeline
Thanks for adding the test case, I added a few minor comments there.
After resolving those, the only remaining issue would be the lack of test coverage for negative offsets.
lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp | ||
---|---|---|
95–96 | Are you happy to remove this FIXME? Looking at the test case, it seems to me that the correct offset is generated. Please take a look at the objdump and check you agree. | |
test/MC/RISCV/relaxation.s | ||
1–2 ↗ | (On Diff #136459) | Using pipes here is a more user-friendly, as in the case of a test failure you get a nicer command to copy and paste that doesn't produce unwanted temporaries. Given we expect this to work for riscv64 as well, add a RUN line for that too: # RUN: llvm-mc -filetype=obj -triple riscv32 -mattr=+c < %s \ # RUN: | llvm-objdump -d - | FileCheck -check-prefix=INSTR %s # RUN: llvm-mc -filetype=obj -triple riscv64 -mattr=+c < %s \ # RUN: | llvm-objdump -d - | FileCheck -check-prefix=INSTR %s |
5 ↗ | (On Diff #136459) | I think checking the instruction location is unnecessary (and a little brittle) as you're already using #INSTR-NEXT. You should include all instruction operands in the check line as that demonstrates that the fixup has been resolved to a sensible value. e.g. |
test/MC/RISCV/relaxation.s | ||
---|---|---|
1–2 ↗ | (On Diff #136459) | c.jal is an RV32C instruction only, so I think I have to break this test into two tests. One for 32 and one for 64 bits. |
5 ↗ | (On Diff #136459) | I added the location because I wanted to check for the instruction size (2 or 4). But I think you are right, it is enough to check the mnemonic for that and check all the operands. |
Looks good to me. You might want to use c.nop in the tests rather than nop to avoid test churn (changing offsets) once automatic compression is merged.
Thanks for the timely review, Alex!
Updated the nop to c.nop in the committed version.
Are you happy to remove this FIXME? Looking at the test case, it seems to me that the correct offset is generated. Please take a look at the objdump and check you agree.