<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 - [InstCombine] MinMax patterns produce an infinite loop within InstCombine."
   href="https://bugs.llvm.org/show_bug.cgi?id=37526">37526</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>[InstCombine] MinMax patterns produce an infinite loop within InstCombine.
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>new-bugs
          </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>normal
          </td>
        </tr>

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

        <tr>
          <th>Component</th>
          <td>new bugs
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>matthew.davis@sony.com
          </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=20319" name="attach_20319" title="Reduced Reproducer">attachment 20319</a> <a href="attachment.cgi?id=20319&action=edit" title="Reduced Reproducer">[details]</a></span>
Reduced Reproducer

The attached test case is a reduced version of some code that we have found to
be producing an infinite loop within InstCombine.

I have noted that the code works prior to r320157 (December 2017) but with the
added handling of MinMax patterns in the r320157 patch, it seems that
InstCombine::run gets stuck (infinite loop).

In particular, a minmax pattern is discovered in InstCombiner, and
removeBitcastsFromLoadStoreOnMinMax is called (InstCombineLoadStoreAlloca.cpp)
to handle an instruction that matches that pattern.  This routine introduces a
load and store which eventually get removed during the same iteration of
InstCombiner::run(). 
The load becomes trivially dead. The store is removed because it is
automatically added to the Worklist in InstCombiner, and is visited in the same
run() iteration.  When this newly created Store instruction is visited it is
recognized as being part of a minmax pattern, and
removeBitcastsFromLoadStoreOnMinMax is called.  That routine is successful, and
that store is removed.

This instruction add/removal sets the InstCombine::MadeIRChange,  flag which
controls the exit of InstCombine::run.  However, since that iteration of run()
will always add and remove instructions, no fixed point is achieved, and run()
is called indefinitely.

Reproduced with trunk and 6.0 release:
clang++ -O2 ./reducer.cc -c</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>