From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 25BF43858D3C; Wed, 29 Nov 2023 07:42:27 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 25BF43858D3C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1701243747; bh=zT/k3+fYoO0KpeTDgzF9sC/lLbV7oDLI+MSDGwXTgEc=; h=From:To:Subject:Date:From; b=X7r51GePFgTH7qAlxqdKk982/qantVIlLRvrhMHnyrCV9KNo02868IrxZnu5gHCcn l924kdnOGBUG2FkohtmwWjJb+MbiHn+/RbswR4V9sINMXW4KhNyG3UB4AAtW72pMyt x+VuPryYkHx7kdZvpdFRT5s3vt+u2+7Mu6mVZmkQ= From: "zsojka at seznam dot cz" To: gcc-bugs@gcc.gnu.org Subject: [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() Date: Wed, 29 Nov 2023 07:42:26 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: target X-Bugzilla-Version: 14.0 X-Bugzilla-Keywords: wrong-code X-Bugzilla-Severity: normal X-Bugzilla-Who: zsojka at seznam dot cz X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status keywords bug_severity priority component assigned_to reporter target_milestone cf_gcchost cf_gcctarget attachments.created Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D112760 Bug ID: 112760 Summary: [14 Regression] wrong code with -O2 -fno-dce -fno-guess-branch-probability -m8bit-idiv -mavx --param=3Dmax-cse-insns=3D0 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=3D56715&action=3Dedit reduced testcase Output: $ x86_64-pc-linux-gnu-gcc -m32 -O2 -fno-dce -fno-guess-branch-probability -m8bit-idiv -mavx --param=3Dmax-cse-insns=3D0 testcase.c $ ./a.out=20 Aborted The code for __builtin_add_overflow() check looks wrong: # testcase.c:9: u16 x =3D __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=20 --- 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 versi= on 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=3D30 --param ggc-min-heapsize=3D4= 096 -# options passed: -m32 -m8bit-idiv -masm=3Dintel -mtune=3Dgeneric -march= =3Dx86-64 -O2 -fno-dce -fno-guess-branch-probability --param=3Dmax-cse-insns=3D0 +# options passed: -m32 -m8bit-idiv -mavx -masm=3Dintel -mtune=3Dgeneric -march=3Dx86-64 -O2 -fno-dce -fno-guess-branch-probability --param=3Dmax-cse-insns=3D0 .text .p2align 4 .globl foo0 @@ -28,10 +28,8 @@ movzx esi, WORD PTR [esp+16] # b, b # testcase.c:9: u16 x =3D __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 -=3D 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=3D/repo/gcc-trunk/binary-latest-amd64/bin/x86_64-pc-linux-gnu-g= cc COLLECT_LTO_WRAPPER=3D/repo/gcc-trunk/binary-trunk-r14-5940-20231128183456-= g3d104d93a70-checking-yes-rtl-df-extra-amd64/bin/../libexec/gcc/x86_64-pc-l= inux-gnu/14.0.0/lto-wrapper Target: x86_64-pc-linux-gnu Configured with: /repo/gcc-trunk//configure --enable-languages=3Dc,c++ --enable-valgrind-annotations --disable-nls --enable-checking=3Dyes,rtl,df,= extra --with-cloog --with-ppl --with-isl --build=3Dx86_64-pc-linux-gnu --host=3Dx86_64-pc-linux-gnu --target=3Dx86_64-pc-linux-gnu --with-ld=3D/usr/bin/x86_64-pc-linux-gnu-ld --with-as=3D/usr/bin/x86_64-pc-linux-gnu-as --disable-libstdcxx-pch --prefix=3D/repo/gcc-trunk//binary-trunk-r14-5940-20231128183456-g3d104d93a= 70-checking-yes-rtl-df-extra-amd64 Thread model: posix Supported LTO compression algorithms: zlib zstd gcc version 14.0.0 20231128 (experimental) (GCC)=