[llvm-bugs] [Bug 30692] New: Failing to hoist all loads out of a loop

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Oct 13 17:13:34 PDT 2016


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

            Bug ID: 30692
           Summary: Failing to hoist all loads out of a loop
           Product: tools
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: opt
          Assignee: unassignedbugs at nondot.org
          Reporter: charles_li at playstation.sony.com
                CC: llvm-bugs at lists.llvm.org
    Classification: Unclassified

Hi Everyone,

Found a optimization issue.


Here is the test case.
$ cat t.cpp
/*************************/
int aaa = 10;
int bbb = 20;
int ccc = 30;

void foo(const int *pData)
{
    while (1)
    {
        int x = *pData++;

        if (x > ccc)
            bbb += x;

        if (x > bbb)
            aaa += x;

        if (x > aaa)
            ccc += x;

        if (x < 0)
            break;
    }
}
/*************************/


Compile this test with optimization.
$ clang t.cpp -S -O2


Here is the assembly.
$ cat t.s

        .text
        .file   "t.cpp"
        .globl  _Z3fooPKi
        .p2align        4, 0x90
        .type   _Z3fooPKi, at function
_Z3fooPKi:                              # @_Z3fooPKi
        .cfi_startproc
# BB#0:                                 # %entry
        movl    ccc(%rip), %eax
        .p2align        4, 0x90
.LBB0_1:                                # %while.body
                                        # =>This Inner Loop Header: Depth=1
        movl    (%rdi), %ecx
        movl    bbb(%rip), %edx
        cmpl    %eax, %ecx
        jle     .LBB0_3
# BB#2:                                 # %if.then
                                        #   in Loop: Header=BB0_1 Depth=1
        addl    %ecx, %edx
        movl    %edx, bbb(%rip)
.LBB0_3:                                # %if.end
                                        #   in Loop: Header=BB0_1 Depth=1
        movl    aaa(%rip), %esi
        cmpl    %edx, %ecx
        jle     .LBB0_5
# BB#4:                                 # %if.then2
                                        #   in Loop: Header=BB0_1 Depth=1
        addl    %ecx, %esi
        movl    %esi, aaa(%rip)
.LBB0_5:                                # %if.end4
                                        #   in Loop: Header=BB0_1 Depth=1
        cmpl    %esi, %ecx
        jle     .LBB0_7
# BB#6:                                 # %if.then6
                                        #   in Loop: Header=BB0_1 Depth=1
        addl    %ecx, %eax
        movl    %eax, ccc(%rip)
.LBB0_7:                                # %if.end8
                                        #   in Loop: Header=BB0_1 Depth=1
        addq    $4, %rdi
        testl   %ecx, %ecx
        jns     .LBB0_1
# BB#8:                                 # %while.end
        retq
.Lfunc_end0:
        .size   _Z3fooPKi, .Lfunc_end0-_Z3fooPKi
        .cfi_endproc

        .type   aaa, at object             # @aaa
        .data
        .globl  aaa
        .p2align        2
aaa:
        .long   10                      # 0xa
        .size   aaa, 4

        .type   bbb, at object             # @bbb
        .globl  bbb
        .p2align        2
bbb:
        .long   20                      # 0x14
        .size   bbb, 4

        .type   ccc, at object             # @ccc
        .globl  ccc
        .p2align        2
ccc:
        .long   30                      # 0x1e
        .size   ccc, 4



Looking at the location of these 3 instructions:
  movl    ccc(%rip), %eax
  movl    bbb(%rip), %edx
  movl    aaa(%rip), %esi
we can see that, 
only the load of “ccc” got hoisted into the %entry block,
while the load of “bbb” and “aaa” are still inside the %while.body.

-- 
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/20161014/4422c0d4/attachment.html>


More information about the llvm-bugs mailing list