Skip to content

LLVM Assertion failed when optimizing SIMD code on aarch64.apple.darwin #140933

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

Open
bk-eclipse opened this issue May 12, 2025 · 5 comments
Open
Labels
A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. A-SIMD Area: SIMD (Single Instruction Multiple Data) C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ O-apple Operating system: Apple (macOS, iOS, tvOS, visionOS, watchOS) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@bk-eclipse
Copy link

Code

#![feature(portable_simd)]
use core::simd::Simd;

type BASE=u64;
fn test(
    value: [Simd<BASE, 1>; 2]
) -> Simd<BASE, 1> {
    rotate_right(Simd::splat(1) ^ value[0], 8)
}

fn rotate_right(v: Simd<BASE, 1>, count: BASE) -> Simd<BASE, 1> {
    (v >> count) | (v << (64-count))
}

fn main() {
    let v = [Simd::splat(1); 2];
    assert_eq!(test(v), Simd::splat(1));
}

Meta

rustc --version --verbose:

rustc 1.89.0-nightly (dcecb9917 2025-05-09)

Error output

error: rustc interrupted by SIGILL, printing backtrace
Backtrace

Thread 9 "lto cgu.0" received signal SIGILL, Illegal instruction.
[Switching to Thread 0x7fffdcbff6c0 (LWP 481356)]
0x00007fffed215dbb in llvm::AArch64InstrInfo::copyPhysReg(llvm::MachineBasicBlock&, llvm::MachineInstrBundleIterator<llvm::MachineInstr, false>, llvm::DebugLoc const&, llvm::MCRegister, llvm::MCRegister, bool, bool, bool) const ()
   from ~/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM.so.20.1-rust-1.89.0-nightly
(gdb) bt
#0  0x00007fffed215dbb in llvm::AArch64InstrInfo::copyPhysReg(llvm::MachineBasicBlock&, llvm::MachineInstrBundleIterator<llvm::MachineInstr, false>, llvm::DebugLoc const&, llvm::MCRegister, llvm::MCRegister, bool, bool, bool) const ()
   from ~/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM.so.20.1-rust-1.89.0-nightly
#1  0x00007fffef8b6eac in llvm::TargetInstrInfo::lowerCopy(llvm::MachineInstr*, llvm::TargetRegisterInfo const*) const [clone .cold] ()
   from ~/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM.so.20.1-rust-1.89.0-nightly
#2  0x00007fffeec34b8d in (anonymous namespace)::ExpandPostRA::runOnMachineFunction(llvm::MachineFunction&) ()
   from ~/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM.so.20.1-rust-1.89.0-nightly
#3  0x00007fffee828f91 in llvm::FPPassManager::runOnFunction(llvm::Function&) ()
   from ~/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM.so.20.1-rust-1.89.0-nightly
#4  0x00007fffee8283ef in llvm::FPPassManager::runOnModule(llvm::Module&) ()
   from ~/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM.so.20.1-rust-1.89.0-nightly
#5  0x00007fffeee5d7c3 in llvm::legacy::PassManagerImpl::run(llvm::Module&) ()
   from ~/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM.so.20.1-rust-1.89.0-nightly
#6  0x00007ffff6830302 in LLVMRustWriteOutputFile ()
   from ~/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-9dc9f9e211dbb3c2.so
#7  0x00007ffff682fe61 in rustc_codegen_llvm::back::write::write_output_file ()
   from ~/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-9dc9f9e211dbb3c2.so
#8  0x00007ffff682d426 in rustc_codegen_llvm::back::write::codegen ()
   from ~/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-9dc9f9e211dbb3c2.so
#9  0x00007ffff682d0f4 in rustc_codegen_ssa::back::write::finish_intra_module_work::<rustc_codegen_llvm::LlvmCodegenBackend> ()
   from ~/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-9dc9f9e211dbb3c2.so
#10 0x00007ffff682be2a in std::sys::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 ~/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-9dc9f9e211dbb3c2.so
#11 0x00007ffff68f8c5c 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 ~/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-9dc9f9e211dbb3c2.so
#12 0x00007ffff68f8feb in std::sys::pal::unix::thread::Thread::new::thread_start ()
   from ~/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-9dc9f9e211dbb3c2.so
#13 0x00007ffff069c043 in start_thread (arg=<optimized out>) at ./nptl/pthread_create.c:447
#14 0x00007ffff071a778 in __GI___clone3 () at ../sysdeps/unix/sysv/linux/x86_64/clone3.S:78

@bk-eclipse bk-eclipse added 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. C-bug Category: This is a bug. labels May 12, 2025
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label May 12, 2025
@bk-eclipse
Copy link
Author

bk-eclipse commented May 12, 2025

Bisecting showed that this bug was introduced on nightly at 2024-02-13 - the same day LLVM 18 was merged.

@bk-eclipse
Copy link
Author

A workaround is to disable the target feature sha3:

RUSTFLAGS="-C target-feature=-sha3" cargo b --release --target aarch64-apple-darwin

@moxian

This comment has been minimized.

@rustbot rustbot added A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. A-SIMD Area: SIMD (Single Instruction Multiple Data) O-apple Operating system: Apple (macOS, iOS, tvOS, visionOS, watchOS) and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels May 12, 2025
@appetrosyan
Copy link

I replicated this bug on Mac OS. The same code on the same (and newer) nightlies compiles on Linux. This is a Darwin-specific problem

@bk-eclipse
Copy link
Author

It looks like the compiler tries to optimize this code with a special xar instruction. This seem to fails because the SIMD requires only one lane here.

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. A-SIMD Area: SIMD (Single Instruction Multiple Data) C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ O-apple Operating system: Apple (macOS, iOS, tvOS, visionOS, watchOS) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants