https://gcc.gnu.org/bugzilla/show_bug.cgi?id=128983
Bug ID: 128983
Summary: VRP regression involving volatile operands
Product: gcc
Version: 16.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 expect A1.c and A2.c to compile to the same code, but they do not
with GCC 16.2.0 at -O3. Although x2 is volatile, value range
propagation (VRP) should be able to determine at compile time that t
is always 0. (The left-hand side of the comparison has a value range
of [-28, -11], even if the three volatile reads yield different
values.)
This regression appears to have occurred between GCC 11.5.0 and GCC
13.3.0.
gcc-16.2.0 diff
gcc-14.1.0 diff
gcc-13.3.0 diff
gcc-11.5.0 OK
gcc-10.5.0 OK
gcc-8.5.0 OK
+--------------------------------------------------+----------------------------+
| A1.c | A2.c
|
+--------------------------------------------------+----------------------------+
| int main(void) | int main(void)
|
| { | {
|
| int x1 = 1; | int x1 = 1;
|
| volatile long x2 = 0; | volatile long x2 = 0;
|
| int t = (int)(((x2 % -4 + 15) / 2) * | int t = 0;
|
| (-2 * x1 - (0 > x2)) + x2 % 2) >= 0; | t = 0, x2, x2, x2;
|
| |
|
| if (t != 0) | if (t != 0)
|
| __builtin_abort(); | __builtin_abort();
|
| return 0; | return 0;
|
| } | }
|
+--------------------------------------------------+----------------------------+
gcc-16.2.0
+-------------------------------+-------------------------------+
| A1.s (gcc-16 A1.c -O3 -S) | A2.s (gcc-16 A2.c -O3 -S) |
+-------------------------------+-------------------------------+
| .file "A1.c" | .file "A2.c" |
| .text | .text |
| .section .text.unlikel... | |
| .LCOLDB0: | |
| .section .text.startup... | .section .text.startup... |
| .LHOTB0: | |
| .p2align 4 | .p2align 4 |
| .globl main | .globl main |
| .type main, @function | .type main, @function |
| main: | main: |
| .LFB0: | .LFB0: |
| .cfi_startproc | .cfi_startproc |
| subq $24, %rsp | |
| .cfi_def_cfa_offset 32 | |
| movq $0, 8(%rsp) | movq $0, -8(%rsp) |
| movq 8(%rsp), %rax | movq -8(%rsp), %rax |
| movq 8(%rsp), %rsi | movq -8(%rsp), %rax |
| movq 8(%rsp), %rdx | movq -8(%rsp), %rax |
| movq %rax, %rcx | |
| sarq $63, %rcx | |
| shrq $63, %rsi | |
| shrq $62, %rcx | |
| addq %rcx, %rax | |
| andl $3, %eax | |
| subq %rcx, %rax | |
| movl $-2, %ecx | |
| addq $15, %rax | |
| subl %esi, %ecx | |
| sarq %rax | |
| imull %ecx, %eax | |
| movq %rdx, %rcx | |
| shrq $63, %rcx | |
| addq %rcx, %rdx | |
| andl $1, %edx | |
| subq %rcx, %rdx | |
| addl %edx, %eax | |
| jns .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, @fu... | |
| 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, .-m... | |
| .LCOLDE0: | |
| .section .text.startup | |
| .LHOTE0: | |
| .ident "GCC: (GNU) 16... | .ident "GCC: (GNU) 16... |
| .section .note.GNU-sta... | .section .note.GNU-sta... |
+-------------------------------+-------------------------------+
gcc-11.5.0
+-------------------------------+-------------------------------+
| A1.s (gcc-11 A1.c -O3 -S) | A2.s (gcc-11 A2.c -O3 -S) |
+-------------------------------+-------------------------------+
| .file "A1.c" | .file "A2.c" |
| .text | .text |
| .section .text.startup... | .section .text.startup... |
| .p2align 4 | .p2align 4 |
| .globl main | .globl main |
| .type main, @function | .type main, @function |
| main: | main: |
| .LFB0: | .LFB0: |
| .cfi_startproc | .cfi_startproc |
| endbr64 | endbr64 |
| movq $0, -8(%rsp) | movq $0, -8(%rsp) |
| movq -8(%rsp), %rax | movq -8(%rsp), %rax |
| movq -8(%rsp), %rax | movq -8(%rsp), %rax |
| movq -8(%rsp), %rax | movq -8(%rsp), %rax |
| xorl %eax, %eax | xorl %eax, %eax |
| ret | ret |
| .cfi_endproc | .cfi_endproc |
| .LFE0: | .LFE0: |
| .size main, .-main | .size main, .-main |
| .ident "GCC: (Ubuntu... | .ident "GCC: (Ubuntu... |
| .section .note.GNU-sta... | .section .note.GNU-sta... |
| .section .note.gnu.pro... | .section .note.gnu.pro... |
| .align 8 | .align 8 |
| .long 1f - 0f | .long 1f - 0f |
| .long 4f - 1f | .long 4f - 1f |
| .long 5 | .long 5 |
| 0: | 0: |
| .string "GNU" | .string "GNU" |
| 1: | 1: |
| .align 8 | .align 8 |
| .long 0xc0000002 | .long 0xc0000002 |
| .long 3f - 2f | .long 3f - 2f |
| 2: | 2: |
| .long 0x3 | .long 0x3 |
| 3: | 3: |
| .align 8 | .align 8 |
| 4: | 4: |
+-------------------------------+-------------------------------+
$ gcc-16 -v
Using built-in specs.
COLLECT_GCC=gcc-16
COLLECT_LTO_WRAPPER=/home/<user>/.local/opt/gcc-16.2.0/libexec/gcc/x86_64-pc-linux-gnu/16.2.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: /home/<user>/.local/src/gcc-16.2.0-src/configure
--prefix=/home/<user>/.local/opt/gcc-16.2.0 --enable-languages=c,c++
--disable-multilib --disable-bootstrap --with-system-zlib
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 16.2.0 (GCC)
$ gcc-11 -v
Using built-in specs.
COLLECT_GCC=gcc-11
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/11/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none:amdgcn-amdhsa
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v
--with-pkgversion='Ubuntu 11.5.0-1ubuntu1~24.04.1'
--with-bugurl=file:///usr/share/doc/gcc-11/README.Bugs
--enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++,m2 --prefix=/usr
--with-gcc-major-version-only --program-suffix=-11
--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-plugin --enable-default-pie
--with-system-zlib --enable-libphobos-checking=release
--with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch
--disable-werror --enable-cet --with-arch-32=i686 --with-abi=m64
--with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic
--enable-offload-targets=nvptx-none=/build/gcc-11-8tD0Xq/gcc-11-11.5.0/debian/tmp-nvptx/usr,amdgcn-amdhsa=/build/gcc-11-8tD0Xq/gcc-11-11.5.0/debian/tmp-gcn/usr
--without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu
--host=x86_64-linux-gnu --target=x86_64-linux-gnu
--with-build-config=bootstrap-lto-lean --enable-link-serialization=2
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 11.5.0 (Ubuntu 11.5.0-1ubuntu1~24.04.1)