<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 - Missed vectorization opportunity"
   href="https://bugs.llvm.org/show_bug.cgi?id=44148">44148</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Missed vectorization opportunity
          </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>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>david.bolvansky@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>#define N 512

int a[N], b[N];

int
foo (int aval)
{
  int res = 0;
  for (int i=0; i<N; i++)
  {
    if (a[i] != 0)
      res = aval;
  }
  return res;
}

Clang -O3 -march=haswell: loop not vectorized [-Rpass-missed=loop-vectorize]

foo(int): # @foo(int)
  xor eax, eax
  mov rcx, -2048
.LBB0_1: # =>This Inner Loop Header: Depth=1
  mov edx, dword ptr [rcx + a+2052]
  or edx, dword ptr [rcx + a+2048]
  or edx, dword ptr [rcx + a+2056]
  or edx, dword ptr [rcx + a+2060]
  or edx, dword ptr [rcx + a+2064]
  or edx, dword ptr [rcx + a+2068]
  or edx, dword ptr [rcx + a+2072]
  or edx, dword ptr [rcx + a+2076]
  cmovne eax, edi
  add rcx, 32
  jne .LBB0_1
  ret
a:
  .zero 2048

b:
  .zero 2048


ICC -O3 -march=haswell:
foo(int):
        xor       eax, eax                                      #10.11
        vpxor     ymm1, ymm1, ymm1                              #13.17
        xor       edx, edx                                      #11.3
        vpcmpeqd  ymm0, ymm0, ymm0                              #10.11
..B1.2:                         # Preds ..B1.2 ..B1.1
        vpcmpeqd  ymm2, ymm1, YMMWORD PTR [a+rdx*4]             #13.17
        add       rdx, 8                                        #11.3
        vpxor     ymm3, ymm2, ymm0                              #10.11
        vmovmskps ecx, ymm3                                     #10.11
        or        eax, ecx                                      #10.11
        cmp       rdx, 512                                      #11.3
        jb        ..B1.2        # Prob 99%                      #11.3
        test      eax, eax                                      #16.10
        cmovne    eax, edi                                      #16.10
        vzeroupper                                              #16.10
        ret                                                     #16.10
a:
b:

<a href="https://godbolt.org/z/AjRQNY">https://godbolt.org/z/AjRQNY</a>

This loop is similar, also not vectorized:
int
foo (int aval)
{
  int res = 0;
  for (int i=0; i<N; i++)
  {
    if (a[i] != 0)
      res = b[i];
  }
  return res;
}

<a href="https://godbolt.org/z/AU_5rf">https://godbolt.org/z/AU_5rf</a></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>