<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - LoopDeletion causes an assert `use_empty() && "Uses remain when a value is destroyed!"'"
   href="https://bugs.llvm.org/show_bug.cgi?id=35884">35884</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>LoopDeletion causes an assert `use_empty() && "Uses remain when a value is destroyed!"'
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libraries
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>Loop Optimizer
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>serguei.katkov@azul.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>For the following simple reproducer:
define i64 @foo() {
entry:
  br label %badloop
badloop:
  %indvar1 = phi i64 [ 3, %entry ], [ %indvar2, %badloop_iter ]
  %check = icmp ult i64 %indvar1, 400
  br i1 %check, label %badloop_iter, label %loopexit
badloop_iter:
  %indvar2 = add i64 %indvar1, 1
  %baddef = add i64 0, 0
  br label %badloop
loopexit:
  ret i64 0
deadcode:
  ret i64 %baddef
}

<span class="quote">> opt -S -loop-deletion test.ll</span >

While deleting: i64 %baddef
Use still stuck around after Def is destroyed:  ret i64 %baddef
opt: ../../lib/IR/Value.cpp:92: llvm::Value::~Value(): Assertion `use_empty()
&& "Uses remain when a value is destroyed!"' failed.

The cause of this is that %baddef is defined in BB which does not dominate exit
and as a result LCCSA does not create a Phi node for it.

As a result LoopDeletion detects that loop is invariant and tries to delete it.

Assert happens when %baddef instruction is deleted due to it has use in
unreachable block.

The IR is well-formed because %baddef dominates all instructions in unreachable
block.</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>