public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "morwenn29 at hotmail dot fr" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/67962] New: Optimization opportunity with conditional swap Date: Wed, 14 Oct 2015 11:06:00 -0000 [thread overview] Message-ID: <bug-67962-4@http.gcc.gnu.org/bugzilla/> (raw) https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67962 Bug ID: 67962 Summary: Optimization opportunity with conditional swap Product: gcc Version: 5.2.0 Status: UNCONFIRMED Severity: minor Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: morwenn29 at hotmail dot fr Target Milestone: --- If have some algorithms that use an extensive number of conditional swaps like this (a few hundreds I guess): if (y < x) { std::swap(x, y); } I thought that such a construct could be optimized by the compiler, but it appears that the following function is more performant with integers most of the time: void swap_if(int& x, int& y) { int dx = x; int dy = y; int tmp = x = std::min(dx, dy); y ^= dx ^ tmp; } Would it be possible for g++ to recognize this kind of construct and optimize it, at least for integer types? Reordering two values seems like something common enough so that optimizing it could also benefit existing code. As a side note, I hope that Bugzilla is he right place for this kind of request. Sorry if it isn't.
next reply other threads:[~2015-10-14 11:06 UTC|newest] Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top 2015-10-14 11:06 morwenn29 at hotmail dot fr [this message] 2015-10-14 11:44 ` [Bug tree-optimization/67962] Optimization opportunity with conditional swap to two MIN/MAX in phiopt rguenth at gcc dot gnu.org 2021-08-30 5:45 ` pinskia at gcc dot gnu.org 2023-07-21 8:26 ` rguenth at gcc dot gnu.org
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-67962-4@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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).