Assertion error in llvm/lib/Target/X86/X86AvoidStoreForwardingBlocks.cpp:293
| Bugzilla Link | 41838 |
| Resolution | FIXED |
| Resolved on | May 31, 2019 14:02 |
| Version | trunk |
| OS | Linux |
| Attachments | reproducer for the assertion |
| CC | @topperc,@gregbedwell,@RKSimon,@rlougher,@rotateright |
| Fixed by commit(s) | r360606,r361527 |
Extended Description
We run into an assertion error in LLVM when building zircon:
clang: /usr/local/google/home/leonardchan/llvm-monorepo/llvm-project-2/llvm/lib/Target/X86/X86AvoidStoreForwardingBlocks.cpp:293: int getAddrOffset(llvm::MachineInstr *): Assertion `AddrOffset != -1 && "Expected Memory Operand"' failed. Stack dump: 0. Program arguments: ../llvm-build-2-address-space-fix/bin/clang -cc1 -triple x86_64-fuchsia -emit-obj --mrelax-relocations -disable-free -main-file-name state_tests.cpp -mrelocation-model pic -pic-level 2 -pic-is-pie -mthread-model posix -mdisable-fp-elim -masm-verbose -mconstructor-aliases -munwind-tables -fuse-init-array -target-cpu x86-64 -dwarf-column-info -debug-info-kind=limited -dwarf-version=4 -debugger-tuning=gdb -ffunction-sections -fdata-sections -coverage-notes-file /b/s/w/ir/k/out/x64.zircon/user-x64-clang/obj/system/utest/inspect-vmo/inspect-vmo-test.state_tests.cpp.gcno -sys-header-deps -D TOOLCHAIN_VERSION=/b/s/w/ir/k/recipe_cleanup/clangzdnyvE/bin -D ZX_DEBUGLEVEL=2 -D WITH_FRAME_POINTERS=1 -D _LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS=1 -D _ALL_SOURCE -O2 -Wall -Wextra -Wno-multichar -Wno-unused-parameter -Wno-unused-function -Werror=unused-label -Werror=return-type -Wnewline-eof -Wno-address-of-packed-member -Wimplicit-fallthrough -Wthread-safety -Werror -Wno-error=deprecated-declarations -Wconversion -Wno-sign-conversion -Wextra-semi -std=c++17 -fdeprecated-macro -fdebug-prefix-map=/b/s/w/ir/k/zircon=../../zircon -ferror-limit 19 -fmessage-length 0 -fsanitize=safe-stack -stack-protector 2 -fno-rtti -fno-threadsafe-statics -fobjc-runtime=gcc -fno-common -fdiagnostics-show-option -fcolor-diagnostics -vectorize-loops -vectorize-slp -x c++ state_tests-84151a.cpp -faddrsig
parser at end of file - Code generation
- Running pass 'Function Pass Manager' on module 'state_tests-84151a.cpp'.
- Running pass 'X86 Avoid Store Forwarding Blocks' on function '@_ZN12_GLOBAL__N_122SetPropertyOutOfMemoryEv' #0 0x0000000006eb1699 llvm::sys::PrintStackTrace(llvm::raw_ostream&) /usr/local/google/home/leonardchan/llvm-monorepo/llvm-project-2/llvm/lib/Support/Unix/Signals.inc:494:11 #1 0x0000000006eb1789 PrintStackTraceSignalHandler(void*) /usr/local/google/home/leonardchan/llvm-monorepo/llvm-project-2/llvm/lib/Support/Unix/Signals.inc:558:1 #2 0x0000000006eb025b llvm::sys::RunSignalHandlers() /usr/local/google/home/leonardchan/llvm-monorepo/llvm-project-2/llvm/lib/Support/Signals.cpp:67:5 #3 0x0000000006eb1d88 SignalHandler(int) /usr/local/google/home/leonardchan/llvm-monorepo/llvm-project-2/llvm/lib/Support/Unix/Signals.inc:357:1 #4 0x00007ffa2548b0c0 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x110c0) #5 0x00007ffa247b6fcf raise (/lib/x86_64-linux-gnu/libc.so.6+0x32fcf) #6 0x00007ffa247b83fa abort (/lib/x86_64-linux-gnu/libc.so.6+0x343fa) #7 0x00007ffa247afe37 (/lib/x86_64-linux-gnu/libc.so.6+0x2be37) #8 0x00007ffa247afee2 (/lib/x86_64-linux-gnu/libc.so.6+0x2bee2) #9 0x0000000005a570d7 getAddrOffset(llvm::MachineInstr*) /usr/local/google/home/leonardchan/llvm-monorepo/llvm-project-2/llvm/lib/Target/X86/X86AvoidStoreForwardingBlocks.cpp:294:39 #10 0x0000000005a57105 getBaseOperand(llvm::MachineInstr*) /usr/local/google/home/leonardchan/llvm-monorepo/llvm-project-2/llvm/lib/Target/X86/X86AvoidStoreForwardingBlocks.cpp:299:7 #11 0x0000000005a56715 updateKillStatus(llvm::MachineInstr*, llvm::MachineInstr*) /usr/local/google/home/leonardchan/llvm-monorepo/llvm-project-2/llvm/lib/Target/X86/X86AvoidStoreForwardingBlocks.cpp:510:53 #12 0x0000000005a55401 (anonymous namespace)::X86AvoidSFBPass::runOnMachineFunction(llvm::MachineFunction&) /usr/local/google/home/leonardchan/llvm-monorepo/llvm-project-2/llvm/lib/Target/X86/X86AvoidStoreForwardingBlocks.cpp:718:5 #13 0x000000000609502f llvm::MachineFunctionPass::runOnFunction(llvm::Function&) /usr/local/google/home/leonardchan/llvm-monorepo/llvm-project-2/llvm/lib/CodeGen/MachineFunctionPass.cpp:73:8 #14 0x000000000654c86c llvm::FPPassManager::runOnFunction(llvm::Function&) /usr/local/google/home/leonardchan/llvm-monorepo/llvm-project-2/llvm/lib/IR/LegacyPassManager.cpp:1648:23 #15 0x000000000654cccf llvm::FPPassManager::runOnModule(llvm::Module&) /usr/local/google/home/leonardchan/llvm-monorepo/llvm-project-2/llvm/lib/IR/LegacyPassManager.cpp:1685:16 #16 0x000000000654d451 (anonymous namespace)::MPPassManager::runOnModule(llvm::Module&) /usr/local/google/home/leonardchan/llvm-monorepo/llvm-project-2/llvm/lib/IR/LegacyPassManager.cpp:1752:23 #17 0x000000000654cf88 llvm::legacy::PassManagerImpl::run(llvm::Module&) /usr/local/google/home/leonardchan/llvm-monorepo/llvm-project-2/llvm/lib/IR/LegacyPassManager.cpp:1865:16 #18 0x000000000654d9e1 llvm::legacy::PassManager::run(llvm::Module&) /usr/local/google/home/leonardchan/llvm-monorepo/llvm-project-2/llvm/lib/IR/LegacyPassManager.cpp:1896:3 #19 0x00000000071e2d7d (anonymous namespace)::EmitAssemblyHelper::EmitAssembly(clang::BackendAction, std::__2::unique_ptr<llvm::raw_pwrite_stream, std::__2::default_deletellvm::raw_pwrite_stream >) /usr/local/google/home/leonardchan/llvm-monorepo/llvm-project-2/clang/lib/CodeGen/BackendUtil.cpp:894:3 #20 0x00000000071df5c0 clang::EmitBackendOutput(clang::DiagnosticsEngine&, clang::HeaderSearchOptions const&, clang::CodeGenOptions const&, clang::TargetOptions const&, clang::LangOptions const&, llvm::DataLayout const&, llvm::Module*, clang::BackendAction, std::__2::unique_ptr<llvm::raw_pwrite_stream, std::__2::default_deletellvm::raw_pwrite_stream >) /usr/local/google/home/leonardchan/llvm-monorepo/llvm-project-2/clang/lib/CodeGen/BackendUtil.cpp:1466:5 #21 0x0000000007c3573b clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) /usr/local/google/home/leonardchan/llvm-monorepo/llvm-project-2/clang/lib/CodeGen/CodeGenAction.cpp:300:7 #22 0x0000000009a56782 clang::ParseAST(clang::Sema&, bool, bool) /usr/local/google/home/leonardchan/llvm-monorepo/llvm-project-2/clang/lib/Parse/ParseAST.cpp:178:12 #23 0x0000000007aa9b22 clang::ASTFrontendAction::ExecuteAction() /usr/local/google/home/leonardchan/llvm-monorepo/llvm-project-2/clang/lib/Frontend/FrontendAction.cpp:1037:1 #24 0x0000000007c32d9c clang::CodeGenAction::ExecuteAction() /usr/local/google/home/leonardchan/llvm-monorepo/llvm-project-2/clang/lib/CodeGen/CodeGenAction.cpp:1057:1 #25 0x0000000007aa9563 clang::FrontendAction::Execute() /usr/local/google/home/leonardchan/llvm-monorepo/llvm-project-2/clang/lib/Frontend/FrontendAction.cpp:938:7 #26 0x00000000079e0964 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) /usr/local/google/home/leonardchan/llvm-monorepo/llvm-project-2/clang/lib/Frontend/CompilerInstance.cpp:945:7 #27 0x0000000007c237a9 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) /usr/local/google/home/leonardchan/llvm-monorepo/llvm-project-2/clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp:273:8 #28 0x0000000004469313 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) /usr/local/google/home/leonardchan/llvm-monorepo/llvm-project-2/clang/tools/driver/cc1_main.cpp:225:13 #29 0x000000000445c46f ExecuteCC1Tool(llvm::ArrayRef<char const*>, llvm::StringRef) /usr/local/google/home/leonardchan/llvm-monorepo/llvm-project-2/clang/tools/driver/driver.cpp:309:5 #30 0x000000000445b80c main /usr/local/google/home/leonardchan/llvm-monorepo/llvm-project-2/clang/tools/driver/driver.cpp:381:5 #31 0x00007ffa247a42b1 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x202b1) #32 0x000000000445b02a _start (../llvm-build-2-address-space-fix/bin/clang+0x445b02a)
Can confirm that with rL361527, we no longer hit this assertion. Thanks for the fix!
Reverted in r360606.
Chris/Robert - you've re-submitted D61680 at rL361527- can this be resolved now or should it wait for D62408?
Reverted in r360606.
No problem. Thanks for addressing this.
We have a fix, however, it will need reviewing so we have decided to revert the original commit and reopen. Sorry for the delay...
Thanks for the updates! Let me know if a fix gets landed today so we won't need to revert.
Like Greg I also have no access to my computers until I unpack them on Monday. However, a cursory look at the code shows a place that also needs to be updated to handle debug intrinsics between the load and store:
493 static void updateKillStatus(MachineInstr *LoadInst, MachineInstr *StoreInst) { 494 MachineOperand &LoadBase = getBaseOperand(LoadInst); 495 MachineOperand &StoreBase = getBaseOperand(StoreInst); 496 if (LoadBase.isReg()) { 497 MachineInstr *LastLoad = LoadInst->getPrevNode(); 498 // If the original load and store to xmm/ymm were consecutive 499 // then the partial copies were also created in 500 // a consecutive order to reduce register pressure, 501 // and the location of the last load is before the last store. 502 if (StoreInst->getPrevNode() == LoadInst) 503 LastLoad = LoadInst->getPrevNode()->getPrevNode(); 504 getBaseOperand(LastLoad).setIsKill(LoadBase.isKill()); 505 } 506 if (StoreBase.isReg()) { 507 MachineInstr *StInst = StoreInst; 508 if (StoreInst->getPrevNode() == LoadInst) 509 StInst = LoadInst; 510 getBaseOperand(StInst->getPrevNode()).setIsKill(StoreBase.isKill()); 511 } 512 }
When creating the partial copies, a debug intrinsic between the load/store is no longer a block. This code, however, is expecting the last load to be the previous instruction of the last store, which will not be the case.
Something for Chris to look at first thing on Monday. If this fixes the patch it does not need to be reverted.
One of the buildbots is reporting this as well:
http://lab.llvm.org:8011/builders/clang-x64-windows-msvc/builds/6762/steps/annotate/logs/stdio
bugpoint reduced ir bugpoint reduced ir
FWIW, although I don't currently have access to the upstream repo I managed to grab a build from our downstream fork which reproduced it with:
$ clang -c preproc1.cpp -w -std=c++17 -O2 -g --target=x86_64-fuchsia
I did a quick manual testcase reduction. I expect someone on a machine with access to c-reduce/bugpoint can probably do better :).
// ============================================= int printf(...); void abort(); void *operator new(unsigned long, void *) {} struct Vector { void grow_for_new_element() { if (size_) { printf(0, 0, 0, 0); abort(); } if (size_) { if (size_ < 16) { printf(0, 0, 0, 0); abort(); } printf(0, 0); abort(); } } char *ptr_; unsigned long size_; }; struct StringPiece { StringPiece(char *data, unsigned long length) : data_(data), length_(length) {} char *data_; long length_; }; struct Property { ~Property(); }; struct State { Property CreateProperty(long a, long b, long c, StringPiece value); }; void SetPropertyOutOfMemory(State *state, Vector vec) { vec.grow_for_new_element(); new (&vec) char(); state->CreateProperty(0, 0, 0, {vec.ptr_, vec.size_}); } // =============================================
Thanks for the report!
Our office is having refurbishment over the weekend so all our computers are turned off locked away in boxes (I have access to this bugzilla, but not easily to an opensource build to verify/reduce the testcase). I suspect that the earliest we'll be able to revert or commit a fix will be Monday afternoon UK time once we've unpacked our equipment again. Please feel free to revert in the meantime.
It seems like it was introduced in https://reviews.llvm.org/D61680