https://llvm.org/bugs/show_bug.cgi?id=28969

            Bug ID: 28969
           Summary: Loop not optimized away
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: Loop Optimizer
          Assignee: unassignedb...@nondot.org
          Reporter: jmuizel...@mozilla.com
                CC: llvm-bugs@lists.llvm.org
    Classification: Unclassified

Compiling this code with clang with -Oz gives


void m();

void l(unsigned int r) {
        for (unsigned int x = 0, q = 0; x<r; x++, q++) {
            if (q == r) {
                m();
            }
        }
}

(__TEXT,__text) section
_l:
pushq    %rbp
movq    %rsp, %rbp
leal    0x1(%rdi), %eax
xorl    %ecx, %ecx
movl    %eax, %edx
andl    $0x7, %edx
je    0x18
xorl    %ecx, %ecx
incl    %ecx
cmpl    %ecx, %edx
jne    0x12
cmpl    $0x7, %edi
jb    0x24
subl    %ecx, %eax
addl    $-0x8, %eax
jne    0x1f
popq    %rbp
retq

changing:
if (q == r) {
to:
if (x == r) {

allows clang to successfully optimize the function away.
gcc optimizes the function away without any changes.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to