From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id ADD89385700D; Wed, 5 Aug 2020 08:53:43 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org ADD89385700D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1596617623; bh=Eej4jVfKmu1KKyTK3dacpbusqhDH86IoxGclKh87ScU=; h=From:To:Subject:Date:From; b=YkKRbkbRlvVjBuJkj5shCkLZEI4d4is5JzEYZDc9evtLBKE1PmyQrwgQeidKqdseV OLkAOsaphIZQb3gnfAHg2/uP1tIFnVCEVIhcr+wXBI9FcdoWtIp/7lV4luLUVxOo6p oaM24q9dGy+OnIX0DQRGxxSt3nV42N+U5J/m619Y= From: "kurkindmit at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/96480] New: missed optimisation: unnecessary compare in standard algorithms Date: Wed, 05 Aug 2020 08:53:43 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 10.2.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: kurkindmit 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: Wed, 05 Aug 2020 08:53:43 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D96480 Bug ID: 96480 Summary: missed optimisation: unnecessary compare in standard algorithms Product: gcc Version: 10.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: kurkindmit at gmail dot com Target Milestone: --- Consider the C++ code: #include #include enum ENUM { A, B, C, D, E, F, G, }; const std::array foo{A, B, C, D}; bool is_foo(ENUM e) { return std::any_of(foo.begin(), foo.end(), [e] (auto ee) { return e =3D=3D ee; }); } GCC 7.4 optimizes if_foo to a single compare operation e <=3D 3, but newer GCC versions do two comare operations e <=3D 2 || e =3D=3D 3. see https://godbolt.org/z/5a6aPa=