mold
mold copied to clipboard
RV64: Relax AUIPC+JALR to C.JAL
Currently, we relax AUIPC+JALR only to JAL, but if the C extension is available and the displacement is within its range, we should optimize it further to C.JAL. Doing this should save extra one byte for each instruction.
It looks like most if not all Unix-like systems assume that the C extension is supported, so we may not have to detect if C.JAL is allowed. Instead, we may want to assume that C.JAL is always usable.
It seems that C.JAL is an RV32IC-only instruction, so this optimization may not work with RV64.
Are you sure? I thought that it's also a part of the RV64 C extension.
Yes, C.ADDIW is an RV64-only instruction, they share the same opcode.
Copied from the Spec:
C.JAL is an RV32C-only instruction that performs the same operation as C.J, but additionally writes the address of the instruction following the jump (pc+2) to the link register, x1. C.JAL expands to jal x1, offset.
Oh, that's true. Thank you for pointing it out!