<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 --- - LoopVectorizer does not properly preserve LoopInfo"
   href="https://llvm.org/bugs/show_bug.cgi?id=26952">26952</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>LoopVectorizer does not properly preserve LoopInfo
          </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>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>anemet@apple.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=16040" name="attach_16040" title="testcase">attachment 16040</a> <a href="attachment.cgi?id=16040&action=edit" title="testcase">[details]</a></span>
testcase

On the attached testcase based on MultiSource/Benchmarks/nbench/nbench1.c, LV
fails to preserve LoopInfo.  -verify-loop-info fails with:

$ opt before-vect-func.ll -targetlibinfo -tti -tbaa -scoped-noalias
-assumption-cache-tracker -forceattrs -inferattrs -loop-vectorize
-verify-loop-info

Assertion failed: (HasInsideLoopSuccs && "Loop block has no in-loop
successors!"), function verifyLoop, file
../include/llvm/Analysis/LoopInfoImpl.h, line 279.

This is the difference between what -loops and what LV produces:

@@ -21 +20,0 @@
-    Loop at depth 2 containing:
%vector.body<header>,%pred.store.if,%13,%pred.store.continue,%pred.store.if2,%15,%pred.store.continue3<latch><exiting>
@@ -31,0 +31 @@
+    Loop at depth 2 containing:
%vector.body<header><exiting>,%pred.store.continue<exiting>,%pred.store.continue3<latch><exiting>

Bunch of blocks are missing, looks like all related to store predication.

I triggered this latent bug after making LoopLoadElimination dependent on
LoopSimplify.  LoopSimplify trims many blocks because of corrupt LI:

LoopSimplify: Deleting edge from dead predecessor
LoopSimplify: Deleting edge from dead predecessor
LoopSimplify: Creating dedicated exit block .loopexit
LoopSimplify: Creating dedicated exit block .loopexit4
LoopSimplify: Creating dedicated exit block for.end31.loopexit</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>