This is an archive of the discontinued LLVM Phabricator instance.

[RISCV] Generate 32 bits jumptable entries when code model is small
ClosedPublic

Authored by pcwang-thead on Dec 31 2021, 12:20 AM.

Details

Summary

The code can only address the whole RV32 address space or the lower 2 GiB
of the RV64 address space in small code model, so 32 bits entry is enough.
Cache hit ratio and code size have some improvements.

Diff Detail

Unit TestsFailed

Event Timeline

pcwang-thead requested review of this revision.Dec 31 2021, 12:20 AM
Herald added a project: Restricted Project. · View Herald TranscriptDec 31 2021, 12:20 AM
asb accepted this revision.Jan 6 2022, 4:17 AM

LGTM. It doesn't make much practical difference, but I wonder if gating the getJumpTableEncoding case on RV64 (as well as your other preconditions) might make sense - as the default EK_BlockAddress lowering is equivalent in that case.

This revision is now accepted and ready to land.Jan 6 2022, 4:17 AM
jrtc27 added a comment.EditedJan 6 2022, 7:55 AM

AArch64 does even better and has a PC-relative jump table lowering whose element size depends on how big your switch is, not the code model in use. Ideally this would be made target-independent, or at least copied to RISC-V. That'd let you have small entries even for medany RV64.

pcwang-thead added a comment.EditedJan 6 2022, 7:11 PM

AArch64 does even better and has a PC-relative jump table lowering whose element size depends on how big your switch is, not the code model in use. Ideally this would be made target-independent, or at least copied to RISC-V. That'd let you have small entries even for medany RV64.

Thanks for your advice!

It seems that AArch64 has a pass called AArch64CompressJumpTables to do this, I may add it to RISCV later (or make it a target-independent pass).

Address comment.

AArch64 does even better and has a PC-relative jump table lowering whose element size depends on how big your switch is, not the code model in use. Ideally this would be made target-independent, or at least copied to RISC-V. That'd let you have small entries even for medany RV64.

Thanks for your advice!

It seems that AArch64 has a pass called AArch64CompressJumpTables to do this, I may add it to RISCV later (or make it a target-independent pass).

It may take some time to do these changes, so I will land this patch first.