Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DebugInfo][RemoveDIs] Phi nodes and debug records #85254

Closed
rgwott opened this issue Mar 14, 2024 · 2 comments · Fixed by #85288
Closed

[DebugInfo][RemoveDIs] Phi nodes and debug records #85254

rgwott opened this issue Mar 14, 2024 · 2 comments · Fixed by #85288

Comments

@rgwott
Copy link
Contributor

rgwott commented Mar 14, 2024

The works discussed in [1] caused a regression downstream that can be reproduced upstream. We understand this is some weird interaction of the removal of debug intrinsics with phi nodes in some cases.

Until recently the error message was something else but [2] changed the error:

clang: /data_nvme1n1/llvm/llvm-project/llvm/lib/IR/Instruction.cpp:163: void llvm::Instruction::insertBefore(llvm::BasicBlock&, llvm::iplist_impl<llvm::simple_ilist<llvm::Instruction, llvm::ilist_iterator_bits<true> >, llvm::SymbolTableListTraits<llvm::Instruction, llvm::ilist_iterator_bits<true> > >::iterator): Assertion !isa<PHINode>(this) && "Inserting PHI after debug-records!" failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
0.	Program arguments: build/bin/clang -c -O1 --target=arm-arm-none-eabi -march=armv8.1-m.main -g /tmp/repro.c -o /tmp/repro.bin
1.	<eof> parser at end of file
2.	Code generation
3.	Running pass 'Function Pass Manager' on module '/tmp/repro.c'.
4.	Running pass 'Hardware Loop Insertion' on function '@func1'
 #0 0x00005609005d2030 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (build/bin/clang+0x3fb4030)
 #1 0x00005609005cf43f llvm::sys::RunSignalHandlers() (build/bin/clang+0x3fb143f)
 #2 0x0000560900515d78 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
 #3 0x00007f9b95242520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #4 0x00007f9b952969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
 #5 0x00007f9b95242476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
 #6 0x00007f9b952287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
 #7 0x00007f9b9522871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)
 #8 0x00007f9b95239e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
 #9 0x00005608ffee54a2 (build/bin/clang+0x38c74a2)
#10 0x00005608ffee54db llvm::Instruction::insertInto(llvm::BasicBlock*, llvm::ilist_iterator_w_bits<llvm::ilist_detail::node_options<llvm::Instruction, true, false, void, true>, false, false>) (build/bin/clang+0x38c74db)
#11 0x00005608ffed3437 llvm::IRBuilderDefaultInserter::InsertHelper(llvm::Instruction*, llvm::Twine const&, llvm::BasicBlock*, llvm::ilist_iterator_w_bits<llvm::ilist_detail::node_options<llvm::Instruction, true, false, void, true>, false, false>) const (build/bin/clang+0x38b5437)
#12 0x00005608ff82b002 (anonymous namespace)::HardwareLoopsImpl::TryConvertLoop(llvm::Loop*, llvm::LLVMContext&) HardwareLoops.cpp:0:0
#13 0x00005608ff82da91 (anonymous namespace)::HardwareLoopsLegacy::runOnFunction(llvm::Function&) (.part.0) HardwareLoops.cpp:0:0
#14 0x00005608fff3cf7e llvm::FPPassManager::runOnFunction(llvm::Function&) (build/bin/clang+0x391ef7e)
#15 0x00005608fff3d1c9 llvm::FPPassManager::runOnModule(llvm::Module&) (build/bin/clang+0x391f1c9)
#16 0x00005608fff3db35 llvm::legacy::PassManagerImpl::run(llvm::Module&) (build/bin/clang+0x391fb35)
#17 0x000056090083ff76 clang::EmitBackendOutput(clang::DiagnosticsEngine&, clang::HeaderSearchOptions const&, clang::CodeGenOptions const&, clang::TargetOptions const&, clang::LangOptions const&, llvm::StringRef, llvm::Module*, clang::BackendAction, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>, clang::BackendConsumer*) (build/bin/clang+0x4221f76)
#18 0x0000560900e48b67 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (build/bin/clang+0x482ab67)
#19 0x000056090295ed8c clang::ParseAST(clang::Sema&, bool, bool) (build/bin/clang+0x6340d8c)
#20 0x00005609010dc2a9 clang::FrontendAction::Execute() (build/bin/clang+0x4abe2a9)
#21 0x00005609010558e5 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (build/bin/clang+0x4a378e5)
#22 0x00005609011ad5e5 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (build/bin/clang+0x4b8f5e5)
#23 0x00005608fd77cde9 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (build/bin/clang+0x115ede9)
#24 0x00005608fd775053 ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#25 0x0000560900e8d7dd void llvm::function_ref<void ()>::callback_fn<clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const::'lambda'()>(long) Job.cpp:0:0
#26 0x0000560900516240 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (build/bin/clang+0x3ef8240)
#27 0x0000560900e8e05e clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const (.part.0) Job.cpp:0:0
#28 0x0000560900e538ea clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (build/bin/clang+0x48358ea)
#29 0x0000560900e543bd clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const (build/bin/clang+0x48363bd)
#30 0x0000560900e61224 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (build/bin/clang+0x4843224)
#31 0x00005608fd77a155 clang_main(int, char**, llvm::ToolContext const&) (build/bin/clang+0x115c155)
#32 0x00005608fd687b8b main (build/bin/clang+0x1069b8b)
#33 0x00007f9b95229d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#34 0x00007f9b95229e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#35 0x00005608fd773c75 _start (build/bin/clang+0x1155c75)
clang: error: clang frontend command failed with exit code 134 (use -v to see invocation)
clang version 19.0.0git (git@github.com:llvm/llvm-project.git 995d1d114e4e4ff708a03cdb0a975209c6197f9f)
Target: arm-arm-none-eabi
Thread model: posix

