From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 9DE923858CD1; Wed, 29 Nov 2023 08:02:49 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9DE923858CD1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1701244969; bh=+ZHwJEWy8oTeZMd6i+W1dp/J5pmi4vCTWaBO8JSypdQ=; h=From:To:Subject:Date:In-Reply-To:References:From; b=SG7lTVF8+Y+aRuK+PKw9bWvaqaBIxDKCV48Brj+sST1gGKch6zszqL9OaF42LTXDL V0RglGnoOJHTmYUIarxa2h91/M7Wwc1uZP2EG0ua3skUx17AetIoUbQZDB2qgRRFl6 A3SA4+DyUe2tTWM2fL0jEVzD0zQIo1MZsfy9SeIM= From: "zsojka at seznam dot cz" To: gcc-bugs@gcc.gnu.org Subject: [Bug target/112760] [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 08:02:48 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed 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: attachments.created Message-ID: In-Reply-To: References: 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 --- Comment #1 from Zdenek Sojka --- Created attachment 56716 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=3D56716&action=3Dedit more complex testcase, with less compiler flags Attached a testcase that needs only -O2 -mavx; might be a different issue, though. $ x86_64-pc-linux-gnu-gcc -m32 -O2 -mavx testcase.c $ ./a.out=20 Aborted $ diff -u a-testcase.GOOD.s a-testcase.BAD.s=20 --- a-testcase.GOOD.s 2023-11-29 08:53:43.058791568 +0100 +++ a-testcase.BAD.s 2023-11-29 08:52:39.878792460 +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 -masm=3Dintel -mtune=3Dgeneric -march=3Dx86-64 -O2 +# options passed: -m32 -mavx -masm=3Dintel -mtune=3Dgeneric -march=3Dx86-6= 4 -O2 .text .p2align 4 .globl foo0 @@ -37,19 +37,19 @@ rol ax, 8 # _5, # testcase.c:11: u64 u64_1 =3D __builtin_bswap16 (SHL (u64_0, u8_0)) % u= 16_0; div bx # u16_0 -# testcase.c:12: u8 u8_1 =3D __builtin_add_overflow_p (u8_0, u8_0, u8_0); - mov eax, ecx # u8_0, u8_0 # testcase.c:13: u32 u32_1 =3D foo0_u32_0 & u16_0; movzx ebx, bx # u16_0, u16_0 # testcase.c:12: u8 u8_1 =3D __builtin_add_overflow_p (u8_0, u8_0, u8_0); - add al, cl # u8_0, u8_0 + add al, al # u8_0, u8_0 +# testcase.c:14: u32 u32_2 =3D __builtin_sub_overflow_p (0, u64_1, (u8) = 0); + movzx edx, dx # _6, tmp127 +# testcase.c:12: u8 u8_1 =3D __builtin_add_overflow_p (u8_0, u8_0, u8_0); setc al #, _15 # testcase.c:14: u32 u32_2 =3D __builtin_sub_overflow_p (0, u64_1, (u8) = 0); xor ecx, ecx # tmp133 # testcase.c:13: u32 u32_1 =3D foo0_u32_0 & u16_0; and ebx, DWORD PTR foo0_u32_0 # u32_1, foo0_u32_0 # testcase.c:14: u32 u32_2 =3D __builtin_sub_overflow_p (0, u64_1, (u8) = 0); - movzx edx, dx # _6, tmp127 sub ecx, edx # tmp132, _6 setb dl #, _18 and ecx, -256 # tmp132, Here, the problem is with: # testcase.c:12: u8 u8_1 =3D __builtin_add_overflow_p (u8_0, u8_0, u8_0); add al, al # u8_0, u8_0 due to the: -# testcase.c:12: u8 u8_1 =3D __builtin_add_overflow_p (u8_0, u8_0, u8_0); - mov eax, ecx # u8_0, u8_0 there is no "u8_0" in eax Maybe the compiler tries to use an AVX instruction, that is in the end not generated?=