-
Notifications
You must be signed in to change notification settings - Fork 13.3k
RISC-V Codegen Problem with type information #114508
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
Comments
LLVM integers types do not differentiate between signed or unsigned integers. It's the operation (ie the intrinsic) that makes the differentiation and
It's seems to me that it's a problem with the RISC-V LLVM backend. @rustbot labels: +A-LLVM +A-codegen +O-riscv +T-compiler -needs-triage |
According to the documentation, for RV64, the registers are 64 bits wide. The arguments of the |
The problem here is that we don't set |
cc @kito-cheng @michaelmaitland @robin-randhawa-sifive Please triage and/or address this issue. |
I don't think there is a problem here. I think this statement is incorrect.
As @rakicaleksandar1999 points out, on RV64, the registers are 64 bits wide. The I think we should be able to close this issue. |
Hm, this does compile to just pub extern "C" fn max(a: u32 , b: u32) -> u32 {
u32::max(a, b)
} becomes example::max::hd12728cb718981ea:
maxu a0, a0, a1
ret |
C++ can also be compiled into just one https://godbolt.org/z/x9dv5v1h3 uint32_t max(uint32_t x, uint32_t y) {
return std::max(x, y);
} max(unsigned int, unsigned int):
maxu a0,a0,a1
ret |
Can rust generate I think this should fix the problem. |
@nikic where is the distinction between Rust ABI and |
All of the relevant code should be in
But if it's not it may be somewhere in:
And rustc will indeed generate
|
@rustbot claim I wanna give it a try. |
After staring at the code a bit longer. I think the RISC-V specific code only runs via |
Probably so! Unless this is expected to be generally profitable, in which case we could give doing it on all platforms a go. |
One option to fix is to add the extension in Edit: it looks like we tried to but didn't? |
Wasn't the loongarch.rs code copied from riscv.rs? The problem is that no target specific code is used for the Rust ABI. |
Is not generally profitable. It's a RISC-V-ism that was also copied to LoongArch. They are the only 2 in tree targets in LLVM that don't have i32 as a legal type. |
We should probably introduce a similar fn named something like |
Set `signext` or `zeroext` for integer arguments on RISC-V and LoongArch64 Fixes rust-lang#114508. This PR contains 3 commits: - the first one introduces a new function `adjust_for_rust_abi` in `rustc_target`, and moves the x86 specific adjustment code into it; - the second one adds RISC-V specific adjustment code into it, which sets `signext` or `zeroext` attribute for integer arguments. - **UPDATE**: added the 3rd commit for apply the same adjustment for LoongArch64. r? `@workingjubilee` CC `@coastalwhite` `@Urgau` `@topperc` `@michaelmaitland` try-job: dist-loongarch64-linux try-job: dist-riscv64-linux try-job: test-various try-job: i686-gnu-nopt try-job: i686-gnu
Set `signext` or `zeroext` for integer arguments on RISC-V and LoongArch64 Fixes rust-lang#114508. This PR contains 3 commits: - the first one introduces a new function `adjust_for_rust_abi` in `rustc_target`, and moves the x86 specific adjustment code into it; - the second one adds RISC-V specific adjustment code into it, which sets `signext` or `zeroext` attribute for integer arguments. - **UPDATE**: added the 3rd commit for apply the same adjustment for LoongArch64. r? `@workingjubilee` CC `@coastalwhite` `@Urgau` `@topperc` `@michaelmaitland` try-job: dist-loongarch64-linux try-job: dist-riscv64-linux try-job: test-various try-job: i686-gnu-nopt try-job: i686-gnu
Codegen for
riscv64gc-unknown-linux-gnu
sends wrong type information to LLVM.When I compile on godbolt.org with the following flags.
GodBolt Link
I tried this code:
It outputs:
It definitely does not need to sign extend
a0
ora1
and in fact, when we inspect the LLVM IR, it seems to assume that the numbers arei32
s instead ofu32
s. Is this a problem with Rust's codegen output?LLVM IR:
Properly optimized code would be:
The text was updated successfully, but these errors were encountered: