https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61839
Bug ID: 61839 Summary: More optimize opportunity Product: gcc Version: 4.8.4 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 We have two equvalent programs (A) and (B), which only differ by one line (marked by "// <---HERE"), where (B) simply folds a+972195718 to 972195717, for local variable a=-1. Resulting code by "x86_64-unknown-linux-gnu-gcc-4.8.4 -Os -S" is different; the code for (A) is less optimized than that of (B). (A) int main (void) { int a = -1; volatile unsigned b = 1U; int c = 1; c = (a + 972195718) >> (1LU <= b); // <---HERE if (c == 486097858); else __builtin_abort(); return 0; } (B) int main (void) { int a = -1; volatile unsigned b = 1U; int c = 1; c = 972195717 >> (1LU <= b); // <---HERE if (c == 486097858); else __builtin_abort(); return 0; } +-----------------------------+-----------------------------+ |(A) |(B) | +-----------------------------+-----------------------------+ |main: |main: | |.LFB0: |.LFB0: | | .cfi_startproc | .cfi_startproc | | subq $24, %rsp | subq $24, %rsp | | .cfi_def_cfa_offset 32 | .cfi_def_cfa_offset 32 | | movl $1, 12(%rsp) | movl $1, 12(%rsp) | | movl 12(%rsp), %eax | movl 12(%rsp), %eax | | testl %eax, %eax | testl %eax, %eax | | movl $972195717, %eax | | | setne %cl | | | sarl %cl, %eax | | | cmpl $486097858, %eax | | | jne .L5 | jne .L2 | | xorl %eax, %eax | call abort | | addq $24, %rsp |.L2: | | .cfi_remember_state | xorl %eax, %eax | | .cfi_def_cfa_offset 8 | addq $24, %rsp | | ret | .cfi_def_cfa_offset 8 | |.L5: | ret | | .cfi_restore_state | .cfi_endproc | | call abort | | | .cfi_endproc | | +-----------------------------+-----------------------------+ $ x86_64-unknown-linux-gnu-gcc-4.8.4 -v Using built-in specs. COLLECT_GCC=x86_64-unknown-linux-gnu-gcc-4.8.4 COLLECT_LTO_WRAPPER=/usr/local/x86_64-tools/gcc-4.8.4/libexec/gcc/x86_64-unknown-linux-gnu/4.8.4/lto-wrapper Target: x86_64-unknown-linux-gnu Configured with: /home/hassy/gcc/configure --prefix=/usr/local/x86_64-tools/gcc-4.8.4/ --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 4.8.4 20140622 (prerelease) (GCC)