Skip to content
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

LLVM intrinsic emission is inconsistent #88817

Closed
MabezDev opened this issue Sep 10, 2021 · 4 comments
Closed

LLVM intrinsic emission is inconsistent #88817

MabezDev opened this issue Sep 10, 2021 · 4 comments
Labels
C-bug Category: This is a bug.

Comments

@MabezDev
Copy link
Contributor

Running the following snippet across a few different platforms (x86_64-unknown-linux-gnu, riscv32imc-esp-espidf) has varying results in the intrinsic's used in the llvm-ir output.

let f: f32 = 1.0;
let f = f.mul_add(2.0, 3.0);
println!("f = {}", f);

I would expect the llvm-ir for each target to have calls in llvm intrinsic's, because that's exactly whats in the function body of mul_add, however on the riscv32imc-esp-espidf platform, this doesn't always end up happening.

Adding a call to a new unstable function lerp for example, and the intrinsic is now emitted in the llvm-ir even though its calling the same mul_add functions inside it.

I thought maybe compiler_builtins might have an implementation that is used in the simple example, but that doesn't seem to be the case.

Meta

rustc --version --verbose:

1.55.0, also happens on 1.54.0 too

also on a side note, where can I find the intrinsic's that must be implemented for a std platform? I notice in the case of the float modules, some calls use intrinsic's, some use cmath. I would be great to have a list of the required intrinsic's as we are bringing up Xtensa Rust support.

@MabezDev MabezDev added the C-bug Category: This is a bug. label Sep 10, 2021
@nagisa
Copy link
Member

nagisa commented Sep 10, 2021

What the actual motivation underlying this? What LLVM-IR Rust generates is entirely an implementation detail of the compiler, so I'm not sure we do or will guarantee any specific output in terms of LLVM-IR.

@MabezDev
Copy link
Contributor Author

The motivation is that I am bootstrapping Xtensa targets, in which we are also running a fork of llvm. When rebasing the rust patchset on top of 1.55, our standard library port stopped compiling, throwing a missing intrinsic error (fma). Specifically it failed in a new function introduced in 1.55, lerp .I noticed that just using mul_add did not emit a intrinsic call, but the inclusion of lerp did.

Overall, I guess it doesn't matter if the compiler does emit it or not. What matters is can the compiler emit it? Is there a list (or an easy way to find) the intrinsics used by the standard library, so we can implement them in our llvm fork?

@nagisa
Copy link
Member

nagisa commented Sep 13, 2021

https://github.com/rust-lang/rust/blob/master/compiler/rustc_codegen_llvm/src/intrinsic.rs is probably a good way to find out all of the LLVM intrinsic calls that we might emit for some Rust code. grep for llvm. in that file for a list.

@MabezDev
Copy link
Contributor Author

Thanks for the assistance @nagisa, we've resolved the issue by correctly implementing the basic llvm intrinsics.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug.
Projects
None yet
Development

No branches or pull requests

2 participants