[Bug target/112760] New: [14 Regression] wrong code with -O2 -fno-dce -fno-guess-branch-probability -m8bit-idiv -mavx --param=max-cse-insns=0 and __builtin_add_overflow_p()
zsojka at seznam dot cz
gcc-bugzilla@gcc.gnu.org
Wed Nov 29 07:42:26 GMT 2023
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112760
Bug ID: 112760
Summary: [14 Regression] wrong code with -O2 -fno-dce
-fno-guess-branch-probability -m8bit-idiv -mavx
--param=max-cse-insns=0 and __builtin_add_overflow_p()
Product: gcc
Version: 14.0
Status: UNCONFIRMED
Keywords: wrong-code
Severity: normal
Priority: P3
Component: target
Assignee: unassigned at gcc dot gnu.org
Reporter: zsojka at seznam dot cz
Target Milestone: ---
Host: x86_64-pc-linux-gnu
Target: i686-pc-linux-gnu
Created attachment 56715
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=56715&action=edit
reduced testcase
Output:
$ x86_64-pc-linux-gnu-gcc -m32 -O2 -fno-dce -fno-guess-branch-probability
-m8bit-idiv -mavx --param=max-cse-insns=0 testcase.c
$ ./a.out
Aborted
The code for __builtin_add_overflow() check looks wrong:
# testcase.c:9: u16 x = __builtin_add_overflow_p (a, g, (u16) 0);
add eax, ecx # tmp110, g.0_1
mov eax, 1 # tmp118,
setc bl #, _8
cmovne ebx, eax # _8,, _8, tmp118
Comparing the code without -mavx, the breakage can be observed better:
$ diff -u a-testcase.GOOD.s a-testcase.BAD.s
--- a-testcase.GOOD.s 2023-11-29 08:34:39.978807709 +0100
+++ a-testcase.BAD.s 2023-11-29 08:32:27.458809580 +0100
@@ -4,7 +4,7 @@
# compiled by GNU C version 14.0.0 20231128 (experimental), GMP version
6.3.0, MPFR version 4.2.1, MPC version 1.3.1, isl version isl-0.26-GMP
# GGC heuristics: --param ggc-min-expand=30 --param ggc-min-heapsize=4096
-# options passed: -m32 -m8bit-idiv -masm=intel -mtune=generic -march=x86-64
-O2 -fno-dce -fno-guess-branch-probability --param=max-cse-insns=0
+# options passed: -m32 -m8bit-idiv -mavx -masm=intel -mtune=generic
-march=x86-64 -O2 -fno-dce -fno-guess-branch-probability
--param=max-cse-insns=0
.text
.p2align 4
.globl foo0
@@ -28,10 +28,8 @@
movzx esi, WORD PTR [esp+16] # b, b
# testcase.c:9: u16 x = __builtin_add_overflow_p (a, g, (u16) 0);
add eax, ecx # tmp110, g.0_1
- movzx edx, ax # tmp111, tmp110
- setc bl #, _8
- cmp eax, edx # tmp110, tmp111
mov eax, 1 # tmp118,
+ setc bl #, _8
cmovne ebx, eax # _8,, _8, tmp118
# testcase.c:10: g -= g / b;
mov eax, ecx # tmp119, g.0_1
The "cmovne" instruction is using the Z flag from a different comparison.
$ x86_64-pc-linux-gnu-gcc -v
Using built-in specs.
COLLECT_GCC=/repo/gcc-trunk/binary-latest-amd64/bin/x86_64-pc-linux-gnu-gcc
COLLECT_LTO_WRAPPER=/repo/gcc-trunk/binary-trunk-r14-5940-20231128183456-g3d104d93a70-checking-yes-rtl-df-extra-amd64/bin/../libexec/gcc/x86_64-pc-linux-gnu/14.0.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: /repo/gcc-trunk//configure --enable-languages=c,c++
--enable-valgrind-annotations --disable-nls --enable-checking=yes,rtl,df,extra
--with-cloog --with-ppl --with-isl --build=x86_64-pc-linux-gnu
--host=x86_64-pc-linux-gnu --target=x86_64-pc-linux-gnu
--with-ld=/usr/bin/x86_64-pc-linux-gnu-ld
--with-as=/usr/bin/x86_64-pc-linux-gnu-as --disable-libstdcxx-pch
--prefix=/repo/gcc-trunk//binary-trunk-r14-5940-20231128183456-g3d104d93a70-checking-yes-rtl-df-extra-amd64
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 14.0.0 20231128 (experimental) (GCC)
More information about the Gcc-bugs
mailing list