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
          Reporter: nsz at gcc dot
  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

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

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

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

Reply via email to