<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 --- - Vectorizer failure"
   href="https://llvm.org/bugs/show_bug.cgi?id=26314">26314</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Vectorizer failure
          </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>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>Loop Optimizer
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>egor.kochetov@intel.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=15718" name="attach_15718" title="The reproducer (20 SLOC, either C or C++, does not matter)">attachment 15718</a> <a href="attachment.cgi?id=15718&action=edit" title="The reproducer (20 SLOC, either C or C++, does not matter)">[details]</a></span>
The reproducer (20 SLOC, either C or C++, does not matter)

While compiling the attached 'main.cpp' I've encountered clang vectorization
problem, the performance difference is 58ms vs 20ms (almost 200%). After the
commit r257134 clang fails to vectorize 'slow_function'.

I compile with:
    clang++ -O2 -m64 -march=slm -mfpmath=sse -fPIE -flto -g -fvectorize
Results for -O2 and -Ofast, for -m32 and -m64 are all the same.

Here is what I get from an old (fast) clang:

    main.cpp:11:9: remark: the cost-model indicates that interleaving is not
beneficial [-Rpass-analysis=loop-vectorize]
            for (int k=0; k<Z; k++) {

Here is what I get from a new (slow) clang:

    main.cpp:11:9: remark: loop not vectorized: cannot check memory
dependencies at runtime [-Rpass-analysis=loop-vectorize]
            for (int k=0; k<Z; k++) {

The triggering SVN change is:

    Index: lib/Analysis/LoopAccessAnalysis.cpp
    ===================================================================
    --- lib/Analysis/LoopAccessAnalysis.cpp (revision 257133)
    +++ lib/Analysis/LoopAccessAnalysis.cpp (revision 257134)
    @@ -845,6 +845,7 @@
       if (Lp != AR->getLoop()) {
         DEBUG(dbgs() << "LAA: Bad stride - Not striding over innermost loop "
<<
               *Ptr << " SCEV: " << *PtrScev << "\n");
    +    return 0;
       }

       // The address calculation must not wrap. Otherwise, a dependence could
be

For comparison, here is what I get from GCC 6.0 trunk with
'-fopt-info-vec-note':

    loop at main.cpp:12: if (ivtmp_126 >= bnd.8_75)

    main.cpp:11:24: note: LOOP VECTORIZED

The binary compiled by GCC is slightly faster than that compiled by old clang
(well, if I add fwrite of s to /dev/null at the end of 'main').</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>