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

            Bug ID: 81165
           Summary: Regression in GCC-8.0.0's optimizer
           Product: gcc
           Version: 8.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: ishiura-compiler at ml dot kwansei.ac.jp
  Target Milestone: ---

We compiled the following program by GCC-8.0.0 and GCC-7.0.1 with -O3 option.
GCC-7.0.1 performed better optimization than GCC-8.0.0.

$ cat test.c
void func() __attribute__((noinline));
short x0 = 15;

int main (void){
  long i;
  for(i = 0; i < 100000000; i++){
    func();
  }
  return 0;
}

void func (){
  volatile int x1 = 1U;
  volatile char x2 = 0;
  char t0 = 0;
  unsigned long t1 = 2LU;
  int i = 0;

  if(1>>x2) {
    t0 = -1;
    t1 = (1&(short)(x1^8U))-1;
  }

  while(i > (int)((1U>>t1)+(char)(128%(10*(25LU&(29%x0)))))) {
    i += (int)(12L/(1!=(int)t1));
  }

  if (t0 != -1) __builtin_abort();
  if (t1 != 0L) __builtin_abort();
}

$ gcc-8.0 test.c -O3 -o test.out && time ./test.out  
./test.out  1.50s user 0.00s system 99% cpu 1.506 total

$ gcc-7.0.1 test.c -O3 -o test.out && time ./test.out
./test.out  0.26s user 0.00s system 98% cpu 0.264 total

+-------------------------------------+---------------------------------------+
|gcc-8.0.s    (gcc-8.0 test.c -O3 -S) |gcc-7.0.1.s  (gcc-7.0.1 test.c -O3 -S) |
+-------------------------------------+---------------------------------------+
|         .cfi_startproc              |          .cfi_startproc               | 
|         subq     $24, %rsp          |          subq      $24, %rsp          | 
|         .cfi_def_cfa_offset 32      |          .cfi_def_cfa_offset 32       | 
|         movl     $1, %edi           |          movl      $1, %eax           | 
|         movl     $1, 12(%rsp)       |          movl      $1, 12(%rsp)       | 
|         movb     $0, 11(%rsp)       |          movb      $0, 11(%rsp)       | 
|         movl     %edi, %eax         |                                       |
|         movzbl     11(%rsp), %ecx   |          movzbl  11(%rsp), %ecx       |
|         sarl     %cl, %eax          |          sarl      %cl, %eax          |
|         testl     %eax, %eax        |          testl      %eax, %eax        |
|         je         .L7              |          jne      .L12                |
|         movl     12(%rsp), %ecx     |                                       |
|         movl     $-1, %r9d          |                                       |
|         andl     $1, %ecx           |                                       |
|         subl     $1, %ecx           |                                       |
|         movslq     %ecx, %r8        |                                       |
|         shrl     %cl, %edi          |                                       |
|.L2:                                 |.L2:                                   |
|         movswl     x0(%rip), %esi   |          call      abort              |
|         movl     $29, %eax          |          .p2align 4,,10               |
|         cltd                        |          .p2align 3                   |
|         idivl     %esi              |.L12:                                  |
|         movl     $128, %eax         |          movl      12(%rsp), %eax     |
|         andl     $25, %edx          |          andl      $1, %eax           |
|         leaq     (%rdx,%rdx,4), %rsi|          subl      $1, %eax           |
|         xorl     %edx, %edx         |          testl      %eax, %eax        |
|         addq     %rsi, %rsi         |          jne      .L2                 |
|         divq     %rsi               |                                       |
|         movsbl     %dl, %edx        |                                       | 
|         addl     %edi, %edx         |                                       |
|         jns     .L3                 |                                       | 
|         cmpl     $1, %ecx           |                                       |
|         je         .L10             |                                       |
|.L3:                                 |                                       |
|         cmpb     $-1, %r9b          |                                       |
|         jne     .L6                 |                                       |
|         testq     %r8, %r8          |                                       |
|         jne     .L6                 |                                       |
|         addq     $24, %rsp          |          addq      $24, %rsp          |
|         .cfi_remember_state         |                                       |
|         .cfi_def_cfa_offset 8       |          .cfi_def_cfa_offset 8        |
|         ret                         |          ret                          |
|         .p2align 4,,10              |                                       |
|         .p2align 3                  |                                       |
|.L10:                                |                                       |
|         .cfi_restore_state          |                                       |
|         ud2                         |                                       |
|         .p2align 4,,10              |                                       |
|         .p2align 3                  |                                       |
|.L7:                                 |                                       |
|         movl     $2, %ecx           |                                       |
|         xorl     %edi, %edi         |                                       |
|         movl     $2, %r8d           |                                       |
|         xorl     %r9d, %r9d         |                                       |
|         jmp     .L2                 |                                       |
|         .cfi_endproc                |          .cfi_endproc                 |
|         .section         .text.un...|                                       |
|         .cfi_startproc              |                                       | 
|         .type     func.cold.0, @f...|                                       | 
|func.cold.0:                         |                                       | 
|.L6:                                 |                                       | 
|         .cfi_def_cfa_offset 32      |                                       | 
|         call     abort              |                                       | 
|         .cfi_endproc                |                                       | 
|.LFE1:                               |.LFE1:                                 | 
|         .text                       |                                       | 
|         .size     func, .-func      |          .size      func, .-func      |
|         .section         .text.un...|                                       |
|         .size     func.cold.0, .-...|                                       |
|.LCOLDE0:                            |                                       |
|         .text                       |                                       |
|.LHOTE0:                             |                                       |
|         .section         .text.st...|          .section          .text.st...|
|         .p2align 4,,15              |          .p2align 4,,15               |
|         .globl     main             |          .globl  main                 |
+-------------------------------------+---------------------------------------+
|         movl     $100000000, %ebx   |          movl      $100000000, %ebx   |
|         .p2align 4,,10              |          .p2align 4,,10               |
|         .p2align 3                  |          .p2align 3                   |
|.L12:                                |.L14:                                  |
|         xorl     %eax, %eax         |          xorl      %eax, %eax         |
|         call     func               |          call      func               |
|         subq     $1, %rbx           |          subq      $1, %rbx           |
|         jne     .L12                |          jne      .L14                |
|         xorl     %eax, %eax         |          xorl      %eax, %eax         |
|         popq     %rbx               |          popq      %rbx               |
|         .cfi_def_cfa_offset 8       |          .cfi_def_cfa_offset 8        |
+-------------------------------------+---------------------------------------+
|         .size     x0, 2             |          .size      x0, 2             |
|x0:                                  |x0:                                    |
|         .value     15               |          .value  15                   |
|         .ident     "GCC: (GNU) 8....|          .ident  "GCC: (GNU) 7.0.1 ...|
|         .section         .note.GN...|          .section          .note.GN...|
+-------------------------------------+---------------------------------------+

$ gcc-8.0 -v
using built-in specs.
COLLECT_GCC=gcc-8.0
COLLECT_LTO_WRAPPER=/home/kota/opt/gcc-8.0/libexec/gcc/x86_64-pc-linux-gnu/8.0.0/lto-wrapper
target: x86_64-pc-linux-gnu
configure woth: ../gcc/configure --prefix=/home/kota/opt/gcc
--program-suffix=-8.0 --disable-multilib --enable-languages=c
thred model: posix
gcc version 8.0.0 20170621 (experimental) (GCC) 

$ gcc-7.0.1 -v
using built-in specs.
COLLECT_GCC=gcc-7.0.1
COLLECT_LTO_WRAPPER=/home/kota/opt/gcc-7.0.1/libexec/gcc/x86_64-pc-linux-gnu/7.0.1/lto-wrapper
target: x86_64-pc-linux-gnu
configure woth: ../gcc/configure --prefix=/home/kota/opt/gcc
--program-suffix=-7.0.1 --disable-multilib --enable-languages=c
thred model: posix
gcc version 7.0.1 20170216 (experimental) (GCC)

Reply via email to