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

error: failed to parse bitcode for LTO module: Invalid cast #110707

Closed
connerebbinghaus opened this issue Apr 23, 2023 · 1 comment · Fixed by #126923
Closed

error: failed to parse bitcode for LTO module: Invalid cast #110707

connerebbinghaus opened this issue Apr 23, 2023 · 1 comment · Fixed by #126923
Labels
A-SIMD Area: SIMD (Single Instruction Multiple Data) C-bug Category: This is a bug. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ PG-portable-simd Project group: Portable SIMD (https://github.com/rust-lang/project-portable-simd) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@connerebbinghaus
Copy link

Compiling the following in release on the recent nightlies causes a crash. Note that compiling in debug succeeds.

Code

#![feature(portable_simd)]
use std::simd::*;
use std::arch::x86_64::*;

#[target_feature(enable = "sse4.1")]
pub unsafe fn fast_round_sse(i: f32x8) -> f32x8 {
    let a = i.to_array();
    let [low, high]: [[f32; 4]; 2] =
        unsafe { std::mem::transmute::<[f32; 8], [[f32; 4]; 2]>(a) };
        
    let low = f32x4::from(_mm_round_ps::<{_MM_FROUND_TO_NEAREST_INT | _MM_FROUND_NO_EXC}>(f32x4::from_array(low).into()));
    let high = f32x4::from(_mm_round_ps::<{_MM_FROUND_TO_NEAREST_INT | _MM_FROUND_NO_EXC}>(f32x4::from_array(high).into()));

    let a: [f32; 8] =
        unsafe { std::mem::transmute::<[[f32; 4]; 2], [f32; 8]>([low.to_array(), high.to_array()]) };
    f32x8::from_array(a)
}

//#[target_feature(enable = "sse4.1")]
//pub unsafe fn round_many(b: &mut [f32x8]) {
//    for a in b {
//        *a = fast_round_sse(*a);
//    }
//}

Meta

rustc --version --verbose:

rustc 1.71.0-nightly (fec9adcdb 2023-04-21)
binary: rustc
commit-hash: fec9adcdbc21469ef105162cc8cabf81c72d06be
commit-date: 2023-04-21
host: x86_64-unknown-linux-gnu
release: 1.71.0-nightly
LLVM version: 16.0.2

Error output

error: failed to parse bitcode for LTO module: Invalid cast (Producer: 'LLVM16.0.2-rust-1.71.0-nightly' Reader: 'LLVM 16.0.2-rust-1.71.0-nightly')

error: could not compile `ice_repro` (lib) due to previous error

If the round_many function is uncommented, rustc instead crashes with an illegal instruction

error: could not compile `ice_repro` (lib)

Caused by:
  process didn't exit successfully: `rustc --crate-name ice_repro --edition=2021 src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=236 --crate-type lib --emit=dep-info,metadata,link -C opt-level=3 -C embed-bitcode=no -C metadata=720812225537f937 -C extra-filename=-720812225537f937 --out-dir /home/conner/ice_repro/target/release/deps -L dependency=/home/conner/ice_repro/target/release/deps` (signal: 4, SIGILL: illegal instruction)

Bisect

searched nightlies: from nightly-2023-04-17 to nightly-2023-04-23
regressed nightly: nightly-2023-04-18
searched commit range: d0f204e...7908a1d
regressed commit: 5546cb6

bisected with cargo-bisect-rustc v0.6.6

Host triple: x86_64-unknown-linux-gnu
Reproduce with:

cargo bisect-rustc -- build --release 
@connerebbinghaus connerebbinghaus 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 Apr 23, 2023
@saethlin
Copy link
Member

This bisects to a MIR inlining PR, but the actual bug here is related to lowering of repr(simd). It's possible to write code that gets lowered to invalid LLVM IR without MIR inlining, but the code required is rather contrived.

This has been extensively discussed on the Zulip: https://rust-lang.zulipchat.com/#narrow/stream/257879-project-portable-simd/topic/splat.20no.20longer.20compiles.20for.20release.20builds I'm surprised nobody else opened an issue for this. Thanks!

@saethlin saethlin added the PG-portable-simd Project group: Portable SIMD (https://github.com/rust-lang/project-portable-simd) label Apr 23, 2023
@workingjubilee workingjubilee added E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. A-SIMD Area: SIMD (Single Instruction Multiple Data) labels May 15, 2023
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. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ PG-portable-simd Project group: Portable SIMD (https://github.com/rust-lang/project-portable-simd) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants