Skip to content

SIGILL in LLVM when compiling with -C target-cpu=sandybridge -C opt-level=3 on a Kabylake CPU #122252

Closed
@linkmauve

Description

@linkmauve

Note that I can’t reproduce this SIGILL with -C target-cpu=nehalem, only sandybridge or higher (including native).

The crate I wanted to build is https://github.com/wwylele/astc-decode, here is a minimal version:

Code

use std::convert::TryFrom;

fn read_bits(data: &mut u128, n_bits: u32) -> u32 {
    let ret = *data & ((1 << n_bits) - 1);
    *data >>= n_bits;
    ret as u32
}

fn decode_trit_block(bits: &mut u128, bits_per_value: u32) -> impl Iterator<Item = u32> {
    let mut m = [0u32; 2];
    m[0] = read_bits(bits, bits_per_value);
    m[1] = read_bits(bits, bits_per_value);
    IntoIterator::into_iter(m)
}

pub fn decode_color_values() {
    let encoding = 0;
    let mut color_stream = 0;
    for result in (0..).flat_map(|_| decode_trit_block(&mut color_stream, encoding)) {
        u8::try_from(result).unwrap();
    }
}

Meta

rustc --version --verbose:

rustc 1.78.0-nightly (46b180ec2 2024-03-08)

Error output

% cargo build --release
   Compiling astc-decode v0.3.1 (/home/linkmauve/dev/rust/astc-decode)
error: could not compile `astc-decode` (lib)

Caused by:
  process didn't exit successfully: `/home/linkmauve/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/rustc --crate-name astc_decode --edition=2018 src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=136 --crate-type lib --emit=dep-info,metadata,link -C opt-level=3 -C embed-bitcode=no -C metadata=be6b907dba14f377 -C extra-filename=-be6b907dba14f377 --out-dir /home/linkmauve/dev/rust/astc-decode/target/release/deps -C linker=clang -C strip=debuginfo -L dependency=/home/linkmauve/dev/rust/astc-decode/target/release/deps -C target-cpu=native` (signal: 4, SIGILL: illegal instruction)
Backtrace

(gdb) bt
#0  0x00007ffff07d7d24 in llvm::MVT::getVectorMinNumElements() const [clone .cold.0] () from /home/linkmauve/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM.so.18.1-rust-1.78.0-nightly
#1  0x00007ffff00abdab in llvm::X86TargetLowering::PerformDAGCombine(llvm::SDNode*, llvm::TargetLowering::DAGCombinerInfo&) const () from /home/linkmauve/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM.so.18.1-rust-1.78.0-nightly
#2  0x00007fffefdfc329 in (anonymous namespace)::DAGCombiner::combine(llvm::SDNode*) () from /home/linkmauve/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM.so.18.1-rust-1.78.0-nightly
#3  0x00007ffff00c8ab2 in llvm::SelectionDAG::Combine(llvm::CombineLevel, llvm::AAResults*, llvm::CodeGenOptLevel) () from /home/linkmauve/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM.so.18.1-rust-1.78.0-nightly
#4  0x00007ffff014aacd in llvm::SelectionDAGISel::CodeGenAndEmitDAG() () from /home/linkmauve/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM.so.18.1-rust-1.78.0-nightly
#5  0x00007ffff0147289 in llvm::SelectionDAGISel::SelectAllBasicBlocks(llvm::Function const&) () from /home/linkmauve/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM.so.18.1-rust-1.78.0-nightly
#6  0x00007fffefc83285 in llvm::SelectionDAGISel::runOnMachineFunction(llvm::MachineFunction&) () from /home/linkmauve/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM.so.18.1-rust-1.78.0-nightly
#7  0x00007fffefc829d3 in (anonymous namespace)::X86DAGToDAGISel::runOnMachineFunction(llvm::MachineFunction&) [clone .llvm.1074036353181391359] ()
   from /home/linkmauve/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM.so.18.1-rust-1.78.0-nightly
#8  0x00007fffefdf27bf in llvm::FPPassManager::runOnFunction(llvm::Function&) () from /home/linkmauve/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM.so.18.1-rust-1.78.0-nightly
#9  0x00007fffefdf1cef in llvm::FPPassManager::runOnModule(llvm::Module&) () from /home/linkmauve/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM.so.18.1-rust-1.78.0-nightly
#10 0x00007fffefff6eea in llvm::legacy::PassManagerImpl::run(llvm::Module&) () from /home/linkmauve/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM.so.18.1-rust-1.78.0-nightly
#11 0x00007ffff6974a10 in LLVMRustWriteOutputFile () from /home/linkmauve/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-766f7798aafe0dd0.so
#12 0x00007ffff6974622 in rustc_codegen_llvm::back::write::write_output_file () from /home/linkmauve/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-766f7798aafe0dd0.so
#13 0x00007ffff6971f6c in rustc_codegen_llvm::back::write::codegen () from /home/linkmauve/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-766f7798aafe0dd0.so
#14 0x00007ffff6971c5c in rustc_codegen_ssa::back::write::finish_intra_module_work::<rustc_codegen_llvm::LlvmCodegenBackend> () from /home/linkmauve/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-766f7798aafe0dd0.so
#15 0x00007ffff697bc1c in std::sys_common::backtrace::__rust_begin_short_backtrace::<<rustc_codegen_llvm::LlvmCodegenBackend as rustc_codegen_ssa::traits::backend::ExtraBackendMethods>::spawn_named_thread<rustc_codegen_ssa::back::write::spawn_work<rustc_codegen_llvm::LlvmCodegenBackend>::{closure#0}, ()>::{closure#0}, ()> () from /home/linkmauve/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-766f7798aafe0dd0.so
#16 0x00007ffff697b223 in <<std::thread::Builder>::spawn_unchecked_<<rustc_codegen_llvm::LlvmCodegenBackend as rustc_codegen_ssa::traits::backend::ExtraBackendMethods>::spawn_named_thread<rustc_codegen_ssa::back::write::spawn_work<rustc_codegen_llvm::LlvmCodegenBackend>::{closure#0}, ()>::{closure#0}, ()>::{closure#1} as core::ops::function::FnOnce<()>>::call_once::{shim:vtable#0} () from /home/linkmauve/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-766f7798aafe0dd0.so
#17 0x00007ffff7f59435 in alloc::boxed::{impl#47}::call_once<(), dyn core::ops::function::FnOnce<(), Output=()>, alloc::alloc::Global> () at library/alloc/src/boxed.rs:2016
#18 alloc::boxed::{impl#47}::call_once<(), alloc::boxed::Box<dyn core::ops::function::FnOnce<(), Output=()>, alloc::alloc::Global>, alloc::alloc::Global> () at library/alloc/src/boxed.rs:2016
#19 std::sys::pal::unix::thread::{impl#2}::new::thread_start () at library/std/src/sys/pal/unix/thread.rs:108
#20 0x00007ffff1aa955a in ?? () from /usr/lib/libc.so.6
#21 0x00007ffff1b26a3c in ?? () from /usr/lib/libc.so.6

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.C-bugCategory: This is a bug.I-crashIssue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.llvm-fixed-upstreamIssue expected to be fixed by the next major LLVM upgrade, or backported fixes

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions