https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64322
Bug ID: 64322 Summary: More optimize opportunity for constant folding 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) change 0x100000000L to 0L. Resulting codes by "x86_64-unknown-linux-gnu-gcc-5.0.0 -Os -S" are different; the code (A.s) for (A.c) is less optimized than (B.s) for (B.c). Note that variable c is not referenced at all in this program. (A.c) int main (void) { long a = -1L; volatile long b = 0L; volatile long c = 0x100000000L; // <---HERE a = (1+b >> 63 << 1) / 0x100000000L; if (a == 0L); else __builtin_abort(); return 0; } (B.c) int main (void) { long a = -1L; volatile long b = 0L; volatile long c = 0L; // <---HERE a = (1+b >> 63 << 1) / 0x100000000L; if (a == 0L); else __builtin_abort(); return 0; } +-----------------------------+-----------------------------+ |(A.s) |(B.s) | +-----------------------------+-----------------------------+ |main: |main: | |.LFB0: |.LFB0: | | .cfi_startproc | .cfi_startproc | | subq $24, %rsp | movq $0, -24(%rsp) | | .cfi_def_cfa_offset 32 | movq $0, -16(%rsp) | | movabsq $4294967296, %rcx | movq -24(%rsp), %rax | | movq $0, (%rsp) | | | movq %rcx, 8(%rsp) | | | movq (%rsp), %rax | | | incq %rax | | | sarq $63, %rax | | | addq %rax, %rax | | | cqto | | | idivq %rcx | | | testq %rax, %rax | | | je .L2 | | | call abort | | |.L2: | | | xorl %eax, %eax | xorl %eax, %eax | | addq $24, %rsp | | | .cfi_def_cfa_offset 8 | | | ret | ret | | .cfi_endproc | .cfi_endproc | |.LHOTE0: |.LHOTE0: | +-----------------------------+-----------------------------+ $ 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/hassy/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 20141215 (experimental) (GCC)