<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/85254>85254</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [DebugInfo][RemoveDIs] Phi nodes and debug records
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          rgwott
      </td>
    </tr>
</table>

<pre>
    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] https://github.com/llvm/llvm-project/pull/84054
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzkWltv4zqS_jXMC2FDou4PeXCc9nYOcvYESWb20aDIks1tidSSVC7z6xekZFt0bp3BYIHFNLrdMlms-lRVrCqyTI0ROwlwibIrlF1f0MHulb7Uu2dl7UWt-Ovl4x7ws9K_DObCsMEY4FhIjLKrGGXXmNHBjVCsYafBGKEk5upZGquBdtjuqcWMSlwD1tBrxQcGHA_9OL_E_wV4kBy0sVRybPfCYGGwUR3gZxDaybKgKbOOsWqw3TtGnXqirfvKoR52jkYLaQQz-FnYPe73AkvFwTiknhejBswSRdcoWo2ff5NWtFgDA2nbV88XtFYad2AM3QF-piMOuxdyh6E1gOvBuhcn_sX3VO6AnxaiZDXnj_Jo-uu_spbKHUpWGJENp5Zu5VMHsYwR2bTtUzf9t-i1-m9gdjYqakQ2N_fuwyl18JpYsr5HySrOE8fySQmOPX2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