Skip to content

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

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

Closed
linkmauve opened this issue Mar 9, 2024 · 3 comments · Fixed by #122559
Labels
A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. C-bug Category: This is a bug. I-crash Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics. llvm-fixed-upstream Issue expected to be fixed by the next major LLVM upgrade, or backported fixes T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@linkmauve
Copy link
Contributor

linkmauve commented Mar 9, 2024

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

@linkmauve linkmauve 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 Mar 9, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Mar 9, 2024
@nikic nikic added the A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. label Mar 9, 2024
@linkmauve linkmauve changed the title SIGILL in LLVM when compiling with -C target-cpu=native -C opt-level=3 on a Kabylake CPU SIGILL in LLVM when compiling with -C target-cpu=sandybridge -C opt-level=3 on a Kabylake CPU Mar 9, 2024
@saethlin
Copy link
Member

saethlin commented Mar 9, 2024

LLVM assertion:

rustc: /checkout/src/llvm-project/llvm/include/llvm/CodeGen/ValueTypes.h:300: MVT llvm::EVT::getSimpleVT() const: Assertion `isSimple() && "Expected a SimpleValueType!"' failed.
#5  0x00007195748dbd46 in __assert_fail (
    assertion=0x71956bda6f50 <str.70.llvm> "isSimple() && \"Expected a SimpleValueType!\"", 
    file=0x71956bcd2af1 <str.96.llvm> "/checkout/src/llvm-project/llvm/include/llvm/CodeGen/ValueTypes.h", line=300, 
    function=0x71956c1abf90 <__PRETTY_FUNCTION__._ZNK4llvm3EVT11getSimpleVTEv.llvm.3367855232127228133> "MVT llvm::EVT::getSimpleVT() const") at assert.c:103
#6  0x0000719573768dfa in llvm::X86TargetLowering::PerformDAGCombine(llvm::SDNode*, llvm::TargetLowering::DAGCombinerInfo&) const [clone .cold.0] () from /home/ben/.rustup/toolchains/master-stage1/lib/libLLVM.so.18.1-rust-1.78.0-nightly
#7  0x0000719572887561 in (anonymous namespace)::DAGCombiner::combine(llvm::SDNode*) ()
   from /home/ben/.rustup/toolchains/master-stage1/lib/libLLVM.so.18.1-rust-1.78.0-nightly
#8  0x0000719572886402 in llvm::SelectionDAG::Combine(llvm::CombineLevel, llvm::AAResults*, llvm::CodeGenOptLevel) ()
   from /home/ben/.rustup/toolchains/master-stage1/lib/libLLVM.so.18.1-rust-1.78.0-nightly
#9  0x00007195728a74bb in llvm::SelectionDAGISel::CodeGenAndEmitDAG() ()
   from /home/ben/.rustup/toolchains/master-stage1/lib/libLLVM.so.18.1-rust-1.78.0-nightly
#10 0x00007195729d3f7d in llvm::SelectionDAGISel::SelectAllBasicBlocks(llvm::Function const&) ()
   from /home/ben/.rustup/toolchains/master-stage1/lib/libLLVM.so.18.1-rust-1.78.0-nightly
#11 0x00007195729478f6 in llvm::SelectionDAGISel::runOnMachineFunction(llvm::MachineFunction&) ()
   from /home/ben/.rustup/toolchains/master-stage1/lib/libLLVM.so.18.1-rust-1.78.0-nightly
#12 0x000071957294721a in (anonymous namespace)::X86DAGToDAGISel::runOnMachineFunction(llvm::MachineFunction&) [clone .llvm.5886998833922345724] () from /home/ben/.rustup/toolchains/master-stage1/lib/libLLVM.so.18.1-rust-1.78.0-nightly
#13 0x0000719572623ad8 in llvm::MachineFunctionPass::runOnFunction(llvm::Function&) ()
   from /home/ben/.rustup/toolchains/master-stage1/lib/libLLVM.so.18.1-rust-1.78.0-nightly
#14 0x0000719572a01f1f in llvm::FPPassManager::runOnFunction(llvm::Function&) ()
   from /home/ben/.rustup/toolchains/master-stage1/lib/libLLVM.so.18.1-rust-1.78.0-nightly
#15 0x0000719572a00df2 in llvm::FPPassManager::runOnModule(llvm::Module&) ()
   from /home/ben/.rustup/toolchains/master-stage1/lib/libLLVM.so.18.1-rust-1.78.0-nightly
#16 0x0000719572ceb92a in llvm::legacy::PassManagerImpl::run(llvm::Module&) ()
   from /home/ben/.rustup/toolchains/master-stage1/lib/libLLVM.so.18.1-rust-1.78.0-nightly
#17 0x0000719575de1957 in LLVMRustWriteOutputFile ()
   from /home/ben/.rustup/toolchains/master-stage1/lib/librustc_driver-b46e18e56798bf7b.so

@saethlin saethlin added I-crash Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics. and removed I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Mar 9, 2024
@dianqk
Copy link
Member

dianqk commented Mar 10, 2024

Upstream issue: llvm/llvm-project#84660

@dianqk
Copy link
Member

dianqk commented Mar 10, 2024

@rustbot label llvm-fixed-upstream

@rustbot rustbot added the llvm-fixed-upstream Issue expected to be fixed by the next major LLVM upgrade, or backported fixes label Mar 10, 2024
@bors bors closed this as completed in 7aa1de7 Mar 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. C-bug Category: This is a bug. I-crash Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics. llvm-fixed-upstream Issue expected to be fixed by the next major LLVM upgrade, or backported fixes 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.

5 participants