<html>
    <head>
      <base href="https://llvm.org/bugs/" />
    </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 --- - Bad PHI node after loop distribute"
   href="https://llvm.org/bugs/show_bug.cgi?id=28037">28037</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Bad PHI node after loop distribute
          </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>Linux
          </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>mikael.holmen@ericsson.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=16486" name="attach_16486" title="Reproducer ll file">attachment 16486</a> <a href="attachment.cgi?id=16486&action=edit" title="Reproducer ll file">[details]</a></span>
Reproducer ll file

We've stumled upon a case where loop-distribute produces wrong code:

opt -loop-distribute loopdistbad.ll

gives

PHINode should have one entry for each predecessor of its parent basic block!
%split = phi i16 [ undef, %bb6 ]
LLVM ERROR: Broken function found, compilation aborted!

It's after LoopVersioning that the code looks bad. Specifically after the call
to

LVer.versionLoop(DefsUsedOutside);


Before bb5.bb7_crit_edge looks like:

bb5.bb7_crit_edge: ; preds = %bb6
%_tmp142.lcssa = phi i16 [ %_tmp142, %bb6 ]
%split = phi i16 [ %_tmp12114, %bb6 ]
store i16 %_tmp142.lcssa, i16* %k.19
br label %bb7

and after:

bb5.bb7_crit_edge: ; preds = %bb6.lver.orig, %bb6
%_tmp142.lcssa = phi i16 [ %_tmp142, %bb6 ], [ %_tmp142.lver.orig,
%bb6.lver.orig ]
%split = phi i16 [ %_tmp12114, %bb6 ]
store i16 %_tmp142.lcssa, i16* %k.19
br label %bb7

The PHI

%_tmp142.lcssa = phi i16 [ %_tmp142, %bb6 ]

is rewritten by LoopVersioning::addPHINodes to add the new incoming edge, but
DefsUsedOutside doesn't contain the other PHI so that one isn't rewritten and
thus is left in a bad state.</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>