[Bug tree-optimization/97964] New: Missed optimization opportunity for VRP
ishiura-compiler at ml dot kwansei.ac.jp
gcc-bugzilla@gcc.gnu.org
Tue Nov 24 07:47:48 GMT 2020
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97964
Bug ID: 97964
Summary: Missed optimization opportunity for VRP
Product: gcc
Version: 10.2.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 two programs (A1.c, A2.c) by gcc-10.2.0 with -O3 option.
The two programs are equivalent, but resulted in different assembly codes.
Although varialbe a is volatile, the value of variable t can be
determined at compile time via VRP optimization.
Note that gcc-7.5.0 or older versions compiled the both code into the
same minimum assebmly codes. For more precise:
gcc-10.2.0 diff
gcc-9.3.0 diff
gcc-8.0.1 diff
gcc-7.5.0 OK
gcc-6.5.0 OK
gcc-5.5.0 OK
+---------------------------------+---------------------------------+
| A1.c | A2.c |
+---------------------------------+---------------------------------+
|int main (void) |int main (void) |
|{ |{ |
| volatile int a = -1; | volatile int a = 1; |
| long b = -2; | |
| | |
| int c = a>0; | |
| int d = b*c; | |
| int e = 1-d; | a; |
| int t = (-1/(int)e)==1; | int t = 0; |
| | |
| if (t != 0) __builtin_abort(); | if (t != 0) __builtin_abort(); |
| | |
| return 0; | return 0; |
|} |} |
+---------------------------------+---------------------------------+
gcc-10.2.0
+-------------------------------+------------------------------+
| A1.s (gcc-10.2.0 A1.c -O3 -S) | A2.s (gcc-10.2.0 A2.c -O3 -S)|
+-------------------------------+------------------------------+
|main: |main: |
|.LFB0: |.LFB0: |
| .cfi_startproc | .cfi_startproc |
| subq $24, %rsp | movl $1, -4(%rsp) |
| .cfi_def_cfa_offset 32 | movl -4(%rsp), %eax |
| movl $1, 12(%ecx) | |
| movl $-1, 12(%rsp) | |
| movl 12(%rsp), %eax | |
| testl %eax, %eax | |
| setle %al | |
| movzbl %al, %eax | |
| leal -2(%rax,%rax), %eax | |
| subl %eax, %ecx | |
| movl $-1, %eax | |
| cltd | |
| idiv %ecx | |
| cmpl $1, %eax | |
| je .L3 | |
| xorl %eax, %eax | xorl %eax, %eax |
| addq $24, %rsp | |
| .cfi_def_cfa_offset 8 | |
| ret | ret |
| .cfi_endproc | .cfi_endproc |
| .section .text.unlikely | |
| .cfi_startproc | |
| .type main.cold, @function| |
|main.cold: | |
|.LFSB0: | |
|.L3: | |
| .cfi_def_cfa_offset 32 | |
| call abort | |
| .cfi_endproc | |
|.LFE0: |.LFE0: |
| .section text.startup | |
| .size main, .-main | .size main, .-main |
| .section .text.unlikely | |
| .size main.cold, .-mai...| |
|.LCOLDE0: | |
| .section .text.startup | |
|.LHOTE0: | |
| .ident "GCC:(GNU) 10.2.0" | .ident "GCC:(GNU) 10.2.0" |
| .section .note.GNU-stac...| .section .note.GNU-stac...|
+--------------------------------------------------------------+
gcc-7.5.0
+-------------------------------+------------------------------+
| A1.s (gcc-7.5.0 A1.c -O3 -S) | A2.s (gcc-7.5.0 A2.c -O3 -S) |
+-------------------------------+------------------------------+
|main: |main: |
|.LFB0: |.LFB0: |
| .cfi_startproc | .cfi_startproc |
| movl $1, -4(%rsp) | movl $1, -4(%rsp) |
| movl -4(%rsp), %eax | movl -4(%rsp), %eax |
| xorl %eax, %eax | xorl %eax, %eax |
| ret | ret |
| .cfi_endproc | .cfi_endproc |
|.LFE0: |.LFE0: |
| .size main, .-main | .size main, .-main |
| .ident "GCC:(Ubuntu 7.5...| .ident "GCC:(Ubuntu 7.5...|
| .section .note.GNU-stac...| .section .note.GNU-stac...|
+--------------------------------------------------------------+
$ gcc -v
using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/local/libexec/gcc/x86_64-pc-linux-gnu/10.2.0/lto-wrapper
target: x86_64-pc-linux-gnu
configure woth: ../configure --enable-languages=c,c++ --prefix=/usr/local
--disable-bootstrap --disable-multilib
thred model: posix
Supported LTO compression algorithms: zlib
gcc version 10.2.0 (GCC)
$ gcc-7 -v
Using built-in specs.
COLLECT_GCC=gcc-7
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/7/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu
7.5.0-3ubuntu1~18.04'
--with-bugurl=file:///usr/share/doc/gcc-7/README.Bugs
--enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++ --prefix=/usr
--with-gcc-major-version-only --program-suffix=-7
--program-prefix=x86_64-linux-gnu-
--enable-shared --enable-linker-build-id --libexecdir=/usr/lib
--without-included-gettext
--enable-threads=posix --libdir=/usr/lib --enable-nls --enable-bootstrap
--enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes
--with-default-libstdcxx-abi=new --enable-gnu-unique-object
--disable-vtable-verify
--enable-libmpx --enable-plugin --enable-default-pie --with-system-zlib
--with-target-system-zlib --enable-objc-gc=auto --enable-multiarch
--disable-werror
--with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32
--enable-multilib
--with-tune=generic --enable-offload-targets=nvptx-none --without-cuda-driver
--enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu
--target=x86_64-linux-gnu
Thread model: posix
gcc version 7.5.0 (Ubuntu 7.5.0-3ubuntu1~18.04)
More information about the Gcc-bugs
mailing list