From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 5854E385DC1B; Mon, 27 Apr 2020 00:40:24 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5854E385DC1B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1587948024; bh=QxgFwaWA2LeMuHuuRlFy0XB61dNlKHZ3dQbPmurjq1Y=; h=From:To:Subject:Date:From; b=Zi1E7caKepql/5/1HZTRj04brrgsMFP3dkP8ybv6i9lC1PMSqRH9ZYAR9CbNnNjWa UFkS9tMWNFkTE5Hhty/j/H4iMiAHIkMffAyD8yICaQfnVmIgUis2gxLFCmMdUbnzBR fTz+ph9JKFkvAAEhmE3z0wXKsa2n0Gx5spUQiScU= From: "gabravier at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/94779] New: Bad optimization of simple switch Date: Mon, 27 Apr 2020 00:40:24 +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: 10.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: gabravier 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 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 27 Apr 2020 00:40:24 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D94779 Bug ID: 94779 Summary: Bad optimization of simple switch Product: gcc Version: 10.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: gabravier at gmail dot com Target Milestone: --- int f1(unsigned x) { switch (x) { case 0: return 1; case 1: return 2; } } gcc fails to optimize this to `return x + 1`, instead opting for some rather weird code generation (involving `sbb` on x86). However, adding this : if (x >=3D 2) __builtin_unreachable(); at the beginning of the function makes it be optimized properly. Maybe this= is a sign of the `x >=3D 2` condition being always false (due to it leading to= UB) being found too late ?=