Reproducer:

int arr[10];
int z = 42;

void func1(void)
{
  int i;
  int *p1;
  for (p1=arr,i=0; i<10; i++,p1++)
     *p1 = z;
}

clang -c -O1 --target=arm-arm-none-eabi -march=armv8.1-m.main -g repro.c

[1] https://discourse.llvm.org/t/rfc-instruction-api-changes-needed-to-eliminate-debug-intrinsics-from-ir/68939
[2] #84054

@llvmbot
Copy link
Member

llvmbot commented Mar 14, 2024

@llvm/issue-subscribers-debuginfo

Author: Rodolfo Wottrich (rgwott)

The works discussed in [1] caused a regression downstream that can be reproduced upstream. We understand this is some weird interaction of the removal of debug intrinsics with phi nodes in some cases.

Until recently the error message was something else but [2] changed the error:

clang: /data_nvme1n1/llvm/llvm-project/llvm/lib/IR/Instruction.cpp:163: void llvm::Instruction::insertBefore(llvm::BasicBlock&amp;, llvm::iplist_impl&lt;llvm::simple_ilist&lt;llvm::Instruction, llvm::ilist_iterator_bits&lt;true&gt; &gt;, llvm::SymbolTableListTraits&lt;llvm::Instruction, llvm::ilist_iterator_bits&lt;true&gt; &gt; &gt;::iterator): Assertion !isa&lt;PHINode&gt;(this) &amp;&amp; "Inserting PHI after debug-records!" failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
0.	Program arguments: build/bin/clang -c -O1 --target=arm-arm-none-eabi -march=armv8.1-m.main -g /tmp/repro.c -o /tmp/repro.bin
1.	&lt;eof&gt; parser at end of file
2.	Code generation
3.	Running pass 'Function Pass Manager' on module '/tmp/repro.c'.
4.	Running pass 'Hardware Loop Insertion' on function '@<!-- -->func1'
 #<!-- -->0 0x00005609005d2030 llvm::sys::PrintStackTrace(llvm::raw_ostream&amp;, int) (build/bin/clang+0x3fb4030)
 #<!-- -->1 0x00005609005cf43f llvm::sys::RunSignalHandlers() (build/bin/clang+0x3fb143f)
 #<!-- -->2 0x0000560900515d78 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
 #<!-- -->3 0x00007f9b95242520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #<!-- -->4 0x00007f9b952969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
 #<!-- -->5 0x00007f9b95242476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
 #<!-- -->6 0x00007f9b952287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
 #<!-- -->7 0x00007f9b9522871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)
 #<!-- -->8 0x00007f9b95239e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
 #<!-- -->9 0x00005608ffee54a2 (build/bin/clang+0x38c74a2)
