Skip to content

Conversation

@lenary
Copy link
Member

@lenary lenary commented Jul 2, 2025

These relaxations are implemented as part of
RISCVLDBackend::doRelaxationCall as they apply to the same relocation/instructions.

The relaxations are:

  • AUIPC; JALR ra -> QC.E.JAL
  • AUIPC; JALR zero -> QC.E.J

These respect the existing command-line switches which prevent these being applied when relaxations (or xqci relaxations) are disabled. This is particularly important in this case as standard instructions are replaced by custom Xqci instructions, which will fail to execute on most RISC-V implementations.

These relaxations are described in
http://github.com/quic/riscv-elf-psabi-quic-extensions/releases/latest

This continues the implementation of #147.

I also took the time to refactor doRelaxationCall to make the priority between relaxations clearer, and the verbose "relaxation missed" messages be emitted later, once we're surer the relaxation has been missed.

@lenary
Copy link
Member Author

lenary commented Jul 8, 2025

This PR has bugs. Working on them.

@lenary
Copy link
Member Author

lenary commented Jul 9, 2025

Trying something now, where I undo unnecessary changes to try to work out what's causing the failures/bugs I'm seeing.

@lenary lenary force-pushed the pr/riscv-xqci-call-relax branch 3 times, most recently from 0a0187f to fad37a2 Compare July 9, 2025 19:54
@lenary lenary force-pushed the pr/riscv-xqci-call-relax branch from 1dddeb9 to d1a9688 Compare July 25, 2025 01:17
@lenary
Copy link
Member Author

lenary commented Jul 25, 2025

I'm going to call out the following again from the message:

I also took the time to refactor doRelaxationCall to make the priority between relaxations clearer, and the verbose "relaxation missed" messages be emitted later, once we're surer the relaxation has been missed.

The structure of the whole function is now different. This is broadly because instead of choosing between 2 different possible relaxations (CALL to JAL or CALL to C_JAL), there are now three. This means a lot of the logic was going to end up with more and more nested ternaries and the like, and the logic was getting difficult to follow.

Instead, the function is now written in the following way:

  1. Calculate the relocation value and look at the instructions to work out rd.
  2. Check which relaxations are possible, without actually doing the relaxation.
  3. For each relaxation, in order of most preferred (smallest, usually) to least (largest, usually), if that relaxation is allowed:
    • Do the relaxation
    • Report a missed relaxation if this did not result in the shortest code sequence.
    • Exit
  4. If no relaxations were done, report a missed relaxation

One nice advantage of how this ends up working is that DeletedBytes + MissedBytes should always equal the same amount, which seems like a reasonable invariant for users to follow. The disadvantage is that there will likely always be missed relaxations because not all calls can be turned into c.jal (which has a short range).

@lenary lenary marked this pull request as ready for review July 31, 2025 04:26
@lenary
Copy link
Member Author

lenary commented Jul 31, 2025

From my PoV, this is ready to land, and I would like it to be backported to llvm 21. I think I have addressed the core of all of the comments so far.

These relaxations are implemented as part of
RISCVLDBackend::doRelaxationCall as they apply to the same
relocation/instructions.

The relaxations are:
- `AUIPC; JALR ra`   -> `QC.E.JAL`
- `AUIPC; JALR zero` -> `QC.E.J`

These respect the existing command-line switches which prevent these
being applied when relaxations (or xqci relaxations) are disabled.

These relaxations are described in
http://github.com/quic/riscv-elf-psabi-quic-extensions/releases/latest

This continues the implementation of qualcomm#147.

I also took the time to refactor `doRelaxationCall` to make the priority
between relaxations clearer, and the verbose "relaxation missed"
messages be emitted later, once we're surer the relaxation has been
missed.

Signed-off-by: Sam Elliott <aelliott@qti.qualcomm.com>
@lenary lenary force-pushed the pr/riscv-xqci-call-relax branch from 5c72eb7 to 73a34cf Compare August 1, 2025 18:42
@quic-seaswara quic-seaswara merged commit 7c0a0fc into qualcomm:main Aug 1, 2025
3 checks passed
@lenary lenary deleted the pr/riscv-xqci-call-relax branch September 23, 2025 17:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants