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

Broken LLVM intrinsics with SIMD FFI on riscv64gc #77866

Closed
calebzulawski opened this issue Oct 12, 2020 · 3 comments
Closed

Broken LLVM intrinsics with SIMD FFI on riscv64gc #77866

calebzulawski opened this issue Oct 12, 2020 · 3 comments
Labels
A-SIMD Area: SIMD (Single Instruction Multiple Data) C-bug Category: This is a bug. F-simd_ffi `#![feature(simd_ffi)]` I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@calebzulawski
Copy link
Member

calebzulawski commented Oct 12, 2020

I could only produce this error when running cargo test (I actually used cross test), and only on riscv64gc-unknown-linux-gnu. This was discovered in stdsimd: rust-lang/portable-simd#34 (failing github actions job).

Code

#![feature(link_llvm_intrinsics, repr_simd, simd_ffi)]

#[allow(non_camel_case_types)]
#[repr(simd)]
struct v2f32(f32, f32);

#[allow(improper_ctypes)]
extern "C" {
    #[link_name = "llvm.round.v2f32"]
    fn round_v2f32(x: v2f32) -> v2f32;
}

#[cfg(test)]
mod test {
    #[test]
    fn round_v2f32() {
        let _ = unsafe { crate::round_v2f32(crate::v2f32(0.5, 0.5)) };
    }
}

Meta

rustc --version --verbose:

rustc 1.49.0-nightly (38d911dfc 2020-10-09)
binary: rustc
commit-hash: 38d911dfc55a7a1eea1c80139113ed2ff0151087
commit-date: 2020-10-09
host: x86_64-apple-darwin
release: 1.49.0-nightly
LLVM version: 11.0

Error output

   Compiling llvminttest v0.1.0 (/project)
Intrinsic has incorrect return type!
i64 (i64)* @llvm.round.v2f32
in function _ZN11llvminttest4test11round_v2f3217h00423c4f93b51af2E
LLVM ERROR: Broken function found, compilation aborted!
error: could not compile `llvminttest`.

To learn more, run the command again with --verbose.
@calebzulawski calebzulawski added C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Oct 12, 2020
@jonas-schievink jonas-schievink added A-SIMD Area: SIMD (Single Instruction Multiple Data) F-simd_ffi `#![feature(simd_ffi)]` labels Oct 12, 2020
@programmerjake
Copy link
Member

I am not familiar with rustc's internals, but I'm inclined to say that the LLVM IR produced for functions declared extern "C" is correct, the bug is that LLVM intrinsic functions should not be extern "C", they should be extern "llvm-ir" or something like that. extern "C" FFI lowering is split between LLVM and rustc/clang/etc., we shouldn't expect it to produce any particular LLVM IR.

@workingjubilee
Copy link
Member

This is indeed kinda close to "not actually a bug, per se, but an expected result of willfully and unwisely generating LLVM IR and then expecting it to take a form viable for FFI" but until we shake out our story regarding this a bit more I am leaving this open.

@workingjubilee
Copy link
Member

From the perspective of a little more experience, this seems to be "not actually a bug", just an annoying "feature" in how LLVM works. We have to tightly control how we expose our interfaces to C code, rather than assuming that LLVM intrinsics expose anything FFI friendly. Closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-SIMD Area: SIMD (Single Instruction Multiple Data) C-bug Category: This is a bug. F-simd_ffi `#![feature(simd_ffi)]` I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants