Error "Cannot emit physreg copy instruction"

I'm getting an error that I don't know how to fix. I've isolated the
input as much as I easily can. I've attached the file that produces the
problem. Just calling "llc err.ll -o err.s" generates the error.

I'm going to try and isolate even further, but as I'm not sure what I'm
looking for I don't know if I'll be successful. Does anybody know what
this error means?

Cannot emit physreg copy instruction
UNREACHABLE executed at X86InstrInfo.cpp:2899!
0 libLLVM-3.3.so 0x00007f9f68ddf642
llvm::sys::PrintStackTrace(_IO_FILE*) + 34
1 libLLVM-3.3.so 0x00007f9f68dde9a9
2 libpthread.so.0 0x00007f9f67a07cb0
3 libc.so.6 0x00007f9f67156425 gsignal + 53
4 libc.so.6 0x00007f9f67159b8b abort + 379
5 libLLVM-3.3.so 0x00007f9f68dc1e7c
6 libLLVM-3.3.so 0x00007f9f68fd1832
llvm::X86InstrInfo::copyPhysReg(llvm::MachineBasicBlock&,
llvm::MachineBasicBlock::bundle_iterator<llvm::MachineInstr,
llvm::ilist_iterator<llvm::MachineInstr> >, llvm::DebugLoc, unsigned
int, unsigned int, bool) const + 1762
7 libLLVM-3.3.so 0x00007f9f683afab1
8 libLLVM-3.3.so 0x00007f9f6864c417
llvm::FPPassManager::runOnFunction(llvm::Function&) + 487
9 libLLVM-3.3.so 0x00007f9f6864c50b
llvm::FPPassManager::runOnModule(llvm::Module&) + 43
10 libLLVM-3.3.so 0x00007f9f6864beff
llvm::MPPassManager::runOnModule(llvm::Module&) + 559
11 libLLVM-3.3.so 0x00007f9f6864c165
llvm::PassManagerImpl::run(llvm::Module&) + 245
12 llc 0x000000000040d217
13 llc 0x0000000000409a58 main + 360
14 libc.so.6 0x00007f9f6714176d __libc_start_main + 237
15 llc 0x0000000000409ae1
Stack dump:
0. Program arguments: /opt/llvm/install/bin/llc err.ll -o err.s
1. Running pass 'Function Pass Manager' on module 'err.ll'.
2. Running pass 'Post-RA pseudo instruction expansion pass' on function
'@junk___init_module_get_args_3'

err.ll (5.27 KB)

I've reduced the example down to a minimum. The error is quite
perplexing since the IR appears fine. It is a nonsensical infinite loop
now, but that shouldn't be a problem.

declare i64 @leaf_exception_personality(i64, i32, i64, i8*, i8*)

declare i8* @count_malloc(i64)

define internal i8 @junk___init_module_get_args_3() #0 {
entry:
  %_exception = alloca { i8*, i64 }
  %ignore0 = invoke i8* @count_malloc(i64 10)
          to label %loop_cond_7 unwind label %defer_error_land_4

defer_error_land_4:
  %lpres = landingpad { i8*, i64 } personality i64 (i64, i32, i64, i8*,
i8*)* @leaf_exception_personality
          cleanup
  store { i8*, i64 } %lpres, { i8*, i64 }* %_exception
  ret i8 0

loop_cond_7:
  %ignore1 = invoke i8* @count_malloc(i64 40)
          to label %loop_cond_7 unwind label %defer_error_land_4
}

I can make the problem go away, but perhaps there is still an issue in
LLVM. At least a missing assert somewhere. It's strange that only this
very particular structure causes the failure.

If I change the personality routine return value to i32 from i64 then it
works.

Hey edA-qa mort-ora-y,

I'm getting an error that I don't know how to fix. I've isolated the
input as much as I easily can. I've attached the file that produces the
problem. Just calling "llc err.ll -o err.s" generates the error.

I'm going to try and isolate even further, but as I'm not sure what I'm
looking for I don't know if I'll be successful. Does anybody know what
this error means?

Cannot emit physreg copy instruction
UNREACHABLE executed at X86InstrInfo.cpp:2899!
0 libLLVM-3.3.so 0x00007f9f68ddf642
llvm::sys::PrintStackTrace(_IO_FILE*) + 34
1 libLLVM-3.3.so 0x00007f9f68dde9a9
2 libpthread.so.0 0x00007f9f67a07cb0
3 libc.so.6 0x00007f9f67156425 gsignal + 53
4 libc.so.6 0x00007f9f67159b8b abort + 379
5 libLLVM-3.3.so 0x00007f9f68dc1e7c
6 libLLVM-3.3.so 0x00007f9f68fd1832
llvm::X86InstrInfo::copyPhysReg(llvm::MachineBasicBlock&,
llvm::MachineBasicBlock::bundle_iterator<llvm::MachineInstr,
llvm::ilist_iterator<llvm::MachineInstr> >, llvm::DebugLoc, unsigned
int, unsigned int, bool) const + 1762
7 libLLVM-3.3.so 0x00007f9f683afab1
8 libLLVM-3.3.so 0x00007f9f6864c417
llvm::FPPassManager::runOnFunction(llvm::Function&) + 487
9 libLLVM-3.3.so 0x00007f9f6864c50b
llvm::FPPassManager::runOnModule(llvm::Module&) + 43
10 libLLVM-3.3.so 0x00007f9f6864beff
llvm::MPPassManager::runOnModule(llvm::Module&) + 559
11 libLLVM-3.3.so 0x00007f9f6864c165
llvm::PassManagerImpl::run(llvm::Module&) + 245
12 llc 0x000000000040d217
13 llc 0x0000000000409a58 main + 360
14 libc.so.6 0x00007f9f6714176d __libc_start_main + 237
15 llc 0x0000000000409ae1
Stack dump:
0. Program arguments: /opt/llvm/install/bin/llc err.ll -o err.s
1. Running pass 'Function Pass Manager' on module 'err.ll'.
2. Running pass 'Post-RA pseudo instruction expansion pass' on function
'@junk___init_module_get_args_3'

--
edA-qa mort-ora-y

I agree that this is an especially hard issue to diagnose, as I have
had issues with it in the recent past. At that time, I was not able to
find a good way to trace the COPY pseudo to a particular statement in
the IR. But, I digress...

The UNREACHABLE you are hitting comes from
X86InstrInfo::copyPhysReg(...) in
llvm/lib/Target/X86/X86InstrInfo.cpp. You're expanding a pseudo COPY
instruction, but the x86 target does not know how to produce a reg-reg
move that matches the problematic COPY instruction.

To find the COPY instruction that is the problem, try compiling with
-debug. You should see a statement, "Cannot copy...", which will give
you the details of the failing instruction.

I have also tried the test cases that you supplied, but was not able
to reproduce the error with ToT. What cpu target are you looking at?

-Cameron

I am targeting Linux x86_64 with LLVM 3.3.

I found the problem was the "store" instruction for the landingpad
result. I don't understand why it was a problem but I have it
"corrected" now (switch i64 to i32 result).