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

            Bug ID: 64992
           Summary: More optimize opportunity
           Product: gcc
           Version: 5.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

The two programs (A.c) and (B.c) only differ by one line (marked by "//
<---HERE"),
where (B.c) simply replace local variable b by its initial value 2U.
The code (A.s) for (A.c) is less optimized than (B.s) for (B.c).

(org.c)
int main (void)
{
  volatile int a = -1;
  unsigned int b = 2U;

  int          c = a + 0;
  unsigned     d = b * (1 == c);     //<---HERE

  if (c == -1) ;
  else __builtin_abort();
  if (d == 0U) ;
  else __builtin_abort();

  return 0;
}

(opt.c)
int main (void)
{
  volatile int a = -1;
  unsigned int b = 2U;

  int          c = a + 0;
  unsigned     d = 2U * (1 == c);    //<---HERE

  if (c == -1) ;
  else __builtin_abort();
  if (d == 0U) ;
  else __builtin_abort();

  return 0;
}

(org.s)
main:
.LFB0:
  .cfi_startproc
  subq   $24, %rsp
  .cfi_def_cfa_offset 32
  xorl   %eax, %eax
  movl   $-1, 12(%rsp)
  movl   12(%rsp), %edx
  cmpl   $1, %edx
  sete   %al
  addl   %eax, %eax
  cmpl   $-1, %edx
  jne    .L3
  testl  %eax, %eax
  jne    .L3
  addq   $24, %rsp
  .cfi_remember_state
  .cfi_def_cfa_offset 8
  ret
.L3:
  .cfi_restore_state
  call  abort
  .cfi_endproc
.LFE0:
  .size  main, .-main
  .section  .text.unlikely
.LCOLDE0:
  .section  .text.startup
.LHOTE0:
  .ident  "GCC: (GNU) 5.0.0 20150205 (experimental)"
  .section  .note.GNU-stack,"",@progbits

(opt.s)
main:
.LFB0:
  .cfi_startproc
  subq   $24, %rsp
  .cfi_def_cfa_offset 32
  movl   $-1, 12(%rsp)
  movl   12(%rsp), %eax
  cmpl   $-1, %eax
  jne    .L5
  xorl   %eax, %eax
  addq   $24, %rsp
  .cfi_remember_state
  .cfi_def_cfa_offset 8
  ret
.L5:
  .cfi_restore_state
  call  abort
  .cfi_endproc
.LFE0:
  .size  main, .-main
  .section  .text.unlikely
.LCOLDE0:
  .section  .text.startup
.LHOTE0:
  .ident  "GCC: (GNU) 5.0.0 20150205 (experimental)"
  .section  .note.GNU-stack,"",@progbits


$ x86_64-unknown-linux-gnu-gcc-5.0.0 -v
Using built-in specs.
COLLECT_GCC=x86_64-unknown-linux-gnu-gcc-5.0.0
COLLECT_LTO_WRAPPER=/usr/local/x86_64-tools/gcc-5.0.0/libexec/gcc/x86_64-unknown-linux-gnu/5.0.0/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: /home/iwatsuji/gcc/configure
--prefix=/usr/local/x86_64-tools/gcc-5.0.0/
--with-gmp=/usr/local/gmp-5.1.1/ --with-mpfr=/usr/local/mpfr-3.1.2/
--with-mpc=/usr/local/mpc-1.0.1/ --disable-multilib --disable-nls
--enable-languages=c
Thread model: posix
gcc version 5.0.0 20150205 (experimental) (GCC)

Reply via email to