#<!-- -->10 0x00005608ffee54db llvm::Instruction::insertInto(llvm::BasicBlock*, llvm::ilist_iterator_w_bits&lt;llvm::ilist_detail::node_options&lt;llvm::Instruction, true, false, void, true&gt;, false, false&gt;) (build/bin/clang+0x38c74db)
#<!-- -->11 0x00005608ffed3437 llvm::IRBuilderDefaultInserter::InsertHelper(llvm::Instruction*, llvm::Twine const&amp;, llvm::BasicBlock*, llvm::ilist_iterator_w_bits&lt;llvm::ilist_detail::node_options&lt;llvm::Instruction, true, false, void, true&gt;, false, false&gt;) const (build/bin/clang+0x38b5437)
#<!-- -->12 0x00005608ff82b002 (anonymous namespace)::HardwareLoopsImpl::TryConvertLoop(llvm::Loop*, llvm::LLVMContext&amp;) HardwareLoops.cpp:0:0
#<!-- -->13 0x00005608ff82da91 (anonymous namespace)::HardwareLoopsLegacy::runOnFunction(llvm::Function&amp;) (.part.0) HardwareLoops.cpp:0:0
#<!-- -->14 0x00005608fff3cf7e llvm::FPPassManager::runOnFunction(llvm::Function&amp;) (build/bin/clang+0x391ef7e)
#<!-- -->15 0x00005608fff3d1c9 llvm::FPPassManager::runOnModule(llvm::Module&amp;) (build/bin/clang+0x391f1c9)
#<!-- -->16 0x00005608fff3db35 llvm::legacy::PassManagerImpl::run(llvm::Module&amp;) (build/bin/clang+0x391fb35)
#<!-- -->17 0x000056090083ff76 clang::EmitBackendOutput(clang::DiagnosticsEngine&amp;, clang::HeaderSearchOptions const&amp;, clang::CodeGenOptions const&amp;, clang::TargetOptions const&amp;, clang::LangOptions const&amp;, llvm::StringRef, llvm::Module*, clang::BackendAction, llvm::IntrusiveRefCntPtr&lt;llvm::vfs::FileSystem&gt;, std::unique_ptr&lt;llvm::raw_pwrite_stream, std::default_delete&lt;llvm::raw_pwrite_stream&gt;&gt;, clang::BackendConsumer*) (build/bin/clang+0x4221f76)
#<!-- -->18 0x0000560900e48b67 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&amp;) (build/bin/clang+0x482ab67)
#<!-- -->19 0x000056090295ed8c clang::ParseAST(clang::Sema&amp;, bool, bool) (build/bin/clang+0x6340d8c)
#<!-- -->20 0x00005609010dc2a9 clang::FrontendAction::Execute() (build/bin/clang+0x4abe2a9)
#<!-- -->21 0x00005609010558e5 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&amp;) (build/bin/clang+0x4a378e5)
#<!-- -->22 0x00005609011ad5e5 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (build/bin/clang+0x4b8f5e5)
#<!-- -->23 0x00005608fd77cde9 cc1_main(llvm::ArrayRef&lt;char const*&gt;, char const*, void*) (build/bin/clang+0x115ede9)
#<!-- -->24 0x00005608fd775053 ExecuteCC1Tool(llvm::SmallVectorImpl&lt;char const*&gt;&amp;, llvm::ToolContext const&amp;) driver.cpp:0:0
#<!-- -->25 0x0000560900e8d7dd void llvm::function_ref&lt;void ()&gt;::callback_fn&lt;clang::driver::CC1Command::Execute(llvm::ArrayRef&lt;std::optional&lt;llvm::StringRef&gt;&gt;, std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt;&gt;*, bool*) const::'lambda'()&gt;(long) Job.cpp:0:0
#<!-- -->26 0x0000560900516240 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref&lt;void ()&gt;) (build/bin/clang+0x3ef8240)
#<!-- -->27 0x0000560900e8e05e clang::driver::CC1Command::Execute(llvm::ArrayRef&lt;std::optional&lt;llvm::StringRef&gt;&gt;, std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt;&gt;*, bool*) const (.part.0) Job.cpp:0:0
#<!-- -->28 0x0000560900e538ea clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&amp;, clang::driver::Command const*&amp;, bool) const (build/bin/clang+0x48358ea)
#<!-- -->29 0x0000560900e543bd clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&amp;, llvm::SmallVectorImpl&lt;std::pair&lt;int, clang::driver::Command const*&gt;&gt;&amp;, bool) const (build/bin/clang+0x48363bd)
#<!-- -->30 0x0000560900e61224 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&amp;, llvm::SmallVectorImpl&lt;std::pair&lt;int, clang::driver::Command const*&gt;&gt;&amp;) (build/bin/clang+0x4843224)
#<!-- -->31 0x00005608fd77a155 clang_main(int, char**, llvm::ToolContext const&amp;) (build/bin/clang+0x115c155)
#<!-- -->32 0x00005608fd687b8b main (build/bin/clang+0x1069b8b)
#<!-- -->33 0x00007f9b95229d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#<!-- -->34 0x00007f9b95229e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#<!-- -->35 0x00005608fd773c75 _start (build/bin/clang+0x1155c75)
clang: error: clang frontend command failed with exit code 134 (use -v to see invocation)
clang version 19.0.0git (git@<!-- -->github.com:llvm/llvm-project.git 995d1d114e4e4ff708a03cdb0a975209c6197f9f)
Target: arm-arm-none-eabi
Thread model: posix

Reproducer:

int arr[10];
int z = 42;

void func1(void)
{
  int i;
  int *p1;
  for (p1=arr,i=0; i&lt;10; i++,p1++)
     *p1 = z;
}

clang -c -O1 --target=arm-arm-none-eabi -march=armv8.1-m.main -g repro.c

[1] https://discourse.llvm.org/t/rfc-instruction-api-changes-needed-to-eliminate-debug-intrinsics-from-ir/68939
[2] #84054

@SLTozer
Copy link
Contributor

SLTozer commented Mar 14, 2024

Looks like the likely candidate is here: https://github.com/llvm/llvm-project/blob/main/llvm/lib/CodeGen/HardwareLoops.cpp#L583
Should have a fix up shortly.

@aeubanks aeubanks removed their assignment Mar 14, 2024
SLTozer added a commit that referenced this issue Mar 14, 2024
Fixes: #85254

Hardware loops inserts PHIs at the position `getFirstNonPhi()`, which is
incorrect - instead, `getFirstNonPhiIt()` is required to not insert the
PHI after any debug records that immediately follow the last existing
PHI.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants