<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 --- - [x86, loop vectorizer] cost model causes loop to not vectorize"
   href="https://llvm.org/bugs/show_bug.cgi?id=27619">27619</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>[x86, loop vectorizer] cost model causes loop to not vectorize
          </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>spatel+llvm@rotateright.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>Re-filing the example from <a class="bz_bug_link 
          bz_status_RESOLVED  bz_closed"
   title="RESOLVED FIXED - [ppc] slow data reorganization in VSX register (through memory)"
   href="show_bug.cgi?id=27078">bug 27078</a> as a potential x86 cost model bug and/or
loop vectorizer bug. Note that this vectorizes for PPC but not x86 w/ AVX. But
I don't think the vectorization is being done optimally for PPC: no shuffles
should be needed if we treat everything as <12 x float>.

$ ./clang -O2 27078_orig.c -S -o - -emit-llvm -Rpass-analysis=loop-vectorize
-mavx
27078_orig.c:5:30: remark: the cost-model indicates that vectorization is not
beneficial [-Rpass-analysis=loop-vectorize]
      float* blurred_pixel = blurred_row[j];
                             ^
27078_orig.c:5:30: remark: the cost-model indicates that interleaving is not
beneficial [-Rpass-analysis=loop-vectorize]


typedef float Vector3_f[3];

void foo(Vector3_f* blurred_row, int width, float* pixel, float pixel_diff_avg)
{
    for (int j = 0; j < width; ++j, pixel += 3) {
      float* blurred_pixel = blurred_row[j];

      float pixel_diff[3];
      pixel_diff[0] = blurred_pixel[0] - pixel[0];
      pixel_diff[1] = blurred_pixel[1] - pixel[1];
      pixel_diff[2] = blurred_pixel[2] - pixel[2];

      pixel_diff[0] -= pixel_diff_avg;
      pixel_diff[1] -= pixel_diff_avg;
      pixel_diff[2] -= pixel_diff_avg;

      pixel[0] += pixel_diff[0];
      pixel[1] += pixel_diff[1];
      pixel[2] += pixel_diff[2];
    }
}</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>