From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 90CE23865C30; Fri, 15 Dec 2023 09:14:41 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 90CE23865C30 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1702631681; bh=/UfbM+pjJOcbAqX0JAwIG0A0INv8+4VUFv96DLmk20w=; h=From:To:Subject:Date:In-Reply-To:References:From; b=HkvsMDeOQbcQeRxD6wxFr6nwCYFdDfgLtP8UscPcP7/DTk+PR220jVqFbGJS1ZR2J O09RJicrgnurPshBbAUq3Qhmbr9bjzYI1TwlDPO/hvqPHTct1tvP2MCiCAdFDeVSOk 1E0KcdSX8HSw43K38fuRFqoJX5D+o1/23Up/ALhI= From: "cvs-commit at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/113024] Nested cast not optimized out in GIMPLE Date: Fri, 15 Dec 2023 09:14:39 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: tree-optimization X-Bugzilla-Version: 14.0 X-Bugzilla-Keywords: missed-optimization X-Bugzilla-Severity: enhancement 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=3D113024 --- Comment #3 from GCC Commits --- The master branch has been updated by Jakub Jelinek : https://gcc.gnu.org/g:330f1e078dae257d4f8f7b13299ececc2344e681 commit r14-6580-g330f1e078dae257d4f8f7b13299ececc2344e681 Author: Jakub Jelinek Date: Fri Dec 15 10:13:44 2023 +0100 match.pd: Optimize sign-extension followed by truncation [PR113024] While looking at a bitint ICE, I've noticed we don't optimize in f1 and f5 functions below the 2 casts into just one at GIMPLE, even when optimize it in convert_to_integer if it appears in the same stmt. The large match.pd simplification of two conversions in a row has many complex rules and as the testcase shows, everything else from the narrowest -> widest -> prec_in_between all integer conversions is already handled, either because the inside_unsignedp =3D=3D inter_un= signedp rule kicks in, or the && ((inter_unsignedp && inter_prec > inside_prec) =3D=3D (final_unsignedp && final_prec > inter_prec)) one, but there is no reason why sign extension to from narrowest to widest type followed by truncation to something in between can't be done just as sign extension from narrowest to the final type. After al= l, if the widest type is signed rather than unsigned, regardless of the fi= nal type signedness we already handle it that way. And since PR93044 we also handle it if the final precision is not wider than the inside precision. 2023-12-15 Jakub Jelinek PR tree-optimization/113024 * match.pd (two conversions in a row): Simplify scalar integer sign-extension followed by truncation. * gcc.dg/tree-ssa/pr113024.c: New test.=