public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "redbeard0531 at gmail dot com" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug target/105661] New: Comparisons to atomic variables generates less efficient code Date: Thu, 19 May 2022 12:59:19 +0000 [thread overview] Message-ID: <bug-105661-4@http.gcc.gnu.org/bugzilla/> (raw) https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105661 Bug ID: 105661 Summary: Comparisons to atomic variables generates less efficient code Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: target Assignee: unassigned at gcc dot gnu.org Reporter: redbeard0531 at gmail dot com Target Milestone: --- With normal variables, gcc will generate a nice cmp/js pair when checking if the high bit is null. When using an atomic, gcc generates a movzx/test/js triple, even though it could use the same codegen as for a non-atomic. https://godbolt.org/z/GorvWfrsh #include <atomic> #include <cstdint> [[gnu::noinline]] void f(); uint8_t plain; std::atomic<uint8_t> atomic; void plain_test() { if (plain & 0x80) f(); } void atomic_test() { if (atomic.load(std::memory_order_relaxed) & 0x80) f(); } With both -O2 and -O3 this generates: plain_test(): cmp BYTE PTR plain[rip], 0 js .L4 ret .L4: jmp f() atomic_test(): movzx eax, BYTE PTR atomic[rip] test al, al js .L7 ret .L7: jmp f() ARM64 seems to be hit even harder, but I don't know that platform well enough to know if the non-atomic codegen is valid there https://godbolt.org/z/c3h8Y1dan. It seems likely though, at least for a relaxed load.
next reply other threads:[~2022-05-19 12:59 UTC|newest] Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top 2022-05-19 12:59 redbeard0531 at gmail dot com [this message] 2022-10-26 23:34 ` [Bug rtl-optimization/105661] " pinskia at gcc dot gnu.org 2022-10-26 23:35 ` pinskia at gcc dot gnu.org 2023-02-09 18:11 ` pinskia 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-105661-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).