<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 - NewGVN will fail to fixpoint on some phis with undef"
   href="https://bugs.llvm.org/show_bug.cgi?id=32403">32403</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>NewGVN will fail to fixpoint on some phis with undef
          </td>
        </tr>

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

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

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

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

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

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

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

        <tr>
          <th>Component</th>
          <td>Scalar Optimizations
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>dberlin@dberlin.org
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=18162" name="attach_18162" title="undef strikes again.ll">attachment 18162</a> <a href="attachment.cgi?id=18162&action=edit" title="undef strikes again.ll">[details]</a></span>
undef strikes again.ll

The attached will cause newgvn to infinite loop due to undef in a phi.

It requires a very unfortunate series of events.

We use the same check for whether we can use undef in a phi node as simplify*,
and we need to extend it, it turns out.

Here is what happens:

We have a dom tree that looks like this:

  A
 / \
B   C

..

Note that the first requirement is that B not dominate C and C not dominate B.
We also must visit C before B in RPO (note that here, either could be chosen as
the second block in RPO)

Next, in B and C there are two instructions that end up in the same congruence
class.
We visit C first, so the one in C becomes the leader.

The phi nodes eventually resolve to the instruction in B, which, if you look up
the leader, you get the one in C.

On the next iteration:
    // We also special case undef, so that if we have an undef, we can't use
the
    // common value unless it dominates the phi block.
  if (HasUndef) {
      // Only have to check for instructions
      if (auto *AllSameInst = dyn_cast<Instruction>(AllSameValue))
        if (!DT->dominates(AllSameInst, I))
           return E;

The instruction  in B dominates the phis, but the instruction in C does not.

So we dutily say "whoops, can't value number this phi to this value"
Which resets the resolution of the phi node cycles.
Which starts again, and gets the same result.

I believe the correct check here is in fact, "does any member of the class of
AllSameInst dominate I"
Since we only would replace it with a member that dominates that phis anyway,
this should be correct.</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>