[LLVMbugs] [Bug 17803] New: loop increment/compare/branch should be removed for vectorized and unrolled code

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Mon Nov 4 11:56:14 PST 2013


http://llvm.org/bugs/show_bug.cgi?id=17803

            Bug ID: 17803
           Summary: loop increment/compare/branch should be removed for
                    vectorized and unrolled code
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: Loop Optimizer
          Assignee: unassignedbugs at nondot.org
          Reporter: kkhoo at perfwizard.com
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified

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

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20131104/5b5a7623/attachment.html>


More information about the llvm-bugs mailing list