public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/96480] New: missed optimisation: unnecessary compare in standard algorithms
@ 2020-08-05  8:53 kurkindmit at gmail dot com
  2020-08-05 11:22 ` [Bug c++/96480] [8/9/10/11 Regression] " jakub at gcc dot gnu.org
                   ` (11 more replies)
  0 siblings, 12 replies; 13+ messages in thread
From: kurkindmit at gmail dot com @ 2020-08-05  8:53 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96480

            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 <algorithm>
#include <array>

enum ENUM { A, B, C, D, E, F, G, };

const std::array<ENUM, 4> foo{A, B, C, D};

bool is_foo(ENUM e) {
    return std::any_of(foo.begin(), foo.end(),
    [e] (auto ee) { return e == ee; });
}

GCC 7.4 optimizes if_foo to a single compare operation e <= 3,
but newer GCC versions do two comare operations e <= 2 || e == 3.

see https://godbolt.org/z/5a6aPa

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2023-07-07  9:01 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-05  8:53 [Bug c++/96480] New: missed optimisation: unnecessary compare in standard algorithms kurkindmit at gmail dot com
2020-08-05 11:22 ` [Bug c++/96480] [8/9/10/11 Regression] " jakub at gcc dot gnu.org
2020-08-05 11:26 ` jakub at gcc dot gnu.org
2020-08-05 11:32 ` [Bug tree-optimization/96480] " rguenth at gcc dot gnu.org
2020-08-05 11:44 ` jakub at gcc dot gnu.org
2020-08-05 14:29 ` jakub at gcc dot gnu.org
2020-08-06 13:48 ` cvs-commit at gcc dot gnu.org
2020-08-06 13:53 ` [Bug tree-optimization/96480] [8/9/10 " jakub at gcc dot gnu.org
2021-05-14  9:53 ` [Bug tree-optimization/96480] [9/10 " jakub at gcc dot gnu.org
2021-06-01  8:18 ` rguenth at gcc dot gnu.org
2022-05-27  9:43 ` [Bug tree-optimization/96480] [10 " rguenth at gcc dot gnu.org
2022-06-28 10:41 ` jakub at gcc dot gnu.org
2023-07-07  9:01 ` rguenth at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).