Skip to content

ICE due to generating LLVM bitcast vec -> array #105439

Closed
@JakobDegen

Description

@JakobDegen

Found here: #105344 (comment)

Code:

#![feature(portable_simd)]
fn main() {
    use core::simd::Simd;
    let a = Simd::from_array([0, 4, 1, 5]);
    let b = Simd::from_array([2, 6, 3, 7]);
    let (x, y) = a.deinterleave(b);
    assert_eq!(x.to_array(), [0, 1, 2, 3]);
    assert_eq!(y.to_array(), [4, 5, 6, 7]);
}

Invocation:

$ rustc +nightly --version
rustc 1.67.0-nightly (e1d819583 2022-12-05)
binary: rustc
commit-hash: e1d819583f0bf13b016b119c1c2c43e6d3979450
commit-date: 2022-12-05
host: x86_64-unknown-linux-gnu
release: 1.67.0-nightly
LLVM version: 15.0.4
Compiler returned: 0
$ rustc +nightly --edition 2021 -C opt-level=3 -Zmir-opt-level=3 -C no-prepopulate-passes

Causes an LLVM ICE:

Invalid bitcast
  %27 = bitcast <4 x i32> %22 to [4 x i32], !dbg !268
Invalid bitcast
  %31 = bitcast <4 x i32> %26 to [4 x i32], !dbg !280
in function _ZN7example4main17h82e1f57aed922fc8E
LLVM ERROR: Broken function found, compilation aborted!
Compiler returned: 101

This reproduces easily on Godbolt.

The invalid bitcast is introduced by codgen for the MIR statement _1 = (_25.0: [i32; 4]); on line 151.

Local _25 has type std::simd::Simd<i32, 4>. I believe the bitcast is introduced here, but I don't think this path is even intended to handle Simd types. I'm not exactly sure what the bug here is either, ie I have no idea how this was supposed to be codegened.

@rustbot label +A-codegen +A-llvm +I-ICE +T-compiler

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.A-SIMDArea: SIMD (Single Instruction Multiple Data)A-codegenArea: Code generationI-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️PG-portable-simdProject group: Portable SIMD (https://github.com/rust-lang/project-portable-simd)T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions