Repository: rust
Issue: Rustc crash while generating aarch64 code with inline asm. Maybe an LLVM problem.
Labels: I-crash,A-LLVM,O-macos,C-bug,O-AArch64

After a long minimization session, I obtain the following test-case on a MacOS M1 machine.

```
% cat lib.rs
trait Reduce where {
    fn run(vec: &[u16]) -> u16;
}

struct Ker;

impl Reduce for Ker {
    fn run(buf: &[u16]) -> u16 {
        #[target_feature(enable = "fp16")]
        unsafe fn run(_: &[u16]) -> u16 {
            let mut out: u16 = u16::MIN;
            std::arch::asm!("dup v0.8h, v0.h[0]", inout("v0") out);
            out
        }

        unsafe {
            run(buf)
        }
    }
}
% rustc --crate-type lib lib.rs
[1]    19352 trace trap  rustc --crate-type lib lib.rs
```

I expected to see a silent compilation success, or failure with an error message.

Instead, the compiler crashes.

It is actually possible to reproduce this issue while cross compiling from e.g. a linux intel machine:

```
% rustc --target aarch64-unknown-linux-musl --crate-type lib lib.rs 
[1]    51954 illegal hardware instruction  rustc --target aarch64-unknown-linux-musl --crate-type lib lib.rs
```

And I was able to capture a backtrace with gdb:

```
Thread 5 "opt cgu.0" received signal SIGILL, Illegal instruction.
[Switching to Thread 0x7fffe1fff6c0 (LWP 52932)]
0x00007fffef53f4ff in llvm::AArch64InstrInfo::copyPhysReg(llvm::MachineBasicBlock&, llvm::MachineInstrBundleIterator<llvm::MachineInstr, false>, llvm::DebugLoc const&, llvm::MCRegister, llvm::MCRegister, bool) const ()
   from /home/kali/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/libLLVM-17-rust-1.75.0-stable.so
(gdb) bt
#0  0x00007fffef53f4ff in llvm::AArch64InstrInfo::copyPhysReg(llvm::MachineBasicBlock&, llvm::MachineInstrBundleIterator<llvm::MachineInstr, false>, llvm::DebugLoc const&, llvm::MCRegister, llvm::MCRegister, bool) const ()
   from /home/kali/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/libLLVM-17-rust-1.75.0-stable.so
#1  0x00007ffff1417d6f in llvm::TargetInstrInfo::lowerCopy(llvm::MachineInstr*, llvm::TargetRegisterInfo const*) const [clone .cold.0] ()
   from /home/kali/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/libLLVM-17-rust-1.75.0-stable.so
#2  0x00007ffff08a306b in (anonymous namespace)::ExpandPostRA::runOnMachineFunction(llvm::MachineFunction&) ()
   from /home/kali/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/libLLVM-17-rust-1.75.0-stable.so
#3  0x00007ffff075d400 in llvm::FPPassManager::runOnFunction(llvm::Function&) ()
   from /home/kali/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/libLLVM-17-rust-1.75.0-stable.so
#4  0x00007ffff075c987 in llvm::FPPassManager::runOnModule(llvm::Module&) ()
   from /home/kali/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/libLLVM-17-rust-1.75.0-stable.so
#5  0x00007ffff09184ba in llvm::legacy::PassManagerImpl::run(llvm::Module&) ()
   from /home/kali/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/libLLVM-17-rust-1.75.0-stable.so
#6  0x00007ffff6ec7250 in LLVMRustWriteOutputFile ()
   from /home/kali/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/librustc_driver-5aef5f09b8575cae.so
#7  0x00007ffff6ec6e8c in rustc_codegen_llvm[aca462edc423cf78]::back::write::write_output_file ()
   from /home/kali/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/librustc_driver-5aef5f09b8575cae.so
#8  0x00007ffff6ec47a3 in rustc_codegen_llvm[aca462edc423cf78]::back::write::codegen ()
   from /home/kali/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/librustc_driver-5aef5f09b8575cae.so
#9  0x00007ffff6ec443f in rustc_codegen_ssa[d1233806591d2b47]::back::write::finish_intra_module_work::<rustc_codegen_llvm[aca462edc423cf78]::LlvmCodegenBackend> () from /home/kali/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/librustc_driver-5aef5f09b8575cae.so
#10 0x00007ffff6ec7a5c in std[409886f6357001f0]::sys_common::backtrace::__rust_begin_short_backtrace::<<rustc_codegen_llvm[aca462edc423cf78]::LlvmCodegenBackend as rustc_codegen_ssa[d1233806591d2b47]::traits::backend::ExtraBackendMethods>::spawn_named_thread<rustc_codegen_ssa[d1233806591d2b47]::back::write::spawn_work<rustc_codegen_llvm[aca462edc423cf78]::LlvmCodegenBackend>::{closure#0}, ()>::{closure#0}, ()> ()
   from /home/kali/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/librustc_driver-5aef5f09b8575cae.so
#11 0x00007ffff6ec7540 in <<std[409886f6357001f0]::thread::Builder>::spawn_unchecked_<<rustc_codegen_llvm[aca462edc423cf78]::LlvmCodegenBackend as rustc_codegen_ssa[d1233806591d2b47]::traits::backend::ExtraBackendMethods>::spawn_named_thread<rustc_codegen_ssa[d1233806591d2b47]::back::write::spawn_work<rustc_codegen_llvm[aca462edc423cf78]::LlvmCodegenBackend>::{closure#0}, ()>::{closure#0}, ()>::{closure#1} as core[21cdcf8e8af4c2d9]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0} ()
   from /home/kali/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/librustc_driver-5aef5f09b8575cae.so
#12 0x00007ffff23986a5 in alloc::boxed::{impl#47}::call_once<(), dyn core::ops::function::FnOnce<(), Output=()>, alloc::alloc::Global> ()
    at library/alloc/src/boxed.rs:2007
```

### Meta

`rustc --version --verbose`:
```
WAX 26/01 14:34 ~% rustc --version --verbose
rustc 1.75.0 (82e1608df 2023-12-21)
binary: rustc
commit-hash: 82e1608dfa6e0b5569232559e3d385fea5a93112
commit-date: 2023-12-21
host: aarch64-apple-darwin
release: 1.75.0
LLVM version: 17.0.6
```