matsc-at-sics-se / unison

Unison's source code
http://unison-code.github.io/
Other
5 stars 0 forks source link

llc crash, show-stopping FFT study #27

Closed matsc-at-sics-se closed 6 years ago

matsc-at-sics-se commented 6 years ago

fftbug.c.txt I tried to narrow it down as much as possible. Reproducer:

$ clang-3.8 -O1 -emit-llvm -S fftbug.c && llc fftbug.ll -unison 
llc: /home/matsc/llvm/lib/CodeGen/MIRPrinter.cpp:686: void llvm::MIPrinter::printStackObjectReference(int): Assertion `ObjectInfo != StackObjectOperandMapping.end() && "Invalid frame index"' failed.
#0 0x000000000265b0e0 llvm::sys::PrintStackTrace(llvm::raw_ostream&) /home/matsc/llvm/lib/Support/Unix/Signals.inc:322:0
#1 0x000000000265b438 PrintStackTraceSignalHandler(void*) /home/matsc/llvm/lib/Support/Unix/Signals.inc:380:0
#2 0x000000000265996f llvm::sys::RunSignalHandlers() /home/matsc/llvm/lib/Support/Signals.cpp:44:0
#3 0x000000000265aafc SignalHandler(int) /home/matsc/llvm/lib/Support/Unix/Signals.inc:210:0
#4 0x00007f1aeeb80390 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x11390)
#5 0x00007f1aedd1f428 gsignal /build/glibc-Cl5G7W/glibc-2.23/signal/../sysdeps/unix/sysv/linux/raise.c:54:0
#6 0x00007f1aedd2102a abort /build/glibc-Cl5G7W/glibc-2.23/stdlib/abort.c:91:0
#7 0x00007f1aedd17bd7 __assert_fail_base /build/glibc-Cl5G7W/glibc-2.23/assert/assert.c:92:0
#8 0x00007f1aedd17c82 (/lib/x86_64-linux-gnu/libc.so.6+0x2dc82)
#9 0x0000000001f8873d llvm::MIPrinter::printStackObjectReference(int) /home/matsc/llvm/lib/CodeGen/MIRPrinter.cpp:685:0
#10 0x0000000001f89ab6 llvm::MIPrinter::print(llvm::MachineMemOperand const&) /home/matsc/llvm/lib/CodeGen/MIRPrinter.cpp:933:0
#11 0x0000000001f8832c llvm::MIPrinter::print(llvm::MachineInstr const&) /home/matsc/llvm/lib/CodeGen/MIRPrinter.cpp:624:0
#12 0x0000000001f87ce8 llvm::MIPrinter::print(llvm::MachineBasicBlock const&) /home/matsc/llvm/lib/CodeGen/MIRPrinter.cpp:548:0
#13 0x0000000001f8547c llvm::MIRPrinter::print(llvm::MachineFunction const&) /home/matsc/llvm/lib/CodeGen/MIRPrinter.cpp:194:0
#14 0x0000000001f8a14d llvm::printMIR(llvm::raw_ostream&, llvm::MachineFunction const&, llvm::MIRAuxiliaryInfo&) /home/matsc/llvm/lib/CodeGen/MIRPrinter.cpp:1030:0
#15 0x0000000001e26651 (anonymous namespace)::MIRPrintingPass::runOnMachineFunction(llvm::MachineFunction&) /home/matsc/llvm/lib/CodeGen/MIRPrintingPass.cpp:65:0
#16 0x0000000001da6b5d llvm::MachineFunctionPass::runOnFunction(llvm::Function&) /home/matsc/llvm/lib/CodeGen/MachineFunctionPass.cpp:44:0
#17 0x00000000021a76ac llvm::FPPassManager::runOnFunction(llvm::Function&) /home/matsc/llvm/lib/IR/LegacyPassManager.cpp:1550:0
#18 0x00000000021a7845 llvm::FPPassManager::runOnModule(llvm::Module&) /home/matsc/llvm/lib/IR/LegacyPassManager.cpp:1571:0
#19 0x00000000021a7bc0 (anonymous namespace)::MPPassManager::runOnModule(llvm::Module&) /home/matsc/llvm/lib/IR/LegacyPassManager.cpp:1627:0
#20 0x00000000021a82d5 llvm::legacy::PassManagerImpl::run(llvm::Module&) /home/matsc/llvm/lib/IR/LegacyPassManager.cpp:1730:0
#21 0x00000000021a84e1 llvm::legacy::PassManager::run(llvm::Module&) /home/matsc/llvm/lib/IR/LegacyPassManager.cpp:1762:0
#22 0x0000000000d6b001 compileModule(char**, llvm::LLVMContext&) /home/matsc/llvm/tools/llc/llc.cpp:417:0
#23 0x0000000000d69c4e main /home/matsc/llvm/tools/llc/llc.cpp:212:0
#24 0x00007f1aedd0a830 __libc_start_main /build/glibc-Cl5G7W/glibc-2.23/csu/../csu/libc-start.c:325:0
#25 0x0000000000d681d9 _start (/usr/local/bin/llc+0xd681d9)
Stack dump:
0.  Program arguments: llc fftbug.ll -unison 
1.  Running pass 'Function Pass Manager' on module 'fftbug.ll'.
2.  Running pass 'MIR Printing Pass' on function '@dft'
Aborted (core dumped)
matsc-at-sics-se commented 6 years ago

Assertion triggers in this code:

void MIPrinter::printStackObjectReference(int FrameIndex) {
  auto ObjectInfo = StackObjectOperandMapping.find(FrameIndex);
  assert(ObjectInfo != StackObjectOperandMapping.end() &&
         "Invalid frame index");
  const FrameIndexOperand &Operand = ObjectInfo->second;
  if (Operand.IsFixed) {
    OS << "%fixed-stack." << Operand.ID;
    return;
  }
  OS << "%stack." << Operand.ID;
  if (!Operand.Name.empty())
    OS << '.' << Operand.Name;
}

So no ObjectInfo is found for the given FrameIndex. Happens while printing a MOVAPSrm instruction, which loads from some stack frame object.

Question: is it possible to invoke the MIR printing pass by some means other than the -unison flag?

I don't know how to make progress. Roberto, please help.

robcasloz commented 6 years ago

Hi, you can try the option --print-machineinstrs on llc, it dumps the MIR after each pass (in a slightly different format).

matsc-at-sics-se commented 6 years ago

Attached are two transcript: LOG1.txt LOG2.txt

One after llc fftbug.ll -O2 -print-machineinstrs, one after llc fftbug.ll -O2 -print-machineinstrs -unison.

The second one shows the crash, whereas in the same place the first one successfully dumps the machine code after Live Variable Analysis. There are other interesting differences.

Where do we go from here?

robcasloz commented 6 years ago

The updated llc from commit unison-code/llvm@7fd605e does not crash anymore.