From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id E5B443857C42; Fri, 26 Jan 2024 11:59:28 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E5B443857C42 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1706270368; bh=N/G37LN8iNTkP+EIbr3nFMdU1CFrluum1FAJTJzctPg=; h=From:To:Subject:Date:In-Reply-To:References:From; b=pkzAzlONPIcEyUJzqBRO3hmUyr8RGW/5Q9CYoHyYb7E0dt9b38R06hh35e2bqucQl 1t0Vamqv65z7XA0lpRuz9o9HiFsepDKWJKcg8ttRuQGb6Ma1LIuqoLhY4ZCRv3n5Sr Eogy6ST51Q+ee1VQWLj8GEB++yQNwTyOQFu71soo= From: "fkastl at suse dot cz" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/112687] missed-optimization: switch statement does not simplify to it's expression Date: Fri, 26 Jan 2024 11:59:27 +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: 13.2.1 X-Bugzilla-Keywords: missed-optimization X-Bugzilla-Severity: normal X-Bugzilla-Who: fkastl at suse dot cz X-Bugzilla-Status: NEW 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=3D112687 --- Comment #2 from Filip Kastl --- Created attachment 57222 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=3D57222&action=3Dedit WIP patch to fix the missed optimization, version 0 I'm working on a patch. The problem (as Richard stated in pr112645) is that= the testcase gets optimized into switch (v & 3) { default: return 0; case 1: return 1; case 2: return 2; case 3: return 3; } so the information that there are only 4 possible values of the expression = 'v & 3' is lost. I add capability for switch conversion to recover from this. With my patch, before processing the switch, switch conversion finds out if the default ca= se only corresponds to one possible value of the index expression. If so, it creates a case for this value and marks default as unreachable. With the patch applied, functions opt() and unopt() compile into the same sequence of assembly instructions. I've attached the patch. Do you think th= is is a good approach? I'll also appreciate any suggestions/comments for the patch.=