This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug tree-optimization/84515] New: missed optimization: expected loop merging


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84515

            Bug ID: 84515
           Summary: missed optimization: expected loop merging
           Product: gcc
           Version: 8.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: nsz at gcc dot gnu.org
  Target Milestone: ---

i expected f1 and f2 to compile to the same code:

unsigned g;

void f1(unsigned count) {
    unsigned i;
    for (i = 0; i < count  ; i++) g++;
}

void f2(unsigned count) {
    unsigned i;
    for (i = 0; i < count/2; i++) g++;
    for (     ; i < count  ; i++) g++;
}


but with -O3 the asm is

f1:
  testl %edi, %edi
  je .L1
  addl %edi, g(%rip)
.L1:
  ret

f2:
  movl %edi, %eax
  shrl %eax
  je .L8
  addl %eax, g(%rip)
.L8:
  cmpl %eax, %edi
  jbe .L7
  subl %eax, %edi
  addl %edi, g(%rip)
.L7:
  ret

(on aarch64 even the address of g is recomputed for the second loop with adrp)

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]