-
Notifications
You must be signed in to change notification settings - Fork 99
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[RISC-V] codegen seems not ideal #361
Comments
Oh, someday I'll have to become an LLVM developer. I'm 99% sure these strange things have nothing to do with Rust itself, but I need to check anyway. |
|
|
Hi! I'm a developer at lowRISC, working with Alex Bradbury on the RISC-V llvm backend. I've just started (yesterday!) looking at where we can improve the RISC-V Rust backend, in addition to my main LLVM work. The LLVM backend only recently became non-experimental (around the time of the 9.0 branch, with releases imminent). With that, the aim is that we can compile most RISC-V programs in Looking at these issues:
I hope this clears up what's going on! |
For anyone working on branch prediction, this was just recently fixed: rust-lang/rust#109426. Enable like this: SUPERCILEX/hardcaml_riscv@d1125a6#diff-f34d15ec63ba1edb3a7a25b6a3e3b7d3c1f02cbef0b66a6a73e8cf5c959a8576 |
|
The compiler fence seems to disappear when |
Confirmed that this works, So, I guess this would only cause an issue for users trying to run This could be an annoying "gotcha" for the |
Everything sounds like it's working more-or-less as expected now. Anyone object to closing this issue? |
Thanks for triaging! |
Disclaimer: I don't know much of the RISC-V ISA so this may be just my poor
understanding.
Some things I observed while working with the hifive1 board.
jalr
instead ofjal
All direct function calls seems to use some sort of relocatable form. Example
below:
That
auipc
,jalr
combination looks like relocatable code to me (not that Iknow much about relocatable code). I was expecting to see
jal
function callsof this form:
Since the target specification says
relocation-model: "static"
:That would save 4 bytes of
.text
per function call.atomic::compiler_fence
produces an instructionThis program shows that
atomic::compiler_fence
produces afence
instructionEven though the description of the function states that "
compiler_fence
doesnot emit any machine code".
As it is, both
atomic::fence
andatomic::compiler_fence
generate the samemachine code.
You don't see this behavior with the ARM Cortex-M backend:
intrinsics::abort
!=UNIMP
Calling
intrinsics::abort
produces a function call to theabort
symbol eventhough the
UNIMP
instruction exists.I was actually expecting something like this to be generated:
noreturn nounwind
& divergent functionsThe
riscv32imac-unknown-none-elf
target usespanic-strategy: "abort"
; thattells the backend that functions never unwind so divergent functions
fn() -> !
, which never return and are marked as
noreturn nounwind
in LLVM IR, shouldnot preserve the caller "saved registers". However, one observes register
stacking in the following program:
s0
ands1
are pushed onto the stack but never popped. Is that required bythe ISA / C ABI?
(off-topic: why is
ra
also being pushed onto the stack when_start
performsno function call?)
Compare the previous program to this ARM Cortex-M program:
Registers are never pushed onto the stack.
Compare that machine code to the machine code generated for a non-divergent
function:
Registers are pushed in the prologue and then popped in the epilogue of the
function.
It would be good to check if these backend issues have been fixed in the latest
version of LLVM (using
llc
) becauserustc
is using a several months oldLLVM. If a recent commit shows the same issues then we may want to submit bug
reports to the LLVM project.
Metadata
cc @rust-embedded/riscv @Disasm
The text was updated successfully, but these errors were encountered: