title: Clang fails to vectorize when comparing sequential array elements
body: <p>I am attempting to vectorize the inner loop of my alignment function, and have run into a problem I do not understand. When two elements that are sequential in the input array are compared, the loop does not vectorize, but when the elements being compared are offset by 2, it successfully vectorizes. A minimal example:</p>
  
  <pre><code>int *vec_test(int *input) {
    int i, n1, n2;
    int *out = (int *) malloc(100 * sizeof(int));
  
    // This loop fails to vectorize
    for(i=1;i&lt;100;i++) {
      n1 = input[i-1];
      n2 = input[i];
      out[i] = n1 &gt; n2 ? n1 : n2;
    }
  
    // This loop successfully vectorizes
    for(i=1;i&lt;100;i++) {
      n1 = input[i-1];
      n2 = input[i+1];
      out[i] = n1 &gt; n2 ? n1 : n2;
    }
  
    return(out);
  }
  </code></pre>
  
  <p>When I use clang to compile this code (clang++ -O2 -Rpass=loop-vectorize -Rpass-analysis=loop-vectorize -c minimal.cpp) the second loop vectorizes, but the first loop does not.</p>
  
  <blockquote>
    <p>minimal.cpp:17:17: remark: loop not vectorized: value that could not
    be
          identified as reduction is used outside the loop</p>
    
    <p>minimal.cpp:23:3: remark: vectorized loop (vectorization factor: 4,
    unrolling
          interleave factor: 1) [-Rpass=loop-vectorize]</p>
  </blockquote>
  
  <p>The only difference is that the elements being compared are consecutive in the first loop, and offset by 2 in the second loop. Why does the first loop fail to vectorize?</p>
  
  <p><strong>Edit:</strong> Replacing the ints with different width types (int64_t, int32_t, or int16_t) yields the same results in all cases: the bottom loop vectorizes, the top loop fails to do so.</p>