public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "gabravier at gmail dot com" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug target/102402] New: Seemingly suboptimal optimization of jmp/cmovcc for conditionally loading constants Date: Sat, 18 Sep 2021 18:17:08 +0000 [thread overview] Message-ID: <bug-102402-4@http.gcc.gnu.org/bugzilla/> (raw) https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102402 Bug ID: 102402 Summary: Seemingly suboptimal optimization of jmp/cmovcc for conditionally loading constants Product: gcc Version: 12.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: target Assignee: unassigned at gcc dot gnu.org Reporter: gabravier at gmail dot com Target Milestone: --- #include <stdint.h> struct MusicPlayerTrack { uint8_t flags; uint8_t modT; }; void ClearModM(struct MusicPlayerTrack *track, uint8_t modT) { if (track->modT == 0) track->flags |= 3; else track->flags |= 12; } This is optimized weirdly by GCC. Leaving it as-is gives this AMD64 assembly: ClearModM: movzx edx, BYTE PTR [rdi] mov eax, edx or eax, 12 cmp BYTE PTR [rdi+1], 0 jne .L3 mov eax, edx or eax, 3 .L3: mov BYTE PTR [rdi], al ret Whereas changing the `if` to `if (modT == 0)` gives this: ClearModM: movzx eax, BYTE PTR [rdi] mov edx, eax or eax, 12 or edx, 3 test sil, sil cmove eax, edx mov BYTE PTR [rdi], al ret It seems to me that this should be better than the first output, though of course this could be the other way considering how finicky cmovcc seems to be, but it seems to me like at least one should be preferred above the other. Note that this also occurs on IA-32, so the issue seems unrelated to whether modT is in a register or in memory. Perhaps it's about whether it's a function argument ?
next reply other threads:[~2021-09-18 18:17 UTC|newest] Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-09-18 18:17 gabravier at gmail dot com [this message] 2021-09-18 18:35 ` [Bug tree-optimization/102402] " 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-102402-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).