<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 - miscompile with Loop Vectorizer on a simple double-nested loop"
   href="https://bugs.llvm.org/show_bug.cgi?id=42384">42384</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>miscompile with Loop Vectorizer on a simple double-nested loop
          </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>fedor.v.sergeev@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=22137" name="attach_22137" title="bad-vector.ll">attachment 22137</a> <a href="attachment.cgi?id=22137&action=edit" title="bad-vector.ll">[details]</a></span>
bad-vector.ll

Consider this C testcase:

] cat vector.c
extern int printf(const char*, ...);

long mainTest() {
  int byFld = 0;
  long instanceCount=0;
  int i24=0;
  for (int i25 = 0; ++i25 < 260;) {
    i24 += i25;
    for (int i30 = 1; i30 < 31; i30++) {
      instanceCount += (i30 ^ byFld);
      byFld -= (char)i24;
    }
  }
  return instanceCount;
}

int main() {
  printf("%ld\n", mainTest());
}
] gcc -m64 vector.c; ./a.out
-139279619
]

Attached is IR produced and reduced from an equivalent Java program,
snapshotted right before Loop Vectorizer. It looks basically as what you would
expect to see by translating the above C code into IR, yet I did not bother to
find exact sequence of clang optimizations that could show me the same result.

] grep -n define bad-vector.ll
6:define i64 @mainTest() {
49:define i32 @main() {
] bin/opt bad-vector.ll | bin/lli
-139279619

As you see, the result matches the expected output shown above.
Now adding loop-vectorizer:

] bin/opt -passes=loop-vectorize bad-vector.ll | bin/lli
-139446659

and here is a wrong result.</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>