From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 2C8E03857C5E; Fri, 1 Dec 2023 08:27:52 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2C8E03857C5E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1701419272; bh=YjxK9Cz9VtTOa0uNf4KIZ5f4rVTwz9j5v6bolhBetPI=; h=From:To:Subject:Date:In-Reply-To:References:From; b=rfmvE6Ql8lyNC+FAturabhG7mXMv+bQuYTVePihyQ4s6Re6Ug5W9onMFSFBUx3LJT AteFS2kzpNNAfcDtoyshkACr2ruxGRxaU3ft/WpeHYVzYwmK+6aBxejsQ89qyL94th h46WhRQabjf3L0eWqeAne8uIwjJfMN6c6mpS8XIU= From: "cvs-commit at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug middle-end/112750] wrong code with _BitInt(256) and above with __builtin_sub_overflow_p() at -O0 Date: Fri, 01 Dec 2023 08:27:51 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: middle-end X-Bugzilla-Version: 14.0 X-Bugzilla-Keywords: wrong-code X-Bugzilla-Severity: normal X-Bugzilla-Who: cvs-commit at gcc dot gnu.org X-Bugzilla-Status: ASSIGNED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: jakub at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: 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=3D112750 --- Comment #2 from GCC Commits --- The master branch has been updated by Jakub Jelinek : https://gcc.gnu.org/g:364332658ef790d09d250db39c5b13e27c3543f1 commit r14-6042-g364332658ef790d09d250db39c5b13e27c3543f1 Author: Jakub Jelinek Date: Fri Dec 1 09:25:45 2023 +0100 lower-bitint: Fix _BitInt .{ADD,SUB}_OVERFLOW lowering [PR112750] The .{ADD,SUB}_OVERFLOW lowering is implemented by performing normal addition/subtraction (perhaps extended to even more bits than normally = by continuing with extended values of operands after running of normal bit= s) and in addition to that trying to compute if certain sets of bits are either all zero or all sign extensions of the least significant bit. That code is in a lot of cases guarded just by a single condition (which can be idx > startlimb, idx >=3D startlimb or idx =3D=3D startlimb) or = by 2 conditions - if (idx >=3D startlimb) { if (idx =3D=3D startlimb) ... = else ... } Now, if_then_if_then_else when the second argument is NULL works just as if_then and sets m_gsi to be within the initially empty then block and = that is where we emit code for constant tidx startlimb + (cmp_code =3D=3D GT_EX= PR). But in the 2 conditions case, m_gsi is set to the initially empty else block, so using EQ_EXPR for the condition was incorrect (and strangely nothing in the testsuite caught that), because the code for extracting = the lowest set of bits (i.e. when tidx is startlimb) is then done when idx is not startlimb rather than when it is. The following patch fixes that. Note, when developing the lowering, I was using gcov to make sure all c= ode is covered by the testsuite with minimum exceptions, so no idea how this slipped out. 2023-12-01 Jakub Jelinek PR middle-end/112750 * gimple-lower-bitint.cc (bitint_large_huge::lower_addsub_overflow): Use NE_EXPR rather than EQ_EXPR for g2 if !single_comparison and adjust probabilities. * gcc.dg/bitint-41.c: Use -std=3Dc23 rather than -std=3Dc2x. * gcc.dg/torture/bitint-43.c: Likewise. * gcc.dg/torture/bitint-44.c: Likewise. * gcc.dg/torture/bitint-45.c: New test.=