<html>
    <head>
      <base href="http://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 --- - LoopSimplify inserts backedge block in wrong spot"
   href="http://llvm.org/bugs/show_bug.cgi?id=15596">15596</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>LoopSimplify inserts backedge block in wrong spot
          </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>tim.besard@elis.ugent.be
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvmbugs@cs.uiuc.edu
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>When a loop contains multiple backedges, LoopSimplify inserts a new backedge in
order to ensure that all loops have exactly one backedge
(LoopSimplify::InsertUniqueBackedgeBlock). When inserting the newly created
back-edge, the comments detail that the block is to be inserted right after the
last backedge block. This is implemented by inserting before
"BackedgeBlocks.back()+1".

However, BackedgeBlocks is filled by a loop which iterates over the
predecessors of the loop header. As it seems, pred_iterator does not iterate
the predecessors in order of occurrence in the program, but (as far as I see)
the other way around: it starts with the last predecessor, and ends up with the
first one.

This means that "BackedgeBlocks.back()+1" actually points to right after the
first backedge block, rather than the last one.

I don't know whether pred_iterator is supposed to iterate the predecessors from
last predecessor to the first one, but if it is I think it would suffice to
change "InsertPos = BackedgeBlocks.back()" to "BackedgeBlocks.front()" in order
to get the documented behaviour.</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>