From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 8973E3858D1E; Thu, 23 Nov 2023 21:43:03 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8973E3858D1E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1700775783; bh=lzwcaw28M01dfqyxSRw8qnygQBYumxwBB2KjUPP67GY=; h=From:To:Subject:Date:From; b=ReYJtBsE/YDYmbciwJ+TDqnxZnfFK4wlA+EWhSG9yaSVZsM3UNv11O8LJ3gr90L5t upALrR2rDZxJdtyC4yfInHZ+40JJtuwo/IDair0qtqYAYcziNEEjBiNaEBBEajKbs3 XZ7SriKAEPhSJWZ8886tvcW9u9jeWj5yKxzuaBx8= From: "goon.pri.low at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/112687] New: missed-optimization: switch statement does not simplify to it's expression Date: Thu, 23 Nov 2023 21:43:03 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: tree-optimization X-Bugzilla-Version: 13.2.1 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: goon.pri.low at gmail dot com 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 bug_severity priority component assigned_to reporter target_milestone 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=3D112687 Bug ID: 112687 Summary: missed-optimization: switch statement does not simplify to it's expression Product: gcc Version: 13.2.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: goon.pri.low at gmail dot com Target Milestone: --- This following code: int unopt(int v) { switch (v & 3) { case 0: return 0; case 1: return 1; case 2: return 2; case 3: return 3; default: __builtin_unreachable(); } } unopt: mov eax, edi and eax, 3 lea edx, [rax-1] cmp edx, 3 mov edx, 0 cmovnb eax, edx ret Ought to be optimized to: int opt(int v) { return v & 3; } opt: mov eax, edi and eax, 3 ret Note: I decided to separate this problem from https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D112645 since it was unrelate= d to the main bug, though Richard offers some initial insight into the problem.=