Hints needed for debugging an X86 backend bug.

I have a IR file which has been reduced by bugpoint, the IR is originally compiled for X86_64 and has custom transforms applied.
It compiles fine if I set the triple to aarch64-arm-none-eabi, but crashes when using the X86 backend , results in the following stack trace:

Assertion failed: (itr != mi2iMap.end() && "Instruction not found in maps."), function getInstructionIndex, file LLVM/llvm/include/llvm/CodeGen/SlotIndexes.h, line 399.
PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash backtrace.
Stack dump:
0. Program arguments: bin/llc LLCCrash.bc -debug
1. Running pass 'Function Pass Manager' on module 'LLCCrash.bc'.
2. Running pass 'Simple Register Coalescing' on function '@_ZNK8CryptoPP15DL_VerifierBaseINS_8ECPPointEE17RecoverAndRestartEPhRNS_21PK_MessageAccumulatorE'
0 llc 0x0000000103289eca llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 58
1 llc 0x000000010328a459 PrintStackTraceSignalHandler(void*) + 25
2 llc 0x000000010328832b llvm::sys::RunSignalHandlers() + 123
3 llc 0x000000010328c209 SignalHandler(int) + 249
4 libsystem_platform.dylib 0x00007fff2052bd7d _sigtramp + 29
5 libdyld.dylib 0x00007fff20501473 dyldGlobalLockRelease() + 0
6 libsystem_c.dylib 0x00007fff2043a720 abort + 120
7 libsystem_c.dylib 0x00007fff204399d6 err + 0
8 llc 0x0000000101e67066 llvm::SlotIndexes::getInstructionIndex(llvm::MachineInstr const&, bool) const + 470
9 llc 0x0000000101e66e06 llvm::LiveIntervals::getInstructionIndex(llvm::MachineInstr const&) const + 38
10 llc 0x0000000101ec5da5 (anonymous namespace)::RegisterCoalescer::joinCopy(llvm::MachineInstr*, bool&) + 149
11 llc 0x0000000101ec2e5c (anonymous namespace)::RegisterCoalescer::copyCoalesceWorkList(llvm::MutableArrayRef<llvm::MachineInstr*>) + 204
12 llc 0x0000000101ebdc34 (anonymous namespace)::RegisterCoalescer::joinAllIntervals() + 740
13 llc 0x0000000101ebad54 (anonymous namespace)::RegisterCoalescer::runOnMachineFunction(llvm::MachineFunction&) + 804

The IR passesopt -verify, and given AArch64 backend works fine, I assume it’s a bug in the X86 backend, thus I modified SlotIndexes::getInstructionIndex to print the MachineInstr:


which gives me:



I’m now absolutely lost on where this “UNKNOWN” comes from.


MachineInstr prints “UNKNOWN” only when “TII” in invalid. https://llvm.org/doxygen/MachineInstr_8cpp_source.html#l01669

It’s a bit strange that you generate IR using aarch64 while using X86 as backend. I think some target specific builtins won’t work, as well as many function attributes are not available.