<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/64435>64435</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[x86_64/GlobalISel] Returning `half` type causes error "Cannot emit physreg copy instruction"
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
HazyFish
</td>
</tr>
</table>
<pre>
## Description
Returning `half` type will crash the `x86_64` Global ISel backend with `LLVM ERROR: Cannot emit physreg copy instruction`.
The problem does not exist with `i686` or `aarch64`.
The problem also does not exist when not using Global ISel.
## Minimal Reproduction
https://godbolt.org/z/G1rszzf1n
### Code
```ll
define half @f(ptr %0) {
%h = load half, ptr %0
ret half %h
}
```
### Stack Trace
```console
LLVM ERROR: Cannot emit physreg copy instruction
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0. Program arguments: /opt/compiler-explorer/clang-assertions-trunk/bin/llc -o /app/output.s -x86-asm-syntax=intel -mtriple=x86_64 --global-isel <source>
1. Running pass 'Function Pass Manager' on module '<source>'.
2. Running pass 'Post-RA pseudo instruction expansion pass' on function '@f'
#0 0x0000000003398418 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x3398418)
#1 0x0000000003395d0c SignalHandler(int) Signals.cpp:0:0
#2 0x00007f6d11af4420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
#3 0x00007f6d115b700b raise (/lib/x86_64-linux-gnu/libc.so.6+0x4300b)
#4 0x00007f6d11596859 abort (/lib/x86_64-linux-gnu/libc.so.6+0x22859)
#5 0x0000000000695331 (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x695331)
#6 0x00000000032ee9e8 (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x32ee9e8)
#7 0x0000000001d4ef15 llvm::X86InstrInfo::copyPhysReg(llvm::MachineBasicBlock&, llvm::MachineInstrBundleIterator<llvm::MachineInstr, false>, llvm::DebugLoc const&, llvm::MCRegister, llvm::MCRegister, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x1d4ef15)
#8 0x0000000002937b38 llvm::TargetInstrInfo::lowerCopy(llvm::MachineInstr*, llvm::TargetRegisterInfo const*) const (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x2937b38)
#9 0x000000000253ff67 (anonymous namespace)::ExpandPostRA::runOnMachineFunction(llvm::MachineFunction&) ExpandPostRAPseudos.cpp:0:0
#10 0x0000000002680049 llvm::MachineFunctionPass::runOnFunction(llvm::Function&) (.part.0) MachineFunctionPass.cpp:0:0
#11 0x0000000002bf8bb9 llvm::FPPassManager::runOnFunction(llvm::Function&) (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x2bf8bb9)
#12 0x0000000002bf8df1 llvm::FPPassManager::runOnModule(llvm::Module&) (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x2bf8df1)
#13 0x0000000002bf9612 llvm::legacy::PassManagerImpl::run(llvm::Module&) (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x2bf9612)
#14 0x000000000075e092 compileModule(char**, llvm::LLVMContext&) llc.cpp:0:0
#15 0x000000000069a7e6 main (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x69a7e6)
#16 0x00007f6d11598083 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x24083)
#17 0x0000000000754a4e _start (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x754a4e)
Program terminated with signal: SIGSEGV
Compiler returned: 139
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy8WF9v6joS_zTmxQI5zv8HHiiUcyud6lb06GrfkJNMEu9x7Mh2tnA-_cpJaBPKrrpn0a3aAvbkN7_54xkPzBheSYA1Ch9QuFuwztZKr_9gv857bupFporzGlEfUR_vwOSat5YricgOk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