[llvm-bugs] [Bug 35087] New: Compiler transforming loop into an infinite loop when optimizations are enabled after r316208

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Oct 25 16:31:26 PDT 2017


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

            Bug ID: 35087
           Summary: Compiler transforming loop into an infinite loop when
                    optimizations are enabled after r316208
           Product: new-bugs
           Version: trunk
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: new bugs
          Assignee: unassignedbugs at nondot.org
          Reporter: douglas_yung at playstation.sony.com
                CC: llvm-bugs at lists.llvm.org

Recently IR Value Tracking was enabled by default in the compiler with r316208,
and in one of our tests, we noticed that after this commit, when optimizations
are enabled, the compiler is transforming a loop into an infinite loop.

Consider the following code repro.cpp:

extern void bar( int );

void foo() {
  for ( int x = 0x7ffffff0; x != -0x7ffffff0; ++x )
    bar( x );
}

When compiled using -O2 and a compiler built from r316207, the following x86
assembly is generated for the loop (it is fully unrolled):

        pushq   %rax
        .cfi_def_cfa_offset 16
        movl    $2147483632, %edi       # imm = 0x7FFFFFF0
        callq   _Z3bari
        movl    $2147483633, %edi       # imm = 0x7FFFFFF1
        callq   _Z3bari

        ...

        movl    $-2147483634, %edi      # imm = 0x8000000E
        callq   _Z3bari
        movl    $-2147483633, %edi      # imm = 0x8000000F
        popq    %rax
        jmp     _Z3bari                 # TAILCALL

When compiled using -O2 and a compiler built from r316208, the following code
is generated instead for the loop:

        movl    $2147483632, %ebx       # imm = 0x7FFFFFF0
        .p2align        4, 0x90
.LBB0_1:                                # %for.cond
                                        # =>This Inner Loop Header: Depth=1
        movl    %ebx, %edi
        callq   _Z3bari
        addl    $1, %ebx
        jmp     .LBB0_1

As can be seen, the compiler transformed the loop into an infinite loop.

-- 
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/20171025/f456bacc/attachment.html>


More information about the llvm-bugs mailing list