<html>
    <head>
      <base href="http://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 --- - loop increment/compare/branch should be removed for vectorized and unrolled code"
   href="http://llvm.org/bugs/show_bug.cgi?id=17803">17803</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>loop increment/compare/branch should be removed for vectorized and unrolled code
          </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>kkhoo@perfwizard.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvmbugs@cs.uiuc.edu
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>For this fixed-length loop:

$ cat xor.c 
void foo(unsigned char *a) {
    for (int i = 0; i < 128; i++) {
        a[i] = 0x36 ^ a[i];
    }
}

LLVM is unrolling and vectorizing, but fails to remove the loop
comparison/branch. The unrolled portion of the code will never loop:

$ ./clang  -O3 -fomit-frame-pointer  -o - -S xor.c -ffp-contract=fast
-march=core-avx2
    .section    __TEXT,__text,regular,pure_instructions
    .section    __TEXT,__const
    .align    5
LCPI0_0:
    .space    32,54
    .section    __TEXT,__text,regular,pure_instructions
    .globl    _foo
    .align    4, 0x90
_foo:                                   ## @foo
    .cfi_startproc
## BB#0:                                ## %entry
    xorl    %eax, %eax
    vmovaps    LCPI0_0(%rip), %ymm0
    .align    4, 0x90
LBB0_1:                                 ## %vector.body
                                        ## =>This Inner Loop Header: Depth=1
    vmovups    (%rdi,%rax), %ymm1
    vmovups    32(%rdi,%rax), %ymm2
    vxorps    %ymm0, %ymm1, %ymm1
    vxorps    %ymm0, %ymm2, %ymm2
    vxorps    64(%rdi,%rax), %ymm0, %ymm3
    vmovups    %ymm1, (%rdi,%rax)
    vmovups    %ymm2, 32(%rdi,%rax)
    vmovups    %ymm3, 64(%rdi,%rax)
    addq    $96, %rax              <--- %rax = 96 the first time through
    cmpq    $96, %rax              <--- always true
    jne    LBB0_1
## BB#2:                                ## %for.body.preheader
    xorl    %eax, %eax
    .align    4, 0x90
LBB0_3:                                 ## %for.body
                                        ## =>This Inner Loop Header: Depth=1
    xorb    $54, 96(%rdi,%rax)
    incq    %rax
    cmpq    $32, %rax
    jne    LBB0_3
## BB#4:                                ## %for.end
    vzeroupper
    ret


This is with:
$ ./clang  -v
clang version 3.4 (trunk 193529) (llvm/trunk 193527)
Target: x86_64-apple-darwin11.4.2
Thread model: posix</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>