<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 - Loop vectorizer miscompile resulting in additional loop iteration"
   href="https://bugs.llvm.org/show_bug.cgi?id=32317">32317</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Loop vectorizer miscompile resulting in additional loop iteration
          </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>Loop Optimizer
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>igor@azulsystems.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Attached test case produces incorrect result when run -force-vector-width=2:

$ lli test.ll
89.000000

$ opt -S -O3 -force-vector-width=2 test.ll > test.opt.ll
$ lli test.opt.ll
90.000000

$ opt -S -O3 -force-vector-width=4 test.ll > test.opt.ll
$ lli test.opt.ll
89.000000

Looking at the output I believe that vectorizer incorrectly calculates
resulting loop value for the fFld:

vector.body:                                      
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %vec.ind = phi <2 x i64> [ <i64 4, i64 5>, %vector.ph ], [ %vec.ind.next,
%vector.body ]
  %vector.recur = phi <2 x i64> [ %vector.recur.init, %vector.ph ], [ %20,
%vector.body ]
  %20 = add nsw <2 x i64> %vec.ind, %broadcast.splat
  %21 = shufflevector <2 x i64> %vector.recur, <2 x i64> %20, <2 x i32> <i32 1,
i32 2>
  %index.next = add i64 %index, 2
  %vec.ind.next = add <2 x i64> %vec.ind, <i64 2, i64 2>
  %22 = icmp eq i64 %index.next, 86
  br i1 %22, label %middle.block, label %vector.body, !llvm.loop !52

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 86, 86
  %vector.recur.extract = extractelement <2 x i64> %20, i32 1
  br i1 %cmp.n, label %bci_64, label %scalar.ph

If in the "%vector.recur.extract" instead of the "%20" we would have used
"%vec.ind" - result would have been correct.

Attached .ll test case and roughly equivalent c code.</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>