rust icon indicating copy to clipboard operation
rust copied to clipboard

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

Open linkmauve opened this issue 5 months ago • 3 comments

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 avatar Mar 09 '24 19:03 linkmauve

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 avatar Mar 09 '24 23:03 saethlin

Upstream issue: https://github.com/llvm/llvm-project/issues/84660

DianQK avatar Mar 10 '24 00:03 DianQK

@rustbot label llvm-fixed-upstream

DianQK avatar Mar 10 '24 22:03 DianQK